From abf9de57d9176e73a97e82a6402cfbd0e00127c5 Mon Sep 17 00:00:00 2001 From: Matthew Leibowitz Date: Thu, 22 Feb 2018 19:56:48 +0200 Subject: [PATCH] Lets build a preview nuget when we build nugets --- .gitignore | 1 + build.cake | 59 ++++++++++++------- cake/UtilsMSBuild.cake | 23 +++++--- cake/UtilsManaged.cake | 9 ++- ...z.nuspec => SkiaSharp.HarfBuzz.All.nuspec} | 0 5 files changed, 56 insertions(+), 36 deletions(-) rename nuget/{SkiaSharp.HarfBuzz.nuspec => SkiaSharp.HarfBuzz.All.nuspec} (100%) diff --git a/.gitignore b/.gitignore index 76888c7ae..f6406cb40 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ output/ tools/ *.VC.db **/Resources/Resource.designer.cs +nuget/*.prerelease.nuspec # User-specific files *.suo diff --git a/build.cake b/build.cake index 4921809ef..9478f9902 100644 --- a/build.cake +++ b/build.cake @@ -214,7 +214,7 @@ Task ("tests") .IsDependentOn ("nuget") .Does (() => { - ClearSkiaSharpNuGetCache (); + ClearSkiaSharpNuGetCache (VERSION_PACKAGES.Keys.ToArray ()); RunNuGetRestore ("./tests/SkiaSharp.Desktop.Tests/SkiaSharp.Desktop.Tests.sln"); @@ -264,10 +264,10 @@ Task ("samples") .Does (() => { // clear the NuGets so we can use the build output - ClearSkiaSharpNuGetCache (); + ClearSkiaSharpNuGetCache (VERSION_PACKAGES.Keys.ToArray ()); // create the samples archive - CreateSamplesZip ("./samples/", "./output/"); + CreateSamplesZip ("./samples/", "./output/", VERSION_PACKAGES); var isLinux = IsRunningOnLinux (); var isMac = IsRunningOnMac (); @@ -499,37 +499,37 @@ Task ("update-docs") //////////////////////////////////////////////////////////////////////////////////////////////////// Task ("nuget") + .IsDependentOn ("set-versions") .IsDependentOn ("libs") .IsDependentOn ("docs") .Does (() => { - // we can only build the combined package on CI + var windows = GetFiles ("./nuget/*.Windows.*nuspec").Select (f => f.FullPath); + var mac = GetFiles ("./nuget/*.Mac.*nuspec").Select (f => f.FullPath); + var linux = GetFiles ("./nuget/*.Linux.*nuspec").Select (f => f.FullPath); + var all = GetFiles ("./nuget/*.All.*nuspec").Select (f => f.FullPath); + var finals = GetFiles ("./nuget/*.nuspec").Select (f => f.FullPath); + finals = finals.Except (windows).Except (mac).Except (linux).Except (all); + + var toPack = all; if (IS_ON_FINAL_CI) { - PackageNuGet ("./nuget/SkiaSharp.nuspec", "./output/"); - PackageNuGet ("./nuget/HarfBuzzSharp.nuspec", "./output/"); - PackageNuGet ("./nuget/SkiaSharp.Views.nuspec", "./output/"); - PackageNuGet ("./nuget/SkiaSharp.Views.Forms.nuspec", "./output/"); + // we can only build the combined package on CI + toPack = toPack.Union (finals); } else { if (IsRunningOnWindows ()) { - PackageNuGet ("./nuget/SkiaSharp.Windows.nuspec", "./output/"); - PackageNuGet ("./nuget/HarfBuzzSharp.Windows.nuspec", "./output/"); - PackageNuGet ("./nuget/SkiaSharp.Views.Windows.nuspec", "./output/"); - PackageNuGet ("./nuget/SkiaSharp.Views.Forms.Windows.nuspec", "./output/"); + toPack = toPack.Union (windows); } if (IsRunningOnMac ()) { - PackageNuGet ("./nuget/SkiaSharp.Mac.nuspec", "./output/"); - PackageNuGet ("./nuget/HarfBuzzSharp.Mac.nuspec", "./output/"); - PackageNuGet ("./nuget/SkiaSharp.Views.Mac.nuspec", "./output/"); - PackageNuGet ("./nuget/SkiaSharp.Views.Forms.Mac.nuspec", "./output/"); + toPack = toPack.Union (mac); } if (IsRunningOnLinux ()) { - PackageNuGet ("./nuget/SkiaSharp.Linux.nuspec", "./output/"); - PackageNuGet ("./nuget/HarfBuzzSharp.Linux.nuspec", "./output/"); - PackageNuGet ("./nuget/SkiaSharp.Views.Linux.nuspec", "./output/"); + toPack = toPack.Union (linux); } } - // HarfBuzz is a PCL - PackageNuGet ("./nuget/SkiaSharp.HarfBuzz.nuspec", "./output/"); + + foreach (var nuspec in toPack) { + PackageNuGet (nuspec, "./output/"); + } }); //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -547,6 +547,19 @@ Task ("set-versions") sha = "{GIT_SHA}"; } + // set the build number for the preview nugets + var buildNumber = EnvironmentVariable ("BUILD_NUMBER") ?? string.Empty; + if (string.IsNullOrEmpty (buildNumber)) { + buildNumber = "0"; + } + + // make a copy of the nuspecs to have a preview release + DeleteFiles ("./nuget/*.prerelease.nuspec"); + foreach (var file in GetFiles ("./nuget/*.nuspec")) { + var newFile = file.GetDirectory ().CombineWithFilePath (file.GetFilenameWithoutExtension () + ".prerelease.nuspec"); + CopyFile (file, newFile); + } + var files = new List (); var add = new Action (glob => { files.AddRange (GetFiles (glob).Select (p => MakeAbsolute (p).ToString ())); @@ -556,7 +569,7 @@ Task ("set-versions") add ("./tests/**/*.csproj"); // update foreach (var file in files) { - UpdateSkiaSharpVersion (file, VERSION_PACKAGES); + UpdateSkiaSharpVersion (file, VERSION_PACKAGES, "-build-" + buildNumber); } // assembly infos @@ -619,6 +632,8 @@ Task ("clean-managed").Does (() => CleanDirectories ("./externals/Windows.Foundation.UniversalApiContract/bin"); CleanDirectories ("./externals/Windows.Foundation.UniversalApiContract/obj"); + DeleteFiles ("./nuget/*.prerelease.nuspec"); + if (DirectoryExists ("./output")) DeleteDirectory ("./output", true); }); diff --git a/cake/UtilsMSBuild.cake b/cake/UtilsMSBuild.cake index ac1a4b74a..9b51f3b4b 100644 --- a/cake/UtilsMSBuild.cake +++ b/cake/UtilsMSBuild.cake @@ -1,13 +1,14 @@ var MSBuildNS = (XNamespace) "http://schemas.microsoft.com/developer/msbuild/2003"; -var UpdateSkiaSharpVersion = new Action> ((path, versions) => { +var UpdateSkiaSharpVersion = new Action, string> ((path, versions, previewSuffix) => { path = MakeAbsolute (path); var fn = path.GetFilename ().ToString (); var ext = path.GetExtension (); if (ext == ".nuspec") { // NuGet + var suffix = fn.EndsWith (".prerelease.nuspec") ? previewSuffix : ""; var modified = false; var xdoc = XDocument.Load (path.ToString ()); // @@ -24,10 +25,12 @@ var UpdateSkiaSharpVersion = new Action> (( var oldVersion = package.Attribute ("version"); if (id != null && oldVersion != null) { string version; - if (versions.TryGetValue (id.Value, out version) && - version != oldVersion.Value) { - oldVersion.Value = version; - modified = true; + if (versions.TryGetValue (id.Value, out version)) { + version += suffix; + if (version != oldVersion.Value) { + oldVersion.Value = version; + modified = true; + } } } } @@ -36,10 +39,12 @@ var UpdateSkiaSharpVersion = new Action> (( var xVersion = metadata.Elements ("version").FirstOrDefault (); if (xId != null && xVersion != null) { string version; - if (versions.TryGetValue (xId.Value, out version) && - version != xVersion.Value) { - xVersion.Value = version; - modified = true; + if (versions.TryGetValue (xId.Value, out version)) { + version += suffix; + if (version != xVersion.Value) { + xVersion.Value = version; + modified = true; + } } } if (modified) { diff --git a/cake/UtilsManaged.cake b/cake/UtilsManaged.cake index ea4b780e6..c1130fea9 100644 --- a/cake/UtilsManaged.cake +++ b/cake/UtilsManaged.cake @@ -171,7 +171,7 @@ var RunGenApi = new Action ((input, output) => "[System.ComponentModel.EditorBrowsableAttribute((System.ComponentModel.EditorBrowsableState)1)]"); }); -var ClearSkiaSharpNuGetCache = new Action (() => { +var ClearSkiaSharpNuGetCache = new Action ((packages) => { // first we need to add our new nuget to the cache so we can restore // we first need to delete the old stuff var packagesDir = EnvironmentVariable ("NUGET_PACKAGES"); @@ -180,7 +180,6 @@ var ClearSkiaSharpNuGetCache = new Action (() => { packagesDir = ((DirectoryPath) home).Combine (".nuget").Combine ("packages").ToString(); } var installedNuGet = packagesDir + "/*"; - var packages = VERSION_PACKAGES.Keys; var dirs = GetDirectories (installedNuGet); foreach (var pkg in packages) { Information ("Looking for an installed version of {0} in {1}...", pkg, installedNuGet); @@ -208,7 +207,7 @@ var DecompressArchive = new Action ((archive, outputDir } }); -var CreateSamplesZip = new Action ((samplesDirPath, outputDirPath) => { +var CreateSamplesZip = new Action> ((samplesDirPath, outputDirPath, packageVersions) => { var workingDir = outputDirPath.Combine ("samples"); // copy the current samples directory @@ -306,13 +305,13 @@ var CreateSamplesZip = new Action ((samplesDirPath // we assume "Desired.Package.Id..csproj" var binding = System.IO.Path.GetFileNameWithoutExtension (System.IO.Path.GetFileNameWithoutExtension (absInclude)); // check to see if we have a specific version - binding = VERSION_PACKAGES.Keys.FirstOrDefault (p => p.Equals (binding, StringComparison.OrdinalIgnoreCase)); + binding = packageVersions.Keys.FirstOrDefault (p => p.Equals (binding, StringComparison.OrdinalIgnoreCase)); if (!string.IsNullOrWhiteSpace (binding)) { // add a var name = projItem.Name.Namespace + "PackageReference"; projItem.AddAfterSelf (new XElement (name, new object[] { new XAttribute("Include", binding), - new XAttribute("Version", VERSION_PACKAGES[binding]), + new XAttribute("Version", packageVersions[binding]), })); } } diff --git a/nuget/SkiaSharp.HarfBuzz.nuspec b/nuget/SkiaSharp.HarfBuzz.All.nuspec similarity index 100% rename from nuget/SkiaSharp.HarfBuzz.nuspec rename to nuget/SkiaSharp.HarfBuzz.All.nuspec