Compare commits
159 Commits
PR/issue-1
...
issue-160-
| Author | SHA1 | Date | |
|---|---|---|---|
|
24880616a0
|
|||
|
b862ca52a9
|
|||
|
59e1eee8ce
|
|||
|
57c8ffda35
|
|||
|
171ebd213d
|
|||
|
2a240cbd09
|
|||
|
068fa3454c
|
|||
|
6b2bcbf2ce
|
|||
|
19e46dac18
|
|||
|
e96c863120
|
|||
|
a30b3c84d7
|
|||
|
0ad5dc4583
|
|||
|
7189998f3b
|
|||
|
b6b24b8e0b
|
|||
|
8e820c6e89
|
|||
|
c74784a37c
|
|||
|
3d940cffcf
|
|||
|
0df044b284
|
|||
|
f576b9fb20
|
|||
|
5e00264119
|
|||
|
|
05eeba32fa | ||
|
|
61019ecd49 | ||
|
|
bed06d1334 | ||
|
|
f09f4bd1b7 | ||
|
|
a3b11f21bb | ||
|
|
69a461d9c3 | ||
|
|
1dfe5cfecf | ||
|
|
8e4550657e | ||
|
|
aee7fa52c3 | ||
|
|
d166cc84a1 | ||
|
|
bb7229d224 | ||
|
|
708cd5ead9 | ||
|
|
f7986cb4da | ||
|
|
395aeb415d | ||
|
|
830fb70492 | ||
|
|
6379a26afb | ||
|
|
2277013c76 | ||
|
|
8934e0e6bd | ||
|
|
59519febbc | ||
|
|
46fcdd356c | ||
|
|
9f343c45e8 | ||
|
|
931904f388 | ||
|
|
a40d0cbb5c | ||
|
|
9f5df9db10 | ||
|
|
d26ddf7015 | ||
|
|
9515065407 | ||
|
|
82a8c61cf6 | ||
|
|
3fae516ce4 | ||
|
|
33eaa765d7 | ||
|
|
3b3dde8413 | ||
|
|
118a2744fe | ||
|
|
2e3dceecf8 | ||
|
|
07fb04bb74 | ||
|
|
8a1dbe9dbb | ||
|
|
4ef3622616 | ||
|
|
82a704ab44 | ||
|
|
0cb22945fe | ||
|
|
d09adf9159 | ||
|
|
0b959c56fb | ||
|
|
ec29332657 | ||
|
|
0f6381e67b | ||
|
|
877b55e21d | ||
|
|
fa11ca665f | ||
|
d9d196439f
|
|||
|
a34fc4ad4f
|
|||
|
b4d52b88c1
|
|||
|
3fc3d27361
|
|||
|
56b86add38
|
|||
|
a608a105e3
|
|||
|
2e3e413f6c
|
|||
|
dfb6c09133
|
|||
|
9636276c17
|
|||
|
41783ff027
|
|||
|
08b0ecd057
|
|||
|
7e31798446
|
|||
|
534afa6e8d
|
|||
|
b56c44a210
|
|||
|
ef0c94fddd
|
|||
|
f14c281841
|
|||
|
b40cefee35
|
|||
|
ff32ccfb50
|
|||
|
581108ab65
|
|||
|
54e8e3efb0
|
|||
|
4dcc63606e
|
|||
|
a396b6044d
|
|||
|
94e5d2e19f
|
|||
|
a0976eee70
|
|||
|
61494d8c4b
|
|||
|
2b34c2dd69
|
|||
|
afc30b87dd
|
|||
|
|
ed0a63eb0c | ||
|
9ba590dd90
|
|||
|
d4bffd2c4a
|
|||
|
650f0a3e4e
|
|||
|
fd6ccf8f0a
|
|||
|
d9fe4b8723
|
|||
|
da2e7e0411
|
|||
|
79d6a50e44
|
|||
|
a13a5e5d20
|
|||
|
82743dda2b
|
|||
|
|
6f80dd1fcc | ||
|
1325dce493
|
|||
|
ac21c19b7e
|
|||
|
2b4088d068
|
|||
|
d86dc9b1d7
|
|||
|
9982311c87
|
|||
|
40c88d0b66
|
|||
|
e0ee1c2f94
|
|||
|
b4fa2780eb
|
|||
|
df86183e97
|
|||
|
f7868dc646
|
|||
|
e742be7693
|
|||
|
924bc8698d
|
|||
|
5214c35b20
|
|||
|
700e04535a
|
|||
|
fedc0bbef6
|
|||
|
468fc5ade9
|
|||
|
2c077db36b
|
|||
|
f80638bba4
|
|||
|
860aa0dafd
|
|||
|
27510b3b51
|
|||
|
96bcbbeeec
|
|||
|
8a632eb3b4
|
|||
|
aa992c0e5d
|
|||
|
810870e3a5
|
|||
|
d584e7b21b
|
|||
|
e93ac62c81
|
|||
|
0d7d6c8382
|
|||
|
5cd9ce8835
|
|||
|
443522d526
|
|||
|
9061e60518
|
|||
|
d65ab434b2
|
|||
|
cff592db82
|
|||
|
97029e8102
|
|||
|
|
828fd9eb10 | ||
|
03800d3b74
|
|||
|
a47304e599
|
|||
|
7b050e9fe2
|
|||
|
687a1d0c88
|
|||
|
e09e3c264d
|
|||
|
b56431b4e3
|
|||
|
70ad50010d
|
|||
|
|
ca3a249bea | ||
|
|
4337cdc38d | ||
|
9f92e0bc86
|
|||
|
98751cf8fb
|
|||
|
2f62067d96
|
|||
|
2cb1554244
|
|||
|
6f3c143228
|
|||
|
9793fc6888
|
|||
|
043cab08ae
|
|||
|
b7c83780da
|
|||
|
cff11135ff
|
|||
|
b94a4123eb
|
|||
|
8ef1c8b5d4
|
|||
|
132d331e7c
|
|||
|
734916728c
|
|||
|
5f6ed1292d
|
|||
|
a7dc03af50
|
203
.gitlab-ci.yml
203
.gitlab-ci.yml
@@ -7,7 +7,7 @@ variables:
|
|||||||
GIT_SSL_NO_VERIFY: "1"
|
GIT_SSL_NO_VERIFY: "1"
|
||||||
|
|
||||||
# Commit of ghc/ci-images repository from which to pull Docker images
|
# Commit of ghc/ci-images repository from which to pull Docker images
|
||||||
DOCKER_REV: 1ac7f435c9312f10422a82d304194778378e2a1a
|
DOCKER_REV: 8d0224e6b2a08157649651e69302380b2bd24e11
|
||||||
|
|
||||||
############################################################
|
############################################################
|
||||||
# CI Step
|
# CI Step
|
||||||
@@ -20,6 +20,7 @@ variables:
|
|||||||
variables:
|
variables:
|
||||||
OS: "LINUX"
|
OS: "LINUX"
|
||||||
ARCH: "64"
|
ARCH: "64"
|
||||||
|
CABAL_DIR: "$CI_PROJECT_DIR/cabal"
|
||||||
|
|
||||||
.alpine:64bit:
|
.alpine:64bit:
|
||||||
image: "alpine:3.12"
|
image: "alpine:3.12"
|
||||||
@@ -28,6 +29,7 @@ variables:
|
|||||||
variables:
|
variables:
|
||||||
OS: "LINUX"
|
OS: "LINUX"
|
||||||
ARCH: "64"
|
ARCH: "64"
|
||||||
|
CABAL_DIR: "$CI_PROJECT_DIR/cabal"
|
||||||
|
|
||||||
.alpine:32bit:
|
.alpine:32bit:
|
||||||
image: "i386/alpine:3.12"
|
image: "i386/alpine:3.12"
|
||||||
@@ -36,22 +38,25 @@ variables:
|
|||||||
variables:
|
variables:
|
||||||
OS: "LINUX"
|
OS: "LINUX"
|
||||||
ARCH: "32"
|
ARCH: "32"
|
||||||
|
CABAL_DIR: "$CI_PROJECT_DIR/cabal"
|
||||||
|
|
||||||
.linux:armv7:
|
.linux:armv7:
|
||||||
image: "arm32v7/fedora"
|
image: "registry.gitlab.haskell.org/ghc/ci-images/armv7-linux-deb10:$DOCKER_REV"
|
||||||
tags:
|
tags:
|
||||||
- armv7-linux
|
- armv7-linux
|
||||||
variables:
|
variables:
|
||||||
OS: "LINUX"
|
OS: "LINUX"
|
||||||
ARCH: "ARM"
|
ARCH: "ARM"
|
||||||
|
CABAL_DIR: "$CI_PROJECT_DIR/cabal"
|
||||||
|
|
||||||
.linux:aarch64:
|
.linux:aarch64:
|
||||||
image: "arm64v8/fedora"
|
image: "registry.gitlab.haskell.org/ghc/ci-images/aarch64-linux-deb10:$DOCKER_REV"
|
||||||
tags:
|
tags:
|
||||||
- aarch64-linux
|
- aarch64-linux
|
||||||
variables:
|
variables:
|
||||||
OS: "LINUX"
|
OS: "LINUX"
|
||||||
ARCH: "ARM64"
|
ARCH: "ARM64"
|
||||||
|
CABAL_DIR: "$CI_PROJECT_DIR/cabal"
|
||||||
|
|
||||||
.darwin:
|
.darwin:
|
||||||
tags:
|
tags:
|
||||||
@@ -59,6 +64,15 @@ variables:
|
|||||||
variables:
|
variables:
|
||||||
OS: "DARWIN"
|
OS: "DARWIN"
|
||||||
ARCH: "64"
|
ARCH: "64"
|
||||||
|
CABAL_DIR: "$CI_PROJECT_DIR/cabal"
|
||||||
|
|
||||||
|
.darwin:aarch64:
|
||||||
|
tags:
|
||||||
|
- aarch64-darwin-m1
|
||||||
|
variables:
|
||||||
|
OS: "DARWIN"
|
||||||
|
ARCH: "ARM64"
|
||||||
|
CABAL_DIR: "$CI_PROJECT_DIR/cabal"
|
||||||
|
|
||||||
.freebsd:
|
.freebsd:
|
||||||
tags:
|
tags:
|
||||||
@@ -66,22 +80,25 @@ variables:
|
|||||||
variables:
|
variables:
|
||||||
OS: "FREEBSD"
|
OS: "FREEBSD"
|
||||||
ARCH: "64"
|
ARCH: "64"
|
||||||
|
CABAL_DIR: "$CI_PROJECT_DIR/cabal"
|
||||||
|
|
||||||
|
.windows:
|
||||||
|
tags:
|
||||||
|
- new-x86_64-windows
|
||||||
|
variables:
|
||||||
|
OS: "WINDOWS"
|
||||||
|
ARCH: "64"
|
||||||
|
CABAL_DIR: "$CI_PROJECT_DIR/cabal"
|
||||||
|
|
||||||
.root_cleanup:
|
.root_cleanup:
|
||||||
after_script:
|
after_script:
|
||||||
- BUILD_DIR=$CI_PROJECT_DIR
|
- bash ./.gitlab/after_script.sh
|
||||||
- echo "Cleaning $BUILD_DIR"
|
|
||||||
- cd $HOME
|
|
||||||
- test -n "$BUILD_DIR"
|
|
||||||
- shopt -s extglob
|
|
||||||
- rm -Rf "$BUILD_DIR"/!(out)
|
|
||||||
- exit 0
|
|
||||||
|
|
||||||
.test_ghcup_version:
|
.test_ghcup_version:
|
||||||
script:
|
script:
|
||||||
- ./.gitlab/script/ghcup_version.sh
|
- bash ./.gitlab/script/ghcup_version.sh
|
||||||
variables:
|
variables:
|
||||||
JSON_VERSION: "0.0.4"
|
JSON_VERSION: "0.0.5"
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 2 week
|
expire_in: 2 week
|
||||||
paths:
|
paths:
|
||||||
@@ -107,14 +124,14 @@ variables:
|
|||||||
- .test_ghcup_version
|
- .test_ghcup_version
|
||||||
- .linux:armv7
|
- .linux:armv7
|
||||||
before_script:
|
before_script:
|
||||||
- ./.gitlab/before_script/linux/install_deps_manual.sh
|
- ./.gitlab/before_script/linux/install_deps.sh
|
||||||
|
|
||||||
.test_ghcup_version:aarch64:
|
.test_ghcup_version:aarch64:
|
||||||
extends:
|
extends:
|
||||||
- .test_ghcup_version
|
- .test_ghcup_version
|
||||||
- .linux:aarch64
|
- .linux:aarch64
|
||||||
before_script:
|
before_script:
|
||||||
- ./.gitlab/before_script/linux/install_deps_manual.sh
|
- ./.gitlab/before_script/linux/install_deps.sh
|
||||||
|
|
||||||
.test_ghcup_version:darwin:
|
.test_ghcup_version:darwin:
|
||||||
extends:
|
extends:
|
||||||
@@ -124,6 +141,32 @@ variables:
|
|||||||
before_script:
|
before_script:
|
||||||
- ./.gitlab/before_script/darwin/install_deps.sh
|
- ./.gitlab/before_script/darwin/install_deps.sh
|
||||||
|
|
||||||
|
.test_ghcup_version:darwin:aarch64:
|
||||||
|
extends:
|
||||||
|
- .test_ghcup_version
|
||||||
|
- .darwin:aarch64
|
||||||
|
- .root_cleanup
|
||||||
|
script: |
|
||||||
|
set -Eeuo pipefail
|
||||||
|
function runInNixShell() {
|
||||||
|
time nix-shell $CI_PROJECT_DIR/.gitlab/shell.nix \
|
||||||
|
-I nixpkgs=https://github.com/angerman/nixpkgs/archive/75f7281738b.tar.gz \
|
||||||
|
--argstr system "aarch64-darwin" \
|
||||||
|
--pure \
|
||||||
|
--keep CI_PROJECT_DIR \
|
||||||
|
--keep MACOSX_DEPLOYMENT_TARGET \
|
||||||
|
--keep JSON_VERSION \
|
||||||
|
--keep ARTIFACT \
|
||||||
|
--keep OS \
|
||||||
|
--keep ARCH \
|
||||||
|
--keep CABAL_DIR \
|
||||||
|
--keep GHC_VERSION \
|
||||||
|
--keep CABAL_VERSION \
|
||||||
|
--run "$1" 2>&1
|
||||||
|
}
|
||||||
|
runInNixShell ./.gitlab/before_script/darwin/install_deps.sh 2>&1
|
||||||
|
runInNixShell ./.gitlab/script/ghcup_version.sh 2>&1
|
||||||
|
|
||||||
.test_ghcup_version:freebsd:
|
.test_ghcup_version:freebsd:
|
||||||
extends:
|
extends:
|
||||||
- .test_ghcup_version
|
- .test_ghcup_version
|
||||||
@@ -132,9 +175,18 @@ variables:
|
|||||||
before_script:
|
before_script:
|
||||||
- ./.gitlab/before_script/freebsd/install_deps.sh
|
- ./.gitlab/before_script/freebsd/install_deps.sh
|
||||||
|
|
||||||
|
.test_ghcup_version:windows:
|
||||||
|
extends:
|
||||||
|
- .test_ghcup_version
|
||||||
|
- .windows
|
||||||
|
- .root_cleanup
|
||||||
|
before_script:
|
||||||
|
- set CABAL_DIR="$CI_PROJECT_DIR/cabal"
|
||||||
|
- bash ./.gitlab/before_script/windows/install_deps.sh
|
||||||
|
|
||||||
.release_ghcup:
|
.release_ghcup:
|
||||||
script:
|
script:
|
||||||
- ./.gitlab/script/ghcup_release.sh
|
- bash ./.gitlab/script/ghcup_release.sh
|
||||||
artifacts:
|
artifacts:
|
||||||
expire_in: 2 week
|
expire_in: 2 week
|
||||||
paths:
|
paths:
|
||||||
@@ -142,7 +194,7 @@ variables:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
variables:
|
variables:
|
||||||
JSON_VERSION: "0.0.4"
|
JSON_VERSION: "0.0.5"
|
||||||
|
|
||||||
######## stack test ########
|
######## stack test ########
|
||||||
|
|
||||||
@@ -165,10 +217,27 @@ test:linux:bootstrap_script:
|
|||||||
script:
|
script:
|
||||||
- ./.gitlab/script/ghcup_bootstrap.sh
|
- ./.gitlab/script/ghcup_bootstrap.sh
|
||||||
variables:
|
variables:
|
||||||
GHC_VERSION: "8.10.4"
|
GHC_VERSION: "8.10.5"
|
||||||
CABAL_VERSION: "3.4.0.0"
|
CABAL_VERSION: "3.4.0.0"
|
||||||
extends:
|
extends:
|
||||||
- .debian
|
- .debian
|
||||||
|
- .root_cleanup
|
||||||
|
needs: []
|
||||||
|
|
||||||
|
test:windows:bootstrap_powershell_script:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- ./bootstrap-haskell.ps1 -InstallDir $CI_PROJECT_DIR -BootstrapUrl $CI_PROJECT_DIR/bootstrap-haskell -InBash
|
||||||
|
after_script:
|
||||||
|
- "[Environment]::SetEnvironmentVariable('GHCUP_INSTALL_BASE_PREFIX', $null, [System.EnvironmentVariableTarget]::User)"
|
||||||
|
- "[Environment]::SetEnvironmentVariable('GHCUP_MSYS2', $null, [System.EnvironmentVariableTarget]::User)"
|
||||||
|
- "[Environment]::SetEnvironmentVariable('CABAL_DIR', $null, [System.EnvironmentVariableTarget]::User)"
|
||||||
|
- bash ./.gitlab/after_script.sh
|
||||||
|
variables:
|
||||||
|
GHC_VERSION: "8.10.5"
|
||||||
|
CABAL_VERSION: "3.4.0.0"
|
||||||
|
extends:
|
||||||
|
- .windows
|
||||||
needs: []
|
needs: []
|
||||||
|
|
||||||
######## linux test ########
|
######## linux test ########
|
||||||
@@ -177,7 +246,7 @@ test:linux:recommended:
|
|||||||
stage: test
|
stage: test
|
||||||
extends: .test_ghcup_version:linux
|
extends: .test_ghcup_version:linux
|
||||||
variables:
|
variables:
|
||||||
GHC_VERSION: "8.10.4"
|
GHC_VERSION: "8.10.5"
|
||||||
CABAL_VERSION: "3.4.0.0"
|
CABAL_VERSION: "3.4.0.0"
|
||||||
needs: []
|
needs: []
|
||||||
|
|
||||||
@@ -185,7 +254,7 @@ test:linux:latest:
|
|||||||
stage: test
|
stage: test
|
||||||
extends: .test_ghcup_version:linux
|
extends: .test_ghcup_version:linux
|
||||||
variables:
|
variables:
|
||||||
GHC_VERSION: "8.10.4"
|
GHC_VERSION: "9.0.1"
|
||||||
CABAL_VERSION: "3.4.0.0"
|
CABAL_VERSION: "3.4.0.0"
|
||||||
needs: []
|
needs: []
|
||||||
|
|
||||||
@@ -195,7 +264,7 @@ test:linux:recommended:32bit:
|
|||||||
stage: test
|
stage: test
|
||||||
extends: .test_ghcup_version:linux32
|
extends: .test_ghcup_version:linux32
|
||||||
variables:
|
variables:
|
||||||
GHC_VERSION: "8.10.4"
|
GHC_VERSION: "8.10.5"
|
||||||
CABAL_VERSION: "3.2.0.0"
|
CABAL_VERSION: "3.2.0.0"
|
||||||
needs: []
|
needs: []
|
||||||
|
|
||||||
@@ -233,10 +302,19 @@ test:mac:latest:
|
|||||||
stage: test
|
stage: test
|
||||||
extends: .test_ghcup_version:darwin
|
extends: .test_ghcup_version:darwin
|
||||||
variables:
|
variables:
|
||||||
GHC_VERSION: "8.10.4"
|
GHC_VERSION: "9.0.1"
|
||||||
CABAL_VERSION: "3.4.0.0"
|
CABAL_VERSION: "3.4.0.0"
|
||||||
needs: []
|
needs: []
|
||||||
|
|
||||||
|
test:mac:recommended:aarch64:
|
||||||
|
stage: test
|
||||||
|
extends: .test_ghcup_version:darwin:aarch64
|
||||||
|
variables:
|
||||||
|
GHC_VERSION: "8.10.5"
|
||||||
|
CABAL_VERSION: "3.4.0.0"
|
||||||
|
needs: []
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
|
||||||
######## freebsd test ########
|
######## freebsd test ########
|
||||||
|
|
||||||
@@ -250,16 +328,15 @@ test:freebsd:recommended:
|
|||||||
when: manual
|
when: manual
|
||||||
needs: []
|
needs: []
|
||||||
|
|
||||||
test:freebsd:latest:
|
######## windows test ########
|
||||||
stage: test
|
|
||||||
extends: .test_ghcup_version:freebsd
|
|
||||||
variables:
|
|
||||||
GHC_VERSION: "8.10.4"
|
|
||||||
CABAL_VERSION: "3.4.0.0"
|
|
||||||
allow_failure: true # freebsd runners are unreliable
|
|
||||||
when: manual
|
|
||||||
needs: []
|
|
||||||
|
|
||||||
|
test:windows:recommended:
|
||||||
|
stage: test
|
||||||
|
extends: .test_ghcup_version:windows
|
||||||
|
variables:
|
||||||
|
GHC_VERSION: "8.10.5"
|
||||||
|
CABAL_VERSION: "3.4.0.0"
|
||||||
|
needs: []
|
||||||
|
|
||||||
######## linux release ########
|
######## linux release ########
|
||||||
|
|
||||||
@@ -273,7 +350,7 @@ release:linux:64bit:
|
|||||||
- ./.gitlab/before_script/linux/alpine/install_deps.sh
|
- ./.gitlab/before_script/linux/alpine/install_deps.sh
|
||||||
variables:
|
variables:
|
||||||
ARTIFACT: "x86_64-linux-ghcup"
|
ARTIFACT: "x86_64-linux-ghcup"
|
||||||
GHC_VERSION: "8.10.4"
|
GHC_VERSION: "8.10.5"
|
||||||
CABAL_VERSION: "3.4.0.0"
|
CABAL_VERSION: "3.4.0.0"
|
||||||
|
|
||||||
|
|
||||||
@@ -287,7 +364,7 @@ release:linux:32bit:
|
|||||||
- ./.gitlab/before_script/linux/alpine/install_deps.sh
|
- ./.gitlab/before_script/linux/alpine/install_deps.sh
|
||||||
variables:
|
variables:
|
||||||
ARTIFACT: "i386-linux-ghcup"
|
ARTIFACT: "i386-linux-ghcup"
|
||||||
GHC_VERSION: "8.10.4"
|
GHC_VERSION: "8.10.5"
|
||||||
CABAL_VERSION: "3.2.0.0"
|
CABAL_VERSION: "3.2.0.0"
|
||||||
|
|
||||||
release:linux:armv7:
|
release:linux:armv7:
|
||||||
@@ -297,7 +374,7 @@ release:linux:armv7:
|
|||||||
- .linux:armv7
|
- .linux:armv7
|
||||||
- .release_ghcup
|
- .release_ghcup
|
||||||
before_script:
|
before_script:
|
||||||
- ./.gitlab/before_script/linux/install_deps_manual.sh
|
- ./.gitlab/before_script/linux/install_deps.sh
|
||||||
variables:
|
variables:
|
||||||
ARTIFACT: "armv7-linux-ghcup"
|
ARTIFACT: "armv7-linux-ghcup"
|
||||||
GHC_VERSION: "8.10.4"
|
GHC_VERSION: "8.10.4"
|
||||||
@@ -310,7 +387,7 @@ release:linux:aarch64:
|
|||||||
- .linux:aarch64
|
- .linux:aarch64
|
||||||
- .release_ghcup
|
- .release_ghcup
|
||||||
before_script:
|
before_script:
|
||||||
- ./.gitlab/before_script/linux/install_deps_manual.sh
|
- ./.gitlab/before_script/linux/install_deps.sh
|
||||||
variables:
|
variables:
|
||||||
ARTIFACT: "aarch64-linux-ghcup"
|
ARTIFACT: "aarch64-linux-ghcup"
|
||||||
GHC_VERSION: "8.10.4"
|
GHC_VERSION: "8.10.4"
|
||||||
@@ -329,16 +406,50 @@ release:darwin:
|
|||||||
- ./.gitlab/before_script/darwin/install_deps.sh
|
- ./.gitlab/before_script/darwin/install_deps.sh
|
||||||
variables:
|
variables:
|
||||||
ARTIFACT: "x86_64-apple-darwin-ghcup"
|
ARTIFACT: "x86_64-apple-darwin-ghcup"
|
||||||
GHC_VERSION: "8.10.4"
|
GHC_VERSION: "8.10.5"
|
||||||
CABAL_VERSION: "3.4.0.0"
|
CABAL_VERSION: "3.4.0.0"
|
||||||
MACOSX_DEPLOYMENT_TARGET: "10.7"
|
MACOSX_DEPLOYMENT_TARGET: "10.7"
|
||||||
|
|
||||||
|
release:darwin:aarch64:
|
||||||
|
stage: release
|
||||||
|
needs: ["test:mac:recommended:aarch64"]
|
||||||
|
extends:
|
||||||
|
- .darwin:aarch64
|
||||||
|
- .release_ghcup
|
||||||
|
- .root_cleanup
|
||||||
|
script: |
|
||||||
|
set -Eeuo pipefail
|
||||||
|
function runInNixShell() {
|
||||||
|
time nix-shell .gitlab/shell.nix \
|
||||||
|
-I nixpkgs=https://github.com/angerman/nixpkgs/archive/75f7281738b.tar.gz \
|
||||||
|
--argstr system "aarch64-darwin" \
|
||||||
|
--pure \
|
||||||
|
--keep CI_PROJECT_DIR \
|
||||||
|
--keep MACOSX_DEPLOYMENT_TARGET \
|
||||||
|
--keep JSON_VERSION \
|
||||||
|
--keep ARTIFACT \
|
||||||
|
--keep OS \
|
||||||
|
--keep ARCH \
|
||||||
|
--keep CABAL_DIR \
|
||||||
|
--keep GHC_VERSION \
|
||||||
|
--keep CABAL_VERSION \
|
||||||
|
--run "$1" 2>&1
|
||||||
|
}
|
||||||
|
runInNixShell ./.gitlab/before_script/darwin/install_deps.sh 2>&1
|
||||||
|
runInNixShell ./.gitlab/script/ghcup_release.sh 2>&1
|
||||||
|
variables:
|
||||||
|
ARTIFACT: "aarch64-apple-darwin-ghcup"
|
||||||
|
GHC_VERSION: "8.10.5"
|
||||||
|
CABAL_VERSION: "3.4.0.0"
|
||||||
|
MACOSX_DEPLOYMENT_TARGET: "10.7"
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
|
||||||
######## freebsd release ########
|
######## freebsd release ########
|
||||||
|
|
||||||
release:freebsd:
|
release:freebsd:
|
||||||
stage: release
|
stage: release
|
||||||
needs: ["test:freebsd:recommended", "test:freebsd:latest"]
|
needs: ["test:freebsd:recommended"]
|
||||||
extends:
|
extends:
|
||||||
- .freebsd
|
- .freebsd
|
||||||
- .release_ghcup
|
- .release_ghcup
|
||||||
@@ -347,9 +458,25 @@ release:freebsd:
|
|||||||
- ./.gitlab/before_script/freebsd/install_deps.sh
|
- ./.gitlab/before_script/freebsd/install_deps.sh
|
||||||
variables:
|
variables:
|
||||||
ARTIFACT: "x86_64-portbld-freebsd-ghcup"
|
ARTIFACT: "x86_64-portbld-freebsd-ghcup"
|
||||||
GHC_VERSION: "8.10.4"
|
GHC_VERSION: "8.10.5"
|
||||||
CABAL_VERSION: "3.4.0.0"
|
CABAL_VERSION: "3.4.0.0"
|
||||||
|
allow_failure: true
|
||||||
|
|
||||||
|
######## windows release ########
|
||||||
|
|
||||||
|
release:windows:
|
||||||
|
stage: release
|
||||||
|
needs: ["test:windows:recommended"]
|
||||||
|
extends:
|
||||||
|
- .windows
|
||||||
|
- .release_ghcup
|
||||||
|
- .root_cleanup
|
||||||
|
before_script:
|
||||||
|
- bash ./.gitlab/before_script/windows/install_deps.sh
|
||||||
|
variables:
|
||||||
|
ARTIFACT: "x86_64-mingw64-ghcup"
|
||||||
|
GHC_VERSION: "8.10.5"
|
||||||
|
CABAL_VERSION: "3.4.0.0"
|
||||||
|
|
||||||
######## hlint ########
|
######## hlint ########
|
||||||
|
|
||||||
@@ -362,7 +489,7 @@ hlint:
|
|||||||
script:
|
script:
|
||||||
- ./.gitlab/script/hlint.sh
|
- ./.gitlab/script/hlint.sh
|
||||||
variables:
|
variables:
|
||||||
GHC_VERSION: "8.10.4"
|
GHC_VERSION: "8.10.5"
|
||||||
CABAL_VERSION: "3.4.0.0"
|
CABAL_VERSION: "3.4.0.0"
|
||||||
JSON_VERSION: "0.0.4"
|
JSON_VERSION: "0.0.4"
|
||||||
allow_failure: true
|
allow_failure: true
|
||||||
|
|||||||
15
.gitlab/after_script.sh
Normal file
15
.gitlab/after_script.sh
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
BUILD_DIR=$CI_PROJECT_DIR
|
||||||
|
echo "Cleaning $BUILD_DIR"
|
||||||
|
cd $HOME
|
||||||
|
test -n "$BUILD_DIR"
|
||||||
|
shopt -s extglob
|
||||||
|
rm -Rf "$BUILD_DIR"/!(out)
|
||||||
|
if [ "${OS}" = "WINDOWS" ] ; then
|
||||||
|
rm -Rf /c/ghcup
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
@@ -6,12 +6,27 @@ set -eux
|
|||||||
|
|
||||||
mkdir -p "${TMPDIR}"
|
mkdir -p "${TMPDIR}"
|
||||||
|
|
||||||
curl -sSfL https://downloads.haskell.org/~ghcup/x86_64-apple-darwin-ghcup > ./ghcup-bin
|
if [ $ARCH = 'ARM64' ] ; then
|
||||||
chmod +x ghcup-bin
|
curl -sSfL https://downloads.haskell.org/~ghcup/0.1.15.1/aarch64-apple-darwin-ghcup-0.1.15.1 > ./ghcup-bin
|
||||||
|
chmod +x ghcup-bin
|
||||||
|
else
|
||||||
|
curl -sSfL https://downloads.haskell.org/~ghcup/x86_64-apple-darwin-ghcup > ./ghcup-bin
|
||||||
|
chmod +x ghcup-bin
|
||||||
|
./ghcup-bin upgrade -i -f
|
||||||
|
fi
|
||||||
|
|
||||||
./ghcup-bin upgrade -i -f
|
./ghcup-bin install ${GHC_VERSION}
|
||||||
./ghcup-bin -s file://$(pwd)/ghcup-${JSON_VERSION}.yaml install ${GHC_VERSION}
|
./ghcup-bin set ${GHC_VERSION}
|
||||||
./ghcup-bin -s file://$(pwd)/ghcup-${JSON_VERSION}.yaml set ${GHC_VERSION}
|
./ghcup-bin install-cabal ${CABAL_VERSION}
|
||||||
./ghcup-bin -s file://$(pwd)/ghcup-${JSON_VERSION}.yaml install-cabal ${CABAL_VERSION}
|
|
||||||
|
if [ $ARCH = 'ARM64' ] ; then
|
||||||
|
cabal update
|
||||||
|
mkdir vendored
|
||||||
|
cd vendored
|
||||||
|
cabal unpack network-3.1.2.1
|
||||||
|
cd network*
|
||||||
|
autoreconf -fi
|
||||||
|
cd ../..
|
||||||
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ curl -sSfL https://downloads.haskell.org/~ghcup/x86_64-portbld-freebsd-ghcup > .
|
|||||||
chmod +x ghcup-bin
|
chmod +x ghcup-bin
|
||||||
|
|
||||||
./ghcup-bin upgrade -i -f
|
./ghcup-bin upgrade -i -f
|
||||||
./ghcup-bin -s file://$(pwd)/ghcup-${JSON_VERSION}.yaml install ${GHC_VERSION}
|
./ghcup-bin install ${GHC_VERSION}
|
||||||
./ghcup-bin -s file://$(pwd)/ghcup-${JSON_VERSION}.yaml set ${GHC_VERSION}
|
./ghcup-bin set ${GHC_VERSION}
|
||||||
./ghcup-bin -s file://$(pwd)/ghcup-${JSON_VERSION}.yaml install-cabal ${CABAL_VERSION}
|
./ghcup-bin install-cabal ${CABAL_VERSION}
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|||||||
@@ -28,8 +28,8 @@ else
|
|||||||
fi
|
fi
|
||||||
chmod +x ghcup-bin
|
chmod +x ghcup-bin
|
||||||
./ghcup-bin upgrade -i -f
|
./ghcup-bin upgrade -i -f
|
||||||
./ghcup-bin -s file://$(pwd)/ghcup-${JSON_VERSION}.yaml install ${GHC_VERSION}
|
./ghcup-bin install ${GHC_VERSION}
|
||||||
./ghcup-bin -s file://$(pwd)/ghcup-${JSON_VERSION}.yaml install-cabal ${CABAL_VERSION}
|
./ghcup-bin install-cabal ${CABAL_VERSION}
|
||||||
|
|
||||||
# utils
|
# utils
|
||||||
apk add --no-cache \
|
apk add --no-cache \
|
||||||
@@ -41,6 +41,9 @@ apk add --no-cache \
|
|||||||
zlib \
|
zlib \
|
||||||
zlib-dev \
|
zlib-dev \
|
||||||
zlib-static \
|
zlib-static \
|
||||||
|
bzip2 \
|
||||||
|
bzip2-dev \
|
||||||
|
bzip2-static \
|
||||||
gmp \
|
gmp \
|
||||||
gmp-dev \
|
gmp-dev \
|
||||||
openssl-dev \
|
openssl-dev \
|
||||||
|
|||||||
@@ -7,13 +7,60 @@ set -eux
|
|||||||
mkdir -p "${TMPDIR}"
|
mkdir -p "${TMPDIR}"
|
||||||
|
|
||||||
sudo apt-get update -y
|
sudo apt-get update -y
|
||||||
sudo apt-get install -y libnuma-dev zlib1g-dev libgmp-dev libgmp10 libssl-dev liblzma-dev git wget
|
sudo apt-get install -y libnuma-dev zlib1g-dev libgmp-dev libgmp10 libssl-dev liblzma-dev libbz2-dev git wget lsb-release software-properties-common gnupg2 apt-transport-https
|
||||||
|
|
||||||
curl -sSfL https://downloads.haskell.org/~ghcup/x86_64-linux-ghcup > ./ghcup-bin
|
case "${ARCH}" in
|
||||||
chmod +x ghcup-bin
|
ARM*)
|
||||||
|
case "${ARCH}" in
|
||||||
|
"ARM")
|
||||||
|
ghc_url=https://downloads.haskell.org/~ghc/${GHC_VERSION}/ghc-${GHC_VERSION}-armv7-deb10-linux.tar.xz
|
||||||
|
cabal_url=home.smart-cactus.org/~ben/cabal-install-${CABAL_VERSION}-armv7-linux-bootstrapped.tar.xz
|
||||||
|
;;
|
||||||
|
"ARM64")
|
||||||
|
ghc_url=https://downloads.haskell.org/~ghc/${GHC_VERSION}/ghc-${GHC_VERSION}-aarch64-deb10-linux.tar.xz
|
||||||
|
cabal_url=https://downloads.haskell.org/~cabal/cabal-install-${CABAL_VERSION}/cabal-install-${CABAL_VERSION}-aarch64-ubuntu-18.04.tar.xz
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
exit 1 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
./ghcup-bin upgrade -i -f
|
mkdir -p "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin
|
||||||
./ghcup-bin -s file://$(pwd)/ghcup-${JSON_VERSION}.yaml install ${GHC_VERSION}
|
|
||||||
./ghcup-bin -s file://$(pwd)/ghcup-${JSON_VERSION}.yaml set ${GHC_VERSION}
|
curl -O "${ghc_url}"
|
||||||
./ghcup-bin -s file://$(pwd)/ghcup-${JSON_VERSION}.yaml install-cabal ${CABAL_VERSION}
|
tar -xf ghc-*.tar.*
|
||||||
|
cd ghc-${GHC_VERSION}
|
||||||
|
./configure --prefix="${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/ghc/${GHC_VERSION}
|
||||||
|
make install
|
||||||
|
for i in "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/ghc/${GHC_VERSION}/bin/*-${GHC_VERSION} ; do
|
||||||
|
ln -s "${i}" "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin/${i##*/}
|
||||||
|
done
|
||||||
|
for x in "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin/*-${GHC_VERSION} ; do
|
||||||
|
ln -s ${x##*/} ${x%-${GHC_VERSION}}
|
||||||
|
done
|
||||||
|
cd ..
|
||||||
|
rm -rf ghc-${GHC_VERSION} ghc-*.tar.*
|
||||||
|
unset x i
|
||||||
|
|
||||||
|
mkdir cabal-install
|
||||||
|
cd cabal-install
|
||||||
|
curl -O "${cabal_url}"
|
||||||
|
tar -xf cabal-install-*
|
||||||
|
mv cabal "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin/cabal
|
||||||
|
cd ..
|
||||||
|
rm -rf cabal-install
|
||||||
|
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
url=https://downloads.haskell.org/~ghcup/x86_64-linux-ghcup
|
||||||
|
|
||||||
|
curl -sSfL "${url}" > ./ghcup-bin
|
||||||
|
chmod +x ghcup-bin
|
||||||
|
|
||||||
|
./ghcup-bin upgrade -i -f
|
||||||
|
./ghcup-bin install ${GHC_VERSION}
|
||||||
|
./ghcup-bin set ${GHC_VERSION}
|
||||||
|
./ghcup-bin install-cabal ${CABAL_VERSION}
|
||||||
|
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -eux
|
|
||||||
|
|
||||||
. "$( cd "$(dirname "$0")" ; pwd -P )/../../ghcup_env"
|
|
||||||
|
|
||||||
mkdir -p "${TMPDIR}"
|
|
||||||
|
|
||||||
ednf() {
|
|
||||||
case "${ARCH}" in
|
|
||||||
"ARM")
|
|
||||||
sudo dnf -y --forcearch armv7hl "$@"
|
|
||||||
;;
|
|
||||||
"ARM64")
|
|
||||||
sudo dnf -y --forcearch aarch64 "$@"
|
|
||||||
;;
|
|
||||||
*) exit 1 ;;
|
|
||||||
esac
|
|
||||||
}
|
|
||||||
|
|
||||||
ednf update
|
|
||||||
ednf install gcc gcc-c++ gmp gmp-devel make ncurses ncurses-devel xz xz-devel perl zlib zlib-devel openssl-devel openssl-libs openssl libffi libffi-devel lbzip2 lbzip2-utils
|
|
||||||
if [ "${ARCH}" = "ARM64" ] ; then
|
|
||||||
ednf install numactl numactl-libs numactl-devel
|
|
||||||
fi
|
|
||||||
ednf install bash wget curl git tar
|
|
||||||
ednf install llvm9.0 llvm9.0-devel llvm9.0-libs llvm9.0-static
|
|
||||||
|
|
||||||
case "${ARCH}" in
|
|
||||||
"ARM")
|
|
||||||
ghc_url=https://downloads.haskell.org/~ghc/${GHC_VERSION}/ghc-${GHC_VERSION}-armv7-deb10-linux.tar.xz
|
|
||||||
cabal_url=home.smart-cactus.org/~ben/cabal-install-${CABAL_VERSION}-armv7-linux-bootstrapped.tar.xz
|
|
||||||
;;
|
|
||||||
"ARM64")
|
|
||||||
ghc_url=https://downloads.haskell.org/~ghc/${GHC_VERSION}/ghc-${GHC_VERSION}-aarch64-deb10-linux.tar.xz
|
|
||||||
cabal_url=https://downloads.haskell.org/~cabal/cabal-install-${CABAL_VERSION}/cabal-install-${CABAL_VERSION}-aarch64-ubuntu-18.04.tar.xz
|
|
||||||
;;
|
|
||||||
*) exit 1 ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
mkdir -p "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin
|
|
||||||
|
|
||||||
curl -O "${ghc_url}"
|
|
||||||
tar -xf ghc-*.tar.*
|
|
||||||
cd ghc-${GHC_VERSION}
|
|
||||||
./configure --prefix="${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/ghc/${GHC_VERSION}
|
|
||||||
make install
|
|
||||||
for i in "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/ghc/${GHC_VERSION}/bin/*-${GHC_VERSION} ; do
|
|
||||||
ln -s "${i}" "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin/${i##*/}
|
|
||||||
done
|
|
||||||
for x in "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin/*-${GHC_VERSION} ; do
|
|
||||||
ln -s ${x##*/} ${x%-${GHC_VERSION}}
|
|
||||||
done
|
|
||||||
cd ..
|
|
||||||
rm -rf ghc-${GHC_VERSION} ghc-*.tar.*
|
|
||||||
unset x i
|
|
||||||
|
|
||||||
mkdir cabal-install
|
|
||||||
cd cabal-install
|
|
||||||
curl -O "${cabal_url}"
|
|
||||||
tar -xf cabal-install-*
|
|
||||||
mv cabal "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin/cabal
|
|
||||||
cd ..
|
|
||||||
rm -rf cabal-install
|
|
||||||
@@ -7,4 +7,4 @@ set -eux
|
|||||||
mkdir -p "${TMPDIR}"
|
mkdir -p "${TMPDIR}"
|
||||||
|
|
||||||
sudo apt-get update -y
|
sudo apt-get update -y
|
||||||
sudo apt-get install -y libnuma-dev zlib1g-dev libgmp-dev libgmp10 libssl-dev liblzma-dev git wget
|
sudo apt-get install -y libnuma-dev zlib1g-dev libgmp-dev libgmp10 libssl-dev liblzma-dev libbz2-dev git wget
|
||||||
|
|||||||
21
.gitlab/before_script/windows/install_deps.sh
Normal file
21
.gitlab/before_script/windows/install_deps.sh
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
. "$( cd "$(dirname "$0")" ; pwd -P )/../../ghcup_env"
|
||||||
|
|
||||||
|
mkdir -p "${TMPDIR}" "${CABAL_DIR}"
|
||||||
|
|
||||||
|
mkdir -p "$GHCUP_INSTALL_BASE_PREFIX/ghcup/bin"
|
||||||
|
|
||||||
|
CI_PROJECT_DIR=$(pwd)
|
||||||
|
curl -o ghcup.exe https://downloads.haskell.org/~ghcup/0.1.15.1/x86_64-mingw64-ghcup-0.1.15.1.exe
|
||||||
|
chmod +x ghcup.exe
|
||||||
|
|
||||||
|
./ghcup.exe install ${GHC_VERSION}
|
||||||
|
./ghcup.exe set ${GHC_VERSION}
|
||||||
|
./ghcup.exe install-cabal ${CABAL_VERSION}
|
||||||
|
|
||||||
|
rm ./ghcup.exe
|
||||||
|
|
||||||
|
exit 0
|
||||||
@@ -1,3 +1,9 @@
|
|||||||
export GHCUP_INSTALL_BASE_PREFIX="$CI_PROJECT_DIR"
|
if [ "${OS}" = "WINDOWS" ] ; then
|
||||||
export PATH="$CI_PROJECT_DIR/.ghcup/bin:$CI_PROJECT_DIR/.local/bin:$PATH"
|
export GHCUP_INSTALL_BASE_PREFIX="$CI_PROJECT_DIR"
|
||||||
export TMPDIR="$CI_PROJECT_DIR/tmp"
|
export PATH="$GHCUP_INSTALL_BASE_PREFIX/ghcup/bin:$CI_PROJECT_DIR/.local/bin:$PATH"
|
||||||
|
export TMPDIR="$CI_PROJECT_DIR/tmp"
|
||||||
|
else
|
||||||
|
export GHCUP_INSTALL_BASE_PREFIX="$CI_PROJECT_DIR"
|
||||||
|
export PATH="$CI_PROJECT_DIR/.ghcup/bin:$CI_PROJECT_DIR/.local/bin:/opt/llvm/bin:$PATH"
|
||||||
|
export TMPDIR="$CI_PROJECT_DIR/tmp"
|
||||||
|
fi
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ set -eux
|
|||||||
mkdir -p "$CI_PROJECT_DIR"/.local/bin
|
mkdir -p "$CI_PROJECT_DIR"/.local/bin
|
||||||
|
|
||||||
ecabal() {
|
ecabal() {
|
||||||
cabal --store-dir="$(pwd)"/.store "$@"
|
cabal "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
eghcup() {
|
eghcup() {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ set -eux
|
|||||||
mkdir -p "$CI_PROJECT_DIR"/.local/bin
|
mkdir -p "$CI_PROJECT_DIR"/.local/bin
|
||||||
|
|
||||||
ecabal() {
|
ecabal() {
|
||||||
cabal --store-dir="$(pwd)"/.store "$@"
|
cabal "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
git describe
|
git describe
|
||||||
@@ -29,18 +29,20 @@ if [ "${OS}" = "LINUX" ] ; then
|
|||||||
ecabal build -w ghc-${GHC_VERSION} -ftui
|
ecabal build -w ghc-${GHC_VERSION} -ftui
|
||||||
fi
|
fi
|
||||||
elif [ "${OS}" = "FREEBSD" ] ; then
|
elif [ "${OS}" = "FREEBSD" ] ; then
|
||||||
ecabal build -w ghc-${GHC_VERSION} --ghc-options='-split-sections' --constraint="zlib +bundled-c-zlib" -ftui
|
ecabal build -w ghc-${GHC_VERSION} --ghc-options='-split-sections' --constraint="zlib +bundled-c-zlib" --constraint="zip +disable-zstd" -ftui
|
||||||
|
elif [ "${OS}" = "WINDOWS" ] ; then
|
||||||
|
ecabal build -w ghc-${GHC_VERSION} --constraint="zlib +bundled-c-zlib" --constraint="lzma +static"
|
||||||
else
|
else
|
||||||
ecabal build -w ghc-${GHC_VERSION} --constraint="zlib +bundled-c-zlib" --constraint="lzma +static" -ftui
|
ecabal build -w ghc-${GHC_VERSION} --constraint="zlib +bundled-c-zlib" --constraint="lzma +static" -ftui
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir out
|
mkdir out
|
||||||
cp "$(ecabal new-exec -w ghc-${GHC_VERSION} --verbose=0 --offline sh -- -c 'command -v ghcup')" .
|
binary=$(ecabal new-exec -w ghc-${GHC_VERSION} --verbose=0 --offline sh -- -c 'command -v ghcup')
|
||||||
ver=$(./ghcup --numeric-version)
|
ver=$("${binary}" --numeric-version)
|
||||||
if [ "${OS}" = "DARWIN" ] ; then
|
if [ "${OS}" = "DARWIN" ] ; then
|
||||||
strip ./ghcup
|
strip "${binary}"
|
||||||
else
|
else
|
||||||
strip -s ./ghcup
|
strip -s "${binary}"
|
||||||
fi
|
fi
|
||||||
cp ghcup out/${ARTIFACT}-${ver}
|
cp "${binary}" out/${ARTIFACT}-${ver}
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,18 @@ set -eux
|
|||||||
|
|
||||||
mkdir -p "$CI_PROJECT_DIR"/.local/bin
|
mkdir -p "$CI_PROJECT_DIR"/.local/bin
|
||||||
|
|
||||||
|
CI_PROJECT_DIR=$(pwd)
|
||||||
|
|
||||||
ecabal() {
|
ecabal() {
|
||||||
cabal --store-dir="$(pwd)"/.store "$@"
|
cabal "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
eghcup() {
|
eghcup() {
|
||||||
ghcup -v -c -s file://$(pwd)/ghcup-${JSON_VERSION}.yaml "$@"
|
if [ "${OS}" = "WINDOWS" ] ; then
|
||||||
|
ghcup -v -c -s file:/$CI_PROJECT_DIR/ghcup-${JSON_VERSION}.yaml "$@"
|
||||||
|
else
|
||||||
|
ghcup -v -c -s file://$CI_PROJECT_DIR/ghcup-${JSON_VERSION}.yaml "$@"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
git describe --always
|
git describe --always
|
||||||
@@ -28,31 +34,47 @@ ecabal update
|
|||||||
if [ "${OS}" = "DARWIN" ] ; then
|
if [ "${OS}" = "DARWIN" ] ; then
|
||||||
ecabal build -w ghc-${GHC_VERSION} -ftui
|
ecabal build -w ghc-${GHC_VERSION} -ftui
|
||||||
ecabal test -w ghc-${GHC_VERSION} -ftui ghcup-test
|
ecabal test -w ghc-${GHC_VERSION} -ftui ghcup-test
|
||||||
|
ecabal haddock -w ghc-${GHC_VERSION} -ftui
|
||||||
elif [ "${OS}" = "LINUX" ] ; then
|
elif [ "${OS}" = "LINUX" ] ; then
|
||||||
if [ "${ARCH}" = "32" ] ; then
|
if [ "${ARCH}" = "32" ] ; then
|
||||||
ecabal build -w ghc-${GHC_VERSION} -finternal-downloader -ftui -ftar
|
ecabal build -w ghc-${GHC_VERSION} -finternal-downloader -ftui -ftar
|
||||||
ecabal test -w ghc-${GHC_VERSION} -finternal-downloader -ftui -ftar ghcup-test
|
ecabal test -w ghc-${GHC_VERSION} -finternal-downloader -ftui -ftar ghcup-test
|
||||||
|
ecabal haddock -w ghc-${GHC_VERSION} -finternal-downloader -ftui -ftar
|
||||||
else
|
else
|
||||||
ecabal build -w ghc-${GHC_VERSION} -finternal-downloader -ftui
|
ecabal build -w ghc-${GHC_VERSION} -finternal-downloader -ftui
|
||||||
ecabal test -w ghc-${GHC_VERSION} -finternal-downloader -ftui ghcup-test
|
ecabal test -w ghc-${GHC_VERSION} -finternal-downloader -ftui ghcup-test
|
||||||
|
ecabal haddock -w ghc-${GHC_VERSION} -finternal-downloader -ftui
|
||||||
fi
|
fi
|
||||||
|
elif [ "${OS}" = "FREEBSD" ] ; then
|
||||||
|
ecabal build -w ghc-${GHC_VERSION} -finternal-downloader -ftui --constraint="zip +disable-zstd"
|
||||||
|
ecabal test -w ghc-${GHC_VERSION} -finternal-downloader -ftui --constraint="zip +disable-zstd" ghcup-test
|
||||||
|
ecabal haddock -w ghc-${GHC_VERSION} -finternal-downloader -ftui --constraint="zip +disable-zstd"
|
||||||
|
elif [ "${OS}" = "WINDOWS" ] ; then
|
||||||
|
ecabal build -w ghc-${GHC_VERSION}
|
||||||
|
ecabal test -w ghc-${GHC_VERSION} ghcup-test
|
||||||
|
ecabal haddock -w ghc-${GHC_VERSION}
|
||||||
else
|
else
|
||||||
ecabal build -w ghc-${GHC_VERSION} -finternal-downloader -ftui
|
ecabal build -w ghc-${GHC_VERSION} -finternal-downloader -ftui
|
||||||
ecabal test -w ghc-${GHC_VERSION} -finternal-downloader -ftui ghcup-test
|
ecabal test -w ghc-${GHC_VERSION} -finternal-downloader -ftui ghcup-test
|
||||||
|
ecabal haddock -w ghc-${GHC_VERSION} -finternal-downloader -ftui
|
||||||
fi
|
fi
|
||||||
|
|
||||||
ecabal haddock -w ghc-${GHC_VERSION} -ftar
|
|
||||||
|
|
||||||
cp "$(ecabal new-exec -w ghc-${GHC_VERSION} --verbose=0 --offline sh -- -c 'command -v ghcup')" .
|
if [ "${OS}" = "WINDOWS" ] ; then
|
||||||
cp "$(ecabal new-exec -w ghc-${GHC_VERSION} --verbose=0 --offline sh -- -c 'command -v ghcup-gen')" .
|
ext=".exe"
|
||||||
|
else
|
||||||
cp ./ghcup "$CI_PROJECT_DIR"/.local/bin/ghcup
|
ext=''
|
||||||
cp ./ghcup-gen "$CI_PROJECT_DIR"/.local/bin/ghcup-gen
|
fi
|
||||||
|
cp "$(ecabal new-exec -w ghc-${GHC_VERSION} --verbose=0 --offline sh -- -c 'command -v ghcup')" "$CI_PROJECT_DIR"/.local/bin/ghcup${ext}
|
||||||
|
cp "$(ecabal new-exec -w ghc-${GHC_VERSION} --verbose=0 --offline sh -- -c 'command -v ghcup-gen')" "$CI_PROJECT_DIR"/.local/bin/ghcup-gen${ext}
|
||||||
|
|
||||||
### cleanup
|
### cleanup
|
||||||
|
|
||||||
rm -rf "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup
|
if [ "${OS}" = "WINDOWS" ] ; then
|
||||||
|
rm -rf "${GHCUP_INSTALL_BASE_PREFIX}"/ghcup
|
||||||
|
else
|
||||||
|
rm -rf "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup
|
||||||
|
fi
|
||||||
|
|
||||||
### manual cli based testing
|
### manual cli based testing
|
||||||
|
|
||||||
@@ -75,35 +97,46 @@ eghcup list -t cabal
|
|||||||
|
|
||||||
ghc_ver=$(ghc --numeric-version)
|
ghc_ver=$(ghc --numeric-version)
|
||||||
ghc --version
|
ghc --version
|
||||||
ghci --version
|
ghc-${ghc_ver} --version
|
||||||
ghc-$(ghc --numeric-version) --version
|
if [ "${OS}" != "WINDOWS" ] ; then
|
||||||
ghci-$(ghc --numeric-version) --version
|
ghci --version
|
||||||
|
ghci-${ghc_ver} --version
|
||||||
|
|
||||||
# test installing new ghc doesn't mess with currently set GHC
|
|
||||||
# https://gitlab.haskell.org/haskell/ghcup-hs/issues/7
|
|
||||||
if [ "${OS}" = "LINUX" ] ; then
|
|
||||||
eghcup --downloader=wget install 8.10.3
|
|
||||||
else # test wget a bit
|
|
||||||
eghcup install 8.10.3
|
|
||||||
fi
|
fi
|
||||||
[ "$(ghc --numeric-version)" = "${ghc_ver}" ]
|
|
||||||
eghcup set 8.10.3
|
|
||||||
eghcup set 8.10.3
|
|
||||||
[ "$(ghc --numeric-version)" = "8.10.3" ]
|
|
||||||
eghcup set ${GHC_VERSION}
|
|
||||||
[ "$(ghc --numeric-version)" = "${ghc_ver}" ]
|
|
||||||
eghcup rm 8.10.3
|
|
||||||
[ "$(ghc --numeric-version)" = "${ghc_ver}" ]
|
|
||||||
|
|
||||||
# install hls
|
|
||||||
if [ "${OS}" = "DARWIN" ] ; then
|
if [ "${OS}" = "DARWIN" ] && [ "${ARCH}" = "ARM64" ] ; then
|
||||||
eghcup install hls
|
echo
|
||||||
haskell-language-server-wrapper --version
|
else
|
||||||
elif [ "${OS}" = "LINUX" ] ; then
|
# test installing new ghc doesn't mess with currently set GHC
|
||||||
if [ "${ARCH}" = "64" ] ; then
|
# https://gitlab.haskell.org/haskell/ghcup-hs/issues/7
|
||||||
|
if [ "${OS}" = "LINUX" ] ; then
|
||||||
|
eghcup --downloader=wget install 8.10.3
|
||||||
|
else # test wget a bit
|
||||||
|
eghcup install 8.10.3
|
||||||
|
fi
|
||||||
|
[ "$(ghc --numeric-version)" = "${ghc_ver}" ]
|
||||||
|
eghcup set 8.10.3
|
||||||
|
eghcup set 8.10.3
|
||||||
|
[ "$(ghc --numeric-version)" = "8.10.3" ]
|
||||||
|
eghcup set ${GHC_VERSION}
|
||||||
|
[ "$(ghc --numeric-version)" = "${ghc_ver}" ]
|
||||||
|
eghcup rm 8.10.3
|
||||||
|
[ "$(ghc --numeric-version)" = "${ghc_ver}" ]
|
||||||
|
|
||||||
|
if [ "${OS}" = "DARWIN" ] ; then
|
||||||
eghcup install hls
|
eghcup install hls
|
||||||
haskell-language-server-wrapper --version
|
haskell-language-server-wrapper --version
|
||||||
|
|
||||||
|
eghcup install stack
|
||||||
|
stack --version
|
||||||
|
elif [ "${OS}" = "LINUX" ] ; then
|
||||||
|
if [ "${ARCH}" = "64" ] ; then
|
||||||
|
eghcup install hls
|
||||||
|
haskell-language-server-wrapper --version
|
||||||
|
|
||||||
|
eghcup install stack
|
||||||
|
stack --version
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -111,9 +144,21 @@ fi
|
|||||||
eghcup rm $(ghc --numeric-version)
|
eghcup rm $(ghc --numeric-version)
|
||||||
|
|
||||||
# https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/116
|
# https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/116
|
||||||
eghcup install cabal -u https://oleg.fi/cabal-install-3.4.0.0-rc4/cabal-install-3.4.0.0-x86_64-ubuntu-16.04.tar.xz 3.4.0.0-rc4
|
if [ "${OS}" = "LINUX" ] ; then
|
||||||
eghcup rm cabal 3.4.0.0-rc4
|
if [ "${ARCH}" = "64" ] ; then
|
||||||
|
eghcup install cabal -u https://oleg.fi/cabal-install-3.4.0.0-rc4/cabal-install-3.4.0.0-x86_64-ubuntu-16.04.tar.xz 3.4.0.0-rc4
|
||||||
|
eghcup rm cabal 3.4.0.0-rc4
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
eghcup upgrade
|
eghcup upgrade
|
||||||
eghcup upgrade -f
|
eghcup upgrade -f
|
||||||
|
|
||||||
|
|
||||||
|
# nuke
|
||||||
|
eghcup nuke
|
||||||
|
if [ "${OS}" = "WINDOWS" ] ; then
|
||||||
|
[ ! -e "${GHCUP_INSTALL_BASE_PREFIX}/ghcup" ]
|
||||||
|
else
|
||||||
|
[ ! -e "${GHCUP_INSTALL_BASE_PREFIX}/.ghcup" ]
|
||||||
|
fi
|
||||||
|
|||||||
89
.gitlab/shell.nix
Normal file
89
.gitlab/shell.nix
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
{ system ? "aarch64-darwin"
|
||||||
|
#, nixpkgs ? fetchTarball https://github.com/angerman/nixpkgs/archive/257cb120334.tar.gz #apple-silicon.tar.gz
|
||||||
|
, pkgs ? import <nixpkgs> { inherit system; }
|
||||||
|
, compiler ? if system == "aarch64-darwin" then "ghc8103Binary" else "ghc8103"
|
||||||
|
}: pkgs.mkShell {
|
||||||
|
# this prevents nix from trying to write the env-vars file.
|
||||||
|
# we can't really, as NIX_BUILD_TOP/env-vars is not set.
|
||||||
|
noDumpEnvVars=1;
|
||||||
|
|
||||||
|
# stop polluting LDFLAGS with -liconv
|
||||||
|
dontAddExtraLibs = true;
|
||||||
|
|
||||||
|
# we need to inject ncurses into --with-curses-libraries.
|
||||||
|
# the real fix is to teach terminfo to use libcurses on macOS.
|
||||||
|
# CONFIGURE_ARGS = "--with-intree-gmp --with-curses-libraries=${pkgs.ncurses.out}/lib";
|
||||||
|
CONFIGURE_ARGS = "--with-intree-gmp --with-curses-libraries=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib --with-iconv-includes=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include --with-iconv-libraries=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib SH=/bin/bash";
|
||||||
|
|
||||||
|
# magic speedup pony :facepalm:
|
||||||
|
#
|
||||||
|
# nix has the ugly habbit of duplicating ld flags more than necessary. This
|
||||||
|
# somewhat consolidates this.
|
||||||
|
shellHook = ''
|
||||||
|
export NIX_LDFLAGS=$(for a in $NIX_LDFLAGS; do echo $a; done |sort|uniq|xargs)
|
||||||
|
export NIX_LDFLAGS_FOR_TARGET=$(for a in $NIX_LDFLAGS_FOR_TARGET; do echo $a; done |sort|uniq|xargs)
|
||||||
|
export NIX_LDFLAGS_FOR_TARGET=$(comm -3 <(for l in $NIX_LDFLAGS_FOR_TARGET; do echo $l; done) <(for l in $NIX_LDFLAGS; do echo $l; done))
|
||||||
|
|
||||||
|
|
||||||
|
# Impurity hack for GHC releases.
|
||||||
|
#################################
|
||||||
|
# We don't want binary releases to depend on nix, thus we'll need to make sure we don't leak in references.
|
||||||
|
# GHC externally depends only on iconv and curses. However we can't force a specific curses library for
|
||||||
|
# the terminfo package, as such we'll need to make sure we only look in the system path for the curses library
|
||||||
|
# and not pick up the tinfo from the nix provided ncurses package.
|
||||||
|
#
|
||||||
|
# We also need to force us to use the systems COREFOUNDATION, not the one that nix builds. Again this is impure,
|
||||||
|
# but it will allow us to have proper binary distributions.
|
||||||
|
#
|
||||||
|
# do not use nixpkgs provided core foundation
|
||||||
|
export NIX_COREFOUNDATION_RPATH=/System/Library/Frameworks
|
||||||
|
# drop curses from the LDFLAGS, we really want the system ones, not the nix ones.
|
||||||
|
export NIX_LDFLAGS=$(for lib in $NIX_LDFLAGS; do case "$lib" in *curses*);; *) echo -n "$lib ";; esac; done;)
|
||||||
|
export NIX_CFLAGS_COMPILE+=" -Wno-nullability-completeness -Wno-availability -Wno-expansion-to-defined -Wno-builtin-requires-header -Wno-unused-command-line-argument"
|
||||||
|
|
||||||
|
# unconditionally add the MacOSX.sdk and TargetConditional.h
|
||||||
|
export NIX_CFLAGS_COMPILE+=" -isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include"
|
||||||
|
|
||||||
|
'';
|
||||||
|
|
||||||
|
nativeBuildInputs = (with pkgs; [
|
||||||
|
# This needs to come *before* ghc,
|
||||||
|
# otherwise we migth end up with the clang from
|
||||||
|
# the bootstrap GHC in PATH with higher priority.
|
||||||
|
clang_11
|
||||||
|
llvm_11
|
||||||
|
|
||||||
|
haskell.compiler.${compiler}
|
||||||
|
haskell.packages.${compiler}.cabal-install
|
||||||
|
haskell.packages.${compiler}.alex
|
||||||
|
haskell.packages.${compiler}.happy # _1_19_12 is needed for older GHCs.
|
||||||
|
|
||||||
|
automake
|
||||||
|
autoconf
|
||||||
|
m4
|
||||||
|
|
||||||
|
gmp
|
||||||
|
zlib.out
|
||||||
|
zlib.dev
|
||||||
|
glibcLocales
|
||||||
|
# locale doesn't build yet :-/
|
||||||
|
# locale
|
||||||
|
|
||||||
|
git
|
||||||
|
|
||||||
|
python3
|
||||||
|
# python3Full
|
||||||
|
# python3Packages.sphinx
|
||||||
|
perl
|
||||||
|
|
||||||
|
which
|
||||||
|
wget
|
||||||
|
curl
|
||||||
|
file
|
||||||
|
|
||||||
|
xz
|
||||||
|
xlibs.lndir
|
||||||
|
|
||||||
|
cacert ])
|
||||||
|
++ (with pkgs.darwin.apple_sdk.frameworks; [ Foundation Security ]);
|
||||||
|
}
|
||||||
24
CHANGELOG.md
24
CHANGELOG.md
@@ -1,10 +1,30 @@
|
|||||||
# Revision history for ghcup
|
# Revision history for ghcup
|
||||||
|
|
||||||
## 0.1.15 -- ????-??-??
|
## 0.1.16 -- ????-??-??
|
||||||
|
|
||||||
* Add date to GHC bindist names created by ghcup
|
* Add 'nuke' subcommand wrt [#135](https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/135), implemented by Arjun Kathuria
|
||||||
|
|
||||||
|
## 0.1.15.2 -- 2021-06-13
|
||||||
|
|
||||||
|
* Remove legacy handling of cabal binary and be more graceful about binaries not installed by ghcup (e.g. stack)
|
||||||
|
* Fix GHC compilation from git
|
||||||
|
* Fix 'ghcup upgrade' on windows
|
||||||
|
* Allow to skip update checks via `GHCUP_SKIP_UPDATE_CHECK`
|
||||||
|
* Use libarchive on windows as well, fixing unpack errors wrt [#147](https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/147)
|
||||||
|
|
||||||
|
## 0.1.15.1 -- 2021-06-11
|
||||||
|
|
||||||
|
* Add Apple Silicon support
|
||||||
|
* Add windows support wrt [#130](https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/130)
|
||||||
|
* Add stack support
|
||||||
* Warn when /tmp doesn't have 5GB or more of disk space
|
* Warn when /tmp doesn't have 5GB or more of disk space
|
||||||
* Allow to compile GHC from git repo wrt [#126](https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/126)
|
* Allow to compile GHC from git repo wrt [#126](https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/126)
|
||||||
|
* Allow to set custom ghc version when running 'ghcup compile ghc' wrt [#136](https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/136)
|
||||||
|
* Add date to GHC bindist names created by ghcup
|
||||||
|
|
||||||
|
## 0.1.14.2 -- 2021-05-12
|
||||||
|
|
||||||
|
* Remove dead dependency on ascii-string
|
||||||
|
|
||||||
## 0.1.14.1 -- 2021-04-11
|
## 0.1.14.1 -- 2021-04-11
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,6 @@
|
|||||||
|
|
||||||
This is an open variant, similar to [plucky](https://hackage.haskell.org/package/plucky) or [oops](https://github.com/i-am-tom/oops) and allows us to combine different error types. Maybe it is too much and it's a little bit [unergonomic](https://github.com/haskus/packages/issues/32) at times. If it really hurts maintenance, it will be removed. It was more of an experiment.
|
This is an open variant, similar to [plucky](https://hackage.haskell.org/package/plucky) or [oops](https://github.com/i-am-tom/oops) and allows us to combine different error types. Maybe it is too much and it's a little bit [unergonomic](https://github.com/haskus/packages/issues/32) at times. If it really hurts maintenance, it will be removed. It was more of an experiment.
|
||||||
|
|
||||||
### No use of filepath or directory
|
|
||||||
|
|
||||||
Filepath and directory have two fundamental problems: 1. they use String as filepath (see [AFPP](https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/abstract-file-path) as to why this is wrong) and 2. they try very hard to be cross-platform at the expense of low-level correctness. Instead, we use the [hpath](https://github.com/hasufell/hpath) libraries for file and filepath related stuff, which also gives us stronger filepath types.
|
|
||||||
|
|
||||||
### No use of haskell-TLS
|
### No use of haskell-TLS
|
||||||
|
|
||||||
I consider haskell-TLS an interesting experiment, but not a battle-tested and peer-reviewed crypto implementation. There is little to no research about what the intricacies of using haskell for low-level crypto are and how vulnerable such binaries are. Instead, we use either curl the binary (for FreeBSD and mac) or http-io-streams, which works with OpenSSL bindings.
|
I consider haskell-TLS an interesting experiment, but not a battle-tested and peer-reviewed crypto implementation. There is little to no research about what the intricacies of using haskell for low-level crypto are and how vulnerable such binaries are. Instead, we use either curl the binary (for FreeBSD and mac) or http-io-streams, which works with OpenSSL bindings.
|
||||||
@@ -73,3 +69,7 @@ yaml files: `ghcup-<yaml-ver>.yaml`.
|
|||||||
Most of the `Version` parameters to functions had to be replaced with
|
Most of the `Version` parameters to functions had to be replaced with
|
||||||
that and ensured the logic is consistent for cross and non-cross
|
that and ensured the logic is consistent for cross and non-cross
|
||||||
installs.
|
installs.
|
||||||
|
2. This refactor added windows support wrt [#130](https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/130).
|
||||||
|
The major changes here were switching `hpath` library out for `filepath`/`directory` (sadly) and
|
||||||
|
introducing a non-unix way of handling processes via the `process` library. It also introduced considerable
|
||||||
|
amounts of CPP wrt file handling, installation etc.
|
||||||
|
|||||||
16
README.md
16
README.md
@@ -1,11 +1,9 @@
|
|||||||
`ghcup` makes it easy to install specific versions of `ghc` on GNU/Linux,
|
`ghcup` makes it easy to install specific versions of `ghc` on GNU/Linux,
|
||||||
macOS (aka Darwin) and FreeBSD and can also bootstrap a fresh Haskell developer environment from scratch.
|
macOS (aka Darwin), FreeBSD and Windows and can also bootstrap a fresh Haskell developer environment from scratch.
|
||||||
It follows the unix UNIX philosophy of [do one thing and do it well](https://en.wikipedia.org/wiki/Unix_philosophy#Do_One_Thing_and_Do_It_Well).
|
It follows the unix UNIX philosophy of [do one thing and do it well](https://en.wikipedia.org/wiki/Unix_philosophy#Do_One_Thing_and_Do_It_Well).
|
||||||
|
|
||||||
Similar in scope to [rustup](https://github.com/rust-lang-nursery/rustup.rs), [pyenv](https://github.com/pyenv/pyenv) and [jenv](http://www.jenv.be).
|
Similar in scope to [rustup](https://github.com/rust-lang-nursery/rustup.rs), [pyenv](https://github.com/pyenv/pyenv) and [jenv](http://www.jenv.be).
|
||||||
|
|
||||||
*Ubuntu users may prefer [hvr's ppa](https://launchpad.net/~hvr/+archive/ubuntu/ghc).*
|
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
* [Installation](#installation)
|
* [Installation](#installation)
|
||||||
@@ -79,7 +77,7 @@ ghcup install cabal
|
|||||||
ghcup upgrade
|
ghcup upgrade
|
||||||
```
|
```
|
||||||
|
|
||||||
Generally this is meant to be used with [`cabal-install`](https://hackage.haskell.org/package/cabal-install), which
|
GHCup works very well with [`cabal-install`](https://hackage.haskell.org/package/cabal-install), which
|
||||||
handles your haskell packages and can demand that [a specific version](https://cabal.readthedocs.io/en/latest/nix-local-build.html#cfg-flag---with-compiler) of `ghc` is available, which `ghcup` can do.
|
handles your haskell packages and can demand that [a specific version](https://cabal.readthedocs.io/en/latest/nix-local-build.html#cfg-flag---with-compiler) of `ghc` is available, which `ghcup` can do.
|
||||||
|
|
||||||
### Configuration
|
### Configuration
|
||||||
@@ -87,7 +85,7 @@ handles your haskell packages and can demand that [a specific version](https://c
|
|||||||
A configuration file can be put in `~/.ghcup/config.yaml`. The default config file
|
A configuration file can be put in `~/.ghcup/config.yaml`. The default config file
|
||||||
explaining all possible configurations can be found in this repo: [config.yaml](./config.yaml).
|
explaining all possible configurations can be found in this repo: [config.yaml](./config.yaml).
|
||||||
|
|
||||||
Partial configuration is fine. Command line options always overwrite the config file settings.
|
Partial configuration is fine. Command line options always override the config file settings.
|
||||||
|
|
||||||
### Manpages
|
### Manpages
|
||||||
|
|
||||||
@@ -125,6 +123,9 @@ Then you can control the locations via XDG environment variables as such:
|
|||||||
* `XDG_BIN_HOME`: binaries end up here (default: `~/.local/bin`)
|
* `XDG_BIN_HOME`: binaries end up here (default: `~/.local/bin`)
|
||||||
* `XDG_CONFIG_HOME`: the config file is stored in `ghcup` subdir as `config.yaml` (default: `~/.config`)
|
* `XDG_CONFIG_HOME`: the config file is stored in `ghcup` subdir as `config.yaml` (default: `~/.config`)
|
||||||
|
|
||||||
|
**Note that `ghcup` makes some assumptions about structure of files in `XDG_BIN_HOME`. So if you have other tools
|
||||||
|
installing e.g. stack/cabal/ghc into it, this will likely clash. In that case consider disabling XDG support.**
|
||||||
|
|
||||||
### Env variables
|
### Env variables
|
||||||
|
|
||||||
This is the complete list of env variables that change GHCup behavior:
|
This is the complete list of env variables that change GHCup behavior:
|
||||||
@@ -134,6 +135,7 @@ This is the complete list of env variables that change GHCup behavior:
|
|||||||
* `GHCUP_INSTALL_BASE_PREFIX`: the base of ghcup (default: `$HOME`)
|
* `GHCUP_INSTALL_BASE_PREFIX`: the base of ghcup (default: `$HOME`)
|
||||||
* `GHCUP_CURL_OPTS`: additional options that can be passed to curl
|
* `GHCUP_CURL_OPTS`: additional options that can be passed to curl
|
||||||
* `GHCUP_WGET_OPTS`: additional options that can be passed to wget
|
* `GHCUP_WGET_OPTS`: additional options that can be passed to wget
|
||||||
|
* `GHCUP_SKIP_UPDATE_CHECK`: Skip the (possibly annoying) update check when you run a command
|
||||||
* `CC`/`LD` etc.: full environment is passed to the build system when compiling GHC via GHCup
|
* `CC`/`LD` etc.: full environment is passed to the build system when compiling GHC via GHCup
|
||||||
|
|
||||||
### Installing custom bindists
|
### Installing custom bindists
|
||||||
@@ -236,8 +238,8 @@ ghcup is not a reimplementation of stack. The only common part is automatic inst
|
|||||||
|
|
||||||
2. Why not support windows?
|
2. Why not support windows?
|
||||||
|
|
||||||
Consider using [Chocolatey](https://chocolatey.org/search?q=ghc) or [ghcups](https://github.com/kakkun61/ghcups).
|
We do.
|
||||||
|
|
||||||
3. Why the haskell reimplementation?
|
3. Why the haskell reimplementation?
|
||||||
|
|
||||||
Why not?
|
:-)
|
||||||
|
|||||||
@@ -69,13 +69,15 @@ tarballFilterP = option readm $
|
|||||||
long "tarball-filter" <> short 'u' <> metavar "<tool>-<version>" <> value def
|
long "tarball-filter" <> short 'u' <> metavar "<tool>-<version>" <> value def
|
||||||
<> help "Only check certain tarballs (format: <tool>-<version>)"
|
<> help "Only check certain tarballs (format: <tool>-<version>)"
|
||||||
where
|
where
|
||||||
def = TarballFilter Nothing (makeRegex ("" :: String))
|
def = TarballFilter (Right Nothing) (makeRegex ("" :: String))
|
||||||
readm = do
|
readm = do
|
||||||
s <- str
|
s <- str
|
||||||
case span (/= '-') s of
|
case span (/= '-') s of
|
||||||
(_, []) -> fail "invalid format, missing '-' after the tool name"
|
(_, []) -> fail "invalid format, missing '-' after the tool name"
|
||||||
(t, v) | [tool] <- [ tool | tool <- [minBound..maxBound], low (show tool) == low t ] ->
|
(t, v) | [tool] <- [ tool | tool <- [minBound..maxBound], low (show tool) == low t ] ->
|
||||||
pure (TarballFilter $ Just tool) <*> makeRegexOptsM compIgnoreCase execBlank (drop 1 v)
|
pure (TarballFilter $ Right $ Just tool) <*> makeRegexOptsM compIgnoreCase execBlank (drop 1 v)
|
||||||
|
(t, v) | [tool] <- [ tool | tool <- [minBound..maxBound], low (show tool) == low t ] ->
|
||||||
|
pure (TarballFilter $ Left tool) <*> makeRegexOptsM compIgnoreCase execBlank (drop 1 v)
|
||||||
_ -> fail "invalid tool"
|
_ -> fail "invalid tool"
|
||||||
low = fmap toLower
|
low = fmap toLower
|
||||||
|
|
||||||
@@ -105,26 +107,21 @@ main :: IO ()
|
|||||||
main = do
|
main = do
|
||||||
_ <- customExecParser (prefs showHelpOnError) (info (opts <**> helper) idm)
|
_ <- customExecParser (prefs showHelpOnError) (info (opts <**> helper) idm)
|
||||||
>>= \Options {..} -> case optCommand of
|
>>= \Options {..} -> case optCommand of
|
||||||
ValidateYAML vopts -> case vopts of
|
ValidateYAML vopts -> withValidateYamlOpts vopts validate
|
||||||
ValidateYAMLOpts { vInput = Nothing } ->
|
ValidateTarballs vopts tarballFilter -> withValidateYamlOpts vopts (validateTarballs tarballFilter)
|
||||||
B.getContents >>= valAndExit validate
|
|
||||||
ValidateYAMLOpts { vInput = Just StdInput } ->
|
|
||||||
B.getContents >>= valAndExit validate
|
|
||||||
ValidateYAMLOpts { vInput = Just (FileInput file) } ->
|
|
||||||
B.readFile file >>= valAndExit validate
|
|
||||||
ValidateTarballs vopts tarballFilter -> case vopts of
|
|
||||||
ValidateYAMLOpts { vInput = Nothing } ->
|
|
||||||
B.getContents >>= valAndExit (validateTarballs tarballFilter)
|
|
||||||
ValidateYAMLOpts { vInput = Just StdInput } ->
|
|
||||||
B.getContents >>= valAndExit (validateTarballs tarballFilter)
|
|
||||||
ValidateYAMLOpts { vInput = Just (FileInput file) } ->
|
|
||||||
B.readFile file >>= valAndExit (validateTarballs tarballFilter)
|
|
||||||
pure ()
|
pure ()
|
||||||
|
|
||||||
where
|
where
|
||||||
|
withValidateYamlOpts vopts f = case vopts of
|
||||||
|
ValidateYAMLOpts { vInput = Nothing } ->
|
||||||
|
B.getContents >>= valAndExit f
|
||||||
|
ValidateYAMLOpts { vInput = Just StdInput } ->
|
||||||
|
B.getContents >>= valAndExit f
|
||||||
|
ValidateYAMLOpts { vInput = Just (FileInput file) } ->
|
||||||
|
B.readFile file >>= valAndExit f
|
||||||
valAndExit f contents = do
|
valAndExit f contents = do
|
||||||
(GHCupInfo _ av) <- case Y.decodeEither' contents of
|
(GHCupInfo _ av gt) <- case Y.decodeEither' contents of
|
||||||
Right r -> pure r
|
Right r -> pure r
|
||||||
Left e -> die (color Red $ show e)
|
Left e -> die (color Red $ show e)
|
||||||
myLoggerT (LoggerConfig True (B.hPut stdout) (\_ -> pure ())) (f av)
|
myLoggerT (LoggerConfig True (B.hPut stdout) (\_ -> pure ())) (f av gt)
|
||||||
>>= exitWith
|
>>= exitWith
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ module Validate where
|
|||||||
import GHCup
|
import GHCup
|
||||||
import GHCup.Download
|
import GHCup.Download
|
||||||
import GHCup.Errors
|
import GHCup.Errors
|
||||||
|
import GHCup.Platform
|
||||||
import GHCup.Types
|
import GHCup.Types
|
||||||
import GHCup.Types.Optics
|
import GHCup.Types.Optics
|
||||||
import GHCup.Utils
|
import GHCup.Utils
|
||||||
@@ -22,6 +23,7 @@ import qualified Codec.Archive.Tar as Tar
|
|||||||
#else
|
#else
|
||||||
import Codec.Archive
|
import Codec.Archive
|
||||||
#endif
|
#endif
|
||||||
|
import Control.Applicative
|
||||||
import Control.Exception.Safe
|
import Control.Exception.Safe
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Control.Monad.IO.Class
|
import Control.Monad.IO.Class
|
||||||
@@ -37,12 +39,11 @@ import Data.IORef
|
|||||||
import Data.List
|
import Data.List
|
||||||
import Data.String.Interpolate
|
import Data.String.Interpolate
|
||||||
import Data.Versions
|
import Data.Versions
|
||||||
import HPath ( toFilePath, rel )
|
|
||||||
import Haskus.Utils.Variant.Excepts
|
import Haskus.Utils.Variant.Excepts
|
||||||
import Optics
|
import Optics
|
||||||
|
import System.FilePath
|
||||||
import System.Exit
|
import System.Exit
|
||||||
import System.IO
|
import System.IO
|
||||||
import System.Posix.FilePath
|
|
||||||
import Text.ParserCombinators.ReadP
|
import Text.ParserCombinators.ReadP
|
||||||
import Text.PrettyPrint.HughesPJClass ( prettyShow )
|
import Text.PrettyPrint.HughesPJClass ( prettyShow )
|
||||||
import Text.Regex.Posix
|
import Text.Regex.Posix
|
||||||
@@ -67,8 +68,9 @@ addError = do
|
|||||||
|
|
||||||
validate :: (Monad m, MonadLogger m, MonadThrow m, MonadIO m, MonadUnliftIO m)
|
validate :: (Monad m, MonadLogger m, MonadThrow m, MonadIO m, MonadUnliftIO m)
|
||||||
=> GHCupDownloads
|
=> GHCupDownloads
|
||||||
|
-> M.Map GlobalTool DownloadInfo
|
||||||
-> m ExitCode
|
-> m ExitCode
|
||||||
validate dls = do
|
validate dls _ = do
|
||||||
ref <- liftIO $ newIORef 0
|
ref <- liftIO $ newIORef 0
|
||||||
|
|
||||||
-- verify binary downloads --
|
-- verify binary downloads --
|
||||||
@@ -106,6 +108,10 @@ validate dls = do
|
|||||||
addError
|
addError
|
||||||
when ((notElem FreeBSD pspecs) && arch == A_64) $ lift $ $(logWarn)
|
when ((notElem FreeBSD pspecs) && arch == A_64) $ lift $ $(logWarn)
|
||||||
[i|FreeBSD missing for #{t} #{v'} #{arch'}|]
|
[i|FreeBSD missing for #{t} #{v'} #{arch'}|]
|
||||||
|
when (notElem Windows pspecs && arch == A_64) $ do
|
||||||
|
lift $ $(logError)
|
||||||
|
[i|Windows missing for for #{t} #{v'} #{arch'}|]
|
||||||
|
addError
|
||||||
|
|
||||||
-- alpine needs to be set explicitly, because
|
-- alpine needs to be set explicitly, because
|
||||||
-- we cannot assume that "Linux UnknownLinux" runs on Alpine
|
-- we cannot assume that "Linux UnknownLinux" runs on Alpine
|
||||||
@@ -178,7 +184,7 @@ validate dls = do
|
|||||||
isBase _ = False
|
isBase _ = False
|
||||||
|
|
||||||
data TarballFilter = TarballFilter
|
data TarballFilter = TarballFilter
|
||||||
{ tfTool :: Maybe Tool
|
{ tfTool :: Either GlobalTool (Maybe Tool)
|
||||||
, tfVersion :: Regex
|
, tfVersion :: Regex
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,22 +194,23 @@ validateTarballs :: ( Monad m
|
|||||||
, MonadIO m
|
, MonadIO m
|
||||||
, MonadUnliftIO m
|
, MonadUnliftIO m
|
||||||
, MonadMask m
|
, MonadMask m
|
||||||
|
, Alternative m
|
||||||
|
, MonadFail m
|
||||||
)
|
)
|
||||||
=> TarballFilter
|
=> TarballFilter
|
||||||
-> GHCupDownloads
|
-> GHCupDownloads
|
||||||
|
-> M.Map GlobalTool DownloadInfo
|
||||||
-> m ExitCode
|
-> m ExitCode
|
||||||
validateTarballs (TarballFilter tool versionRegex) dls = do
|
validateTarballs (TarballFilter etool versionRegex) dls gt = do
|
||||||
ref <- liftIO $ newIORef 0
|
ref <- liftIO $ newIORef 0
|
||||||
|
|
||||||
flip runReaderT ref $ do
|
flip runReaderT ref $ do
|
||||||
-- download/verify all tarballs
|
-- download/verify all tarballs
|
||||||
let dlis = nubOrd $ dls ^.. each
|
let dlis = either (const []) (\tool -> nubOrd $ dls ^.. each %& indices (maybe (const True) (==) tool) %> each %& indices (matchTest versionRegex . T.unpack . prettyVer) % (viSourceDL % _Just `summing` viArch % each % each % each)) etool
|
||||||
%& indices (maybe (const True) (==) tool) %> each
|
let gdlis = nubOrd $ gt ^.. each
|
||||||
%& indices (matchTest versionRegex . T.unpack . prettyVer)
|
let allDls = either (const gdlis) (const dlis) etool
|
||||||
% (viSourceDL % _Just `summing` viArch % each % each % each)
|
when (null allDls) $ $(logError) [i|no tarballs selected by filter|] *> addError
|
||||||
when (null dlis) $ $(logError) [i|no tarballs selected by filter|] *> addError
|
forM_ allDls downloadAll
|
||||||
|
|
||||||
forM_ dlis downloadAll
|
|
||||||
|
|
||||||
-- exit
|
-- exit
|
||||||
e <- liftIO $ readIORef ref
|
e <- liftIO $ readIORef ref
|
||||||
@@ -220,11 +227,21 @@ validateTarballs (TarballFilter tool versionRegex) dls = do
|
|||||||
}
|
}
|
||||||
downloadAll dli = do
|
downloadAll dli = do
|
||||||
dirs <- liftIO getDirs
|
dirs <- liftIO getDirs
|
||||||
let settings = AppState (Settings True False Never Curl False GHCupURL) dirs defaultKeyBindings
|
|
||||||
|
pfreq <- (
|
||||||
|
runLogger . runE @'[NoCompatiblePlatform, NoCompatibleArch, DistroNotFound] . liftE $ platformRequest
|
||||||
|
) >>= \case
|
||||||
|
VRight r -> pure r
|
||||||
|
VLeft e -> do
|
||||||
|
lift $ runLogger
|
||||||
|
($(logError) $ T.pack $ prettyShow e)
|
||||||
|
liftIO $ exitWith (ExitFailure 2)
|
||||||
|
|
||||||
|
let appstate = AppState (Settings True False Never Curl False GHCupURL) dirs defaultKeyBindings (GHCupInfo mempty mempty mempty) pfreq
|
||||||
|
|
||||||
r <-
|
r <-
|
||||||
runLogger
|
runLogger
|
||||||
. flip runReaderT settings
|
. flip runReaderT appstate
|
||||||
. runResourceT
|
. runResourceT
|
||||||
. runE @'[DigestError
|
. runE @'[DigestError
|
||||||
, DownloadFailed
|
, DownloadFailed
|
||||||
@@ -236,23 +253,25 @@ validateTarballs (TarballFilter tool versionRegex) dls = do
|
|||||||
#endif
|
#endif
|
||||||
]
|
]
|
||||||
$ do
|
$ do
|
||||||
case tool of
|
case etool of
|
||||||
Just GHCup -> do
|
Right (Just GHCup) -> do
|
||||||
let fn = [rel|ghcup|]
|
tmpUnpack <- lift mkGhcupTmpDir
|
||||||
dir <- liftIO ghcupCacheDir
|
_ <- liftE $ download (settings appstate) dli tmpUnpack Nothing
|
||||||
p <- liftE $ download dli dir (Just fn)
|
|
||||||
liftE $ checkDigest dli p
|
|
||||||
pure Nothing
|
pure Nothing
|
||||||
_ -> do
|
Right _ -> do
|
||||||
p <- liftE $ downloadCached dli Nothing
|
p <- liftE $ downloadCached (settings appstate) dirs dli Nothing
|
||||||
fmap (Just . head . splitDirectories . head)
|
fmap (Just . head . splitDirectories . head)
|
||||||
. liftE
|
. liftE
|
||||||
. getArchiveFiles
|
. getArchiveFiles
|
||||||
$ p
|
$ p
|
||||||
|
Left ShimGen -> do
|
||||||
|
tmpUnpack <- lift mkGhcupTmpDir
|
||||||
|
_ <- liftE $ download (settings appstate) dli tmpUnpack Nothing
|
||||||
|
pure Nothing
|
||||||
case r of
|
case r of
|
||||||
VRight (Just basePath) -> do
|
VRight (Just basePath) -> do
|
||||||
case _dlSubdir dli of
|
case _dlSubdir dli of
|
||||||
Just (RealDir (toFilePath -> prel)) -> do
|
Just (RealDir prel) -> do
|
||||||
lift $ $(logInfo)
|
lift $ $(logInfo)
|
||||||
[i|verifying subdir: #{prel}|]
|
[i|verifying subdir: #{prel}|]
|
||||||
when (basePath /= prel) $ do
|
when (basePath /= prel) $ do
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
{-# LANGUAGE TemplateHaskell #-}
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
{-# LANGUAGE TypeApplications #-}
|
{-# LANGUAGE TypeApplications #-}
|
||||||
{-# LANGUAGE ViewPatterns #-}
|
{-# LANGUAGE ViewPatterns #-}
|
||||||
|
{-# LANGUAGE RankNTypes #-}
|
||||||
|
|
||||||
module BrickMain where
|
module BrickMain where
|
||||||
|
|
||||||
@@ -14,6 +15,7 @@ import GHCup.Download
|
|||||||
import GHCup.Errors
|
import GHCup.Errors
|
||||||
import GHCup.Types
|
import GHCup.Types
|
||||||
import GHCup.Utils
|
import GHCup.Utils
|
||||||
|
import GHCup.Utils.Prelude ( decUTF8Safe )
|
||||||
import GHCup.Utils.File
|
import GHCup.Utils.File
|
||||||
import GHCup.Utils.Logger
|
import GHCup.Utils.Logger
|
||||||
|
|
||||||
@@ -31,6 +33,7 @@ import Codec.Archive
|
|||||||
import Control.Exception.Safe
|
import Control.Exception.Safe
|
||||||
import Control.Monad.Logger
|
import Control.Monad.Logger
|
||||||
import Control.Monad.Reader
|
import Control.Monad.Reader
|
||||||
|
import Control.Monad.Trans.Except
|
||||||
import Control.Monad.Trans.Resource
|
import Control.Monad.Trans.Resource
|
||||||
import Data.Bool
|
import Data.Bool
|
||||||
import Data.Functor
|
import Data.Functor
|
||||||
@@ -57,16 +60,18 @@ import qualified Graphics.Vty as Vty
|
|||||||
import qualified Data.Vector as V
|
import qualified Data.Vector as V
|
||||||
|
|
||||||
|
|
||||||
|
hiddenTools :: [Tool]
|
||||||
|
hiddenTools = [Stack]
|
||||||
|
|
||||||
|
|
||||||
data BrickData = BrickData
|
data BrickData = BrickData
|
||||||
{ lr :: [ListResult]
|
{ lr :: [ListResult]
|
||||||
, dls :: GHCupDownloads
|
|
||||||
, pfreq :: PlatformRequest
|
|
||||||
}
|
}
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
data BrickSettings = BrickSettings
|
data BrickSettings = BrickSettings
|
||||||
{ showAll :: Bool
|
{ showAllVersions :: Bool
|
||||||
|
, showAllTools :: Bool
|
||||||
}
|
}
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
@@ -95,19 +100,24 @@ keyHandlers KeyBindings {..} =
|
|||||||
[ (bQuit, const "Quit" , halt)
|
[ (bQuit, const "Quit" , halt)
|
||||||
, (bInstall, const "Install" , withIOAction install')
|
, (bInstall, const "Install" , withIOAction install')
|
||||||
, (bUninstall, const "Uninstall", withIOAction del')
|
, (bUninstall, const "Uninstall", withIOAction del')
|
||||||
, (bSet, const "Set" , withIOAction set')
|
, (bSet, const "Set" , withIOAction ((liftIO .) . set'))
|
||||||
, (bChangelog, const "ChangeLog", withIOAction changelog')
|
, (bChangelog, const "ChangeLog", withIOAction changelog')
|
||||||
, ( bShowAll
|
, ( bShowAllVersions
|
||||||
, \BrickSettings {..} ->
|
, \BrickSettings {..} ->
|
||||||
if showAll then "Hide old versions" else "Show all versions"
|
if showAllVersions then "Don't show all versions" else "Show all versions"
|
||||||
, hideShowHandler
|
, hideShowHandler (not . showAllVersions) showAllTools
|
||||||
|
)
|
||||||
|
, ( bShowAllTools
|
||||||
|
, \BrickSettings {..} ->
|
||||||
|
if showAllTools then "Don't show all tools" else "Show all tools"
|
||||||
|
, hideShowHandler showAllVersions (not . showAllTools)
|
||||||
)
|
)
|
||||||
, (bUp, const "Up", \BrickState {..} -> continue BrickState{ appState = moveCursor 1 appState Up, .. })
|
, (bUp, const "Up", \BrickState {..} -> continue BrickState{ appState = moveCursor 1 appState Up, .. })
|
||||||
, (bDown, const "Down", \BrickState {..} -> continue BrickState{ appState = moveCursor 1 appState Down, .. })
|
, (bDown, const "Down", \BrickState {..} -> continue BrickState{ appState = moveCursor 1 appState Down, .. })
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
hideShowHandler BrickState{..} =
|
hideShowHandler f p BrickState{..} =
|
||||||
let newAppSettings = appSettings { showAll = not . showAll $ appSettings }
|
let newAppSettings = appSettings { showAllVersions = f appSettings , showAllTools = p appSettings }
|
||||||
newInternalState = constructList appData newAppSettings (Just appState)
|
newInternalState = constructList appData newAppSettings (Just appState)
|
||||||
in continue (BrickState appData newAppSettings newInternalState appKeys)
|
in continue (BrickState appData newAppSettings newInternalState appKeys)
|
||||||
|
|
||||||
@@ -194,6 +204,7 @@ ui dimAttrs BrickState{ appSettings = as@BrickSettings{}, ..}
|
|||||||
printTool GHC = str "GHC"
|
printTool GHC = str "GHC"
|
||||||
printTool GHCup = str "GHCup"
|
printTool GHCup = str "GHCup"
|
||||||
printTool HLS = str "HLS"
|
printTool HLS = str "HLS"
|
||||||
|
printTool Stack = str "Stack"
|
||||||
|
|
||||||
printNotes ListResult {..} =
|
printNotes ListResult {..} =
|
||||||
(if hlsPowered then [withAttr "hls-powered" $ str "hls-powered"] else mempty
|
(if hlsPowered then [withAttr "hls-powered" $ str "hls-powered"] else mempty
|
||||||
@@ -316,21 +327,25 @@ moveCursor steps ais@BrickInternalState{..} direction =
|
|||||||
|
|
||||||
-- | Suspend the current UI and run an IO action in terminal. If the
|
-- | Suspend the current UI and run an IO action in terminal. If the
|
||||||
-- IO action returns a Left value, then it's thrown as userError.
|
-- IO action returns a Left value, then it's thrown as userError.
|
||||||
withIOAction :: (BrickState -> (Int, ListResult) -> IO (Either String a))
|
withIOAction :: (BrickState
|
||||||
|
-> (Int, ListResult)
|
||||||
|
-> ReaderT AppState IO (Either String a))
|
||||||
-> BrickState
|
-> BrickState
|
||||||
-> EventM n (Next BrickState)
|
-> EventM n (Next BrickState)
|
||||||
withIOAction action as = case listSelectedElement' (appState as) of
|
withIOAction action as = case listSelectedElement' (appState as) of
|
||||||
Nothing -> continue as
|
Nothing -> continue as
|
||||||
Just (ix, e) -> suspendAndResume $ do
|
Just (ix, e) -> do
|
||||||
action as (ix, e) >>= \case
|
suspendAndResume $ do
|
||||||
Left err -> putStrLn ("Error: " <> err)
|
settings <- readIORef settings'
|
||||||
Right _ -> putStrLn "Success"
|
flip runReaderT settings $ action as (ix, e) >>= \case
|
||||||
getAppData Nothing (pfreq . appData $ as) >>= \case
|
Left err -> liftIO $ putStrLn ("Error: " <> err)
|
||||||
Right data' -> do
|
Right _ -> liftIO $ putStrLn "Success"
|
||||||
putStrLn "Press enter to continue"
|
getAppData Nothing >>= \case
|
||||||
_ <- getLine
|
Right data' -> do
|
||||||
pure (updateList data' as)
|
putStrLn "Press enter to continue"
|
||||||
Left err -> throwIO $ userError err
|
_ <- getLine
|
||||||
|
pure (updateList data' as)
|
||||||
|
Left err -> throwIO $ userError err
|
||||||
|
|
||||||
|
|
||||||
-- | Update app data and list internal state based on new evidence.
|
-- | Update app data and list internal state based on new evidence.
|
||||||
@@ -351,7 +366,9 @@ constructList :: BrickData
|
|||||||
-> Maybe BrickInternalState
|
-> Maybe BrickInternalState
|
||||||
-> BrickInternalState
|
-> BrickInternalState
|
||||||
constructList appD appSettings =
|
constructList appD appSettings =
|
||||||
replaceLR (filterVisible (showAll appSettings)) (lr appD)
|
replaceLR (filterVisible (showAllVersions appSettings)
|
||||||
|
(showAllTools appSettings))
|
||||||
|
(lr appD)
|
||||||
|
|
||||||
listSelectedElement' :: BrickInternalState -> Maybe (Int, ListResult)
|
listSelectedElement' :: BrickInternalState -> Maybe (Int, ListResult)
|
||||||
listSelectedElement' BrickInternalState{..} = fmap (ix, ) $ clr !? ix
|
listSelectedElement' BrickInternalState{..} = fmap (ix, ) $ clr !? ix
|
||||||
@@ -384,21 +401,32 @@ replaceLR filterF lr s =
|
|||||||
lTool e1 == lTool e2 && lVer e1 == lVer e2 && lCross e1 == lCross e2
|
lTool e1 == lTool e2 && lVer e1 == lVer e2 && lCross e1 == lCross e2
|
||||||
|
|
||||||
|
|
||||||
filterVisible :: Bool -> ListResult -> Bool
|
filterVisible :: Bool -> Bool -> ListResult -> Bool
|
||||||
filterVisible showAll e | lInstalled e = True
|
filterVisible v t e | lInstalled e = True
|
||||||
| showAll = True
|
| v
|
||||||
| otherwise = not (elem Old (lTag e))
|
, not t
|
||||||
|
, not (elem (lTool e) hiddenTools) = True
|
||||||
|
| not v
|
||||||
|
, t
|
||||||
|
, not (elem Old (lTag e)) = True
|
||||||
|
| v
|
||||||
|
, t = True
|
||||||
|
| otherwise = not (elem Old (lTag e)) &&
|
||||||
|
not (elem (lTool e) hiddenTools)
|
||||||
|
|
||||||
|
|
||||||
install' :: BrickState -> (Int, ListResult) -> IO (Either String ())
|
install' :: (MonadReader AppState m, MonadIO m, MonadThrow m, MonadFail m, MonadMask m, MonadUnliftIO m)
|
||||||
install' BrickState { appData = BrickData {..} } (_, ListResult {..}) = do
|
=> BrickState
|
||||||
settings <- readIORef settings'
|
-> (Int, ListResult)
|
||||||
l <- readIORef logger'
|
-> m (Either String ())
|
||||||
|
install' _ (_, ListResult {..}) = do
|
||||||
|
AppState { ghcupInfo = GHCupInfo { _ghcupDownloads = dls }} <- ask
|
||||||
|
|
||||||
|
l <- liftIO $ readIORef logger'
|
||||||
let runLogger = myLoggerT l
|
let runLogger = myLoggerT l
|
||||||
|
|
||||||
let run =
|
let run =
|
||||||
runLogger
|
runLogger
|
||||||
. flip runReaderT settings
|
|
||||||
. runResourceT
|
. runResourceT
|
||||||
. runE
|
. runE
|
||||||
@'[ AlreadyInstalled
|
@'[ AlreadyInstalled
|
||||||
@@ -422,21 +450,24 @@ install' BrickState { appData = BrickData {..} } (_, ListResult {..}) = do
|
|||||||
case lTool of
|
case lTool of
|
||||||
GHC -> do
|
GHC -> do
|
||||||
let vi = getVersionInfo lVer GHC dls
|
let vi = getVersionInfo lVer GHC dls
|
||||||
liftE $ installGHCBin dls lVer pfreq $> vi
|
liftE $ installGHCBin lVer $> vi
|
||||||
Cabal -> do
|
Cabal -> do
|
||||||
let vi = getVersionInfo lVer Cabal dls
|
let vi = getVersionInfo lVer Cabal dls
|
||||||
liftE $ installCabalBin dls lVer pfreq $> vi
|
liftE $ installCabalBin lVer $> vi
|
||||||
GHCup -> do
|
GHCup -> do
|
||||||
let vi = snd <$> getLatest dls GHCup
|
let vi = snd <$> getLatest dls GHCup
|
||||||
liftE $ upgradeGHCup dls Nothing False pfreq $> vi
|
liftE $ upgradeGHCup Nothing False $> vi
|
||||||
HLS -> do
|
HLS -> do
|
||||||
let vi = getVersionInfo lVer HLS dls
|
let vi = getVersionInfo lVer HLS dls
|
||||||
liftE $ installHLSBin dls lVer pfreq $> vi
|
liftE $ installHLSBin lVer $> vi
|
||||||
|
Stack -> do
|
||||||
|
let vi = getVersionInfo lVer Stack dls
|
||||||
|
liftE $ installStackBin lVer $> vi
|
||||||
)
|
)
|
||||||
>>= \case
|
>>= \case
|
||||||
VRight vi -> do
|
VRight vi -> do
|
||||||
forM_ (_viPostInstall =<< vi) $ \msg ->
|
forM_ (_viPostInstall =<< vi) $ \msg ->
|
||||||
runLogger $ $(logInfo) msg
|
myLoggerT l $ $(logInfo) msg
|
||||||
pure $ Right ()
|
pure $ Right ()
|
||||||
VLeft (V (AlreadyInstalled _ _)) -> pure $ Right ()
|
VLeft (V (AlreadyInstalled _ _)) -> pure $ Right ()
|
||||||
VLeft (V NoUpdate) -> pure $ Right ()
|
VLeft (V NoUpdate) -> pure $ Right ()
|
||||||
@@ -460,6 +491,7 @@ set' _ (_, ListResult {..}) = do
|
|||||||
GHC -> liftE $ setGHC (GHCTargetVersion lCross lVer) SetGHCOnly $> ()
|
GHC -> liftE $ setGHC (GHCTargetVersion lCross lVer) SetGHCOnly $> ()
|
||||||
Cabal -> liftE $ setCabal lVer $> ()
|
Cabal -> liftE $ setCabal lVer $> ()
|
||||||
HLS -> liftE $ setHLS lVer $> ()
|
HLS -> liftE $ setHLS lVer $> ()
|
||||||
|
Stack -> liftE $ setStack lVer $> ()
|
||||||
GHCup -> pure ()
|
GHCup -> pure ()
|
||||||
)
|
)
|
||||||
>>= \case
|
>>= \case
|
||||||
@@ -467,13 +499,16 @@ set' _ (_, ListResult {..}) = do
|
|||||||
VLeft e -> pure $ Left (prettyShow e)
|
VLeft e -> pure $ Left (prettyShow e)
|
||||||
|
|
||||||
|
|
||||||
del' :: BrickState -> (Int, ListResult) -> IO (Either String ())
|
del' :: (MonadReader AppState m, MonadIO m, MonadFail m, MonadMask m, MonadUnliftIO m)
|
||||||
del' BrickState { appData = BrickData {..} } (_, ListResult {..}) = do
|
=> BrickState
|
||||||
settings <- readIORef settings'
|
-> (Int, ListResult)
|
||||||
l <- readIORef logger'
|
-> m (Either String ())
|
||||||
let runLogger = myLoggerT l
|
del' _ (_, ListResult {..}) = do
|
||||||
|
AppState { ghcupInfo = GHCupInfo { _ghcupDownloads = dls }} <- ask
|
||||||
|
|
||||||
let run = runLogger . flip runReaderT settings . runE @'[NotInstalled]
|
l <- liftIO $ readIORef logger'
|
||||||
|
let runLogger = myLoggerT l
|
||||||
|
let run = myLoggerT l . runE @'[NotInstalled]
|
||||||
|
|
||||||
run (do
|
run (do
|
||||||
let vi = getVersionInfo lVer lTool dls
|
let vi = getVersionInfo lVer lTool dls
|
||||||
@@ -481,6 +516,7 @@ del' BrickState { appData = BrickData {..} } (_, ListResult {..}) = do
|
|||||||
GHC -> liftE $ rmGHCVer (GHCTargetVersion lCross lVer) $> vi
|
GHC -> liftE $ rmGHCVer (GHCTargetVersion lCross lVer) $> vi
|
||||||
Cabal -> liftE $ rmCabalVer lVer $> vi
|
Cabal -> liftE $ rmCabalVer lVer $> vi
|
||||||
HLS -> liftE $ rmHLSVer lVer $> vi
|
HLS -> liftE $ rmHLSVer lVer $> vi
|
||||||
|
Stack -> liftE $ rmStackVer lVer $> vi
|
||||||
GHCup -> pure Nothing
|
GHCup -> pure Nothing
|
||||||
)
|
)
|
||||||
>>= \case
|
>>= \case
|
||||||
@@ -491,8 +527,12 @@ del' BrickState { appData = BrickData {..} } (_, ListResult {..}) = do
|
|||||||
VLeft e -> pure $ Left (prettyShow e)
|
VLeft e -> pure $ Left (prettyShow e)
|
||||||
|
|
||||||
|
|
||||||
changelog' :: BrickState -> (Int, ListResult) -> IO (Either String ())
|
changelog' :: (MonadReader AppState m, MonadIO m)
|
||||||
changelog' BrickState { appData = BrickData {..} } (_, ListResult {..}) = do
|
=> BrickState
|
||||||
|
-> (Int, ListResult)
|
||||||
|
-> m (Either String ())
|
||||||
|
changelog' _ (_, ListResult {..}) = do
|
||||||
|
AppState { pfreq, ghcupInfo = GHCupInfo { _ghcupDownloads = dls }} <- ask
|
||||||
case getChangeLog dls lTool (Left lVer) of
|
case getChangeLog dls lTool (Left lVer) of
|
||||||
Nothing -> pure $ Left
|
Nothing -> pure $ Left
|
||||||
[i|Could not find ChangeLog for #{lTool}, version #{prettyVer lVer}|]
|
[i|Could not find ChangeLog for #{lTool}, version #{prettyVer lVer}|]
|
||||||
@@ -501,7 +541,8 @@ changelog' BrickState { appData = BrickData {..} } (_, ListResult {..}) = do
|
|||||||
Darwin -> "open"
|
Darwin -> "open"
|
||||||
Linux _ -> "xdg-open"
|
Linux _ -> "xdg-open"
|
||||||
FreeBSD -> "xdg-open"
|
FreeBSD -> "xdg-open"
|
||||||
exec cmd True [serializeURIRef' uri] Nothing Nothing >>= \case
|
Windows -> "start"
|
||||||
|
exec cmd [T.unpack $ decUTF8Safe $ serializeURIRef' uri] Nothing Nothing >>= \case
|
||||||
Right _ -> pure $ Right ()
|
Right _ -> pure $ Right ()
|
||||||
Left e -> pure $ Left $ prettyShow e
|
Left e -> pure $ Left $ prettyShow e
|
||||||
|
|
||||||
@@ -520,6 +561,8 @@ settings' = unsafePerformIO $ do
|
|||||||
})
|
})
|
||||||
dirs
|
dirs
|
||||||
defaultKeyBindings
|
defaultKeyBindings
|
||||||
|
(GHCupInfo mempty mempty mempty)
|
||||||
|
(PlatformRequest A_64 Darwin Nothing)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -535,10 +578,9 @@ logger' = unsafePerformIO
|
|||||||
|
|
||||||
brickMain :: AppState
|
brickMain :: AppState
|
||||||
-> LoggerConfig
|
-> LoggerConfig
|
||||||
-> GHCupDownloads
|
-> GHCupInfo
|
||||||
-> PlatformRequest
|
|
||||||
-> IO ()
|
-> IO ()
|
||||||
brickMain s l av pfreq' = do
|
brickMain s l gi = do
|
||||||
writeIORef settings' s
|
writeIORef settings' s
|
||||||
-- logger interpreter
|
-- logger interpreter
|
||||||
writeIORef logger' l
|
writeIORef logger' l
|
||||||
@@ -546,7 +588,7 @@ brickMain s l av pfreq' = do
|
|||||||
|
|
||||||
no_color <- isJust <$> lookupEnv "NO_COLOR"
|
no_color <- isJust <$> lookupEnv "NO_COLOR"
|
||||||
|
|
||||||
eAppData <- getAppData (Just av) pfreq'
|
eAppData <- getAppData (Just gi)
|
||||||
case eAppData of
|
case eAppData of
|
||||||
Right ad ->
|
Right ad ->
|
||||||
defaultMain
|
defaultMain
|
||||||
@@ -564,11 +606,11 @@ brickMain s l av pfreq' = do
|
|||||||
|
|
||||||
|
|
||||||
defaultAppSettings :: BrickSettings
|
defaultAppSettings :: BrickSettings
|
||||||
defaultAppSettings = BrickSettings { showAll = False }
|
defaultAppSettings = BrickSettings { showAllVersions = False, showAllTools = False }
|
||||||
|
|
||||||
|
|
||||||
getDownloads' :: IO (Either String GHCupDownloads)
|
getGHCupInfo :: IO (Either String GHCupInfo)
|
||||||
getDownloads' = do
|
getGHCupInfo = do
|
||||||
settings <- readIORef settings'
|
settings <- readIORef settings'
|
||||||
l <- readIORef logger'
|
l <- readIORef logger'
|
||||||
let runLogger = myLoggerT l
|
let runLogger = myLoggerT l
|
||||||
@@ -577,29 +619,25 @@ getDownloads' = do
|
|||||||
runLogger
|
runLogger
|
||||||
. flip runReaderT settings
|
. flip runReaderT settings
|
||||||
. runE @'[JSONError , DownloadFailed , FileDoesNotExistError]
|
. runE @'[JSONError , DownloadFailed , FileDoesNotExistError]
|
||||||
$ fmap _ghcupDownloads
|
|
||||||
$ liftE
|
$ liftE
|
||||||
$ getDownloadsF (urlSource . GT.settings $ settings)
|
$ getDownloadsF (GT.settings settings) (GT.dirs settings)
|
||||||
|
|
||||||
case r of
|
case r of
|
||||||
VRight a -> pure $ Right a
|
VRight a -> pure $ Right a
|
||||||
VLeft e -> pure $ Left (prettyShow e)
|
VLeft e -> pure $ Left (prettyShow e)
|
||||||
|
|
||||||
|
|
||||||
getAppData :: Maybe GHCupDownloads
|
getAppData :: Maybe GHCupInfo
|
||||||
-> PlatformRequest
|
|
||||||
-> IO (Either String BrickData)
|
-> IO (Either String BrickData)
|
||||||
getAppData mg pfreq' = do
|
getAppData mgi = runExceptT $ do
|
||||||
settings <- readIORef settings'
|
l <- liftIO $ readIORef logger'
|
||||||
l <- readIORef logger'
|
|
||||||
let runLogger = myLoggerT l
|
let runLogger = myLoggerT l
|
||||||
|
|
||||||
r <- maybe getDownloads' (pure . Right) mg
|
r <- ExceptT $ maybe getGHCupInfo (pure . Right) mgi
|
||||||
|
liftIO $ modifyIORef settings' (\s -> s { ghcupInfo = r })
|
||||||
|
settings <- liftIO $ readIORef settings'
|
||||||
|
|
||||||
runLogger . flip runReaderT settings $ do
|
runLogger . flip runReaderT settings $ do
|
||||||
case r of
|
lV <- listVersions Nothing Nothing
|
||||||
Right dls -> do
|
pure $ BrickData (reverse lV)
|
||||||
lV <- listVersions dls Nothing Nothing pfreq'
|
|
||||||
pure $ Right $ BrickData (reverse lV) dls pfreq'
|
|
||||||
Left e -> pure $ Left [i|#{e}|]
|
|
||||||
|
|
||||||
|
|||||||
@@ -53,8 +53,6 @@ import Data.Versions hiding ( str )
|
|||||||
import Data.Void
|
import Data.Void
|
||||||
import GHC.IO.Encoding
|
import GHC.IO.Encoding
|
||||||
import Haskus.Utils.Variant.Excepts
|
import Haskus.Utils.Variant.Excepts
|
||||||
import HPath
|
|
||||||
import HPath.IO
|
|
||||||
import Language.Haskell.TH
|
import Language.Haskell.TH
|
||||||
import Options.Applicative hiding ( style )
|
import Options.Applicative hiding ( style )
|
||||||
import Options.Applicative.Help.Pretty ( text )
|
import Options.Applicative.Help.Pretty ( text )
|
||||||
@@ -64,6 +62,7 @@ import System.Console.Pretty hiding ( color )
|
|||||||
import qualified System.Console.Pretty as Pretty
|
import qualified System.Console.Pretty as Pretty
|
||||||
import System.Environment
|
import System.Environment
|
||||||
import System.Exit
|
import System.Exit
|
||||||
|
import System.FilePath
|
||||||
import System.IO hiding ( appendFile )
|
import System.IO hiding ( appendFile )
|
||||||
import Text.Read hiding ( lift )
|
import Text.Read hiding ( lift )
|
||||||
import Text.PrettyPrint.HughesPJClass ( prettyShow )
|
import Text.PrettyPrint.HughesPJClass ( prettyShow )
|
||||||
@@ -80,8 +79,6 @@ import qualified Text.Megaparsec.Char as MPC
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data Options = Options
|
data Options = Options
|
||||||
{
|
{
|
||||||
-- global options
|
-- global options
|
||||||
@@ -106,6 +103,7 @@ data Command
|
|||||||
| Upgrade UpgradeOpts Bool
|
| Upgrade UpgradeOpts Bool
|
||||||
| ToolRequirements
|
| ToolRequirements
|
||||||
| ChangeLog ChangeLogOptions
|
| ChangeLog ChangeLogOptions
|
||||||
|
| Nuke
|
||||||
#if defined(BRICK)
|
#if defined(BRICK)
|
||||||
| Interactive
|
| Interactive
|
||||||
#endif
|
#endif
|
||||||
@@ -126,6 +124,7 @@ toSetToolVer Nothing = SetRecommended
|
|||||||
data InstallCommand = InstallGHC InstallOptions
|
data InstallCommand = InstallGHC InstallOptions
|
||||||
| InstallCabal InstallOptions
|
| InstallCabal InstallOptions
|
||||||
| InstallHLS InstallOptions
|
| InstallHLS InstallOptions
|
||||||
|
| InstallStack InstallOptions
|
||||||
|
|
||||||
data InstallOptions = InstallOptions
|
data InstallOptions = InstallOptions
|
||||||
{ instVer :: Maybe ToolVersion
|
{ instVer :: Maybe ToolVersion
|
||||||
@@ -137,6 +136,7 @@ data InstallOptions = InstallOptions
|
|||||||
data SetCommand = SetGHC SetOptions
|
data SetCommand = SetGHC SetOptions
|
||||||
| SetCabal SetOptions
|
| SetCabal SetOptions
|
||||||
| SetHLS SetOptions
|
| SetHLS SetOptions
|
||||||
|
| SetStack SetOptions
|
||||||
|
|
||||||
-- a superset of ToolVersion
|
-- a superset of ToolVersion
|
||||||
data SetToolVersion = SetToolVersion GHCTargetVersion
|
data SetToolVersion = SetToolVersion GHCTargetVersion
|
||||||
@@ -157,6 +157,7 @@ data ListOptions = ListOptions
|
|||||||
data RmCommand = RmGHC RmOptions
|
data RmCommand = RmGHC RmOptions
|
||||||
| RmCabal Version
|
| RmCabal Version
|
||||||
| RmHLS Version
|
| RmHLS Version
|
||||||
|
| RmStack Version
|
||||||
|
|
||||||
data RmOptions = RmOptions
|
data RmOptions = RmOptions
|
||||||
{ ghcVer :: GHCTargetVersion
|
{ ghcVer :: GHCTargetVersion
|
||||||
@@ -167,17 +168,18 @@ data CompileCommand = CompileGHC GHCCompileOptions
|
|||||||
|
|
||||||
data GHCCompileOptions = GHCCompileOptions
|
data GHCCompileOptions = GHCCompileOptions
|
||||||
{ targetGhc :: Either Version GitBranch
|
{ targetGhc :: Either Version GitBranch
|
||||||
, bootstrapGhc :: Either Version (Path Abs)
|
, bootstrapGhc :: Either Version FilePath
|
||||||
, jobs :: Maybe Int
|
, jobs :: Maybe Int
|
||||||
, buildConfig :: Maybe (Path Abs)
|
, buildConfig :: Maybe FilePath
|
||||||
, patchDir :: Maybe (Path Abs)
|
, patchDir :: Maybe FilePath
|
||||||
, crossTarget :: Maybe Text
|
, crossTarget :: Maybe Text
|
||||||
, addConfArgs :: [Text]
|
, addConfArgs :: [Text]
|
||||||
, setCompile :: Bool
|
, setCompile :: Bool
|
||||||
|
, ovewrwiteVer :: Maybe Version
|
||||||
}
|
}
|
||||||
|
|
||||||
data UpgradeOpts = UpgradeInplace
|
data UpgradeOpts = UpgradeInplace
|
||||||
| UpgradeAt (Path Abs)
|
| UpgradeAt FilePath
|
||||||
| UpgradeGHCupDir
|
| UpgradeGHCupDir
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
@@ -218,7 +220,7 @@ invertableSwitch'
|
|||||||
-> Mod FlagFields Bool -- ^ option modifier for --no-foo
|
-> Mod FlagFields Bool -- ^ option modifier for --no-foo
|
||||||
-> Parser (Maybe Bool)
|
-> Parser (Maybe Bool)
|
||||||
invertableSwitch' longopt shortopt defv enmod dismod = optional
|
invertableSwitch' longopt shortopt defv enmod dismod = optional
|
||||||
( flag' True (enmod <> long longopt <> if defv then mempty else short shortopt)
|
( flag' True ( enmod <> long longopt <> if defv then mempty else short shortopt)
|
||||||
<|> flag' False (dismod <> long nolongopt <> if defv then short shortopt else mempty)
|
<|> flag' False (dismod <> long nolongopt <> if defv then short shortopt else mempty)
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
@@ -291,7 +293,7 @@ com =
|
|||||||
( Install
|
( Install
|
||||||
<$> info
|
<$> info
|
||||||
(installParser <**> helper)
|
(installParser <**> helper)
|
||||||
( progDesc "Install or update GHC/cabal"
|
( progDesc "Install or update GHC/cabal/HLS"
|
||||||
<> footerDoc (Just $ text installToolFooter)
|
<> footerDoc (Just $ text installToolFooter)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -307,7 +309,7 @@ com =
|
|||||||
"rm"
|
"rm"
|
||||||
(info
|
(info
|
||||||
(Rm <$> rmParser <**> helper)
|
(Rm <$> rmParser <**> helper)
|
||||||
( progDesc "Remove a GHC/cabal version"
|
( progDesc "Remove a GHC/cabal/HLS version"
|
||||||
<> footerDoc (Just $ text rmFooter)
|
<> footerDoc (Just $ text rmFooter)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -367,6 +369,14 @@ com =
|
|||||||
)
|
)
|
||||||
<> internal
|
<> internal
|
||||||
)
|
)
|
||||||
|
<|> subparser
|
||||||
|
(command
|
||||||
|
"nuke"
|
||||||
|
(info (pure Nuke <**> helper)
|
||||||
|
(progDesc "Completely remove ghcup from your system"))
|
||||||
|
<> commandGroup "Nuclear Commands:"
|
||||||
|
)
|
||||||
|
|
||||||
where
|
where
|
||||||
installToolFooter :: String
|
installToolFooter :: String
|
||||||
installToolFooter = [s|Discussion:
|
installToolFooter = [s|Discussion:
|
||||||
@@ -392,7 +402,6 @@ com =
|
|||||||
By default returns the URI of the ChangeLog of the latest GHC release.
|
By default returns the URI of the ChangeLog of the latest GHC release.
|
||||||
Pass '-o' to automatically open via xdg-open.|]
|
Pass '-o' to automatically open via xdg-open.|]
|
||||||
|
|
||||||
|
|
||||||
installCabalFooter :: String
|
installCabalFooter :: String
|
||||||
installCabalFooter = [s|Discussion:
|
installCabalFooter = [s|Discussion:
|
||||||
Installs the specified cabal-install version (or a recommended default one)
|
Installs the specified cabal-install version (or a recommended default one)
|
||||||
@@ -432,6 +441,15 @@ installParser =
|
|||||||
<> footerDoc (Just $ text installHLSFooter)
|
<> footerDoc (Just $ text installHLSFooter)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
<> command
|
||||||
|
"stack"
|
||||||
|
( InstallStack
|
||||||
|
<$> info
|
||||||
|
(installOpts (Just Stack) <**> helper)
|
||||||
|
( progDesc "Install stack"
|
||||||
|
<> footerDoc (Just $ text installStackFooter)
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
<|> (Right <$> installOpts Nothing)
|
<|> (Right <$> installOpts Nothing)
|
||||||
@@ -442,9 +460,17 @@ installParser =
|
|||||||
into "~/.ghcup/bin"
|
into "~/.ghcup/bin"
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
# install recommended GHC
|
# install recommended HLS
|
||||||
ghcup install hls|]
|
ghcup install hls|]
|
||||||
|
|
||||||
|
installStackFooter :: String
|
||||||
|
installStackFooter = [s|Discussion:
|
||||||
|
Installs stack binaries into "~/.ghcup/bin"
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
# install recommended Stack
|
||||||
|
ghcup install stack|]
|
||||||
|
|
||||||
installGHCFooter :: String
|
installGHCFooter :: String
|
||||||
installGHCFooter = [s|Discussion:
|
installGHCFooter = [s|Discussion:
|
||||||
Installs the specified GHC version (or a recommended default one) into
|
Installs the specified GHC version (or a recommended default one) into
|
||||||
@@ -528,6 +554,15 @@ setParser =
|
|||||||
<> footerDoc (Just $ text setHLSFooter)
|
<> footerDoc (Just $ text setHLSFooter)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
<> command
|
||||||
|
"stack"
|
||||||
|
( SetStack
|
||||||
|
<$> info
|
||||||
|
(setOpts (Just Stack) <**> helper)
|
||||||
|
( progDesc "Set stack version"
|
||||||
|
<> footerDoc (Just $ text setStackFooter)
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
<|> (Right <$> setOpts Nothing)
|
<|> (Right <$> setOpts Nothing)
|
||||||
@@ -542,6 +577,10 @@ setParser =
|
|||||||
setCabalFooter = [s|Discussion:
|
setCabalFooter = [s|Discussion:
|
||||||
Sets the the current Cabal version.|]
|
Sets the the current Cabal version.|]
|
||||||
|
|
||||||
|
setStackFooter :: String
|
||||||
|
setStackFooter = [s|Discussion:
|
||||||
|
Sets the the current Stack version.|]
|
||||||
|
|
||||||
setHLSFooter :: String
|
setHLSFooter :: String
|
||||||
setHLSFooter = [s|Discussion:
|
setHLSFooter = [s|Discussion:
|
||||||
Sets the the current haskell-language-server version.|]
|
Sets the the current haskell-language-server version.|]
|
||||||
@@ -594,6 +633,12 @@ rmParser =
|
|||||||
<$> info (versionParser' (Just ListInstalled) (Just HLS) <**> helper)
|
<$> info (versionParser' (Just ListInstalled) (Just HLS) <**> helper)
|
||||||
(progDesc "Remove haskell-language-server version")
|
(progDesc "Remove haskell-language-server version")
|
||||||
)
|
)
|
||||||
|
<> command
|
||||||
|
"stack"
|
||||||
|
( RmStack
|
||||||
|
<$> info (versionParser' (Just ListInstalled) (Just Stack) <**> helper)
|
||||||
|
(progDesc "Remove stack version")
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
<|> (Right <$> rmOpts Nothing)
|
<|> (Right <$> rmOpts Nothing)
|
||||||
@@ -615,6 +660,7 @@ changelogP =
|
|||||||
"ghc" -> Right GHC
|
"ghc" -> Right GHC
|
||||||
"cabal" -> Right Cabal
|
"cabal" -> Right Cabal
|
||||||
"ghcup" -> Right GHCup
|
"ghcup" -> Right GHCup
|
||||||
|
"stack" -> Right Stack
|
||||||
e -> Left e
|
e -> Left e
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -681,8 +727,7 @@ ghcCompileOpts =
|
|||||||
<*> option
|
<*> option
|
||||||
(eitherReader
|
(eitherReader
|
||||||
(\x ->
|
(\x ->
|
||||||
(bimap (const "Not a valid version") Left . version . T.pack $ x)
|
(bimap (const "Not a valid version") Left . version . T.pack $ x) <|> (if isPathSeparator (head x) then pure $ Right x else Left "Not an absolute Path")
|
||||||
<|> (bimap show Right . parseAbs . E.encodeUtf8 . T.pack $ x)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
( short 'b'
|
( short 'b'
|
||||||
@@ -700,26 +745,14 @@ ghcCompileOpts =
|
|||||||
)
|
)
|
||||||
<*> optional
|
<*> optional
|
||||||
(option
|
(option
|
||||||
(eitherReader
|
str
|
||||||
(\x ->
|
|
||||||
first show . parseAbs . E.encodeUtf8 . T.pack $ x :: Either
|
|
||||||
String
|
|
||||||
(Path Abs)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
(short 'c' <> long "config" <> metavar "CONFIG" <> help
|
(short 'c' <> long "config" <> metavar "CONFIG" <> help
|
||||||
"Absolute path to build config file"
|
"Absolute path to build config file"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
<*> optional
|
<*> optional
|
||||||
(option
|
(option
|
||||||
(eitherReader
|
str
|
||||||
(\x ->
|
|
||||||
first show . parseAbs . E.encodeUtf8 . T.pack $ x :: Either
|
|
||||||
String
|
|
||||||
(Path Abs)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
(short 'p' <> long "patchdir" <> metavar "PATCH_DIR" <> help
|
(short 'p' <> long "patchdir" <> metavar "PATCH_DIR" <> help
|
||||||
"Absolute path to patch directory (applied in order, uses -p1)"
|
"Absolute path to patch directory (applied in order, uses -p1)"
|
||||||
)
|
)
|
||||||
@@ -738,6 +771,15 @@ ghcCompileOpts =
|
|||||||
(long "set" <> help
|
(long "set" <> help
|
||||||
"Set as active version after install"
|
"Set as active version after install"
|
||||||
)
|
)
|
||||||
|
<*> optional
|
||||||
|
(option
|
||||||
|
(eitherReader
|
||||||
|
(first (const "Not a valid version") . version . T.pack)
|
||||||
|
)
|
||||||
|
(short 'o' <> long "overwrite-version" <> metavar "OVERWRITE_VERSION" <> help
|
||||||
|
"Allows to overwrite the finally installed VERSION with a different one, e.g. when you build 8.10.4 with your own patches, you might want to set this to '8.10.4-p1'"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
toolVersionParser :: Parser ToolVersion
|
toolVersionParser :: Parser ToolVersion
|
||||||
@@ -781,53 +823,47 @@ versionArgument criteria tool = argument (eitherReader tVersionEither) (metavar
|
|||||||
|
|
||||||
tagCompleter :: Tool -> [String] -> Completer
|
tagCompleter :: Tool -> [String] -> Completer
|
||||||
tagCompleter tool add = listIOCompleter $ do
|
tagCompleter tool add = listIOCompleter $ do
|
||||||
|
dirs' <- liftIO getDirs
|
||||||
let loggerConfig = LoggerConfig
|
let loggerConfig = LoggerConfig
|
||||||
{ lcPrintDebug = False
|
{ lcPrintDebug = False
|
||||||
, colorOutter = mempty
|
, colorOutter = mempty
|
||||||
, rawOutter = mempty
|
, rawOutter = mempty
|
||||||
}
|
}
|
||||||
|
let runLogger = myLoggerT loggerConfig
|
||||||
runLogger = myLoggerT loggerConfig
|
mGhcUpInfo <- runLogger . runE $ readFromCache dirs'
|
||||||
|
|
||||||
dirs <- getDirs
|
|
||||||
let simpleSettings = Settings False False Never Curl False GHCupURL
|
|
||||||
simpleAppState = AppState simpleSettings dirs defaultKeyBindings
|
|
||||||
runEnv = runLogger . flip runReaderT simpleAppState
|
|
||||||
|
|
||||||
mGhcUpInfo <- runEnv . runE $ readFromCache
|
|
||||||
|
|
||||||
case mGhcUpInfo of
|
case mGhcUpInfo of
|
||||||
VRight dls -> do
|
VRight ghcupInfo -> do
|
||||||
let allTags = filter (\t -> t /= Old)
|
let allTags = filter (\t -> t /= Old)
|
||||||
$ join
|
$ join
|
||||||
$ M.elems
|
$ M.elems
|
||||||
$ availableToolVersions (_ghcupDownloads dls) tool
|
$ availableToolVersions (_ghcupDownloads ghcupInfo) tool
|
||||||
pure $ nub $ (add ++) $ fmap tagToString allTags
|
pure $ nub $ (add ++) $ fmap tagToString allTags
|
||||||
VLeft _ -> pure (nub $ ["recommended", "latest"] ++ add)
|
VLeft _ -> pure (nub $ ["recommended", "latest"] ++ add)
|
||||||
|
|
||||||
|
|
||||||
versionCompleter :: Maybe ListCriteria -> Tool -> Completer
|
versionCompleter :: Maybe ListCriteria -> Tool -> Completer
|
||||||
versionCompleter criteria tool = listIOCompleter $ do
|
versionCompleter criteria tool = listIOCompleter $ do
|
||||||
|
dirs' <- liftIO getDirs
|
||||||
let loggerConfig = LoggerConfig
|
let loggerConfig = LoggerConfig
|
||||||
{ lcPrintDebug = False
|
{ lcPrintDebug = False
|
||||||
, colorOutter = mempty
|
, colorOutter = mempty
|
||||||
, rawOutter = mempty
|
, rawOutter = mempty
|
||||||
}
|
}
|
||||||
|
let runLogger = myLoggerT loggerConfig
|
||||||
runLogger = myLoggerT loggerConfig
|
mGhcUpInfo <- runLogger . runE $ readFromCache dirs'
|
||||||
|
|
||||||
mpFreq <- runLogger . runE $ platformRequest
|
mpFreq <- runLogger . runE $ platformRequest
|
||||||
|
forFold mpFreq $ \pfreq ->
|
||||||
|
forFold mGhcUpInfo $ \ghcupInfo -> do
|
||||||
|
let appState = AppState
|
||||||
|
(Settings True False Never Curl False GHCupURL)
|
||||||
|
dirs'
|
||||||
|
defaultKeyBindings
|
||||||
|
ghcupInfo
|
||||||
|
pfreq
|
||||||
|
|
||||||
forFold mpFreq $ \pfreq -> do
|
runEnv = runLogger . flip runReaderT appState
|
||||||
dirs <- getDirs
|
|
||||||
let simpleSettings = Settings False False Never Curl False GHCupURL
|
|
||||||
simpleAppState = AppState simpleSettings dirs defaultKeyBindings
|
|
||||||
runEnv = runLogger . flip runReaderT simpleAppState
|
|
||||||
|
|
||||||
mGhcUpInfo <- runEnv . runE $ readFromCache
|
installedVersions <- runEnv $ listVersions (Just tool) criteria
|
||||||
|
|
||||||
forFold mGhcUpInfo $ \(GHCupInfo _ dls) -> do
|
|
||||||
installedVersions <- runEnv $ listVersions dls (Just tool) criteria pfreq
|
|
||||||
return $ T.unpack . prettyVer . lVer <$> installedVersions
|
return $ T.unpack . prettyVer . lVer <$> installedVersions
|
||||||
|
|
||||||
|
|
||||||
@@ -948,9 +984,8 @@ bindistParser :: String -> Either String URI
|
|||||||
bindistParser = first show . parseURI strictURIParserOptions . UTF8.fromString
|
bindistParser = first show . parseURI strictURIParserOptions . UTF8.fromString
|
||||||
|
|
||||||
|
|
||||||
toSettings :: Options -> IO AppState
|
toSettings :: Options -> IO (Settings, KeyBindings)
|
||||||
toSettings options = do
|
toSettings options = do
|
||||||
dirs <- getDirs
|
|
||||||
userConf <- runE @'[ JSONError ] ghcupConfigFile >>= \case
|
userConf <- runE @'[ JSONError ] ghcupConfigFile >>= \case
|
||||||
VRight r -> pure r
|
VRight r -> pure r
|
||||||
VLeft (V (JSONDecodeError e)) -> do
|
VLeft (V (JSONDecodeError e)) -> do
|
||||||
@@ -958,10 +993,10 @@ toSettings options = do
|
|||||||
pure defaultUserSettings
|
pure defaultUserSettings
|
||||||
_ -> do
|
_ -> do
|
||||||
die "Unexpected error!"
|
die "Unexpected error!"
|
||||||
pure $ mergeConf options dirs userConf
|
pure $ mergeConf options userConf
|
||||||
where
|
where
|
||||||
mergeConf :: Options -> Dirs -> UserSettings -> AppState
|
mergeConf :: Options -> UserSettings -> (Settings, KeyBindings)
|
||||||
mergeConf Options{..} dirs UserSettings{..} =
|
mergeConf Options{..} UserSettings{..} =
|
||||||
let cache = fromMaybe (fromMaybe False uCache) optCache
|
let cache = fromMaybe (fromMaybe False uCache) optCache
|
||||||
noVerify = fromMaybe (fromMaybe False uNoVerify) optNoVerify
|
noVerify = fromMaybe (fromMaybe False uNoVerify) optNoVerify
|
||||||
verbose = fromMaybe (fromMaybe False uVerbose) optVerbose
|
verbose = fromMaybe (fromMaybe False uVerbose) optVerbose
|
||||||
@@ -969,7 +1004,7 @@ toSettings options = do
|
|||||||
downloader = fromMaybe (fromMaybe defaultDownloader uDownloader) optsDownloader
|
downloader = fromMaybe (fromMaybe defaultDownloader uDownloader) optsDownloader
|
||||||
keyBindings = maybe defaultKeyBindings mergeKeys uKeyBindings
|
keyBindings = maybe defaultKeyBindings mergeKeys uKeyBindings
|
||||||
urlSource = maybe (fromMaybe GHCupURL uUrlSource) OwnSource optUrlSource
|
urlSource = maybe (fromMaybe GHCupURL uUrlSource) OwnSource optUrlSource
|
||||||
in AppState (Settings {..}) dirs keyBindings
|
in (Settings {..}, keyBindings)
|
||||||
#if defined(INTERNAL_DOWNLOADER)
|
#if defined(INTERNAL_DOWNLOADER)
|
||||||
defaultDownloader = Internal
|
defaultDownloader = Internal
|
||||||
#else
|
#else
|
||||||
@@ -986,7 +1021,8 @@ toSettings options = do
|
|||||||
, bUninstall = fromMaybe bUninstall kUninstall
|
, bUninstall = fromMaybe bUninstall kUninstall
|
||||||
, bSet = fromMaybe bSet kSet
|
, bSet = fromMaybe bSet kSet
|
||||||
, bChangelog = fromMaybe bChangelog kChangelog
|
, bChangelog = fromMaybe bChangelog kChangelog
|
||||||
, bShowAll = fromMaybe bShowAll kShowAll
|
, bShowAllVersions = fromMaybe bShowAllVersions kShowAll
|
||||||
|
, bShowAllTools = fromMaybe bShowAllTools kShowAllTools
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -999,13 +1035,7 @@ upgradeOptsP =
|
|||||||
)
|
)
|
||||||
<|> ( UpgradeAt
|
<|> ( UpgradeAt
|
||||||
<$> option
|
<$> option
|
||||||
(eitherReader
|
str
|
||||||
(\x ->
|
|
||||||
first show . parseAbs . E.encodeUtf8 . T.pack $ x :: Either
|
|
||||||
String
|
|
||||||
(Path Abs)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
(short 't' <> long "target" <> metavar "TARGET_DIR" <> help
|
(short 't' <> long "target" <> metavar "TARGET_DIR" <> help
|
||||||
"Absolute filepath to write ghcup into"
|
"Absolute filepath to write ghcup into"
|
||||||
)
|
)
|
||||||
@@ -1017,9 +1047,12 @@ upgradeOptsP =
|
|||||||
describe_result :: String
|
describe_result :: String
|
||||||
describe_result = $( LitE . StringL <$>
|
describe_result = $( LitE . StringL <$>
|
||||||
runIO (do
|
runIO (do
|
||||||
CapturedProcess{..} <- executeOut [rel|git|] ["describe"] Nothing
|
CapturedProcess{..} <- do
|
||||||
|
dirs <- liftIO getDirs
|
||||||
|
let settings = AppState (Settings True False Never Curl False GHCupURL) dirs defaultKeyBindings
|
||||||
|
flip runReaderT settings $ executeOut "git" ["describe"] Nothing
|
||||||
case _exitCode of
|
case _exitCode of
|
||||||
ExitSuccess -> pure . T.unpack . decUTF8Safe $ _stdOut
|
ExitSuccess -> pure . T.unpack . decUTF8Safe' $ _stdOut
|
||||||
ExitFailure _ -> pure numericVer
|
ExitFailure _ -> pure numericVer
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -1027,6 +1060,11 @@ describe_result = $( LitE . StringL <$>
|
|||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
|
-- https://gitlab.haskell.org/ghc/ghc/issues/8118
|
||||||
|
setLocaleEncoding utf8
|
||||||
|
|
||||||
|
void enableAnsiSupport
|
||||||
|
|
||||||
let versionHelp = infoOption
|
let versionHelp = infoOption
|
||||||
( ("The GHCup Haskell installer, version " <>)
|
( ("The GHCup Haskell installer, version " <>)
|
||||||
(head . lines $ describe_result)
|
(head . lines $ describe_result)
|
||||||
@@ -1063,28 +1101,82 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
(footerDoc (Just $ text main_footer))
|
(footerDoc (Just $ text main_footer))
|
||||||
)
|
)
|
||||||
>>= \opt@Options {..} -> do
|
>>= \opt@Options {..} -> do
|
||||||
appstate@AppState{dirs = Dirs{..}, ..} <- toSettings opt
|
dirs <- getDirs
|
||||||
|
|
||||||
-- create ~/.ghcup dir
|
-- create ~/.ghcup dir
|
||||||
createDirRecursive' baseDir
|
ensureDirectories dirs
|
||||||
|
|
||||||
|
(settings, keybindings) <- toSettings opt
|
||||||
|
|
||||||
-- logger interpreter
|
-- logger interpreter
|
||||||
logfile <- flip runReaderT appstate $ initGHCupFileLogging
|
logfile <- initGHCupFileLogging (logsDir dirs)
|
||||||
let loggerConfig = LoggerConfig
|
let loggerConfig = LoggerConfig
|
||||||
{ lcPrintDebug = verbose settings
|
{ lcPrintDebug = verbose settings
|
||||||
, colorOutter = B.hPut stderr
|
, colorOutter = B.hPut stderr
|
||||||
, rawOutter = appendFile logfile
|
, rawOutter =
|
||||||
|
case optCommand of
|
||||||
|
Nuke -> \_ -> pure ()
|
||||||
|
_ -> B.appendFile logfile
|
||||||
}
|
}
|
||||||
let runLogger = myLoggerT loggerConfig
|
let runLogger = myLoggerT loggerConfig
|
||||||
|
let siletRunLogger = myLoggerT loggerConfig { colorOutter = \_ -> pure () }
|
||||||
|
|
||||||
|
pfreq <- (
|
||||||
|
runLogger . runE @'[NoCompatiblePlatform, NoCompatibleArch, DistroNotFound] . liftE $ platformRequest
|
||||||
|
) >>= \case
|
||||||
|
VRight r -> pure r
|
||||||
|
VLeft e -> do
|
||||||
|
runLogger
|
||||||
|
($(logError) $ T.pack $ prettyShow e)
|
||||||
|
exitWith (ExitFailure 2)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
----------------------------------------
|
||||||
|
-- Getting download and platform info --
|
||||||
|
----------------------------------------
|
||||||
|
|
||||||
|
ghcupInfo <-
|
||||||
|
( runLogger
|
||||||
|
. runE @'[JSONError , DownloadFailed, FileDoesNotExistError]
|
||||||
|
$ liftE
|
||||||
|
$ getDownloadsF settings dirs
|
||||||
|
)
|
||||||
|
>>= \case
|
||||||
|
VRight r -> pure r
|
||||||
|
VLeft e -> do
|
||||||
|
runLogger
|
||||||
|
($(logError) $ T.pack $ prettyShow e)
|
||||||
|
exitWith (ExitFailure 2)
|
||||||
|
|
||||||
|
let appstate@AppState{dirs = Dirs{..}
|
||||||
|
, ghcupInfo = GHCupInfo { _ghcupDownloads = dls, .. }
|
||||||
|
} = AppState settings dirs keybindings ghcupInfo pfreq
|
||||||
|
|
||||||
|
case optCommand of
|
||||||
|
Upgrade _ _ -> pure ()
|
||||||
|
_ -> do
|
||||||
|
lookupEnv "GHCUP_SKIP_UPDATE_CHECK" >>= \case
|
||||||
|
Nothing -> runLogger $ flip runReaderT appstate $ checkForUpdates
|
||||||
|
Just _ -> pure ()
|
||||||
|
|
||||||
|
|
||||||
|
-- ensure global tools
|
||||||
|
(siletRunLogger $ flip runReaderT appstate $ runE ensureGlobalTools) >>= \case
|
||||||
|
VRight _ -> pure ()
|
||||||
|
VLeft e -> do
|
||||||
|
runLogger
|
||||||
|
($(logError) $ T.pack $ prettyShow e)
|
||||||
|
exitWith (ExitFailure 30)
|
||||||
|
|
||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
-- Effect interpreters --
|
-- Effect interpreters --
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
let runInstTool' appstate' =
|
let runInstTool' appstate' mInstPlatform =
|
||||||
runLogger
|
runLogger
|
||||||
. flip runReaderT appstate'
|
. flip runReaderT (maybe appstate' (\x -> appstate'{ pfreq = x }) mInstPlatform)
|
||||||
. runResourceT
|
. runResourceT
|
||||||
. runE
|
. runE
|
||||||
@'[ AlreadyInstalled
|
@'[ AlreadyInstalled
|
||||||
@@ -1187,57 +1279,22 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
----------------------------------------
|
|
||||||
-- Getting download and platform info --
|
|
||||||
----------------------------------------
|
|
||||||
|
|
||||||
pfreq <- (
|
|
||||||
runLogger . runE @'[NoCompatiblePlatform, NoCompatibleArch, DistroNotFound] . liftE $ platformRequest
|
|
||||||
) >>= \case
|
|
||||||
VRight r -> pure r
|
|
||||||
VLeft e -> do
|
|
||||||
runLogger
|
|
||||||
($(logError) $ T.pack $ prettyShow e)
|
|
||||||
exitWith (ExitFailure 2)
|
|
||||||
|
|
||||||
|
|
||||||
(GHCupInfo treq dls) <-
|
|
||||||
( runLogger
|
|
||||||
. flip runReaderT appstate
|
|
||||||
. runE @'[JSONError , DownloadFailed, FileDoesNotExistError]
|
|
||||||
$ liftE
|
|
||||||
$ getDownloadsF (urlSource settings)
|
|
||||||
)
|
|
||||||
>>= \case
|
|
||||||
VRight r -> pure r
|
|
||||||
VLeft e -> do
|
|
||||||
runLogger
|
|
||||||
($(logError) $ T.pack $ prettyShow e)
|
|
||||||
exitWith (ExitFailure 2)
|
|
||||||
|
|
||||||
case optCommand of
|
|
||||||
Upgrade _ _ -> pure ()
|
|
||||||
_ -> runLogger $ flip runReaderT appstate $ checkForUpdates dls pfreq
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
-- Command functions --
|
-- Command functions --
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
let installGHC InstallOptions{..} =
|
let installGHC InstallOptions{..} =
|
||||||
(case instBindist of
|
(case instBindist of
|
||||||
Nothing -> runInstTool $ do
|
Nothing -> runInstTool instPlatform $ do
|
||||||
(v, vi) <- liftE $ fromVersion dls instVer GHC
|
(v, vi) <- liftE $ fromVersion instVer GHC
|
||||||
liftE $ installGHCBin dls (_tvVersion v) (fromMaybe pfreq instPlatform)
|
liftE $ installGHCBin (_tvVersion v)
|
||||||
when instSet $ void $ liftE $ setGHC v SetGHCOnly
|
when instSet $ void $ liftE $ setGHC v SetGHCOnly
|
||||||
pure vi
|
pure vi
|
||||||
Just uri -> runInstTool' appstate{ settings = settings {noVerify = True}} $ do
|
Just uri -> runInstTool' appstate{ settings = settings {noVerify = True}} instPlatform $ do
|
||||||
(v, vi) <- liftE $ fromVersion dls instVer GHC
|
(v, vi) <- liftE $ fromVersion instVer GHC
|
||||||
liftE $ installGHCBindist
|
liftE $ installGHCBindist
|
||||||
(DownloadInfo uri (Just $ RegexDir "ghc-.*") "")
|
(DownloadInfo uri (Just $ RegexDir "ghc-.*") "")
|
||||||
(_tvVersion v)
|
(_tvVersion v)
|
||||||
(fromMaybe pfreq instPlatform)
|
|
||||||
when instSet $ void $ liftE $ setGHC v SetGHCOnly
|
when instSet $ void $ liftE $ setGHC v SetGHCOnly
|
||||||
pure vi
|
pure vi
|
||||||
)
|
)
|
||||||
@@ -1253,8 +1310,8 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
pure ExitSuccess
|
pure ExitSuccess
|
||||||
VLeft err@(V (BuildFailed tmpdir _)) -> do
|
VLeft err@(V (BuildFailed tmpdir _)) -> do
|
||||||
case keepDirs settings of
|
case keepDirs settings of
|
||||||
Never -> runLogger ($(logError) $ T.pack $ prettyShow err)
|
Never -> myLoggerT loggerConfig $ ($(logError) $ T.pack $ prettyShow err)
|
||||||
_ -> runLogger ($(logError) [i|#{prettyShow err}
|
_ -> myLoggerT loggerConfig $ ($(logError) [i|#{prettyShow err}
|
||||||
Check the logs at #{logsDir} and the build directory #{tmpdir} for more clues.
|
Check the logs at #{logsDir} and the build directory #{tmpdir} for more clues.
|
||||||
Make sure to clean up #{tmpdir} afterwards.|])
|
Make sure to clean up #{tmpdir} afterwards.|])
|
||||||
pure $ ExitFailure 3
|
pure $ ExitFailure 3
|
||||||
@@ -1267,16 +1324,15 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
|
|
||||||
let installCabal InstallOptions{..} =
|
let installCabal InstallOptions{..} =
|
||||||
(case instBindist of
|
(case instBindist of
|
||||||
Nothing -> runInstTool $ do
|
Nothing -> runInstTool instPlatform $ do
|
||||||
(v, vi) <- liftE $ fromVersion dls instVer Cabal
|
(v, vi) <- liftE $ fromVersion instVer Cabal
|
||||||
liftE $ installCabalBin dls (_tvVersion v) (fromMaybe pfreq instPlatform)
|
liftE $ installCabalBin (_tvVersion v)
|
||||||
pure vi
|
pure vi
|
||||||
Just uri -> runInstTool' appstate{ settings = settings { noVerify = True}} $ do
|
Just uri -> runInstTool' appstate{ settings = settings { noVerify = True}} instPlatform $ do
|
||||||
(v, vi) <- liftE $ fromVersion dls instVer Cabal
|
(v, vi) <- liftE $ fromVersion instVer Cabal
|
||||||
liftE $ installCabalBindist
|
liftE $ installCabalBindist
|
||||||
(DownloadInfo uri Nothing "")
|
(DownloadInfo uri Nothing "")
|
||||||
(_tvVersion v)
|
(_tvVersion v)
|
||||||
(fromMaybe pfreq instPlatform)
|
|
||||||
pure vi
|
pure vi
|
||||||
)
|
)
|
||||||
>>= \case
|
>>= \case
|
||||||
@@ -1297,16 +1353,15 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
|
|
||||||
let installHLS InstallOptions{..} =
|
let installHLS InstallOptions{..} =
|
||||||
(case instBindist of
|
(case instBindist of
|
||||||
Nothing -> runInstTool $ do
|
Nothing -> runInstTool instPlatform $ do
|
||||||
(v, vi) <- liftE $ fromVersion dls instVer HLS
|
(v, vi) <- liftE $ fromVersion instVer HLS
|
||||||
liftE $ installHLSBin dls (_tvVersion v) (fromMaybe pfreq instPlatform)
|
liftE $ installHLSBin (_tvVersion v)
|
||||||
pure vi
|
pure vi
|
||||||
Just uri -> runInstTool' appstate{ settings = settings { noVerify = True}} $ do
|
Just uri -> runInstTool' appstate{ settings = settings { noVerify = True}} instPlatform $ do
|
||||||
(v, vi) <- liftE $ fromVersion dls instVer HLS
|
(v, vi) <- liftE $ fromVersion instVer HLS
|
||||||
liftE $ installHLSBindist
|
liftE $ installHLSBindist
|
||||||
(DownloadInfo uri Nothing "")
|
(DownloadInfo uri Nothing "")
|
||||||
(_tvVersion v)
|
(_tvVersion v)
|
||||||
(fromMaybe pfreq instPlatform)
|
|
||||||
pure vi
|
pure vi
|
||||||
)
|
)
|
||||||
>>= \case
|
>>= \case
|
||||||
@@ -1325,10 +1380,39 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
$(logError) [i|Also check the logs in #{logsDir}|]
|
$(logError) [i|Also check the logs in #{logsDir}|]
|
||||||
pure $ ExitFailure 4
|
pure $ ExitFailure 4
|
||||||
|
|
||||||
|
let installStack InstallOptions{..} =
|
||||||
|
(case instBindist of
|
||||||
|
Nothing -> runInstTool instPlatform $ do
|
||||||
|
(v, vi) <- liftE $ fromVersion instVer Stack
|
||||||
|
liftE $ installStackBin (_tvVersion v)
|
||||||
|
pure vi
|
||||||
|
Just uri -> runInstTool' appstate{ settings = settings { noVerify = True}} instPlatform $ do
|
||||||
|
(v, vi) <- liftE $ fromVersion instVer Stack
|
||||||
|
liftE $ installStackBindist
|
||||||
|
(DownloadInfo uri Nothing "")
|
||||||
|
(_tvVersion v)
|
||||||
|
pure vi
|
||||||
|
)
|
||||||
|
>>= \case
|
||||||
|
VRight vi -> do
|
||||||
|
runLogger $ $(logInfo) "Stack installation successful"
|
||||||
|
forM_ (_viPostInstall =<< vi) $ \msg ->
|
||||||
|
runLogger $ $(logInfo) msg
|
||||||
|
pure ExitSuccess
|
||||||
|
VLeft (V (AlreadyInstalled _ v)) -> do
|
||||||
|
runLogger $ $(logWarn)
|
||||||
|
[i|Stack ver #{prettyVer v} already installed; if you really want to reinstall it, you may want to run 'ghcup rm stack #{prettyVer v}' first|]
|
||||||
|
pure ExitSuccess
|
||||||
|
VLeft e -> do
|
||||||
|
runLogger $ do
|
||||||
|
$(logError) $ T.pack $ prettyShow e
|
||||||
|
$(logError) [i|Also check the logs in #{logsDir}|]
|
||||||
|
pure $ ExitFailure 4
|
||||||
|
|
||||||
|
|
||||||
let setGHC' SetOptions{..} =
|
let setGHC' SetOptions{..} =
|
||||||
runSetGHC (do
|
runSetGHC (do
|
||||||
v <- liftE $ fst <$> fromVersion' dls sToolVer GHC
|
v <- liftE $ fst <$> fromVersion' sToolVer GHC
|
||||||
liftE $ setGHC v SetGHCOnly
|
liftE $ setGHC v SetGHCOnly
|
||||||
)
|
)
|
||||||
>>= \case
|
>>= \case
|
||||||
@@ -1343,7 +1427,7 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
|
|
||||||
let setCabal' SetOptions{..} =
|
let setCabal' SetOptions{..} =
|
||||||
runSetCabal (do
|
runSetCabal (do
|
||||||
v <- liftE $ fst <$> fromVersion' dls sToolVer Cabal
|
v <- liftE $ fst <$> fromVersion' sToolVer Cabal
|
||||||
liftE $ setCabal (_tvVersion v)
|
liftE $ setCabal (_tvVersion v)
|
||||||
pure v
|
pure v
|
||||||
)
|
)
|
||||||
@@ -1359,7 +1443,7 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
|
|
||||||
let setHLS' SetOptions{..} =
|
let setHLS' SetOptions{..} =
|
||||||
runSetHLS (do
|
runSetHLS (do
|
||||||
v <- liftE $ fst <$> fromVersion' dls sToolVer HLS
|
v <- liftE $ fst <$> fromVersion' sToolVer HLS
|
||||||
liftE $ setHLS (_tvVersion v)
|
liftE $ setHLS (_tvVersion v)
|
||||||
pure v
|
pure v
|
||||||
)
|
)
|
||||||
@@ -1373,6 +1457,22 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
runLogger $ $(logError) $ T.pack $ prettyShow e
|
runLogger $ $(logError) $ T.pack $ prettyShow e
|
||||||
pure $ ExitFailure 14
|
pure $ ExitFailure 14
|
||||||
|
|
||||||
|
let setStack' SetOptions{..} =
|
||||||
|
runSetCabal (do
|
||||||
|
v <- liftE $ fst <$> fromVersion' sToolVer Stack
|
||||||
|
liftE $ setStack (_tvVersion v)
|
||||||
|
pure v
|
||||||
|
)
|
||||||
|
>>= \case
|
||||||
|
VRight GHCTargetVersion{..} -> do
|
||||||
|
runLogger
|
||||||
|
$ $(logInfo)
|
||||||
|
[i|Stack #{prettyVer _tvVersion} successfully set as default version|]
|
||||||
|
pure ExitSuccess
|
||||||
|
VLeft e -> do
|
||||||
|
runLogger $ $(logError) $ T.pack $ prettyShow e
|
||||||
|
pure $ ExitFailure 14
|
||||||
|
|
||||||
let rmGHC' RmOptions{..} =
|
let rmGHC' RmOptions{..} =
|
||||||
runRm (do
|
runRm (do
|
||||||
liftE $
|
liftE $
|
||||||
@@ -1418,10 +1518,25 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
runLogger $ $(logError) $ T.pack $ prettyShow e
|
runLogger $ $(logError) $ T.pack $ prettyShow e
|
||||||
pure $ ExitFailure 15
|
pure $ ExitFailure 15
|
||||||
|
|
||||||
|
let rmStack' tv =
|
||||||
|
runRm (do
|
||||||
|
liftE $
|
||||||
|
rmStackVer tv
|
||||||
|
pure (getVersionInfo tv Stack dls)
|
||||||
|
)
|
||||||
|
>>= \case
|
||||||
|
VRight vi -> do
|
||||||
|
forM_ (_viPostRemove =<< vi) $ \msg ->
|
||||||
|
runLogger $ $(logInfo) msg
|
||||||
|
pure ExitSuccess
|
||||||
|
VLeft e -> do
|
||||||
|
runLogger $ $(logError) $ T.pack $ prettyShow e
|
||||||
|
pure $ ExitFailure 15
|
||||||
|
|
||||||
res <- case optCommand of
|
res <- case optCommand of
|
||||||
#if defined(BRICK)
|
#if defined(BRICK)
|
||||||
Interactive -> liftIO $ brickMain appstate loggerConfig dls pfreq >> pure ExitSuccess
|
Interactive -> do
|
||||||
|
liftIO $ brickMain appstate loggerConfig ghcupInfo >> pure ExitSuccess
|
||||||
#endif
|
#endif
|
||||||
Install (Right iopts) -> do
|
Install (Right iopts) -> do
|
||||||
runLogger ($(logWarn) [i|This is an old-style command for installing GHC. Use 'ghcup install ghc' instead.|])
|
runLogger ($(logWarn) [i|This is an old-style command for installing GHC. Use 'ghcup install ghc' instead.|])
|
||||||
@@ -1429,6 +1544,7 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
Install (Left (InstallGHC iopts)) -> installGHC iopts
|
Install (Left (InstallGHC iopts)) -> installGHC iopts
|
||||||
Install (Left (InstallCabal iopts)) -> installCabal iopts
|
Install (Left (InstallCabal iopts)) -> installCabal iopts
|
||||||
Install (Left (InstallHLS iopts)) -> installHLS iopts
|
Install (Left (InstallHLS iopts)) -> installHLS iopts
|
||||||
|
Install (Left (InstallStack iopts)) -> installStack iopts
|
||||||
InstallCabalLegacy iopts -> do
|
InstallCabalLegacy iopts -> do
|
||||||
runLogger ($(logWarn) [i|This is an old-style command for installing cabal. Use 'ghcup install cabal' instead.|])
|
runLogger ($(logWarn) [i|This is an old-style command for installing cabal. Use 'ghcup install cabal' instead.|])
|
||||||
installCabal iopts
|
installCabal iopts
|
||||||
@@ -1439,10 +1555,11 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
Set (Left (SetGHC sopts)) -> setGHC' sopts
|
Set (Left (SetGHC sopts)) -> setGHC' sopts
|
||||||
Set (Left (SetCabal sopts)) -> setCabal' sopts
|
Set (Left (SetCabal sopts)) -> setCabal' sopts
|
||||||
Set (Left (SetHLS sopts)) -> setHLS' sopts
|
Set (Left (SetHLS sopts)) -> setHLS' sopts
|
||||||
|
Set (Left (SetStack sopts)) -> setStack' sopts
|
||||||
|
|
||||||
List ListOptions {..} ->
|
List ListOptions {..} ->
|
||||||
runListGHC (do
|
runListGHC (do
|
||||||
l <- listVersions dls loTool lCriteria pfreq
|
l <- listVersions loTool lCriteria
|
||||||
liftIO $ printListResult lRawFormat l
|
liftIO $ printListResult lRawFormat l
|
||||||
pure ExitSuccess
|
pure ExitSuccess
|
||||||
)
|
)
|
||||||
@@ -1453,6 +1570,7 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
Rm (Left (RmGHC rmopts)) -> rmGHC' rmopts
|
Rm (Left (RmGHC rmopts)) -> rmGHC' rmopts
|
||||||
Rm (Left (RmCabal rmopts)) -> rmCabal' rmopts
|
Rm (Left (RmCabal rmopts)) -> rmCabal' rmopts
|
||||||
Rm (Left (RmHLS rmopts)) -> rmHLS' rmopts
|
Rm (Left (RmHLS rmopts)) -> rmHLS' rmopts
|
||||||
|
Rm (Left (RmStack rmopts)) -> rmStack' rmopts
|
||||||
|
|
||||||
DInfo ->
|
DInfo ->
|
||||||
do runDebugInfo $ liftE getDebugInfo
|
do runDebugInfo $ liftE getDebugInfo
|
||||||
@@ -1475,14 +1593,14 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
"...waiting for 5 seconds, you can still abort..."
|
"...waiting for 5 seconds, you can still abort..."
|
||||||
liftIO $ threadDelay 5000000 -- for compilation, give the user a sec to intervene
|
liftIO $ threadDelay 5000000 -- for compilation, give the user a sec to intervene
|
||||||
Right _ -> pure ()
|
Right _ -> pure ()
|
||||||
targetVer <- liftE $ compileGHC dls
|
targetVer <- liftE $ compileGHC
|
||||||
(first (GHCTargetVersion crossTarget) targetGhc)
|
(first (GHCTargetVersion crossTarget) targetGhc)
|
||||||
|
ovewrwiteVer
|
||||||
bootstrapGhc
|
bootstrapGhc
|
||||||
jobs
|
jobs
|
||||||
buildConfig
|
buildConfig
|
||||||
patchDir
|
patchDir
|
||||||
addConfArgs
|
addConfArgs
|
||||||
pfreq
|
|
||||||
let vi = getVersionInfo (_tvVersion targetVer) GHC dls
|
let vi = getVersionInfo (_tvVersion targetVer) GHC dls
|
||||||
when setCompile $ void $ liftE $
|
when setCompile $ void $ liftE $
|
||||||
setGHC targetVer SetGHCOnly
|
setGHC targetVer SetGHCOnly
|
||||||
@@ -1501,8 +1619,8 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
pure ExitSuccess
|
pure ExitSuccess
|
||||||
VLeft err@(V (BuildFailed tmpdir _)) -> do
|
VLeft err@(V (BuildFailed tmpdir _)) -> do
|
||||||
case keepDirs settings of
|
case keepDirs settings of
|
||||||
Never -> runLogger $ $(logError) $ T.pack $ prettyShow err
|
Never -> myLoggerT loggerConfig $ $(logError) $ T.pack $ prettyShow err
|
||||||
_ -> runLogger ($(logError) [i|#{prettyShow err}
|
_ -> myLoggerT loggerConfig $ ($(logError) [i|#{prettyShow err}
|
||||||
Check the logs at #{logsDir} and the build directory #{tmpdir} for more clues.
|
Check the logs at #{logsDir} and the build directory #{tmpdir} for more clues.
|
||||||
Make sure to clean up #{tmpdir} afterwards.|])
|
Make sure to clean up #{tmpdir} afterwards.|])
|
||||||
pure $ ExitFailure 9
|
pure $ ExitFailure 9
|
||||||
@@ -1512,14 +1630,11 @@ Make sure to clean up #{tmpdir} afterwards.|])
|
|||||||
|
|
||||||
Upgrade uOpts force -> do
|
Upgrade uOpts force -> do
|
||||||
target <- case uOpts of
|
target <- case uOpts of
|
||||||
UpgradeInplace -> do
|
UpgradeInplace -> Just <$> liftIO getExecutablePath
|
||||||
efp <- liftIO getExecutablePath
|
|
||||||
p <- parseAbs . E.encodeUtf8 . T.pack $ efp
|
|
||||||
pure $ Just p
|
|
||||||
(UpgradeAt p) -> pure $ Just p
|
(UpgradeAt p) -> pure $ Just p
|
||||||
UpgradeGHCupDir -> pure (Just (binDir </> [rel|ghcup|]))
|
UpgradeGHCupDir -> pure (Just (binDir </> "ghcup" <> exeExt))
|
||||||
|
|
||||||
runUpgrade (liftE $ upgradeGHCup dls target force pfreq) >>= \case
|
runUpgrade (liftE $ upgradeGHCup target force) >>= \case
|
||||||
VRight v' -> do
|
VRight v' -> do
|
||||||
let pretty_v = prettyVer v'
|
let pretty_v = prettyVer v'
|
||||||
let vi = fromJust $ snd <$> getLatest dls GHCup
|
let vi = fromJust $ snd <$> getLatest dls GHCup
|
||||||
@@ -1536,12 +1651,13 @@ Make sure to clean up #{tmpdir} afterwards.|])
|
|||||||
pure $ ExitFailure 11
|
pure $ ExitFailure 11
|
||||||
|
|
||||||
ToolRequirements ->
|
ToolRequirements ->
|
||||||
runLogger
|
flip runReaderT appstate
|
||||||
|
$ runLogger
|
||||||
(runE
|
(runE
|
||||||
@'[NoCompatiblePlatform , DistroNotFound , NoToolRequirements]
|
@'[NoCompatiblePlatform , DistroNotFound , NoToolRequirements]
|
||||||
$ do
|
$ do
|
||||||
platform <- liftE getPlatform
|
platform <- liftE getPlatform
|
||||||
req <- getCommonRequirements platform treq ?? NoToolRequirements
|
req <- getCommonRequirements platform _toolRequirements ?? NoToolRequirements
|
||||||
liftIO $ T.hPutStr stdout (prettyRequirements req)
|
liftIO $ T.hPutStr stdout (prettyRequirements req)
|
||||||
)
|
)
|
||||||
>>= \case
|
>>= \case
|
||||||
@@ -1573,12 +1689,13 @@ Make sure to clean up #{tmpdir} afterwards.|])
|
|||||||
Darwin -> "open"
|
Darwin -> "open"
|
||||||
Linux _ -> "xdg-open"
|
Linux _ -> "xdg-open"
|
||||||
FreeBSD -> "xdg-open"
|
FreeBSD -> "xdg-open"
|
||||||
|
Windows -> "start"
|
||||||
|
|
||||||
if clOpen
|
if clOpen
|
||||||
then
|
then
|
||||||
|
flip runReaderT appstate $
|
||||||
exec cmd
|
exec cmd
|
||||||
True
|
[T.unpack $ decUTF8Safe $ serializeURIRef' uri]
|
||||||
[serializeURIRef' uri]
|
|
||||||
Nothing
|
Nothing
|
||||||
Nothing
|
Nothing
|
||||||
>>= \case
|
>>= \case
|
||||||
@@ -1587,42 +1704,78 @@ Make sure to clean up #{tmpdir} afterwards.|])
|
|||||||
>> pure (ExitFailure 13)
|
>> pure (ExitFailure 13)
|
||||||
else putStrLn uri' >> pure ExitSuccess
|
else putStrLn uri' >> pure ExitSuccess
|
||||||
|
|
||||||
|
Nuke ->
|
||||||
|
runRm (do
|
||||||
|
lift $ $logWarn "WARNING: This will remove GHCup and all installed components from your system."
|
||||||
|
lift $ $logWarn "Waiting 10 seconds before commencing, if you want to cancel it, now would be the time."
|
||||||
|
liftIO $ threadDelay 10000000 -- wait 10s
|
||||||
|
|
||||||
|
lift $ $logInfo "Initiating Nuclear Sequence 🚀🚀🚀"
|
||||||
|
lift $ $logInfo "Nuking in 3...2...1"
|
||||||
|
|
||||||
|
lInstalled <- lift $ listVersions Nothing (Just ListInstalled)
|
||||||
|
|
||||||
|
forM_ lInstalled (liftE . rmTool)
|
||||||
|
|
||||||
|
lift rmGhcupDirs
|
||||||
|
|
||||||
|
) >>= \case
|
||||||
|
VRight leftOverFiles
|
||||||
|
| null leftOverFiles -> do
|
||||||
|
runLogger $ $logInfo "Nuclear Annihilation complete!"
|
||||||
|
pure ExitSuccess
|
||||||
|
| otherwise -> do
|
||||||
|
runLogger $ $logWarn "These Files have survived Nuclear Annihilation, you may remove them manually."
|
||||||
|
forM_ leftOverFiles putStrLn
|
||||||
|
pure ExitSuccess
|
||||||
|
|
||||||
|
VLeft e -> do
|
||||||
|
runLogger $ $(logError) $ T.pack $ prettyShow e
|
||||||
|
pure $ ExitFailure 15
|
||||||
|
|
||||||
|
|
||||||
case res of
|
case res of
|
||||||
ExitSuccess -> pure ()
|
ExitSuccess -> pure ()
|
||||||
ef@(ExitFailure _) -> exitWith ef
|
ef@(ExitFailure _) -> exitWith ef
|
||||||
|
|
||||||
|
|
||||||
pure ()
|
pure ()
|
||||||
|
|
||||||
fromVersion :: (MonadLogger m, MonadFail m, MonadReader AppState m, MonadThrow m, MonadIO m, MonadCatch m)
|
fromVersion :: (MonadLogger m, MonadFail m, MonadReader AppState m, MonadThrow m, MonadIO m, MonadCatch m)
|
||||||
=> GHCupDownloads
|
=> Maybe ToolVersion
|
||||||
-> Maybe ToolVersion
|
|
||||||
-> Tool
|
-> Tool
|
||||||
-> Excepts '[TagNotFound, NextVerNotFound, NoToolVersionSet] m (GHCTargetVersion, Maybe VersionInfo)
|
-> Excepts '[TagNotFound, NextVerNotFound, NoToolVersionSet] m (GHCTargetVersion, Maybe VersionInfo)
|
||||||
fromVersion av tv = fromVersion' av (toSetToolVer tv)
|
fromVersion tv = fromVersion' (toSetToolVer tv)
|
||||||
|
|
||||||
fromVersion' :: (MonadLogger m, MonadFail m, MonadReader AppState m, MonadThrow m, MonadIO m, MonadCatch m)
|
fromVersion' :: (MonadLogger m, MonadFail m, MonadReader AppState m, MonadThrow m, MonadIO m, MonadCatch m)
|
||||||
=> GHCupDownloads
|
=> SetToolVersion
|
||||||
-> SetToolVersion
|
|
||||||
-> Tool
|
-> Tool
|
||||||
-> Excepts '[TagNotFound, NextVerNotFound, NoToolVersionSet] m (GHCTargetVersion, Maybe VersionInfo)
|
-> Excepts '[TagNotFound, NextVerNotFound, NoToolVersionSet] m (GHCTargetVersion, Maybe VersionInfo)
|
||||||
fromVersion' av SetRecommended tool =
|
fromVersion' SetRecommended tool = do
|
||||||
(\(x, y) -> (mkTVer x, Just y)) <$> getRecommended av tool
|
AppState { ghcupInfo = GHCupInfo { _ghcupDownloads = dls }} <- lift ask
|
||||||
|
(\(x, y) -> (mkTVer x, Just y)) <$> getRecommended dls tool
|
||||||
?? TagNotFound Recommended tool
|
?? TagNotFound Recommended tool
|
||||||
fromVersion' av (SetToolVersion v) tool = do
|
fromVersion' (SetToolVersion v) tool = do
|
||||||
let vi = getVersionInfo (_tvVersion v) tool av
|
AppState { ghcupInfo = GHCupInfo { _ghcupDownloads = dls }} <- lift ask
|
||||||
|
let vi = getVersionInfo (_tvVersion v) tool dls
|
||||||
case pvp $ prettyVer (_tvVersion v) of
|
case pvp $ prettyVer (_tvVersion v) of
|
||||||
Left _ -> pure (v, vi)
|
Left _ -> pure (v, vi)
|
||||||
Right (PVP (major' :|[minor'])) ->
|
Right (PVP (major' :|[minor'])) ->
|
||||||
case getLatestGHCFor (fromIntegral major') (fromIntegral minor') av of
|
case getLatestGHCFor (fromIntegral major') (fromIntegral minor') dls of
|
||||||
Just (v', vi') -> pure (GHCTargetVersion (_tvTarget v) v', Just vi')
|
Just (v', vi') -> pure (GHCTargetVersion (_tvTarget v) v', Just vi')
|
||||||
Nothing -> pure (v, vi)
|
Nothing -> pure (v, vi)
|
||||||
Right _ -> pure (v, vi)
|
Right _ -> pure (v, vi)
|
||||||
fromVersion' av (SetToolTag Latest) tool =
|
fromVersion' (SetToolTag Latest) tool = do
|
||||||
(\(x, y) -> (mkTVer x, Just y)) <$> getLatest av tool ?? TagNotFound Latest tool
|
AppState { ghcupInfo = GHCupInfo { _ghcupDownloads = dls }} <- lift ask
|
||||||
fromVersion' av (SetToolTag Recommended) tool =
|
(\(x, y) -> (mkTVer x, Just y)) <$> getLatest dls tool ?? TagNotFound Latest tool
|
||||||
(\(x, y) -> (mkTVer x, Just y)) <$> getRecommended av tool ?? TagNotFound Recommended tool
|
fromVersion' (SetToolTag Recommended) tool = do
|
||||||
fromVersion' av (SetToolTag (Base pvp'')) GHC =
|
AppState { ghcupInfo = GHCupInfo { _ghcupDownloads = dls }} <- lift ask
|
||||||
(\(x, y) -> (mkTVer x, Just y)) <$> getLatestBaseVersion av pvp'' ?? TagNotFound (Base pvp'') GHC
|
(\(x, y) -> (mkTVer x, Just y)) <$> getRecommended dls tool ?? TagNotFound Recommended tool
|
||||||
fromVersion' av SetNext tool = do
|
fromVersion' (SetToolTag (Base pvp'')) GHC = do
|
||||||
|
AppState { ghcupInfo = GHCupInfo { _ghcupDownloads = dls }} <- lift ask
|
||||||
|
(\(x, y) -> (mkTVer x, Just y)) <$> getLatestBaseVersion dls pvp'' ?? TagNotFound (Base pvp'') GHC
|
||||||
|
fromVersion' SetNext tool = do
|
||||||
|
AppState { ghcupInfo = GHCupInfo { _ghcupDownloads = dls }} <- lift ask
|
||||||
next <- case tool of
|
next <- case tool of
|
||||||
GHC -> do
|
GHC -> do
|
||||||
set <- fmap _tvVersion $ ghcSet Nothing !? NoToolVersionSet tool
|
set <- fmap _tvVersion $ ghcSet Nothing !? NoToolVersionSet tool
|
||||||
@@ -1654,18 +1807,25 @@ fromVersion' av SetNext tool = do
|
|||||||
. cycle
|
. cycle
|
||||||
. sort
|
. sort
|
||||||
$ hlses) ?? NoToolVersionSet tool
|
$ hlses) ?? NoToolVersionSet tool
|
||||||
|
Stack -> do
|
||||||
|
set <- stackSet !? NoToolVersionSet tool
|
||||||
|
stacks <- rights <$> lift getInstalledStacks
|
||||||
|
(fmap (GHCTargetVersion Nothing)
|
||||||
|
. headMay
|
||||||
|
. tail
|
||||||
|
. dropWhile (/= set)
|
||||||
|
. cycle
|
||||||
|
. sort
|
||||||
|
$ stacks) ?? NoToolVersionSet tool
|
||||||
GHCup -> fail "GHCup cannot be set"
|
GHCup -> fail "GHCup cannot be set"
|
||||||
let vi = getVersionInfo (_tvVersion next) tool av
|
let vi = getVersionInfo (_tvVersion next) tool dls
|
||||||
pure (next, vi)
|
pure (next, vi)
|
||||||
fromVersion' _ (SetToolTag t') tool =
|
fromVersion' (SetToolTag t') tool =
|
||||||
throwE $ TagNotFound t' tool
|
throwE $ TagNotFound t' tool
|
||||||
|
|
||||||
|
|
||||||
printListResult :: Bool -> [ListResult] -> IO ()
|
printListResult :: Bool -> [ListResult] -> IO ()
|
||||||
printListResult raw lr = do
|
printListResult raw lr = do
|
||||||
-- https://gitlab.haskell.org/ghc/ghc/issues/8118
|
|
||||||
setLocaleEncoding utf8
|
|
||||||
|
|
||||||
no_color <- isJust <$> lookupEnv "NO_COLOR"
|
no_color <- isJust <$> lookupEnv "NO_COLOR"
|
||||||
|
|
||||||
let
|
let
|
||||||
@@ -1689,9 +1849,15 @@ printListResult raw lr = do
|
|||||||
. fmap
|
. fmap
|
||||||
(\ListResult {..} ->
|
(\ListResult {..} ->
|
||||||
let marks = if
|
let marks = if
|
||||||
|
#if defined(IS_WINDOWS)
|
||||||
|
| lSet -> (color Green "IS")
|
||||||
|
| lInstalled -> (color Green "I ")
|
||||||
|
| otherwise -> (color Red "X ")
|
||||||
|
#else
|
||||||
| lSet -> (color Green "✔✔")
|
| lSet -> (color Green "✔✔")
|
||||||
| lInstalled -> (color Green "✓ ")
|
| lInstalled -> (color Green "✓ ")
|
||||||
| otherwise -> (color Red "✗ ")
|
| otherwise -> (color Red "✗ ")
|
||||||
|
#endif
|
||||||
in
|
in
|
||||||
(if raw then [] else [marks])
|
(if raw then [] else [marks])
|
||||||
++ [ fmap toLower . show $ lTool
|
++ [ fmap toLower . show $ lTool
|
||||||
@@ -1818,11 +1984,10 @@ checkForUpdates :: ( MonadReader AppState m
|
|||||||
, MonadFail m
|
, MonadFail m
|
||||||
, MonadLogger m
|
, MonadLogger m
|
||||||
)
|
)
|
||||||
=> GHCupDownloads
|
=> m ()
|
||||||
-> PlatformRequest
|
checkForUpdates = do
|
||||||
-> m ()
|
AppState { ghcupInfo = GHCupInfo { _ghcupDownloads = dls }} <- ask
|
||||||
checkForUpdates dls pfreq = do
|
lInstalled <- listVersions Nothing (Just ListInstalled)
|
||||||
lInstalled <- listVersions dls Nothing (Just ListInstalled) pfreq
|
|
||||||
let latestInstalled tool = (fmap lVer . lastMay . filter (\lr -> lTool lr == tool)) lInstalled
|
let latestInstalled tool = (fmap lVer . lastMay . filter (\lr -> lTool lr == tool)) lInstalled
|
||||||
|
|
||||||
forM_ (getLatest dls GHCup) $ \(l, _) -> do
|
forM_ (getLatest dls GHCup) $ \(l, _) -> do
|
||||||
@@ -1852,14 +2017,21 @@ checkForUpdates dls pfreq = do
|
|||||||
$ $(logWarn)
|
$ $(logWarn)
|
||||||
[i|New HLS version available: #{prettyVer l}. To upgrade, run 'ghcup install hls #{prettyVer l}'|]
|
[i|New HLS version available: #{prettyVer l}. To upgrade, run 'ghcup install hls #{prettyVer l}'|]
|
||||||
|
|
||||||
|
forM_ (getLatest dls Stack) $ \(l, _) -> do
|
||||||
|
let mstack_ver = latestInstalled Stack
|
||||||
|
forM mstack_ver $ \stack_ver ->
|
||||||
|
when (l > stack_ver)
|
||||||
|
$ $(logWarn)
|
||||||
|
[i|New Stack version available: #{prettyVer l}. To upgrade, run 'ghcup install stack #{prettyVer l}'|]
|
||||||
|
|
||||||
|
|
||||||
prettyDebugInfo :: DebugInfo -> String
|
prettyDebugInfo :: DebugInfo -> String
|
||||||
prettyDebugInfo DebugInfo {..} = [i|Debug Info
|
prettyDebugInfo DebugInfo {..} = [i|Debug Info
|
||||||
==========
|
==========
|
||||||
GHCup base dir: #{toFilePath diBaseDir}
|
GHCup base dir: #{diBaseDir}
|
||||||
GHCup bin dir: #{toFilePath diBinDir}
|
GHCup bin dir: #{diBinDir}
|
||||||
GHCup GHC directory: #{toFilePath diGHCDir}
|
GHCup GHC directory: #{diGHCDir}
|
||||||
GHCup cache directory: #{toFilePath diCacheDir}
|
GHCup cache directory: #{diCacheDir}
|
||||||
Architecture: #{prettyShow diArch}
|
Architecture: #{prettyShow diArch}
|
||||||
Platform: #{prettyShow diPlatform}
|
Platform: #{prettyShow diPlatform}
|
||||||
Version: #{describe_result}|]
|
Version: #{describe_result}|]
|
||||||
|
|||||||
@@ -14,26 +14,52 @@
|
|||||||
# safety subshell to avoid executing anything in case this script is not downloaded properly
|
# safety subshell to avoid executing anything in case this script is not downloaded properly
|
||||||
(
|
(
|
||||||
|
|
||||||
: "${GHCUP_INSTALL_BASE_PREFIX:=$HOME}"
|
plat="$(uname -s)"
|
||||||
|
arch=$(uname -m)
|
||||||
|
ghver="0.1.15.2"
|
||||||
|
base_url="https://downloads.haskell.org/~ghcup"
|
||||||
|
|
||||||
export GHCUP_USE_XDG_DIRS
|
case "${plat}" in
|
||||||
|
MSYS*|MINGW*)
|
||||||
|
: "${GHCUP_INSTALL_BASE_PREFIX:=/c}"
|
||||||
|
GHCUP_DIR=$(cygpath -u "${GHCUP_INSTALL_BASE_PREFIX}/ghcup")
|
||||||
|
GHCUP_BIN=$(cygpath -u "${GHCUP_INSTALL_BASE_PREFIX}/ghcup/bin")
|
||||||
|
: "${GHCUP_MSYS2:=${GHCUP_DIR}/msys64}"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
: "${GHCUP_INSTALL_BASE_PREFIX:=$HOME}"
|
||||||
|
export GHCUP_USE_XDG_DIRS
|
||||||
|
|
||||||
if [ -n "${GHCUP_USE_XDG_DIRS}" ] ; then
|
if [ -n "${GHCUP_USE_XDG_DIRS}" ] ; then
|
||||||
GHCUP_DIR=${XDG_DATA_HOME:=$HOME/.local/share}/ghcup
|
GHCUP_DIR=${XDG_DATA_HOME:=$HOME/.local/share}/ghcup
|
||||||
GHCUP_BIN=${XDG_BIN_HOME:=$HOME/.local/bin}
|
GHCUP_BIN=${XDG_BIN_HOME:=$HOME/.local/bin}
|
||||||
else
|
else
|
||||||
GHCUP_DIR=${GHCUP_INSTALL_BASE_PREFIX}/.ghcup
|
GHCUP_DIR=${GHCUP_INSTALL_BASE_PREFIX}/.ghcup
|
||||||
GHCUP_BIN=${GHCUP_INSTALL_BASE_PREFIX}/.ghcup/bin
|
GHCUP_BIN=${GHCUP_INSTALL_BASE_PREFIX}/.ghcup/bin
|
||||||
fi
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
: "${BOOTSTRAP_HASKELL_GHC_VERSION:=recommended}"
|
: "${BOOTSTRAP_HASKELL_GHC_VERSION:=recommended}"
|
||||||
: "${BOOTSTRAP_HASKELL_CABAL_VERSION:=recommended}"
|
: "${BOOTSTRAP_HASKELL_CABAL_VERSION:=recommended}"
|
||||||
|
|
||||||
|
|
||||||
die() {
|
die() {
|
||||||
(>&2 printf "\\033[0;31m%s\\033[0m\\n" "$1")
|
(>&2 printf "\\033[0;31m%s\\033[0m\\n" "$1")
|
||||||
exit 2
|
exit 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
warn() {
|
||||||
|
case "${plat}" in
|
||||||
|
MSYS*|MINGW*)
|
||||||
|
echo -e "\\033[0;35m$1\\033[0m"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
printf "\\033[0;35m%s\\033[0m\\n" "$1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
edo() {
|
edo() {
|
||||||
"$@" || die "\"$*\" failed!"
|
"$@" || die "\"$*\" failed!"
|
||||||
}
|
}
|
||||||
@@ -43,92 +69,137 @@ eghcup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_eghcup() {
|
_eghcup() {
|
||||||
|
if [ -n "${BOOTSTRAP_HASKELL_YAML}" ] ; then
|
||||||
|
args="-s ${BOOTSTRAP_HASKELL_YAML}"
|
||||||
|
fi
|
||||||
if [ -z "${BOOTSTRAP_HASKELL_VERBOSE}" ] ; then
|
if [ -z "${BOOTSTRAP_HASKELL_VERBOSE}" ] ; then
|
||||||
ghcup "$@"
|
"${GHCUP_BIN}/ghcup" ${args} "$@"
|
||||||
else
|
else
|
||||||
ghcup --verbose "$@"
|
"${GHCUP_BIN}/ghcup" ${args} --verbose "$@"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_done() {
|
_done() {
|
||||||
echo
|
case "${plat}" in
|
||||||
echo "All done!"
|
MSYS*|MINGW*)
|
||||||
echo
|
echo
|
||||||
echo "To start a simple repl, run:"
|
echo "All done!"
|
||||||
echo " ghci"
|
echo
|
||||||
echo
|
echo "In a new powershell or cmd.exe session, now you can..."
|
||||||
echo "To start a new haskell project in the current directory, run:"
|
echo
|
||||||
echo " cabal init --interactive"
|
echo "Start a simple repl via:"
|
||||||
echo
|
echo " ghci"
|
||||||
echo "To install other GHC versions, run:"
|
echo
|
||||||
echo " ghcup tui"
|
echo "Start a new haskell project in the current directory via:"
|
||||||
|
echo " cabal init --interactive"
|
||||||
|
echo
|
||||||
|
echo "Install other GHC versions and tools via:"
|
||||||
|
echo " ghcup list"
|
||||||
|
echo " ghcup install <tool> <version>"
|
||||||
|
echo
|
||||||
|
echo "To install system libraries and update msys2/mingw64,"
|
||||||
|
echo "open the \"Mingw haskell shell\""
|
||||||
|
echo "and the \"Mingw package management docs\""
|
||||||
|
echo "desktop shortcuts."
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo
|
||||||
|
echo "All done!"
|
||||||
|
echo
|
||||||
|
echo "To start a simple repl, run:"
|
||||||
|
echo " ghci"
|
||||||
|
echo
|
||||||
|
echo "To start a new haskell project in the current directory, run:"
|
||||||
|
echo " cabal init --interactive"
|
||||||
|
echo
|
||||||
|
echo "To install other GHC versions and tools, run:"
|
||||||
|
echo " ghcup tui"
|
||||||
|
;;
|
||||||
|
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
download_ghcup() {
|
download_ghcup() {
|
||||||
_plat="$(uname -s)"
|
|
||||||
_arch=$(uname -m)
|
|
||||||
_ghver="0.1.14.1"
|
|
||||||
_base_url="https://downloads.haskell.org/~ghcup"
|
|
||||||
|
|
||||||
case "${_plat}" in
|
case "${plat}" in
|
||||||
"linux"|"Linux")
|
"linux"|"Linux")
|
||||||
case "${_arch}" in
|
case "${arch}" in
|
||||||
x86_64|amd64)
|
x86_64|amd64)
|
||||||
# we could be in a 32bit docker container, in which
|
# we could be in a 32bit docker container, in which
|
||||||
# case uname doesn't give us what we want
|
# case uname doesn't give us what we want
|
||||||
if [ "$(getconf LONG_BIT)" = "32" ] ; then
|
if [ "$(getconf LONG_BIT)" = "32" ] ; then
|
||||||
_url=${_base_url}/${_ghver}/i386-linux-ghcup-${_ghver}
|
_url=${base_url}/${ghver}/i386-linux-ghcup-${ghver}
|
||||||
elif [ "$(getconf LONG_BIT)" = "64" ] ; then
|
elif [ "$(getconf LONG_BIT)" = "64" ] ; then
|
||||||
_url=${_base_url}/${_ghver}/x86_64-linux-ghcup-${_ghver}
|
_url=${base_url}/${ghver}/x86_64-linux-ghcup-${ghver}
|
||||||
else
|
else
|
||||||
die "Unknown long bit size: $(getconf LONG_BIT)"
|
die "Unknown long bit size: $(getconf LONG_BIT)"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
i*86)
|
i*86)
|
||||||
_url=${_base_url}/${_ghver}/i386-linux-ghcup-${_ghver}
|
_url=${base_url}/${ghver}/i386-linux-ghcup-${ghver}
|
||||||
;;
|
;;
|
||||||
armv7*)
|
armv7*)
|
||||||
_url=${_base_url}/${_ghver}/armv7-linux-ghcup-${_ghver}
|
_url=${base_url}/${ghver}/armv7-linux-ghcup-${ghver}
|
||||||
;;
|
;;
|
||||||
aarch64|arm64|armv8l)
|
aarch64|arm64|armv8l)
|
||||||
_url=${_base_url}/${_ghver}/aarch64-linux-ghcup-${_ghver}
|
_url=${base_url}/${ghver}/aarch64-linux-ghcup-${ghver}
|
||||||
;;
|
;;
|
||||||
*) die "Unknown architecture: ${_arch}"
|
*) die "Unknown architecture: ${arch}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
"FreeBSD"|"freebsd")
|
"FreeBSD"|"freebsd")
|
||||||
case "${_arch}" in
|
case "${arch}" in
|
||||||
x86_64|amd64)
|
x86_64|amd64)
|
||||||
;;
|
;;
|
||||||
i*86)
|
i*86)
|
||||||
die "i386 currently not supported!"
|
die "i386 currently not supported!"
|
||||||
;;
|
;;
|
||||||
*) die "Unknown architecture: ${_arch}"
|
*) die "Unknown architecture: ${arch}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
_url=${_base_url}/${_ghver}/x86_64-portbld-freebsd-ghcup-${_ghver}
|
_url=${base_url}/${ghver}/x86_64-portbld-freebsd-ghcup-${ghver}
|
||||||
;;
|
;;
|
||||||
"Darwin"|"darwin")
|
"Darwin"|"darwin")
|
||||||
case "${_arch}" in
|
case "${arch}" in
|
||||||
x86_64|amd64)
|
x86_64|amd64)
|
||||||
|
_url=${base_url}/${ghver}/x86_64-apple-darwin-ghcup-${ghver}
|
||||||
|
;;
|
||||||
|
aarch64|arm64|armv8l)
|
||||||
|
_url=${base_url}/${ghver}/aarch64-apple-darwin-ghcup-${ghver}
|
||||||
;;
|
;;
|
||||||
i*86)
|
i*86)
|
||||||
die "i386 currently not supported!"
|
die "i386 currently not supported!"
|
||||||
;;
|
;;
|
||||||
*) die "Unknown architecture: ${_arch}"
|
*) die "Unknown architecture: ${arch}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
_url=${_base_url}/${_ghver}/x86_64-apple-darwin-ghcup-${_ghver} ;;
|
;;
|
||||||
*) die "Unknown platform: ${_plat}"
|
MSYS*|MINGW*)
|
||||||
|
case "${arch}" in
|
||||||
|
x86_64|amd64)
|
||||||
|
_url=${base_url}/${ghver}/x86_64-mingw64-ghcup-${ghver}.exe
|
||||||
|
;;
|
||||||
|
*) die "Unknown architecture: ${arch}"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
;;
|
||||||
|
*) die "Unknown platform: ${plat}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
case "${plat}" in
|
||||||
edo curl -Lf "${_url}" > "${GHCUP_BIN}"/ghcup
|
MSYS*|MINGW*)
|
||||||
|
edo curl -Lf "${_url}" > "${GHCUP_BIN}"/ghcup.exe
|
||||||
edo chmod +x "${GHCUP_BIN}"/ghcup
|
edo chmod +x "${GHCUP_BIN}"/ghcup.exe
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
edo curl -Lf "${_url}" > "${GHCUP_BIN}"/ghcup
|
||||||
|
edo chmod +x "${GHCUP_BIN}"/ghcup
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
edo mkdir -p "${GHCUP_DIR}"
|
edo mkdir -p "${GHCUP_DIR}"
|
||||||
cat <<-EOF > "${GHCUP_DIR}"/env || die "Failed to create env file"
|
cat <<-EOF > "${GHCUP_DIR}"/env || die "Failed to create env file"
|
||||||
@@ -137,8 +208,90 @@ download_ghcup() {
|
|||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
edo . "${GHCUP_DIR}"/env
|
edo . "${GHCUP_DIR}"/env
|
||||||
eghcup upgrade
|
eghcup upgrade
|
||||||
|
}
|
||||||
|
|
||||||
unset _plat _arch _url _ghver _base_url
|
adjust_bashrc() {
|
||||||
|
case $SHELL in
|
||||||
|
*/zsh) # login shell is zsh
|
||||||
|
GHCUP_PROFILE_FILE="$HOME/.zshrc"
|
||||||
|
MY_SHELL="zsh" ;;
|
||||||
|
*/bash) # login shell is bash
|
||||||
|
GHCUP_PROFILE_FILE="$HOME/.bashrc"
|
||||||
|
MY_SHELL="bash" ;;
|
||||||
|
*/sh) # login shell is sh, but might be a symlink to bash or zsh
|
||||||
|
if [ -n "${BASH}" ] ; then
|
||||||
|
GHCUP_PROFILE_FILE="$HOME/.bashrc"
|
||||||
|
MY_SHELL="bash"
|
||||||
|
elif [ -n "${ZSH_VERSION}" ] ; then
|
||||||
|
GHCUP_PROFILE_FILE="$HOME/.zshrc"
|
||||||
|
MY_SHELL="zsh"
|
||||||
|
else
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*/fish) # login shell is fish
|
||||||
|
GHCUP_PROFILE_FILE="$HOME/.config/fish/config.fish"
|
||||||
|
MY_SHELL="fish" ;;
|
||||||
|
*) return ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
warn ""
|
||||||
|
warn "Detected ${MY_SHELL} shell on your system..."
|
||||||
|
warn "If you want ghcup to automatically add the required PATH variable to \"${GHCUP_PROFILE_FILE}\""
|
||||||
|
warn ""
|
||||||
|
warn "[Y] Yes [N] No [?] Help (default is \"Y\")."
|
||||||
|
warn ""
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
||||||
|
read -r next_answer </dev/tty
|
||||||
|
else
|
||||||
|
next_answer="yes"
|
||||||
|
fi
|
||||||
|
|
||||||
|
case $next_answer in
|
||||||
|
[Nn]*)
|
||||||
|
return ;;
|
||||||
|
[Yy]* | "")
|
||||||
|
case $MY_SHELL in
|
||||||
|
"") break ;;
|
||||||
|
fish)
|
||||||
|
mkdir -p "${GHCUP_PROFILE_FILE%/*}"
|
||||||
|
sed -i -e '/# ghcup-env$/ s/^#*/#/' "${GHCUP_PROFILE_FILE}"
|
||||||
|
echo "set -q GHCUP_INSTALL_BASE_PREFIX[1]; or set GHCUP_INSTALL_BASE_PREFIX \$HOME ; test -f $GHCUP_DIR/env ; and set -gx PATH \$HOME/.cabal/bin $GHCUP_BIN \$PATH # ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
||||||
|
break ;;
|
||||||
|
bash)
|
||||||
|
sed -i -e '/# ghcup-env$/ s/^#*/#/' "${GHCUP_PROFILE_FILE}"
|
||||||
|
echo "[ -f \"${GHCUP_DIR}/env\" ] && source \"${GHCUP_DIR}/env\" # ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
||||||
|
case "${plat}" in
|
||||||
|
"Darwin"|"darwin")
|
||||||
|
if ! grep -q "ghcup-env" "${HOME}/.bash_profile" ; then
|
||||||
|
echo "[[ -f ~/.bashrc ]] && source ~/.bashrc # ghcup-env" >> "${HOME}/.bash_profile"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
break ;;
|
||||||
|
|
||||||
|
zsh)
|
||||||
|
sed -i -e '/# ghcup-env$/ s/^#*/#/' "${GHCUP_PROFILE_FILE}"
|
||||||
|
echo "[ -f \"${GHCUP_DIR}/env\" ] && source \"${GHCUP_DIR}/env\" # ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
||||||
|
break ;;
|
||||||
|
esac
|
||||||
|
warn "OK! ${GHCUP_PROFILE_FILE} has been modified. Restart your terminal for the changes to take effect,"
|
||||||
|
warn "or type \"source ${GHCUP_DIR}/env\" to apply them in your current terminal session."
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Possible choices are:"
|
||||||
|
echo
|
||||||
|
echo "Y - Yes, update my \"${GHCUP_PROFILE_FILE}\" (default)"
|
||||||
|
echo "N - No, don't mess with my configuration"
|
||||||
|
echo
|
||||||
|
echo "Please make your choice and press ENTER."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -147,14 +300,22 @@ echo "Welcome to Haskell!"
|
|||||||
echo
|
echo
|
||||||
echo "This script will download and install the following binaries:"
|
echo "This script will download and install the following binaries:"
|
||||||
echo " * ghcup - The Haskell toolchain installer"
|
echo " * ghcup - The Haskell toolchain installer"
|
||||||
echo " (for managing GHC/cabal versions)"
|
|
||||||
echo " * ghc - The Glasgow Haskell Compiler"
|
echo " * ghc - The Glasgow Haskell Compiler"
|
||||||
echo " * cabal - The Cabal build tool"
|
echo " * cabal - The Cabal build tool for managing Haskell software"
|
||||||
|
echo " * stack - (optional) A cross-platform program for developing Haskell projects"
|
||||||
|
echo " * hls - (optional) A language server for developers to integrate with their editor/IDE"
|
||||||
echo
|
echo
|
||||||
if [ -z "${GHCUP_USE_XDG_DIRS}" ] ; then
|
if [ -z "${GHCUP_USE_XDG_DIRS}" ] ; then
|
||||||
echo "ghcup installs only into the following directory,"
|
echo "ghcup installs only into the following directory,"
|
||||||
echo "which can be removed anytime:"
|
echo "which can be removed anytime:"
|
||||||
echo " $GHCUP_INSTALL_BASE_PREFIX/.ghcup"
|
case "${plat}" in
|
||||||
|
MSYS*|MINGW*)
|
||||||
|
echo " $(cygpath -w "$GHCUP_DIR")"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo " $GHCUP_DIR"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
else
|
else
|
||||||
echo "ghcup installs into XDG directories as long as"
|
echo "ghcup installs into XDG directories as long as"
|
||||||
echo "'GHCUP_USE_XDG_DIRS' is set."
|
echo "'GHCUP_USE_XDG_DIRS' is set."
|
||||||
@@ -162,8 +323,8 @@ fi
|
|||||||
echo
|
echo
|
||||||
|
|
||||||
if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "Press ENTER to proceed or ctrl-c to abort."
|
warn "Press ENTER to proceed or ctrl-c to abort."
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "Note that this script can be re-run at any given time."
|
warn "Note that this script can be re-run at any given time."
|
||||||
echo
|
echo
|
||||||
# Wait for user input to continue.
|
# Wait for user input to continue.
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
@@ -181,12 +342,12 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "$(ghcup tool-requirements)"
|
echo "$(if [ -n "${BOOTSTRAP_HASKELL_YAML}" ] ; then ghcup -s "${BOOTSTRAP_HASKELL_YAML}" tool-requirements ; else ghcup tool-requirements ; fi)"
|
||||||
echo
|
echo
|
||||||
|
|
||||||
if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "Press ENTER to proceed or ctrl-c to abort."
|
warn "Press ENTER to proceed or ctrl-c to abort."
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "Installation may take a while."
|
warn "Installation may take a while."
|
||||||
echo
|
echo
|
||||||
|
|
||||||
# Wait for user input to continue.
|
# Wait for user input to continue.
|
||||||
@@ -199,116 +360,124 @@ eghcup --cache install ghc "${BOOTSTRAP_HASKELL_GHC_VERSION}"
|
|||||||
eghcup set ghc "${BOOTSTRAP_HASKELL_GHC_VERSION}"
|
eghcup set ghc "${BOOTSTRAP_HASKELL_GHC_VERSION}"
|
||||||
eghcup --cache install cabal "${BOOTSTRAP_HASKELL_CABAL_VERSION}"
|
eghcup --cache install cabal "${BOOTSTRAP_HASKELL_CABAL_VERSION}"
|
||||||
|
|
||||||
edo cabal new-update
|
adjust_cabal_config() {
|
||||||
|
edo cabal user-config -a "extra-prog-path: $(cygpath -w "$GHCUP_BIN"), $(cygpath -w "$HOME"/AppData/Roaming/cabal/bin), $(cygpath -w "$GHCUP_MSYS2"/usr/bin), $(cygpath -w "$GHCUP_MSYS2"/mingw64/bin)" -a "extra-include-dirs: $(cygpath -w "$GHCUP_MSYS2"/mingw64/include)" -a "extra-lib-dirs: $(cygpath -w "$GHCUP_MSYS2"/mingw64/lib)" -f init
|
||||||
|
}
|
||||||
|
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" ""
|
case "${plat}" in
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "Installation done!"
|
MSYS*|MINGW*)
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" ""
|
if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
||||||
|
warn "Create an initial cabal.config including relevant msys2 paths (recommended)?"
|
||||||
|
warn "[Y] Yes [N] No [?] Help (default is \"Y\")."
|
||||||
|
echo
|
||||||
|
while true; do
|
||||||
|
read -r mingw_answer </dev/tty
|
||||||
|
|
||||||
|
case $mingw_answer in
|
||||||
|
[Yy]* | "")
|
||||||
|
adjust_cabal_config
|
||||||
|
break ;;
|
||||||
|
[Nn]*)
|
||||||
|
echo "Make sure that your global cabal.config references the correct mingw64 paths (extra-prog-path, extra-include-dirs and extra-lib-dirs)."
|
||||||
|
echo "And set the environment variable GHCUP_MSYS2 to the root path of your msys2 installation."
|
||||||
|
sleep 5
|
||||||
|
break ;;
|
||||||
|
*)
|
||||||
|
echo "Possible choices are:"
|
||||||
|
echo
|
||||||
|
echo "Y - Yes, create a cabal.config with pre-set paths to msys2/mingw64 (default)"
|
||||||
|
echo "N - No, leave the current/default cabal config untouched"
|
||||||
|
echo
|
||||||
|
echo "Please make your choice and press ENTER."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
else
|
||||||
|
adjust_cabal_config
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
|
||||||
|
edo cabal new-update
|
||||||
|
|
||||||
|
|
||||||
if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "Do you want to install haskell-language-server (HLS) now?"
|
warn "Do you want to install haskell-language-server (HLS) now?"
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "HLS is a language-server that provides IDE-like functionality"
|
warn "HLS is a language-server that provides IDE-like functionality"
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "and can integrate with different editors, such as Vim, Emacs, VS Code, Atom, ..."
|
warn "and can integrate with different editors, such as Vim, Emacs, VS Code, Atom, ..."
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "Also see https://github.com/haskell/haskell-language-server/blob/master/README.md"
|
warn "Also see https://github.com/haskell/haskell-language-server/blob/master/README.md"
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" ""
|
warn ""
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "Answer with YES or NO and press ENTER."
|
warn "[Y] Yes [N] No [?] Help (default is \"N\")."
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" ""
|
warn ""
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
read -r hls_answer </dev/tty
|
read -r hls_answer </dev/tty
|
||||||
|
|
||||||
case $hls_answer in
|
case $hls_answer in
|
||||||
[Yy]*)
|
[Yy]*)
|
||||||
eghcup --cache install hls
|
_eghcup --cache install hls || warn "HLS installation failed, continuing anyway"
|
||||||
break ;;
|
break ;;
|
||||||
[Nn]*)
|
[Nn]* | "")
|
||||||
break ;;
|
break ;;
|
||||||
*)
|
*)
|
||||||
echo "Please type YES or NO and press enter.";;
|
echo "Possible choices are:"
|
||||||
|
echo
|
||||||
|
echo "Y - Yes, install the haskell-langauge-server"
|
||||||
|
echo "N - No, don't install anything more (default)"
|
||||||
|
echo
|
||||||
|
echo "Please make your choice and press ENTER."
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "In order to run ghc and cabal, you need to adjust your PATH variable."
|
warn "Do you want to install stack now?"
|
||||||
echo "You may want to source '$GHCUP_DIR/env' in your shell"
|
warn "Stack is a haskell build tool similar to cabal that is used by some projects."
|
||||||
echo "configuration to do so (e.g. ~/.bashrc)."
|
warn "Also see https://docs.haskellstack.org/"
|
||||||
|
warn ""
|
||||||
|
warn "[Y] Yes [N] No [?] Help (default is \"N\")."
|
||||||
|
warn ""
|
||||||
|
|
||||||
case $SHELL in
|
while true; do
|
||||||
*/zsh) # login shell is zsh
|
read -r stack_answer </dev/tty
|
||||||
GHCUP_PROFILE_FILE="$HOME/.zshrc"
|
|
||||||
MY_SHELL="zsh" ;;
|
case $stack_answer in
|
||||||
*/bash) # login shell is bash
|
[Yy]*)
|
||||||
GHCUP_PROFILE_FILE="$HOME/.bashrc"
|
_eghcup --cache install stack || warn "Stack installation failed, continuing anyway"
|
||||||
MY_SHELL="bash" ;;
|
break ;;
|
||||||
*/sh) # login shell is sh, but might be a symlink to bash or zsh
|
[Nn]* | "")
|
||||||
if [ -n "${BASH}" ] ; then
|
break ;;
|
||||||
GHCUP_PROFILE_FILE="$HOME/.bashrc"
|
*)
|
||||||
MY_SHELL="bash"
|
echo "Possible choices are:"
|
||||||
elif [ -n "${ZSH_VERSION}" ] ; then
|
echo
|
||||||
GHCUP_PROFILE_FILE="$HOME/.zshrc"
|
echo "Y - Yes, install stack"
|
||||||
MY_SHELL="zsh"
|
echo "N - No, don't install anything more (default)"
|
||||||
else
|
echo
|
||||||
_done
|
echo "Please make your choice and press ENTER."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# short-circuit script based on platform
|
||||||
|
case "${plat}" in
|
||||||
|
MSYS*|MINGW*)
|
||||||
|
# For windows we always adjust bashrc, since it's inside msys2
|
||||||
|
adjust_bashrc
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
||||||
|
echo "In order to run ghc and cabal, you need to adjust your PATH variable."
|
||||||
|
echo "You may want to source '$GHCUP_DIR/env' in your shell"
|
||||||
|
echo "configuration to do so (e.g. ~/.bashrc)."
|
||||||
|
|
||||||
|
adjust_bashrc
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
*/fish) # login shell is fish
|
esac
|
||||||
GHCUP_PROFILE_FILE="$HOME/.config/fish/config.fish"
|
|
||||||
MY_SHELL="fish" ;;
|
|
||||||
*) _done ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
|
_done
|
||||||
|
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" ""
|
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "Detected ${MY_SHELL} shell on your system..."
|
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "If you want ghcup to automatically add the required PATH variable to \"${GHCUP_PROFILE_FILE}\""
|
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "answer with YES, otherwise with NO and press ENTER."
|
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" ""
|
|
||||||
|
|
||||||
while true; do
|
|
||||||
read -r next_answer </dev/tty
|
|
||||||
|
|
||||||
case $next_answer in
|
|
||||||
[Yy]*)
|
|
||||||
case $MY_SHELL in
|
|
||||||
"") break ;;
|
|
||||||
fish)
|
|
||||||
if ! grep -q "ghcup-env" "${GHCUP_PROFILE_FILE}" ; then
|
|
||||||
mkdir -p "${GHCUP_PROFILE_FILE%/*}"
|
|
||||||
echo "# ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
|
||||||
echo "set -q GHCUP_INSTALL_BASE_PREFIX[1]; or set GHCUP_INSTALL_BASE_PREFIX \$HOME" >> "${GHCUP_PROFILE_FILE}"
|
|
||||||
echo "test -f $GHCUP_DIR/env ; and set -gx PATH \$HOME/.cabal/bin $GHCUP_BIN \$PATH" >> "${GHCUP_PROFILE_FILE}"
|
|
||||||
fi
|
|
||||||
break ;;
|
|
||||||
bash)
|
|
||||||
if ! grep -q "ghcup-env" "${GHCUP_PROFILE_FILE}" ; then
|
|
||||||
echo "[ -f \"${GHCUP_DIR}/env\" ] && source \"${GHCUP_DIR}/env\" # ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
|
||||||
fi
|
|
||||||
case "$(uname -s)" in
|
|
||||||
"Darwin"|"darwin")
|
|
||||||
if ! grep -q "ghcup-env" "${HOME}/.bash_profile" ; then
|
|
||||||
echo "[[ -f ~/.bashrc ]] && source ~/.bashrc # ghcup-env" >> "${HOME}/.bash_profile"
|
|
||||||
fi
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
break ;;
|
|
||||||
|
|
||||||
zsh)
|
|
||||||
if ! grep -q "ghcup-env" "${GHCUP_PROFILE_FILE}" ; then
|
|
||||||
echo "[ -f \"${GHCUP_DIR}/env\" ] && source \"${GHCUP_DIR}/env\" # ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
|
||||||
fi
|
|
||||||
break ;;
|
|
||||||
esac
|
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "OK! ${GHCUP_PROFILE_FILE} has been modified. Restart your terminal for the changes to take effect,"
|
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "or type \"source ${GHCUP_DIR}/env\" to apply them in your current terminal session."
|
|
||||||
_done
|
|
||||||
;;
|
|
||||||
[Nn]*)
|
|
||||||
_done ;;
|
|
||||||
*)
|
|
||||||
echo "Please type YES or NO and press enter.";;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# vim: tabstop=4 shiftwidth=4 expandtab
|
# vim: tabstop=4 shiftwidth=4 expandtab
|
||||||
|
|||||||
422
bootstrap-haskell.ps1
Normal file
422
bootstrap-haskell.ps1
Normal file
@@ -0,0 +1,422 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Script to bootstrap a Haskell environment
|
||||||
|
|
||||||
|
.DESCRIPTION
|
||||||
|
This is the windows GHCup installer, installing:
|
||||||
|
|
||||||
|
* ghcup - The Haskell toolchain installer"
|
||||||
|
* ghc - The Glasgow Haskell Compiler"
|
||||||
|
* msys2 - Unix-style toolchain needed for dependencies and tools
|
||||||
|
* cabal - The Cabal build tool for managing Haskell software"
|
||||||
|
* stack - (optional) A cross-platform program for developing Haskell projects"
|
||||||
|
* hls - (optional) A language server for developers to integrate with their editor/IDE"
|
||||||
|
#>
|
||||||
|
param (
|
||||||
|
# Run an interactive installation
|
||||||
|
[switch]$Interactive,
|
||||||
|
# Specify the install root (default: 'C:\')
|
||||||
|
[string]$InstallDir,
|
||||||
|
# Instead of installing a new MSys2, use an existing installation
|
||||||
|
[string]$ExistingMsys2Dir,
|
||||||
|
# Specify the cabal root directory (default: '$InstallDir\cabal')
|
||||||
|
[string]$CabalDir,
|
||||||
|
# Overwrite (or rather backup) a previous install
|
||||||
|
[switch]$Overwrite,
|
||||||
|
# Specify the bootstrap url (default: 'https://www.haskell.org/ghcup/sh/bootstrap-haskell')
|
||||||
|
[string]$BootstrapUrl,
|
||||||
|
# Run the final bootstrap script via 'bash' instead of a full newly spawned msys2 shell
|
||||||
|
[switch]$InBash
|
||||||
|
)
|
||||||
|
|
||||||
|
$Silent = !$Interactive
|
||||||
|
|
||||||
|
function Print-Msg {
|
||||||
|
param ( [Parameter(Mandatory=$true, HelpMessage='String to output')][string]$msg, [string]$color = "Green" )
|
||||||
|
Write-Host ('{0}' -f $msg) -ForegroundColor $color
|
||||||
|
}
|
||||||
|
|
||||||
|
function Create-Shortcut {
|
||||||
|
param ( [Parameter(Mandatory=$true,HelpMessage='Target path')][string]$SourceExe, [Parameter(Mandatory=$true,HelpMessage='Arguments to the path/exe')][AllowEmptyString()]$ArgumentsToSourceExe, [Parameter(Mandatory=$true,HelpMessage='The destination of the desktop link')][string]$DestinationPath )
|
||||||
|
$WshShell = New-Object -comObject WScript.Shell
|
||||||
|
$Shortcut = $WshShell.CreateShortcut($DestinationPath)
|
||||||
|
$Shortcut.TargetPath = $SourceExe
|
||||||
|
if($ArgumentsToSourceExe) {
|
||||||
|
$Shortcut.Arguments = $ArgumentsToSourceExe
|
||||||
|
}
|
||||||
|
$Shortcut.Save()
|
||||||
|
}
|
||||||
|
|
||||||
|
function Add-EnvPath {
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory=$true,HelpMessage='The Path to add to Users environment')]
|
||||||
|
[string] $Path,
|
||||||
|
|
||||||
|
[ValidateSet('Machine', 'User', 'Session')]
|
||||||
|
[string] $Container = 'Session'
|
||||||
|
)
|
||||||
|
|
||||||
|
if ($Container -eq 'Session') {
|
||||||
|
$envPaths = [Collections.Generic.List[String]]($env:Path -split ([IO.Path]::PathSeparator))
|
||||||
|
if ($envPaths -notcontains $Path) {
|
||||||
|
$envPaths.Add($Path)
|
||||||
|
$env:PATH = $envPaths -join ([IO.Path]::PathSeparator)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
[Microsoft.Win32.RegistryHive]$hive, $keyPath = switch ($Container) {
|
||||||
|
'Machine' { 'LocalMachine', 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment' }
|
||||||
|
'User' { 'CurrentUser', 'Environment' }
|
||||||
|
}
|
||||||
|
|
||||||
|
$hiveKey = $envKey = $null
|
||||||
|
try {
|
||||||
|
$hiveKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($hive, '')
|
||||||
|
$envKey = $hiveKey.OpenSubKey($keyPath, $true)
|
||||||
|
$rawPath = $envKey.GetValue('PATH', '', 'DoNotExpandEnvironmentNames')
|
||||||
|
|
||||||
|
$envPaths = [Collections.Generic.List[String]]($rawPath -split ([IO.Path]::PathSeparator))
|
||||||
|
if ($envPaths -notcontains $Path) {
|
||||||
|
$envPaths.Add($Path)
|
||||||
|
$envKey.SetValue('PATH', ($envPaths -join ([IO.Path]::PathSeparator)), 'ExpandString')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
if ($envKey) { $envKey.Close() }
|
||||||
|
if ($hiveKey) { $hiveKey.Close() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
filter Get-FileSize {
|
||||||
|
'{0:N2} {1}' -f $(
|
||||||
|
if ($_ -lt 1kb) { $_, 'Bytes' }
|
||||||
|
elseif ($_ -lt 1mb) { ($_/1kb), 'KB' }
|
||||||
|
elseif ($_ -lt 1gb) { ($_/1mb), 'MB' }
|
||||||
|
elseif ($_ -lt 1tb) { ($_/1gb), 'GB' }
|
||||||
|
elseif ($_ -lt 1pb) { ($_/1tb), 'TB' }
|
||||||
|
else { ($_/1pb), 'PB' }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Get-FileWCSynchronous{
|
||||||
|
param(
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]$url,
|
||||||
|
[string]$destinationFolder="$env:USERPROFILE\Downloads",
|
||||||
|
[switch]$includeStats
|
||||||
|
)
|
||||||
|
$wc = New-Object -TypeName Net.WebClient
|
||||||
|
$wc.UseDefaultCredentials = $true
|
||||||
|
$destination = Join-Path -Path $destinationFolder -ChildPath ($url | Split-Path -Leaf)
|
||||||
|
$start = Get-Date
|
||||||
|
$wc.DownloadFile($url, $destination)
|
||||||
|
$elapsed = ((Get-Date) - $start).ToString('hh\:mm\:ss')
|
||||||
|
$totalSize = (Get-Item -Path $destination).Length | Get-FileSize
|
||||||
|
if ($includeStats.IsPresent){
|
||||||
|
[PSCustomObject]@{Name=$MyInvocation.MyCommand;TotalSize=$totalSize;Time=$elapsed}
|
||||||
|
}
|
||||||
|
Get-Item -Path $destination | Unblock-File
|
||||||
|
}
|
||||||
|
|
||||||
|
function Test-AbsolutePath {
|
||||||
|
Param (
|
||||||
|
[Parameter(Mandatory=$True)]
|
||||||
|
[ValidateScript({[System.IO.Path]::IsPathRooted($_)})]
|
||||||
|
[String]$Path
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function Exec
|
||||||
|
{
|
||||||
|
[CmdletBinding()]
|
||||||
|
param(
|
||||||
|
[Parameter(Position = 0, Mandatory = 1)][string]$cmd,
|
||||||
|
[Parameter()][string]$errorMessage,
|
||||||
|
[parameter(ValueFromRemainingArguments = $true)]
|
||||||
|
[string[]]$Passthrough
|
||||||
|
)
|
||||||
|
& $cmd @Passthrough
|
||||||
|
if ($lastexitcode -ne 0) {
|
||||||
|
if (!($errorMessage)) {
|
||||||
|
throw ('Exec: Error executing command {0} with arguments ''{1}''' -f $cmd, "$Passthrough")
|
||||||
|
} else {
|
||||||
|
throw ('Exec: ' + $errorMessage)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
|
$GhcupBasePrefixEnv = [System.Environment]::GetEnvironmentVariable('GHCUP_INSTALL_BASE_PREFIX', 'user')
|
||||||
|
|
||||||
|
if ($GhcupBasePrefixEnv) {
|
||||||
|
$defaultGhcupBasePrefix = $GhcupBasePrefixEnv
|
||||||
|
} else {
|
||||||
|
$partitions = Get-CimInstance win32_logicaldisk
|
||||||
|
$defaultGhcupBasePrefix = $null
|
||||||
|
foreach ($p in $partitions){
|
||||||
|
try {
|
||||||
|
if ($p."FreeSpace" -lt 5368709120) { # at least 5 GB are needed
|
||||||
|
throw ("Not enough free space on {0}" -f $p."DeviceId")
|
||||||
|
}
|
||||||
|
$null = New-Item -Path ('{0}\' -f $p."DeviceId") -Name "ghcup.test" -ItemType "directory" -Force
|
||||||
|
$defaultGhcupBasePrefix = ('{0}\' -f $p."DeviceId")
|
||||||
|
Remove-Item -LiteralPath ('{0}\ghcup.test' -f $p."DeviceId")
|
||||||
|
break
|
||||||
|
} catch {
|
||||||
|
Print-Msg -color Yellow -msg ("{0} not writable or not enough disk space, trying next device" -f $p."DeviceId")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($defaultGhcupBasePrefix) {
|
||||||
|
Print-Msg -color Green -msg ("Picked {0} as default Install prefix!" -f $defaultGhcupBasePrefix)
|
||||||
|
} else {
|
||||||
|
Print-Msg -color Red -msg "Couldn't find a writable partition with at least 5GB free disk space!"
|
||||||
|
Exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($Silent -and !($InstallDir)) {
|
||||||
|
$GhcupBasePrefix = $defaultGhcupBasePrefix
|
||||||
|
} elseif ($InstallDir) {
|
||||||
|
if (!(Test-Path -LiteralPath ('{0}' -f $InstallDir) -IsValid)) {
|
||||||
|
Print-Msg -color Red -msg "Not a valid directory!"
|
||||||
|
Exit 1
|
||||||
|
} elseif (!(Split-Path -IsAbsolute -Path "$InstallDir")) {
|
||||||
|
Print-Msg -color Red -msg "Non-absolute Path specified!"
|
||||||
|
Exit 1
|
||||||
|
} else {
|
||||||
|
$GhcupBasePrefix = $InstallDir
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while ($true) {
|
||||||
|
Print-Msg -color Magenta -msg ('Where to install to (this should be a short Path, preferably a Drive like ''C:\''){1}Press enter to accept the default [{0}]:' -f $defaultGhcupBasePrefix, "`n")
|
||||||
|
$basePrefixPrompt = Read-Host
|
||||||
|
$GhcupBasePrefix = ($defaultGhcupBasePrefix,$basePrefixPrompt)[[bool]$basePrefixPrompt]
|
||||||
|
if (!($GhcupBasePrefix.EndsWith('\'))) {
|
||||||
|
$GhcupBasePrefix = ('{0}\' -f $GhcupBasePrefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!($GhcupBasePrefix)) {
|
||||||
|
Print-Msg -color Red -msg "No directory specified!"
|
||||||
|
} elseif (!(Test-Path -LiteralPath ('{0}' -f $GhcupBasePrefix))) {
|
||||||
|
Print-Msg -color Red -msg "Directory does not exist, need to specify an existing Drive/Directory"
|
||||||
|
} elseif (!(Split-Path -IsAbsolute -Path "$GhcupBasePrefix")) {
|
||||||
|
Print-Msg -color Red -msg "Invalid/Non-absolute Path specified"
|
||||||
|
} else {
|
||||||
|
Break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Print-Msg -msg ('Setting env variable GHCUP_INSTALL_BASE_PREFIX to ''{0}''' -f $GhcupBasePrefix)
|
||||||
|
$null = [Environment]::SetEnvironmentVariable("GHCUP_INSTALL_BASE_PREFIX", $GhcupBasePrefix, [System.EnvironmentVariableTarget]::User)
|
||||||
|
|
||||||
|
|
||||||
|
$GhcupDir = ('{0}\ghcup' -f $GhcupBasePrefix)
|
||||||
|
$MsysDir = ('{0}\msys64' -f $GhcupDir)
|
||||||
|
$Bash = ('{0}\usr\bin\bash' -f $MsysDir)
|
||||||
|
if (!($BootstrapUrl)) {
|
||||||
|
$BootstrapUrl = 'https://www.haskell.org/ghcup/sh/bootstrap-haskell'
|
||||||
|
}
|
||||||
|
$GhcupMsys2 = [System.Environment]::GetEnvironmentVariable('GHCUP_MSYS2', 'user')
|
||||||
|
|
||||||
|
Print-Msg -msg 'Preparing for GHCup installation...'
|
||||||
|
|
||||||
|
if (Test-Path -LiteralPath ('{0}' -f $GhcupDir)) {
|
||||||
|
Print-Msg -msg ('GHCup already installed at ''{0}''...' -f $GhcupDir)
|
||||||
|
if ($Overwrite) {
|
||||||
|
$decision = 0
|
||||||
|
} elseif (!($Silent)) {
|
||||||
|
$decision = $Host.UI.PromptForChoice('Install GHCup'
|
||||||
|
, 'GHCup is already installed, what do you want to do?'
|
||||||
|
, [System.Management.Automation.Host.ChoiceDescription[]] @('&Reinstall'
|
||||||
|
'&Continue'
|
||||||
|
'&Abort'), 1)
|
||||||
|
} else {
|
||||||
|
$decision = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($decision -eq 0) {
|
||||||
|
$suffix = [IO.Path]::GetRandomFileName()
|
||||||
|
Print-Msg -msg ('Backing up {0} to {0}-{1} ...' -f $GhcupDir, $suffix)
|
||||||
|
Rename-Item -Path ('{0}' -f $GhcupDir) -NewName ('{0}-{1}' -f $GhcupDir, $suffix)
|
||||||
|
} elseif ($decision -eq 1) {
|
||||||
|
Print-Msg -msg 'Continuing installation...'
|
||||||
|
} elseif ($decision -eq 2) {
|
||||||
|
Exit 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$null = New-Item -Path ('{0}' -f $GhcupDir) -ItemType 'directory' -ErrorAction SilentlyContinue
|
||||||
|
$null = New-Item -Path ('{0}' -f $GhcupDir) -Name 'bin' -ItemType 'directory' -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
Print-Msg -msg 'First checking for Msys2...'
|
||||||
|
|
||||||
|
if (!(Test-Path -Path ('{0}' -f $MsysDir))) {
|
||||||
|
if ($Silent) {
|
||||||
|
$msys2Decision = 0
|
||||||
|
} else {
|
||||||
|
$msys2Decision = $Host.UI.PromptForChoice('Install MSys2'
|
||||||
|
, 'Do you want GHCup to install a default MSys2 toolchain (recommended)?'
|
||||||
|
, [System.Management.Automation.Host.ChoiceDescription[]] @('&Yes'
|
||||||
|
'&No'), 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($msys2Decision -eq 0) {
|
||||||
|
Print-Msg -msg ('...Msys2 doesn''t exist, installing into {0} ...this may take a while' -f $MsysDir)
|
||||||
|
|
||||||
|
# Download the archive
|
||||||
|
Print-Msg -msg 'Downloading Msys2 archive...'
|
||||||
|
$archive = 'msys2-x86_64-latest.sfx.exe'
|
||||||
|
|
||||||
|
if (Get-Command -Name 'curl.exe' -ErrorAction SilentlyContinue) {
|
||||||
|
Exec "curl.exe" '-o' ('{0}\{1}' -f $env:TEMP, $archive) ('https://repo.msys2.org/distrib/{0}' -f $archive)
|
||||||
|
} else {
|
||||||
|
Get-FileWCSynchronous -url ('https://repo.msys2.org/distrib/{0}' -f $archive) -destinationFolder "$env:TEMP" -includeStats
|
||||||
|
}
|
||||||
|
|
||||||
|
Print-Msg -msg 'Extracting Msys2 archive...'
|
||||||
|
$null = & "$env:TEMP\$archive" '-y' ('-o{0}' -f $GhcupDir) # Extract
|
||||||
|
Remove-Item -Path ('{0}/{1}' -f $env:TEMP, $archive)
|
||||||
|
|
||||||
|
Print-Msg -msg 'Processing MSYS2 bash for first time use...'
|
||||||
|
Exec "$Bash" '-lc' 'exit'
|
||||||
|
|
||||||
|
Exec "$env:windir\system32\taskkill.exe" /F /FI `"MODULES eq msys-2.0.dll`"
|
||||||
|
|
||||||
|
Print-Msg -msg 'Upgrading full system...'
|
||||||
|
Exec "$Bash" '-lc' 'pacman --noconfirm -Syuu'
|
||||||
|
|
||||||
|
Print-Msg -msg 'Upgrading full system twice...'
|
||||||
|
Exec "$Bash" '-lc' 'pacman --noconfirm -Syuu'
|
||||||
|
|
||||||
|
Print-Msg -msg 'Installing Dependencies...'
|
||||||
|
Exec "$Bash" '-lc' 'pacman --noconfirm -S --needed curl mingw-w64-x86_64-pkgconf'
|
||||||
|
|
||||||
|
Print-Msg -msg 'Updating SSL root certificate authorities...'
|
||||||
|
Exec "$Bash" '-lc' 'pacman --noconfirm -S ca-certificates'
|
||||||
|
|
||||||
|
Print-Msg -msg 'Setting default home directory...'
|
||||||
|
Exec "$Bash" '-lc' "sed -i -e 's/db_home:.*$/db_home: windows/' /etc/nsswitch.conf"
|
||||||
|
} elseif ($msys2Decision -eq 1) {
|
||||||
|
Print-Msg -color Yellow -msg 'Skipping MSys2 installation.'
|
||||||
|
while ($true) {
|
||||||
|
if ($GhcupMsys2) {
|
||||||
|
$defaultMsys2Dir = $GhcupMsys2
|
||||||
|
Print-Msg -color Magenta -msg ('Input existing MSys2 toolchain directory. Press enter to accept the default [{0}]:' -f $defaultMsys2Dir)
|
||||||
|
$MsysDirPrompt = Read-Host
|
||||||
|
$MsysDir = ($defaultMsys2Dir,$MsysDirPrompt)[[bool]$MsysDirPrompt]
|
||||||
|
} else {
|
||||||
|
Print-Msg -color Magenta -msg 'Input existing MSys2 toolchain directory:'
|
||||||
|
$MsysDir = Read-Host
|
||||||
|
}
|
||||||
|
if (!($MsysDir)) {
|
||||||
|
Print-Msg -color Red -msg "No directory specified!"
|
||||||
|
} elseif (!(Test-Path -LiteralPath ('{0}' -f $MsysDir))) {
|
||||||
|
Print-Msg -color Red -msg ('MSys2 installation at ''{0}'' could not be found!' -f $MsysDir)
|
||||||
|
} elseif (!(Split-Path -IsAbsolute -Path "$MsysDir")) {
|
||||||
|
Print-Msg -color Red -msg "Invalid/Non-absolute Path specified"
|
||||||
|
} else {
|
||||||
|
Break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Print-Msg -msg ('Setting GHCUP_MSYS2 env var to ''{0}''' -f $MsysDir)
|
||||||
|
$null = [Environment]::SetEnvironmentVariable("GHCUP_MSYS2", $MsysDir, [System.EnvironmentVariableTarget]::User)
|
||||||
|
$Bash = ('{0}\usr\bin\bash' -f $MsysDir)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Print-Msg -msg ('...Msys2 found in {0} ...skipping Msys2 installation.' -f $MsysDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
Print-Msg -msg 'Creating shortcuts...'
|
||||||
|
$DesktopDir = [Environment]::GetFolderPath("Desktop")
|
||||||
|
$GhcInstArgs = '-mingw64 -mintty -c "pacman --noconfirm -S --needed base-devel gettext autoconf make libtool automake python p7zip patch unzip"'
|
||||||
|
Create-Shortcut -SourceExe ('{0}\msys2_shell.cmd' -f $MsysDir) -ArgumentsToSourceExe $GhcInstArgs -DestinationPath ('{0}\Install GHC dev dependencies.lnk' -f $DesktopDir)
|
||||||
|
Create-Shortcut -SourceExe ('{0}\msys2_shell.cmd' -f $MsysDir) -ArgumentsToSourceExe '-mingw64' -DestinationPath ('{0}\Mingw haskell shell.lnk' -f $DesktopDir)
|
||||||
|
Create-Shortcut -SourceExe 'https://www.msys2.org/docs/package-management' -ArgumentsToSourceExe '' -DestinationPath ('{0}\Mingw package management docs.url' -f $DesktopDir)
|
||||||
|
|
||||||
|
Print-Msg -msg ('Adding {0}\bin to Users Path...' -f $GhcupDir)
|
||||||
|
Add-EnvPath -Path ('{0}\bin' -f ([System.IO.Path]::GetFullPath("$GhcupDir"))) -Container 'User'
|
||||||
|
|
||||||
|
if ($CabalDir) {
|
||||||
|
$CabDirEnv = $CabalDir
|
||||||
|
if (!($CabDirEnv)) {
|
||||||
|
Print-Msg -color Red -msg "No directory specified!"
|
||||||
|
Exit 1
|
||||||
|
} elseif (!(Split-Path -IsAbsolute -Path "$CabDirEnv")) {
|
||||||
|
Print-Msg -color Red -msg "Invalid/Non-absolute Path specified"
|
||||||
|
Exit 1
|
||||||
|
}
|
||||||
|
} elseif (!($Silent)) {
|
||||||
|
while ($true) {
|
||||||
|
|
||||||
|
$defaultCabalDir = ('{0}\cabal' -f $GhcupBasePrefix)
|
||||||
|
Print-Msg -color Magenta -msg ('Specify Cabal directory (this is where haskell packages end up). Press enter to accept the default [{0}]:' -f $defaultCabalDir)
|
||||||
|
$CabalDirPrompt = Read-Host
|
||||||
|
$CabDirEnv = ($defaultCabalDir,$CabalDirPrompt)[[bool]$CabalDirPrompt]
|
||||||
|
|
||||||
|
if (!($CabDirEnv)) {
|
||||||
|
Print-Msg -color Red -msg "No directory specified!"
|
||||||
|
} elseif (!(Split-Path -IsAbsolute -Path "$CabDirEnv")) {
|
||||||
|
Print-Msg -color Red -msg "Invalid/Non-absolute Path specified"
|
||||||
|
} else {
|
||||||
|
Break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$CabDirEnv = ('{0}\cabal' -f $GhcupBasePrefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
$CabalDirFull = [System.IO.Path]::GetFullPath("$CabDirEnv")
|
||||||
|
Print-Msg -msg ('Setting CABAL_DIR to ''{0}''' -f $CabalDirFull)
|
||||||
|
$null = [Environment]::SetEnvironmentVariable("CABAL_DIR", $CabalDirFull, [System.EnvironmentVariableTarget]::User)
|
||||||
|
|
||||||
|
Print-Msg -msg 'Starting GHCup installer...'
|
||||||
|
|
||||||
|
$Msys2Shell = ('{0}\msys2_shell.cmd' -f $MsysDir)
|
||||||
|
|
||||||
|
if ($Silent) {
|
||||||
|
$SilentExport = 'export BOOTSTRAP_HASKELL_NONINTERACTIVE=1 ;'
|
||||||
|
} else {
|
||||||
|
$SilentExport = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((Get-Process -ID $PID).ProcessName.StartsWith("bootstrap-haskell") -Or $InBash) {
|
||||||
|
Exec "$Bash" '-lc' ('{4} [ -n ''{1}'' ] && export GHCUP_MSYS2=$(cygpath -m ''{1}'') ; [ -n ''{2}'' ] && export GHCUP_INSTALL_BASE_PREFIX=$(cygpath -m ''{2}/'') ; export PATH=$(cygpath -u ''{3}/bin''):$PATH ; export CABAL_DIR=''{5}'' ; [[ ''{0}'' = https* ]] && curl --proto ''=https'' --tlsv1.2 -sSf {0} | bash || cat $(cygpath -m ''{0}'') | bash' -f $BootstrapUrl, $MsysDir, $GhcupBasePrefix, $GhcupDir, $SilentExport, $CabalDirFull)
|
||||||
|
} else {
|
||||||
|
Exec "$Msys2Shell" '-mingw64' '-mintty' '-c' ('{4} [ -n ''{1}'' ] && export GHCUP_MSYS2=$(cygpath -m ''{1}'') ; [ -n ''{2}'' ] && export GHCUP_INSTALL_BASE_PREFIX=$(cygpath -m ''{2}/'') ; export PATH=$(cygpath -u ''{3}/bin''):$PATH ; export CABAL_DIR=''{5}'' ; trap ''echo Press any key to exit && read -n 1 && exit'' 2 ; [[ ''{0}'' = https* ]] && curl --proto ''=https'' --tlsv1.2 -sSf {0} | bash || cat $(cygpath -m ''{0}'') | bash ; echo ''Press any key to exit'' && read -n 1' -f $BootstrapUrl, $MsysDir, $GhcupBasePrefix, $GhcupDir, $SilentExport, $CabalDirFull)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# SIG # Begin signature block
|
||||||
|
# MIID4QYJKoZIhvcNAQcCoIID0jCCA84CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
|
||||||
|
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
|
||||||
|
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUVqKek181kF/Jx/P7z176herc
|
||||||
|
# ZyCgggH/MIIB+zCCAWSgAwIBAgIQGOezhGS1A5tHh9VubW0liDANBgkqhkiG9w0B
|
||||||
|
# AQUFADAYMRYwFAYDVQQDDA1KdWxpYW4gT3NwYWxkMB4XDTIxMDUzMDE4Mzk1OVoX
|
||||||
|
# DTI1MDUzMDAwMDAwMFowGDEWMBQGA1UEAwwNSnVsaWFuIE9zcGFsZDCBnzANBgkq
|
||||||
|
# hkiG9w0BAQEFAAOBjQAwgYkCgYEAs76XCXYPM14buR1RkVKhOB8pyM4Df6kPaz75
|
||||||
|
# nkbA0nq1VmMhBfCYFWyYHd7jniqTH0LoAKGGquN1bniREaCP9j2pFWpMIgLpQH3H
|
||||||
|
# +jpsfmxV2BTG8q+Jok88gTXS1FlAk72E85zO/Jhr6Fja1aFYAdibBRsRxcVMTVh7
|
||||||
|
# 4AGLNGUCAwEAAaNGMEQwEwYDVR0lBAwwCgYIKwYBBQUHAwMwHQYDVR0OBBYEFC+R
|
||||||
|
# hdhPo0Ty5HnzHyo1pN35IfZQMA4GA1UdDwEB/wQEAwIHgDANBgkqhkiG9w0BAQUF
|
||||||
|
# AAOBgQAl3IdBVIwbJJDp7BksMYPeM4ivB3UyNvlw8aVxGwAzNgdSaezYIdMFtKXV
|
||||||
|
# CSv5bd4VnFRAPDJW9dhW0h3SkeJUoklUxMjKXhR3qygQhSxPDjIatAuOCffGACba
|
||||||
|
# ZZ7Om40b+pKXc6i/HnlApk9DGbXJ59bFcLGGcZ9QjoUae6Ex1DGCAUwwggFIAgEB
|
||||||
|
# MCwwGDEWMBQGA1UEAwwNSnVsaWFuIE9zcGFsZAIQGOezhGS1A5tHh9VubW0liDAJ
|
||||||
|
# BgUrDgMCGgUAoHgwGAYKKwYBBAGCNwIBDDEKMAigAoAAoQKAADAZBgkqhkiG9w0B
|
||||||
|
# CQMxDAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3AgELMQ4wDAYKKwYBBAGCNwIBFTAj
|
||||||
|
# BgkqhkiG9w0BCQQxFgQUosm9nN1JgajqSBa1cUwxxhLrAsYwDQYJKoZIhvcNAQEB
|
||||||
|
# BQAEgYCnKzfsH1aDjS6xkC/uymjaBowHSnh6nFu2AkjcKu8RgcBZzP5SLBXgU9wm
|
||||||
|
# aED5Ujwyq3Qre+TGVRUqwkEauDhQiX2A008G00fRO6+di6yJRCRn5eaRAbdU3Xww
|
||||||
|
# E5VhEwLBnwzWrvLKtdEclhgUCo5Tq87QMXVdgX4aRmunl4ZE+Q==
|
||||||
|
# SIG # End signature block
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,18 +1,26 @@
|
|||||||
packages: ./ghcup.cabal
|
packages: ./ghcup.cabal
|
||||||
|
|
||||||
|
optional-packages: ./vendored/*/*.cabal
|
||||||
|
|
||||||
optimization: 2
|
optimization: 2
|
||||||
|
|
||||||
package streamly
|
|
||||||
ghc-options: -O2 -fspec-constr-recursive=16 -fmax-worker-args=16
|
|
||||||
|
|
||||||
package ghcup
|
package ghcup
|
||||||
ghc-options: -O2 -fspec-constr-recursive=16 -fmax-worker-args=16
|
|
||||||
tests: True
|
tests: True
|
||||||
flags: +tui
|
flags: +tui
|
||||||
|
|
||||||
|
source-repository-package
|
||||||
|
type: git
|
||||||
|
location: https://github.com/Bodigrim/tar
|
||||||
|
tag: ac197ec7ea4838dc2b4e22b9b888b080cedf29cf
|
||||||
|
|
||||||
|
source-repository-package
|
||||||
|
type: git
|
||||||
|
location: https://github.com/bgamari/terminal-size
|
||||||
|
tag: 34ea816bd63f75f800eedac12c6908c6f3736036
|
||||||
|
|
||||||
constraints: http-io-streams -brotli
|
constraints: http-io-streams -brotli
|
||||||
|
|
||||||
package libarchive
|
package libarchive
|
||||||
flags: -system-libarchive
|
flags: -system-libarchive
|
||||||
|
|
||||||
allow-newer: base, ghc-prim, template-haskell
|
allow-newer: base, ghc-prim, template-haskell, language-c
|
||||||
|
|||||||
2
cabal.project.freeze
Normal file
2
cabal.project.freeze
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
-- windows picks weird version
|
||||||
|
constraints: any.hsc2hs ==0.68.7
|
||||||
@@ -29,6 +29,8 @@ key-bindings:
|
|||||||
KChar: 'c'
|
KChar: 'c'
|
||||||
show-all:
|
show-all:
|
||||||
KChar: 'a'
|
KChar: 'a'
|
||||||
|
show-all-tools:
|
||||||
|
KChar: 't'
|
||||||
|
|
||||||
# Where to get GHC/cabal/hls download info/versions from. For more detailed explanation
|
# Where to get GHC/cabal/hls download info/versions from. For more detailed explanation
|
||||||
# check the 'URLSource' type in the code.
|
# check the 'URLSource' type in the code.
|
||||||
|
|||||||
125
ghcup-0.0.4.yaml
125
ghcup-0.0.4.yaml
@@ -1286,6 +1286,7 @@ ghcupDownloads:
|
|||||||
dlHash: bb9c97826b1f4d7a8ef8bce0616b612f1ded10480ef10fcf7fb4e6d10a6681c8
|
dlHash: bb9c97826b1f4d7a8ef8bce0616b612f1ded10480ef10fcf7fb4e6d10a6681c8
|
||||||
8.10.3:
|
8.10.3:
|
||||||
viTags:
|
viTags:
|
||||||
|
- old
|
||||||
- base-4.14.1.0
|
- base-4.14.1.0
|
||||||
viChangeLog: https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/8.10.3-notes.html
|
viChangeLog: https://downloads.haskell.org/~ghc/8.10.3/docs/html/users_guide/8.10.3-notes.html
|
||||||
viSourceDL:
|
viSourceDL:
|
||||||
@@ -1375,7 +1376,6 @@ ghcupDownloads:
|
|||||||
dlHash: b823b58cae36fbac0741680ca7605180fa4cf4c6ae439123d282184b94d32fd6
|
dlHash: b823b58cae36fbac0741680ca7605180fa4cf4c6ae439123d282184b94d32fd6
|
||||||
8.10.4:
|
8.10.4:
|
||||||
viTags:
|
viTags:
|
||||||
- Recommended
|
|
||||||
- base-4.14.1.0
|
- base-4.14.1.0
|
||||||
viChangeLog: https://downloads.haskell.org/~ghc/8.10.4/docs/html/users_guide/8.10.4-notes.html
|
viChangeLog: https://downloads.haskell.org/~ghc/8.10.4/docs/html/users_guide/8.10.4-notes.html
|
||||||
viSourceDL:
|
viSourceDL:
|
||||||
@@ -1383,7 +1383,7 @@ ghcupDownloads:
|
|||||||
dlSubdir: ghc-8.10.4
|
dlSubdir: ghc-8.10.4
|
||||||
dlHash: 52af871b4e08550257d720c2944ac85727d0b948407cef1bebfe7508c224910e
|
dlHash: 52af871b4e08550257d720c2944ac85727d0b948407cef1bebfe7508c224910e
|
||||||
viPostRemove: *ghc-post-remove
|
viPostRemove: *ghc-post-remove
|
||||||
viPreCompile: "If you have autoconf >= 2.70 you'll need this patch https://gitlab.haskell.org/ghc/ghc/-/snippets/2040 (see the --patchdir option)"
|
viPreCompile: &ghc-pre-compile "If you have autoconf >= 2.70 you'll need this patch https://gitlab.haskell.org/ghc/ghc/-/snippets/2040 (see the --patchdir option)"
|
||||||
viArch:
|
viArch:
|
||||||
A_64:
|
A_64:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
@@ -1464,6 +1464,97 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/8.10.4/ghc-8.10.4-armv7-deb10-linux.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/8.10.4/ghc-8.10.4-armv7-deb10-linux.tar.xz
|
||||||
dlSubdir: ghc-8.10.4
|
dlSubdir: ghc-8.10.4
|
||||||
dlHash: 0d18ef83593272f6196a41cc3abdc48dfe5e14372db75d71ea19fe35320c4e81
|
dlHash: 0d18ef83593272f6196a41cc3abdc48dfe5e14372db75d71ea19fe35320c4e81
|
||||||
|
8.10.5:
|
||||||
|
viTags:
|
||||||
|
- Recommended
|
||||||
|
- base-4.14.2.0
|
||||||
|
viChangeLog: https://downloads.haskell.org/~ghc/8.10.5/docs/html/users_guide/8.10.5-notes.html
|
||||||
|
viSourceDL:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.10.5/ghc-8.10.5-src.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.5
|
||||||
|
dlHash: f10941f16e4fbd98580ab5241b9271bb0851304560c4d5ca127e3b0e20e3076f
|
||||||
|
viPostRemove: *ghc-post-remove
|
||||||
|
viPreCompile: *ghc-pre-compile
|
||||||
|
viArch:
|
||||||
|
A_64:
|
||||||
|
Linux_Debian:
|
||||||
|
'( >= 9 && < 10 )': &ghc-8105-64-deb9
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.10.5/ghc-8.10.5-x86_64-deb9-linux.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.5
|
||||||
|
dlHash: 15e71325c3bdfe3804be0f84c2fc5c913d811322d19b0f4d4cff20f29cdd804d
|
||||||
|
'( >= 10 && < 11 )': &ghc-8105-64-deb10
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.10.5/ghc-8.10.5-x86_64-deb10-linux.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.5
|
||||||
|
dlHash: bc623c20ca4c5c18e952071ba14aa0cfc5c94d34219bffaa615f7b491f376787
|
||||||
|
unknown_versioning: *ghc-8105-64-deb9
|
||||||
|
Linux_Ubuntu:
|
||||||
|
unknown_versioning: &ghc-8105-64-fedora
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.10.5/ghc-8.10.5-x86_64-fedora27-linux.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.5
|
||||||
|
dlHash: 73528ebfb219b50aa9042ee51a0a2bd764828d605f058404989d0b645752d210
|
||||||
|
'( >= 16 && < 19 )': *ghc-8105-64-deb9
|
||||||
|
Linux_Mint:
|
||||||
|
unknown_versioning: *ghc-8105-64-deb10
|
||||||
|
Linux_Fedora:
|
||||||
|
'( >= 27 && < 28 )': *ghc-8105-64-fedora
|
||||||
|
unknown_versioning: *ghc-8105-64-fedora
|
||||||
|
Linux_CentOS:
|
||||||
|
'( >= 7 && < 8 )': &ghc-8105-64-centos
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.10.5/ghc-8.10.5-x86_64-centos7-linux.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.5
|
||||||
|
dlHash: 4cdb259ec74d1408dab45dab20dcedc21690f39921c2ea4546486fb3e81f4fbd
|
||||||
|
unknown_versioning: *ghc-8105-64-centos
|
||||||
|
Linux_RedHat:
|
||||||
|
unknown_versioning: *ghc-8105-64-centos
|
||||||
|
Linux_Alpine:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.10.5/ghc-8.10.5-x86_64-alpine3.10-linux-integer-simple.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.5-x86_64-unknown-linux
|
||||||
|
dlHash: f4d7cd9ed12a4b8592219c9a63a86db1a256a09fa9e6ed755a60afc57dc782e2
|
||||||
|
Linux_AmazonLinux:
|
||||||
|
unknown_versioning: *ghc-8105-64-centos
|
||||||
|
Linux_UnknownLinux:
|
||||||
|
unknown_versioning: *ghc-8105-64-fedora
|
||||||
|
Darwin:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.10.5/ghc-8.10.5-x86_64-apple-darwin.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.5
|
||||||
|
dlHash: ef0f47eff8962d58fa447123636cf8ef31c1e5b2d0ae90177d3388861ddf4a22
|
||||||
|
FreeBSD:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghcup/unofficial-bindists/ghc/8.10.5/ghc-8.10.5-x86_64-portbld-freebsd.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.5
|
||||||
|
dlHash: 11a0b490bfb2f57b5bc87c69c197542eafce1b4991cc22f625179a6c6e567834
|
||||||
|
A_32:
|
||||||
|
Linux_Debian:
|
||||||
|
'( >= 9 && < 10 )': &ghc-8105-32-deb9
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.10.5/ghc-8.10.5-i386-deb9-linux.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.5
|
||||||
|
dlHash: 0ccb5b2c1222374874795c35410754dd650f649b774872abbea2a4ef21ac9c9d
|
||||||
|
unknown_versioning: *ghc-8105-32-deb9
|
||||||
|
Linux_Ubuntu:
|
||||||
|
unknown_versioning: *ghc-8105-32-deb9
|
||||||
|
Linux_Mint:
|
||||||
|
unknown_versioning: *ghc-8105-32-deb9
|
||||||
|
Linux_UnknownLinux:
|
||||||
|
unknown_versioning: *ghc-8105-32-deb9
|
||||||
|
Linux_Alpine:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghcup/unofficial-bindists/ghc/8.10.5/ghc-8.10.5-i386-alpine-linux.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.5
|
||||||
|
dlHash: 0e91abe61607f9375d4e252ee9c261e4856df396f60641bb1b880ab8a3a83ea7
|
||||||
|
A_ARM64:
|
||||||
|
Linux_UnknownLinux:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.10.5/ghc-8.10.5-aarch64-deb10-linux.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.5
|
||||||
|
dlHash: 9a085cd8a7f8e0ace21ac67dbf659a56fcf41564b48817ba42cd8a1aac7f0ddc
|
||||||
|
A_ARM:
|
||||||
|
Linux_UnknownLinux:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.10.5/ghc-8.10.5-armv7-deb10-linux.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.5
|
||||||
|
dlHash: 56170d1a8450e18b7eb9c23c94723da352815b27ec250bb23742a62f16dcab6c
|
||||||
9.0.1:
|
9.0.1:
|
||||||
viTags:
|
viTags:
|
||||||
- Latest
|
- Latest
|
||||||
@@ -1777,7 +1868,7 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal/3.4.0.0/cabal-install-3.4.0.0-armv7-linux-bootstrapped.tar.xz
|
dlUri: https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal/3.4.0.0/cabal-install-3.4.0.0-armv7-linux-bootstrapped.tar.xz
|
||||||
dlHash: 16c0d1eaba24bed14f3e152970179a45d9f9bb5cc839b2c210ad06eb7d4826ed
|
dlHash: 16c0d1eaba24bed14f3e152970179a45d9f9bb5cc839b2c210ad06eb7d4826ed
|
||||||
GHCup:
|
GHCup:
|
||||||
0.1.14.1:
|
0.1.15.2:
|
||||||
viTags:
|
viTags:
|
||||||
- Recommended
|
- Recommended
|
||||||
- Latest
|
- Latest
|
||||||
@@ -1787,35 +1878,39 @@ ghcupDownloads:
|
|||||||
A_64:
|
A_64:
|
||||||
Linux_UnknownLinux:
|
Linux_UnknownLinux:
|
||||||
unknown_versioning: &ghcup-64
|
unknown_versioning: &ghcup-64
|
||||||
dlUri: https://downloads.haskell.org/~ghcup/0.1.14.1/x86_64-linux-ghcup-0.1.14.1
|
dlUri: https://downloads.haskell.org/~ghcup/0.1.15.2/x86_64-linux-ghcup-0.1.15.2
|
||||||
dlHash: 59e31b2ede3ed20f79dce0f8ba0a68b6fb25e5f00ba2d7243f6a8af68d979ff5
|
dlHash: 1eb1bb318a327754f42eaa2245bc81fe53be7c791160d28a186893ded3004ed7
|
||||||
Darwin:
|
Darwin:
|
||||||
unknown_versioning:
|
unknown_versioning:
|
||||||
dlUri: https://downloads.haskell.org/~ghcup/0.1.14.1/x86_64-apple-darwin-ghcup-0.1.14.1
|
dlUri: https://downloads.haskell.org/~ghcup/0.1.15.2/x86_64-apple-darwin-ghcup-0.1.15.2
|
||||||
dlHash: 3e1dd173b3e7b5d90dcdece423c3ddd3efb4c83e964967b0fb574c9b7b2c44e1
|
dlHash: c2a6436a49f19f108493954d4a3efcb27503e343dd6288c2641784d32320b1ea
|
||||||
FreeBSD:
|
FreeBSD:
|
||||||
unknown_versioning:
|
unknown_versioning:
|
||||||
dlUri: https://downloads.haskell.org/~ghcup/0.1.14.1/x86_64-portbld-freebsd-ghcup-0.1.14.1
|
dlUri: https://downloads.haskell.org/~ghcup/0.1.15.2/x86_64-portbld-freebsd-ghcup-0.1.15.2
|
||||||
dlHash: 89a70980d77888dae8b9fd0f05e7a7920f421bc3bb5192da8e73fd4e7b4cb86f
|
dlHash: 7e0c17dd78ebd9fd03e6ecea278c192bac31ca333721bde5b0ef99438b847a20
|
||||||
Linux_Alpine:
|
Linux_Alpine:
|
||||||
unknown_versioning: *ghcup-64
|
unknown_versioning: *ghcup-64
|
||||||
A_32:
|
A_32:
|
||||||
Linux_UnknownLinux:
|
Linux_UnknownLinux:
|
||||||
unknown_versioning: &ghcup-32
|
unknown_versioning: &ghcup-32
|
||||||
dlUri: https://downloads.haskell.org/~ghcup/0.1.14.1/i386-linux-ghcup-0.1.14.1
|
dlUri: https://downloads.haskell.org/~ghcup/0.1.15.2/i386-linux-ghcup-0.1.15.2
|
||||||
dlHash: 610aac7c3be3ba3874c07b9cae5b2ca0da9a92bf381afc2597bd2dc9c70aae0c
|
dlHash: 3b1fe710cded0398e920ec9716089ba65226abf181741897f387e7c539a619c2
|
||||||
Linux_Alpine:
|
Linux_Alpine:
|
||||||
unknown_versioning: *ghcup-32
|
unknown_versioning: *ghcup-32
|
||||||
A_ARM64:
|
A_ARM64:
|
||||||
Linux_UnknownLinux:
|
Linux_UnknownLinux:
|
||||||
unknown_versioning:
|
unknown_versioning:
|
||||||
dlUri: https://downloads.haskell.org/~ghcup/0.1.14.1/aarch64-linux-ghcup-0.1.14.1
|
dlUri: https://downloads.haskell.org/~ghcup/0.1.15.2/aarch64-linux-ghcup-0.1.15.2
|
||||||
dlHash: e9ae07b7d41ea03e6af9c1f3587f61287827c4e29478b6a5d46ea1ce5af4cee5
|
dlHash: d91b7a5416f292f2cf813824eb419f76ad9976d258cee3581123cb6eb01db9a7
|
||||||
|
Darwin:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghcup/0.1.15.2/aarch64-apple-darwin-ghcup-0.1.15.2
|
||||||
|
dlHash: 20625ba5e7488f2a6155331750ecead3815ea16b2695c20521633c1412f012cc
|
||||||
A_ARM:
|
A_ARM:
|
||||||
Linux_UnknownLinux:
|
Linux_UnknownLinux:
|
||||||
unknown_versioning:
|
unknown_versioning:
|
||||||
dlUri: https://downloads.haskell.org/~ghcup/0.1.14.1/armv7-linux-ghcup-0.1.14.1
|
dlUri: https://downloads.haskell.org/~ghcup/0.1.15.2/armv7-linux-ghcup-0.1.15.2
|
||||||
dlHash: 646832030efbc0a848df24c08b5eb7507bd15d1c2eb95fea6d9d03890f3662be
|
dlHash: 03a4af5ed895ada1dd21f4cc3f64dc9078a5bf4268313021d004c04bea7f9c2e
|
||||||
HLS:
|
HLS:
|
||||||
1.1.0:
|
1.1.0:
|
||||||
viTags:
|
viTags:
|
||||||
|
|||||||
2175
ghcup-0.0.5.yaml
Normal file
2175
ghcup-0.0.5.yaml
Normal file
File diff suppressed because it is too large
Load Diff
117
ghcup.cabal
117
ghcup.cabal
@@ -1,6 +1,6 @@
|
|||||||
cabal-version: 3.0
|
cabal-version: 3.0
|
||||||
name: ghcup
|
name: ghcup
|
||||||
version: 0.1.14.1
|
version: 0.1.15.2
|
||||||
license: LGPL-3.0-only
|
license: LGPL-3.0-only
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
copyright: Julian Ospald 2020
|
copyright: Julian Ospald 2020
|
||||||
@@ -19,6 +19,7 @@ extra-doc-files:
|
|||||||
CHANGELOG.md
|
CHANGELOG.md
|
||||||
config.yaml
|
config.yaml
|
||||||
ghcup-0.0.4.yaml
|
ghcup-0.0.4.yaml
|
||||||
|
ghcup-0.0.5.yaml
|
||||||
HACKING.md
|
HACKING.md
|
||||||
README.md
|
README.md
|
||||||
RELEASING.md
|
RELEASING.md
|
||||||
@@ -28,19 +29,21 @@ source-repository head
|
|||||||
location: https://gitlab.haskell.org/haskell/ghcup-hs.git
|
location: https://gitlab.haskell.org/haskell/ghcup-hs.git
|
||||||
|
|
||||||
flag tui
|
flag tui
|
||||||
description: Build the brick powered tui (ghcup tui)
|
description:
|
||||||
|
Build the brick powered tui (ghcup tui). This is disabled on windows.
|
||||||
|
|
||||||
default: False
|
default: False
|
||||||
manual: True
|
manual: True
|
||||||
|
|
||||||
flag internal-downloader
|
flag internal-downloader
|
||||||
description:
|
description:
|
||||||
Compile the internal downloader, which links against OpenSSL
|
Compile the internal downloader, which links against OpenSSL. This is disabled on windows.
|
||||||
|
|
||||||
default: False
|
default: False
|
||||||
manual: True
|
manual: True
|
||||||
|
|
||||||
flag tar
|
flag tar
|
||||||
description: Use tar-bytestring instead of libarchive
|
description: Use tar-bytestring instead of libarchive.
|
||||||
default: False
|
default: False
|
||||||
manual: True
|
manual: True
|
||||||
|
|
||||||
@@ -58,6 +61,7 @@ library
|
|||||||
GHCup.Utils
|
GHCup.Utils
|
||||||
GHCup.Utils.Dirs
|
GHCup.Utils.Dirs
|
||||||
GHCup.Utils.File
|
GHCup.Utils.File
|
||||||
|
GHCup.Utils.File.Common
|
||||||
GHCup.Utils.Logger
|
GHCup.Utils.Logger
|
||||||
GHCup.Utils.MegaParsec
|
GHCup.Utils.MegaParsec
|
||||||
GHCup.Utils.Prelude
|
GHCup.Utils.Prelude
|
||||||
@@ -70,14 +74,20 @@ library
|
|||||||
autogen-modules: Paths_ghcup
|
autogen-modules: Paths_ghcup
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
default-extensions:
|
default-extensions:
|
||||||
|
DeriveGeneric
|
||||||
LambdaCase
|
LambdaCase
|
||||||
MultiWayIf
|
MultiWayIf
|
||||||
|
NamedFieldPuns
|
||||||
PackageImports
|
PackageImports
|
||||||
|
QuasiQuotes
|
||||||
RecordWildCards
|
RecordWildCards
|
||||||
ScopedTypeVariables
|
ScopedTypeVariables
|
||||||
Strict
|
Strict
|
||||||
StrictData
|
StrictData
|
||||||
TupleSections
|
TupleSections
|
||||||
|
TypeApplications
|
||||||
|
TypeFamilies
|
||||||
|
ViewPatterns
|
||||||
|
|
||||||
ghc-options:
|
ghc-options:
|
||||||
-Wall -fwarn-tabs -fwarn-incomplete-uni-patterns
|
-Wall -fwarn-tabs -fwarn-incomplete-uni-patterns
|
||||||
@@ -85,28 +95,25 @@ library
|
|||||||
|
|
||||||
build-depends:
|
build-depends:
|
||||||
, aeson >=1.4 && <1.6
|
, aeson >=1.4 && <1.6
|
||||||
, ascii-string ^>=1.0
|
|
||||||
, async >=0.8 && <2.3
|
, async >=0.8 && <2.3
|
||||||
, base >=4.13 && <5
|
, base >=4.13 && <5
|
||||||
, base16-bytestring >=0.1.1.6 && <1.1
|
, base16-bytestring >=0.1.1.6 && <1.1
|
||||||
, binary ^>=0.8.6.0
|
, binary ^>=0.8.6.0
|
||||||
, bytestring ^>=0.10
|
, bytestring ^>=0.10
|
||||||
, bz2 >=0.5.0.5 && <1.1
|
|
||||||
, case-insensitive ^>=1.2.1.0
|
, case-insensitive ^>=1.2.1.0
|
||||||
, casing ^>=0.1.4.1
|
, casing ^>=0.1.4.1
|
||||||
, concurrent-output ^>=1.10.11
|
, concurrent-output ^>=1.10.11
|
||||||
, containers ^>=0.6
|
, containers ^>=0.6
|
||||||
, cryptohash-sha256 ^>=0.11.101.0
|
, cryptohash-sha256 ^>=0.11.101.0
|
||||||
|
, deepseq ^>=1.4.4.0
|
||||||
|
, directory ^>=1.3.6.0
|
||||||
, disk-free-space ^>=0.1.0.1
|
, disk-free-space ^>=0.1.0.1
|
||||||
|
, extra ^>=1.7.9
|
||||||
|
, filepath ^>=1.4.2.1
|
||||||
, generics-sop ^>=0.5
|
, generics-sop ^>=0.5
|
||||||
, haskus-utils-types ^>=1.5
|
, haskus-utils-types ^>=1.5
|
||||||
, haskus-utils-variant >=3.0 && <3.2
|
, haskus-utils-variant >=3.0 && <3.2
|
||||||
, hpath >=0.11 && <0.13
|
, lzma-static ^>=5.2.5.3
|
||||||
, hpath-directory ^>=0.14.1
|
|
||||||
, hpath-filepath ^>=0.10.3
|
|
||||||
, hpath-io ^>=0.14.1
|
|
||||||
, hpath-posix ^>=0.13.2
|
|
||||||
, lzma-static ^>=5.2.5.2
|
|
||||||
, megaparsec >=8.0.0 && <9.1
|
, megaparsec >=8.0.0 && <9.1
|
||||||
, monad-logger ^>=0.3.31
|
, monad-logger ^>=0.3.31
|
||||||
, mtl ^>=2.2
|
, mtl ^>=2.2
|
||||||
@@ -121,44 +128,62 @@ library
|
|||||||
, safe ^>=0.3.18
|
, safe ^>=0.3.18
|
||||||
, safe-exceptions ^>=0.1
|
, safe-exceptions ^>=0.1
|
||||||
, split ^>=0.2.3.4
|
, split ^>=0.2.3.4
|
||||||
, streamly ^>=0.7.3
|
|
||||||
, streamly-bytestring ^>=0.1.2
|
|
||||||
, streamly-posix ^>=0.1.0.0
|
|
||||||
, strict-base ^>=0.4
|
, strict-base ^>=0.4
|
||||||
, string-interpolate >=0.2.0.0 && <0.4
|
, string-interpolate >=0.2.0.0 && <0.4
|
||||||
, template-haskell >=2.7 && <2.17
|
, template-haskell >=2.7 && <2.18
|
||||||
|
, temporary ^>=1.3
|
||||||
, text ^>=1.2.4.0
|
, text ^>=1.2.4.0
|
||||||
, time ^>=1.9.3
|
, time ^>=1.9.3
|
||||||
, transformers ^>=0.5
|
, transformers ^>=0.5
|
||||||
, unix ^>=2.7
|
|
||||||
, unix-bytestring ^>=0.3
|
|
||||||
, unliftio-core ^>=0.2.0.1
|
, unliftio-core ^>=0.2.0.1
|
||||||
, unordered-containers ^>=0.2.10.0
|
, unordered-containers ^>=0.2.10.0
|
||||||
, uri-bytestring ^>=0.3.2.2
|
, uri-bytestring ^>=0.3.2.2
|
||||||
, utf8-string ^>=1.0
|
, utf8-string ^>=1.0
|
||||||
, vector ^>=0.12
|
, vector ^>=0.12
|
||||||
, versions ^>=4.0.1
|
, versions >=4.0.1 && <5.1
|
||||||
, vty >=5.28.2 && <5.34
|
|
||||||
, word8 ^>=0.1.3
|
, word8 ^>=0.1.3
|
||||||
, yaml ^>=0.11.4.0
|
, yaml ^>=0.11.4.0
|
||||||
|
, zip ^>=1.7.1
|
||||||
, zlib ^>=0.6.2.2
|
, zlib ^>=0.6.2.2
|
||||||
|
|
||||||
if flag(internal-downloader)
|
if (flag(internal-downloader) && !os(windows))
|
||||||
exposed-modules: GHCup.Download.IOStreams
|
exposed-modules: GHCup.Download.IOStreams
|
||||||
cpp-options: -DINTERNAL_DOWNLOADER
|
cpp-options: -DINTERNAL_DOWNLOADER
|
||||||
build-depends:
|
build-depends:
|
||||||
, HsOpenSSL >=0.11.4.18
|
, HsOpenSSL >=0.11.4.18
|
||||||
, http-io-streams >=0.1.2.0
|
, http-io-streams >=0.1.2.0
|
||||||
, io-streams >=1.5
|
, io-streams >=1.5.2.1
|
||||||
, terminal-progress-bar >=0.4.1
|
, terminal-progress-bar >=0.4.1
|
||||||
|
|
||||||
if flag(tar)
|
if flag(tar)
|
||||||
cpp-options: -DTAR
|
cpp-options: -DTAR
|
||||||
build-depends: tar-bytestring ^>=0.6.3.1
|
build-depends: tar
|
||||||
|
|
||||||
else
|
else
|
||||||
build-depends: libarchive ^>=3.0.0.0
|
build-depends: libarchive ^>=3.0.0.0
|
||||||
|
|
||||||
|
if os(windows)
|
||||||
|
cpp-options: -DIS_WINDOWS
|
||||||
|
other-modules: GHCup.Utils.File.Windows
|
||||||
|
build-depends:
|
||||||
|
, bzlib
|
||||||
|
, process ^>=1.6.11.0
|
||||||
|
, retry ^>=0.8.1.2
|
||||||
|
, Win32 ^>=2.10
|
||||||
|
|
||||||
|
else
|
||||||
|
other-modules: GHCup.Utils.File.Posix
|
||||||
|
build-depends:
|
||||||
|
, bz2 >=0.5.0.5 && <1.1
|
||||||
|
, hpath-posix ^>=0.13.3
|
||||||
|
, process ^>=1.6.9
|
||||||
|
, unix ^>=2.7
|
||||||
|
, unix-bytestring ^>=0.3.7.3
|
||||||
|
|
||||||
|
if (flag(tui) && !os(windows))
|
||||||
|
cpp-options: -DBRICK
|
||||||
|
build-depends: vty >=5.28.2 && <5.34
|
||||||
|
|
||||||
executable ghcup
|
executable ghcup
|
||||||
main-is: Main.hs
|
main-is: Main.hs
|
||||||
hs-source-dirs: app/ghcup
|
hs-source-dirs: app/ghcup
|
||||||
@@ -166,6 +191,7 @@ executable ghcup
|
|||||||
default-extensions:
|
default-extensions:
|
||||||
LambdaCase
|
LambdaCase
|
||||||
MultiWayIf
|
MultiWayIf
|
||||||
|
NamedFieldPuns
|
||||||
PackageImports
|
PackageImports
|
||||||
RecordWildCards
|
RecordWildCards
|
||||||
ScopedTypeVariables
|
ScopedTypeVariables
|
||||||
@@ -178,14 +204,12 @@ executable ghcup
|
|||||||
-fwarn-incomplete-record-updates -threaded
|
-fwarn-incomplete-record-updates -threaded
|
||||||
|
|
||||||
build-depends:
|
build-depends:
|
||||||
, aeson >=1.4 && <1.6
|
|
||||||
, base >=4.13 && <5
|
, base >=4.13 && <5
|
||||||
, bytestring ^>=0.10
|
, bytestring ^>=0.10
|
||||||
, containers ^>=0.6
|
, containers ^>=0.6
|
||||||
|
, filepath ^>=1.4.2.1
|
||||||
, ghcup
|
, ghcup
|
||||||
, haskus-utils-variant >=3.0 && <3.2
|
, haskus-utils-variant >=3.0 && <3.2
|
||||||
, hpath >=0.11 && <0.13
|
|
||||||
, hpath-io ^>=0.14.1
|
|
||||||
, megaparsec >=8.0.0 && <9.1
|
, megaparsec >=8.0.0 && <9.1
|
||||||
, monad-logger ^>=0.3.31
|
, monad-logger ^>=0.3.31
|
||||||
, mtl ^>=2.2
|
, mtl ^>=2.2
|
||||||
@@ -196,22 +220,26 @@ executable ghcup
|
|||||||
, safe ^>=0.3.18
|
, safe ^>=0.3.18
|
||||||
, safe-exceptions ^>=0.1
|
, safe-exceptions ^>=0.1
|
||||||
, string-interpolate >=0.2.0.0 && <0.4
|
, string-interpolate >=0.2.0.0 && <0.4
|
||||||
, template-haskell >=2.7 && <2.17
|
, template-haskell >=2.7 && <2.18
|
||||||
, text ^>=1.2.4.0
|
, text ^>=1.2.4.0
|
||||||
, uri-bytestring ^>=0.3.2.2
|
, uri-bytestring ^>=0.3.2.2
|
||||||
, utf8-string ^>=1.0
|
, utf8-string ^>=1.0
|
||||||
, versions ^>=4.0.1
|
, versions >=4.0.1 && <5.1
|
||||||
|
|
||||||
if flag(internal-downloader)
|
if flag(internal-downloader)
|
||||||
cpp-options: -DINTERNAL_DOWNLOADER
|
cpp-options: -DINTERNAL_DOWNLOADER
|
||||||
|
|
||||||
if flag(tui)
|
if (flag(tui) && !os(windows))
|
||||||
cpp-options: -DBRICK
|
cpp-options: -DBRICK
|
||||||
other-modules: BrickMain
|
other-modules: BrickMain
|
||||||
build-depends:
|
build-depends:
|
||||||
, brick >=0.5 && <0.62
|
, brick >=0.5 && <0.62
|
||||||
, vector ^>=0.12
|
, transformers ^>=0.5
|
||||||
, vty >=5.28.2 && <5.34
|
, vector ^>=0.12
|
||||||
|
, vty >=5.28.2 && <5.34
|
||||||
|
|
||||||
|
if os(windows)
|
||||||
|
cpp-options: -DIS_WINDOWS
|
||||||
|
|
||||||
if flag(tar)
|
if flag(tar)
|
||||||
cpp-options: -DTAR
|
cpp-options: -DTAR
|
||||||
@@ -225,27 +253,32 @@ executable ghcup-gen
|
|||||||
other-modules: Validate
|
other-modules: Validate
|
||||||
default-language: Haskell2010
|
default-language: Haskell2010
|
||||||
default-extensions:
|
default-extensions:
|
||||||
|
DeriveGeneric
|
||||||
LambdaCase
|
LambdaCase
|
||||||
MultiWayIf
|
MultiWayIf
|
||||||
|
NamedFieldPuns
|
||||||
PackageImports
|
PackageImports
|
||||||
|
QuasiQuotes
|
||||||
RecordWildCards
|
RecordWildCards
|
||||||
ScopedTypeVariables
|
ScopedTypeVariables
|
||||||
|
Strict
|
||||||
|
StrictData
|
||||||
TupleSections
|
TupleSections
|
||||||
|
TypeApplications
|
||||||
|
TypeFamilies
|
||||||
|
ViewPatterns
|
||||||
|
|
||||||
ghc-options:
|
ghc-options:
|
||||||
-Wall -fwarn-tabs -fwarn-incomplete-uni-patterns
|
-Wall -fwarn-tabs -fwarn-incomplete-uni-patterns
|
||||||
-fwarn-incomplete-record-updates -threaded
|
-fwarn-incomplete-record-updates -threaded
|
||||||
|
|
||||||
build-depends:
|
build-depends:
|
||||||
, aeson >=1.4 && <1.6
|
|
||||||
, aeson-pretty ^>=0.8.8
|
|
||||||
, base >=4.13 && <5
|
, base >=4.13 && <5
|
||||||
, bytestring ^>=0.10
|
, bytestring ^>=0.10
|
||||||
, containers ^>=0.6
|
, containers ^>=0.6
|
||||||
|
, filepath ^>=1.4.2.1
|
||||||
, ghcup
|
, ghcup
|
||||||
, haskus-utils-variant >=3.0 && <3.2
|
, haskus-utils-variant >=3.0 && <3.2
|
||||||
, hpath >=0.11 && <0.13
|
|
||||||
, hpath-filepath ^>=0.10.3
|
|
||||||
, monad-logger ^>=0.3.31
|
, monad-logger ^>=0.3.31
|
||||||
, mtl ^>=2.2
|
, mtl ^>=2.2
|
||||||
, optics >=0.2 && <0.5
|
, optics >=0.2 && <0.5
|
||||||
@@ -259,13 +292,12 @@ executable ghcup-gen
|
|||||||
, text ^>=1.2.4.0
|
, text ^>=1.2.4.0
|
||||||
, transformers ^>=0.5
|
, transformers ^>=0.5
|
||||||
, uri-bytestring ^>=0.3.2.2
|
, uri-bytestring ^>=0.3.2.2
|
||||||
, utf8-string ^>=1.0
|
, versions >=4.0.1 && <5.1
|
||||||
, versions ^>=4.0.1
|
|
||||||
, yaml ^>=0.11.4.0
|
, yaml ^>=0.11.4.0
|
||||||
|
|
||||||
if flag(tar)
|
if flag(tar)
|
||||||
cpp-options: -DTAR
|
cpp-options: -DTAR
|
||||||
build-depends: tar-bytestring ^>=0.6.3.1
|
build-depends: tar
|
||||||
|
|
||||||
else
|
else
|
||||||
build-depends: libarchive ^>=3.0.0.0
|
build-depends: libarchive ^>=3.0.0.0
|
||||||
@@ -298,11 +330,10 @@ test-suite ghcup-test
|
|||||||
, containers ^>=0.6
|
, containers ^>=0.6
|
||||||
, generic-arbitrary ^>=0.1.0
|
, generic-arbitrary ^>=0.1.0
|
||||||
, ghcup
|
, ghcup
|
||||||
, hpath >=0.11 && <0.13
|
, hspec ^>=2.7.10
|
||||||
, hspec ^>=2.7.4
|
, hspec-golden-aeson ^>=0.9
|
||||||
, hspec-golden-aeson >=0.7 && <0.10
|
|
||||||
, QuickCheck ^>=2.14.1
|
, QuickCheck ^>=2.14.1
|
||||||
, quickcheck-arbitrary-adt ^>=0.3.1.0
|
, quickcheck-arbitrary-adt ^>=0.3.1.0
|
||||||
, text ^>=1.2.4.0
|
, text ^>=1.2.4.0
|
||||||
, uri-bytestring ^>=0.3.2.2
|
, uri-bytestring ^>=0.3.2.2
|
||||||
, versions ^>=4.0.1
|
, versions >=4.0.1 && <5.1
|
||||||
|
|||||||
33548
golden/GHCupInfo.json
33548
golden/GHCupInfo.json
File diff suppressed because it is too large
Load Diff
1016
lib/GHCup.hs
1016
lib/GHCup.hs
File diff suppressed because it is too large
Load Diff
@@ -16,7 +16,7 @@ Copyright : (c) Julian Ospald, 2020
|
|||||||
License : LGPL-3.0
|
License : LGPL-3.0
|
||||||
Maintainer : hasufell@hasufell.de
|
Maintainer : hasufell@hasufell.de
|
||||||
Stability : experimental
|
Stability : experimental
|
||||||
Portability : POSIX
|
Portability : portable
|
||||||
|
|
||||||
Module for handling all download related functions.
|
Module for handling all download related functions.
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ import GHCup.Errors
|
|||||||
import GHCup.Types
|
import GHCup.Types
|
||||||
import GHCup.Types.JSON ( )
|
import GHCup.Types.JSON ( )
|
||||||
import GHCup.Types.Optics
|
import GHCup.Types.Optics
|
||||||
import GHCup.Utils
|
import GHCup.Utils.Dirs
|
||||||
import GHCup.Utils.File
|
import GHCup.Utils.File
|
||||||
import GHCup.Utils.Prelude
|
import GHCup.Utils.Prelude
|
||||||
import GHCup.Version
|
import GHCup.Version
|
||||||
@@ -57,7 +57,7 @@ import Data.ByteString ( ByteString )
|
|||||||
#if defined(INTERNAL_DOWNLOADER)
|
#if defined(INTERNAL_DOWNLOADER)
|
||||||
import Data.CaseInsensitive ( CI )
|
import Data.CaseInsensitive ( CI )
|
||||||
#endif
|
#endif
|
||||||
import Data.List ( find )
|
import Data.List.Extra
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Data.String.Interpolate
|
import Data.String.Interpolate
|
||||||
import Data.Time.Clock
|
import Data.Time.Clock
|
||||||
@@ -68,32 +68,29 @@ import Data.Time.Format
|
|||||||
import Data.Versions
|
import Data.Versions
|
||||||
import Data.Word8
|
import Data.Word8
|
||||||
import GHC.IO.Exception
|
import GHC.IO.Exception
|
||||||
import HPath
|
|
||||||
import HPath.IO as HIO hiding ( hideError )
|
|
||||||
import Haskus.Utils.Variant.Excepts
|
import Haskus.Utils.Variant.Excepts
|
||||||
import Optics
|
import Optics
|
||||||
import Prelude hiding ( abs
|
import Prelude hiding ( abs
|
||||||
, readFile
|
, readFile
|
||||||
, writeFile
|
, writeFile
|
||||||
)
|
)
|
||||||
|
import System.Directory
|
||||||
|
import System.Environment
|
||||||
|
import System.FilePath
|
||||||
import System.IO.Error
|
import System.IO.Error
|
||||||
import System.Posix.Env.ByteString ( getEnv )
|
|
||||||
import URI.ByteString
|
import URI.ByteString
|
||||||
|
|
||||||
import qualified Crypto.Hash.SHA256 as SHA256
|
import qualified Crypto.Hash.SHA256 as SHA256
|
||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as B
|
||||||
import qualified Data.ByteString.Base16 as B16
|
import qualified Data.ByteString.Base16 as B16
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
import qualified Data.Map.Strict as M
|
import qualified Data.Map.Strict as M
|
||||||
#if defined(INTERNAL_DOWNLOADER)
|
#if defined(INTERNAL_DOWNLOADER)
|
||||||
import qualified Data.CaseInsensitive as CI
|
import qualified Data.CaseInsensitive as CI
|
||||||
import qualified Data.Text as T
|
|
||||||
#endif
|
#endif
|
||||||
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Encoding as E
|
import qualified Data.Text.Encoding as E
|
||||||
import qualified Data.Yaml as Y
|
import qualified Data.Yaml as Y
|
||||||
import qualified System.Posix.Files.ByteString as PF
|
|
||||||
import qualified System.Posix.RawFilePath.Directory
|
|
||||||
as RD
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -115,26 +112,26 @@ getDownloadsF :: ( FromJSONKey Tool
|
|||||||
, MonadLogger m
|
, MonadLogger m
|
||||||
, MonadThrow m
|
, MonadThrow m
|
||||||
, MonadFail m
|
, MonadFail m
|
||||||
, MonadReader AppState m
|
|
||||||
)
|
)
|
||||||
=> URLSource
|
=> Settings
|
||||||
|
-> Dirs
|
||||||
-> Excepts
|
-> Excepts
|
||||||
'[JSONError , DownloadFailed , FileDoesNotExistError]
|
'[JSONError , DownloadFailed , FileDoesNotExistError]
|
||||||
m
|
m
|
||||||
GHCupInfo
|
GHCupInfo
|
||||||
getDownloadsF urlSource = do
|
getDownloadsF settings@Settings{ urlSource } dirs = do
|
||||||
case urlSource of
|
case urlSource of
|
||||||
GHCupURL -> liftE getBase
|
GHCupURL -> liftE $ getBase dirs settings
|
||||||
(OwnSource url) -> do
|
(OwnSource url) -> do
|
||||||
bs <- reThrowAll DownloadFailed $ downloadBS url
|
bs <- reThrowAll DownloadFailed $ downloadBS (downloader settings) url
|
||||||
lE' JSONDecodeError $ first show $ Y.decodeEither' (L.toStrict bs)
|
lE' JSONDecodeError $ first show $ Y.decodeEither' (L.toStrict bs)
|
||||||
(OwnSpec av) -> pure av
|
(OwnSpec av) -> pure av
|
||||||
(AddSource (Left ext)) -> do
|
(AddSource (Left ext)) -> do
|
||||||
base <- liftE getBase
|
base <- liftE $ getBase dirs settings
|
||||||
pure (mergeGhcupInfo base ext)
|
pure (mergeGhcupInfo base ext)
|
||||||
(AddSource (Right uri)) -> do
|
(AddSource (Right uri)) -> do
|
||||||
base <- liftE getBase
|
base <- liftE $ getBase dirs settings
|
||||||
bsExt <- reThrowAll DownloadFailed $ downloadBS uri
|
bsExt <- reThrowAll DownloadFailed $ downloadBS (downloader settings) uri
|
||||||
ext <- lE' JSONDecodeError $ first show $ Y.decodeEither' (L.toStrict bsExt)
|
ext <- lE' JSONDecodeError $ first show $ Y.decodeEither' (L.toStrict bsExt)
|
||||||
pure (mergeGhcupInfo base ext)
|
pure (mergeGhcupInfo base ext)
|
||||||
|
|
||||||
@@ -143,36 +140,39 @@ getDownloadsF urlSource = do
|
|||||||
mergeGhcupInfo :: GHCupInfo -- ^ base to merge with
|
mergeGhcupInfo :: GHCupInfo -- ^ base to merge with
|
||||||
-> GHCupInfo -- ^ extension overwriting the base
|
-> GHCupInfo -- ^ extension overwriting the base
|
||||||
-> GHCupInfo
|
-> GHCupInfo
|
||||||
mergeGhcupInfo (GHCupInfo tr base) (GHCupInfo _ ext) =
|
mergeGhcupInfo (GHCupInfo tr base base2) (GHCupInfo _ ext ext2) =
|
||||||
let new = M.mapWithKey (\k a -> case M.lookup k ext of
|
let newDownloads = M.mapWithKey (\k a -> case M.lookup k ext of
|
||||||
Just a' -> M.union a' a
|
Just a' -> M.union a' a
|
||||||
Nothing -> a
|
Nothing -> a
|
||||||
) base
|
) base
|
||||||
in GHCupInfo tr new
|
newGlobalTools = M.union base2 ext2
|
||||||
|
in GHCupInfo tr newDownloads newGlobalTools
|
||||||
|
|
||||||
|
|
||||||
readFromCache :: (MonadIO m, MonadCatch m, MonadLogger m, MonadReader AppState m)
|
readFromCache :: (MonadIO m, MonadCatch m, MonadLogger m)
|
||||||
=> Excepts '[JSONError, FileDoesNotExistError] m GHCupInfo
|
=> Dirs
|
||||||
readFromCache = do
|
-> Excepts '[JSONError, FileDoesNotExistError] m GHCupInfo
|
||||||
AppState {dirs = Dirs {..}} <- lift ask
|
readFromCache Dirs {..} = do
|
||||||
lift $ $(logWarn)
|
lift $ $(logWarn)
|
||||||
[i|Could not get download info, trying cached version (this may not be recent!)|]
|
[i|Could not get download info, trying cached version (this may not be recent!)|]
|
||||||
let path = view pathL' ghcupURL
|
let path = view pathL' ghcupURL
|
||||||
yaml_file <- (cacheDir </>) <$> urlBaseName path
|
let yaml_file = cacheDir </> (T.unpack . decUTF8Safe . urlBaseName $ path)
|
||||||
bs <-
|
bs <-
|
||||||
handleIO' NoSuchThing
|
handleIO' NoSuchThing
|
||||||
(\_ -> throwE $ FileDoesNotExistError (toFilePath yaml_file))
|
(\_ -> throwE $ FileDoesNotExistError yaml_file)
|
||||||
$ liftIO
|
$ liftIO
|
||||||
$ readFile yaml_file
|
$ L.readFile yaml_file
|
||||||
lE' JSONDecodeError $ first show $ Y.decodeEither' (L.toStrict bs)
|
lE' JSONDecodeError $ first show $ Y.decodeEither' (L.toStrict bs)
|
||||||
|
|
||||||
|
|
||||||
getBase :: (MonadFail m, MonadIO m, MonadCatch m, MonadLogger m, MonadReader AppState m)
|
getBase :: (MonadFail m, MonadIO m, MonadCatch m, MonadLogger m)
|
||||||
=> Excepts '[JSONError , FileDoesNotExistError] m GHCupInfo
|
=> Dirs
|
||||||
getBase =
|
-> Settings
|
||||||
handleIO (\_ -> readFromCache)
|
-> Excepts '[JSONError , FileDoesNotExistError] m GHCupInfo
|
||||||
|
getBase dirs@Dirs{..} Settings{ downloader } =
|
||||||
|
handleIO (\_ -> readFromCache dirs)
|
||||||
$ catchE @_ @'[JSONError, FileDoesNotExistError]
|
$ catchE @_ @'[JSONError, FileDoesNotExistError]
|
||||||
(\(DownloadFailed _) -> readFromCache)
|
(\(DownloadFailed _) -> readFromCache dirs)
|
||||||
(reThrowAll @_ @_ @'[JSONError, DownloadFailed] DownloadFailed (smartDl ghcupURL)
|
(reThrowAll @_ @_ @'[JSONError, DownloadFailed] DownloadFailed (smartDl ghcupURL)
|
||||||
>>= (liftE . lE' @_ @_ @'[JSONError] JSONDecodeError . first show . Y.decodeEither' . L.toStrict))
|
>>= (liftE . lE' @_ @_ @'[JSONError] JSONDecodeError . first show . Y.decodeEither' . L.toStrict))
|
||||||
where
|
where
|
||||||
@@ -190,7 +190,6 @@ getBase =
|
|||||||
, MonadIO m1
|
, MonadIO m1
|
||||||
, MonadFail m1
|
, MonadFail m1
|
||||||
, MonadLogger m1
|
, MonadLogger m1
|
||||||
, MonadReader AppState m1
|
|
||||||
)
|
)
|
||||||
=> URI
|
=> URI
|
||||||
-> Excepts
|
-> Excepts
|
||||||
@@ -205,33 +204,29 @@ getBase =
|
|||||||
m1
|
m1
|
||||||
L.ByteString
|
L.ByteString
|
||||||
smartDl uri' = do
|
smartDl uri' = do
|
||||||
AppState {dirs = Dirs {..}} <- lift ask
|
|
||||||
let path = view pathL' uri'
|
let path = view pathL' uri'
|
||||||
json_file <- (cacheDir </>) <$> urlBaseName path
|
let json_file = cacheDir </> (T.unpack . decUTF8Safe . urlBaseName $ path)
|
||||||
e <- liftIO $ doesFileExist json_file
|
e <- liftIO $ doesFileExist json_file
|
||||||
if e
|
if e
|
||||||
then do
|
then do
|
||||||
accessTime <-
|
accessTime <- liftIO $ getAccessTime json_file
|
||||||
PF.accessTimeHiRes
|
currentTime <- liftIO getCurrentTime
|
||||||
<$> liftIO (PF.getFileStatus (toFilePath json_file))
|
|
||||||
currentTime <- liftIO getPOSIXTime
|
|
||||||
|
|
||||||
-- access time won't work on most linuxes, but we can try regardless
|
-- access time won't work on most linuxes, but we can try regardless
|
||||||
if (currentTime - accessTime) > 300
|
if (utcTimeToPOSIXSeconds currentTime - utcTimeToPOSIXSeconds accessTime) > 300
|
||||||
then do -- no access in last 5 minutes, re-check upstream mod time
|
then do -- no access in last 5 minutes, re-check upstream mod time
|
||||||
getModTime >>= \case
|
getModTime >>= \case
|
||||||
Just modTime -> do
|
Just modTime -> do
|
||||||
fileMod <- liftIO $ getModificationTime json_file
|
fileMod <- liftIO $ getModificationTime json_file
|
||||||
if modTime > fileMod
|
if modTime > fileMod
|
||||||
then dlWithMod modTime json_file
|
then dlWithMod modTime json_file
|
||||||
else liftIO $ readFile json_file
|
else liftIO $ L.readFile json_file
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
lift $ $(logDebug) [i|Unable to get/parse Last-Modified header|]
|
lift $ $(logDebug) [i|Unable to get/parse Last-Modified header|]
|
||||||
dlWithoutMod json_file
|
dlWithoutMod json_file
|
||||||
else -- access in less than 5 minutes, re-use file
|
else -- access in less than 5 minutes, re-use file
|
||||||
liftIO $ readFile json_file
|
liftIO $ L.readFile json_file
|
||||||
else do
|
else do
|
||||||
liftIO $ createDirRecursive' cacheDir
|
|
||||||
getModTime >>= \case
|
getModTime >>= \case
|
||||||
Just modTime -> dlWithMod modTime json_file
|
Just modTime -> dlWithMod modTime json_file
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
@@ -242,14 +237,14 @@ getBase =
|
|||||||
|
|
||||||
where
|
where
|
||||||
dlWithMod modTime json_file = do
|
dlWithMod modTime json_file = do
|
||||||
bs <- liftE $ downloadBS uri'
|
bs <- liftE $ downloadBS downloader uri'
|
||||||
liftIO $ writeFileWithModTime modTime json_file bs
|
liftIO $ writeFileWithModTime modTime json_file bs
|
||||||
pure bs
|
pure bs
|
||||||
dlWithoutMod json_file = do
|
dlWithoutMod json_file = do
|
||||||
bs <- liftE $ downloadBS uri'
|
bs <- liftE $ downloadBS downloader uri'
|
||||||
liftIO $ hideError doesNotExistErrorType $ deleteFile json_file
|
liftIO $ hideError doesNotExistErrorType $ rmFile json_file
|
||||||
liftIO $ writeFileL json_file (Just newFilePerms) bs
|
liftIO $ L.writeFile json_file bs
|
||||||
liftIO $ setModificationTime json_file (fromIntegral @Int 0)
|
liftIO $ setModificationTime json_file (posixSecondsToUTCTime (fromIntegral @Int 0))
|
||||||
pure bs
|
pure bs
|
||||||
|
|
||||||
|
|
||||||
@@ -278,11 +273,10 @@ getBase =
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
writeFileWithModTime :: UTCTime -> Path Abs -> L.ByteString -> IO ()
|
writeFileWithModTime :: UTCTime -> FilePath -> L.ByteString -> IO ()
|
||||||
writeFileWithModTime utctime path content = do
|
writeFileWithModTime utctime path content = do
|
||||||
let mod_time = utcTimeToPOSIXSeconds utctime
|
L.writeFile path content
|
||||||
writeFileL path (Just newFilePerms) content
|
setModificationTime path utctime
|
||||||
setModificationTimeHiRes path mod_time
|
|
||||||
|
|
||||||
|
|
||||||
getDownloadInfo :: Tool
|
getDownloadInfo :: Tool
|
||||||
@@ -328,16 +322,16 @@ getDownloadInfo t v (PlatformRequest a p mv) dls = maybe
|
|||||||
--
|
--
|
||||||
-- The file must not exist.
|
-- The file must not exist.
|
||||||
download :: ( MonadMask m
|
download :: ( MonadMask m
|
||||||
, MonadReader AppState m
|
|
||||||
, MonadThrow m
|
, MonadThrow m
|
||||||
, MonadLogger m
|
, MonadLogger m
|
||||||
, MonadIO m
|
, MonadIO m
|
||||||
)
|
)
|
||||||
=> DownloadInfo
|
=> Settings
|
||||||
-> Path Abs -- ^ destination dir
|
-> DownloadInfo
|
||||||
-> Maybe (Path Rel) -- ^ optional filename
|
-> FilePath -- ^ destination dir
|
||||||
-> Excepts '[DigestError , DownloadFailed] m (Path Abs)
|
-> Maybe FilePath -- ^ optional filename
|
||||||
download dli dest mfn
|
-> Excepts '[DigestError , DownloadFailed] m FilePath
|
||||||
|
download settings@Settings{ downloader } dli dest mfn
|
||||||
| scheme == "https" = dl
|
| scheme == "https" = dl
|
||||||
| scheme == "http" = dl
|
| scheme == "http" = dl
|
||||||
| scheme == "file" = cp
|
| scheme == "file" = cp
|
||||||
@@ -348,9 +342,9 @@ download dli dest mfn
|
|||||||
cp = do
|
cp = do
|
||||||
-- destination dir must exist
|
-- destination dir must exist
|
||||||
liftIO $ createDirRecursive' dest
|
liftIO $ createDirRecursive' dest
|
||||||
destFile <- getDestFile
|
let destFile = getDestFile
|
||||||
fromFile <- parseAbs path
|
let fromFile = T.unpack . decUTF8Safe $ path
|
||||||
liftIO $ copyFile fromFile destFile Strict
|
liftIO $ copyFile fromFile destFile
|
||||||
pure destFile
|
pure destFile
|
||||||
dl = do
|
dl = do
|
||||||
let uri' = decUTF8Safe (serializeURIRef' (view dlUri dli))
|
let uri' = decUTF8Safe (serializeURIRef' (view dlUri dli))
|
||||||
@@ -358,37 +352,37 @@ download dli dest mfn
|
|||||||
|
|
||||||
-- destination dir must exist
|
-- destination dir must exist
|
||||||
liftIO $ createDirRecursive' dest
|
liftIO $ createDirRecursive' dest
|
||||||
destFile <- getDestFile
|
let destFile = getDestFile
|
||||||
|
|
||||||
-- download
|
-- download
|
||||||
flip onException
|
flip onException
|
||||||
(liftIO $ hideError doesNotExistErrorType $ deleteFile destFile)
|
(liftIO $ hideError doesNotExistErrorType $ rmFile destFile)
|
||||||
$ catchAllE @_ @'[ProcessError, DownloadFailed, UnsupportedScheme]
|
$ catchAllE @_ @'[ProcessError, DownloadFailed, UnsupportedScheme]
|
||||||
(\e ->
|
(\e ->
|
||||||
liftIO (hideError doesNotExistErrorType $ deleteFile destFile)
|
liftIO (hideError doesNotExistErrorType $ rmFile destFile)
|
||||||
>> (throwE . DownloadFailed $ e)
|
>> (throwE . DownloadFailed $ e)
|
||||||
) $ do
|
) $ do
|
||||||
lift getDownloader >>= \case
|
case downloader of
|
||||||
Curl -> do
|
Curl -> do
|
||||||
o' <- liftIO getCurlOpts
|
o' <- liftIO getCurlOpts
|
||||||
liftE $ lEM @_ @'[ProcessError] $ liftIO $ exec "curl" True
|
liftE $ lEM @_ @'[ProcessError] $ exec "curl"
|
||||||
(o' ++ ["-fL", "-o", toFilePath destFile, serializeURIRef' $ view dlUri dli]) Nothing Nothing
|
(o' ++ ["-fL", "-o", destFile, (T.unpack . decUTF8Safe) $ serializeURIRef' $ view dlUri dli]) Nothing Nothing
|
||||||
Wget -> do
|
Wget -> do
|
||||||
o' <- liftIO getWgetOpts
|
o' <- liftIO getWgetOpts
|
||||||
liftE $ lEM @_ @'[ProcessError] $ liftIO $ exec "wget" True
|
liftE $ lEM @_ @'[ProcessError] $ exec "wget"
|
||||||
(o' ++ ["-O", toFilePath destFile , serializeURIRef' $ view dlUri dli]) Nothing Nothing
|
(o' ++ ["-O", destFile , (T.unpack . decUTF8Safe) $ serializeURIRef' $ view dlUri dli]) Nothing Nothing
|
||||||
#if defined(INTERNAL_DOWNLOADER)
|
#if defined(INTERNAL_DOWNLOADER)
|
||||||
Internal -> do
|
Internal -> do
|
||||||
(https, host, fullPath, port) <- liftE $ uriToQuadruple (view dlUri dli)
|
(https, host, fullPath, port) <- liftE $ uriToQuadruple (view dlUri dli)
|
||||||
liftE $ downloadToFile https host fullPath port destFile
|
liftE $ downloadToFile https host fullPath port destFile
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
liftE $ checkDigest dli destFile
|
liftE $ checkDigest settings dli destFile
|
||||||
pure destFile
|
pure destFile
|
||||||
|
|
||||||
-- Manage to find a file we can write the body into.
|
-- Manage to find a file we can write the body into.
|
||||||
getDestFile :: MonadThrow m => m (Path Abs)
|
getDestFile :: FilePath
|
||||||
getDestFile = maybe (urlBaseName path <&> (dest </>)) (pure . (dest </>)) mfn
|
getDestFile = maybe (dest </> T.unpack (decUTF8Safe (urlBaseName path))) (dest </>) mfn
|
||||||
|
|
||||||
path = view (dlUri % pathL') dli
|
path = view (dlUri % pathL') dli
|
||||||
|
|
||||||
@@ -401,27 +395,40 @@ downloadCached :: ( MonadMask m
|
|||||||
, MonadLogger m
|
, MonadLogger m
|
||||||
, MonadIO m
|
, MonadIO m
|
||||||
, MonadUnliftIO m
|
, MonadUnliftIO m
|
||||||
, MonadReader AppState m
|
|
||||||
)
|
)
|
||||||
=> DownloadInfo
|
=> Settings
|
||||||
-> Maybe (Path Rel) -- ^ optional filename
|
-> Dirs
|
||||||
-> Excepts '[DigestError , DownloadFailed] m (Path Abs)
|
-> DownloadInfo
|
||||||
downloadCached dli mfn = do
|
-> Maybe FilePath -- ^ optional filename
|
||||||
cache <- lift getCache
|
-> Excepts '[DigestError , DownloadFailed] m FilePath
|
||||||
|
downloadCached settings@Settings{ cache } dirs dli mfn = do
|
||||||
case cache of
|
case cache of
|
||||||
True -> do
|
True -> downloadCached' settings dirs dli mfn
|
||||||
AppState {dirs = Dirs {..}} <- lift ask
|
|
||||||
fn <- maybe (urlBaseName $ view (dlUri % pathL') dli) pure mfn
|
|
||||||
let cachfile = cacheDir </> fn
|
|
||||||
fileExists <- liftIO $ doesFileExist cachfile
|
|
||||||
if
|
|
||||||
| fileExists -> do
|
|
||||||
liftE $ checkDigest dli cachfile
|
|
||||||
pure cachfile
|
|
||||||
| otherwise -> liftE $ download dli cacheDir mfn
|
|
||||||
False -> do
|
False -> do
|
||||||
tmp <- lift withGHCupTmpDir
|
tmp <- lift withGHCupTmpDir
|
||||||
liftE $ download dli tmp mfn
|
liftE $ download settings dli tmp mfn
|
||||||
|
|
||||||
|
|
||||||
|
downloadCached' :: ( MonadMask m
|
||||||
|
, MonadThrow m
|
||||||
|
, MonadLogger m
|
||||||
|
, MonadIO m
|
||||||
|
, MonadUnliftIO m
|
||||||
|
)
|
||||||
|
=> Settings
|
||||||
|
-> Dirs
|
||||||
|
-> DownloadInfo
|
||||||
|
-> Maybe FilePath -- ^ optional filename
|
||||||
|
-> Excepts '[DigestError , DownloadFailed] m FilePath
|
||||||
|
downloadCached' settings Dirs{..} dli mfn = do
|
||||||
|
let fn = fromMaybe ((T.unpack . decUTF8Safe) $ urlBaseName $ view (dlUri % pathL') dli) mfn
|
||||||
|
let cachfile = cacheDir </> fn
|
||||||
|
fileExists <- liftIO $ doesFileExist cachfile
|
||||||
|
if
|
||||||
|
| fileExists -> do
|
||||||
|
liftE $ checkDigest settings dli cachfile
|
||||||
|
pure cachfile
|
||||||
|
| otherwise -> liftE $ download settings dli cacheDir mfn
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -434,8 +441,9 @@ downloadCached dli mfn = do
|
|||||||
|
|
||||||
|
|
||||||
-- | This is used for downloading the JSON.
|
-- | This is used for downloading the JSON.
|
||||||
downloadBS :: (MonadReader AppState m, MonadCatch m, MonadIO m, MonadLogger m)
|
downloadBS :: (MonadCatch m, MonadIO m, MonadLogger m)
|
||||||
=> URI
|
=> Downloader
|
||||||
|
-> URI
|
||||||
-> Excepts
|
-> Excepts
|
||||||
'[ FileDoesNotExistError
|
'[ FileDoesNotExistError
|
||||||
, HTTPStatusError
|
, HTTPStatusError
|
||||||
@@ -447,14 +455,14 @@ downloadBS :: (MonadReader AppState m, MonadCatch m, MonadIO m, MonadLogger m)
|
|||||||
]
|
]
|
||||||
m
|
m
|
||||||
L.ByteString
|
L.ByteString
|
||||||
downloadBS uri'
|
downloadBS downloader uri'
|
||||||
| scheme == "https"
|
| scheme == "https"
|
||||||
= dl True
|
= dl True
|
||||||
| scheme == "http"
|
| scheme == "http"
|
||||||
= dl False
|
= dl False
|
||||||
| scheme == "file"
|
| scheme == "file"
|
||||||
= liftIOException doesNotExistErrorType (FileDoesNotExistError path)
|
= liftIOException doesNotExistErrorType (FileDoesNotExistError $ T.unpack $ decUTF8Safe path)
|
||||||
(liftIO $ RD.readFile path)
|
(liftIO $ L.readFile (T.unpack $ decUTF8Safe path))
|
||||||
| otherwise
|
| otherwise
|
||||||
= throwE UnsupportedScheme
|
= throwE UnsupportedScheme
|
||||||
|
|
||||||
@@ -467,23 +475,23 @@ downloadBS uri'
|
|||||||
dl _ = do
|
dl _ = do
|
||||||
#endif
|
#endif
|
||||||
lift $ $(logDebug) [i|downloading: #{serializeURIRef' uri'}|]
|
lift $ $(logDebug) [i|downloading: #{serializeURIRef' uri'}|]
|
||||||
lift getDownloader >>= \case
|
case downloader of
|
||||||
Curl -> do
|
Curl -> do
|
||||||
o' <- liftIO getCurlOpts
|
o' <- liftIO getCurlOpts
|
||||||
let exe = [rel|curl|]
|
let exe = "curl"
|
||||||
args = o' ++ ["-sSfL", serializeURIRef' uri']
|
args = o' ++ ["-sSfL", T.unpack $ decUTF8Safe $ serializeURIRef' uri']
|
||||||
liftIO (executeOut exe args Nothing) >>= \case
|
lift (executeOut exe args Nothing) >>= \case
|
||||||
CapturedProcess ExitSuccess stdout _ -> do
|
CapturedProcess ExitSuccess stdout _ -> do
|
||||||
pure $ L.fromStrict stdout
|
pure stdout
|
||||||
CapturedProcess (ExitFailure i') _ _ -> throwE $ NonZeroExit i' (toFilePath exe) args
|
CapturedProcess (ExitFailure i') _ _ -> throwE $ NonZeroExit i' exe args
|
||||||
Wget -> do
|
Wget -> do
|
||||||
o' <- liftIO getWgetOpts
|
o' <- liftIO getWgetOpts
|
||||||
let exe = [rel|wget|]
|
let exe = "wget"
|
||||||
args = o' ++ ["-qO-", serializeURIRef' uri']
|
args = o' ++ ["-qO-", T.unpack $ decUTF8Safe $ serializeURIRef' uri']
|
||||||
liftIO (executeOut exe args Nothing) >>= \case
|
lift (executeOut exe args Nothing) >>= \case
|
||||||
CapturedProcess ExitSuccess stdout _ -> do
|
CapturedProcess ExitSuccess stdout _ -> do
|
||||||
pure $ L.fromStrict stdout
|
pure stdout
|
||||||
CapturedProcess (ExitFailure i') _ _ -> throwE $ NonZeroExit i' (toFilePath exe) args
|
CapturedProcess (ExitFailure i') _ _ -> throwE $ NonZeroExit i' exe args
|
||||||
#if defined(INTERNAL_DOWNLOADER)
|
#if defined(INTERNAL_DOWNLOADER)
|
||||||
Internal -> do
|
Internal -> do
|
||||||
(_, host', fullPath', port') <- liftE $ uriToQuadruple uri'
|
(_, host', fullPath', port') <- liftE $ uriToQuadruple uri'
|
||||||
@@ -491,33 +499,39 @@ downloadBS uri'
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
checkDigest :: (MonadIO m, MonadThrow m, MonadLogger m, MonadReader AppState m)
|
checkDigest :: (MonadIO m, MonadThrow m, MonadLogger m)
|
||||||
=> DownloadInfo
|
=> Settings
|
||||||
-> Path Abs
|
-> DownloadInfo
|
||||||
|
-> FilePath
|
||||||
-> Excepts '[DigestError] m ()
|
-> Excepts '[DigestError] m ()
|
||||||
checkDigest dli file = do
|
checkDigest Settings{ noVerify } dli file = do
|
||||||
verify <- lift ask <&> (not . noVerify . settings)
|
let verify = not noVerify
|
||||||
when verify $ do
|
when verify $ do
|
||||||
p' <- toFilePath <$> basename file
|
let p' = takeFileName file
|
||||||
lift $ $(logInfo) [i|verifying digest of: #{p'}|]
|
lift $ $(logInfo) [i|verifying digest of: #{p'}|]
|
||||||
c <- liftIO $ readFile file
|
c <- liftIO $ L.readFile file
|
||||||
cDigest <- throwEither . E.decodeUtf8' . B16.encode . SHA256.hashlazy $ c
|
cDigest <- throwEither . E.decodeUtf8' . B16.encode . SHA256.hashlazy $ c
|
||||||
let eDigest = view dlHash dli
|
let eDigest = view dlHash dli
|
||||||
when ((cDigest /= eDigest) && verify) $ throwE (DigestError cDigest eDigest)
|
when ((cDigest /= eDigest) && verify) $ throwE (DigestError cDigest eDigest)
|
||||||
|
|
||||||
|
|
||||||
-- | Get additional curl args from env. This is an undocumented option.
|
-- | Get additional curl args from env. This is an undocumented option.
|
||||||
getCurlOpts :: IO [ByteString]
|
getCurlOpts :: IO [String]
|
||||||
getCurlOpts =
|
getCurlOpts =
|
||||||
getEnv "GHCUP_CURL_OPTS" >>= \case
|
lookupEnv "GHCUP_CURL_OPTS" >>= \case
|
||||||
Just r -> pure $ BS.split _space r
|
Just r -> pure $ splitOn " " r
|
||||||
Nothing -> pure []
|
Nothing -> pure []
|
||||||
|
|
||||||
|
|
||||||
-- | Get additional wget args from env. This is an undocumented option.
|
-- | Get additional wget args from env. This is an undocumented option.
|
||||||
getWgetOpts :: IO [ByteString]
|
getWgetOpts :: IO [String]
|
||||||
getWgetOpts =
|
getWgetOpts =
|
||||||
getEnv "GHCUP_WGET_OPTS" >>= \case
|
lookupEnv "GHCUP_WGET_OPTS" >>= \case
|
||||||
Just r -> pure $ BS.split _space r
|
Just r -> pure $ splitOn " " r
|
||||||
Nothing -> pure []
|
Nothing -> pure []
|
||||||
|
|
||||||
|
|
||||||
|
urlBaseName :: ByteString -- ^ the url path (without scheme and host)
|
||||||
|
-> ByteString
|
||||||
|
urlBaseName = snd . B.breakEnd (== _slash) . urlDecode False
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ import Data.CaseInsensitive ( CI )
|
|||||||
import Data.IORef
|
import Data.IORef
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Data.Text.Read
|
import Data.Text.Read
|
||||||
import HPath
|
|
||||||
import HPath.IO as HIO
|
|
||||||
import Haskus.Utils.Variant.Excepts
|
import Haskus.Utils.Variant.Excepts
|
||||||
import Network.Http.Client hiding ( URL )
|
import Network.Http.Client hiding ( URL )
|
||||||
import Optics
|
import Optics
|
||||||
@@ -33,11 +31,8 @@ import Prelude hiding ( abs
|
|||||||
, readFile
|
, readFile
|
||||||
, writeFile
|
, writeFile
|
||||||
)
|
)
|
||||||
import "unix" System.Posix.IO.ByteString
|
|
||||||
hiding ( fdWrite )
|
|
||||||
import "unix-bytestring" System.Posix.IO.ByteString
|
|
||||||
( fdWrite )
|
|
||||||
import System.ProgressBar
|
import System.ProgressBar
|
||||||
|
import System.IO
|
||||||
import URI.ByteString
|
import URI.ByteString
|
||||||
|
|
||||||
import qualified Data.ByteString as BS
|
import qualified Data.ByteString as BS
|
||||||
@@ -81,12 +76,12 @@ downloadToFile :: (MonadMask m, MonadIO m)
|
|||||||
-> ByteString -- ^ host (e.g. "www.example.com")
|
-> ByteString -- ^ host (e.g. "www.example.com")
|
||||||
-> ByteString -- ^ path (e.g. "/my/file") including query
|
-> ByteString -- ^ path (e.g. "/my/file") including query
|
||||||
-> Maybe Int -- ^ optional port (e.g. 3000)
|
-> Maybe Int -- ^ optional port (e.g. 3000)
|
||||||
-> Path Abs -- ^ destination file to create and write to
|
-> FilePath -- ^ destination file to create and write to
|
||||||
-> Excepts '[DownloadFailed] m ()
|
-> Excepts '[DownloadFailed] m ()
|
||||||
downloadToFile https host fullPath port destFile = do
|
downloadToFile https host fullPath port destFile = do
|
||||||
fd <- liftIO $ createRegularFileFd newFilePerms destFile
|
fd <- liftIO $ openFile destFile WriteMode
|
||||||
let stepper = fdWrite fd
|
let stepper = BS.hPut fd
|
||||||
flip finally (liftIO $ closeFd fd)
|
flip finally (liftIO $ hClose fd)
|
||||||
$ reThrowAll DownloadFailed $ downloadInternal True https host fullPath port stepper
|
$ reThrowAll DownloadFailed $ downloadInternal True https host fullPath port stepper
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,12 +15,11 @@ Copyright : (c) Julian Ospald, 2020
|
|||||||
License : LGPL-3.0
|
License : LGPL-3.0
|
||||||
Maintainer : hasufell@hasufell.de
|
Maintainer : hasufell@hasufell.de
|
||||||
Stability : experimental
|
Stability : experimental
|
||||||
Portability : POSIX
|
Portability : portable
|
||||||
-}
|
-}
|
||||||
module GHCup.Errors where
|
module GHCup.Errors where
|
||||||
|
|
||||||
import GHCup.Types
|
import GHCup.Types
|
||||||
import GHCup.Utils.Prelude
|
|
||||||
|
|
||||||
#if !defined(TAR)
|
#if !defined(TAR)
|
||||||
import Codec.Archive
|
import Codec.Archive
|
||||||
@@ -28,11 +27,9 @@ import Codec.Archive
|
|||||||
import qualified Codec.Archive.Tar as Tar
|
import qualified Codec.Archive.Tar as Tar
|
||||||
#endif
|
#endif
|
||||||
import Control.Exception.Safe
|
import Control.Exception.Safe
|
||||||
import Data.ByteString ( ByteString )
|
|
||||||
import Data.String.Interpolate
|
import Data.String.Interpolate
|
||||||
import Data.Text ( Text )
|
import Data.Text ( Text )
|
||||||
import Data.Versions
|
import Data.Versions
|
||||||
import HPath
|
|
||||||
import Haskus.Utils.Variant
|
import Haskus.Utils.Variant
|
||||||
import Text.PrettyPrint
|
import Text.PrettyPrint
|
||||||
import Text.PrettyPrint.HughesPJClass
|
import Text.PrettyPrint.HughesPJClass
|
||||||
@@ -86,12 +83,12 @@ instance Pretty DistroNotFound where
|
|||||||
text "Unable to figure out the distribution of the host."
|
text "Unable to figure out the distribution of the host."
|
||||||
|
|
||||||
-- | The archive format is unknown. We don't know how to extract it.
|
-- | The archive format is unknown. We don't know how to extract it.
|
||||||
data UnknownArchive = UnknownArchive ByteString
|
data UnknownArchive = UnknownArchive FilePath
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
instance Pretty UnknownArchive where
|
instance Pretty UnknownArchive where
|
||||||
pPrint (UnknownArchive file) =
|
pPrint (UnknownArchive file) =
|
||||||
text [i|The archive format is unknown. We don't know how to extract the file "#{decUTF8Safe file}"|]
|
text [i|The archive format is unknown. We don't know how to extract the file "#{file}"|]
|
||||||
|
|
||||||
-- | The scheme is not supported (such as ftp).
|
-- | The scheme is not supported (such as ftp).
|
||||||
data UnsupportedScheme = UnsupportedScheme
|
data UnsupportedScheme = UnsupportedScheme
|
||||||
@@ -143,12 +140,12 @@ instance Pretty NotInstalled where
|
|||||||
text [i|The version "#{prettyShow ver}" of the tool "#{tool}" is not installed.|]
|
text [i|The version "#{prettyShow ver}" of the tool "#{tool}" is not installed.|]
|
||||||
|
|
||||||
-- | An executable was expected to be in PATH, but was not found.
|
-- | An executable was expected to be in PATH, but was not found.
|
||||||
data NotFoundInPATH = NotFoundInPATH (Path Rel)
|
data NotFoundInPATH = NotFoundInPATH FilePath
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
instance Pretty NotFoundInPATH where
|
instance Pretty NotFoundInPATH where
|
||||||
pPrint (NotFoundInPATH exe) =
|
pPrint (NotFoundInPATH exe) =
|
||||||
text [i|The exe "#{decUTF8Safe . toFilePath $ exe}" was not found in PATH.|]
|
text [i|The exe "#{exe}" was not found in PATH.|]
|
||||||
|
|
||||||
-- | JSON decoding failed.
|
-- | JSON decoding failed.
|
||||||
data JSONError = JSONDecodeError String
|
data JSONError = JSONDecodeError String
|
||||||
@@ -160,12 +157,12 @@ instance Pretty JSONError where
|
|||||||
|
|
||||||
-- | A file that is supposed to exist does not exist
|
-- | A file that is supposed to exist does not exist
|
||||||
-- (e.g. when we use file scheme to "download" something).
|
-- (e.g. when we use file scheme to "download" something).
|
||||||
data FileDoesNotExistError = FileDoesNotExistError ByteString
|
data FileDoesNotExistError = FileDoesNotExistError FilePath
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
instance Pretty FileDoesNotExistError where
|
instance Pretty FileDoesNotExistError where
|
||||||
pPrint (FileDoesNotExistError file) =
|
pPrint (FileDoesNotExistError file) =
|
||||||
text [i|File "#{decUTF8Safe file}" does not exist.|]
|
text [i|File "#{file}" does not exist.|]
|
||||||
|
|
||||||
data TarDirDoesNotExist = TarDirDoesNotExist TarDir
|
data TarDirDoesNotExist = TarDirDoesNotExist TarDir
|
||||||
deriving Show
|
deriving Show
|
||||||
@@ -252,11 +249,11 @@ deriving instance Show DownloadFailed
|
|||||||
|
|
||||||
|
|
||||||
-- | A build failed.
|
-- | A build failed.
|
||||||
data BuildFailed = forall es . Show (V es) => BuildFailed (Path Abs) (V es)
|
data BuildFailed = forall es . Show (V es) => BuildFailed FilePath (V es)
|
||||||
|
|
||||||
instance Pretty BuildFailed where
|
instance Pretty BuildFailed where
|
||||||
pPrint (BuildFailed path reason) =
|
pPrint (BuildFailed path reason) =
|
||||||
text [i|BuildFailed failed in dir "#{decUTF8Safe . toFilePath $ path}": #{reason}|]
|
text [i|BuildFailed failed in dir "#{path}": #{reason}|]
|
||||||
|
|
||||||
deriving instance Show BuildFailed
|
deriving instance Show BuildFailed
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ Copyright : (c) Julian Ospald, 2020
|
|||||||
License : LGPL-3.0
|
License : LGPL-3.0
|
||||||
Maintainer : hasufell@hasufell.de
|
Maintainer : hasufell@hasufell.de
|
||||||
Stability : experimental
|
Stability : experimental
|
||||||
Portability : POSIX
|
Portability : portable
|
||||||
-}
|
-}
|
||||||
module GHCup.Platform where
|
module GHCup.Platform where
|
||||||
|
|
||||||
@@ -36,18 +36,21 @@ import Data.Maybe
|
|||||||
import Data.String.Interpolate
|
import Data.String.Interpolate
|
||||||
import Data.Text ( Text )
|
import Data.Text ( Text )
|
||||||
import Data.Versions
|
import Data.Versions
|
||||||
import HPath
|
|
||||||
import HPath.IO
|
|
||||||
import Haskus.Utils.Variant.Excepts
|
import Haskus.Utils.Variant.Excepts
|
||||||
import Prelude hiding ( abs
|
import Prelude hiding ( abs
|
||||||
, readFile
|
, readFile
|
||||||
, writeFile
|
, writeFile
|
||||||
)
|
)
|
||||||
import System.Info
|
import System.Info
|
||||||
|
import System.Directory
|
||||||
import System.OsRelease
|
import System.OsRelease
|
||||||
|
import Text.PrettyPrint.HughesPJClass ( prettyShow )
|
||||||
import Text.Regex.Posix
|
import Text.Regex.Posix
|
||||||
|
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
import qualified Data.Text.IO as T
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--------------------------
|
--------------------------
|
||||||
--[ Platform detection ]--
|
--[ Platform detection ]--
|
||||||
@@ -55,7 +58,7 @@ import qualified Data.Text as T
|
|||||||
|
|
||||||
|
|
||||||
-- | Get the full platform request, consisting of architecture, distro, ...
|
-- | Get the full platform request, consisting of architecture, distro, ...
|
||||||
platformRequest :: (MonadLogger m, MonadCatch m, MonadIO m)
|
platformRequest :: (Alternative m, MonadFail m, MonadLogger m, MonadCatch m, MonadIO m)
|
||||||
=> Excepts
|
=> Excepts
|
||||||
'[NoCompatiblePlatform, NoCompatibleArch, DistroNotFound]
|
'[NoCompatiblePlatform, NoCompatibleArch, DistroNotFound]
|
||||||
m
|
m
|
||||||
@@ -80,7 +83,7 @@ getArchitecture = case arch of
|
|||||||
what -> Left (NoCompatibleArch what)
|
what -> Left (NoCompatibleArch what)
|
||||||
|
|
||||||
|
|
||||||
getPlatform :: (MonadLogger m, MonadCatch m, MonadIO m)
|
getPlatform :: (Alternative m, MonadLogger m, MonadCatch m, MonadIO m, MonadFail m)
|
||||||
=> Excepts
|
=> Excepts
|
||||||
'[NoCompatiblePlatform, DistroNotFound]
|
'[NoCompatiblePlatform, DistroNotFound]
|
||||||
m
|
m
|
||||||
@@ -95,36 +98,34 @@ getPlatform = do
|
|||||||
either (const Nothing) Just
|
either (const Nothing) Just
|
||||||
. versioning
|
. versioning
|
||||||
-- TODO: maybe do this somewhere else
|
-- TODO: maybe do this somewhere else
|
||||||
. getMajorVersion
|
. decUTF8Safe'
|
||||||
. decUTF8Safe
|
|
||||||
<$> getDarwinVersion
|
<$> getDarwinVersion
|
||||||
pure $ PlatformResult { _platform = Darwin, _distroVersion = ver }
|
pure $ PlatformResult { _platform = Darwin, _distroVersion = ver }
|
||||||
"freebsd" -> do
|
"freebsd" -> do
|
||||||
ver <-
|
ver <-
|
||||||
either (const Nothing) Just . versioning . decUTF8Safe
|
either (const Nothing) Just . versioning . decUTF8Safe'
|
||||||
<$> getFreeBSDVersion
|
<$> getFreeBSDVersion
|
||||||
pure $ PlatformResult { _platform = FreeBSD, _distroVersion = ver }
|
pure $ PlatformResult { _platform = FreeBSD, _distroVersion = ver }
|
||||||
|
"mingw32" -> pure PlatformResult { _platform = Windows, _distroVersion = Nothing }
|
||||||
what -> throwE $ NoCompatiblePlatform what
|
what -> throwE $ NoCompatiblePlatform what
|
||||||
lift $ $(logDebug) [i|Identified Platform as: #{pfr}|]
|
lift $ $(logDebug) [i|Identified Platform as: #{prettyShow pfr}|]
|
||||||
pure pfr
|
pure pfr
|
||||||
where
|
where
|
||||||
getMajorVersion = T.intercalate "." . take 2 . T.split (== '.')
|
getFreeBSDVersion = lift $ fmap _stdOut $ executeOut "freebsd-version" [] Nothing
|
||||||
getFreeBSDVersion =
|
getDarwinVersion = lift $ fmap _stdOut $ executeOut "sw_vers"
|
||||||
liftIO $ fmap _stdOut $ executeOut [rel|freebsd-version|] [] Nothing
|
|
||||||
getDarwinVersion = liftIO $ fmap _stdOut $ executeOut [rel|sw_vers|]
|
|
||||||
["-productVersion"]
|
["-productVersion"]
|
||||||
Nothing
|
Nothing
|
||||||
|
|
||||||
|
|
||||||
getLinuxDistro :: (MonadCatch m, MonadIO m)
|
getLinuxDistro :: (Alternative m, MonadCatch m, MonadIO m, MonadFail m)
|
||||||
=> Excepts '[DistroNotFound] m (LinuxDistro, Maybe Versioning)
|
=> Excepts '[DistroNotFound] m (LinuxDistro, Maybe Versioning)
|
||||||
getLinuxDistro = do
|
getLinuxDistro = do
|
||||||
-- TODO: don't do alternative on IO, because it hides bugs
|
-- TODO: don't do alternative on IO, because it hides bugs
|
||||||
(name, ver) <- handleIO (\_ -> throwE DistroNotFound) $ liftIO $ asum
|
(name, ver) <- handleIO (\_ -> throwE DistroNotFound) $ lift $ asum
|
||||||
[ try_os_release
|
[ liftIO try_os_release
|
||||||
, try_lsb_release_cmd
|
, try_lsb_release_cmd
|
||||||
, try_redhat_release
|
, liftIO try_redhat_release
|
||||||
, try_debian_version
|
, liftIO try_debian_version
|
||||||
]
|
]
|
||||||
let parsedVer = ver >>= either (const Nothing) Just . versioning
|
let parsedVer = ver >>= either (const Nothing) Just . versioning
|
||||||
distro = if
|
distro = if
|
||||||
@@ -147,12 +148,12 @@ getLinuxDistro = do
|
|||||||
where
|
where
|
||||||
regex x = makeRegexOpts compIgnoreCase execBlank ([s|\<|] ++ x ++ [s|\>|])
|
regex x = makeRegexOpts compIgnoreCase execBlank ([s|\<|] ++ x ++ [s|\>|])
|
||||||
|
|
||||||
lsb_release_cmd :: Path Rel
|
lsb_release_cmd :: FilePath
|
||||||
lsb_release_cmd = [rel|lsb-release|]
|
lsb_release_cmd = "lsb-release"
|
||||||
redhat_release :: Path Abs
|
redhat_release :: FilePath
|
||||||
redhat_release = [abs|/etc/redhat-release|]
|
redhat_release = "/etc/redhat-release"
|
||||||
debian_version :: Path Abs
|
debian_version :: FilePath
|
||||||
debian_version = [abs|/etc/debian_version|]
|
debian_version = "/etc/debian_version"
|
||||||
|
|
||||||
try_os_release :: IO (Text, Maybe Text)
|
try_os_release :: IO (Text, Maybe Text)
|
||||||
try_os_release = do
|
try_os_release = do
|
||||||
@@ -160,16 +161,17 @@ getLinuxDistro = do
|
|||||||
fmap osRelease <$> parseOsRelease
|
fmap osRelease <$> parseOsRelease
|
||||||
pure (T.pack name, fmap T.pack version_id)
|
pure (T.pack name, fmap T.pack version_id)
|
||||||
|
|
||||||
try_lsb_release_cmd :: IO (Text, Maybe Text)
|
try_lsb_release_cmd :: (MonadFail m, MonadIO m)
|
||||||
|
=> m (Text, Maybe Text)
|
||||||
try_lsb_release_cmd = do
|
try_lsb_release_cmd = do
|
||||||
(Just _) <- findExecutable lsb_release_cmd
|
(Just _) <- liftIO $ findExecutable lsb_release_cmd
|
||||||
name <- fmap _stdOut $ executeOut lsb_release_cmd ["-si"] Nothing
|
name <- fmap _stdOut $ executeOut lsb_release_cmd ["-si"] Nothing
|
||||||
ver <- fmap _stdOut $ executeOut lsb_release_cmd ["-sr"] Nothing
|
ver <- fmap _stdOut $ executeOut lsb_release_cmd ["-sr"] Nothing
|
||||||
pure (decUTF8Safe name, Just $ decUTF8Safe ver)
|
pure (decUTF8Safe' name, Just $ decUTF8Safe' ver)
|
||||||
|
|
||||||
try_redhat_release :: IO (Text, Maybe Text)
|
try_redhat_release :: IO (Text, Maybe Text)
|
||||||
try_redhat_release = do
|
try_redhat_release = do
|
||||||
t <- fmap decUTF8Safe' $ readFile redhat_release
|
t <- T.readFile redhat_release
|
||||||
let nameRegex n =
|
let nameRegex n =
|
||||||
makeRegexOpts compIgnoreCase
|
makeRegexOpts compIgnoreCase
|
||||||
execBlank
|
execBlank
|
||||||
@@ -191,5 +193,5 @@ getLinuxDistro = do
|
|||||||
|
|
||||||
try_debian_version :: IO (Text, Maybe Text)
|
try_debian_version :: IO (Text, Maybe Text)
|
||||||
try_debian_version = do
|
try_debian_version = do
|
||||||
ver <- readFile debian_version
|
ver <- T.readFile debian_version
|
||||||
pure (T.pack "debian", Just . decUTF8Safe' $ ver)
|
pure (T.pack "debian", Just ver)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Copyright : (c) Julian Ospald, 2020
|
|||||||
License : LGPL-3.0
|
License : LGPL-3.0
|
||||||
Maintainer : hasufell@hasufell.de
|
Maintainer : hasufell@hasufell.de
|
||||||
Stability : experimental
|
Stability : experimental
|
||||||
Portability : POSIX
|
Portability : portable
|
||||||
-}
|
-}
|
||||||
module GHCup.Requirements where
|
module GHCup.Requirements where
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
{-# LANGUAGE CPP #-}
|
{-# LANGUAGE CPP #-}
|
||||||
{-# LANGUAGE DeriveGeneric #-}
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE QuasiQuotes #-}
|
|
||||||
|
|
||||||
{-|
|
{-|
|
||||||
Module : GHCup.Types
|
Module : GHCup.Types
|
||||||
@@ -11,26 +10,43 @@ Copyright : (c) Julian Ospald, 2020
|
|||||||
License : LGPL-3.0
|
License : LGPL-3.0
|
||||||
Maintainer : hasufell@hasufell.de
|
Maintainer : hasufell@hasufell.de
|
||||||
Stability : experimental
|
Stability : experimental
|
||||||
Portability : POSIX
|
Portability : portable
|
||||||
-}
|
-}
|
||||||
module GHCup.Types where
|
module GHCup.Types
|
||||||
|
( module GHCup.Types
|
||||||
|
#if defined(BRICK)
|
||||||
|
, Key(..)
|
||||||
|
#endif
|
||||||
|
)
|
||||||
|
where
|
||||||
|
|
||||||
|
import Control.Applicative
|
||||||
|
import Control.Monad.Logger
|
||||||
import Data.Map.Strict ( Map )
|
import Data.Map.Strict ( Map )
|
||||||
import Data.List.NonEmpty ( NonEmpty (..) )
|
import Data.List.NonEmpty ( NonEmpty (..) )
|
||||||
import Data.String.Interpolate
|
|
||||||
import Data.Text ( Text )
|
import Data.Text ( Text )
|
||||||
import Data.Versions
|
import Data.Versions
|
||||||
import HPath
|
import Haskus.Utils.Variant.Excepts
|
||||||
import Text.PrettyPrint.HughesPJClass (Pretty, pPrint, text)
|
import Text.PrettyPrint.HughesPJClass (Pretty, pPrint, text)
|
||||||
import URI.ByteString
|
import URI.ByteString
|
||||||
|
#if defined(BRICK)
|
||||||
|
import Graphics.Vty ( Key(..) )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
import qualified Control.Monad.Trans.Class as Trans
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Encoding as E
|
|
||||||
import qualified Data.Text.Encoding.Error as E
|
|
||||||
import qualified GHC.Generics as GHC
|
import qualified GHC.Generics as GHC
|
||||||
import qualified Graphics.Vty as Vty
|
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(BRICK)
|
||||||
|
data Key = KEsc | KChar Char | KBS | KEnter
|
||||||
|
| KLeft | KRight | KUp | KDown
|
||||||
|
| KUpLeft | KUpRight | KDownLeft | KDownRight | KCenter
|
||||||
|
| KFun Int | KBackTab | KPrtScr | KPause | KIns
|
||||||
|
| KHome | KPageUp | KDel | KEnd | KPageDown | KBegin | KMenu
|
||||||
|
deriving (Eq,Show,Read,Ord,GHC.Generic)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
--------------------
|
--------------------
|
||||||
--[ GHCInfo Tree ]--
|
--[ GHCInfo Tree ]--
|
||||||
@@ -40,6 +56,7 @@ import qualified Graphics.Vty as Vty
|
|||||||
data GHCupInfo = GHCupInfo
|
data GHCupInfo = GHCupInfo
|
||||||
{ _toolRequirements :: ToolRequirements
|
{ _toolRequirements :: ToolRequirements
|
||||||
, _ghcupDownloads :: GHCupDownloads
|
, _ghcupDownloads :: GHCupDownloads
|
||||||
|
, _globalTools :: Map GlobalTool DownloadInfo
|
||||||
}
|
}
|
||||||
deriving (Show, GHC.Generic)
|
deriving (Show, GHC.Generic)
|
||||||
|
|
||||||
@@ -85,6 +102,10 @@ data Tool = GHC
|
|||||||
| Cabal
|
| Cabal
|
||||||
| GHCup
|
| GHCup
|
||||||
| HLS
|
| HLS
|
||||||
|
| Stack
|
||||||
|
deriving (Eq, GHC.Generic, Ord, Show, Enum, Bounded)
|
||||||
|
|
||||||
|
data GlobalTool = ShimGen
|
||||||
deriving (Eq, GHC.Generic, Ord, Show, Enum, Bounded)
|
deriving (Eq, GHC.Generic, Ord, Show, Enum, Bounded)
|
||||||
|
|
||||||
|
|
||||||
@@ -156,12 +177,15 @@ data Platform = Linux LinuxDistro
|
|||||||
| Darwin
|
| Darwin
|
||||||
-- ^ must exit
|
-- ^ must exit
|
||||||
| FreeBSD
|
| FreeBSD
|
||||||
|
| Windows
|
||||||
|
-- ^ must exit
|
||||||
deriving (Eq, GHC.Generic, Ord, Show)
|
deriving (Eq, GHC.Generic, Ord, Show)
|
||||||
|
|
||||||
platformToString :: Platform -> String
|
platformToString :: Platform -> String
|
||||||
platformToString (Linux distro) = "linux-" ++ distroToString distro
|
platformToString (Linux distro) = "linux-" ++ distroToString distro
|
||||||
platformToString Darwin = "darwin"
|
platformToString Darwin = "darwin"
|
||||||
platformToString FreeBSD = "freebsd"
|
platformToString FreeBSD = "freebsd"
|
||||||
|
platformToString Windows = "windows"
|
||||||
|
|
||||||
instance Pretty Platform where
|
instance Pretty Platform where
|
||||||
pPrint = text . platformToString
|
pPrint = text . platformToString
|
||||||
@@ -217,12 +241,12 @@ data DownloadInfo = DownloadInfo
|
|||||||
|
|
||||||
|
|
||||||
-- | How to descend into a tar archive.
|
-- | How to descend into a tar archive.
|
||||||
data TarDir = RealDir (Path Rel)
|
data TarDir = RealDir FilePath
|
||||||
| RegexDir String -- ^ will be compiled to regex, the first match will "win"
|
| RegexDir String -- ^ will be compiled to regex, the first match will "win"
|
||||||
deriving (Eq, Ord, GHC.Generic, Show)
|
deriving (Eq, Ord, GHC.Generic, Show)
|
||||||
|
|
||||||
instance Pretty TarDir where
|
instance Pretty TarDir where
|
||||||
pPrint (RealDir path) = text [i|#{E.decodeUtf8With E.lenientDecode . toFilePath $ path}|]
|
pPrint (RealDir path) = text path
|
||||||
pPrint (RegexDir regex) = text regex
|
pPrint (RegexDir regex) = text regex
|
||||||
|
|
||||||
|
|
||||||
@@ -249,45 +273,50 @@ defaultUserSettings :: UserSettings
|
|||||||
defaultUserSettings = UserSettings Nothing Nothing Nothing Nothing Nothing Nothing Nothing
|
defaultUserSettings = UserSettings Nothing Nothing Nothing Nothing Nothing Nothing Nothing
|
||||||
|
|
||||||
data UserKeyBindings = UserKeyBindings
|
data UserKeyBindings = UserKeyBindings
|
||||||
{ kUp :: Maybe Vty.Key
|
{ kUp :: Maybe Key
|
||||||
, kDown :: Maybe Vty.Key
|
, kDown :: Maybe Key
|
||||||
, kQuit :: Maybe Vty.Key
|
, kQuit :: Maybe Key
|
||||||
, kInstall :: Maybe Vty.Key
|
, kInstall :: Maybe Key
|
||||||
, kUninstall :: Maybe Vty.Key
|
, kUninstall :: Maybe Key
|
||||||
, kSet :: Maybe Vty.Key
|
, kSet :: Maybe Key
|
||||||
, kChangelog :: Maybe Vty.Key
|
, kChangelog :: Maybe Key
|
||||||
, kShowAll :: Maybe Vty.Key
|
, kShowAll :: Maybe Key
|
||||||
|
, kShowAllTools :: Maybe Key
|
||||||
}
|
}
|
||||||
deriving (Show, GHC.Generic)
|
deriving (Show, GHC.Generic)
|
||||||
|
|
||||||
data KeyBindings = KeyBindings
|
data KeyBindings = KeyBindings
|
||||||
{ bUp :: Vty.Key
|
{ bUp :: Key
|
||||||
, bDown :: Vty.Key
|
, bDown :: Key
|
||||||
, bQuit :: Vty.Key
|
, bQuit :: Key
|
||||||
, bInstall :: Vty.Key
|
, bInstall :: Key
|
||||||
, bUninstall :: Vty.Key
|
, bUninstall :: Key
|
||||||
, bSet :: Vty.Key
|
, bSet :: Key
|
||||||
, bChangelog :: Vty.Key
|
, bChangelog :: Key
|
||||||
, bShowAll :: Vty.Key
|
, bShowAllVersions :: Key
|
||||||
|
, bShowAllTools :: Key
|
||||||
}
|
}
|
||||||
deriving (Show, GHC.Generic)
|
deriving (Show, GHC.Generic)
|
||||||
|
|
||||||
defaultKeyBindings :: KeyBindings
|
defaultKeyBindings :: KeyBindings
|
||||||
defaultKeyBindings = KeyBindings
|
defaultKeyBindings = KeyBindings
|
||||||
{ bUp = Vty.KUp
|
{ bUp = KUp
|
||||||
, bDown = Vty.KDown
|
, bDown = KDown
|
||||||
, bQuit = Vty.KChar 'q'
|
, bQuit = KChar 'q'
|
||||||
, bInstall = Vty.KChar 'i'
|
, bInstall = KChar 'i'
|
||||||
, bUninstall = Vty.KChar 'u'
|
, bUninstall = KChar 'u'
|
||||||
, bSet = Vty.KChar 's'
|
, bSet = KChar 's'
|
||||||
, bChangelog = Vty.KChar 'c'
|
, bChangelog = KChar 'c'
|
||||||
, bShowAll = Vty.KChar 'a'
|
, bShowAllVersions = KChar 'a'
|
||||||
|
, bShowAllTools = KChar 't'
|
||||||
}
|
}
|
||||||
|
|
||||||
data AppState = AppState
|
data AppState = AppState
|
||||||
{ settings :: Settings
|
{ settings :: Settings
|
||||||
, dirs :: Dirs
|
, dirs :: Dirs
|
||||||
, keyBindings :: KeyBindings
|
, keyBindings :: KeyBindings
|
||||||
|
, ghcupInfo :: GHCupInfo
|
||||||
|
, pfreq :: PlatformRequest
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
data Settings = Settings
|
data Settings = Settings
|
||||||
@@ -301,11 +330,11 @@ data Settings = Settings
|
|||||||
deriving (Show, GHC.Generic)
|
deriving (Show, GHC.Generic)
|
||||||
|
|
||||||
data Dirs = Dirs
|
data Dirs = Dirs
|
||||||
{ baseDir :: Path Abs
|
{ baseDir :: FilePath
|
||||||
, binDir :: Path Abs
|
, binDir :: FilePath
|
||||||
, cacheDir :: Path Abs
|
, cacheDir :: FilePath
|
||||||
, logsDir :: Path Abs
|
, logsDir :: FilePath
|
||||||
, confDir :: Path Abs
|
, confDir :: FilePath
|
||||||
}
|
}
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
@@ -322,10 +351,10 @@ data Downloader = Curl
|
|||||||
deriving (Eq, Show, Ord)
|
deriving (Eq, Show, Ord)
|
||||||
|
|
||||||
data DebugInfo = DebugInfo
|
data DebugInfo = DebugInfo
|
||||||
{ diBaseDir :: Path Abs
|
{ diBaseDir :: FilePath
|
||||||
, diBinDir :: Path Abs
|
, diBinDir :: FilePath
|
||||||
, diGHCDir :: Path Abs
|
, diGHCDir :: FilePath
|
||||||
, diCacheDir :: Path Abs
|
, diCacheDir :: FilePath
|
||||||
, diArch :: Architecture
|
, diArch :: Architecture
|
||||||
, diPlatform :: PlatformResult
|
, diPlatform :: PlatformResult
|
||||||
}
|
}
|
||||||
@@ -418,3 +447,16 @@ instance Pretty Versioning where
|
|||||||
|
|
||||||
instance Pretty Version where
|
instance Pretty Version where
|
||||||
pPrint = text . T.unpack . prettyVer
|
pPrint = text . T.unpack . prettyVer
|
||||||
|
|
||||||
|
|
||||||
|
instance (Monad m, Alternative m) => Alternative (LoggingT m) where
|
||||||
|
empty = Trans.lift empty
|
||||||
|
{-# INLINE empty #-}
|
||||||
|
m <|> n = LoggingT $ \ r -> runLoggingT m r <|> runLoggingT n r
|
||||||
|
{-# INLINE (<|>) #-}
|
||||||
|
|
||||||
|
|
||||||
|
instance MonadLogger m => MonadLogger (Excepts e m) where
|
||||||
|
monadLoggerLog a b c d = Trans.lift $ monadLoggerLog a b c d
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ Copyright : (c) Julian Ospald, 2020
|
|||||||
License : LGPL-3.0
|
License : LGPL-3.0
|
||||||
Maintainer : hasufell@hasufell.de
|
Maintainer : hasufell@hasufell.de
|
||||||
Stability : experimental
|
Stability : experimental
|
||||||
Portability : POSIX
|
Portability : portable
|
||||||
-}
|
-}
|
||||||
module GHCup.Types.JSON where
|
module GHCup.Types.JSON where
|
||||||
|
|
||||||
@@ -33,38 +33,27 @@ import Data.List.NonEmpty ( NonEmpty(..) )
|
|||||||
import Data.Text.Encoding as E
|
import Data.Text.Encoding as E
|
||||||
import Data.Versions
|
import Data.Versions
|
||||||
import Data.Void
|
import Data.Void
|
||||||
import Data.Word8
|
|
||||||
import HPath
|
|
||||||
import URI.ByteString
|
import URI.ByteString
|
||||||
import Text.Casing
|
import Text.Casing
|
||||||
|
|
||||||
import qualified Data.ByteString as BS
|
|
||||||
import qualified Data.List.NonEmpty as NE
|
import qualified Data.List.NonEmpty as NE
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Graphics.Vty as Vty
|
|
||||||
import qualified Text.Megaparsec as MP
|
import qualified Text.Megaparsec as MP
|
||||||
import qualified Text.Megaparsec.Char as MPC
|
import qualified Text.Megaparsec.Char as MPC
|
||||||
|
|
||||||
|
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } { fieldLabelModifier = removeLensFieldLabel } ''Architecture
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } { fieldLabelModifier = removeLensFieldLabel } ''Architecture
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''LinuxDistro
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''LinuxDistro
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''Mess
|
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''MChunk
|
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''Platform
|
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''SemVer
|
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''Tool
|
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''VSep
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''VSep
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''VUnit
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''VUnit
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''VersionInfo
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''MChunk
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''DownloadInfo
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''Platform
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''GHCupInfo
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''Mess
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''Requirements
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''SemVer
|
||||||
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''Tool
|
||||||
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''GlobalTool
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''KeepDirs
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''KeepDirs
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''Downloader
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''Downloader
|
||||||
deriveJSON defaultOptions { sumEncoding = ObjectWithSingleField } ''URLSource
|
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = \str' -> maybe str' T.unpack . T.stripPrefix (T.pack "u-") . T.pack . kebab $ str' } ''UserSettings
|
|
||||||
deriveJSON defaultOptions { fieldLabelModifier = \str' -> maybe str' T.unpack . T.stripPrefix (T.pack "k-") . T.pack . kebab $ str' } ''UserKeyBindings
|
|
||||||
deriveJSON defaultOptions { sumEncoding = ObjectWithSingleField } ''Vty.Key
|
|
||||||
|
|
||||||
instance ToJSON Tag where
|
instance ToJSON Tag where
|
||||||
toJSON Latest = String "Latest"
|
toJSON Latest = String "Latest"
|
||||||
@@ -128,11 +117,13 @@ instance ToJSONKey Platform where
|
|||||||
Darwin -> T.pack "Darwin"
|
Darwin -> T.pack "Darwin"
|
||||||
FreeBSD -> T.pack "FreeBSD"
|
FreeBSD -> T.pack "FreeBSD"
|
||||||
Linux d -> T.pack ("Linux_" <> show d)
|
Linux d -> T.pack ("Linux_" <> show d)
|
||||||
|
Windows -> T.pack "Windows"
|
||||||
|
|
||||||
instance FromJSONKey Platform where
|
instance FromJSONKey Platform where
|
||||||
fromJSONKey = FromJSONKeyTextParser $ \t -> if
|
fromJSONKey = FromJSONKeyTextParser $ \t -> if
|
||||||
| T.pack "Darwin" == t -> pure Darwin
|
| T.pack "Darwin" == t -> pure Darwin
|
||||||
| T.pack "FreeBSD" == t -> pure FreeBSD
|
| T.pack "FreeBSD" == t -> pure FreeBSD
|
||||||
|
| T.pack "Windows" == t -> pure Windows
|
||||||
| T.pack "Linux_" `T.isPrefixOf` t -> case
|
| T.pack "Linux_" `T.isPrefixOf` t -> case
|
||||||
T.stripPrefix (T.pack "Linux_") t
|
T.stripPrefix (T.pack "Linux_") t
|
||||||
of
|
of
|
||||||
@@ -199,19 +190,11 @@ instance ToJSONKey Tool where
|
|||||||
instance FromJSONKey Tool where
|
instance FromJSONKey Tool where
|
||||||
fromJSONKey = genericFromJSONKey defaultJSONKeyOptions
|
fromJSONKey = genericFromJSONKey defaultJSONKeyOptions
|
||||||
|
|
||||||
instance ToJSON (Path Rel) where
|
instance ToJSONKey GlobalTool where
|
||||||
toJSON p = case and . fmap isAscii . BS.unpack $ fp of
|
toJSONKey = genericToJSONKey defaultJSONKeyOptions
|
||||||
True -> toJSON . decUTF8Safe $ fp
|
|
||||||
False -> String "/not/a/valid/path"
|
|
||||||
where fp = toFilePath p
|
|
||||||
|
|
||||||
instance FromJSON (Path Rel) where
|
|
||||||
parseJSON = withText "HPath Rel" $ \t -> do
|
|
||||||
let d = encodeUtf8 t
|
|
||||||
case parseRel d of
|
|
||||||
Right x -> pure x
|
|
||||||
Left e -> fail $ "Failure in HPath Rel (FromJSON)" <> show e
|
|
||||||
|
|
||||||
|
instance FromJSONKey GlobalTool where
|
||||||
|
fromJSONKey = genericFromJSONKey defaultJSONKeyOptions
|
||||||
|
|
||||||
instance ToJSON TarDir where
|
instance ToJSON TarDir where
|
||||||
toJSON (RealDir p) = toJSON p
|
toJSON (RealDir p) = toJSON p
|
||||||
@@ -322,3 +305,14 @@ instance FromJSONKey (Maybe VersionRange) where
|
|||||||
just t = case MP.parse versionRangeP "" t of
|
just t = case MP.parse versionRangeP "" t of
|
||||||
Right x -> pure $ Just x
|
Right x -> pure $ Just x
|
||||||
Left e -> fail $ "Failure in (Maybe VersionRange) (FromJSONKey)" <> MP.errorBundlePretty e
|
Left e -> fail $ "Failure in (Maybe VersionRange) (FromJSONKey)" <> MP.errorBundlePretty e
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''Requirements
|
||||||
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''DownloadInfo
|
||||||
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''VersionInfo
|
||||||
|
deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''GHCupInfo
|
||||||
|
deriveJSON defaultOptions { sumEncoding = ObjectWithSingleField } ''URLSource
|
||||||
|
deriveJSON defaultOptions { sumEncoding = ObjectWithSingleField } ''Key
|
||||||
|
deriveJSON defaultOptions { fieldLabelModifier = \str' -> maybe str' T.unpack . T.stripPrefix (T.pack "k-") . T.pack . kebab $ str' } ''UserKeyBindings
|
||||||
|
deriveJSON defaultOptions { fieldLabelModifier = \str' -> maybe str' T.unpack . T.stripPrefix (T.pack "u-") . T.pack . kebab $ str' } ''UserSettings
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Copyright : (c) Julian Ospald, 2020
|
|||||||
License : LGPL-3.0
|
License : LGPL-3.0
|
||||||
Maintainer : hasufell@hasufell.de
|
Maintainer : hasufell@hasufell.de
|
||||||
Stability : experimental
|
Stability : experimental
|
||||||
Portability : POSIX
|
Portability : portable
|
||||||
-}
|
-}
|
||||||
module GHCup.Types.Optics where
|
module GHCup.Types.Optics where
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
4
lib/GHCup/Utils.hs-boot
Normal file
4
lib/GHCup/Utils.hs-boot
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
module GHCup.Utils where
|
||||||
|
|
||||||
|
getLinkTarget :: FilePath -> IO FilePath
|
||||||
|
pathIsLink :: FilePath -> IO Bool
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
{-# LANGUAGE CPP #-}
|
||||||
{-# LANGUAGE DataKinds #-}
|
{-# LANGUAGE DataKinds #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
@@ -12,10 +13,11 @@ Copyright : (c) Julian Ospald, 2020
|
|||||||
License : LGPL-3.0
|
License : LGPL-3.0
|
||||||
Maintainer : hasufell@hasufell.de
|
Maintainer : hasufell@hasufell.de
|
||||||
Stability : experimental
|
Stability : experimental
|
||||||
Portability : POSIX
|
Portability : portable
|
||||||
-}
|
-}
|
||||||
module GHCup.Utils.Dirs
|
module GHCup.Utils.Dirs
|
||||||
( getDirs
|
( getDirs
|
||||||
|
, ghcupBaseDir
|
||||||
, ghcupConfigFile
|
, ghcupConfigFile
|
||||||
, ghcupCacheDir
|
, ghcupCacheDir
|
||||||
, ghcupGHCBaseDir
|
, ghcupGHCBaseDir
|
||||||
@@ -24,6 +26,10 @@ module GHCup.Utils.Dirs
|
|||||||
, parseGHCupGHCDir
|
, parseGHCupGHCDir
|
||||||
, relativeSymlink
|
, relativeSymlink
|
||||||
, withGHCupTmpDir
|
, withGHCupTmpDir
|
||||||
|
, getConfigFilePath
|
||||||
|
#if !defined(IS_WINDOWS)
|
||||||
|
, useXDG
|
||||||
|
#endif
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
|
||||||
@@ -34,7 +40,6 @@ import GHCup.Types.JSON ( )
|
|||||||
import GHCup.Utils.MegaParsec
|
import GHCup.Utils.MegaParsec
|
||||||
import GHCup.Utils.Prelude
|
import GHCup.Utils.Prelude
|
||||||
|
|
||||||
import Control.Applicative
|
|
||||||
import Control.Exception.Safe
|
import Control.Exception.Safe
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Control.Monad.IO.Unlift
|
import Control.Monad.IO.Unlift
|
||||||
@@ -42,32 +47,22 @@ import Control.Monad.Logger
|
|||||||
import Control.Monad.Reader
|
import Control.Monad.Reader
|
||||||
import Control.Monad.Trans.Resource hiding (throwM)
|
import Control.Monad.Trans.Resource hiding (throwM)
|
||||||
import Data.Bifunctor
|
import Data.Bifunctor
|
||||||
import Data.ByteString ( ByteString )
|
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Data.String.Interpolate
|
import Data.String.Interpolate
|
||||||
import GHC.IO.Exception ( IOErrorType(NoSuchThing) )
|
import GHC.IO.Exception ( IOErrorType(NoSuchThing) )
|
||||||
import Haskus.Utils.Variant.Excepts
|
import Haskus.Utils.Variant.Excepts
|
||||||
import HPath
|
|
||||||
import HPath.IO
|
|
||||||
import Optics
|
import Optics
|
||||||
import Prelude hiding ( abs
|
#if !defined(IS_WINDOWS)
|
||||||
, readFile
|
import System.Directory
|
||||||
, writeFile
|
#endif
|
||||||
)
|
|
||||||
import System.DiskSpace
|
import System.DiskSpace
|
||||||
import System.Posix.Env.ByteString ( getEnv
|
import System.Environment
|
||||||
, getEnvDefault
|
import System.FilePath
|
||||||
)
|
import System.IO.Temp
|
||||||
import System.Posix.FilePath hiding ( (</>) )
|
|
||||||
import System.Posix.Temp.ByteString ( mkdtemp )
|
|
||||||
|
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString as BS
|
||||||
import qualified Data.ByteString.UTF8 as UTF8
|
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Encoding as E
|
|
||||||
import qualified Data.Yaml as Y
|
import qualified Data.Yaml as Y
|
||||||
import qualified System.Posix.FilePath as FP
|
|
||||||
import qualified System.Posix.User as PU
|
|
||||||
import qualified Text.Megaparsec as MP
|
import qualified Text.Megaparsec as MP
|
||||||
import Control.Concurrent (threadDelay)
|
import Control.Concurrent (threadDelay)
|
||||||
|
|
||||||
@@ -82,96 +77,117 @@ import Control.Concurrent (threadDelay)
|
|||||||
--
|
--
|
||||||
-- If 'GHCUP_USE_XDG_DIRS' is set (to anything),
|
-- If 'GHCUP_USE_XDG_DIRS' is set (to anything),
|
||||||
-- then uses 'XDG_DATA_HOME/ghcup' as per xdg spec.
|
-- then uses 'XDG_DATA_HOME/ghcup' as per xdg spec.
|
||||||
ghcupBaseDir :: IO (Path Abs)
|
ghcupBaseDir :: IO FilePath
|
||||||
ghcupBaseDir = do
|
ghcupBaseDir = do
|
||||||
|
#if defined(IS_WINDOWS)
|
||||||
|
bdir <- fromMaybe "C:\\" <$> lookupEnv "GHCUP_INSTALL_BASE_PREFIX"
|
||||||
|
pure (bdir </> "ghcup")
|
||||||
|
#else
|
||||||
xdg <- useXDG
|
xdg <- useXDG
|
||||||
if xdg
|
if xdg
|
||||||
then do
|
then do
|
||||||
bdir <- getEnv "XDG_DATA_HOME" >>= \case
|
bdir <- lookupEnv "XDG_DATA_HOME" >>= \case
|
||||||
Just r -> parseAbs r
|
Just r -> pure r
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
home <- liftIO getHomeDirectory
|
home <- liftIO getHomeDirectory
|
||||||
pure (home </> [rel|.local/share|])
|
pure (home </> ".local" </> "share")
|
||||||
pure (bdir </> [rel|ghcup|])
|
pure (bdir </> "ghcup")
|
||||||
else do
|
else do
|
||||||
bdir <- getEnv "GHCUP_INSTALL_BASE_PREFIX" >>= \case
|
bdir <- lookupEnv "GHCUP_INSTALL_BASE_PREFIX" >>= \case
|
||||||
Just r -> parseAbs r
|
Just r -> pure r
|
||||||
Nothing -> liftIO getHomeDirectory
|
Nothing -> liftIO getHomeDirectory
|
||||||
pure (bdir </> [rel|.ghcup|])
|
pure (bdir </> ".ghcup")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
-- | ~/.ghcup by default
|
-- | ~/.ghcup by default
|
||||||
--
|
--
|
||||||
-- If 'GHCUP_USE_XDG_DIRS' is set (to anything),
|
-- If 'GHCUP_USE_XDG_DIRS' is set (to anything),
|
||||||
-- then uses 'XDG_CONFIG_HOME/ghcup' as per xdg spec.
|
-- then uses 'XDG_CONFIG_HOME/ghcup' as per xdg spec.
|
||||||
ghcupConfigDir :: IO (Path Abs)
|
ghcupConfigDir :: IO FilePath
|
||||||
ghcupConfigDir = do
|
ghcupConfigDir = do
|
||||||
|
#if defined(IS_WINDOWS)
|
||||||
|
ghcupBaseDir
|
||||||
|
#else
|
||||||
xdg <- useXDG
|
xdg <- useXDG
|
||||||
if xdg
|
if xdg
|
||||||
then do
|
then do
|
||||||
bdir <- getEnv "XDG_CONFIG_HOME" >>= \case
|
bdir <- lookupEnv "XDG_CONFIG_HOME" >>= \case
|
||||||
Just r -> parseAbs r
|
Just r -> pure r
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
home <- liftIO getHomeDirectory
|
home <- liftIO getHomeDirectory
|
||||||
pure (home </> [rel|.config|])
|
pure (home </> ".config")
|
||||||
pure (bdir </> [rel|ghcup|])
|
pure (bdir </> "ghcup")
|
||||||
else do
|
else do
|
||||||
bdir <- getEnv "GHCUP_INSTALL_BASE_PREFIX" >>= \case
|
bdir <- lookupEnv "GHCUP_INSTALL_BASE_PREFIX" >>= \case
|
||||||
Just r -> parseAbs r
|
Just r -> pure r
|
||||||
Nothing -> liftIO getHomeDirectory
|
Nothing -> liftIO getHomeDirectory
|
||||||
pure (bdir </> [rel|.ghcup|])
|
pure (bdir </> ".ghcup")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
-- | If 'GHCUP_USE_XDG_DIRS' is set (to anything),
|
-- | If 'GHCUP_USE_XDG_DIRS' is set (to anything),
|
||||||
-- then uses 'XDG_BIN_HOME' env var or defaults to '~/.local/bin'
|
-- then uses 'XDG_BIN_HOME' env var or defaults to '~/.local/bin'
|
||||||
-- (which, sadly is not strictly xdg spec).
|
-- (which, sadly is not strictly xdg spec).
|
||||||
ghcupBinDir :: IO (Path Abs)
|
ghcupBinDir :: IO FilePath
|
||||||
ghcupBinDir = do
|
ghcupBinDir = do
|
||||||
|
#if defined(IS_WINDOWS)
|
||||||
|
ghcupBaseDir <&> (</> "bin")
|
||||||
|
#else
|
||||||
xdg <- useXDG
|
xdg <- useXDG
|
||||||
if xdg
|
if xdg
|
||||||
then do
|
then do
|
||||||
getEnv "XDG_BIN_HOME" >>= \case
|
lookupEnv "XDG_BIN_HOME" >>= \case
|
||||||
Just r -> parseAbs r
|
Just r -> pure r
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
home <- liftIO getHomeDirectory
|
home <- liftIO getHomeDirectory
|
||||||
pure (home </> [rel|.local/bin|])
|
pure (home </> ".local" </> "bin")
|
||||||
else ghcupBaseDir <&> (</> [rel|bin|])
|
else ghcupBaseDir <&> (</> "bin")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
-- | Defaults to '~/.ghcup/cache'.
|
-- | Defaults to '~/.ghcup/cache'.
|
||||||
--
|
--
|
||||||
-- If 'GHCUP_USE_XDG_DIRS' is set (to anything),
|
-- If 'GHCUP_USE_XDG_DIRS' is set (to anything),
|
||||||
-- then uses 'XDG_CACHE_HOME/ghcup' as per xdg spec.
|
-- then uses 'XDG_CACHE_HOME/ghcup' as per xdg spec.
|
||||||
ghcupCacheDir :: IO (Path Abs)
|
ghcupCacheDir :: IO FilePath
|
||||||
ghcupCacheDir = do
|
ghcupCacheDir = do
|
||||||
|
#if defined(IS_WINDOWS)
|
||||||
|
ghcupBaseDir <&> (</> "cache")
|
||||||
|
#else
|
||||||
xdg <- useXDG
|
xdg <- useXDG
|
||||||
if xdg
|
if xdg
|
||||||
then do
|
then do
|
||||||
bdir <- getEnv "XDG_CACHE_HOME" >>= \case
|
bdir <- lookupEnv "XDG_CACHE_HOME" >>= \case
|
||||||
Just r -> parseAbs r
|
Just r -> pure r
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
home <- liftIO getHomeDirectory
|
home <- liftIO getHomeDirectory
|
||||||
pure (home </> [rel|.cache|])
|
pure (home </> ".cache")
|
||||||
pure (bdir </> [rel|ghcup|])
|
pure (bdir </> "ghcup")
|
||||||
else ghcupBaseDir <&> (</> [rel|cache|])
|
else ghcupBaseDir <&> (</> "cache")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
-- | Defaults to '~/.ghcup/logs'.
|
-- | Defaults to '~/.ghcup/logs'.
|
||||||
--
|
--
|
||||||
-- If 'GHCUP_USE_XDG_DIRS' is set (to anything),
|
-- If 'GHCUP_USE_XDG_DIRS' is set (to anything),
|
||||||
-- then uses 'XDG_CACHE_HOME/ghcup/logs' as per xdg spec.
|
-- then uses 'XDG_CACHE_HOME/ghcup/logs' as per xdg spec.
|
||||||
ghcupLogsDir :: IO (Path Abs)
|
ghcupLogsDir :: IO FilePath
|
||||||
ghcupLogsDir = do
|
ghcupLogsDir = do
|
||||||
|
#if defined(IS_WINDOWS)
|
||||||
|
ghcupBaseDir <&> (</> "logs")
|
||||||
|
#else
|
||||||
xdg <- useXDG
|
xdg <- useXDG
|
||||||
if xdg
|
if xdg
|
||||||
then do
|
then do
|
||||||
bdir <- getEnv "XDG_CACHE_HOME" >>= \case
|
bdir <- lookupEnv "XDG_CACHE_HOME" >>= \case
|
||||||
Just r -> parseAbs r
|
Just r -> pure r
|
||||||
Nothing -> do
|
Nothing -> do
|
||||||
home <- liftIO getHomeDirectory
|
home <- liftIO getHomeDirectory
|
||||||
pure (home </> [rel|.cache|])
|
pure (home </> ".cache")
|
||||||
pure (bdir </> [rel|ghcup/logs|])
|
pure (bdir </> "ghcup" </> "logs")
|
||||||
else ghcupBaseDir <&> (</> [rel|logs|])
|
else ghcupBaseDir <&> (</> "logs")
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
getDirs :: IO Dirs
|
getDirs :: IO Dirs
|
||||||
@@ -189,16 +205,19 @@ getDirs = do
|
|||||||
--[ GHCup files ]--
|
--[ GHCup files ]--
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
|
getConfigFilePath :: (MonadIO m) => m FilePath
|
||||||
|
getConfigFilePath = do
|
||||||
|
confDir <- liftIO ghcupConfigDir
|
||||||
|
pure $ confDir </> "config.yaml"
|
||||||
|
|
||||||
ghcupConfigFile :: (MonadIO m)
|
ghcupConfigFile :: (MonadIO m)
|
||||||
=> Excepts '[JSONError] m UserSettings
|
=> Excepts '[JSONError] m UserSettings
|
||||||
ghcupConfigFile = do
|
ghcupConfigFile = do
|
||||||
confDir <- liftIO ghcupConfigDir
|
filepath <- getConfigFilePath
|
||||||
let file = confDir </> [rel|config.yaml|]
|
contents <- liftIO $ handleIO' NoSuchThing (\_ -> pure Nothing) $ Just <$> BS.readFile filepath
|
||||||
bs <- liftIO $ handleIO' NoSuchThing (\_ -> pure Nothing) $ Just <$> readFile file
|
case contents of
|
||||||
case bs of
|
|
||||||
Nothing -> pure defaultUserSettings
|
Nothing -> pure defaultUserSettings
|
||||||
Just bs' -> lE' JSONDecodeError . first show . Y.decodeEither' . L.toStrict $ bs'
|
Just contents' -> lE' JSONDecodeError . first show . Y.decodeEither' $ contents'
|
||||||
|
|
||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
@@ -207,10 +226,10 @@ ghcupConfigFile = do
|
|||||||
|
|
||||||
|
|
||||||
-- | ~/.ghcup/ghc by default.
|
-- | ~/.ghcup/ghc by default.
|
||||||
ghcupGHCBaseDir :: (MonadReader AppState m) => m (Path Abs)
|
ghcupGHCBaseDir :: (MonadReader AppState m) => m FilePath
|
||||||
ghcupGHCBaseDir = do
|
ghcupGHCBaseDir = do
|
||||||
AppState { dirs = Dirs {..} } <- ask
|
AppState { dirs = Dirs {..} } <- ask
|
||||||
pure (baseDir </> [rel|ghc|])
|
pure (baseDir </> "ghc")
|
||||||
|
|
||||||
|
|
||||||
-- | Gets '~/.ghcup/ghc/<ghcupGHCDir>'.
|
-- | Gets '~/.ghcup/ghc/<ghcupGHCDir>'.
|
||||||
@@ -219,35 +238,32 @@ ghcupGHCBaseDir = do
|
|||||||
-- * 8.8.4
|
-- * 8.8.4
|
||||||
ghcupGHCDir :: (MonadReader AppState m, MonadThrow m)
|
ghcupGHCDir :: (MonadReader AppState m, MonadThrow m)
|
||||||
=> GHCTargetVersion
|
=> GHCTargetVersion
|
||||||
-> m (Path Abs)
|
-> m FilePath
|
||||||
ghcupGHCDir ver = do
|
ghcupGHCDir ver = do
|
||||||
ghcbasedir <- ghcupGHCBaseDir
|
ghcbasedir <- ghcupGHCBaseDir
|
||||||
verdir <- parseRel $ E.encodeUtf8 (tVerToText ver)
|
let verdir = T.unpack $ tVerToText ver
|
||||||
pure (ghcbasedir </> verdir)
|
pure (ghcbasedir </> verdir)
|
||||||
|
|
||||||
|
|
||||||
-- | See 'ghcupToolParser'.
|
-- | See 'ghcupToolParser'.
|
||||||
parseGHCupGHCDir :: MonadThrow m => Path Rel -> m GHCTargetVersion
|
parseGHCupGHCDir :: MonadThrow m => FilePath -> m GHCTargetVersion
|
||||||
parseGHCupGHCDir (toFilePath -> f) = do
|
parseGHCupGHCDir (T.pack -> fp) =
|
||||||
fp <- throwEither $ E.decodeUtf8' f
|
|
||||||
throwEither $ MP.parse ghcTargetVerP "" fp
|
throwEither $ MP.parse ghcTargetVerP "" fp
|
||||||
|
|
||||||
|
|
||||||
mkGhcupTmpDir :: (MonadUnliftIO m, MonadLogger m, MonadCatch m, MonadThrow m, MonadIO m) => m (Path Abs)
|
mkGhcupTmpDir :: (MonadUnliftIO m, MonadLogger m, MonadCatch m, MonadThrow m, MonadIO m) => m FilePath
|
||||||
mkGhcupTmpDir = do
|
mkGhcupTmpDir = do
|
||||||
tmpdir <- liftIO $ getEnvDefault "TMPDIR" "/tmp"
|
tmpdir <- liftIO getCanonicalTemporaryDirectory
|
||||||
let fp = T.unpack $ decUTF8Safe tmpdir
|
|
||||||
|
|
||||||
let minSpace = 5000 -- a rough guess, aight?
|
let minSpace = 5000 -- a rough guess, aight?
|
||||||
space <- handleIO (\_ -> pure Nothing) $ fmap Just $ liftIO $ getAvailSpace fp
|
space <- handleIO (\_ -> pure Nothing) $ fmap Just $ liftIO $ getAvailSpace tmpdir
|
||||||
when (maybe False (toBytes minSpace >) space) $ do
|
when (maybe False (toBytes minSpace >) space) $ do
|
||||||
$(logWarn) [i|Possibly insufficient disk space on #{fp}. At least #{minSpace} MB are recommended, but only #{toMB (fromJust space)} are free. Consider freeing up disk space or setting TMPDIR env variable.|]
|
$(logWarn) [i|Possibly insufficient disk space on #{tmpdir}. At least #{minSpace} MB are recommended, but only #{toMB (fromJust space)} are free. Consider freeing up disk space or setting TMPDIR env variable.|]
|
||||||
$(logWarn)
|
$(logWarn)
|
||||||
"...waiting for 10 seconds before continuing anyway, you can still abort..."
|
"...waiting for 10 seconds before continuing anyway, you can still abort..."
|
||||||
liftIO $ threadDelay 10000000 -- give the user a sec to intervene
|
liftIO $ threadDelay 10000000 -- give the user a sec to intervene
|
||||||
|
|
||||||
tmp <- liftIO $ mkdtemp (tmpdir FP.</> "ghcup-")
|
liftIO $ createTempDirectory tmpdir "ghcup"
|
||||||
parseAbs tmp
|
|
||||||
where
|
where
|
||||||
toBytes mb = mb * 1024 * 1024
|
toBytes mb = mb * 1024 * 1024
|
||||||
toMB b = show (truncate' (fromIntegral b / (1024 * 1024) :: Double) 2)
|
toMB b = show (truncate' (fromIntegral b / (1024 * 1024) :: Double) 2)
|
||||||
@@ -256,8 +272,8 @@ mkGhcupTmpDir = do
|
|||||||
where t = 10^n
|
where t = 10^n
|
||||||
|
|
||||||
|
|
||||||
withGHCupTmpDir :: (MonadUnliftIO m, MonadLogger m, MonadCatch m, MonadResource m, MonadThrow m, MonadIO m) => m (Path Abs)
|
withGHCupTmpDir :: (MonadUnliftIO m, MonadLogger m, MonadCatch m, MonadResource m, MonadThrow m, MonadIO m) => m FilePath
|
||||||
withGHCupTmpDir = snd <$> withRunInIO (\run -> run $ allocate (run mkGhcupTmpDir) deleteDirRecursive)
|
withGHCupTmpDir = snd <$> withRunInIO (\run -> run $ allocate (run mkGhcupTmpDir) rmPath)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -267,29 +283,21 @@ withGHCupTmpDir = snd <$> withRunInIO (\run -> run $ allocate (run mkGhcupTmpDir
|
|||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
|
||||||
getHomeDirectory :: IO (Path Abs)
|
#if !defined(IS_WINDOWS)
|
||||||
getHomeDirectory = do
|
|
||||||
e <- getEnv "HOME"
|
|
||||||
case e of
|
|
||||||
Just fp -> parseAbs fp
|
|
||||||
Nothing -> do
|
|
||||||
h <- PU.homeDirectory <$> (PU.getEffectiveUserID >>= PU.getUserEntryForID)
|
|
||||||
parseAbs $ UTF8.fromString h -- this is a guess
|
|
||||||
|
|
||||||
|
|
||||||
useXDG :: IO Bool
|
useXDG :: IO Bool
|
||||||
useXDG = isJust <$> getEnv "GHCUP_USE_XDG_DIRS"
|
useXDG = isJust <$> lookupEnv "GHCUP_USE_XDG_DIRS"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
relativeSymlink :: Path Abs -- ^ the path in which to create the symlink
|
relativeSymlink :: FilePath -- ^ the path in which to create the symlink
|
||||||
-> Path Abs -- ^ the symlink destination
|
-> FilePath -- ^ the symlink destination
|
||||||
-> ByteString
|
-> FilePath
|
||||||
relativeSymlink (toFilePath -> p1) (toFilePath -> p2) =
|
relativeSymlink p1 p2 =
|
||||||
let d1 = splitDirectories p1
|
let d1 = splitDirectories p1
|
||||||
d2 = splitDirectories p2
|
d2 = splitDirectories p2
|
||||||
common = takeWhile (\(x, y) -> x == y) $ zip d1 d2
|
common = takeWhile (\(x, y) -> x == y) $ zip d1 d2
|
||||||
cPrefix = drop (length common) d1
|
cPrefix = drop (length common) d1
|
||||||
in joinPath (replicate (length cPrefix) "..")
|
in joinPath (replicate (length cPrefix) "..")
|
||||||
<> joinPath ("/" : drop (length common) d2)
|
<> joinPath ([pathSeparator] : drop (length common) d2)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,494 +1,17 @@
|
|||||||
{-# LANGUAGE QuasiQuotes #-}
|
{-# LANGUAGE CPP #-}
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
module GHCup.Utils.File (
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
module GHCup.Utils.File.Common,
|
||||||
{-# LANGUAGE ViewPatterns #-}
|
#if IS_WINDOWS
|
||||||
|
module GHCup.Utils.File.Windows
|
||||||
{-|
|
#else
|
||||||
Module : GHCup.Utils.File
|
module GHCup.Utils.File.Posix
|
||||||
Description : File and unix APIs
|
#endif
|
||||||
Copyright : (c) Julian Ospald, 2020
|
) where
|
||||||
License : LGPL-3.0
|
|
||||||
Maintainer : hasufell@hasufell.de
|
import GHCup.Utils.File.Common
|
||||||
Stability : experimental
|
#if IS_WINDOWS
|
||||||
Portability : POSIX
|
import GHCup.Utils.File.Windows
|
||||||
|
#else
|
||||||
This module handles file and executable handling.
|
import GHCup.Utils.File.Posix
|
||||||
Some of these functions use sophisticated logging.
|
#endif
|
||||||
-}
|
|
||||||
module GHCup.Utils.File where
|
|
||||||
|
|
||||||
import GHCup.Utils.Prelude
|
|
||||||
import GHCup.Types
|
|
||||||
|
|
||||||
import Control.Concurrent
|
|
||||||
import Control.Concurrent.Async
|
|
||||||
import Control.Exception ( evaluate )
|
|
||||||
import Control.Exception.Safe
|
|
||||||
import Control.Monad
|
|
||||||
import Control.Monad.Logger
|
|
||||||
import Control.Monad.Reader
|
|
||||||
import Control.Monad.Trans.State.Strict
|
|
||||||
import Data.ByteString ( ByteString )
|
|
||||||
import Data.Foldable
|
|
||||||
import Data.Functor
|
|
||||||
import Data.IORef
|
|
||||||
import Data.Maybe
|
|
||||||
import Data.Sequence ( Seq, (|>) )
|
|
||||||
import Data.String.Interpolate
|
|
||||||
import Data.Text ( Text )
|
|
||||||
import Data.Void
|
|
||||||
import Data.Word8
|
|
||||||
import GHC.IO.Exception
|
|
||||||
import HPath
|
|
||||||
import HPath.IO hiding ( hideError )
|
|
||||||
import Optics hiding ((<|), (|>))
|
|
||||||
import System.Console.Pretty hiding ( Pretty )
|
|
||||||
import System.Console.Regions
|
|
||||||
import System.IO.Error
|
|
||||||
import System.Posix.Directory.ByteString
|
|
||||||
import System.Posix.FD as FD
|
|
||||||
import System.Posix.FilePath hiding ( (</>) )
|
|
||||||
import System.Posix.Files.ByteString
|
|
||||||
import System.Posix.Foreign ( oExcl, oAppend )
|
|
||||||
import "unix" System.Posix.IO.ByteString
|
|
||||||
hiding ( openFd )
|
|
||||||
import System.Posix.Process ( ProcessStatus(..) )
|
|
||||||
import System.Posix.Types
|
|
||||||
import Text.PrettyPrint.HughesPJClass hiding ( (<>) )
|
|
||||||
import Text.Regex.Posix
|
|
||||||
|
|
||||||
|
|
||||||
import qualified Control.Exception as EX
|
|
||||||
import qualified Data.Sequence as Sq
|
|
||||||
import qualified Data.Text as T
|
|
||||||
import qualified Data.Text.Encoding as E
|
|
||||||
import qualified System.Posix.Process.ByteString
|
|
||||||
as SPPB
|
|
||||||
import Streamly.External.Posix.DirStream
|
|
||||||
import qualified Streamly.Prelude as S
|
|
||||||
import qualified Text.Megaparsec as MP
|
|
||||||
import qualified Data.ByteString as BS
|
|
||||||
import qualified "unix-bytestring" System.Posix.IO.ByteString
|
|
||||||
as SPIB
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
data ProcessError = NonZeroExit Int ByteString [ByteString]
|
|
||||||
| PTerminated ByteString [ByteString]
|
|
||||||
| PStopped ByteString [ByteString]
|
|
||||||
| NoSuchPid ByteString [ByteString]
|
|
||||||
deriving Show
|
|
||||||
|
|
||||||
instance Pretty ProcessError where
|
|
||||||
pPrint (NonZeroExit e exe args) =
|
|
||||||
text [i|Process "#{decUTF8Safe exe}" with arguments #{fmap decUTF8Safe args} failed with exit code #{e}.|]
|
|
||||||
pPrint (PTerminated exe args) =
|
|
||||||
text [i|Process "#{decUTF8Safe exe}" with arguments #{fmap decUTF8Safe args} terminated.|]
|
|
||||||
pPrint (PStopped exe args) =
|
|
||||||
text [i|Process "#{decUTF8Safe exe}" with arguments #{fmap decUTF8Safe args} stopped.|]
|
|
||||||
pPrint (NoSuchPid exe args) =
|
|
||||||
text [i|Could not find PID for process running "#{decUTF8Safe exe}" with arguments #{fmap decUTF8Safe args}.|]
|
|
||||||
|
|
||||||
data CapturedProcess = CapturedProcess
|
|
||||||
{ _exitCode :: ExitCode
|
|
||||||
, _stdOut :: ByteString
|
|
||||||
, _stdErr :: ByteString
|
|
||||||
}
|
|
||||||
deriving (Eq, Show)
|
|
||||||
|
|
||||||
makeLenses ''CapturedProcess
|
|
||||||
|
|
||||||
|
|
||||||
-- | Find the given executable by searching all *absolute* PATH components.
|
|
||||||
-- Relative paths in PATH are ignored.
|
|
||||||
--
|
|
||||||
-- This shouldn't throw IO exceptions, unless getting the environment variable
|
|
||||||
-- PATH does.
|
|
||||||
findExecutable :: Path Rel -> IO (Maybe (Path Abs))
|
|
||||||
findExecutable ex = do
|
|
||||||
sPaths <- fmap (catMaybes . fmap parseAbs) getSearchPath
|
|
||||||
-- We don't want exceptions to mess up our result. If we can't
|
|
||||||
-- figure out if a file exists, then treat it as a negative result.
|
|
||||||
asum $ fmap
|
|
||||||
(handleIO (\_ -> pure Nothing)
|
|
||||||
-- asum for short-circuiting behavior
|
|
||||||
. (\s' -> (isExecutable (s' </> ex) >>= guard) $> Just (s' </> ex))
|
|
||||||
)
|
|
||||||
sPaths
|
|
||||||
|
|
||||||
|
|
||||||
-- | Execute the given command and collect the stdout, stderr and the exit code.
|
|
||||||
-- The command is run in a subprocess.
|
|
||||||
executeOut :: Path b -- ^ command as filename, e.g. 'ls'
|
|
||||||
-> [ByteString] -- ^ arguments to the command
|
|
||||||
-> Maybe (Path Abs) -- ^ chdir to this path
|
|
||||||
-> IO CapturedProcess
|
|
||||||
executeOut path args chdir = captureOutStreams $ do
|
|
||||||
maybe (pure ()) (changeWorkingDirectory . toFilePath) chdir
|
|
||||||
SPPB.executeFile (toFilePath path) True args Nothing
|
|
||||||
|
|
||||||
|
|
||||||
execLogged :: (MonadReader AppState m, MonadIO m, MonadThrow m)
|
|
||||||
=> ByteString -- ^ thing to execute
|
|
||||||
-> Bool -- ^ whether to search PATH for the thing
|
|
||||||
-> [ByteString] -- ^ args for the thing
|
|
||||||
-> Path Rel -- ^ log filename (opened in append mode)
|
|
||||||
-> Maybe (Path Abs) -- ^ optionally chdir into this
|
|
||||||
-> Maybe [(ByteString, ByteString)] -- ^ optional environment
|
|
||||||
-> m (Either ProcessError ())
|
|
||||||
execLogged exe spath args lfile chdir env = do
|
|
||||||
AppState { settings = Settings {..}, dirs = Dirs {..} } <- ask
|
|
||||||
logfile <- (logsDir </>) <$> parseRel (toFilePath lfile <> ".log")
|
|
||||||
liftIO $ bracket (openFd (toFilePath logfile) WriteOnly [oAppend] (Just newFilePerms))
|
|
||||||
closeFd
|
|
||||||
(action verbose)
|
|
||||||
where
|
|
||||||
action verbose fd = do
|
|
||||||
actionWithPipes $ \(stdoutRead, stdoutWrite) -> do
|
|
||||||
-- start the thread that logs to stdout
|
|
||||||
pState <- newEmptyMVar
|
|
||||||
done <- newEmptyMVar
|
|
||||||
void
|
|
||||||
$ forkIO
|
|
||||||
$ EX.handle (\(_ :: IOException) -> pure ())
|
|
||||||
$ EX.finally
|
|
||||||
(if verbose
|
|
||||||
then tee fd stdoutRead
|
|
||||||
else printToRegion fd stdoutRead 6 pState
|
|
||||||
)
|
|
||||||
(putMVar done ())
|
|
||||||
|
|
||||||
-- fork the subprocess
|
|
||||||
pid <- SPPB.forkProcess $ do
|
|
||||||
void $ dupTo stdoutWrite stdOutput
|
|
||||||
void $ dupTo stdoutWrite stdError
|
|
||||||
closeFd stdoutRead
|
|
||||||
closeFd stdoutWrite
|
|
||||||
|
|
||||||
-- execute the action
|
|
||||||
maybe (pure ()) (changeWorkingDirectory . toFilePath) chdir
|
|
||||||
void $ SPPB.executeFile exe spath args env
|
|
||||||
|
|
||||||
closeFd stdoutWrite
|
|
||||||
|
|
||||||
-- wait for the subprocess to finish
|
|
||||||
e <- toProcessError exe args <$!> SPPB.getProcessStatus True True pid
|
|
||||||
putMVar pState (either (const False) (const True) e)
|
|
||||||
|
|
||||||
void $ race (takeMVar done) (threadDelay (1000000 * 3))
|
|
||||||
closeFd stdoutRead
|
|
||||||
|
|
||||||
pure e
|
|
||||||
|
|
||||||
tee :: Fd -> Fd -> IO ()
|
|
||||||
tee fileFd fdIn = readTilEOF lineAction fdIn
|
|
||||||
|
|
||||||
where
|
|
||||||
lineAction :: ByteString -> IO ()
|
|
||||||
lineAction bs' = do
|
|
||||||
void $ SPIB.fdWrite fileFd (bs' <> "\n")
|
|
||||||
void $ SPIB.fdWrite stdOutput (bs' <> "\n")
|
|
||||||
|
|
||||||
-- Reads fdIn and logs the output in a continous scrolling area
|
|
||||||
-- of 'size' terminal lines. Also writes to a log file.
|
|
||||||
printToRegion :: Fd -> Fd -> Int -> MVar Bool -> IO ()
|
|
||||||
printToRegion fileFd fdIn size pState = do
|
|
||||||
void $ displayConsoleRegions $ do
|
|
||||||
rs <-
|
|
||||||
liftIO
|
|
||||||
. fmap Sq.fromList
|
|
||||||
. sequence
|
|
||||||
. replicate size
|
|
||||||
. openConsoleRegion
|
|
||||||
$ Linear
|
|
||||||
flip runStateT mempty
|
|
||||||
$ handle
|
|
||||||
(\(ex :: SomeException) -> do
|
|
||||||
ps <- liftIO $ takeMVar pState
|
|
||||||
when ps (forM_ rs (liftIO . closeConsoleRegion))
|
|
||||||
throw ex
|
|
||||||
)
|
|
||||||
$ readTilEOF (lineAction rs) fdIn
|
|
||||||
|
|
||||||
where
|
|
||||||
-- action to perform line by line
|
|
||||||
-- TODO: do this with vty for efficiency
|
|
||||||
lineAction :: (MonadMask m, MonadIO m)
|
|
||||||
=> Seq ConsoleRegion
|
|
||||||
-> ByteString
|
|
||||||
-> StateT (Seq ByteString) m ()
|
|
||||||
lineAction rs = \bs' -> do
|
|
||||||
void $ liftIO $ SPIB.fdWrite fileFd (bs' <> "\n")
|
|
||||||
modify (swapRegs bs')
|
|
||||||
regs <- get
|
|
||||||
liftIO $ forM_ (Sq.zip regs rs) $ \(bs, r) -> setConsoleRegion r $ do
|
|
||||||
w <- consoleWidth
|
|
||||||
return
|
|
||||||
. T.pack
|
|
||||||
. color Blue
|
|
||||||
. T.unpack
|
|
||||||
. decUTF8Safe
|
|
||||||
. trim w
|
|
||||||
. (\b -> "[ " <> toFilePath lfile <> " ] " <> b)
|
|
||||||
$ bs
|
|
||||||
|
|
||||||
swapRegs :: a -> Seq a -> Seq a
|
|
||||||
swapRegs bs = \regs -> if
|
|
||||||
| Sq.length regs < size -> regs |> bs
|
|
||||||
| otherwise -> Sq.drop 1 regs |> bs
|
|
||||||
|
|
||||||
-- trim output line to terminal width
|
|
||||||
trim :: Int -> ByteString -> ByteString
|
|
||||||
trim w = \bs -> if
|
|
||||||
| BS.length bs > w && w > 5 -> BS.take (w - 4) bs <> "..."
|
|
||||||
| otherwise -> bs
|
|
||||||
|
|
||||||
-- Consecutively read from Fd in 512 chunks until we hit
|
|
||||||
-- newline or EOF.
|
|
||||||
readLine :: MonadIO m
|
|
||||||
=> Fd -- ^ input file descriptor
|
|
||||||
-> ByteString -- ^ rest buffer (read across newline)
|
|
||||||
-> m (ByteString, ByteString, Bool) -- ^ (full line, rest, eof)
|
|
||||||
readLine fd = go
|
|
||||||
where
|
|
||||||
go inBs = do
|
|
||||||
-- if buffer is not empty, process it first
|
|
||||||
mbs <- if BS.length inBs == 0
|
|
||||||
-- otherwise attempt read
|
|
||||||
then liftIO
|
|
||||||
$ handleIO (\e -> if isEOFError e then pure Nothing else ioError e)
|
|
||||||
$ fmap Just
|
|
||||||
$ SPIB.fdRead fd 512
|
|
||||||
else pure $ Just inBs
|
|
||||||
case mbs of
|
|
||||||
Nothing -> pure ("", "", True)
|
|
||||||
Just bs -> do
|
|
||||||
-- split on newline
|
|
||||||
let (line, rest) = BS.span (/= _lf) bs
|
|
||||||
if
|
|
||||||
| BS.length rest /= 0 -> pure (line, BS.tail rest, False)
|
|
||||||
-- if rest is empty, then there was no newline, process further
|
|
||||||
| otherwise -> (\(l, r, b) -> (line <> l, r, b)) <$!> go mempty
|
|
||||||
|
|
||||||
readTilEOF :: MonadIO m => (ByteString -> m a) -> Fd -> m ()
|
|
||||||
readTilEOF ~action' fd' = go mempty
|
|
||||||
where
|
|
||||||
go bs' = do
|
|
||||||
(bs, rest, eof) <- readLine fd' bs'
|
|
||||||
if eof
|
|
||||||
then liftIO $ ioError (mkIOError eofErrorType "" Nothing Nothing)
|
|
||||||
else void (action' bs) >> go rest
|
|
||||||
|
|
||||||
|
|
||||||
-- | Capture the stdout and stderr of the given action, which
|
|
||||||
-- is run in a subprocess. Stdin is closed. You might want to
|
|
||||||
-- 'race' this to make sure it terminates.
|
|
||||||
captureOutStreams :: IO a
|
|
||||||
-- ^ the action to execute in a subprocess
|
|
||||||
-> IO CapturedProcess
|
|
||||||
captureOutStreams action = do
|
|
||||||
actionWithPipes $ \(parentStdoutRead, childStdoutWrite) ->
|
|
||||||
actionWithPipes $ \(parentStderrRead, childStderrWrite) -> do
|
|
||||||
pid <- SPPB.forkProcess $ do
|
|
||||||
-- dup stdout
|
|
||||||
void $ dupTo childStdoutWrite stdOutput
|
|
||||||
closeFd childStdoutWrite
|
|
||||||
closeFd parentStdoutRead
|
|
||||||
|
|
||||||
-- dup stderr
|
|
||||||
void $ dupTo childStderrWrite stdError
|
|
||||||
closeFd childStderrWrite
|
|
||||||
closeFd parentStderrRead
|
|
||||||
|
|
||||||
-- execute the action
|
|
||||||
a <- action
|
|
||||||
void $ evaluate a
|
|
||||||
|
|
||||||
-- close everything we don't need
|
|
||||||
closeFd childStdoutWrite
|
|
||||||
closeFd childStderrWrite
|
|
||||||
|
|
||||||
-- start thread that writes the output
|
|
||||||
refOut <- newIORef BS.empty
|
|
||||||
refErr <- newIORef BS.empty
|
|
||||||
done <- newEmptyMVar
|
|
||||||
_ <-
|
|
||||||
forkIO
|
|
||||||
$ EX.handle (\(_ :: IOException) -> pure ())
|
|
||||||
$ flip EX.finally (putMVar done ())
|
|
||||||
$ writeStds parentStdoutRead parentStderrRead refOut refErr
|
|
||||||
|
|
||||||
status <- SPPB.getProcessStatus True True pid
|
|
||||||
void $ race (takeMVar done) (threadDelay (1000000 * 3))
|
|
||||||
|
|
||||||
case status of
|
|
||||||
-- readFd will take care of closing the fd
|
|
||||||
Just (SPPB.Exited es) -> do
|
|
||||||
stdout' <- readIORef refOut
|
|
||||||
stderr' <- readIORef refErr
|
|
||||||
pure $ CapturedProcess { _exitCode = es
|
|
||||||
, _stdOut = stdout'
|
|
||||||
, _stdErr = stderr'
|
|
||||||
}
|
|
||||||
|
|
||||||
_ -> throwIO $ userError ("No such PID " ++ show pid)
|
|
||||||
|
|
||||||
where
|
|
||||||
writeStds pout perr rout rerr = do
|
|
||||||
doneOut <- newEmptyMVar
|
|
||||||
void
|
|
||||||
$ forkIO
|
|
||||||
$ hideError eofErrorType
|
|
||||||
$ flip EX.finally (putMVar doneOut ())
|
|
||||||
$ readTilEOF (\x -> modifyIORef' rout (<> x)) pout
|
|
||||||
doneErr <- newEmptyMVar
|
|
||||||
void
|
|
||||||
$ forkIO
|
|
||||||
$ hideError eofErrorType
|
|
||||||
$ flip EX.finally (putMVar doneErr ())
|
|
||||||
$ readTilEOF (\x -> modifyIORef' rerr (<> x)) perr
|
|
||||||
takeMVar doneOut
|
|
||||||
takeMVar doneErr
|
|
||||||
|
|
||||||
readTilEOF ~action' fd' = do
|
|
||||||
bs <- SPIB.fdRead fd' 512
|
|
||||||
void $ action' bs
|
|
||||||
readTilEOF action' fd'
|
|
||||||
|
|
||||||
|
|
||||||
actionWithPipes :: ((Fd, Fd) -> IO b) -> IO b
|
|
||||||
actionWithPipes a =
|
|
||||||
createPipe >>= \(p1, p2) -> flip finally (cleanup [p1, p2]) $ a (p1, p2)
|
|
||||||
|
|
||||||
cleanup :: [Fd] -> IO ()
|
|
||||||
cleanup fds = for_ fds $ \fd -> handleIO (\_ -> pure ()) $ closeFd fd
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- | Create a new regular file in write-only mode. The file must not exist.
|
|
||||||
createRegularFileFd :: FileMode -> Path b -> IO Fd
|
|
||||||
createRegularFileFd fm dest =
|
|
||||||
FD.openFd (toFilePath dest) WriteOnly [oExcl] (Just fm)
|
|
||||||
|
|
||||||
|
|
||||||
-- | Thin wrapper around `executeFile`.
|
|
||||||
exec :: ByteString -- ^ thing to execute
|
|
||||||
-> Bool -- ^ whether to search PATH for the thing
|
|
||||||
-> [ByteString] -- ^ args for the thing
|
|
||||||
-> Maybe (Path Abs) -- ^ optionally chdir into this
|
|
||||||
-> Maybe [(ByteString, ByteString)] -- ^ optional environment
|
|
||||||
-> IO (Either ProcessError ())
|
|
||||||
exec exe spath args chdir env = do
|
|
||||||
pid <- SPPB.forkProcess $ do
|
|
||||||
maybe (pure ()) (changeWorkingDirectory . toFilePath) chdir
|
|
||||||
SPPB.executeFile exe spath args env
|
|
||||||
|
|
||||||
fmap (toProcessError exe args) $ SPPB.getProcessStatus True True pid
|
|
||||||
|
|
||||||
|
|
||||||
toProcessError :: ByteString
|
|
||||||
-> [ByteString]
|
|
||||||
-> Maybe ProcessStatus
|
|
||||||
-> Either ProcessError ()
|
|
||||||
toProcessError exe args mps = case mps of
|
|
||||||
Just (SPPB.Exited (ExitFailure xi)) -> Left $ NonZeroExit xi exe args
|
|
||||||
Just (SPPB.Exited ExitSuccess ) -> Right ()
|
|
||||||
Just (Terminated _ _ ) -> Left $ PTerminated exe args
|
|
||||||
Just (Stopped _ ) -> Left $ PStopped exe args
|
|
||||||
Nothing -> Left $ NoSuchPid exe args
|
|
||||||
|
|
||||||
|
|
||||||
-- | Search for a file in the search paths.
|
|
||||||
--
|
|
||||||
-- Catches `PermissionDenied` and `NoSuchThing` and returns `Nothing`.
|
|
||||||
searchPath :: [Path Abs] -> Path Rel -> IO (Maybe (Path Abs))
|
|
||||||
searchPath paths needle = go paths
|
|
||||||
where
|
|
||||||
go [] = pure Nothing
|
|
||||||
go (x : xs) =
|
|
||||||
hideErrorDefM [InappropriateType, PermissionDenied, NoSuchThing] (go xs)
|
|
||||||
$ do
|
|
||||||
dirStream <- openDirStream (toFilePath x)
|
|
||||||
S.findM (\(_, p) -> isMatch x p) (dirContentsStream dirStream)
|
|
||||||
>>= \case
|
|
||||||
Just _ -> pure $ Just (x </> needle)
|
|
||||||
Nothing -> go xs
|
|
||||||
isMatch basedir p = do
|
|
||||||
if p == toFilePath needle
|
|
||||||
then isExecutable (basedir </> needle)
|
|
||||||
else pure False
|
|
||||||
|
|
||||||
|
|
||||||
-- | Check wether a binary is shadowed by another one that comes before
|
|
||||||
-- it in PATH. Returns the path to said binary, if any.
|
|
||||||
isShadowed :: Path Abs -> IO (Maybe (Path Abs))
|
|
||||||
isShadowed p = do
|
|
||||||
let dir = dirname p
|
|
||||||
fn <- basename p
|
|
||||||
spaths <- catMaybes . fmap parseAbs <$> liftIO getSearchPath
|
|
||||||
if dir `elem` spaths
|
|
||||||
then do
|
|
||||||
let shadowPaths = takeWhile (/= dir) spaths
|
|
||||||
searchPath shadowPaths fn
|
|
||||||
else pure Nothing
|
|
||||||
|
|
||||||
|
|
||||||
-- | Check whether the binary is in PATH. This returns only `True`
|
|
||||||
-- if the directory containing the binary is part of PATH.
|
|
||||||
isInPath :: Path Abs -> IO Bool
|
|
||||||
isInPath p = do
|
|
||||||
let dir = dirname p
|
|
||||||
fn <- basename p
|
|
||||||
spaths <- catMaybes . fmap parseAbs <$> liftIO getSearchPath
|
|
||||||
if dir `elem` spaths
|
|
||||||
then isJust <$> searchPath [dir] fn
|
|
||||||
else pure False
|
|
||||||
|
|
||||||
|
|
||||||
findFiles :: Path Abs -> Regex -> IO [Path Rel]
|
|
||||||
findFiles path regex = do
|
|
||||||
dirStream <- openDirStream (toFilePath path)
|
|
||||||
f <-
|
|
||||||
(fmap . fmap) snd
|
|
||||||
. S.toList
|
|
||||||
. S.filter (\(_, p) -> match regex p)
|
|
||||||
$ dirContentsStream dirStream
|
|
||||||
pure $ parseRel =<< f
|
|
||||||
|
|
||||||
|
|
||||||
findFiles' :: Path Abs -> MP.Parsec Void Text () -> IO [Path Rel]
|
|
||||||
findFiles' path parser = do
|
|
||||||
dirStream <- openDirStream (toFilePath path)
|
|
||||||
f <-
|
|
||||||
(fmap . fmap) snd
|
|
||||||
. S.toList
|
|
||||||
. S.filter (\(_, p) -> case E.decodeUtf8' p of
|
|
||||||
Left _ -> False
|
|
||||||
Right p' -> isJust $ MP.parseMaybe parser p')
|
|
||||||
$ dirContentsStream dirStream
|
|
||||||
pure $ parseRel =<< f
|
|
||||||
|
|
||||||
|
|
||||||
isBrokenSymlink :: Path Abs -> IO Bool
|
|
||||||
isBrokenSymlink p =
|
|
||||||
handleIO
|
|
||||||
(\e -> if ioeGetErrorType e == NoSuchThing then pure True else throwIO e)
|
|
||||||
$ do
|
|
||||||
_ <- canonicalizePath p
|
|
||||||
pure False
|
|
||||||
|
|
||||||
|
|
||||||
chmod_755 :: (MonadLogger m, MonadIO m) => Path a -> m ()
|
|
||||||
chmod_755 (toFilePath -> fp) = do
|
|
||||||
let exe_mode =
|
|
||||||
nullFileMode
|
|
||||||
`unionFileModes` ownerExecuteMode
|
|
||||||
`unionFileModes` ownerReadMode
|
|
||||||
`unionFileModes` ownerWriteMode
|
|
||||||
`unionFileModes` groupExecuteMode
|
|
||||||
`unionFileModes` groupReadMode
|
|
||||||
`unionFileModes` otherExecuteMode
|
|
||||||
`unionFileModes` otherReadMode
|
|
||||||
$(logDebug) [i|chmod 755 #{fp}|]
|
|
||||||
liftIO $ setFileMode fp exe_mode
|
|
||||||
|
|||||||
106
lib/GHCup/Utils/File/Common.hs
Normal file
106
lib/GHCup/Utils/File/Common.hs
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
{-# LANGUAGE ViewPatterns #-}
|
||||||
|
|
||||||
|
module GHCup.Utils.File.Common where
|
||||||
|
|
||||||
|
import GHCup.Utils.Prelude
|
||||||
|
|
||||||
|
import Control.Monad.Extra
|
||||||
|
import Control.Monad.Reader
|
||||||
|
import Data.Maybe
|
||||||
|
import Data.String.Interpolate
|
||||||
|
import GHC.IO.Exception
|
||||||
|
import Optics hiding ((<|), (|>))
|
||||||
|
import System.Directory
|
||||||
|
import System.FilePath
|
||||||
|
import Text.PrettyPrint.HughesPJClass hiding ( (<>) )
|
||||||
|
import Text.Regex.Posix
|
||||||
|
|
||||||
|
import qualified Data.ByteString.Lazy as BL
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
data ProcessError = NonZeroExit Int FilePath [String]
|
||||||
|
| PTerminated FilePath [String]
|
||||||
|
| PStopped FilePath [String]
|
||||||
|
| NoSuchPid FilePath [String]
|
||||||
|
deriving Show
|
||||||
|
|
||||||
|
instance Pretty ProcessError where
|
||||||
|
pPrint (NonZeroExit e exe args) =
|
||||||
|
text [i|Process "#{exe}" with arguments #{args} failed with exit code #{e}.|]
|
||||||
|
pPrint (PTerminated exe args) =
|
||||||
|
text [i|Process "#{exe}" with arguments #{args} terminated.|]
|
||||||
|
pPrint (PStopped exe args) =
|
||||||
|
text [i|Process "#{exe}" with arguments #{args} stopped.|]
|
||||||
|
pPrint (NoSuchPid exe args) =
|
||||||
|
text [i|Could not find PID for process running "#{exe}" with arguments #{args}.|]
|
||||||
|
|
||||||
|
data CapturedProcess = CapturedProcess
|
||||||
|
{ _exitCode :: ExitCode
|
||||||
|
, _stdOut :: BL.ByteString
|
||||||
|
, _stdErr :: BL.ByteString
|
||||||
|
}
|
||||||
|
deriving (Eq, Show)
|
||||||
|
|
||||||
|
makeLenses ''CapturedProcess
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- | Search for a file in the search paths.
|
||||||
|
--
|
||||||
|
-- Catches `PermissionDenied` and `NoSuchThing` and returns `Nothing`.
|
||||||
|
searchPath :: [FilePath] -> FilePath -> IO (Maybe FilePath)
|
||||||
|
searchPath paths needle = go paths
|
||||||
|
where
|
||||||
|
go [] = pure Nothing
|
||||||
|
go (x : xs) =
|
||||||
|
hideErrorDefM [InappropriateType, PermissionDenied, NoSuchThing] (go xs)
|
||||||
|
$ do
|
||||||
|
contents <- listDirectory x
|
||||||
|
findM (isMatch x) contents >>= \case
|
||||||
|
Just _ -> pure $ Just (x </> needle)
|
||||||
|
Nothing -> go xs
|
||||||
|
isMatch basedir p = do
|
||||||
|
if p == needle
|
||||||
|
then isExecutable (basedir </> needle)
|
||||||
|
else pure False
|
||||||
|
|
||||||
|
isExecutable :: FilePath -> IO Bool
|
||||||
|
isExecutable file = executable <$> getPermissions file
|
||||||
|
|
||||||
|
|
||||||
|
-- | Check wether a binary is shadowed by another one that comes before
|
||||||
|
-- it in PATH. Returns the path to said binary, if any.
|
||||||
|
isShadowed :: FilePath -> IO (Maybe FilePath)
|
||||||
|
isShadowed p = do
|
||||||
|
let dir = takeDirectory p
|
||||||
|
let fn = takeFileName p
|
||||||
|
spaths <- liftIO getSearchPath
|
||||||
|
if dir `elem` spaths
|
||||||
|
then do
|
||||||
|
let shadowPaths = takeWhile (/= dir) spaths
|
||||||
|
searchPath shadowPaths fn
|
||||||
|
else pure Nothing
|
||||||
|
|
||||||
|
|
||||||
|
-- | Check whether the binary is in PATH. This returns only `True`
|
||||||
|
-- if the directory containing the binary is part of PATH.
|
||||||
|
isInPath :: FilePath -> IO Bool
|
||||||
|
isInPath p = do
|
||||||
|
let dir = takeDirectory p
|
||||||
|
let fn = takeFileName p
|
||||||
|
spaths <- liftIO getSearchPath
|
||||||
|
if dir `elem` spaths
|
||||||
|
then isJust <$> searchPath [dir] fn
|
||||||
|
else pure False
|
||||||
|
|
||||||
|
|
||||||
|
findFiles :: FilePath -> Regex -> IO [FilePath]
|
||||||
|
findFiles path regex = do
|
||||||
|
contents <- listDirectory path
|
||||||
|
pure $ filter (match regex) contents
|
||||||
|
|
||||||
386
lib/GHCup/Utils/File/Posix.hs
Normal file
386
lib/GHCup/Utils/File/Posix.hs
Normal file
@@ -0,0 +1,386 @@
|
|||||||
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
{-# LANGUAGE ViewPatterns #-}
|
||||||
|
|
||||||
|
{-|
|
||||||
|
Module : GHCup.Utils.File.Posix
|
||||||
|
Description : File and unix APIs
|
||||||
|
Copyright : (c) Julian Ospald, 2020
|
||||||
|
License : LGPL-3.0
|
||||||
|
Maintainer : hasufell@hasufell.de
|
||||||
|
Stability : experimental
|
||||||
|
Portability : POSIX
|
||||||
|
|
||||||
|
This module handles file and executable handling.
|
||||||
|
Some of these functions use sophisticated logging.
|
||||||
|
-}
|
||||||
|
module GHCup.Utils.File.Posix where
|
||||||
|
|
||||||
|
import GHCup.Utils.File.Common
|
||||||
|
import GHCup.Utils.Prelude
|
||||||
|
import GHCup.Types
|
||||||
|
|
||||||
|
import Control.Concurrent
|
||||||
|
import Control.Concurrent.Async
|
||||||
|
import Control.Exception ( evaluate )
|
||||||
|
import Control.Exception.Safe
|
||||||
|
import Control.Monad
|
||||||
|
import Control.Monad.Logger
|
||||||
|
import Control.Monad.Reader
|
||||||
|
import Control.Monad.Trans.State.Strict
|
||||||
|
import Data.ByteString ( ByteString )
|
||||||
|
import Data.Foldable
|
||||||
|
import Data.IORef
|
||||||
|
import Data.Sequence ( Seq, (|>) )
|
||||||
|
import Data.String.Interpolate
|
||||||
|
import Data.List
|
||||||
|
import Data.Word8
|
||||||
|
import GHC.IO.Exception
|
||||||
|
import System.Console.Pretty hiding ( Pretty )
|
||||||
|
import System.Console.Regions
|
||||||
|
import System.IO.Error
|
||||||
|
import System.FilePath
|
||||||
|
import System.Directory
|
||||||
|
import System.Posix.Directory
|
||||||
|
import System.Posix.Files
|
||||||
|
import System.Posix.IO
|
||||||
|
import System.Posix.Process ( ProcessStatus(..) )
|
||||||
|
import System.Posix.Types
|
||||||
|
|
||||||
|
|
||||||
|
import qualified Control.Exception as EX
|
||||||
|
import qualified Data.Sequence as Sq
|
||||||
|
import qualified Data.Text as T
|
||||||
|
import qualified Data.Text.Encoding as E
|
||||||
|
import qualified System.Posix.Process as SPP
|
||||||
|
import qualified Data.ByteString as BS
|
||||||
|
import qualified Data.ByteString.Lazy as BL
|
||||||
|
import qualified "unix-bytestring" System.Posix.IO.ByteString
|
||||||
|
as SPIB
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- | Execute the given command and collect the stdout, stderr and the exit code.
|
||||||
|
-- The command is run in a subprocess.
|
||||||
|
executeOut :: MonadIO m
|
||||||
|
=> FilePath -- ^ command as filename, e.g. 'ls'
|
||||||
|
-> [String] -- ^ arguments to the command
|
||||||
|
-> Maybe FilePath -- ^ chdir to this path
|
||||||
|
-> m CapturedProcess
|
||||||
|
executeOut path args chdir = liftIO $ captureOutStreams $ do
|
||||||
|
maybe (pure ()) changeWorkingDirectory chdir
|
||||||
|
SPP.executeFile path True args Nothing
|
||||||
|
|
||||||
|
|
||||||
|
execLogged :: (MonadReader AppState m, MonadIO m, MonadThrow m)
|
||||||
|
=> FilePath -- ^ thing to execute
|
||||||
|
-> [String] -- ^ args for the thing
|
||||||
|
-> Maybe FilePath -- ^ optionally chdir into this
|
||||||
|
-> FilePath -- ^ log filename (opened in append mode)
|
||||||
|
-> Maybe [(String, String)] -- ^ optional environment
|
||||||
|
-> m (Either ProcessError ())
|
||||||
|
execLogged exe args chdir lfile env = do
|
||||||
|
AppState { settings = Settings {..}, dirs = Dirs {..} } <- ask
|
||||||
|
let logfile = logsDir </> lfile <> ".log"
|
||||||
|
liftIO $ bracket (openFd logfile WriteOnly (Just newFilePerms) defaultFileFlags{ append = True })
|
||||||
|
closeFd
|
||||||
|
(action verbose)
|
||||||
|
where
|
||||||
|
action verbose fd = do
|
||||||
|
actionWithPipes $ \(stdoutRead, stdoutWrite) -> do
|
||||||
|
-- start the thread that logs to stdout
|
||||||
|
pState <- newEmptyMVar
|
||||||
|
done <- newEmptyMVar
|
||||||
|
void
|
||||||
|
$ forkIO
|
||||||
|
$ EX.handle (\(_ :: IOException) -> pure ())
|
||||||
|
$ EX.finally
|
||||||
|
(if verbose
|
||||||
|
then tee fd stdoutRead
|
||||||
|
else printToRegion fd stdoutRead 6 pState
|
||||||
|
)
|
||||||
|
(putMVar done ())
|
||||||
|
|
||||||
|
-- fork the subprocess
|
||||||
|
pid <- SPP.forkProcess $ do
|
||||||
|
void $ dupTo stdoutWrite stdOutput
|
||||||
|
void $ dupTo stdoutWrite stdError
|
||||||
|
closeFd stdoutRead
|
||||||
|
closeFd stdoutWrite
|
||||||
|
|
||||||
|
-- execute the action
|
||||||
|
maybe (pure ()) changeWorkingDirectory chdir
|
||||||
|
void $ SPP.executeFile exe (not ("./" `isPrefixOf` exe)) args env
|
||||||
|
|
||||||
|
closeFd stdoutWrite
|
||||||
|
|
||||||
|
-- wait for the subprocess to finish
|
||||||
|
e <- toProcessError exe args <$!> SPP.getProcessStatus True True pid
|
||||||
|
putMVar pState (either (const False) (const True) e)
|
||||||
|
|
||||||
|
void $ race (takeMVar done) (threadDelay (1000000 * 3))
|
||||||
|
closeFd stdoutRead
|
||||||
|
|
||||||
|
pure e
|
||||||
|
|
||||||
|
tee :: Fd -> Fd -> IO ()
|
||||||
|
tee fileFd fdIn = readTilEOF lineAction fdIn
|
||||||
|
|
||||||
|
where
|
||||||
|
lineAction :: ByteString -> IO ()
|
||||||
|
lineAction bs' = do
|
||||||
|
void $ SPIB.fdWrite fileFd (bs' <> "\n")
|
||||||
|
void $ SPIB.fdWrite stdOutput (bs' <> "\n")
|
||||||
|
|
||||||
|
-- Reads fdIn and logs the output in a continous scrolling area
|
||||||
|
-- of 'size' terminal lines. Also writes to a log file.
|
||||||
|
printToRegion :: Fd -> Fd -> Int -> MVar Bool -> IO ()
|
||||||
|
printToRegion fileFd fdIn size pState = do
|
||||||
|
void $ displayConsoleRegions $ do
|
||||||
|
rs <-
|
||||||
|
liftIO
|
||||||
|
. fmap Sq.fromList
|
||||||
|
. sequence
|
||||||
|
. replicate size
|
||||||
|
. openConsoleRegion
|
||||||
|
$ Linear
|
||||||
|
flip runStateT mempty
|
||||||
|
$ handle
|
||||||
|
(\(ex :: SomeException) -> do
|
||||||
|
ps <- liftIO $ takeMVar pState
|
||||||
|
when ps (forM_ rs (liftIO . closeConsoleRegion))
|
||||||
|
throw ex
|
||||||
|
)
|
||||||
|
$ readTilEOF (lineAction rs) fdIn
|
||||||
|
|
||||||
|
where
|
||||||
|
-- action to perform line by line
|
||||||
|
-- TODO: do this with vty for efficiency
|
||||||
|
lineAction :: (MonadMask m, MonadIO m)
|
||||||
|
=> Seq ConsoleRegion
|
||||||
|
-> ByteString
|
||||||
|
-> StateT (Seq ByteString) m ()
|
||||||
|
lineAction rs = \bs' -> do
|
||||||
|
void $ liftIO $ SPIB.fdWrite fileFd (bs' <> "\n")
|
||||||
|
modify (swapRegs bs')
|
||||||
|
regs <- get
|
||||||
|
liftIO $ forM_ (Sq.zip regs rs) $ \(bs, r) -> setConsoleRegion r $ do
|
||||||
|
w <- consoleWidth
|
||||||
|
return
|
||||||
|
. T.pack
|
||||||
|
. color Blue
|
||||||
|
. T.unpack
|
||||||
|
. decUTF8Safe
|
||||||
|
. trim w
|
||||||
|
. (\b -> "[ " <> E.encodeUtf8 (T.pack lfile) <> " ] " <> b)
|
||||||
|
$ bs
|
||||||
|
|
||||||
|
swapRegs :: a -> Seq a -> Seq a
|
||||||
|
swapRegs bs = \regs -> if
|
||||||
|
| Sq.length regs < size -> regs |> bs
|
||||||
|
| otherwise -> Sq.drop 1 regs |> bs
|
||||||
|
|
||||||
|
-- trim output line to terminal width
|
||||||
|
trim :: Int -> ByteString -> ByteString
|
||||||
|
trim w = \bs -> if
|
||||||
|
| BS.length bs > w && w > 5 -> BS.take (w - 4) bs <> "..."
|
||||||
|
| otherwise -> bs
|
||||||
|
|
||||||
|
-- Consecutively read from Fd in 512 chunks until we hit
|
||||||
|
-- newline or EOF.
|
||||||
|
readLine :: MonadIO m
|
||||||
|
=> Fd -- ^ input file descriptor
|
||||||
|
-> ByteString -- ^ rest buffer (read across newline)
|
||||||
|
-> m (ByteString, ByteString, Bool) -- ^ (full line, rest, eof)
|
||||||
|
readLine fd = go
|
||||||
|
where
|
||||||
|
go inBs = do
|
||||||
|
-- if buffer is not empty, process it first
|
||||||
|
mbs <- if BS.length inBs == 0
|
||||||
|
-- otherwise attempt read
|
||||||
|
then liftIO
|
||||||
|
$ handleIO (\e -> if isEOFError e then pure Nothing else ioError e)
|
||||||
|
$ fmap Just
|
||||||
|
$ SPIB.fdRead fd 512
|
||||||
|
else pure $ Just inBs
|
||||||
|
case mbs of
|
||||||
|
Nothing -> pure ("", "", True)
|
||||||
|
Just bs -> do
|
||||||
|
-- split on newline
|
||||||
|
let (line, rest) = BS.span (/= _lf) bs
|
||||||
|
if
|
||||||
|
| BS.length rest /= 0 -> pure (line, BS.tail rest, False)
|
||||||
|
-- if rest is empty, then there was no newline, process further
|
||||||
|
| otherwise -> (\(l, r, b) -> (line <> l, r, b)) <$!> go mempty
|
||||||
|
|
||||||
|
readTilEOF :: MonadIO m => (ByteString -> m a) -> Fd -> m ()
|
||||||
|
readTilEOF ~action' fd' = go mempty
|
||||||
|
where
|
||||||
|
go bs' = do
|
||||||
|
(bs, rest, eof) <- readLine fd' bs'
|
||||||
|
if eof
|
||||||
|
then liftIO $ ioError (mkIOError eofErrorType "" Nothing Nothing)
|
||||||
|
else void (action' bs) >> go rest
|
||||||
|
|
||||||
|
|
||||||
|
-- | Capture the stdout and stderr of the given action, which
|
||||||
|
-- is run in a subprocess. Stdin is closed. You might want to
|
||||||
|
-- 'race' this to make sure it terminates.
|
||||||
|
captureOutStreams :: IO a
|
||||||
|
-- ^ the action to execute in a subprocess
|
||||||
|
-> IO CapturedProcess
|
||||||
|
captureOutStreams action = do
|
||||||
|
actionWithPipes $ \(parentStdoutRead, childStdoutWrite) ->
|
||||||
|
actionWithPipes $ \(parentStderrRead, childStderrWrite) -> do
|
||||||
|
pid <- SPP.forkProcess $ do
|
||||||
|
-- dup stdout
|
||||||
|
void $ dupTo childStdoutWrite stdOutput
|
||||||
|
closeFd childStdoutWrite
|
||||||
|
closeFd parentStdoutRead
|
||||||
|
|
||||||
|
-- dup stderr
|
||||||
|
void $ dupTo childStderrWrite stdError
|
||||||
|
closeFd childStderrWrite
|
||||||
|
closeFd parentStderrRead
|
||||||
|
|
||||||
|
-- execute the action
|
||||||
|
a <- action
|
||||||
|
void $ evaluate a
|
||||||
|
|
||||||
|
-- close everything we don't need
|
||||||
|
closeFd childStdoutWrite
|
||||||
|
closeFd childStderrWrite
|
||||||
|
|
||||||
|
-- start thread that writes the output
|
||||||
|
refOut <- newIORef BL.empty
|
||||||
|
refErr <- newIORef BL.empty
|
||||||
|
done <- newEmptyMVar
|
||||||
|
_ <-
|
||||||
|
forkIO
|
||||||
|
$ EX.handle (\(_ :: IOException) -> pure ())
|
||||||
|
$ flip EX.finally (putMVar done ())
|
||||||
|
$ writeStds parentStdoutRead parentStderrRead refOut refErr
|
||||||
|
|
||||||
|
status <- SPP.getProcessStatus True True pid
|
||||||
|
void $ race (takeMVar done) (threadDelay (1000000 * 3))
|
||||||
|
|
||||||
|
case status of
|
||||||
|
-- readFd will take care of closing the fd
|
||||||
|
Just (SPP.Exited es) -> do
|
||||||
|
stdout' <- readIORef refOut
|
||||||
|
stderr' <- readIORef refErr
|
||||||
|
pure $ CapturedProcess { _exitCode = es
|
||||||
|
, _stdOut = stdout'
|
||||||
|
, _stdErr = stderr'
|
||||||
|
}
|
||||||
|
|
||||||
|
_ -> throwIO $ userError ("No such PID " ++ show pid)
|
||||||
|
|
||||||
|
where
|
||||||
|
writeStds :: Fd -> Fd -> IORef BL.ByteString -> IORef BL.ByteString -> IO ()
|
||||||
|
writeStds pout perr rout rerr = do
|
||||||
|
doneOut <- newEmptyMVar
|
||||||
|
void
|
||||||
|
$ forkIO
|
||||||
|
$ hideError eofErrorType
|
||||||
|
$ flip EX.finally (putMVar doneOut ())
|
||||||
|
$ readTilEOF (\x -> modifyIORef' rout (<> BL.fromStrict x)) pout
|
||||||
|
doneErr <- newEmptyMVar
|
||||||
|
void
|
||||||
|
$ forkIO
|
||||||
|
$ hideError eofErrorType
|
||||||
|
$ flip EX.finally (putMVar doneErr ())
|
||||||
|
$ readTilEOF (\x -> modifyIORef' rerr (<> BL.fromStrict x)) perr
|
||||||
|
takeMVar doneOut
|
||||||
|
takeMVar doneErr
|
||||||
|
|
||||||
|
readTilEOF ~action' fd' = do
|
||||||
|
bs <- SPIB.fdRead fd' 512
|
||||||
|
void $ action' bs
|
||||||
|
readTilEOF action' fd'
|
||||||
|
|
||||||
|
|
||||||
|
actionWithPipes :: ((Fd, Fd) -> IO b) -> IO b
|
||||||
|
actionWithPipes a =
|
||||||
|
createPipe >>= \(p1, p2) -> flip finally (cleanup [p1, p2]) $ a (p1, p2)
|
||||||
|
|
||||||
|
cleanup :: [Fd] -> IO ()
|
||||||
|
cleanup fds = for_ fds $ \fd -> handleIO (\_ -> pure ()) $ closeFd fd
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- | Create a new regular file in write-only mode. The file must not exist.
|
||||||
|
createRegularFileFd :: FileMode -> FilePath -> IO Fd
|
||||||
|
createRegularFileFd fm dest =
|
||||||
|
openFd dest WriteOnly (Just fm) defaultFileFlags{ exclusive = True }
|
||||||
|
|
||||||
|
|
||||||
|
-- | Thin wrapper around `executeFile`.
|
||||||
|
exec :: MonadIO m
|
||||||
|
=> String -- ^ thing to execute
|
||||||
|
-> [String] -- ^ args for the thing
|
||||||
|
-> Maybe FilePath -- ^ optionally chdir into this
|
||||||
|
-> Maybe [(String, String)] -- ^ optional environment
|
||||||
|
-> m (Either ProcessError ())
|
||||||
|
exec exe args chdir env = liftIO $ do
|
||||||
|
pid <- SPP.forkProcess $ do
|
||||||
|
maybe (pure ()) changeWorkingDirectory chdir
|
||||||
|
SPP.executeFile exe (not ("./" `isPrefixOf` exe)) args env
|
||||||
|
|
||||||
|
fmap (toProcessError exe args) $ SPP.getProcessStatus True True pid
|
||||||
|
|
||||||
|
|
||||||
|
toProcessError :: FilePath
|
||||||
|
-> [String]
|
||||||
|
-> Maybe ProcessStatus
|
||||||
|
-> Either ProcessError ()
|
||||||
|
toProcessError exe args mps = case mps of
|
||||||
|
Just (SPP.Exited (ExitFailure xi)) -> Left $ NonZeroExit xi exe args
|
||||||
|
Just (SPP.Exited ExitSuccess ) -> Right ()
|
||||||
|
Just (Terminated _ _ ) -> Left $ PTerminated exe args
|
||||||
|
Just (Stopped _ ) -> Left $ PStopped exe args
|
||||||
|
Nothing -> Left $ NoSuchPid exe args
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
chmod_755 :: (MonadLogger m, MonadIO m) => FilePath -> m ()
|
||||||
|
chmod_755 fp = do
|
||||||
|
let exe_mode =
|
||||||
|
nullFileMode
|
||||||
|
`unionFileModes` ownerExecuteMode
|
||||||
|
`unionFileModes` ownerReadMode
|
||||||
|
`unionFileModes` ownerWriteMode
|
||||||
|
`unionFileModes` groupExecuteMode
|
||||||
|
`unionFileModes` groupReadMode
|
||||||
|
`unionFileModes` otherExecuteMode
|
||||||
|
`unionFileModes` otherReadMode
|
||||||
|
$(logDebug) [i|chmod 755 #{fp}|]
|
||||||
|
liftIO $ setFileMode fp exe_mode
|
||||||
|
|
||||||
|
|
||||||
|
-- |Default permissions for a new file.
|
||||||
|
newFilePerms :: FileMode
|
||||||
|
newFilePerms =
|
||||||
|
ownerWriteMode
|
||||||
|
`unionFileModes` ownerReadMode
|
||||||
|
`unionFileModes` groupWriteMode
|
||||||
|
`unionFileModes` groupReadMode
|
||||||
|
`unionFileModes` otherWriteMode
|
||||||
|
`unionFileModes` otherReadMode
|
||||||
|
|
||||||
|
|
||||||
|
-- | Checks whether the binary is a broken link.
|
||||||
|
isBrokenSymlink :: FilePath -> IO Bool
|
||||||
|
isBrokenSymlink fp = do
|
||||||
|
try (pathIsSymbolicLink fp) >>= \case
|
||||||
|
Right True -> do
|
||||||
|
let symDir = takeDirectory fp
|
||||||
|
tfp <- getSymbolicLinkTarget fp
|
||||||
|
not <$> doesPathExist
|
||||||
|
-- this drops 'symDir' if 'tfp' is absolute
|
||||||
|
(symDir </> tfp)
|
||||||
|
Right b -> pure b
|
||||||
|
Left e | isDoesNotExistError e -> pure False
|
||||||
|
| otherwise -> throwIO e
|
||||||
247
lib/GHCup/Utils/File/Windows.hs
Normal file
247
lib/GHCup/Utils/File/Windows.hs
Normal file
@@ -0,0 +1,247 @@
|
|||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
|
|
||||||
|
{-|
|
||||||
|
Module : GHCup.Utils.File.Windows
|
||||||
|
Description : File and windows APIs
|
||||||
|
Copyright : (c) Julian Ospald, 2020
|
||||||
|
License : LGPL-3.0
|
||||||
|
Maintainer : hasufell@hasufell.de
|
||||||
|
Stability : experimental
|
||||||
|
Portability : Windows
|
||||||
|
|
||||||
|
This module handles file and executable handling.
|
||||||
|
Some of these functions use sophisticated logging.
|
||||||
|
-}
|
||||||
|
module GHCup.Utils.File.Windows where
|
||||||
|
|
||||||
|
import {-# SOURCE #-} GHCup.Utils ( getLinkTarget, pathIsLink )
|
||||||
|
import GHCup.Utils.Dirs
|
||||||
|
import GHCup.Utils.File.Common
|
||||||
|
import GHCup.Types
|
||||||
|
|
||||||
|
import Control.Concurrent
|
||||||
|
import Control.DeepSeq
|
||||||
|
import Control.Exception.Safe
|
||||||
|
import Control.Monad
|
||||||
|
import Control.Monad.Reader
|
||||||
|
import Data.List
|
||||||
|
import Foreign.C.Error
|
||||||
|
import GHC.IO.Exception
|
||||||
|
import GHC.IO.Handle
|
||||||
|
import System.Directory
|
||||||
|
import System.Environment
|
||||||
|
import System.FilePath
|
||||||
|
import System.IO
|
||||||
|
import System.Process
|
||||||
|
|
||||||
|
import qualified Control.Exception as EX
|
||||||
|
import qualified Data.ByteString as BS
|
||||||
|
import qualified Data.ByteString.Lazy as BL
|
||||||
|
import qualified Data.Map.Strict as Map
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
toProcessError :: FilePath
|
||||||
|
-> [FilePath]
|
||||||
|
-> ExitCode
|
||||||
|
-> Either ProcessError ()
|
||||||
|
toProcessError exe args exitcode = case exitcode of
|
||||||
|
(ExitFailure xi) -> Left $ NonZeroExit xi exe args
|
||||||
|
ExitSuccess -> Right ()
|
||||||
|
|
||||||
|
|
||||||
|
-- | @readCreateProcessWithExitCode@ works exactly like 'readProcessWithExitCode' except that it
|
||||||
|
-- lets you pass 'CreateProcess' giving better flexibility.
|
||||||
|
--
|
||||||
|
-- Note that @Handle@s provided for @std_in@, @std_out@, or @std_err@ via the CreateProcess
|
||||||
|
-- record will be ignored.
|
||||||
|
--
|
||||||
|
-- @since 1.2.3.0
|
||||||
|
readCreateProcessWithExitCodeBS
|
||||||
|
:: CreateProcess
|
||||||
|
-> BL.ByteString
|
||||||
|
-> IO (ExitCode, BL.ByteString, BL.ByteString) -- ^ exitcode, stdout, stderr
|
||||||
|
readCreateProcessWithExitCodeBS cp input = do
|
||||||
|
let cp_opts = cp {
|
||||||
|
std_in = CreatePipe,
|
||||||
|
std_out = CreatePipe,
|
||||||
|
std_err = CreatePipe
|
||||||
|
}
|
||||||
|
withCreateProcess_ "readCreateProcessWithExitCodeBS" cp_opts $
|
||||||
|
\mb_inh mb_outh mb_errh ph ->
|
||||||
|
case (mb_inh, mb_outh, mb_errh) of
|
||||||
|
(Just inh, Just outh, Just errh) -> do
|
||||||
|
|
||||||
|
out <- BS.hGetContents outh
|
||||||
|
err <- BS.hGetContents errh
|
||||||
|
|
||||||
|
-- fork off threads to start consuming stdout & stderr
|
||||||
|
withForkWait (EX.evaluate $ rnf out) $ \waitOut ->
|
||||||
|
withForkWait (EX.evaluate $ rnf err) $ \waitErr -> do
|
||||||
|
|
||||||
|
-- now write any input
|
||||||
|
unless (BL.null input) $
|
||||||
|
ignoreSigPipe $ BL.hPut inh input
|
||||||
|
-- hClose performs implicit hFlush, and thus may trigger a SIGPIPE
|
||||||
|
ignoreSigPipe $ hClose inh
|
||||||
|
|
||||||
|
-- wait on the output
|
||||||
|
waitOut
|
||||||
|
waitErr
|
||||||
|
|
||||||
|
hClose outh
|
||||||
|
hClose errh
|
||||||
|
|
||||||
|
-- wait on the process
|
||||||
|
ex <- waitForProcess ph
|
||||||
|
return (ex, BL.fromStrict out, BL.fromStrict err)
|
||||||
|
|
||||||
|
(Nothing,_,_) -> error "readCreateProcessWithExitCodeBS: Failed to get a stdin handle."
|
||||||
|
(_,Nothing,_) -> error "readCreateProcessWithExitCodeBS: Failed to get a stdout handle."
|
||||||
|
(_,_,Nothing) -> error "readCreateProcessWithExitCodeBS: Failed to get a stderr handle."
|
||||||
|
where
|
||||||
|
ignoreSigPipe :: IO () -> IO ()
|
||||||
|
ignoreSigPipe = EX.handle $ \e -> case e of
|
||||||
|
IOError { ioe_type = ResourceVanished
|
||||||
|
, ioe_errno = Just ioe }
|
||||||
|
| Errno ioe == ePIPE -> return ()
|
||||||
|
_ -> throwIO e
|
||||||
|
-- wrapper so we can get exceptions with the appropriate function name.
|
||||||
|
withCreateProcess_
|
||||||
|
:: String
|
||||||
|
-> CreateProcess
|
||||||
|
-> (Maybe Handle -> Maybe Handle -> Maybe Handle -> ProcessHandle -> IO a)
|
||||||
|
-> IO a
|
||||||
|
withCreateProcess_ fun c action =
|
||||||
|
EX.bracketOnError (createProcess_ fun c) cleanupProcess
|
||||||
|
(\(m_in, m_out, m_err, ph) -> action m_in m_out m_err ph)
|
||||||
|
|
||||||
|
-- | Fork a thread while doing something else, but kill it if there's an
|
||||||
|
-- exception.
|
||||||
|
--
|
||||||
|
-- This is important in the cases above because we want to kill the thread
|
||||||
|
-- that is holding the Handle lock, because when we clean up the process we
|
||||||
|
-- try to close that handle, which could otherwise deadlock.
|
||||||
|
--
|
||||||
|
withForkWait :: IO () -> (IO () -> IO a) -> IO a
|
||||||
|
withForkWait async' body = do
|
||||||
|
waitVar <- newEmptyMVar :: IO (MVar (Either SomeException ()))
|
||||||
|
mask $ \restore -> do
|
||||||
|
tid <- forkIO $ try (restore async') >>= putMVar waitVar
|
||||||
|
let wait' = takeMVar waitVar >>= either throwIO return
|
||||||
|
restore (body wait') `EX.onException` killThread tid
|
||||||
|
|
||||||
|
|
||||||
|
-- | Execute the given command and collect the stdout, stderr and the exit code.
|
||||||
|
-- The command is run in a subprocess.
|
||||||
|
executeOut :: MonadIO m
|
||||||
|
=> FilePath -- ^ command as filename, e.g. 'ls'
|
||||||
|
-> [String] -- ^ arguments to the command
|
||||||
|
-> Maybe FilePath -- ^ chdir to this path
|
||||||
|
-> m CapturedProcess
|
||||||
|
executeOut path args chdir = do
|
||||||
|
cp <- createProcessWithMingwPath ((proc path args){ cwd = chdir })
|
||||||
|
(exit, out, err) <- liftIO $ readCreateProcessWithExitCodeBS cp ""
|
||||||
|
pure $ CapturedProcess exit out err
|
||||||
|
|
||||||
|
|
||||||
|
execLogged :: (MonadReader AppState m, MonadIO m, MonadThrow m)
|
||||||
|
=> FilePath -- ^ thing to execute
|
||||||
|
-> [String] -- ^ args for the thing
|
||||||
|
-> Maybe FilePath -- ^ optionally chdir into this
|
||||||
|
-> FilePath -- ^ log filename (opened in append mode)
|
||||||
|
-> Maybe [(String, String)] -- ^ optional environment
|
||||||
|
-> m (Either ProcessError ())
|
||||||
|
execLogged exe args chdir lfile env = do
|
||||||
|
AppState { dirs = Dirs {..} } <- ask
|
||||||
|
let stdoutLogfile = logsDir </> lfile <> ".stdout.log"
|
||||||
|
stderrLogfile = logsDir </> lfile <> ".stderr.log"
|
||||||
|
cp <- createProcessWithMingwPath ((proc exe args)
|
||||||
|
{ cwd = chdir
|
||||||
|
, env = env
|
||||||
|
, std_in = CreatePipe
|
||||||
|
, std_out = CreatePipe
|
||||||
|
, std_err = CreatePipe
|
||||||
|
})
|
||||||
|
fmap (toProcessError exe args)
|
||||||
|
$ liftIO
|
||||||
|
$ withCreateProcess cp
|
||||||
|
$ \_ mout merr ph ->
|
||||||
|
case (mout, merr) of
|
||||||
|
(Just cStdout, Just cStderr) -> do
|
||||||
|
withForkWait (tee stdoutLogfile cStdout) $ \waitOut ->
|
||||||
|
withForkWait (tee stderrLogfile cStderr) $ \waitErr -> do
|
||||||
|
waitOut
|
||||||
|
waitErr
|
||||||
|
waitForProcess ph
|
||||||
|
_ -> fail "Could not acquire out/err handle"
|
||||||
|
|
||||||
|
where
|
||||||
|
tee :: FilePath -> Handle -> IO ()
|
||||||
|
tee logFile handle' = go
|
||||||
|
where
|
||||||
|
go = do
|
||||||
|
some <- BS.hGetSome handle' 512
|
||||||
|
if BS.null some
|
||||||
|
then pure ()
|
||||||
|
else do
|
||||||
|
void $ BS.appendFile logFile some
|
||||||
|
void $ BS.hPut stdout some
|
||||||
|
go
|
||||||
|
|
||||||
|
|
||||||
|
-- | Thin wrapper around `executeFile`.
|
||||||
|
exec :: MonadIO m
|
||||||
|
=> FilePath -- ^ thing to execute
|
||||||
|
-> [FilePath] -- ^ args for the thing
|
||||||
|
-> Maybe FilePath -- ^ optionally chdir into this
|
||||||
|
-> Maybe [(String, String)] -- ^ optional environment
|
||||||
|
-> m (Either ProcessError ())
|
||||||
|
exec exe args chdir env = do
|
||||||
|
cp <- createProcessWithMingwPath ((proc exe args) { cwd = chdir, env = env })
|
||||||
|
exit_code <- liftIO $ withCreateProcess cp $ \_ _ _ p -> waitForProcess p
|
||||||
|
pure $ toProcessError exe args exit_code
|
||||||
|
|
||||||
|
|
||||||
|
chmod_755 :: MonadIO m => FilePath -> m ()
|
||||||
|
chmod_755 fp =
|
||||||
|
let perm = setOwnerWritable True emptyPermissions
|
||||||
|
in liftIO $ setPermissions fp perm
|
||||||
|
|
||||||
|
|
||||||
|
createProcessWithMingwPath :: MonadIO m
|
||||||
|
=> CreateProcess
|
||||||
|
-> m CreateProcess
|
||||||
|
createProcessWithMingwPath cp = do
|
||||||
|
msys2Dir <- liftIO ghcupMsys2Dir
|
||||||
|
cEnv <- Map.fromList <$> maybe (liftIO getEnvironment) pure (env cp)
|
||||||
|
let mingWPaths = [msys2Dir </> "usr" </> "bin"
|
||||||
|
,msys2Dir </> "mingw64" </> "bin"]
|
||||||
|
paths = ["PATH", "Path"]
|
||||||
|
curPaths = (\x -> maybe [] splitSearchPath (Map.lookup x cEnv)) =<< paths
|
||||||
|
newPath = intercalate [searchPathSeparator] (mingWPaths ++ curPaths)
|
||||||
|
envWithoutPath = foldr (\x y -> Map.delete x y) cEnv paths
|
||||||
|
envWithNewPath = Map.insert "Path" newPath envWithoutPath
|
||||||
|
liftIO $ setEnv "Path" newPath
|
||||||
|
pure $ cp { env = Just $ Map.toList envWithNewPath }
|
||||||
|
|
||||||
|
ghcupMsys2Dir :: IO FilePath
|
||||||
|
ghcupMsys2Dir =
|
||||||
|
lookupEnv "GHCUP_MSYS2" >>= \case
|
||||||
|
Just fp -> pure fp
|
||||||
|
Nothing -> do
|
||||||
|
baseDir <- liftIO ghcupBaseDir
|
||||||
|
pure (baseDir </> "msys64")
|
||||||
|
|
||||||
|
-- | Checks whether the binary is a broken link.
|
||||||
|
isBrokenSymlink :: FilePath -> IO Bool
|
||||||
|
isBrokenSymlink fp = do
|
||||||
|
b <- pathIsLink fp
|
||||||
|
if b
|
||||||
|
then do
|
||||||
|
tfp <- getLinkTarget fp
|
||||||
|
not <$> doesPathExist
|
||||||
|
-- this drops 'symDir' if 'tfp' is absolute
|
||||||
|
(takeDirectory fp </> tfp)
|
||||||
|
else pure False
|
||||||
@@ -8,29 +8,26 @@ Copyright : (c) Julian Ospald, 2020
|
|||||||
License : LGPL-3.0
|
License : LGPL-3.0
|
||||||
Maintainer : hasufell@hasufell.de
|
Maintainer : hasufell@hasufell.de
|
||||||
Stability : experimental
|
Stability : experimental
|
||||||
Portability : POSIX
|
Portability : portable
|
||||||
|
|
||||||
Here we define our main logger.
|
Here we define our main logger.
|
||||||
-}
|
-}
|
||||||
module GHCup.Utils.Logger where
|
module GHCup.Utils.Logger where
|
||||||
|
|
||||||
import GHCup.Types
|
|
||||||
import GHCup.Utils
|
|
||||||
import GHCup.Utils.File
|
import GHCup.Utils.File
|
||||||
import GHCup.Utils.String.QQ
|
import GHCup.Utils.String.QQ
|
||||||
|
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Control.Monad.IO.Class
|
import Control.Monad.IO.Class
|
||||||
import Control.Monad.Reader
|
|
||||||
import Control.Monad.Logger
|
import Control.Monad.Logger
|
||||||
import HPath
|
|
||||||
import HPath.IO
|
|
||||||
import Prelude hiding ( appendFile )
|
import Prelude hiding ( appendFile )
|
||||||
import System.Console.Pretty
|
import System.Console.Pretty
|
||||||
|
import System.FilePath
|
||||||
import System.IO.Error
|
import System.IO.Error
|
||||||
import Text.Regex.Posix
|
import Text.Regex.Posix
|
||||||
|
|
||||||
import qualified Data.ByteString as B
|
import qualified Data.ByteString as B
|
||||||
|
import GHCup.Utils.Prelude
|
||||||
|
|
||||||
|
|
||||||
data LoggerConfig = LoggerConfig
|
data LoggerConfig = LoggerConfig
|
||||||
@@ -68,19 +65,17 @@ myLoggerT LoggerConfig {..} loggingt = runLoggingT loggingt mylogger
|
|||||||
rawOutter outr
|
rawOutter outr
|
||||||
|
|
||||||
|
|
||||||
initGHCupFileLogging :: (MonadIO m, MonadReader AppState m) => m (Path Abs)
|
initGHCupFileLogging :: (MonadIO m) => FilePath -> m FilePath
|
||||||
initGHCupFileLogging = do
|
initGHCupFileLogging logsDir = do
|
||||||
AppState {dirs = Dirs {..}} <- ask
|
let logfile = logsDir </> "ghcup.log"
|
||||||
let logfile = logsDir </> [rel|ghcup.log|]
|
|
||||||
liftIO $ do
|
liftIO $ do
|
||||||
createDirRecursive' logsDir
|
|
||||||
logFiles <- findFiles
|
logFiles <- findFiles
|
||||||
logsDir
|
logsDir
|
||||||
(makeRegexOpts compExtended
|
(makeRegexOpts compExtended
|
||||||
execBlank
|
execBlank
|
||||||
([s|^.*\.log$|] :: B.ByteString)
|
([s|^.*\.log$|] :: B.ByteString)
|
||||||
)
|
)
|
||||||
forM_ logFiles $ hideError doesNotExistErrorType . deleteFile . (logsDir </>)
|
forM_ logFiles $ hideError doesNotExistErrorType . rmFile . (logsDir </>)
|
||||||
|
|
||||||
createRegularFile newFilePerms logfile
|
writeFile logfile ""
|
||||||
pure logfile
|
pure logfile
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ Copyright : (c) Julian Ospald, 2020
|
|||||||
License : LGPL-3.0
|
License : LGPL-3.0
|
||||||
Maintainer : hasufell@hasufell.de
|
Maintainer : hasufell@hasufell.de
|
||||||
Stability : experimental
|
Stability : experimental
|
||||||
Portability : POSIX
|
Portability : portable
|
||||||
-}
|
-}
|
||||||
module GHCup.Utils.MegaParsec where
|
module GHCup.Utils.MegaParsec where
|
||||||
|
|
||||||
@@ -23,6 +23,7 @@ import Data.Maybe
|
|||||||
import Data.Text ( Text )
|
import Data.Text ( Text )
|
||||||
import Data.Versions
|
import Data.Versions
|
||||||
import Data.Void
|
import Data.Void
|
||||||
|
import System.FilePath
|
||||||
|
|
||||||
import qualified Data.List.NonEmpty as NE
|
import qualified Data.List.NonEmpty as NE
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
@@ -117,3 +118,7 @@ verP suffix = do
|
|||||||
v <- versioning'
|
v <- versioning'
|
||||||
MP.setInput rest
|
MP.setInput rest
|
||||||
pure v
|
pure v
|
||||||
|
|
||||||
|
|
||||||
|
pathSep :: MP.Parsec Void Text Char
|
||||||
|
pathSep = MP.oneOf pathSeparators
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
{-# LANGUAGE CPP #-}
|
||||||
{-# LANGUAGE DataKinds #-}
|
{-# LANGUAGE DataKinds #-}
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
{-# LANGUAGE FlexibleInstances #-}
|
{-# LANGUAGE FlexibleInstances #-}
|
||||||
@@ -12,7 +13,7 @@ Copyright : (c) Julian Ospald, 2020
|
|||||||
License : LGPL-3.0
|
License : LGPL-3.0
|
||||||
Maintainer : hasufell@hasufell.de
|
Maintainer : hasufell@hasufell.de
|
||||||
Stability : experimental
|
Stability : experimental
|
||||||
Portability : POSIX
|
Portability : portable
|
||||||
|
|
||||||
GHCup specific prelude. Lots of Excepts functionality.
|
GHCup specific prelude. Lots of Excepts functionality.
|
||||||
-}
|
-}
|
||||||
@@ -25,6 +26,8 @@ import Control.Monad.IO.Class
|
|||||||
import Control.Monad.Trans.Class ( lift )
|
import Control.Monad.Trans.Class ( lift )
|
||||||
import Data.Bifunctor
|
import Data.Bifunctor
|
||||||
import Data.ByteString ( ByteString )
|
import Data.ByteString ( ByteString )
|
||||||
|
import Data.List ( nub )
|
||||||
|
import Data.Foldable
|
||||||
import Data.String
|
import Data.String
|
||||||
import Data.Text ( Text )
|
import Data.Text ( Text )
|
||||||
import Data.Versions
|
import Data.Versions
|
||||||
@@ -32,7 +35,14 @@ import Data.Word8
|
|||||||
import Haskus.Utils.Types.List
|
import Haskus.Utils.Types.List
|
||||||
import Haskus.Utils.Variant.Excepts
|
import Haskus.Utils.Variant.Excepts
|
||||||
import System.IO.Error
|
import System.IO.Error
|
||||||
import System.Posix.Env.ByteString ( getEnvironment )
|
import System.IO.Unsafe
|
||||||
|
import System.Directory
|
||||||
|
import System.FilePath
|
||||||
|
|
||||||
|
#if defined(IS_WINDOWS)
|
||||||
|
import Control.Retry
|
||||||
|
import GHC.IO.Exception
|
||||||
|
#endif
|
||||||
|
|
||||||
import qualified Data.ByteString as B
|
import qualified Data.ByteString as B
|
||||||
import qualified Data.ByteString.Lazy as L
|
import qualified Data.ByteString.Lazy as L
|
||||||
@@ -180,14 +190,14 @@ hideError :: (MonadIO m, MonadCatch m) => IOErrorType -> m () -> m ()
|
|||||||
hideError err = handleIO (\e -> if err == ioeGetErrorType e then pure () else liftIO . ioError $ e)
|
hideError err = handleIO (\e -> if err == ioeGetErrorType e then pure () else liftIO . ioError $ e)
|
||||||
|
|
||||||
|
|
||||||
hideErrorDef :: [IOErrorType] -> a -> IO a -> IO a
|
hideErrorDef :: (MonadIO m, MonadCatch m) => [IOErrorType] -> a -> m a -> m a
|
||||||
hideErrorDef errs def =
|
hideErrorDef errs def =
|
||||||
handleIO (\e -> if ioeGetErrorType e `elem` errs then pure def else ioError e)
|
handleIO (\e -> if ioeGetErrorType e `elem` errs then pure def else liftIO $ ioError e)
|
||||||
|
|
||||||
|
|
||||||
hideErrorDefM :: [IOErrorType] -> IO a -> IO a -> IO a
|
hideErrorDefM :: (MonadIO m, MonadCatch m) => [IOErrorType] -> m a -> m a -> m a
|
||||||
hideErrorDefM errs def =
|
hideErrorDefM errs def =
|
||||||
handleIO (\e -> if ioeGetErrorType e `elem` errs then def else ioError e)
|
handleIO (\e -> if ioeGetErrorType e `elem` errs then def else liftIO $ ioError e)
|
||||||
|
|
||||||
|
|
||||||
-- TODO: does this work?
|
-- TODO: does this work?
|
||||||
@@ -242,6 +252,8 @@ throwEither' e eth = case eth of
|
|||||||
verToBS :: Version -> ByteString
|
verToBS :: Version -> ByteString
|
||||||
verToBS = E.encodeUtf8 . prettyVer
|
verToBS = E.encodeUtf8 . prettyVer
|
||||||
|
|
||||||
|
verToS :: Version -> String
|
||||||
|
verToS = T.unpack . prettyVer
|
||||||
|
|
||||||
intToText :: Integral a => a -> T.Text
|
intToText :: Integral a => a -> T.Text
|
||||||
intToText = TL.toStrict . B.toLazyText . B.decimal
|
intToText = TL.toStrict . B.toLazyText . B.decimal
|
||||||
@@ -252,14 +264,6 @@ removeLensFieldLabel str' =
|
|||||||
maybe str' T.unpack . T.stripPrefix (T.pack "_") . T.pack $ str'
|
maybe str' T.unpack . T.stripPrefix (T.pack "_") . T.pack $ str'
|
||||||
|
|
||||||
|
|
||||||
addToCurrentEnv :: MonadIO m
|
|
||||||
=> [(ByteString, ByteString)]
|
|
||||||
-> m [(ByteString, ByteString)]
|
|
||||||
addToCurrentEnv adds = do
|
|
||||||
cEnv <- liftIO getEnvironment
|
|
||||||
pure (adds ++ cEnv)
|
|
||||||
|
|
||||||
|
|
||||||
pvpToVersion :: PVP -> Version
|
pvpToVersion :: PVP -> Version
|
||||||
pvpToVersion =
|
pvpToVersion =
|
||||||
either (\_ -> error "Couldn't convert PVP to Version") id
|
either (\_ -> error "Couldn't convert PVP to Version") id
|
||||||
@@ -284,3 +288,140 @@ escapeVerRex = B.pack . go . B.unpack . verToBS
|
|||||||
go (x : xs) | x == _period = [_backslash, _period] ++ go xs
|
go (x : xs) | x == _period = [_backslash, _period] ++ go xs
|
||||||
| otherwise = x : go xs
|
| otherwise = x : go xs
|
||||||
|
|
||||||
|
-- | More permissive version of 'createDirRecursive'. This doesn't
|
||||||
|
-- error when the destination is a symlink to a directory.
|
||||||
|
createDirRecursive' :: FilePath -> IO ()
|
||||||
|
createDirRecursive' p =
|
||||||
|
handleIO (\e -> if isAlreadyExistsError e then isSymlinkDir e else throwIO e)
|
||||||
|
. createDirectoryIfMissing True
|
||||||
|
$ p
|
||||||
|
|
||||||
|
where
|
||||||
|
isSymlinkDir e = do
|
||||||
|
ft <- pathIsSymbolicLink p
|
||||||
|
case ft of
|
||||||
|
True -> do
|
||||||
|
rp <- canonicalizePath p
|
||||||
|
rft <- doesDirectoryExist rp
|
||||||
|
case rft of
|
||||||
|
True -> pure ()
|
||||||
|
_ -> throwIO e
|
||||||
|
_ -> throwIO e
|
||||||
|
|
||||||
|
|
||||||
|
-- | Recursively copy the contents of one directory to another path.
|
||||||
|
--
|
||||||
|
-- This is a rip-off of Cabal library.
|
||||||
|
copyDirectoryRecursive :: FilePath -> FilePath -> IO ()
|
||||||
|
copyDirectoryRecursive srcDir destDir = do
|
||||||
|
srcFiles <- getDirectoryContentsRecursive srcDir
|
||||||
|
copyFilesWith copyFile destDir [ (srcDir, f)
|
||||||
|
| f <- srcFiles ]
|
||||||
|
where
|
||||||
|
-- | Common implementation of 'copyFiles', 'installOrdinaryFiles',
|
||||||
|
-- 'installExecutableFiles' and 'installMaybeExecutableFiles'.
|
||||||
|
copyFilesWith :: (FilePath -> FilePath -> IO ())
|
||||||
|
-> FilePath -> [(FilePath, FilePath)] -> IO ()
|
||||||
|
copyFilesWith doCopy targetDir srcFiles = do
|
||||||
|
|
||||||
|
-- Create parent directories for everything
|
||||||
|
let dirs = map (targetDir </>) . nub . map (takeDirectory . snd) $ srcFiles
|
||||||
|
traverse_ (createDirectoryIfMissing True) dirs
|
||||||
|
|
||||||
|
-- Copy all the files
|
||||||
|
sequence_ [ let src = srcBase </> srcFile
|
||||||
|
dest = targetDir </> srcFile
|
||||||
|
in doCopy src dest
|
||||||
|
| (srcBase, srcFile) <- srcFiles ]
|
||||||
|
|
||||||
|
|
||||||
|
-- | List all the files in a directory and all subdirectories.
|
||||||
|
--
|
||||||
|
-- The order places files in sub-directories after all the files in their
|
||||||
|
-- parent directories. The list is generated lazily so is not well defined if
|
||||||
|
-- the source directory structure changes before the list is used.
|
||||||
|
--
|
||||||
|
getDirectoryContentsRecursive :: FilePath -> IO [FilePath]
|
||||||
|
getDirectoryContentsRecursive topdir = recurseDirectories [""]
|
||||||
|
where
|
||||||
|
recurseDirectories :: [FilePath] -> IO [FilePath]
|
||||||
|
recurseDirectories [] = return []
|
||||||
|
recurseDirectories (dir:dirs) = unsafeInterleaveIO $ do
|
||||||
|
(files, dirs') <- collect [] [] =<< getDirectoryContents (topdir </> dir)
|
||||||
|
files' <- recurseDirectories (dirs' ++ dirs)
|
||||||
|
return (files ++ files')
|
||||||
|
|
||||||
|
where
|
||||||
|
collect files dirs' [] = return (reverse files
|
||||||
|
,reverse dirs')
|
||||||
|
collect files dirs' (entry:entries) | ignore entry
|
||||||
|
= collect files dirs' entries
|
||||||
|
collect files dirs' (entry:entries) = do
|
||||||
|
let dirEntry = dir </> entry
|
||||||
|
isDirectory <- doesDirectoryExist (topdir </> dirEntry)
|
||||||
|
if isDirectory
|
||||||
|
then collect files (dirEntry:dirs') entries
|
||||||
|
else collect (dirEntry:files) dirs' entries
|
||||||
|
|
||||||
|
ignore ['.'] = True
|
||||||
|
ignore ['.', '.'] = True
|
||||||
|
ignore _ = False
|
||||||
|
|
||||||
|
-- https://github.com/haskell/directory/issues/110
|
||||||
|
-- https://github.com/haskell/directory/issues/96
|
||||||
|
-- https://www.sqlite.org/src/info/89f1848d7f
|
||||||
|
rmPath :: (MonadIO m, MonadMask m)
|
||||||
|
=> FilePath
|
||||||
|
-> m ()
|
||||||
|
rmPath fp =
|
||||||
|
#if defined(IS_WINDOWS)
|
||||||
|
recovering (fullJitterBackoff 25000 <> limitRetries 10)
|
||||||
|
[\_ -> Handler (\e -> pure $ isPermissionError e)
|
||||||
|
,\_ -> Handler (\e -> pure (ioeGetErrorType e == UnsatisfiedConstraints))
|
||||||
|
,\_ -> Handler (\e -> pure (ioeGetErrorType e == InappropriateType))
|
||||||
|
]
|
||||||
|
(\_ -> liftIO $ removePathForcibly fp)
|
||||||
|
#else
|
||||||
|
liftIO $ removeDirectoryRecursive fp
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
-- https://www.sqlite.org/src/info/89f1848d7f
|
||||||
|
-- https://github.com/haskell/directory/issues/96
|
||||||
|
rmFile :: (MonadIO m, MonadMask m)
|
||||||
|
=> FilePath
|
||||||
|
-> m ()
|
||||||
|
rmFile fp =
|
||||||
|
#if defined(IS_WINDOWS)
|
||||||
|
recovering (fullJitterBackoff 25000 <> limitRetries 10)
|
||||||
|
[\_ -> Handler (\e -> pure $ isPermissionError e)
|
||||||
|
,\_ -> Handler (\e -> pure (ioeGetErrorType e == UnsatisfiedConstraints))
|
||||||
|
]
|
||||||
|
(\_ -> liftIO $ removeFile fp)
|
||||||
|
#else
|
||||||
|
liftIO $ removeFile fp
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
-- Gathering monoidal values
|
||||||
|
traverseFold :: (Foldable t, Applicative m, Monoid b) => (a -> m b) -> t a -> m b
|
||||||
|
traverseFold f = foldl (\mb a -> (<>) <$> mb <*> f a) (pure mempty)
|
||||||
|
|
||||||
|
-- | Gathering monoidal values
|
||||||
|
forFold :: (Foldable t, Applicative m, Monoid b) => t a -> (a -> m b) -> m b
|
||||||
|
forFold = \t -> (`traverseFold` t)
|
||||||
|
|
||||||
|
|
||||||
|
-- | Strip @\\r@ and @\\n@ from 'ByteString's
|
||||||
|
stripNewline :: String -> String
|
||||||
|
stripNewline s
|
||||||
|
| null s = []
|
||||||
|
| head s `elem` "\n\r" = stripNewline (tail s)
|
||||||
|
| otherwise = head s : stripNewline (tail s)
|
||||||
|
|
||||||
|
|
||||||
|
isNewLine :: Word8 -> Bool
|
||||||
|
isNewLine w
|
||||||
|
| w == _lf = True
|
||||||
|
| w == _cr = True
|
||||||
|
| otherwise = False
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Copyright : (c) Audrey Tang <audreyt@audreyt.org> 2019, Julian Ospald <hasufel
|
|||||||
License : LGPL-3.0
|
License : LGPL-3.0
|
||||||
Maintainer : hasufell@hasufell.de
|
Maintainer : hasufell@hasufell.de
|
||||||
Stability : experimental
|
Stability : experimental
|
||||||
Portability : POSIX
|
Portability : portable
|
||||||
|
|
||||||
QuasiQuoter for non-interpolated strings, texts and bytestrings.
|
QuasiQuoter for non-interpolated strings, texts and bytestrings.
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ Copyright : (c) Julian Ospald, 2020
|
|||||||
License : LGPL-3.0
|
License : LGPL-3.0
|
||||||
Maintainer : hasufell@hasufell.de
|
Maintainer : hasufell@hasufell.de
|
||||||
Stability : experimental
|
Stability : experimental
|
||||||
Portability : POSIX
|
Portability : portable
|
||||||
-}
|
-}
|
||||||
module GHCup.Utils.Version.QQ where
|
module GHCup.Utils.Version.QQ where
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ Copyright : (c) Julian Ospald, 2020
|
|||||||
License : LGPL-3.0
|
License : LGPL-3.0
|
||||||
Maintainer : hasufell@hasufell.de
|
Maintainer : hasufell@hasufell.de
|
||||||
Stability : experimental
|
Stability : experimental
|
||||||
Portability : POSIX
|
Portability : portable
|
||||||
-}
|
-}
|
||||||
module GHCup.Version where
|
module GHCup.Version where
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ import qualified Data.Text as T
|
|||||||
|
|
||||||
-- | This reflects the API version of the YAML.
|
-- | This reflects the API version of the YAML.
|
||||||
ghcupURL :: URI
|
ghcupURL :: URI
|
||||||
ghcupURL = [uri|https://www.haskell.org/ghcup/data/ghcup-0.0.4.yaml|]
|
ghcupURL = [uri|https://www.haskell.org/ghcup/data/ghcup-0.0.5.yaml|]
|
||||||
|
|
||||||
-- | The current ghcup version.
|
-- | The current ghcup version.
|
||||||
ghcUpVer :: PVP
|
ghcUpVer :: PVP
|
||||||
|
|||||||
29
stack.yaml
29
stack.yaml
@@ -1,4 +1,4 @@
|
|||||||
resolver: lts-17.4
|
resolver: lts-17.11
|
||||||
|
|
||||||
packages:
|
packages:
|
||||||
- .
|
- .
|
||||||
@@ -7,6 +7,9 @@ extra-deps:
|
|||||||
- git: https://github.com/hasufell/text-conversions.git
|
- git: https://github.com/hasufell/text-conversions.git
|
||||||
commit: 9abf0e5e5664a3178367597c32db19880477a53c
|
commit: 9abf0e5e5664a3178367597c32db19880477a53c
|
||||||
|
|
||||||
|
- git: https://github.com/Bodigrim/tar
|
||||||
|
commit: ac197ec7ea4838dc2b4e22b9b888b080cedf29cf
|
||||||
|
|
||||||
- IfElse-0.85@sha256:6939b94acc6a55f545f63a168a349dd2fbe4b9a7cca73bf60282db5cc6aa47d2,445
|
- IfElse-0.85@sha256:6939b94acc6a55f545f63a168a349dd2fbe4b9a7cca73bf60282db5cc6aa47d2,445
|
||||||
- ascii-string-1.0.1.4@sha256:fa34f1d9ba57e8e89c0d4c9cef5e01ba32cb2d4373d13f92dcc0b531a6c6749b,2582
|
- ascii-string-1.0.1.4@sha256:fa34f1d9ba57e8e89c0d4c9cef5e01ba32cb2d4373d13f92dcc0b531a6c6749b,2582
|
||||||
- brotli-0.0.0.0@sha256:2bf383a4cd308745740986be0b18381c5a0784393fe69b91456aacb2d603de46,2964
|
- brotli-0.0.0.0@sha256:2bf383a4cd308745740986be0b18381c5a0784393fe69b91456aacb2d603de46,2964
|
||||||
@@ -17,21 +20,24 @@ extra-deps:
|
|||||||
- haskus-utils-data-1.3@sha256:f62c4e49021b463185d043f7b69c727b63af641a71d7edd582d9f4f98e80e500,1466
|
- haskus-utils-data-1.3@sha256:f62c4e49021b463185d043f7b69c727b63af641a71d7edd582d9f4f98e80e500,1466
|
||||||
- haskus-utils-types-1.5.1@sha256:991c472f4e751e2f0d7aab6ad4220ef151d6160876dcf0511bbf876bbd432020,1298
|
- haskus-utils-types-1.5.1@sha256:991c472f4e751e2f0d7aab6ad4220ef151d6160876dcf0511bbf876bbd432020,1298
|
||||||
- haskus-utils-variant-3.0@sha256:8d51e45d3b664e61ccc25a58b37c0ccc4ee7537138b9fee21cd15c356906dd34,2159
|
- haskus-utils-variant-3.0@sha256:8d51e45d3b664e61ccc25a58b37c0ccc4ee7537138b9fee21cd15c356906dd34,2159
|
||||||
- hpath-0.11.0@sha256:12b8405bee13d0007d644a888ef8407069ce7bbbd76970f8746b801447124ade,1440
|
|
||||||
- hpath-directory-0.14.1@sha256:548ac1321222c34caa843a41a2379a77d961141082a4695bb37cc4731e91b2c7,5312
|
|
||||||
- hpath-filepath-0.10.4@sha256:e9e44fb5fdbade7f30b5b5451257dbee15b6ef1aae4060034d73008bb3b5d878,1269
|
|
||||||
- hpath-io-0.14.1@sha256:d91373cd81483eb370a1c683e4add6182250dccce32f9b682bb1104f7765c750,1522
|
|
||||||
- hpath-posix-0.13.2@sha256:eec4ff2b00dc86be847aca0f409fc8f6212ffd2170ec36a17dc9a52b46562392,1615
|
|
||||||
- http-io-streams-0.1.6.0@sha256:53f5bab177efb52cd65ec396fd04ed59b93e5f919fb3700cd7dacd6cfce6f06d,3582
|
- http-io-streams-0.1.6.0@sha256:53f5bab177efb52cd65ec396fd04ed59b93e5f919fb3700cd7dacd6cfce6f06d,3582
|
||||||
- lzma-static-5.2.5.2@sha256:ac38dcad9ab423342a72ba48415bd75f62234e9c9e11831495b75603b5a060f6,7184
|
- hpath-filepath-0.10.4@sha256:e9e44fb5fdbade7f30b5b5451257dbee15b6ef1aae4060034d73008bb3b5d878,1269
|
||||||
|
- hpath-posix-0.13.3@sha256:abe472cf16bccd3a8b8814865ed3551a728fde0f3a2baea2acc03023bec6c565,1615
|
||||||
|
- hspec-2.7.10@sha256:c9e82c90086acebac576552a06f3cabd249bba048edd1667c7fae0b1313d5bce,1712
|
||||||
|
- hspec-core-2.7.10@sha256:2aba6ea126442b29e8183ab27f1c811706b19b1d83b02f193a896f6fc1589d13,4621
|
||||||
|
- hspec-discover-2.7.10@sha256:d08bf5dd785629f589571477d9beb7cd91529471bd89f39517c1cb4b9b38160f,2184
|
||||||
|
- hspec-golden-aeson-0.9.0.0@sha256:aa17274114026661ba4dfc9c60c230673c8f408bd86482fd611d2d5cb6aff996,2179
|
||||||
- libarchive-3.0.2.1@sha256:40ebf2a278e585802427bc58826867208bb33822f63d56107a1fcc3ca04d691d,10990
|
- libarchive-3.0.2.1@sha256:40ebf2a278e585802427bc58826867208bb33822f63d56107a1fcc3ca04d691d,10990
|
||||||
|
- lzma-static-5.2.5.3@sha256:2758ee58c35992fcf7db78e98684c357a16a82fa2a4e7c352a6c210c08c555d8,7308
|
||||||
- os-release-1.0.1@sha256:1281c62081f438fc3f0874d3bae6a4887d5964ac25261ba06e29d368ab173467,2716
|
- os-release-1.0.1@sha256:1281c62081f438fc3f0874d3bae6a4887d5964ac25261ba06e29d368ab173467,2716
|
||||||
- primitive-0.7.0.1@sha256:a381571c36edc7dca28b77fe8159b43c14c640087ec5946adacf949feec64231,3433
|
- primitive-0.7.0.1@sha256:a381571c36edc7dca28b77fe8159b43c14c640087ec5946adacf949feec64231,3433
|
||||||
|
- regex-posix-clib-2.7
|
||||||
- streamly-0.7.3@sha256:ad2a488fe802692ed47cab9fd0416c2904aac9e51cf2d8aafd1c3a40064c42f5,27421
|
- streamly-0.7.3@sha256:ad2a488fe802692ed47cab9fd0416c2904aac9e51cf2d8aafd1c3a40064c42f5,27421
|
||||||
- streamly-bytestring-0.1.2@sha256:cc828f41d1c714c711d38fb213b4ed186febabba598ab080e13255f69c20b13c,2469
|
- streamly-bytestring-0.1.2@sha256:cc828f41d1c714c711d38fb213b4ed186febabba598ab080e13255f69c20b13c,2469
|
||||||
- streamly-posix-0.1.0.1@sha256:5d89b806281035d34020387ed99dde1ddab282c7ed66df3b7cd010b38fd3517b,2138
|
- streamly-posix-0.1.0.1@sha256:5d89b806281035d34020387ed99dde1ddab282c7ed66df3b7cd010b38fd3517b,2138
|
||||||
- strict-base-0.4.0.0@sha256:2ff4e43cb95eedf2995558d7fc34d19362846413dd39e6aa6a5b3ea8228fef9f,1248
|
- strict-base-0.4.0.0@sha256:2ff4e43cb95eedf2995558d7fc34d19362846413dd39e6aa6a5b3ea8228fef9f,1248
|
||||||
- xor-0.0.1.0@sha256:f8362b4a68562b9afbcd727ff64c1a303970df3a032e0033d2f4c094c3501df3,2243
|
- xor-0.0.1.0@sha256:f8362b4a68562b9afbcd727ff64c1a303970df3a032e0033d2f4c094c3501df3,2243
|
||||||
|
- zip-1.7.1@sha256:0ce03d0fbffba47c1ab6fbb9166f8ba5373d828d78587df21b7e9d7bb150f929,3918
|
||||||
|
|
||||||
flags:
|
flags:
|
||||||
http-io-streams:
|
http-io-streams:
|
||||||
@@ -40,13 +46,8 @@ flags:
|
|||||||
libarchive:
|
libarchive:
|
||||||
system-libarchive: false
|
system-libarchive: false
|
||||||
|
|
||||||
ghcup:
|
regex-posix:
|
||||||
tui: true
|
_regex-posix-clib: true
|
||||||
internal-downloader: true
|
|
||||||
|
|
||||||
system-ghc: true
|
|
||||||
compiler: ghc-8.10.4
|
|
||||||
compiler-check: match-exact
|
|
||||||
|
|
||||||
ghc-options:
|
ghc-options:
|
||||||
"$locals": -O2
|
"$locals": -O2
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import GHCup.Types
|
|||||||
import Data.ByteString ( ByteString )
|
import Data.ByteString ( ByteString )
|
||||||
import Data.Versions
|
import Data.Versions
|
||||||
import Data.List.NonEmpty
|
import Data.List.NonEmpty
|
||||||
import HPath
|
|
||||||
import Test.QuickCheck
|
import Test.QuickCheck
|
||||||
import Test.QuickCheck.Arbitrary.ADT ( ToADTArbitrary )
|
import Test.QuickCheck.Arbitrary.ADT ( ToADTArbitrary )
|
||||||
import Test.QuickCheck.Arbitrary.Generic
|
import Test.QuickCheck.Arbitrary.Generic
|
||||||
@@ -164,11 +163,6 @@ instance Arbitrary VersionCmp where
|
|||||||
arbitrary = genericArbitrary
|
arbitrary = genericArbitrary
|
||||||
shrink = genericShrink
|
shrink = genericShrink
|
||||||
|
|
||||||
instance Arbitrary (Path Rel) where
|
|
||||||
arbitrary =
|
|
||||||
either (error . show) id . parseRel . E.encodeUtf8 . T.pack
|
|
||||||
<$> listOf1 (elements ['a' .. 'z'])
|
|
||||||
|
|
||||||
instance Arbitrary TarDir where
|
instance Arbitrary TarDir where
|
||||||
arbitrary = genericArbitrary
|
arbitrary = genericArbitrary
|
||||||
shrink = genericShrink
|
shrink = genericShrink
|
||||||
@@ -177,6 +171,10 @@ instance Arbitrary Tool where
|
|||||||
arbitrary = genericArbitrary
|
arbitrary = genericArbitrary
|
||||||
shrink = genericShrink
|
shrink = genericShrink
|
||||||
|
|
||||||
|
instance Arbitrary GlobalTool where
|
||||||
|
arbitrary = genericArbitrary
|
||||||
|
shrink = genericShrink
|
||||||
|
|
||||||
instance Arbitrary GHCupInfo where
|
instance Arbitrary GHCupInfo where
|
||||||
arbitrary = genericArbitrary
|
arbitrary = genericArbitrary
|
||||||
shrink = genericShrink
|
shrink = genericShrink
|
||||||
|
|||||||
@@ -132,13 +132,17 @@ hr {
|
|||||||
margin-bottom: 2em;
|
margin-bottom: 2em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#platform-instructions-linux > div > pre,
|
span.code {
|
||||||
#platform-instructions-mac > div > pre,
|
font-family: 'Lucida Console', monospace;
|
||||||
#platform-instructions-freebsd > div > pre,
|
}
|
||||||
#platform-instructions-win32 > div > pre,
|
|
||||||
#platform-instructions-win64 > div > pre,
|
#platform-instructions-linux div > pre,
|
||||||
#platform-instructions-default > div > div > pre,
|
#platform-instructions-mac div > pre,
|
||||||
#platform-instructions-unknown > div > div > pre {
|
#platform-instructions-freebsd div > pre,
|
||||||
|
#platform-instructions-win32 div > pre,
|
||||||
|
#platform-instructions-win64 div > pre,
|
||||||
|
#platform-instructions-default div > div > pre,
|
||||||
|
#platform-instructions-unknown div > div > pre {
|
||||||
background-color: #515151;
|
background-color: #515151;
|
||||||
color: white;
|
color: white;
|
||||||
margin-left: auto;
|
margin-left: auto;
|
||||||
|
|||||||
@@ -158,8 +158,8 @@ function copyToClipboard() {
|
|||||||
document.body.removeChild(el);
|
document.body.removeChild(el);
|
||||||
}
|
}
|
||||||
|
|
||||||
function copyToClipboardSilicon() {
|
function copyToClipboardPowershell() {
|
||||||
const text = document.getElementById("ghcup-command-silicon").innerText;
|
const text = document.getElementById("ghcup-command-powershell").innerText;
|
||||||
const el = document.createElement('textarea');
|
const el = document.createElement('textarea');
|
||||||
el.value = text;
|
el.value = text;
|
||||||
document.body.appendChild(el);
|
document.body.appendChild(el);
|
||||||
|
|||||||
104
www/index.html
104
www/index.html
@@ -14,7 +14,6 @@
|
|||||||
|
|
||||||
<body id="idx">
|
<body id="idx">
|
||||||
|
|
||||||
<script id='html-content' type="text/html">
|
|
||||||
<a id="platform-button" style="display: none;" href="#">
|
<a id="platform-button" style="display: none;" href="#">
|
||||||
click or press "n" to cycle platforms
|
click or press "n" to cycle platforms
|
||||||
</a>
|
</a>
|
||||||
@@ -32,10 +31,7 @@
|
|||||||
|
|
||||||
<div id="platform-instructions-mac" class="instructions" style="display: none;">
|
<div id="platform-instructions-mac" class="instructions" style="display: none;">
|
||||||
<p>Run the following in your terminal (as a user other than root), then follow the onscreen instructions.</p>
|
<p>Run the following in your terminal (as a user other than root), then follow the onscreen instructions.</p>
|
||||||
<p>On Intel:</p>
|
|
||||||
<div class="command-button"><pre><span class='ghcup-command' id="ghcup-command-normal">curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh</span></pre><button class="tooltip" onclick="copyToClipboard()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button></div>
|
<div class="command-button"><pre><span class='ghcup-command' id="ghcup-command-normal">curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh</span></pre><button class="tooltip" onclick="copyToClipboard()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button></div>
|
||||||
<p>On Apple Silicon:</p>
|
|
||||||
<div class="command-button"><pre><span class='ghcup-command' id="ghcup-command-silicon">curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | arch -x86_64 /bin/bash</span></pre><button class="tooltip" onclick="copyToClipboardSilicon()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button></div>
|
|
||||||
<p class="other-help">If you don't like curl | sh, see <a href="https://gitlab.haskell.org/haskell/ghcup-hs#manual-install">other installation methods</a>.<br/>You appear to be running macOS. If not, <a class="default-platform-button" href="#">display all supported installers</a>.</p>
|
<p class="other-help">If you don't like curl | sh, see <a href="https://gitlab.haskell.org/haskell/ghcup-hs#manual-install">other installation methods</a>.<br/>You appear to be running macOS. If not, <a class="default-platform-button" href="#">display all supported installers</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -47,24 +43,41 @@
|
|||||||
|
|
||||||
<div id="platform-instructions-win32" class="instructions">
|
<div id="platform-instructions-win32" class="instructions">
|
||||||
<p>
|
<p>
|
||||||
To install Haskell, follow the instructions on
|
To install Haskell,<br/>run the following in a powershell session (as a non-admin user).
|
||||||
<a class="windows-download" href="https://www.haskell.org/platform/#windows">Haskell Platform</a>
|
<div>
|
||||||
<p>If you're a Windows Subsystem for Linux user run the following in your terminal, then follow the onscreen instructions to install Haskell.
|
<div class="command-button"><pre><span class='ghcup-command' id="ghcup-command-powershell">Set-ExecutionPolicy Bypass -Scope Process -Force;[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing))) -ArgumentList $false</span></span></pre><button class="tooltip" onclick="copyToClipboardPowershell()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button>
|
||||||
|
</div>
|
||||||
|
<p class="other-help">If you want to run an interactive installation, change <span class='code'>$false</span> to <span class='code'>$true</span> at the end of the script.</p>
|
||||||
|
</div>
|
||||||
|
<p>If you're a Windows Subsystem 2 for Linux user run the following in your terminal, then follow the onscreen instructions to install Haskell.
|
||||||
</p>
|
</p>
|
||||||
<div class="command-button"><pre><span class='ghcup-command'>curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh</span></pre><button class="tooltip" onclick="copyToClipboard()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button></div>
|
<div>
|
||||||
|
<div class="command-button"><pre><span class='ghcup-command'>curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh</span></pre><button class="tooltip" onclick="copyToClipboard()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button>
|
||||||
|
</div>
|
||||||
|
<p class="other-help">WSL1 does not work with ghcup, follow <a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">the instructions here</a> to upgrade to WSL2 if needed.</p>
|
||||||
|
</div>
|
||||||
</p>
|
</p>
|
||||||
<p class="other-help">You appear to be running Windows 32-bit. If not, <a class="default-platform-button" href="#">display all supported installers</a>.</p>
|
<hr/>
|
||||||
|
<p class="other-help">You appear to be running Windows 32-bit. If not, <a class="default-platform-button" href="#">display all supported installers</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="platform-instructions-win64" class="instructions" style="display: none;">
|
<div id="platform-instructions-win64" class="instructions" style="display: none;">
|
||||||
<p>
|
<p>
|
||||||
To install Haskell, follow the instructions on
|
To install Haskell,<br/>run the following in a powershell session (as a non-admin user).
|
||||||
<a class="windows-download" href="https://www.haskell.org/platform/#windows">Haskell Platform</a>
|
<div>
|
||||||
|
<div class="command-button"><pre><span class='ghcup-command'>Set-ExecutionPolicy Bypass -Scope Process -Force;[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing))) -ArgumentList $false</span></span></pre><button class="tooltip" onclick="copyToClipboardPowershell()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button>
|
||||||
|
</div>
|
||||||
|
<p class="other-help">If you want to run an interactive installation, change <span class='code'>$false</span> to <span class='code'>$true</span> at the end of the script.</p>
|
||||||
|
</div>
|
||||||
</p>
|
</p>
|
||||||
<p>If you're a Windows Subsystem for Linux user run the following in your terminal, then follow the onscreen instructions to install Haskell.
|
<p>If you're a Windows Subsystem 2 for Linux user run the following in your terminal, then follow the onscreen instructions to install Haskell.
|
||||||
</p>
|
</p>
|
||||||
<div class="command-button"><pre><span class='ghcup-command'>curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh</span></pre><button class="tooltip" onclick="copyToClipboard()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button></div>
|
<div>
|
||||||
<p class="other-help">You appear to be running Windows 64-bit. If not, <a class="default-platform-button" href="#">display all supported installers</a>.</p>
|
<div class="command-button"><pre><span class='ghcup-command'>curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh</span></pre><button class="tooltip" onclick="copyToClipboard()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button>
|
||||||
|
</div>
|
||||||
|
<p class="other-help">WSL1 does not work with ghcup, follow <a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">the instructions here</a> to upgrade to WSL2 if needed.</p>
|
||||||
|
</div>
|
||||||
|
<p class="other-help">You appear to be running Windows 64-bit. If not, <a class="default-platform-button" href="#">display all supported installers</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="platform-instructions-unknown" class="instructions" style="display: none;">
|
<div id="platform-instructions-unknown" class="instructions" style="display: none;">
|
||||||
@@ -86,7 +99,7 @@
|
|||||||
|
|
||||||
<!-- duplicate the default cross-platform instructions -->
|
<!-- duplicate the default cross-platform instructions -->
|
||||||
<div>
|
<div>
|
||||||
<p>If you are running Linux, macOS, FreeBSD or Windows Subsystem for Linux, run the following in your terminal (as a user other than root), then follow the onscreen instructions.</p>
|
<p>If you are running Linux, macOS, FreeBSD or Windows Subsystem 2 for Linux, run the following in your terminal (as a user other than root), then follow the onscreen instructions.</p>
|
||||||
<div class="command-button"><pre><span class='ghcup-command'>curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh</span></pre><button class="tooltip" onclick="copyToClipboard()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button></div>
|
<div class="command-button"><pre><span class='ghcup-command'>curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh</span></pre><button class="tooltip" onclick="copyToClipboard()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button></div>
|
||||||
<p class="other-help">If you don't like curl | sh, see <a href="https://gitlab.haskell.org/haskell/ghcup-hs#manual-install">other installation methods</a>.</p>
|
<p class="other-help">If you don't like curl | sh, see <a href="https://gitlab.haskell.org/haskell/ghcup-hs#manual-install">other installation methods</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
@@ -95,8 +108,8 @@
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<p>
|
<p>
|
||||||
If you are running Windows,<br/>follow the instructions on
|
If you are running Windows,<br/>run the following in a powershell session (as a non-admin user).
|
||||||
<a class="windows-download" href="https://www.haskell.org/platform/#windows">Haskell Platform</a>
|
<div class="command-button"><pre><span class='ghcup-command'>Set-ExecutionPolicy Bypass -Scope Process -Force;[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing))) -ArgumentList $false</span></span></pre><button class="tooltip" onclick="copyToClipboardPowershell()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button></div>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -104,11 +117,9 @@
|
|||||||
|
|
||||||
<div id="platform-instructions-default" class="instructions">
|
<div id="platform-instructions-default" class="instructions">
|
||||||
<div>
|
<div>
|
||||||
<p>To install Haskell, if you are running Linux, macOS (on Intel), FreeBSD or Windows Subsystem for Linux, run the following
|
<p>To install Haskell, if you are running Linux, macOS, FreeBSD or Windows Subsystem 2 for Linux, run the following
|
||||||
in your terminal (as a user other than root), then follow the onscreen instructions.</p>
|
in your terminal (as a user other than root), then follow the onscreen instructions.</p>
|
||||||
<div class="command-button"><pre><span class='ghcup-command'>curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh</span></pre><button class="tooltip" onclick="copyToClipboard()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button></div>
|
<div class="command-button"><pre><span class='ghcup-command'>curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh</span></pre><button class="tooltip" onclick="copyToClipboard()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button></div>
|
||||||
<p>For macOS on Apple Silicon, run this instead:</p>
|
|
||||||
<div class="command-button"><pre><span class='ghcup-command'>curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | arch -x86_64 /bin/bash</span></pre><button class="tooltip" onclick="copyToClipboardSilicon()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button></div>
|
|
||||||
<p class="other-help">If you don't like curl | sh, see <a href="https://gitlab.haskell.org/haskell/ghcup-hs#manual-install">other installation methods</a>.</p>
|
<p class="other-help">If you don't like curl | sh, see <a href="https://gitlab.haskell.org/haskell/ghcup-hs#manual-install">other installation methods</a>.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -116,15 +127,15 @@
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<p>
|
<p>
|
||||||
If you are running Windows,<br/>follow the instructions on
|
If you are running Windows,<br/>run the following in a powershell session (as a non-admin user).
|
||||||
<a class="windows-download" href="https://www.haskell.org/platform/#windows">Haskell Platform</a>
|
<div class="command-button"><pre><span class='ghcup-command'>Set-ExecutionPolicy Bypass -Scope Process -Force;[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072;Invoke-Command -ScriptBlock ([ScriptBlock]::Create((Invoke-WebRequest https://www.haskell.org/ghcup/sh/bootstrap-haskell.ps1 -UseBasicParsing))) -ArgumentList $false</span></span></pre><button class="tooltip" onclick="copyToClipboardPowershell()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button></div>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Need help? <a href="http://webchat.freenode.net/?randomnick=1&channels=%23haskell&uio=d4">Ask on #haskell</a> or <a href="https://gitlab.haskell.org/haskell/ghcup-hs/issues">report a bug</a>.
|
Need help? Ask on <a href="https://kiwiirc.com/nextclient/irc.libera.chat/#haskell-ghcup">#haskell-ghcup</a>, <a href="https://kiwiirc.com/nextclient/irc.libera.chat/#haskell">#haskell</a> or <a href="https://gitlab.haskell.org/haskell/ghcup-hs/issues">report a bug</a>.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p id="about">
|
<p id="about">
|
||||||
@@ -137,54 +148,7 @@
|
|||||||
·
|
·
|
||||||
<a href="https://github.com/rust-lang/rustup.rs/tree/master/www">web design from rustup</a>
|
<a href="https://github.com/rust-lang/rustup.rs/tree/master/www">web design from rustup</a>
|
||||||
</p>
|
</p>
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
document.write(document.getElementById("html-content").innerHTML);
|
|
||||||
</script>
|
|
||||||
<script type="text/javascript" src="ghcup.js"></script>
|
<script type="text/javascript" src="ghcup.js"></script>
|
||||||
|
|
||||||
<noscript>
|
|
||||||
<p id="pitch">
|
|
||||||
<em>ghcup</em> is an installer for<br/>
|
|
||||||
the general purpose language <a href="https://www.haskell.org/">Haskell</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div id="platform-instructions-default" class="instructions">
|
|
||||||
<div>
|
|
||||||
<p>To install Haskell, if you are running Linux, macOS (on Intel), FreeBSD or Windows Subsystem for Linux, run the following
|
|
||||||
in your terminal (as a user other than root), then follow the onscreen instructions.</p>
|
|
||||||
<pre><span class='ghcup-command'>curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh</span></pre>
|
|
||||||
<p>For macOS on Apple Silicon, run this instead:</p>
|
|
||||||
<div class="command-button"><pre><span class='ghcup-command'>curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | arch -x86_64 /bin/bash</span></pre><button class="tooltip" onclick="copyToClipboardSilicon()"><img src="copy.svg" alt="" /><span class="tooltiptext">Copy to clipboard</span></button></div>
|
|
||||||
<p class="other-help">If you don't like curl | sh, see <a href="https://gitlab.haskell.org/haskell/ghcup-hs#manual-install">other installation methods</a>.</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<hr/>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<p>
|
|
||||||
If you are running Windows,<br/>follow the instructions on
|
|
||||||
<a class="windows-download" href="https://www.haskell.org/platform/#windows">Haskell Platform</a>
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p>
|
|
||||||
Need help? <a href="http://webchat.freenode.net/?randomnick=1&channels=%23haskell&uio=d4">Ask on #haskell</a>.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<p id="about">
|
|
||||||
<img src="haskell-logo.svg" alt="" />
|
|
||||||
ghcup is a haskell.org hosted project.
|
|
||||||
<br/>
|
|
||||||
<a href="https://www.haskell.org/downloads/">other installation options</a>
|
|
||||||
·
|
|
||||||
<a href="https://gitlab.haskell.org/haskell/ghcup-hs">about ghcup</a>
|
|
||||||
·
|
|
||||||
<a href="https://github.com/rust-lang/rustup.rs/tree/master/www">web design from rustup</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
</noscript>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user