Skip to content

Commit

Permalink
tmp: build avalonia.native package on win and local nuget functions, …
Browse files Browse the repository at this point in the history
…align version to 0.10.17 until merged to master
  • Loading branch information
donandren committed Aug 5, 2022
1 parent ef10860 commit eb746f9
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 4 deletions.
131 changes: 128 additions & 3 deletions nukebuild/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -111,8 +112,20 @@ IReadOnlyCollection<Output> 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);
Expand All @@ -130,6 +143,7 @@ IReadOnlyCollection<Output> 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"));
Expand All @@ -155,6 +169,7 @@ bool IsDotnetCoreOnlyBuild()

Target Compile => _ => _
.DependsOn(Clean, CompileNative)
.DependsOn(DownloadAvaloniaNativeLib)
.DependsOn(CompileHtmlPreviewer)
.Executes(async () =>
{
Expand Down Expand Up @@ -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");
});

Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
19 changes: 18 additions & 1 deletion nukebuild/BuildParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit eb746f9

Please sign in to comment.