|
| 1 | +# O6 / D17 / D18 probe: what the published mcpp does when the Windows SDK is not |
| 2 | +# under the conventional "C:\Program Files (x86)\Windows Kits\10" path, as on a |
| 3 | +# machine whose SDK was installed to another drive. Prints; asserts nothing. |
| 4 | +$ErrorActionPreference = 'Continue' |
| 5 | +$PSNativeCommandUseErrorActionPreference = $false |
| 6 | +$v = $env:MCPP_VERSION |
| 7 | +$root = 'C:\probe' |
| 8 | +$logs = "$root\logs" |
| 9 | +New-Item -ItemType Directory -Force $logs | Out-Null |
| 10 | +$summary = $env:GITHUB_STEP_SUMMARY |
| 11 | +function Say($t) { Write-Host $t; Add-Content -Path $summary -Value $t } |
| 12 | + |
| 13 | +Say "## windows sdk probe (mcpp $v)" |
| 14 | +$zip = "$root\mcpp.zip" |
| 15 | +Invoke-WebRequest "https://github.com/mcpp-community/mcpp/releases/download/v$v/mcpp-$v-windows-x86_64.zip" -OutFile $zip |
| 16 | +Expand-Archive $zip -DestinationPath "$root\dist" -Force |
| 17 | +$mcpp = (Get-ChildItem "$root\dist" -Recurse -Filter mcpp.exe | Select-Object -First 1).FullName |
| 18 | +Say "- mcpp: ``$mcpp``" |
| 19 | +Say "- WindowsSdkDir in env: ``$env:WindowsSdkDir`` VSINSTALLDIR: ``$env:VSINSTALLDIR``" |
| 20 | + |
| 21 | +function Run-Case($name, $mcppHome, $dir, [string[]]$cmdArgs) { |
| 22 | + $env:MCPP_HOME = $mcppHome |
| 23 | + New-Item -ItemType Directory -Force $mcppHome | Out-Null |
| 24 | + Push-Location $dir |
| 25 | + $log = "$logs\$name.log" |
| 26 | + & $mcpp @cmdArgs *>&1 | Tee-Object -FilePath $log | Out-Host |
| 27 | + $rc = $LASTEXITCODE |
| 28 | + Pop-Location |
| 29 | + Say "### $name (exit $rc)" |
| 30 | + Say '```' |
| 31 | + Get-Content $log | Select-String -Pattern 'First run|Default|Resolved|warning|error|note|hint|Visual Studio|SDK|MinGW|mingw|Finished|toolchain' | |
| 32 | + Select-Object -First 40 | ForEach-Object { Say $_.Line } |
| 33 | + Say '```' |
| 34 | + $cfg = Join-Path $mcppHome 'config.toml' |
| 35 | + if (Test-Path $cfg) { |
| 36 | + Say "config.toml after ${name}:" |
| 37 | + Say '```' |
| 38 | + Get-Content $cfg | Select-String -Pattern 'toolchain|target' | ForEach-Object { Say $_.Line } |
| 39 | + Say '```' |
| 40 | + } |
| 41 | + return $rc |
| 42 | +} |
| 43 | + |
| 44 | +function New-Hello($name, [string]$toolchainLine) { |
| 45 | + $dir = "$root\$name" |
| 46 | + New-Item -ItemType Directory -Force "$dir\src" | Out-Null |
| 47 | + $toml = "[package]`nname = `"$name`"`nversion = `"0.1.0`"`n" |
| 48 | + if ($toolchainLine) { $toml += "`n[toolchain]`n$toolchainLine`n" } |
| 49 | + $toml += "`n[targets.$name]`nkind = `"bin`"`nmain = `"src/main.cpp`"`n" |
| 50 | + Set-Content -Path "$dir\mcpp.toml" -Value $toml -NoNewline |
| 51 | + Set-Content -Path "$dir\src\main.cpp" -Value "import std;`nint main() { std::println(`"hello from {}`", `"$name`"); }`n" |
| 52 | + return $dir |
| 53 | +} |
| 54 | + |
| 55 | +$home1 = "$root\home-first-run" |
| 56 | +$home2 = "$root\home-llvm" |
| 57 | + |
| 58 | +# B0: control, SDK in its conventional place, llvm declared. |
| 59 | +$b0 = New-Hello 'b0_control_llvm' 'windows = "llvm@23.1.3"' |
| 60 | +Run-Case 'B0_control_llvm_declared' $home2 $b0 @('build') | Out-Null |
| 61 | + |
| 62 | +# Move the SDK and record its new place where an installer would. |
| 63 | +$kits = Join-Path ${env:ProgramFiles(x86)} 'Windows Kits\10' |
| 64 | +$moved = 'C:\MovedKits\10' |
| 65 | +New-Item -ItemType Directory -Force 'C:\MovedKits' | Out-Null |
| 66 | +Say "### moving ``$kits`` -> ``$moved``" |
| 67 | +try { Move-Item -Path $kits -Destination $moved -ErrorAction Stop; Say '- moved' } |
| 68 | +catch { Say "- Move-Item failed: $($_.Exception.Message)"; cmd /c "move `"$kits`" `"$moved`"" | Out-Host } |
| 69 | +Say "- conventional path exists now: $(Test-Path $kits); moved path exists: $(Test-Path $moved)" |
| 70 | +foreach ($k in @('HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows Kits\Installed Roots', |
| 71 | + 'HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots')) { |
| 72 | + if (Test-Path $k) { |
| 73 | + $old = (Get-ItemProperty $k -ErrorAction SilentlyContinue).KitsRoot10 |
| 74 | + Set-ItemProperty -Path $k -Name KitsRoot10 -Value "$moved\" |
| 75 | + Say "- ``$k`` KitsRoot10: ``$old`` -> ``$moved\``" |
| 76 | + } |
| 77 | +} |
| 78 | +foreach ($k in @('HKLM:\SOFTWARE\WOW6432Node\Microsoft\Microsoft SDKs\Windows\v10.0', |
| 79 | + 'HKLM:\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v10.0')) { |
| 80 | + if (Test-Path $k) { |
| 81 | + $old = (Get-ItemProperty $k -ErrorAction SilentlyContinue).InstallationFolder |
| 82 | + Set-ItemProperty -Path $k -Name InstallationFolder -Value "$moved\" |
| 83 | + Say "- ``$k`` InstallationFolder: ``$old`` -> ``$moved\``" |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +# S1: nothing configured anywhere (fresh home, no [toolchain]). |
| 88 | +$s1 = New-Hello 's1_nothing_configured' '' |
| 89 | +Run-Case 'S1_first_run_nothing_configured' $home1 $s1 @('build') | Out-Null |
| 90 | +Run-Case 'S1_self_env' $home1 $s1 @('self', 'env') | Out-Null |
| 91 | + |
| 92 | +# S2: [toolchain] windows = llvm in mcpp.toml (llvm already installed by B0). |
| 93 | +$s2 = New-Hello 's2_llvm_declared' 'windows = "llvm@23.1.3"' |
| 94 | +$rc = Run-Case 'S2_llvm_declared_in_manifest' $home2 $s2 @('build') |
| 95 | +if ($rc -eq 0) { |
| 96 | + $exe = Get-ChildItem "$s2\target" -Recurse -Filter 's2_llvm_declared.exe' | Select-Object -First 1 |
| 97 | + if ($exe) { Say "S2 program output: $(& $exe.FullName)" } |
| 98 | +} |
| 99 | + |
| 100 | +# S3: nothing in mcpp.toml, --toolchain on the command line. |
| 101 | +$s3 = New-Hello 's3_toolchain_flag' '' |
| 102 | +Run-Case 'S3_toolchain_flag' $home2 $s3 @('build', '--toolchain', 'llvm@23.1.3') | Out-Null |
| 103 | + |
| 104 | +# S4: S2 again with --verbose, for the SDK lines the plain run hides. |
| 105 | +Run-Case 'S4_llvm_declared_verbose' $home2 $s2 @('build', '--verbose') | Out-Null |
| 106 | +exit 0 |
0 commit comments