From 0547651f277fa3435f8387f2ca3fcadea4096d2f Mon Sep 17 00:00:00 2001 From: Leilei Zhang Date: Fri, 26 Sep 2025 14:44:47 +0800 Subject: [PATCH] fix Dsc build issue --- .pipelines/generateDscManifests.ps1 | 88 +++++++++++++++++++ .pipelines/v2/templates/job-build-project.yml | 15 +++- tools/build/build-installer.ps1 | 2 +- .../build}/generate-dsc-manifests.ps1 | 0 4 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 .pipelines/generateDscManifests.ps1 rename {.pipelines => tools/build}/generate-dsc-manifests.ps1 (100%) diff --git a/.pipelines/generateDscManifests.ps1 b/.pipelines/generateDscManifests.ps1 new file mode 100644 index 0000000000..109610e62e --- /dev/null +++ b/.pipelines/generateDscManifests.ps1 @@ -0,0 +1,88 @@ +[CmdletBinding()] +param( + [Parameter(Mandatory = $true)] + [string]$BuildPlatform, + + [Parameter(Mandatory = $true)] + [string]$BuildConfiguration, + + [Parameter()] + [string]$RepoRoot = (Get-Location).Path +) + +$ErrorActionPreference = 'Stop' + +function Resolve-PlatformDirectory { + param( + [string]$Root, + [string]$Platform + ) + + $normalized = $Platform.Trim() + $candidates = @() + $candidates += Join-Path $Root $normalized + $candidates += Join-Path $Root ($normalized.ToUpperInvariant()) + $candidates += Join-Path $Root ($normalized.ToLowerInvariant()) + $candidates = $candidates | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -Unique + + foreach ($candidate in $candidates) { + if (Test-Path $candidate) { + return $candidate + } + } + + return $candidates[0] +} + +Write-Host "Repo root: $RepoRoot" +Write-Host "Requested build platform: $BuildPlatform" +Write-Host "Requested configuration: $BuildConfiguration" + +# Always use x64 PowerToys.DSC.exe since CI/CD machines are x64 +$exePlatform = 'x64' +$exeRoot = Resolve-PlatformDirectory -Root $RepoRoot -Platform $exePlatform +$exeOutputDir = Join-Path $exeRoot $BuildConfiguration +$exePath = Join-Path $exeOutputDir 'PowerToys.DSC.exe' + +Write-Host "Using x64 PowerToys.DSC.exe to generate DSC manifests for $BuildPlatform build" + +if (-not (Test-Path $exePath)) { + throw "PowerToys.DSC.exe not found at '$exePath'. Make sure it has been built first." +} + +Write-Host "Using PowerToys.DSC.exe at '$exePath'." + +# Output DSC manifests to the target build platform directory (x64, ARM64, etc.) +$outputRoot = Resolve-PlatformDirectory -Root $RepoRoot -Platform $BuildPlatform +if (-not (Test-Path $outputRoot)) { + Write-Host "Creating missing platform output root at '$outputRoot'." + New-Item -Path $outputRoot -ItemType Directory -Force | Out-Null +} + +$outputDir = Join-Path $outputRoot $BuildConfiguration +if (-not (Test-Path $outputDir)) { + Write-Host "Creating missing configuration output directory at '$outputDir'." + New-Item -Path $outputDir -ItemType Directory -Force | Out-Null +} + +Write-Host "DSC manifests will be generated to: '$outputDir'" + +Write-Host "Cleaning previously generated DSC manifest files from '$outputDir'." +Get-ChildItem -Path $outputDir -Filter 'microsoft.powertoys.*.settings.dsc.resource.json' -ErrorAction SilentlyContinue | Remove-Item -Force + +$arguments = @('manifest', '--resource', 'settings', '--outputDir', $outputDir) +Write-Host "Invoking DSC manifest generator: '$exePath' $($arguments -join ' ')" +& $exePath @arguments +if ($LASTEXITCODE -ne 0) { + throw "PowerToys.DSC.exe exited with code $LASTEXITCODE" +} + +$generatedFiles = Get-ChildItem -Path $outputDir -Filter 'microsoft.powertoys.*.settings.dsc.resource.json' -ErrorAction Stop +if ($generatedFiles.Count -eq 0) { + throw "No DSC manifest files were generated in '$outputDir'." +} + +Write-Host "Generated $($generatedFiles.Count) DSC manifest file(s):" +foreach ($file in $generatedFiles) { + Write-Host " - $($file.FullName)" +} diff --git a/.pipelines/v2/templates/job-build-project.yml b/.pipelines/v2/templates/job-build-project.yml index 7f2a20a4f7..679665cabb 100644 --- a/.pipelines/v2/templates/job-build-project.yml +++ b/.pipelines/v2/templates/job-build-project.yml @@ -263,8 +263,21 @@ jobs: env: SYSTEM_ACCESSTOKEN: $(System.AccessToken) + # Build PowerToys.DSC.exe for ARM64 (x64 uses existing binary from previous build) + - ${{ if ne(parameters.buildPlatform, 'x64') }}: + - task: VSBuild@1 + displayName: Build PowerToys.DSC.exe (x64 for generating manifests) + inputs: + solution: src/dsc/v3/PowerToys.DSC/PowerToys.DSC.csproj + msbuildArgs: /t:Build /m /restore + platform: x64 + configuration: $(BuildConfiguration) + msbuildArchitecture: x64 + maximumCpuCount: true + + # Generate DSC manifests using PowerToys.DSC.exe - pwsh: |- - & '.pipelines/generate-dsc-manifests.ps1' -BuildPlatform '$(BuildPlatform)' -BuildConfiguration '$(BuildConfiguration)' -RepoRoot '$(Build.SourcesDirectory)' + & '.pipelines/generateDscManifests.ps1' -BuildPlatform '$(BuildPlatform)' -BuildConfiguration '$(BuildConfiguration)' -RepoRoot '$(Build.SourcesDirectory)' displayName: Generate DSC manifests - task: CopyFiles@2 diff --git a/tools/build/build-installer.ps1 b/tools/build/build-installer.ps1 index 9403892349..f601146577 100644 --- a/tools/build/build-installer.ps1 +++ b/tools/build/build-installer.ps1 @@ -126,7 +126,7 @@ else { # Generate DSC manifest files Write-Host '[DSC] Generating DSC manifest files...' -$dscScriptPath = Join-Path $repoRoot '.pipelines\generate-dsc-manifests.ps1' +$dscScriptPath = Join-Path $repoRoot '.\tools\build\generate-dsc-manifests.ps1' if (Test-Path $dscScriptPath) { & $dscScriptPath -BuildPlatform $Platform -BuildConfiguration $Configuration -RepoRoot $repoRoot if ($LASTEXITCODE -ne 0) { diff --git a/.pipelines/generate-dsc-manifests.ps1 b/tools/build/generate-dsc-manifests.ps1 similarity index 100% rename from .pipelines/generate-dsc-manifests.ps1 rename to tools/build/generate-dsc-manifests.ps1