Expose ghcup binary to PATH on windows (#4264)

* Expose ghcup binary to PATH on windows

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.

* Set CABAL_DIR and make sure config is adjusted

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,

* Expose cabal dir to PATH as well

* Use Set-SystemVariable

* Fix tests

* Use hardcoded cabal dir

* Fix bootstrap-haskell

* Move test after installation

* Print ghcup installation message

* Don't adjust cabal.config (to include mingw paths)

This may break setups.
This commit is contained in:
Julian Ospald
2021-12-10 09:23:44 +01:00
committed by GitHub
parent fea7c2e6d1
commit 1fb7d122d1
2 changed files with 31 additions and 4 deletions

View File

@@ -32,8 +32,17 @@ Add-MachinePathItem -PathItem $DefaultGhcPath
Write-Host 'Installing cabal...'
Choco-Install -PackageName cabal
Invoke-PesterTests -TestFile 'Haskell'
# install minimal ghcup, utilizing pre-installed msys2 at C:\msys64
Write-Host 'Installing ghcup...'
$msysPath = "C:\msys64"
$ghcupPrefix = "C:\"
$cabalDir = "C:\cabal"
$bootstrapHaskell = Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing
Invoke-Command -ScriptBlock ([ScriptBlock]::Create($bootstrapHaskell)) -ArgumentList $false, $true, $true, $false, $false, $false, $false, C:\, "", C:\msys64, C:\cabal
Invoke-Command -ScriptBlock ([ScriptBlock]::Create($bootstrapHaskell)) -ArgumentList $false, $true, $true, $false, $true, $false, $false, $ghcupPrefix, "", $msysPath, $cabalDir
Set-SystemVariable "GHCUP_INSTALL_BASE_PREFIX" $ghcupPrefix
Set-SystemVariable "GHCUP_MSYS2" $msysPath
Set-SystemVariable "CABAL_DIR" $cabalDir
Add-MachinePathItem "$ghcupPrefix\ghcup\bin"
Add-MachinePathItem "$cabalDir\bin"
Invoke-PesterTests -TestFile 'Haskell'

View File

@@ -24,6 +24,15 @@ Describe "Haskell" {
}
}
$ghcupEnvExists = @(
@{envVar = "GHCUP_INSTALL_BASE_PREFIX"}
@{envVar = "GHCUP_MSYS2"}
)
It "<envVar> environment variable exists" -TestCases $ghcupEnvExists {
Test-Path env:\$envVar
}
It "Accurate 3 versions of GHC are installed" -TestCases @{ghcCount = $ghcCount} {
$ghcCount | Should -BeExactly 3
}
@@ -39,4 +48,13 @@ Describe "Haskell" {
It "Cabal is installed" {
"cabal --version" | Should -ReturnZeroExitCode
}
}
It "cabal config was modified and exists" {
$env:CABAL_DIR | Should -Exist
"cabal user-config diff" | Should -ReturnZeroExitCode
}
It "ghcup is installed" {
"ghcup --version" | Should -ReturnZeroExitCode
}
}