Skip to content

Commit

Permalink
Fix PowerShell Script Issues (#76219)
Browse files Browse the repository at this point in the history
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.

PowerShell/PowerShell#24630
  • Loading branch information
jaredpar authored Dec 2, 2024
1 parent ce5ba07 commit bb6bafa
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 6 deletions.
19 changes: 19 additions & 0 deletions docs/contributing/Powershell Guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion eng/generate-compiler-code.cmd
Original file line number Diff line number Diff line change
@@ -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" %*

3 changes: 2 additions & 1 deletion eng/make-bootstrap.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@echo off
powershell -noprofile -file "%~dp0\make-bootstrap.ps1" %*
set PSMODULEPATH=
powershell -noprofile -executionPolicy Unrestricted -file "%~dp0\make-bootstrap.ps1" %*
2 changes: 2 additions & 0 deletions eng/make-bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 2 additions & 1 deletion eng/test-build-correctness.cmd
Original file line number Diff line number Diff line change
@@ -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" %*
3 changes: 2 additions & 1 deletion eng/test-determinism.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@echo off
powershell -noprofile -file "%~dp0\test-determinism.ps1" %*
set PSMODULEPATH=
powershell -noprofile -executionPolicy Unrestricted -file "%~dp0\test-determinism.ps1" %*
5 changes: 3 additions & 2 deletions eng/test-determinism.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 `
Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions eng/test-rebuild.cmd
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
@echo off
set PSMODULEPATH=
powershell -noprofile -file "%~dp0\test-rebuild.ps1" %*

0 comments on commit bb6bafa

Please sign in to comment.