|
| 1 | +$version = '9.2.6' |
| 2 | +$packageName = 'ghc' |
| 3 | +$url = 'https://downloads.haskell.org/~ghc/8.6.5/ghc-8.6.5-i386-unknown-mingw32.tar.xz' |
| 4 | +$binSha256 = 'bd13aadeeadb3454199eb797961350f0a19275ec74002b2816d1b63093dfd55f' |
| 5 | +$variant = '' |
| 6 | +$pp = Get-PackageParameters |
| 7 | +if ($pp['integer-simple']) { |
| 8 | + $variant = '-integer-simple' |
| 9 | + $binSha256 = 'dd169952cfbd0ae88f811b0b7318676ee5b2f037cb8220ff0082c3c94bbc7d05' |
| 10 | +} |
| 11 | +$baseTarget = 'ghc-' + $version + '-x86_64-unknown-mingw32' |
| 12 | +$target = $baseTarget + $variant |
| 13 | +$url64 = 'https://downloads.haskell.org/~ghc/9.2.6/' + $target + '.tar.xz' |
| 14 | +$is32 = (Get-OSArchitectureWidth 32) -or $env:chocolateyForceX86 -eq 'true' |
| 15 | + |
| 16 | +if($is32) |
| 17 | + { |
| 18 | + Write-Host "# # ####### ####### ### ##### #######" |
| 19 | + Write-Host "## # # # # # # # # " |
| 20 | + Write-Host "# # # # # # # # # " |
| 21 | + Write-Host "# # # # # # # # ##### " |
| 22 | + Write-Host "# # # # # # # # # " |
| 23 | + Write-Host "# ## # # # # # # # " |
| 24 | + Write-Host "# # ####### # ### ##### #######" |
| 25 | + Write-Host "" |
| 26 | + Write-Host " 32 bit binary for Windows is no longer supported." |
| 27 | + Write-Host "GHC 8.6.5 will be installed instead." |
| 28 | + Write-Host "" |
| 29 | + # rewrite the version to 8.6.5 so installer works |
| 30 | + $version = '8.6.5' |
| 31 | + } |
| 32 | + |
| 33 | +# Fixes issue #4 |
| 34 | +if ($pp['installdir']) { |
| 35 | + $binRoot = $pp['installdir'] |
| 36 | +} else { |
| 37 | + $binRoot = Get-ToolsLocation |
| 38 | +} |
| 39 | +$packageFullName = Join-Path $binRoot ($packageName + '-' + $version) |
| 40 | +$binPackageDir = Join-Path $packageFullName "bin" |
| 41 | + |
| 42 | +$tmpPath = Join-Path $packageFullName "tmp" |
| 43 | +$tarFile = $packageName + "Install" |
| 44 | +$tarPath = Join-Path $tmpPath $tarFile |
| 45 | +$tmpFile = Join-Path $binRoot ($tarFile + "~") |
| 46 | + |
| 47 | +Get-ChocolateyWebFile -PackageName $packageName -FileFullPath $tarPath ` |
| 48 | + -Url $url -ChecksumType sha256 -Checksum 2a8fb73080ed4335f7a172fe6cf9da1a2faa51fdb72817c50088292f497fc57a ` |
| 49 | + -Url64bit $url64 -ChecksumType64 sha256 -Checksum64 $binSha256 |
| 50 | +Get-ChocolateyUnzip -fileFullPath $tarPath -destination $binRoot |
| 51 | +Get-ChocolateyUnzip -fileFullPath $tmpFile -destination $binRoot |
| 52 | +rm $tmpFile # Clean up temporary file |
| 53 | + |
| 54 | +# new folders are stupidly long and verbose and break convention. |
| 55 | +# let's normalize them |
| 56 | +$longBinPackageDir = Join-Path $binRoot $baseTarget |
| 57 | +if (Test-Path $longBinPackageDir) { |
| 58 | + # Now delete the extract dir |
| 59 | + Remove-Item -Force -Recurse $packageFullName |
| 60 | + Rename-Item -fo $longBinPackageDir $packageFullName |
| 61 | + Write-Host "Renamed $longBinPackageDir to $packageFullName" |
| 62 | +} |
| 63 | + |
| 64 | +if (Test-Path $tmpPath) { |
| 65 | + # Now delete the tmp path |
| 66 | + Remove-Item -Force -Recurse $tmpPath |
| 67 | +} |
| 68 | + |
| 69 | + |
| 70 | +# FIxes issue #8 |
| 71 | +$installScope = 'User' |
| 72 | +if ($pp['globalinstall'] -eq 'true') { |
| 73 | + $installScope = 'Machine' |
| 74 | + Write-Host "Install scope set to global." |
| 75 | +} |
| 76 | +Install-ChocolateyPath "$binPackageDir" -Machine "$installScope" |
| 77 | + |
| 78 | +# Patch the content of files at a certain line |
| 79 | +function Write-Patch { |
| 80 | + param( [string] $key |
| 81 | + , [string] $fileName |
| 82 | + , [string] $template |
| 83 | + ) |
| 84 | + |
| 85 | + (Get-Content $fileName) | |
| 86 | + Foreach-Object { |
| 87 | + if ($_ -match "$key") |
| 88 | + { |
| 89 | + #Add Lines after the selected pattern |
| 90 | + "$template" |
| 91 | + } |
| 92 | + $_ # send the current line to output |
| 93 | + } | Set-Content $fileName |
| 94 | + |
| 95 | +} |
| 96 | + |
| 97 | +if (-Not $is32 -and -not $pp['no-workarounds']) { |
| 98 | +# HACK: Work around that GHC 9.2.x is missing some components |
| 99 | +# See each individual ticket. |
| 100 | +# Write-Host "`nApplying workarounds for GHC 9.2.3: ` |
| 101 | +# * Broken depencencies: https://gitlab.haskell.org/ghc/ghc/-/issues/21196 ` |
| 102 | +# ` |
| 103 | +# These workarounds do not change the compiler only the packaging, to disable re-run with --params=`"'/no-workarounds'`"`n" |
| 104 | +} |
| 105 | + |
| 106 | +Write-Host "Hiding shims for `'$binRoot`'." |
| 107 | +$files = get-childitem $binRoot -include *.exe -recurse |
| 108 | + |
| 109 | +foreach ($file in $files) { |
| 110 | + #generate an ignore file |
| 111 | + New-Item "$file.ignore" -type file -force | Out-Null |
| 112 | +} |
| 113 | + |
| 114 | +# Detect Github Actions |
| 115 | +if (($null -ne $Env:GITHUB_ACTIONS) -and ("" -ne $Env:GITHUB_ACTIONS)) { |
| 116 | + echo "$binPackageDir" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append |
| 117 | +} |
| 118 | + |
| 119 | +# Detect Azure Pipelines (Fixes issue #9) |
| 120 | +if (($null -ne $Env:TF_BUILD) -and ("" -ne $Env:TF_BUILD)) { |
| 121 | + Write-Host "##vso[task.prependpath]$binPackageDir" |
| 122 | +} |
| 123 | + |
| 124 | +if (($null -ne $Env:TRAVIS) -and ("" -ne $Env:TRAVIS)) { |
| 125 | + Write-Host "Configuring Travis aliases." |
| 126 | + # We need to fix up refreshenv for Travis |
| 127 | + $rc = $Env:HOME + "/.bashrc" |
| 128 | + |
| 129 | + Add-Content $rc "function refreshenv |
| 130 | +{ |
| 131 | + powershell -NonInteractive - <<\EOF |
| 132 | +Import-Module -Force `"`$env:ChocolateyInstall\helpers\chocolateyProfile.psm1`" |
| 133 | +`$pref = `$ErrorActionPreference |
| 134 | +`$ErrorActionPreference = 'SilentlyContinue' |
| 135 | +Update-SessionEnvironment |
| 136 | +`$ErrorActionPreference = `$pref |
| 137 | +# Round brackets in variable names cause problems with bash |
| 138 | +Get-ChildItem env:* | %{ |
| 139 | + if (!(`$_.Name.Contains('('))) { |
| 140 | + `$value = `$_.Value |
| 141 | + if (`$_.Name -eq 'PATH') { |
| 142 | + `$value = `$value -replace ';',':' |
| 143 | + } |
| 144 | + Write-Output (`"export `" + `$_.Name + `"='`" + `$value + `"'`") |
| 145 | + } |
| 146 | +} | Out-File -Encoding ascii $env:TEMP\refreshenv.sh |
| 147 | +EOF |
| 148 | +
|
| 149 | + source `"$env:TEMP/refreshenv.sh`" |
| 150 | +} |
| 151 | +
|
| 152 | +alias RefreshEnv=refreshenv" |
| 153 | + |
| 154 | + Write-Host "Ok, updated ~/.bashrc, source to use refreshenv." |
| 155 | +} |
0 commit comments