Harden CultLib Unity package build
This commit is contained in:
parent
4df2c2a42b
commit
98d15eaf65
2 changed files with 104 additions and 25 deletions
|
|
@ -15,22 +15,7 @@ $outputRoot = if ([System.IO.Path]::IsPathRooted($OutputDirectory)) {
|
|||
Join-Path $repoRoot $OutputDirectory
|
||||
}
|
||||
$pluginRoot = Join-Path $outputRoot "Runtime\Plugins"
|
||||
|
||||
if (Test-Path -LiteralPath $publishRoot) {
|
||||
Remove-Item -LiteralPath $publishRoot -Recurse -Force
|
||||
}
|
||||
if (Test-Path -LiteralPath $outputRoot) {
|
||||
Remove-Item -LiteralPath $outputRoot -Recurse -Force
|
||||
}
|
||||
|
||||
dotnet publish $projectPath -c $Configuration -o $publishRoot
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "CultLib publish failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $pluginRoot | Out-Null
|
||||
Copy-Item -LiteralPath (Join-Path $templateRoot "package.json") -Destination $outputRoot
|
||||
Copy-Item -LiteralPath (Join-Path $templateRoot "README.md") -Destination $outputRoot
|
||||
$manifest = Get-Content -LiteralPath (Join-Path $templateRoot "package.json") -Raw | ConvertFrom-Json
|
||||
|
||||
$expectedAssemblies = @(
|
||||
"ConcurrentCollections.dll",
|
||||
|
|
@ -57,6 +42,68 @@ $expectedAssemblies = @(
|
|||
"System.Text.Json.dll",
|
||||
"System.Threading.Channels.dll"
|
||||
)
|
||||
$ownedAssemblies = @(
|
||||
"GameCult.Caching.dll",
|
||||
"GameCult.Caching.MessagePack.dll",
|
||||
"GameCult.Logging.dll",
|
||||
"GameCult.Mesh.dll",
|
||||
"GameCult.Networking.dll"
|
||||
)
|
||||
$expectedPdbs = $ownedAssemblies | ForEach-Object { [System.IO.Path]::ChangeExtension($_, ".pdb") }
|
||||
|
||||
function Assert-SameNames([string[]] $Actual, [string[]] $Expected, [string] $Description) {
|
||||
$difference = Compare-Object ($Expected | Sort-Object) ($Actual | Sort-Object)
|
||||
if ($difference) {
|
||||
throw "$Description differs from the expected package contract:`n$($difference | Out-String)"
|
||||
}
|
||||
}
|
||||
|
||||
function Assert-Meta([string] $Path) {
|
||||
if (-not (Test-Path -LiteralPath "$Path.meta")) {
|
||||
throw "Unity metadata is missing for: $Path"
|
||||
}
|
||||
}
|
||||
|
||||
if ($manifest.name -ne "org.gamecult.cultlib" -or $manifest.version -notmatch '^\d+\.\d+\.\d+$') {
|
||||
throw "CultLib package manifest has an invalid name or semantic version."
|
||||
}
|
||||
|
||||
$templatePluginRoot = Join-Path $templateRoot "Runtime\Plugins"
|
||||
Assert-SameNames `
|
||||
(Get-ChildItem -LiteralPath $templatePluginRoot -Filter "*.dll" | Select-Object -ExpandProperty Name) `
|
||||
$expectedAssemblies `
|
||||
"Tracked Unity DLL set"
|
||||
Assert-SameNames `
|
||||
(Get-ChildItem -LiteralPath $templatePluginRoot -Filter "*.pdb" | Select-Object -ExpandProperty Name) `
|
||||
$expectedPdbs `
|
||||
"Tracked Unity PDB set"
|
||||
|
||||
@(
|
||||
(Join-Path $templateRoot "package.json"),
|
||||
(Join-Path $templateRoot "README.md"),
|
||||
(Join-Path $templateRoot "Runtime"),
|
||||
(Join-Path $templateRoot "Runtime\GameCult.CultLib.asmdef"),
|
||||
$templatePluginRoot
|
||||
) + ($expectedAssemblies | ForEach-Object { Join-Path $templatePluginRoot $_ }) +
|
||||
($expectedPdbs | ForEach-Object { Join-Path $templatePluginRoot $_ }) |
|
||||
ForEach-Object { Assert-Meta $_ }
|
||||
|
||||
$asmdef = Get-Content -LiteralPath (Join-Path $templateRoot "Runtime\GameCult.CultLib.asmdef") -Raw | ConvertFrom-Json
|
||||
Assert-SameNames $asmdef.precompiledReferences $expectedAssemblies "asmdef precompiled reference set"
|
||||
|
||||
if (Test-Path -LiteralPath $publishRoot) {
|
||||
Remove-Item -LiteralPath $publishRoot -Recurse -Force
|
||||
}
|
||||
if (Test-Path -LiteralPath $outputRoot) {
|
||||
Remove-Item -LiteralPath $outputRoot -Recurse -Force
|
||||
}
|
||||
|
||||
dotnet publish $projectPath -c $Configuration -o $publishRoot --disable-build-servers `
|
||||
-p:UseSharedCompilation=false -m:1 -p:Version=$($manifest.version)
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "CultLib publish failed with exit code $LASTEXITCODE"
|
||||
}
|
||||
|
||||
$publishedByName = @{}
|
||||
foreach ($assembly in Get-ChildItem -LiteralPath $publishRoot -Filter "*.dll") {
|
||||
$publishedByName[$assembly.Name] = $assembly
|
||||
|
|
@ -67,18 +114,50 @@ foreach ($assemblyName in $expectedAssemblies) {
|
|||
}
|
||||
}
|
||||
|
||||
Copy-Item -LiteralPath (Join-Path $templateRoot "Runtime\GameCult.CultLib.asmdef") `
|
||||
-Destination (Join-Path $outputRoot "Runtime")
|
||||
Copy-Item -LiteralPath $templateRoot -Destination $outputRoot -Recurse
|
||||
foreach ($assemblyName in $expectedAssemblies) {
|
||||
$assembly = $publishedByName[$assemblyName]
|
||||
Copy-Item -LiteralPath $assembly.FullName -Destination $pluginRoot
|
||||
$pdb = [System.IO.Path]::ChangeExtension($assembly.FullName, ".pdb")
|
||||
if (Test-Path -LiteralPath $pdb) {
|
||||
Copy-Item -LiteralPath $pdb -Destination $pluginRoot
|
||||
Copy-Item -LiteralPath $publishedByName[$assemblyName].FullName -Destination $pluginRoot -Force
|
||||
}
|
||||
foreach ($pdbName in $expectedPdbs) {
|
||||
$pdbPath = Join-Path $publishRoot $pdbName
|
||||
if (-not (Test-Path -LiteralPath $pdbPath)) {
|
||||
throw "CultLib Unity package is missing expected symbols: $pdbName"
|
||||
}
|
||||
Copy-Item -LiteralPath $pdbPath -Destination $pluginRoot -Force
|
||||
}
|
||||
|
||||
Assert-SameNames `
|
||||
(Get-ChildItem -LiteralPath $pluginRoot -Filter "*.dll" | Select-Object -ExpandProperty Name) `
|
||||
$expectedAssemblies `
|
||||
"Staged Unity DLL set"
|
||||
Assert-SameNames `
|
||||
(Get-ChildItem -LiteralPath $pluginRoot -Filter "*.pdb" | Select-Object -ExpandProperty Name) `
|
||||
$expectedPdbs `
|
||||
"Staged Unity PDB set"
|
||||
|
||||
$expectedFileVersion = "$($manifest.version).0"
|
||||
foreach ($assemblyName in $ownedAssemblies) {
|
||||
$assemblyPath = Join-Path $pluginRoot $assemblyName
|
||||
$fileVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($assemblyPath).FileVersion
|
||||
if ($fileVersion -ne $expectedFileVersion) {
|
||||
throw "$assemblyName has file version $fileVersion; expected $expectedFileVersion."
|
||||
}
|
||||
$freshHash = (Get-FileHash -LiteralPath (Join-Path $publishRoot $assemblyName) -Algorithm SHA256).Hash
|
||||
$stagedHash = (Get-FileHash -LiteralPath $assemblyPath -Algorithm SHA256).Hash
|
||||
if ($freshHash -ne $stagedHash) {
|
||||
throw "$assemblyName differs between the fresh publish and staged package."
|
||||
}
|
||||
}
|
||||
|
||||
$manifest = Get-Content -LiteralPath (Join-Path $outputRoot "package.json") -Raw | ConvertFrom-Json
|
||||
$resolverAssemblyPath = Join-Path $pluginRoot "GameCult.Caching.MessagePack.dll"
|
||||
$resolverAssemblyMetadata = [System.Text.Encoding]::UTF8.GetString(
|
||||
[System.IO.File]::ReadAllBytes($resolverAssemblyPath))
|
||||
if (-not $resolverAssemblyMetadata.Contains("CultDocumentMessagePackResolversAttribute")) {
|
||||
throw "GameCult.Caching.MessagePack.dll lacks CultDocumentMessagePackResolversAttribute."
|
||||
}
|
||||
|
||||
Write-Host "CultLib Unity package: $outputRoot"
|
||||
Write-Host "Package: $($manifest.name)@$($manifest.version)"
|
||||
Write-Host "Managed assemblies: $($expectedAssemblies.Count)"
|
||||
Write-Host "Verified owned assembly version: $expectedFileVersion"
|
||||
Write-Host "Verified Stage 1 MessagePack resolver attribute."
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "org.gamecult.cultlib",
|
||||
"displayName": "CultLib",
|
||||
"version": "1.0.7",
|
||||
"version": "1.0.44",
|
||||
"unity": "2021.3",
|
||||
"description": "CultCache, CultNet, and CultMesh managed runtime assemblies for Unity.",
|
||||
"license": "MIT",
|
||||
|
|
|
|||
Loading…
Reference in a new issue