From bb6bafa869aff333415038754377c4810af7d569 Mon Sep 17 00:00:00 2001 From: Jared Parsons Date: Mon, 2 Dec 2024 15:52:50 -0500 Subject: [PATCH] Fix PowerShell Script Issues (#76219) Ran into issues running PowerShell script issues tonight looking at determinism. After digging down discovered that our scripts didn't run correctly when launching the .cmd files from a pwsh shell. Changed our cmd to avoid this problem. https://github.com/PowerShell/PowerShell/discussions/24630 --- docs/contributing/Powershell Guidelines.md | 19 +++++++++++++++++++ eng/generate-compiler-code.cmd | 3 ++- eng/make-bootstrap.cmd | 3 ++- eng/make-bootstrap.ps1 | 2 ++ eng/test-build-correctness.cmd | 3 ++- eng/test-determinism.cmd | 3 ++- eng/test-determinism.ps1 | 5 +++-- eng/test-rebuild.cmd | 1 + 8 files changed, 33 insertions(+), 6 deletions(-) diff --git a/docs/contributing/Powershell Guidelines.md b/docs/contributing/Powershell Guidelines.md index 9a1852178a291..987e87216f0c9 100644 --- a/docs/contributing/Powershell Guidelines.md +++ b/docs/contributing/Powershell Guidelines.md @@ -106,3 +106,22 @@ in source and unified build. Until that moves to `pwsh` our scripts need to stay The exception is that our VS Code helper scripts should use `pwsh`. That is not a part of our infrastructure and needs to run cross platform hence `pwsh` is appropriate. + +### Supporting .cmd file + +Consider adding a `.cmd` file that calls the `.ps1` file. This is to support users who are not +running a powershell shell. It also helps with ensuring the script is run locally the same it is +run in CI by controlling the powershell used to invoke the script. + +test.cmd + +```cmd +@echo off +set PSMODULEPATH= +powershell -noprofile -ExecutionPolicy Unrestricted -file "%~dp0\test.ps1" %* +``` + +Note: the `PSMODULEPATH` is cleared to ensure a pwsh shell [does not interfere][psmodulepath] +with launching powershell. + +[psmodulepath]: https://github.com/PowerShell/PowerShell/discussions/24630 \ No newline at end of file diff --git a/eng/generate-compiler-code.cmd b/eng/generate-compiler-code.cmd index 808137ef77cb7..60a78f0589889 100644 --- a/eng/generate-compiler-code.cmd +++ b/eng/generate-compiler-code.cmd @@ -1,3 +1,4 @@ @echo off -powershell -noprofile -executionPolicy RemoteSigned -file "%~dp0\generate-compiler-code.ps1" %* +set PSMODULEPATH= +powershell -noprofile -executionPolicy Unrestricted -file "%~dp0\generate-compiler-code.ps1" %* diff --git a/eng/make-bootstrap.cmd b/eng/make-bootstrap.cmd index fe6cae0b6e9f9..612ae9b362fa5 100644 --- a/eng/make-bootstrap.cmd +++ b/eng/make-bootstrap.cmd @@ -1,2 +1,3 @@ @echo off -powershell -noprofile -file "%~dp0\make-bootstrap.ps1" %* \ No newline at end of file +set PSMODULEPATH= +powershell -noprofile -executionPolicy Unrestricted -file "%~dp0\make-bootstrap.ps1" %* \ No newline at end of file diff --git a/eng/make-bootstrap.ps1 b/eng/make-bootstrap.ps1 index 64100d029cdfa..ab01f47766db1 100644 --- a/eng/make-bootstrap.ps1 +++ b/eng/make-bootstrap.ps1 @@ -46,6 +46,8 @@ try { throw "Unsupported bootstrap toolset $toolset" } + $projectPath = Join-Path $RepoRoot $projectPath + $name = Split-Path -Leaf $output $binaryLogFilePath = Join-Path $LogDir "bootstrap-$($name).binlog" diff --git a/eng/test-build-correctness.cmd b/eng/test-build-correctness.cmd index 1c063890db1fe..fa75b0895201f 100644 --- a/eng/test-build-correctness.cmd +++ b/eng/test-build-correctness.cmd @@ -1,2 +1,3 @@ @echo off -powershell -noprofile -file "%~dp0\test-build-correctness.ps1" %* +set PSMODULEPATH= +powershell -noprofile -executionPolicy Unrestricted -file "%~dp0\test-build-correctness.ps1" %* diff --git a/eng/test-determinism.cmd b/eng/test-determinism.cmd index 4f3fccf35b03f..cb0953512879d 100644 --- a/eng/test-determinism.cmd +++ b/eng/test-determinism.cmd @@ -1,2 +1,3 @@ @echo off -powershell -noprofile -file "%~dp0\test-determinism.ps1" %* +set PSMODULEPATH= +powershell -noprofile -executionPolicy Unrestricted -file "%~dp0\test-determinism.ps1" %* diff --git a/eng/test-determinism.ps1 b/eng/test-determinism.ps1 index 57c965bfe5831..b695eed1bdb10 100644 --- a/eng/test-determinism.ps1 +++ b/eng/test-determinism.ps1 @@ -67,6 +67,7 @@ function Run-Build([string]$rootDir, [string]$logFileName) { /p:RepoRoot=$rootDir ` /p:TreatWarningsAsErrors=true ` /p:BootstrapBuildPath=$bootstrapDir ` + /p:DeterministicSourcePaths=true ` /p:RunAnalyzers=false ` /p:RunAnalyzersDuringBuild=false ` /p:RestoreUseStaticGraphEvaluation=$restoreUseStaticGraphEvaluation ` @@ -286,8 +287,8 @@ try { if ($bootstrapDir -eq "") { Write-Host "Building bootstrap compiler" - $bootstrapDir = Join-Path $ArtifactsDir "bootstrap" "determinism" - & eng/make-bootstrap.ps1 -output $bootstrapDir -ci:$ci + $bootstrapDir = Join-Path $ArtifactsDir (Join-Path "bootstrap" "determinism") + & eng/make-bootstrap.ps1 -output $bootstrapDir -ci:$ci -force Test-LastExitCode } diff --git a/eng/test-rebuild.cmd b/eng/test-rebuild.cmd index ae4bc34fcc827..72307d58d0039 100644 --- a/eng/test-rebuild.cmd +++ b/eng/test-rebuild.cmd @@ -1,2 +1,3 @@ @echo off +set PSMODULEPATH= powershell -noprofile -file "%~dp0\test-rebuild.ps1" %*