123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Xml.Linq;
- using Nuke.Common;
- using Nuke.Common.Git;
- using Nuke.Common.ProjectModel;
- using Nuke.Common.Tooling;
- using Nuke.Common.Tools.DotNet;
- using Nuke.Common.Tools.MSBuild;
- using Nuke.Common.Tools.Npm;
- using Nuke.Common.Utilities;
- using Nuke.Common.Utilities.Collections;
- using static Nuke.Common.EnvironmentInfo;
- using static Nuke.Common.IO.FileSystemTasks;
- using static Nuke.Common.IO.PathConstruction;
- using static Nuke.Common.Tools.MSBuild.MSBuildTasks;
- using static Nuke.Common.Tools.DotNet.DotNetTasks;
- using static Nuke.Common.Tools.Xunit.XunitTasks;
- using static Nuke.Common.Tools.VSWhere.VSWhereTasks;
- /*
- Before editing this file, install support plugin for your IDE,
- running and debugging a particular target (optionally without deps) would be way easier
- ReSharper/Rider - https://plugins.jetbrains.com/plugin/10803-nuke-support
- VSCode - https://marketplace.visualstudio.com/items?itemName=nuke.support
- */
- partial class Build : NukeBuild
- {
- [Solution("Avalonia.sln")] readonly Solution Solution;
- BuildParameters Parameters { get; set; }
- protected override void OnBuildInitialized()
- {
- Parameters = new BuildParameters(this);
- Information("Building version {0} of Avalonia ({1}) using version {2} of Nuke.",
- Parameters.Version,
- Parameters.Configuration,
- typeof(NukeBuild).Assembly.GetName().Version.ToString());
- if (Parameters.IsLocalBuild)
- {
- Information("Repository Name: " + Parameters.RepositoryName);
- Information("Repository Branch: " + Parameters.RepositoryBranch);
- }
- Information("Configuration: " + Parameters.Configuration);
- Information("IsLocalBuild: " + Parameters.IsLocalBuild);
- Information("IsRunningOnUnix: " + Parameters.IsRunningOnUnix);
- Information("IsRunningOnWindows: " + Parameters.IsRunningOnWindows);
- Information("IsRunningOnAzure:" + Parameters.IsRunningOnAzure);
- Information("IsPullRequest: " + Parameters.IsPullRequest);
- Information("IsMainRepo: " + Parameters.IsMainRepo);
- Information("IsMasterBranch: " + Parameters.IsMasterBranch);
- Information("IsReleaseBranch: " + Parameters.IsReleaseBranch);
- Information("IsReleasable: " + Parameters.IsReleasable);
- Information("IsMyGetRelease: " + Parameters.IsMyGetRelease);
- Information("IsNuGetRelease: " + Parameters.IsNuGetRelease);
- void ExecWait(string preamble, string command, string args)
- {
- Console.WriteLine(preamble);
- Process.Start(new ProcessStartInfo(command, args) {UseShellExecute = false}).WaitForExit();
- }
- ExecWait("dotnet version:", "dotnet", "--info");
- ExecWait("dotnet workloads:", "dotnet", "workload list");
- Information("Processor count: " + Environment.ProcessorCount);
- Information("Available RAM: " + GC.GetGCMemoryInfo().TotalAvailableMemoryBytes / 0x100000 + "MB");
- }
- DotNetConfigHelper ApplySettingCore(DotNetConfigHelper c)
- {
- if (Parameters.IsRunningOnAzure)
- c.AddProperty("JavaSdkDirectory", GetVariable<string>("JAVA_HOME_11_X64"));
- c.AddProperty("PackageVersion", Parameters.Version)
- .AddProperty("iOSRoslynPathHackRequired", true)
- .SetConfiguration(Parameters.Configuration)
- .SetVerbosity(DotNetVerbosity.Minimal);
- return c;
- }
- DotNetBuildSettings ApplySetting(DotNetBuildSettings c, Configure<DotNetBuildSettings> configurator = null) =>
- ApplySettingCore(c).Build.Apply(configurator);
- DotNetPackSettings ApplySetting(DotNetPackSettings c, Configure<DotNetPackSettings> configurator = null) =>
- ApplySettingCore(c).Pack.Apply(configurator);
- DotNetTestSettings ApplySetting(DotNetTestSettings c, Configure<DotNetTestSettings> configurator = null) =>
- ApplySettingCore(c).Test.Apply(configurator);
- Target Clean => _ => _.Executes(() =>
- {
- Parameters.BuildDirs.ForEach(DeleteDirectory);
- Parameters.BuildDirs.ForEach(EnsureCleanDirectory);
- EnsureCleanDirectory(Parameters.ArtifactsDir);
- EnsureCleanDirectory(Parameters.NugetIntermediateRoot);
- EnsureCleanDirectory(Parameters.NugetRoot);
- EnsureCleanDirectory(Parameters.ZipRoot);
- EnsureCleanDirectory(Parameters.TestResultsRoot);
- });
- Target CompileHtmlPreviewer => _ => _
- .DependsOn(Clean)
- .OnlyWhenStatic(() => !Parameters.SkipPreviewer)
- .Executes(() =>
- {
- var webappDir = RootDirectory / "src" / "Avalonia.DesignerSupport" / "Remote" / "HtmlTransport" / "webapp";
- NpmTasks.NpmInstall(c => c
- .SetProcessWorkingDirectory(webappDir)
- .SetProcessArgumentConfigurator(a => a.Add("--silent")));
- NpmTasks.NpmRun(c => c
- .SetProcessWorkingDirectory(webappDir)
- .SetCommand("dist"));
- });
- Target CompileNative => _ => _
- .DependsOn(Clean)
- .DependsOn(GenerateCppHeaders)
- .OnlyWhenStatic(() => EnvironmentInfo.IsOsx)
- .Executes(() =>
- {
- var project = $"{RootDirectory}/native/Avalonia.Native/src/OSX/Avalonia.Native.OSX.xcodeproj/";
- var args = $"-project {project} -configuration {Parameters.Configuration} CONFIGURATION_BUILD_DIR={RootDirectory}/Build/Products/Release";
- ProcessTasks.StartProcess("xcodebuild", args).AssertZeroExitCode();
- });
- Target Compile => _ => _
- .DependsOn(Clean, CompileNative)
- .DependsOn(CompileHtmlPreviewer)
- .Executes(() =>
- {
- DotNetBuild(c => ApplySetting(c)
- .SetProjectFile(Parameters.MSBuildSolution)
- );
- });
- void RunCoreTest(string projectName)
- {
- Information($"Running tests from {projectName}");
- var project = Solution.GetProject(projectName).NotNull("project != null");
- foreach (var fw in project.GetTargetFrameworks())
- {
- if (fw.StartsWith("net4")
- && RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
- && Environment.GetEnvironmentVariable("FORCE_LINUX_TESTS") != "1")
- {
- Information($"Skipping {projectName} ({fw}) tests on Linux - https://github.com/mono/mono/issues/13969");
- continue;
- }
- Information($"Running for {projectName} ({fw}) ...");
- DotNetTest(c => ApplySetting(c)
- .SetProjectFile(project)
- .SetFramework(fw)
- .EnableNoBuild()
- .EnableNoRestore()
- .When(Parameters.PublishTestResults, _ => _
- .SetLoggers("trx")
- .SetResultsDirectory(Parameters.TestResultsRoot)));
- }
- }
- Target RunHtmlPreviewerTests => _ => _
- .DependsOn(CompileHtmlPreviewer)
- .OnlyWhenStatic(() => !(Parameters.SkipPreviewer || Parameters.SkipTests))
- .Executes(() =>
- {
- var webappTestDir = RootDirectory / "tests" / "Avalonia.DesignerSupport.Tests" / "Remote" / "HtmlTransport" / "webapp";
- NpmTasks.NpmInstall(c => c
- .SetProcessWorkingDirectory(webappTestDir)
- .SetProcessArgumentConfigurator(a => a.Add("--silent")));
- NpmTasks.NpmRun(c => c
- .SetProcessWorkingDirectory(webappTestDir)
- .SetCommand("test"));
- });
- Target RunCoreLibsTests => _ => _
- .OnlyWhenStatic(() => !Parameters.SkipTests)
- .DependsOn(Compile)
- .Executes(() =>
- {
- RunCoreTest("Avalonia.Base.UnitTests");
- RunCoreTest("Avalonia.Controls.UnitTests");
- RunCoreTest("Avalonia.Controls.DataGrid.UnitTests");
- RunCoreTest("Avalonia.Markup.UnitTests");
- RunCoreTest("Avalonia.Markup.Xaml.UnitTests");
- RunCoreTest("Avalonia.Skia.UnitTests");
- RunCoreTest("Avalonia.ReactiveUI.UnitTests");
- });
- Target RunRenderTests => _ => _
- .OnlyWhenStatic(() => !Parameters.SkipTests)
- .DependsOn(Compile)
- .Executes(() =>
- {
- RunCoreTest("Avalonia.Skia.RenderTests");
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- RunCoreTest("Avalonia.Direct2D1.RenderTests");
- });
- Target RunDesignerTests => _ => _
- .OnlyWhenStatic(() => !Parameters.SkipTests && Parameters.IsRunningOnWindows)
- .DependsOn(Compile)
- .Executes(() =>
- {
- RunCoreTest("Avalonia.DesignerSupport.Tests");
- });
- [PackageExecutable("JetBrains.dotMemoryUnit", "dotMemoryUnit.exe")] readonly Tool DotMemoryUnit;
- Target RunLeakTests => _ => _
- .OnlyWhenStatic(() => !Parameters.SkipTests && Parameters.IsRunningOnWindows)
- .DependsOn(Compile)
- .Executes(() =>
- {
- void DoMemoryTest()
- {
- var testAssembly = "tests\\Avalonia.LeakTests\\bin\\Release\\net461\\Avalonia.LeakTests.dll";
- DotMemoryUnit(
- $"{XunitPath.DoubleQuoteIfNeeded()} --propagate-exit-code -- {testAssembly}",
- timeout: 120_000);
- }
- ControlFlow.ExecuteWithRetry(DoMemoryTest, delay: TimeSpan.FromMilliseconds(3));
- });
- Target ZipFiles => _ => _
- .After(CreateNugetPackages, Compile, RunCoreLibsTests, Package)
- .Executes(() =>
- {
- var data = Parameters;
- Zip(data.ZipNuGetArtifacts, data.NugetRoot);
- });
- Target CreateIntermediateNugetPackages => _ => _
- .DependsOn(Compile)
- .After(RunTests)
- .Executes(() =>
- {
- DotNetPack(c => ApplySetting(c).SetProject(Parameters.MSBuildSolution));
- });
- Target CreateNugetPackages => _ => _
- .DependsOn(CreateIntermediateNugetPackages)
- .Executes(() =>
- {
- BuildTasksPatcher.PatchBuildTasksInPackage(Parameters.NugetIntermediateRoot / "Avalonia.Build.Tasks." +
- Parameters.Version + ".nupkg");
- var config = Numerge.MergeConfiguration.LoadFile(RootDirectory / "nukebuild" / "numerge.config");
- EnsureCleanDirectory(Parameters.NugetRoot);
- if(!Numerge.NugetPackageMerger.Merge(Parameters.NugetIntermediateRoot, Parameters.NugetRoot, config,
- new NumergeNukeLogger()))
- throw new Exception("Package merge failed");
- });
- Target RunTests => _ => _
- .DependsOn(RunCoreLibsTests)
- .DependsOn(RunRenderTests)
- .DependsOn(RunDesignerTests)
- .DependsOn(RunHtmlPreviewerTests)
- .DependsOn(RunLeakTests);
- Target Package => _ => _
- .DependsOn(RunTests)
- .DependsOn(CreateNugetPackages);
- Target CiAzureLinux => _ => _
- .DependsOn(RunTests);
- Target CiAzureOSX => _ => _
- .DependsOn(Package)
- .DependsOn(ZipFiles);
- Target CiAzureWindows => _ => _
- .DependsOn(Package)
- .DependsOn(ZipFiles);
- public static int Main() =>
- RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
- ? Execute<Build>(x => x.Package)
- : Execute<Build>(x => x.RunTests);
- }
- public static class ToolSettingsExtensions
- {
- public static T Apply<T>(this T settings, Configure<T> configurator)
- {
- return configurator != null ? configurator(settings) : settings;
- }
- }
|