From eb746f9bc43ff51bd6439560ee791bc26cb540ba Mon Sep 17 00:00:00 2001 From: Andrey Kunchev Date: Fri, 15 Mar 2019 19:18:30 +0200 Subject: [PATCH] tmp: build avalonia.native package on win and local nuget functions, align version to 0.10.17 until merged to master --- nukebuild/Build.cs | 131 ++++++++++++++++++++++++++++++++++- nukebuild/BuildParameters.cs | 19 ++++- 2 files changed, 146 insertions(+), 4 deletions(-) diff --git a/nukebuild/Build.cs b/nukebuild/Build.cs index 7468d88b4df..64124f15c41 100644 --- a/nukebuild/Build.cs +++ b/nukebuild/Build.cs @@ -24,6 +24,7 @@ using static Nuke.Common.Tools.DotNet.DotNetTasks; using static Nuke.Common.Tools.Xunit.XunitTasks; using static Nuke.Common.Tools.VSWhere.VSWhereTasks; +using System.IO.Compression; /* Before editing this file, install support plugin for your IDE, @@ -111,8 +112,20 @@ IReadOnlyCollection MsBuildCommon( Target Clean => _ => _.Executes(() => { - Parameters.BuildDirs.ForEach(DeleteDirectory); - Parameters.BuildDirs.ForEach(EnsureCleanDirectory); + void safe(Action action) + { + try + { + action(); + } + catch (Exception e) { Logger.Warn(e); } + } + //helps local dev builds + void deldir(string dir) => safe(() => DeleteDirectory(dir)); + void cleandir(string dir) => safe(() => EnsureCleanDirectory(dir)); + + Parameters.BuildDirs.ForEach(deldir); + Parameters.BuildDirs.ForEach(cleandir); EnsureCleanDirectory(Parameters.ArtifactsDir); EnsureCleanDirectory(Parameters.NugetIntermediateRoot); EnsureCleanDirectory(Parameters.NugetRoot); @@ -130,6 +143,7 @@ IReadOnlyCollection MsBuildCommon( NpmTasks.NpmInstall(c => c .SetProcessWorkingDirectory(webappDir) .SetProcessArgumentConfigurator(a => a.Add("--silent"))); + NpmTasks.Npm("-- version");//print nodejs versions for tracking NpmTasks.NpmRun(c => c .SetProcessWorkingDirectory(webappDir) .SetCommand("dist")); @@ -155,6 +169,7 @@ bool IsDotnetCoreOnlyBuild() Target Compile => _ => _ .DependsOn(Clean, CompileNative) + .DependsOn(DownloadAvaloniaNativeLib) .DependsOn(CompileHtmlPreviewer) .Executes(async () => { @@ -289,7 +304,7 @@ void RunCoreTest(string projectName) .Executes(() => { RunCoreTest("Avalonia.Skia.RenderTests"); - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Nuke.Common.CI.TeamCity.TeamCity.Instance == null)// no direct2d tests on teamcity - they fail? RunCoreTest("Avalonia.Direct2D1.RenderTests"); }); @@ -334,6 +349,46 @@ void RunCoreTest(string projectName) Zip(data.ZipTargetControlCatalogNetCoreDir, pathToPublish); }); + Target UpdateTeamCityVersion => _ => _ + .Executes(() => + { + Nuke.Common.CI.TeamCity.TeamCity.Instance?.SetBuildNumber(Parameters.Version); + }); + + Target DownloadAvaloniaNativeLib => _ => _ + .After(Clean) + .OnlyWhenStatic(() => EnvironmentInfo.IsWin) + .Executes(() => + { + //download avalonia native osx binary, so we don't have to build it on osx + //expected to be -> Build/Products/Release/libAvalonia.Native.OSX.dylib + //Avalonia.Native.0.10.0-preview5.nupkg + string nugetversion = "0.10.17"; + + var nugetdir = RootDirectory + "/Build/Products/Release/"; + //string nugeturl = "https://www.myget.org/F/avalonia-ci/api/v2/package/Avalonia.Native/"; + string nugeturl = "https://www.nuget.org/api/v2/package/Avalonia.Native/"; + + nugeturl += nugetversion; + + //myget packages are expiring so i've made a copy here + //google drive file share https://drive.google.com/open?id=1HK-XfBZRunGpxXcGUUEC-64H9T_n9cIJ + //nugeturl = "https://drive.google.com/uc?id=1HK-XfBZRunGpxXcGUUEC-64H9T_n9cIJ&export=download";//Avalonia.Native.0.9.999-cibuild0005383-beta + //nugeturl = "https://drive.google.com/uc?id=1fNKJ-KNsPtoi_MYVJZ0l4hbgHAkLMYZZ&export=download";//Avalonia.Native.0.9.2.16.nupkg custom build + //nugeturl = "https://drive.google.com/uc?id=13ek3xvXA__GUgQFeAkemqE0lxiXiTr5s&export=download";//Avalonia.Native.0.10.0.8.nupkg custom build + //nugeturl = "https://drive.google.com/uc?id=13n_Ql64s7eXncUQx_FagU4z5X-tBhtxC&export=download";//Avalonia.Native.0.10.0.16-rc1.nupkg custom build + + string nugetname = $"Avalonia.Native.{nugetversion}"; + string nugetcontentsdir = Path.Combine(nugetdir, nugetname); + string nugetpath = nugetcontentsdir + ".nupkg"; + Logger.Info($"Downloading {nugetname} from {nugeturl}"); + Nuke.Common.IO.HttpTasks.HttpDownloadFile(nugeturl, nugetpath); + System.IO.Compression.ZipFile.ExtractToDirectory(nugetpath, nugetcontentsdir, true); + + CopyFile(nugetcontentsdir + @"/runtimes/osx/native/libAvaloniaNative.dylib", nugetdir + "libAvalonia.Native.OSX." + + "dylib", Nuke.Common.IO.FileExistsPolicy.Overwrite); + }); + Target CreateIntermediateNugetPackages => _ => _ .DependsOn(Compile) .After(RunTests) @@ -342,6 +397,7 @@ void RunCoreTest(string projectName) if (Parameters.IsRunningOnWindows && !IsDotnetCoreOnlyBuild()) MsBuildCommon(Parameters.MSBuildSolution, c => c + .AddProperty("PackAvaloniaNative", "true") .AddTargets("Pack")); else DotNetPack(c => c @@ -364,6 +420,75 @@ void RunCoreTest(string projectName) throw new Exception("Package merge failed"); }); + private static string GetNuGetNugetPackagesDir() + { + string env(string v) => Environment.GetEnvironmentVariable(v); + return env("NUGET_PACKAGES") ?? Path.Combine(env("USERPROFILE") ?? env("HOME"), ".nuget/packages"); + } + + Target PublishLocalNugetPackages => _ => _ + .Executes(() => + { + string nugetPackagesDir = GetNuGetNugetPackagesDir(); + + //clean up often locked dlls from avalonia packages + var preCleanUpDirs = new[] + { + "Avalonia/{0}/tools/", //Avalonia.Build.Tasks.dll + "Avalonia/{0}/lib/", + "Avalonia.Remote.Protocol/{0}/lib/" //Avalonia.Remote.Protocol.dll + }; + foreach (var pattern in preCleanUpDirs) + { + var path = Path.Combine(nugetPackagesDir, string.Format(pattern, Parameters.Version)); + foreach (var filePath in Directory.GetFiles(path, "*.*", SearchOption.AllDirectories)) + { + try + { + DeleteFile(filePath); + } + catch (Exception e) + { + Logger.Warn($"Will rename! Failed delete {e.Message} for {filePath}"); + if (!filePath.EndsWith(".old")) + RenameFile(filePath, $"{filePath}.{Guid.NewGuid()}.old", Nuke.Common.IO.FileExistsPolicy.Overwrite); + } + } + } + + foreach (var package in Directory.EnumerateFiles(Parameters.NugetRoot)) + { + var packName = Path.GetFileName(package); + string packgageFolderName = packName.Replace($".{Parameters.Version}.nupkg", ""); + var nugetCaheFolder = Path.Combine(nugetPackagesDir, packgageFolderName, Parameters.Version); + + //clean directory is not good, nuget will noticed and clean our files + //EnsureCleanDirectory(nugetCaheFolder); + EnsureExistingDirectory(nugetCaheFolder); + + CopyFile(package, nugetCaheFolder + "/" + packName, Nuke.Common.IO.FileExistsPolicy.Skip); + + Logger.Info($"Extracting to {nugetCaheFolder}, {package}"); + + ZipFile.ExtractToDirectory(package, nugetCaheFolder, true); + } + }); + + Target ClearLocalNugetPackages => _ => _ + .Executes(() => + { + string nugetPackagesDir = GetNuGetNugetPackagesDir(); + + foreach (var package in Directory.EnumerateFiles(Parameters.NugetRoot)) + { + var packName = Path.GetFileName(package); + string packgageFolderName = packName.Replace($".{Parameters.Version}.nupkg", ""); + var nugetCaheFolder = Path.Combine(nugetPackagesDir, packgageFolderName, Parameters.Version); + + EnsureCleanDirectory(nugetCaheFolder); + } + }); + Target RunTests => _ => _ .DependsOn(RunCoreLibsTests) .DependsOn(RunRenderTests) diff --git a/nukebuild/BuildParameters.cs b/nukebuild/BuildParameters.cs index a2829cdc690..6ccd5171423 100644 --- a/nukebuild/BuildParameters.cs +++ b/nukebuild/BuildParameters.cs @@ -20,7 +20,10 @@ public partial class Build public string ForceNugetVersion { get; set; } [Parameter("skip-previewer")] - public bool SkipPreviewer { get; set; } + public bool SkipPreviewer { get; set; } = IsLocalBuild; + + [Parameter("nuget-buildtag")] + public string NugetBuildTag { get; set; } [Parameter("force-dotnetcorebuild")] public bool ForceDotNetCoreBuild { get; set; } @@ -105,6 +108,20 @@ public BuildParameters(Build b) IsMyGetRelease = IsReleasable; IsNuGetRelease = IsMainRepo && IsReleasable && IsReleaseBranch; + if (!string.IsNullOrEmpty(b.NugetBuildTag)) + { + var version = GetVersion(); + string versuffix = ""; + int si = version.IndexOf('-'); + if(si > 0) + { + versuffix = version.Substring(si); + version = version.Replace(versuffix,""); + } + //let's force well known version meaning something to us + b.ForceNugetVersion = $"{version}{(string.IsNullOrEmpty(b.NugetBuildTag) ? "" : $"{b.NugetBuildTag}")}{versuffix}"; + } + // VERSION Version = b.ForceNugetVersion ?? GetVersion();