Files
ARCADIA-Studio/scripts/package-cli-windows.ps1
T

76 lines
4.6 KiB
PowerShell

#Requires -Version 5.1
# Package an already-built CLI. No builds, downloads, recovery or application launch.
[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[ValidateSet('x86_64-pc-windows-msvc', 'x86_64-pc-windows-gnullvm')]
[string]$Target,
[Parameter(Mandatory = $true)]
[ValidatePattern('^[A-Za-z0-9][A-Za-z0-9._-]{0,79}$')]
[string]$Version,
[Parameter(Mandatory = $true)]
[string]$BinaryDirectory,
[Parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string]$BuildEvidence,
[string]$LlvmMinGWRoot,
[string]$Python = 'python',
[string]$NoticeManifest = (Join-Path $PSScriptRoot 'windows-notices/manifest.json'),
[string]$OutputRoot = (Join-Path $PSScriptRoot '../dist')
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$repository = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$encoding = New-Object Text.UTF8Encoding($false)
. (Join-Path $PSScriptRoot 'package-common.ps1')
. (Join-Path $PSScriptRoot 'windows-notices.ps1')
$windowsInputs = Get-PackageWindowsInputs $BinaryDirectory $Target $LlvmMinGWRoot @('arcadia.exe')
$inputs = $windowsInputs.Inputs
$inspectedHashes = $windowsInputs.InspectedHashes
$evidence = Read-PackageBuildEvidence $BuildEvidence $Target $windowsInputs.BinaryHashes
$documentation = Invoke-PackageHelper $Python @('docs', '--repository', $repository, '--platform', 'windows', '--product', 'cli')
foreach ($entry in $documentation.files) { $inputs[$entry.path] = $entry.source }
$notices = Get-ArcadiaNotices $repository $Target $NoticeManifest $LlvmMinGWRoot @('oa-cli')
foreach ($name in $notices.Inputs.Keys) {
if ($inputs.Contains($name)) { throw "Notice collides with package input: $name" }
$inputs[$name] = $notices.Inputs[$name]
$inspectedHashes[$name] = $notices.Hashes[$name]
}
$output = [IO.Path]::GetFullPath($OutputRoot)
$packageName = "ArcadiaCLI-$Version-$Target"
$stage = Join-Path $output $packageName
$archive = "$stage.zip"
$checksum = "$archive.sha256"
$lockPath = "$stage.packaging.lock"
foreach ($path in @($stage, $archive, $checksum, $lockPath)) {
if (Test-Path -LiteralPath $path) { throw "Output already exists; choose a fresh version or output root: $path" }
}
foreach ($directory in @('docs', 'examples', 'deployment', 'crates', 'scripts')) {
$sourceRoot = [IO.Path]::GetFullPath((Join-Path $repository $directory)) + [IO.Path]::DirectorySeparatorChar
if (($stage + [IO.Path]::DirectorySeparatorChar).StartsWith($sourceRoot, [StringComparison]::OrdinalIgnoreCase)) { throw 'Output must not be inside a packaged source directory.' }
}
[void][IO.Directory]::CreateDirectory($output)
$lock = [IO.File]::Open($lockPath, [IO.FileMode]::CreateNew, [IO.FileAccess]::Write, [IO.FileShare]::None)
try {
[void][IO.Directory]::CreateDirectory($stage)
$inputHashes = Copy-PackageInputs $stage $inputs $inspectedHashes
$metadata = [ordered]@{
product = 'Arcadia CLI'; version = $Version; target = $Target
acceptance = 'Packaging integrity only; clean-environment CLI verification required.'
build = 'Prebuilt input; source/compiler/profile assertions are recorded, not inferred.'
build_evidence = $evidence; imports = $windowsInputs.Imports; input_sha256 = $inputHashes
}
[IO.File]::WriteAllText((Join-Path $stage 'package.json'), ($metadata | ConvertTo-Json -Depth 14) + "`n", $encoding)
Write-PackageNotices $stage $notices
[IO.File]::WriteAllText((Join-Path $stage 'START-HERE.txt'), "Arcadia CLI portable Windows bundle`nOpen a terminal in this folder and run .\arcadia.exe --help.`nRead README.md and docs/source-cli.md. Keep any bundled runtime DLL beside arcadia.exe.`nNo compiler, desktop editor, network service or machine PATH change is required.`nCopy an example into your own work directory before editing it. Preview is the default; --write saves.`nPackaging integrity does not establish runtime acceptance; see package.json and release evidence.`n", $encoding)
$documentCheck = Invoke-PackageHelper $Python @('check-docs', '--stage', $stage)
[IO.File]::WriteAllText((Join-Path $stage 'documentation-check.json'), ($documentCheck | ConvertTo-Json) + "`n", $encoding)
Write-PackageChecksums $stage
$result = Write-PackageWindowsArchive $stage $archive $packageName
[IO.File]::WriteAllText($checksum, "$($result.SHA256) $packageName.zip`n", $encoding)
[pscustomobject]@{ Directory = $stage; Archive = $archive; SHA256 = $result.SHA256; Files = $result.Files; NativeAcceptance = 'Pending' }
} finally {
$lock.Dispose()
# Keep claims and partial outputs. A retry must never overwrite an earlier attempt.
}