Skip to content

Commit

Permalink
Merge main into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Mar 19, 2021
2 parents 87fbd9c + 1a77955 commit cb963f2
Show file tree
Hide file tree
Showing 25 changed files with 729 additions and 152 deletions.
2 changes: 2 additions & 0 deletions binding/Binding/GRContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public static GRContext CreateMetal (GRMtlBackendContext backendContext, GRConte

public GRBackend Backend => SkiaApi.gr_direct_context_get_backend (Handle).FromNative ();

public bool IsAbandoned => SkiaApi.gr_direct_context_is_abandoned (Handle);

public void AbandonContext (bool releaseResources = false)
{
if (releaseResources)
Expand Down
16 changes: 16 additions & 0 deletions binding/Binding/SkiaApi.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,22 @@ private partial class Delegates {
(gr_direct_context_get_resource_cache_usage_delegate ??= GetSymbol<Delegates.gr_direct_context_get_resource_cache_usage> ("gr_direct_context_get_resource_cache_usage")).Invoke (context, maxResources, maxResourceBytes);
#endif

// bool gr_direct_context_is_abandoned(gr_direct_context_t* context)
#if !USE_DELEGATES
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs (UnmanagedType.I1)]
internal static extern bool gr_direct_context_is_abandoned (gr_direct_context_t context);
#else
private partial class Delegates {
[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
[return: MarshalAs (UnmanagedType.I1)]
internal delegate bool gr_direct_context_is_abandoned (gr_direct_context_t context);
}
private static Delegates.gr_direct_context_is_abandoned gr_direct_context_is_abandoned_delegate;
internal static bool gr_direct_context_is_abandoned (gr_direct_context_t context) =>
(gr_direct_context_is_abandoned_delegate ??= GetSymbol<Delegates.gr_direct_context_is_abandoned> ("gr_direct_context_is_abandoned")).Invoke (context);
#endif

// gr_direct_context_t* gr_direct_context_make_gl(const gr_glinterface_t* glInterface)
#if !USE_DELEGATES
[DllImport (SKIA, CallingConvention = CallingConvention.Cdecl)]
Expand Down
117 changes: 86 additions & 31 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#addin nuget:?package=Cake.FileHelpers&version=3.2.1
#addin nuget:?package=Cake.Json&version=4.0.0
#addin nuget:?package=SharpCompress&version=0.24.0
#addin nuget:?package=Mono.ApiTools.NuGetDiff&version=1.3.0&loaddependencies=true
#addin nuget:?package=Mono.ApiTools.NuGetDiff&version=1.3.2&loaddependencies=true
#addin nuget:?package=Xamarin.Nuget.Validator&version=1.1.1

#tool nuget:?package=mdoc&version=5.7.4.10
Expand All @@ -29,6 +29,7 @@ DirectoryPath ROOT_PATH = MakeAbsolute(Directory("."));

var SKIP_EXTERNALS = Argument ("skipexternals", "")
.ToLower ().Split (new [] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var SKIP_BUILD = Argument ("skipbuild", false);
var PACK_ALL_PLATFORMS = Argument ("packall", Argument ("PackAllPlatforms", false));
var BUILD_ALL_PLATFORMS = Argument ("buildall", Argument ("BuildAllPlatforms", false));
var PRINT_ALL_ENV_VARS = Argument ("printAllEnvVars", false);
Expand All @@ -42,7 +43,6 @@ var PLATFORM_SUPPORTS_VULKAN_TESTS = (IsRunningOnWindows () || IsRunningOnLinux
var SUPPORT_VULKAN_VAR = Argument ("supportVulkan", EnvironmentVariable ("SUPPORT_VULKAN") ?? PLATFORM_SUPPORTS_VULKAN_TESTS);
var SUPPORT_VULKAN = SUPPORT_VULKAN_VAR == "1" || SUPPORT_VULKAN_VAR.ToLower () == "true";

var NuGetToolPath = Context.Tools.Resolve ("nuget.exe");
var CakeToolPath = Context.Tools.Resolve ("Cake.exe");
var MDocPath = Context.Tools.Resolve ("mdoc.exe");

Expand All @@ -54,7 +54,7 @@ var BUILD_NUMBER = EnvironmentVariable ("BUILD_NUMBER") ?? "0";
var GIT_SHA = Argument ("gitSha", EnvironmentVariable ("GIT_SHA") ?? "");
var GIT_BRANCH_NAME = Argument ("gitBranch", EnvironmentVariable ("GIT_BRANCH_NAME") ?? "");

var PREVIEW_FEED_URL = "https://nugetized.blob.core.windows.net/skiasharp-eap/flatcontainer/{0}/{1}/{0}.{1}.nupkg"; // 0=id, 1=version
var PREVIEW_FEED_URL = "https://pkgs.dev.azure.com/xamarin/public/_packaging/SkiaSharp/nuget/v3/index.json";

var TRACKED_NUGETS = new Dictionary<string, Version> {
{ "SkiaSharp", new Version (1, 57, 0) },
Expand Down Expand Up @@ -108,6 +108,7 @@ Task ("externals")

Task ("libs")
.Description ("Build all managed assemblies.")
.WithCriteria(!SKIP_BUILD)
.IsDependentOn ("externals")
.Does (() =>
{
Expand Down Expand Up @@ -485,6 +486,11 @@ Task ("samples")
////////////////////////////////////////////////////////////////////////////////////////////////////

Task ("nuget")
.Description ("Pack all NuGets.")
.IsDependentOn ("nuget-normal")
.IsDependentOn ("nuget-special");

Task ("nuget-normal")
.Description ("Pack all NuGets (build all required dependencies).")
.IsDependentOn ("libs")
.Does (() =>
Expand Down Expand Up @@ -641,42 +647,91 @@ Task ("nuget")
Information ("Metadata validation passed for: {0}", nupkgFile.GetFilename ());
}
}
});

// special case for all the native assets
if (PACK_ALL_PLATFORMS)
{
EnsureDirectoryExists ($"{OUTPUT_SPECIAL_NUGETS_PATH}");
DeleteFiles ($"{OUTPUT_SPECIAL_NUGETS_PATH}/*.nupkg");
var specials = new Dictionary<string, string> {
{ "_NativeAssets", "native" },
{ "_NuGets", "nugets" },
};
foreach (var pair in specials) {
DeleteFiles ($"./output/{pair.Value}/*.nuspec");
Task ("nuget-special")
.Description ("Pack all special NuGets.")
.IsDependentOn ("nuget-normal")
.Does (() =>
{
EnsureDirectoryExists ($"{OUTPUT_SPECIAL_NUGETS_PATH}");
DeleteFiles ($"{OUTPUT_SPECIAL_NUGETS_PATH}/*.nupkg");
// get a list of all the version number variants
var versions = new List<string> ();
if (!string.IsNullOrEmpty (PREVIEW_LABEL) && PREVIEW_LABEL.StartsWith ("pr.")) {
var v = $"0.0.0-{PREVIEW_LABEL}";
if (!string.IsNullOrEmpty (BUILD_NUMBER))
v += $".{BUILD_NUMBER}";
versions.Add (v);
} else {
if (!string.IsNullOrEmpty (GIT_SHA)) {
var v = $"0.0.0-commit.{GIT_SHA}";
if (!string.IsNullOrEmpty (BUILD_NUMBER))
v += $".{BUILD_NUMBER}";
versions.Add (v);
}
if (!string.IsNullOrEmpty (GIT_BRANCH_NAME)) {
var v = $"0.0.0-branch.{GIT_BRANCH_NAME.Replace ("/", ".")}";
if (!string.IsNullOrEmpty (BUILD_NUMBER))
v += $".{BUILD_NUMBER}";
versions.Add (v);
}
}
var nuspec = $"./output/{pair.Value}/{pair.Key}.nuspec";
// get a list of all the nuspecs to pack
var specials = new Dictionary<string, string> ();
// update the version
var xdoc = XDocument.Load ($"./nuget/{pair.Key}.nuspec");
var metadata = xdoc.Root.Element ("metadata");
var version = metadata.Element ("version");
var nativePlatforms = GetDirectories ("./output/native/*")
.Select (d => d.GetDirectoryName ())
.ToArray ();
if (nativePlatforms.Length > 0) {
specials[$"_NativeAssets"] = $"native";
foreach (var platform in nativePlatforms) {
specials[$"_NativeAssets.{platform}"] = $"native/{platform}";
}
}
if (GetFiles ("./output/nugets/*.nupkg").Count > 0) {
specials[$"_NuGets"] = $"nugets";
}
if (!string.IsNullOrEmpty (PREVIEW_LABEL) && PREVIEW_LABEL.StartsWith ("pr.")) {
version.Value = "0.0.0-" + PREVIEW_LABEL;
xdoc.Save (nuspec);
PackageNuGet (nuspec, OUTPUT_SPECIAL_NUGETS_PATH, true);
} else {
version.Value = "0.0.0-commit." + GIT_SHA;
xdoc.Save (nuspec);
PackageNuGet (nuspec, OUTPUT_SPECIAL_NUGETS_PATH, true);
foreach (var pair in specials) {
var id = pair.Key;
var path = pair.Value;
var nuspec = $"./output/{path}/{id}.nuspec";
DeleteFiles ($"./output/{path}/*.nuspec");
version.Value = "0.0.0-branch." + GIT_BRANCH_NAME.Replace ("/", ".");
xdoc.Save (nuspec);
PackageNuGet (nuspec, OUTPUT_SPECIAL_NUGETS_PATH, true);
foreach (var packageVersion in versions) {
// update the version
var fn = id.StartsWith ("_NativeAssets.") ? "_NativeAssets" : id;
var xdoc = XDocument.Load ($"./nuget/{fn}.nuspec");
var metadata = xdoc.Root.Element ("metadata");
metadata.Element ("version").Value = packageVersion;
metadata.Element ("id").Value = id;
if (id == "_NativeAssets") {
// handle the root package
var dependencies = metadata.Element ("dependencies");
foreach (var platform in nativePlatforms) {
dependencies.Add (new XElement ("dependency",
new XAttribute ("id", $"_NativeAssets.{platform}"),
new XAttribute ("version", packageVersion)));
}
} else if (id.StartsWith ("_NativeAssets.")) {
// handle the dependencies
var platform = id.Substring (id.IndexOf (".") + 1);
var files = xdoc.Root.Element ("files");
files.Add (new XElement ("file",
new XAttribute ("src", $"*/**"),
new XAttribute ("target", $"tools/{platform}")));
}
DeleteFiles ($"./output/{pair.Value}/*.nuspec");
xdoc.Save (nuspec);
PackageNuGet (nuspec, OUTPUT_SPECIAL_NUGETS_PATH, true);
}
DeleteFiles ($"./output/{path}/*.nuspec");
}
});

Expand Down
11 changes: 2 additions & 9 deletions cake/UpdateDocs.cake
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,12 @@ void CopyChangelogs (DirectoryPath diffRoot, string id, string version)
}

Task ("docs-download-output")
.Does (() =>
.Does (async () =>
{
EnsureDirectoryExists ("./output");
CleanDirectories ("./output");
EnsureDirectoryExists ("./output/temp");
var url = GetDownloadUrl ("_nugets");
DownloadFile (url, "./output/temp/nugets.nupkg");
Unzip ("./output/temp/nugets.nupkg", "./output/temp");
MoveDirectory ("./output/temp/tools", OUTPUT_NUGETS_PATH);
DeleteDirectory("./output/temp", new DeleteDirectorySettings { Recursive = true, Force = true });
await DownloadPackageAsync ("_nugets", OUTPUT_NUGETS_PATH);
foreach (var id in TRACKED_NUGETS.Keys) {
var version = GetVersion (id);
Expand Down
89 changes: 56 additions & 33 deletions cake/UtilsManaged.cake
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ void PackageNuGet(FilePath nuspecPath, DirectoryPath outputPath, bool allowDefau
var settings = new NuGetPackSettings {
OutputDirectory = MakeAbsolute(outputPath),
BasePath = nuspecPath.GetDirectory(),
ToolPath = NuGetToolPath,
ToolPath = NUGET_EXE,
Properties = new Dictionary<string, string> {
// NU5048: The 'PackageIconUrl'/'iconUrl' element is deprecated. Consider using the 'PackageIcon'/'icon' element instead.
// NU5105: The package version 'xxx' uses SemVer 2.0.0 or components of SemVer 1.0.0 that are not supported on legacy clients.
Expand All @@ -18,25 +18,6 @@ void PackageNuGet(FilePath nuspecPath, DirectoryPath outputPath, bool allowDefau
NuGetPack(nuspecPath, settings);
}

void RunNuGetRestorePackagesConfig(FilePath sln)
{
var dir = sln.GetDirectory();

var nugetSources = new [] { OUTPUT_NUGETS_PATH.FullPath, "https://api.nuget.org/v3/index.json" };

EnsureDirectoryExists(OUTPUT_NUGETS_PATH);

var settings = new NuGetRestoreSettings {
ToolPath = NuGetToolPath,
Source = nugetSources,
NoCache = true,
PackagesDirectory = dir.Combine("packages"),
};

foreach (var config in GetFiles(dir + "/**/packages.config"))
NuGetRestore(config, settings);
}

void RunTests(FilePath testAssembly, bool is32)
{
var dir = testAssembly.GetDirectory();
Expand Down Expand Up @@ -104,21 +85,21 @@ void RunNetCorePublish(FilePath testProject, DirectoryPath output)
void RunCodeCoverage(string testResultsGlob, DirectoryPath output)
{
try {
RunProcess ("reportgenerator", new ProcessSettings {
RunProcess("reportgenerator", new ProcessSettings {
Arguments =
$"-reports:{testResultsGlob} " +
$"-targetdir:{output} " +
$"-reporttypes:HtmlInline_AzurePipelines;Cobertura " +
$"-assemblyfilters:-*.Tests"
});
} catch (Exception ex) {
Error ("Make sure to install the 'dotnet-reportgenerator-globaltool' .NET Core global tool.");
Error (ex);
Error("Make sure to install the 'dotnet-reportgenerator-globaltool' .NET Core global tool.");
Error(ex);
throw;
}
var xml = $"{output}/Cobertura.xml";
var root = FindRegexMatchGroupsInFile (xml, @"<source>(.*)<\/source>", 0)[1].Value;
ReplaceTextInFiles (xml, root, "");
var root = FindRegexMatchGroupsInFile(xml, @"<source>(.*)<\/source>", 0)[1].Value;
ReplaceTextInFiles(xml, root, "");
}

IEnumerable<(string Name, string Value)> CreateTraitsDictionary(string args)
Expand Down Expand Up @@ -260,17 +241,59 @@ async Task<NuGetDiff> CreateNuGetDiffAsync()
}
}

string GetDownloadUrl(string id)
async Task DownloadPackageAsync(string id, DirectoryPath outputDirectory)
{
var version = "0.0.0-";
if (!string.IsNullOrEmpty (PREVIEW_LABEL) && PREVIEW_LABEL.StartsWith ("pr."))
version += PREVIEW_LABEL.ToLower ();
else if (!string.IsNullOrEmpty (GIT_SHA))
version += "commit." + GIT_SHA.ToLower ();
else if (!string.IsNullOrEmpty (GIT_BRANCH_NAME))
version += "branch." + GIT_BRANCH_NAME.Replace ("/", ".").ToLower ();
if (!string.IsNullOrEmpty(PREVIEW_LABEL) && PREVIEW_LABEL.StartsWith("pr."))
version += PREVIEW_LABEL.ToLower();
else if (!string.IsNullOrEmpty(GIT_SHA))
version += "commit." + GIT_SHA.ToLower();
else if (!string.IsNullOrEmpty(GIT_BRANCH_NAME))
version += "branch." + GIT_BRANCH_NAME.Replace("/", ".").ToLower();
else
version += "branch.main";
version += ".*";

var filter = new NuGetVersions.Filter {
IncludePrerelease = true,
SourceUrl = PREVIEW_FEED_URL,
VersionRange = VersionRange.Parse(version),
};

var latestVersion = await NuGetVersions.GetLatestAsync(id, filter);

return string.Format (PREVIEW_FEED_URL, id.ToLower(), version);
var comparer = new NuGetDiff(PREVIEW_FEED_URL);
comparer.PackageCache = PACKAGE_CACHE_PATH.FullPath;

await Download(id, latestVersion);

async Task Download(string currentId, NuGetVersion currentVersion)
{
currentId = currentId.ToLower();

Information($"Downloading: {currentId}...");

var root = await comparer.ExtractCachedPackageAsync(currentId, currentVersion);
var toolsDir = $"{root}/tools/";
if (DirectoryExists(toolsDir)) {
var allFiles = GetFiles(toolsDir + "**/*");
foreach (var file in allFiles) {
var relative = MakeAbsolute(Directory(toolsDir)).GetRelativePath(file);
var dir = $"{outputDirectory}/{relative.GetDirectory()}";
EnsureDirectoryExists(dir);
CopyFileToDirectory(file, dir);
}
}

var nuspec = $"{root}/{currentId}.nuspec";
var xdoc = XDocument.Load(nuspec);
var xmlns = xdoc.Root.Name.Namespace;
var dependencies = xdoc.Root.Descendants(xmlns + "dependency").ToArray();

foreach (var dep in dependencies) {
var depId = dep.Attribute("id").Value;
var depVersion = dep.Attribute("version").Value;
await Download(depId, NuGetVersion.Parse(depVersion));
}
}
}
12 changes: 3 additions & 9 deletions cake/externals.cake
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ foreach (var cake in GetFiles("native/*/build.cake"))

var task = Task($"externals-{native}")
.WithCriteria(should)
.WithCriteria(!SKIP_BUILD)
.Does(() => RunCake(localCake, "Default"));

externalsTask.IsDependentOn(task);
Expand All @@ -25,19 +26,12 @@ Task("externals-osx")
////////////////////////////////////////////////////////////////////////////////////////////////////

Task("externals-download")
.Does(() =>
.Does(async () =>
{
EnsureDirectoryExists ("./output");
CleanDirectories ("./output");
EnsureDirectoryExists ("./output/temp");
var url = GetDownloadUrl ("_nativeassets");
DownloadFile (url, "./output/temp/nativeassets.nupkg");
Unzip ("./output/temp/nativeassets.nupkg", "./output/temp");
MoveDirectory ("./output/temp/tools", "./output/native");
DeleteDirectory("./output/temp", new DeleteDirectorySettings { Recursive = true, Force = true });
await DownloadPackageAsync("_nativeassets", "./output/native");
});

////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit cb963f2

Please sign in to comment.