-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expose ghcup binary to PATH on windows #4264
Expose ghcup binary to PATH on windows #4264
Conversation
The bootstrap-haskell.ps1 script uses '[System.EnvironmentVariableTarget]::User' instead of '[System.EnvironmentVariableTarget]::Machine', so it appears ghcup env vars and PATH update never make it. Do these manually for now.
ea9c21a
to
8b1ede4
Compare
The config adjustment usually includes adding msys2 directories, so cabal can find `pkg-config` and libraries, e.g.: + C: \ghcup\msys64\mingw64\bin + extra-include-dirs: C:\ghcup\msys64\mingw64\include + extra-lib-dirs: C:\ghcup\msys64\mingw64\lib - extra-prog-path: C:\cabal\bin + extra-prog-path: C:\ghcup\bin,
3118adb
to
7a0460b
Compare
This modifies the default |
/azp run windows2016, windows2019, windows2022 |
Azure Pipelines successfully started running 3 pipeline(s). |
$msysPath = "C:\msys64" | ||
$ghcupPrefix = "C:\" | ||
$appdata = [Environment]::GetEnvironmentVariable('APPDATA', [System.EnvironmentVariableTarget]::Machine) | ||
$cabalDir = "$appdata\cabal" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would try to honour a possible previous value of $CABAL_DIR
just in case, as it is setting the env var in 45
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no previous value I believe
I would consider not change it here by default; it could break some setups out there and workflows needing them will be already change it theirselves. |
But it's the correct config that's done by chocolatey, haskell/actions and ghcup. I think people should expect the same config on the windows machine? |
A potential case that can cause problems is with posix-regex: https://gitlab.haskell.org/ghc/ghc/-/issues/19945 I'll think about it. |
Invoke-Command -ScriptBlock ([ScriptBlock]::Create($bootstrapHaskell)) -ArgumentList $false, $true, $true, $false, $false, $false, $false, C:\, "", C:\msys64, C:\cabal | ||
$msysPath = "C:\msys64" | ||
$ghcupPrefix = "C:\" | ||
$appdata = [Environment]::GetEnvironmentVariable('APPDATA', [System.EnvironmentVariableTarget]::Machine) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AppData env var does not exist in Machine scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having a hard time figuring out why env vars set for the user don't make it into the final image?
Seems we do need Machine
scope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it seems my current code doesn't make it work either:
vhd: [-] GHCUP_INSTALL_BASE_PREFIX environment variable exists 866ms (667ms|200ms)
vhd: Expected $true, but got $false.
vhd: at [Environment]::GetEnvironmentVariables("Machine").ContainsKey($envVar) | Should -BeTrue, C:\image\Tests\Haskell.Tests.ps1:33
vhd: at <ScriptBlock>, C:\image\Tests\Haskell.Tests.ps1:33
vhd: [-] GHCUP_MSYS2 environment variable exists 26ms (25ms|1ms)
vhd: Expected $true, but got $false.
vhd: at [Environment]::GetEnvironmentVariables("Machine").ContainsKey($envVar) | Should -BeTrue, C:\image\Tests\Haskell.Tests.ps1:33
vhd: at <ScriptBlock>, C:\image\Tests\Haskell.Tests.ps1:33
vhd: [-] ghcup is installed 15ms (14ms|1ms)
vhd: Command 'ghcup --version' has finished with exit code
vhd: 'ghcup' is not recognized as an internal or external command,
vhd: operable program or batch file.
vhd: at "ghcup --version" | Should -ReturnZeroExitCode, C:\image\Tests\Haskell.Tests.ps1:58
vhd: at <ScriptBlock>, C:\image\Tests\Haskell.Tests.ps1:58
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the end of image generation process packer invokes sysprep util with /generalize param and removes the user which it uses during generation:
The Sysprep /generalize command removes unique information from a Windows installation so that you can reuse that image on different computers.
The value of %AppData% is C:\Users\USERNAME\AppData\Roaming <- That's why it exists only in the USER scope.
We should use the hardcoded variant as before, for example: $cabalDir = "C:\cabal"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hasufell, Could you please apply changes above? ^^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@al-cheb sure, bet that won't fix the issue with ghcup not being in PATH
It "cabal config was modified and exists" { | ||
[Environment]::GetEnvironmentVariable('CABAL_DIR', [System.EnvironmentVariableTarget]::Machine) | Should -Exist | ||
"cabal user-config diff" | Should -Not -BeNullOrEmpty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just a string "cabal user-config diff"
. We should use ReturnZeroExitCode or &
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace | Should -Not -BeNullOrEmpty
to | Should -ReturnZeroExitCode
I take it once this PR is merged For getting this directory before the PR is merged, I could use |
The env vars I set don't seem to work and I don't really understand why: #4264 (comment) |
@al-cheb thoughts on this? |
It "cabal config was modified and exists" { | ||
[Environment]::GetEnvironmentVariable('CABAL_DIR', [System.EnvironmentVariableTarget]::Machine) | Should -Exist | ||
"cabal user-config diff" | Should -Not -BeNullOrEmpty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace | Should -Not -BeNullOrEmpty
to | Should -ReturnZeroExitCode
Can we do a test run? |
/azp run windows2016, windows2019, windows2022 |
Azure Pipelines successfully started running 3 pipeline(s). |
The binary still cannot be found:
I really don't understand these images. |
$msysPath = "C:\msys64" | ||
$ghcupPrefix = "C:\" | ||
$cabalDir = "C:\cabal" | ||
Invoke-Command -ScriptBlock ([ScriptBlock]::Create($bootstrapHaskell)) -ArgumentList $false, $true, $true, $false, $false, $false, $false, $ghcupPrefix, "", $msysPath, $cabalDir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hasufell, This part of script is missing -> ScriptBlock ([ScriptBlock]::Create($bootstrapHaskell))
. The $bootstrapHaskell
var is undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@al-cheb done
@@ -35,5 +35,13 @@ Choco-Install -PackageName cabal | |||
Invoke-PesterTests -TestFile 'Haskell' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hasufell, We should run test after installation. Could you please move this statement at the end?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@al-cheb done
Cool, it seems to have succeeded. |
This may break setups.
I think the change makes sense per se. I suppose (and hope) it will not break the choco installation, used right now in Haskell setup action. @al-cheb is it possible to add a note in the image release about the breaking change? Including the possible workaround (unset the env var f.e.) if possible |
We can create a small announce. Could you please provide additional info that we should add to mitigate the issue? |
Well, the workaorund would be unset the env var [Environment]::SetEnvironmentVariable("CABAL_DIR", $null ,"Machine") will work for all cases |
/azp run windows2016, windows2019, windows2022 |
Azure Pipelines successfully started running 3 pipeline(s). |
Thanks! Where are the announcements posted btw? |
@hasufell thank you for your contribution. We have decided that the changes are relatively safe and skipped creating the announcement. |
each VM update is recorded/announced as GitHub releases |
A new windows vm release was announced: https://github.com/actions/virtual-environments/releases/tag/win19/20211212.1 |
The bootstrap-haskell.ps1 script uses
[System.EnvironmentVariableTarget]::User
instead of[System.EnvironmentVariableTarget]::Machine
, so it appearsghcup env vars and PATH update never make it. Do these manually
for now.
@newhoggy
haskell/actions#70 (comment)
Can't really say if this works as expected, hence the newly added tests. I tried to be as conservative as possible, so not changing default cabal config directory.