From 3e08f509444d1a8a4f272410de2894b306ace7ff Mon Sep 17 00:00:00 2001 From: Bogdan Popa Date: Tue, 14 Jul 2020 15:52:18 +0300 Subject: [PATCH] win32: add Power Shell script to set env vars The added PS script runs msvcprep.bat in a sub shell then reads the environment variables line by line and sets them in the current shell. --- racket/src/worksp/README.txt | 4 ++++ racket/src/worksp/msvcprep.ps1 | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 racket/src/worksp/msvcprep.ps1 diff --git a/racket/src/worksp/README.txt b/racket/src/worksp/README.txt index 26c8866f3c..169cbd5285 100644 --- a/racket/src/worksp/README.txt +++ b/racket/src/worksp/README.txt @@ -21,6 +21,10 @@ tries to find Visual Studio and run its "vcvarsall.bat". Provide an argument such as "x86" (32-bit mode) or "x86_amd64" (64-bit mode) to select the build mode. +When using PowerShell, run the "msvcprep.ps1" script instead of +"msvcprep.bat". Running the latter from PowerShell will appear to +work, but will not actually change any environment variables. + After you have Visual Studio command-line tools set up, then you can build either the traditional Racket implementation or Racket-on-Chez (or both). diff --git a/racket/src/worksp/msvcprep.ps1 b/racket/src/worksp/msvcprep.ps1 new file mode 100644 index 0000000000..afaa940f0c --- /dev/null +++ b/racket/src/worksp/msvcprep.ps1 @@ -0,0 +1,30 @@ +<# +.SYNOPSIS + A variant of msvcprep.bat for PowerShell users. + +.DESCRIPTION + Runs Visual Studio's vcvarsall.bat script to set the necessary + environment variables for a given target platform. + +.EXAMPLE + Set variables for x86. + PS C:\>racket\src\worksp\msvcprep.ps1 x86 + +.EXAMPLE + Set variables for x86_64 + PS C:\>racket\src\worksp\msvcprep.ps1 x86_amd64 + +.NOTES + Adapted from this StackOverflow answer: + * https://stackoverflow.com/a/2124759/144981 +#> + +$command = "echo off & " + $PSScriptRoot + "\msvcprep.bat " + $Args[0] + " & set" +cmd /c $command | + ForEach { + if ($_ -match "=") { + $v = $_.split("=", 2) + Set-Item -Force -Path "ENV:\$($v[0])" -Value "$($v[1])" + } + } +Write-Host "Visual Studio variables set." -ForegroundColor Yellow