-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtiny11Coremaker-from-config.ps1
More file actions
150 lines (137 loc) · 7.3 KB
/
tiny11Coremaker-from-config.ps1
File metadata and controls
150 lines (137 loc) · 7.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# tiny11 Core build wrapper -- invoked by launcher/Gui/Handlers/BuildHandlers.cs
# as a powershell.exe subprocess when the user picks Core mode in the Step 1
# wizard. Differs from tiny11maker-from-config.ps1: no -ConfigPath / no
# selections payload (Core has no catalog), and adds -EnableNet35 (the
# Step 1 .NET 3.5 sub-checkbox).
#
# Hands off to Invoke-Tiny11CoreBuildPipeline (src/Tiny11.Core.psm1) which
# orchestrates the 24-phase Core build. Progress markers + completion +
# error are emitted as JSON lines on STDOUT for line-by-line parsing in
# BuildHandlers (same forwarder used by tiny11maker-from-config.ps1).
#
# Persistent log: this wrapper writes a comprehensive on-disk log to
# $ScratchDir\tiny11-core-build.log covering every phase, every external
# command (DISM/takeown/icacls/reg/oscdimg) with full output + exit code,
# and any caught exception. Survives the WinSxS-cancel cleanup commands
# (those only nuke `mount/` and `source/` subdirs of the scratch root).
[CmdletBinding()]
param(
[Parameter(Mandatory)][string]$Source,
[Parameter(Mandatory)][string]$OutputIso,
[int]$ImageIndex = 0,
[string]$Edition,
[string]$ScratchDir,
[switch]$EnableNet35,
[switch]$UnmountSource,
[switch]$FastBuild,
[switch]$NoPostBootCleanup
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
# Helper: write a JSON marker to STDOUT for the launcher's line-by-line forwarder.
# Matches tiny11maker-from-config.ps1's Write-Marker exactly so the launcher's
# BuildHandlers forwarder routes Core markers identically to standard markers.
function Write-Marker($Type, [hashtable]$Payload) {
$obj = @{ type = $Type; payload = $Payload }
[Console]::WriteLine(($obj | ConvertTo-Json -Compress -Depth 10))
}
# Declared outside the try block so the catch can reference it even if the
# failure fires before the log path is initialized.
$logPath = $null
try {
# Locate bundled modules -- same dir as this wrapper (extracted by EmbeddedResources at runtime).
$RepoRoot = Split-Path -Parent $PSCommandPath
$ModulesDir = Join-Path $RepoRoot 'src'
Import-Module (Join-Path $ModulesDir 'Tiny11.Iso.psm1') -Force
Import-Module (Join-Path $ModulesDir 'Tiny11.Core.psm1') -Force
Import-Module (Join-Path $ModulesDir 'Tiny11.Catalog.psm1') -Force
Import-Module (Join-Path $ModulesDir 'Tiny11.Selections.psm1') -Force
# Load default catalog + selections for the post-boot cleanup task. Core builds
# don't expose Step 2 selections in the UI; the catalog defaults are sane targets
# for re-removal (apps the user expected to be gone after a Core build).
$catalogPath = Join-Path $RepoRoot 'catalog\catalog.json'
$catalog = Get-Tiny11Catalog -Path $catalogPath
$selections = New-Tiny11Selections -Catalog $catalog
$resolved = Resolve-Tiny11Selections -Catalog $catalog -Selections $selections
# Scratch dir resolution. Honour caller's -ScratchDir if provided
# (matches BuildHandlers payload pass-through); fall back to process-
# scoped temp dir so concurrent invocations don't collide.
if (-not $ScratchDir) {
$ScratchDir = Join-Path $env:TEMP "tiny11options-corebuild-$PID"
}
New-Item -ItemType Directory -Path $ScratchDir -Force | Out-Null
# Initialize the persistent log NOW, before any operation that could fail.
# Set-Tiny11CoreLogPath truncates any prior log so each run starts clean.
$logPath = Join-Path $ScratchDir 'tiny11-core-build.log'
Set-Tiny11CoreLogPath -Path $logPath
Write-CoreLog '==== Tiny11 Core build wrapper start ===='
Write-CoreLog "PSVersion=$($PSVersionTable.PSVersion) Architecture=$env:PROCESSOR_ARCHITECTURE OS=$([Environment]::OSVersion.VersionString)"
Write-CoreLog "Wrapper params: Source='$Source' OutputIso='$OutputIso' ImageIndex=$ImageIndex Edition='$Edition' ScratchDir='$ScratchDir' EnableNet35=$($EnableNet35.IsPresent) UnmountSource=$($UnmountSource.IsPresent) FastBuild=$($FastBuild.IsPresent)"
# Preflight: mount the source, enumerate editions, resolve -Edition to
# -ImageIndex if needed. Same pattern as tiny11maker-from-config.ps1
# (lines 77-91) -- keeps the source-mount-then-dismount window short
# before the heavy build phases.
Write-Marker 'build-progress' @{ phase = 'preflight'; step = 'Mounting source for edition enumeration'; percent = 0 }
Write-CoreLog 'PREFLIGHT: Mount-Tiny11Source for edition enumeration'
$preflightMount = Mount-Tiny11Source -InputPath $Source
try {
$editions = @(Get-Tiny11Editions -DriveLetter $preflightMount.DriveLetter)
Write-CoreLog "PREFLIGHT: discovered $($editions.Count) edition(s)"
if ($Edition -and $ImageIndex -le 0) {
$ImageIndex = Resolve-Tiny11ImageIndex -Editions $editions -Edition $Edition
Write-CoreLog "PREFLIGHT: resolved Edition='$Edition' to ImageIndex=$ImageIndex"
}
} finally {
if ($preflightMount.MountedByUs) {
Dismount-Tiny11Source -IsoPath $preflightMount.IsoPath -MountedByUs:$preflightMount.MountedByUs -ForceUnmount:$true
Write-CoreLog 'PREFLIGHT: Dismount-Tiny11Source done'
}
}
if ($ImageIndex -le 0) {
throw "Image index could not be resolved (Edition='$Edition', ImageIndex=$ImageIndex). Pass -Edition or -ImageIndex."
}
# Hand off to Tiny11.Core's orchestrator. Progress markers stream via
# the callback, terminating with build-complete or throwing on error
# (caught by the outer try/catch and emitted as build-error).
Invoke-Tiny11CoreBuildPipeline `
-Source $Source `
-ImageIndex $ImageIndex `
-ScratchDir $ScratchDir `
-OutputIso $OutputIso `
-EnableNet35 $EnableNet35.IsPresent `
-UnmountSource $UnmountSource.IsPresent `
-FastBuild $FastBuild.IsPresent `
-InstallPostBootCleanup (-not $NoPostBootCleanup.IsPresent) `
-Catalog $catalog `
-ResolvedSelections $resolved `
-ProgressCallback {
param($p)
# Forward the entire payload, not just phase/step/percent. The Core
# pipeline emits mount-state markers with extra fields (mountActive,
# mountDir, sourceDir) that the launcher's auto-cleanup button
# depends on. Per-key whitelisting drops those fields silently, so
# JS never sees state.mountActive=true and the cleanup section
# self-gates off. Pass $p through directly -- Write-Marker already
# declares [hashtable]$Payload so any keys present flow through to
# ConvertTo-Json verbatim.
Write-Marker 'build-progress' $p
}
Write-CoreLog '==== Tiny11 Core build SUCCESS ===='
Write-Marker 'build-complete' @{ outputPath = $OutputIso }
exit 0
}
catch {
# Mirror the exception into the persistent log first (best-effort -- Write-CoreLog
# is a no-op if Set-Tiny11CoreLogPath was never called or the module didn't load).
if (Get-Command -Name Write-CoreLog -ErrorAction SilentlyContinue) {
Write-CoreLog '==== Tiny11 Core build FAILED ===='
Write-CoreLog "Exception.Message: $($_.Exception.Message)"
Write-CoreLog "ScriptStackTrace:`n$($_.ScriptStackTrace)"
}
Write-Marker 'build-error' @{
message = $_.Exception.Message
stackTrace = $_.ScriptStackTrace
logPath = $logPath
}
exit 1
}