Skip to content

Commit 86ad442

Browse files
committed
tmp: build avalonia.native package on win and local nuget functions, align version to 0.10.12 until merged to master
1 parent 9e7112e commit 86ad442

File tree

3 files changed

+147
-5
lines changed

3 files changed

+147
-5
lines changed

global.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"sdk": {
3-
"version": "6.0.100"
3+
"version": "6.0.100",
4+
"version3": "3.1.416"
45
},
56
"msbuild-sdks": {
67
"Microsoft.Build.Traversal": "1.0.43",

nukebuild/Build.cs

Lines changed: 127 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using static Nuke.Common.Tools.DotNet.DotNetTasks;
2525
using static Nuke.Common.Tools.Xunit.XunitTasks;
2626
using static Nuke.Common.Tools.VSWhere.VSWhereTasks;
27+
using System.IO.Compression;
2728

2829
/*
2930
Before editing this file, install support plugin for your IDE,
@@ -111,8 +112,20 @@ IReadOnlyCollection<Output> MsBuildCommon(
111112

112113
Target Clean => _ => _.Executes(() =>
113114
{
114-
Parameters.BuildDirs.ForEach(DeleteDirectory);
115-
Parameters.BuildDirs.ForEach(EnsureCleanDirectory);
115+
void safe(Action action)
116+
{
117+
try
118+
{
119+
action();
120+
}
121+
catch (Exception e) { Logger.Warn(e); }
122+
}
123+
//helps local dev builds
124+
void deldir(string dir) => safe(() => DeleteDirectory(dir));
125+
void cleandir(string dir) => safe(() => EnsureCleanDirectory(dir));
126+
127+
Parameters.BuildDirs.ForEach(deldir);
128+
Parameters.BuildDirs.ForEach(cleandir);
116129
EnsureCleanDirectory(Parameters.ArtifactsDir);
117130
EnsureCleanDirectory(Parameters.NugetIntermediateRoot);
118131
EnsureCleanDirectory(Parameters.NugetRoot);
@@ -155,6 +168,7 @@ bool IsDotnetCoreOnlyBuild()
155168

156169
Target Compile => _ => _
157170
.DependsOn(Clean, CompileNative)
171+
.DependsOn(DownloadAvaloniaNativeLib)
158172
.DependsOn(CompileHtmlPreviewer)
159173
.Executes(async () =>
160174
{
@@ -289,7 +303,7 @@ void RunCoreTest(string projectName)
289303
.Executes(() =>
290304
{
291305
RunCoreTest("Avalonia.Skia.RenderTests");
292-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
306+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && Nuke.Common.CI.TeamCity.TeamCity.Instance == null)// no direct2d tests on teamcity - they fail?
293307
RunCoreTest("Avalonia.Direct2D1.RenderTests");
294308
});
295309

@@ -334,6 +348,46 @@ void RunCoreTest(string projectName)
334348
Zip(data.ZipTargetControlCatalogNetCoreDir, pathToPublish);
335349
});
336350

351+
Target UpdateTeamCityVersion => _ => _
352+
.Executes(() =>
353+
{
354+
Nuke.Common.CI.TeamCity.TeamCity.Instance?.SetBuildNumber(Parameters.Version);
355+
});
356+
357+
Target DownloadAvaloniaNativeLib => _ => _
358+
.After(Clean)
359+
.OnlyWhenStatic(() => EnvironmentInfo.IsWin)
360+
.Executes(() =>
361+
{
362+
//download avalonia native osx binary, so we don't have to build it on osx
363+
//expected to be -> Build/Products/Release/libAvalonia.Native.OSX.dylib
364+
//Avalonia.Native.0.10.0-preview5.nupkg
365+
string nugetversion = "0.10.12";
366+
367+
var nugetdir = RootDirectory + "/Build/Products/Release/";
368+
//string nugeturl = "https://www.myget.org/F/avalonia-ci/api/v2/package/Avalonia.Native/";
369+
string nugeturl = "https://www.nuget.org/api/v2/package/Avalonia.Native/";
370+
371+
nugeturl += nugetversion;
372+
373+
//myget packages are expiring so i've made a copy here
374+
//google drive file share https://drive.google.com/open?id=1HK-XfBZRunGpxXcGUUEC-64H9T_n9cIJ
375+
//nugeturl = "https://drive.google.com/uc?id=1HK-XfBZRunGpxXcGUUEC-64H9T_n9cIJ&export=download";//Avalonia.Native.0.9.999-cibuild0005383-beta
376+
//nugeturl = "https://drive.google.com/uc?id=1fNKJ-KNsPtoi_MYVJZ0l4hbgHAkLMYZZ&export=download";//Avalonia.Native.0.9.2.16.nupkg custom build
377+
//nugeturl = "https://drive.google.com/uc?id=13ek3xvXA__GUgQFeAkemqE0lxiXiTr5s&export=download";//Avalonia.Native.0.10.0.8.nupkg custom build
378+
//nugeturl = "https://drive.google.com/uc?id=13n_Ql64s7eXncUQx_FagU4z5X-tBhtxC&export=download";//Avalonia.Native.0.10.0.16-rc1.nupkg custom build
379+
380+
string nugetname = $"Avalonia.Native.{nugetversion}";
381+
string nugetcontentsdir = Path.Combine(nugetdir, nugetname);
382+
string nugetpath = nugetcontentsdir + ".nupkg";
383+
Logger.Info($"Downloading {nugetname} from {nugeturl}");
384+
Nuke.Common.IO.HttpTasks.HttpDownloadFile(nugeturl, nugetpath);
385+
System.IO.Compression.ZipFile.ExtractToDirectory(nugetpath, nugetcontentsdir, true);
386+
387+
CopyFile(nugetcontentsdir + @"/runtimes/osx/native/libAvaloniaNative.dylib", nugetdir + "libAvalonia.Native.OSX." +
388+
"dylib", Nuke.Common.IO.FileExistsPolicy.Overwrite);
389+
});
390+
337391
Target CreateIntermediateNugetPackages => _ => _
338392
.DependsOn(Compile)
339393
.After(RunTests)
@@ -342,6 +396,7 @@ void RunCoreTest(string projectName)
342396
if (Parameters.IsRunningOnWindows && !IsDotnetCoreOnlyBuild())
343397

344398
MsBuildCommon(Parameters.MSBuildSolution, c => c
399+
.AddProperty("PackAvaloniaNative", "true")
345400
.AddTargets("Pack"));
346401
else
347402
DotNetPack(c => c
@@ -364,6 +419,75 @@ void RunCoreTest(string projectName)
364419
throw new Exception("Package merge failed");
365420
});
366421

422+
private static string GetNuGetNugetPackagesDir()
423+
{
424+
string env(string v) => Environment.GetEnvironmentVariable(v);
425+
return env("NUGET_PACKAGES") ?? Path.Combine(env("USERPROFILE") ?? env("HOME"), ".nuget/packages");
426+
}
427+
428+
Target PublishLocalNugetPackages => _ => _
429+
.Executes(() =>
430+
{
431+
string nugetPackagesDir = GetNuGetNugetPackagesDir();
432+
433+
//clean up often locked dlls from avalonia packages
434+
var preCleanUpDirs = new[]
435+
{
436+
"Avalonia/{0}/tools/", //Avalonia.Build.Tasks.dll
437+
"Avalonia/{0}/lib/",
438+
"Avalonia.Remote.Protocol/{0}/lib/" //Avalonia.Remote.Protocol.dll
439+
};
440+
foreach (var pattern in preCleanUpDirs)
441+
{
442+
var path = Path.Combine(nugetPackagesDir, string.Format(pattern, Parameters.Version));
443+
foreach (var filePath in Directory.GetFiles(path, "*.*", SearchOption.AllDirectories))
444+
{
445+
try
446+
{
447+
DeleteFile(filePath);
448+
}
449+
catch (Exception e)
450+
{
451+
Logger.Warn($"Will rename! Failed delete {e.Message} for {filePath}");
452+
if (!filePath.EndsWith(".old"))
453+
RenameFile(filePath, $"{filePath}.{Guid.NewGuid()}.old", Nuke.Common.IO.FileExistsPolicy.Overwrite);
454+
}
455+
}
456+
}
457+
458+
foreach (var package in Directory.EnumerateFiles(Parameters.NugetRoot))
459+
{
460+
var packName = Path.GetFileName(package);
461+
string packgageFolderName = packName.Replace($".{Parameters.Version}.nupkg", "");
462+
var nugetCaheFolder = Path.Combine(nugetPackagesDir, packgageFolderName, Parameters.Version);
463+
464+
//clean directory is not good, nuget will noticed and clean our files
465+
//EnsureCleanDirectory(nugetCaheFolder);
466+
EnsureExistingDirectory(nugetCaheFolder);
467+
468+
CopyFile(package, nugetCaheFolder + "/" + packName, Nuke.Common.IO.FileExistsPolicy.Skip);
469+
470+
Logger.Info($"Extracting to {nugetCaheFolder}, {package}");
471+
472+
ZipFile.ExtractToDirectory(package, nugetCaheFolder, true);
473+
}
474+
});
475+
476+
Target ClearLocalNugetPackages => _ => _
477+
.Executes(() =>
478+
{
479+
string nugetPackagesDir = GetNuGetNugetPackagesDir();
480+
481+
foreach (var package in Directory.EnumerateFiles(Parameters.NugetRoot))
482+
{
483+
var packName = Path.GetFileName(package);
484+
string packgageFolderName = packName.Replace($".{Parameters.Version}.nupkg", "");
485+
var nugetCaheFolder = Path.Combine(nugetPackagesDir, packgageFolderName, Parameters.Version);
486+
487+
EnsureCleanDirectory(nugetCaheFolder);
488+
}
489+
});
490+
367491
Target RunTests => _ => _
368492
.DependsOn(RunCoreLibsTests)
369493
.DependsOn(RunRenderTests)

nukebuild/BuildParameters.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ public partial class Build
2020
public string ForceNugetVersion { get; set; }
2121

2222
[Parameter("skip-previewer")]
23-
public bool SkipPreviewer { get; set; }
23+
public bool SkipPreviewer { get; set; } = IsLocalBuild;
24+
25+
[Parameter("nuget-buildtag")]
26+
public string NugetBuildTag { get; set; }
2427

2528
[Parameter("force-dotnetcorebuild")]
2629
public bool ForceDotNetCoreBuild { get; set; }
@@ -105,6 +108,20 @@ public BuildParameters(Build b)
105108
IsMyGetRelease = IsReleasable;
106109
IsNuGetRelease = IsMainRepo && IsReleasable && IsReleaseBranch;
107110

111+
if (!string.IsNullOrEmpty(b.NugetBuildTag))
112+
{
113+
var version = GetVersion();
114+
string versuffix = "";
115+
int si = version.IndexOf('-');
116+
if(si > 0)
117+
{
118+
versuffix = version.Substring(si);
119+
version = version.Replace(versuffix,"");
120+
}
121+
//let's force well known version meaning something to us
122+
b.ForceNugetVersion = $"{version}{(string.IsNullOrEmpty(b.NugetBuildTag) ? "" : $"{b.NugetBuildTag}")}{versuffix}";
123+
}
124+
108125
// VERSION
109126
Version = b.ForceNugetVersion ?? GetVersion();
110127

0 commit comments

Comments
 (0)