Skip to content

Commit

Permalink
Validate the generated interop files
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Apr 13, 2024
1 parent 63141bf commit f5cd4bd
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 16 deletions.
7 changes: 0 additions & 7 deletions scripts/azure-templates-bootstrapper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,6 @@ jobs:
- pwsh: Remove-Item "$env:AGENT_TOOLSDIRECTORY/dotnet" -Recurse -Force -ErrorAction SilentlyContinue
displayName: Cleanup existing versions of .NET
condition: and(succeeded(), eq(variables['DOWNLOAD_EXTERNALS'], ''))
- task: UseDotNet@2
condition: and(succeeded(), eq(variables['DOWNLOAD_EXTERNALS'], ''))
inputs:
packageType: 'sdk'
version: 3.1.x
retryCountOnTaskFailure: 3
displayName: Install .NET 3.1.x
- task: UseDotNet@2
condition: and(succeeded(), eq(variables['DOWNLOAD_EXTERNALS'], ''))
inputs:
Expand Down
9 changes: 9 additions & 0 deletions scripts/azure-templates-stages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ stages:
${{ if eq(parameters.buildPipelineType, 'both') }}:
dependsOn: native
jobs:
- template: /scripts/azure-templates-bootstrapper.yml@self # Validate Interop
parameters:
name: managed_interop_windows
displayName: Validate Interop
buildPipelineType: ${{ parameters.buildPipelineType }}
buildAgent: ${{ parameters.buildAgentWindows}}
target: externals-interop
additionalArgs: --skipExternals="all" --validateInterop=true
installAndroidSdk: false
- template: /scripts/azure-templates-bootstrapper.yml@self # Build Managed (Windows)
parameters:
name: managed_windows
Expand Down
24 changes: 24 additions & 0 deletions scripts/cake/externals.cake
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@ Task("externals-download")
await DownloadPackageAsync("_nativeassets", "./output/native");
});

////////////////////////////////////////////////////////////////////////////////////////////////////
// EXTERNALS INTEROP - re-generate the interop files
////////////////////////////////////////////////////////////////////////////////////////////////////

Task("externals-interop")
.IsDependentOn("git-sync-deps")
.Does(() =>
{
RunProcess("pwsh", "./utils/generate.ps1");
RunProcess("git", "diff --name-only binding/*/*.generated.cs", out var files);
if (files.Any()) {
Information("Generated files have changed:");
foreach (var file in files) {
Information($" - {file}");
}
if (Argument("validateInterop", false)) {
throw new Exception("Generated interop files are out of date. Please run `pwsh ./utils/generate.ps1`.");
}
}
});

////////////////////////////////////////////////////////////////////////////////////////////////////
// CLEAN - remove all the build artefacts
////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions utils/SkiaSharpGenerator/Generate/GenerateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public GenerateCommand()

protected override OptionSet OnCreateOptions() => new OptionSet
{
{ "s|skia=", "The root of the skia source", v => SourceRoot = v },
{ "r|root=", "The root of the source", v => SourceRoot = v },
{ "c|config=", "The config file path", v => ConfigPath = v },
{ "o|output=", "The output path", v => OutputPath = v },
};
Expand All @@ -31,7 +31,7 @@ protected override bool OnValidateArguments(IEnumerable<string> extras)

if (string.IsNullOrEmpty(SourceRoot))
{
Program.Log.LogError($"{Program.Name}: Path to the skia source was not provided: `--skia=<path-to-skia>`.");
Program.Log.LogError($"{Program.Name}: Path to the skia source was not provided: `--root=<path-to-skia-or-root>`.");
hasError = true;
}
else if (!Directory.Exists(SourceRoot))
Expand Down
2 changes: 1 addition & 1 deletion utils/SkiaSharpGenerator/SkiaSharpGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<RollForward>LatestMajor</RollForward>
</PropertyGroup>
Expand Down
30 changes: 25 additions & 5 deletions utils/generate.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
dotnet run --project=utils/SkiaSharpGenerator/SkiaSharpGenerator.csproj -- generate --config binding/libSkiaSharp.json --skia externals/skia --output binding/SkiaSharp/SkiaApi.generated.cs
dotnet run --project=utils/SkiaSharpGenerator/SkiaSharpGenerator.csproj -- generate --config binding/libSkiaSharp.Skottie.json --skia externals/skia --output binding/SkiaSharp.Skottie/SkottieApi.generated.cs
dotnet run --project=utils/SkiaSharpGenerator/SkiaSharpGenerator.csproj -- generate --config binding/libSkiaSharp.SceneGraph.json --skia externals/skia --output binding/SkiaSharp.SceneGraph/SceneGraphApi.generated.cs
dotnet run --project=utils/SkiaSharpGenerator/SkiaSharpGenerator.csproj -- generate --config binding/libSkiaSharp.Resources.json --skia externals/skia --output binding/SkiaSharp.Resources/ResourcesApi.generated.cs
dotnet run --project=utils/SkiaSharpGenerator/SkiaSharpGenerator.csproj -- generate --config binding/libHarfBuzzSharp.json --skia externals/skia/third_party/externals/harfbuzz --output binding/HarfBuzzSharp/HarfBuzzApi.generated.cs
$ErrorActionPreference = "Stop"

$projects = @(
@{ Json="libSkiaSharp.json"; Root="externals/skia"; Output="SkiaSharp/SkiaApi.generated.cs" },
@{ Json="libSkiaSharp.Skottie.json"; Root="externals/skia"; Output="SkiaSharp.Skottie/SkottieApi.generated.cs" },
@{ Json="libSkiaSharp.SceneGraph.json"; Root="externals/skia"; Output="SkiaSharp.SceneGraph/SceneGraphApi.generated.cs" },
@{ Json="libSkiaSharp.Resources.json"; Root="externals/skia"; Output="SkiaSharp.Resources/ResourcesApi.generated.cs" },
@{ Json="libHarfBuzzSharp.json"; Root="externals/skia/third_party/externals/harfbuzz"; Output="HarfBuzzSharp/HarfBuzzApi.generated.cs" }
)

New-Item -ItemType Directory -Force -Path "output/generated/" | Out-Null

foreach ($proj in $projects) {
$json = $proj.Json;
$output = $proj.Output;
$root = $proj.Root;
$filename = Split-Path $output -Leaf

dotnet run --project=utils/SkiaSharpGenerator/SkiaSharpGenerator.csproj -- generate --config binding/$json --root $root --output binding/$output
if (!$?) {
exit $LASTEXITCODE
}

Copy-Item -Path binding/$output -Destination output/generated/$filename -Force
}

0 comments on commit f5cd4bd

Please sign in to comment.