Merge branch 'windows-support'
This commit is contained in:
commit
98751cf8fb
@ -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,6 +38,7 @@ 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: "arm32v7/fedora"
|
||||||
@ -44,6 +47,7 @@ variables:
|
|||||||
variables:
|
variables:
|
||||||
OS: "LINUX"
|
OS: "LINUX"
|
||||||
ARCH: "ARM"
|
ARCH: "ARM"
|
||||||
|
CABAL_DIR: "$CI_PROJECT_DIR/cabal"
|
||||||
|
|
||||||
.linux:aarch64:
|
.linux:aarch64:
|
||||||
image: "arm64v8/fedora"
|
image: "arm64v8/fedora"
|
||||||
@ -52,6 +56,7 @@ variables:
|
|||||||
variables:
|
variables:
|
||||||
OS: "LINUX"
|
OS: "LINUX"
|
||||||
ARCH: "ARM64"
|
ARCH: "ARM64"
|
||||||
|
CABAL_DIR: "$CI_PROJECT_DIR/cabal"
|
||||||
|
|
||||||
.darwin:
|
.darwin:
|
||||||
tags:
|
tags:
|
||||||
@ -59,6 +64,7 @@ variables:
|
|||||||
variables:
|
variables:
|
||||||
OS: "DARWIN"
|
OS: "DARWIN"
|
||||||
ARCH: "64"
|
ARCH: "64"
|
||||||
|
CABAL_DIR: "$CI_PROJECT_DIR/cabal"
|
||||||
|
|
||||||
.freebsd:
|
.freebsd:
|
||||||
tags:
|
tags:
|
||||||
@ -66,22 +72,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:
|
||||||
@ -132,9 +141,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 +160,7 @@ variables:
|
|||||||
only:
|
only:
|
||||||
- tags
|
- tags
|
||||||
variables:
|
variables:
|
||||||
JSON_VERSION: "0.0.4"
|
JSON_VERSION: "0.0.5"
|
||||||
|
|
||||||
######## stack test ########
|
######## stack test ########
|
||||||
|
|
||||||
@ -260,6 +278,15 @@ test:freebsd:latest:
|
|||||||
when: manual
|
when: manual
|
||||||
needs: []
|
needs: []
|
||||||
|
|
||||||
|
######## windows test ########
|
||||||
|
|
||||||
|
test:windows:recommended:
|
||||||
|
stage: test
|
||||||
|
extends: .test_ghcup_version:windows
|
||||||
|
variables:
|
||||||
|
GHC_VERSION: "8.10.4"
|
||||||
|
CABAL_VERSION: "3.4.0.0"
|
||||||
|
needs: []
|
||||||
|
|
||||||
######## linux release ########
|
######## linux release ########
|
||||||
|
|
||||||
@ -350,6 +377,21 @@ release:freebsd:
|
|||||||
GHC_VERSION: "8.10.4"
|
GHC_VERSION: "8.10.4"
|
||||||
CABAL_VERSION: "3.4.0.0"
|
CABAL_VERSION: "3.4.0.0"
|
||||||
|
|
||||||
|
######## 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.4"
|
||||||
|
CABAL_VERSION: "3.4.0.0"
|
||||||
|
|
||||||
######## hlint ########
|
######## hlint ########
|
||||||
|
|
||||||
|
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
|
@ -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,7 +7,7 @@ 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
|
||||||
|
|
||||||
curl -sSfL https://downloads.haskell.org/~ghcup/x86_64-linux-ghcup > ./ghcup-bin
|
curl -sSfL https://downloads.haskell.org/~ghcup/x86_64-linux-ghcup > ./ghcup-bin
|
||||||
chmod +x ghcup-bin
|
chmod +x ghcup-bin
|
||||||
|
@ -19,7 +19,7 @@ ednf() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ednf update
|
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
|
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 bzip2-devel
|
||||||
if [ "${ARCH}" = "ARM64" ] ; then
|
if [ "${ARCH}" = "ARM64" ] ; then
|
||||||
ednf install numactl numactl-libs numactl-devel
|
ednf install numactl numactl-libs numactl-devel
|
||||||
fi
|
fi
|
||||||
|
@ -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
|
||||||
|
22
.gitlab/before_script/windows/install_deps.sh
Normal file
22
.gitlab/before_script/windows/install_deps.sh
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
. "$( cd "$(dirname "$0")" ; pwd -P )/../../ghcup_env"
|
||||||
|
|
||||||
|
mkdir -p "${TMPDIR}" "${CABAL_DIR}"
|
||||||
|
|
||||||
|
rm -rf /c/ghcup
|
||||||
|
mkdir -p /c/ghcup
|
||||||
|
|
||||||
|
CI_PROJECT_DIR=$(pwd)
|
||||||
|
curl -o ghcup.exe https://downloads.haskell.org/~ghcup/tmp/x86_64-mingw64-ghcup-5.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="/c/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:$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
|
||||||
@ -30,6 +30,8 @@ if [ "${OS}" = "LINUX" ] ; then
|
|||||||
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" -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
|
||||||
|
@ -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
|
||||||
@ -36,6 +42,9 @@ elif [ "${OS}" = "LINUX" ] ; then
|
|||||||
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
|
||||||
fi
|
fi
|
||||||
|
elif [ "${OS}" = "WINDOWS" ] ; then
|
||||||
|
ecabal build -w ghc-${GHC_VERSION}
|
||||||
|
ecabal test -w ghc-${GHC_VERSION} ghcup-test
|
||||||
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
|
||||||
@ -116,8 +125,12 @@ 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
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
## 0.1.15 -- ????-??-??
|
## 0.1.15 -- ????-??-??
|
||||||
|
|
||||||
|
* Add windows support wrt [#130](https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/130)
|
||||||
* Add date to GHC bindist names created by ghcup
|
* Add date to GHC bindist names created by ghcup
|
||||||
* 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)
|
||||||
|
@ -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.
|
||||||
|
@ -234,7 +234,7 @@ ghcup is not a reimplementation of stack. The only common part is automatic inst
|
|||||||
|
|
||||||
2. Why not support windows?
|
2. Why not support windows?
|
||||||
|
|
||||||
Windows support is [WIP](https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/130).
|
We do.
|
||||||
|
|
||||||
3. Why the haskell reimplementation?
|
3. Why the haskell reimplementation?
|
||||||
|
|
||||||
|
@ -123,8 +123,8 @@ main = do
|
|||||||
|
|
||||||
where
|
where
|
||||||
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
|
||||||
@ -188,22 +194,24 @@ 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 tool 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 = nubOrd $ dls ^.. each %& indices (maybe (const True) (==) tool) %> each %& indices (matchTest versionRegex . T.unpack . prettyVer) % (viSourceDL % _Just `summing` viArch % each % each % each)
|
||||||
%& indices (maybe (const True) (==) tool) %> each
|
|
||||||
%& indices (matchTest versionRegex . T.unpack . prettyVer)
|
|
||||||
% (viSourceDL % _Just `summing` viArch % each % each % each)
|
|
||||||
when (null dlis) $ $(logError) [i|no tarballs selected by filter|] *> addError
|
when (null dlis) $ $(logError) [i|no tarballs selected by filter|] *> addError
|
||||||
|
|
||||||
forM_ dlis downloadAll
|
let gdlis = nubOrd $ gt ^.. each
|
||||||
|
|
||||||
|
forM_ (dlis ++ gdlis) downloadAll
|
||||||
|
|
||||||
-- exit
|
-- exit
|
||||||
e <- liftIO $ readIORef ref
|
e <- liftIO $ readIORef ref
|
||||||
@ -220,11 +228,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
|
||||||
@ -238,13 +256,12 @@ validateTarballs (TarballFilter tool versionRegex) dls = do
|
|||||||
$ do
|
$ do
|
||||||
case tool of
|
case tool of
|
||||||
Just GHCup -> do
|
Just GHCup -> do
|
||||||
let fn = [rel|ghcup|]
|
let fn = "ghcup"
|
||||||
dir <- liftIO ghcupCacheDir
|
p <- liftE $ download (settings appstate) dli (cacheDir dirs) (Just fn)
|
||||||
p <- liftE $ download dli dir (Just fn)
|
liftE $ checkDigest (settings appstate) dli p
|
||||||
liftE $ checkDigest dli p
|
|
||||||
pure Nothing
|
pure Nothing
|
||||||
_ -> do
|
_ -> 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
|
||||||
@ -252,7 +269,7 @@ validateTarballs (TarballFilter tool versionRegex) dls = do
|
|||||||
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,11 +60,12 @@ 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
|
||||||
|
|
||||||
@ -96,7 +100,7 @@ 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')
|
||||||
, ( bShowAllVersions
|
, ( bShowAllVersions
|
||||||
, \BrickSettings {..} ->
|
, \BrickSettings {..} ->
|
||||||
@ -148,12 +152,7 @@ ui dimAttrs BrickState{ appSettings = as@BrickSettings{}, ..}
|
|||||||
<+> minHSize 15 (str "Version")
|
<+> minHSize 15 (str "Version")
|
||||||
<+> padLeft (Pad 1) (minHSize 25 $ str "Tags")
|
<+> padLeft (Pad 1) (minHSize 25 $ str "Tags")
|
||||||
<+> padLeft (Pad 5) (str "Notes")
|
<+> padLeft (Pad 5) (str "Notes")
|
||||||
renderList' = withDefAttr listAttr . drawListElements renderItem True . filterStack
|
renderList' = withDefAttr listAttr . drawListElements renderItem True
|
||||||
filterStack appState'
|
|
||||||
| showAllTools as = appState'
|
|
||||||
| let v = clr appState'
|
|
||||||
nv = V.filter (\ListResult{..} -> lTool /= Stack) v
|
|
||||||
, otherwise = BrickInternalState { clr = nv, ix = ix appState' }
|
|
||||||
renderItem _ b listResult@ListResult{..} =
|
renderItem _ b listResult@ListResult{..} =
|
||||||
let marks = if
|
let marks = if
|
||||||
| lSet -> (withAttr "set" $ str "✔✔")
|
| lSet -> (withAttr "set" $ str "✔✔")
|
||||||
@ -328,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.
|
||||||
@ -363,7 +366,9 @@ constructList :: BrickData
|
|||||||
-> Maybe BrickInternalState
|
-> Maybe BrickInternalState
|
||||||
-> BrickInternalState
|
-> BrickInternalState
|
||||||
constructList appD appSettings =
|
constructList appD appSettings =
|
||||||
replaceLR (filterVisible (showAllVersions 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
|
||||||
@ -396,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 showAllVersions e | lInstalled e = True
|
filterVisible v t e | lInstalled e = True
|
||||||
| showAllVersions = 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
|
||||||
@ -434,24 +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
|
Stack -> do
|
||||||
let vi = getVersionInfo lVer Stack dls
|
let vi = getVersionInfo lVer Stack dls
|
||||||
liftE $ installStackBin dls lVer pfreq $> vi
|
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 ()
|
||||||
@ -483,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
|
||||||
@ -508,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}|]
|
||||||
@ -518,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
|
||||||
|
|
||||||
@ -537,6 +561,8 @@ settings' = unsafePerformIO $ do
|
|||||||
})
|
})
|
||||||
dirs
|
dirs
|
||||||
defaultKeyBindings
|
defaultKeyBindings
|
||||||
|
(GHCupInfo mempty mempty mempty)
|
||||||
|
(PlatformRequest A_64 Darwin Nothing)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -552,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
|
||||||
@ -563,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
|
||||||
@ -584,8 +609,8 @@ defaultAppSettings :: BrickSettings
|
|||||||
defaultAppSettings = BrickSettings { showAllVersions = False, showAllTools = 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
|
||||||
@ -594,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
|
||||||
@ -170,17 +167,17 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
data UpgradeOpts = UpgradeInplace
|
data UpgradeOpts = UpgradeInplace
|
||||||
| UpgradeAt (Path Abs)
|
| UpgradeAt FilePath
|
||||||
| UpgradeGHCupDir
|
| UpgradeGHCupDir
|
||||||
deriving Show
|
deriving Show
|
||||||
|
|
||||||
@ -721,8 +718,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'
|
||||||
@ -740,26 +736,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)"
|
||||||
)
|
)
|
||||||
@ -821,53 +805,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
|
||||||
|
|
||||||
|
|
||||||
@ -988,9 +966,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
|
||||||
@ -998,10 +975,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
|
||||||
@ -1009,7 +986,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
|
||||||
@ -1040,13 +1017,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"
|
||||||
)
|
)
|
||||||
@ -1058,9 +1029,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
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -1068,6 +1042,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)
|
||||||
@ -1104,28 +1083,76 @@ 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
|
||||||
|
|
||||||
|
(settings, keybindings) <- toSettings opt
|
||||||
|
|
||||||
-- create ~/.ghcup dir
|
-- create ~/.ghcup dir
|
||||||
createDirRecursive' baseDir
|
createDirRecursive' (baseDir dirs)
|
||||||
|
|
||||||
-- 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 = 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 ()
|
||||||
|
_ -> runLogger $ flip runReaderT appstate $ checkForUpdates
|
||||||
|
|
||||||
|
|
||||||
|
-- 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
|
||||||
@ -1228,57 +1255,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
|
||||||
)
|
)
|
||||||
@ -1294,8 +1286,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
|
||||||
@ -1308,16 +1300,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
|
||||||
@ -1338,16 +1329,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
|
||||||
@ -1368,16 +1358,15 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
|
|
||||||
let installStack InstallOptions{..} =
|
let installStack InstallOptions{..} =
|
||||||
(case instBindist of
|
(case instBindist of
|
||||||
Nothing -> runInstTool $ do
|
Nothing -> runInstTool instPlatform $ do
|
||||||
(v, vi) <- liftE $ fromVersion dls instVer Stack
|
(v, vi) <- liftE $ fromVersion instVer Stack
|
||||||
liftE $ installStackBin dls (_tvVersion v) (fromMaybe pfreq instPlatform)
|
liftE $ installStackBin (_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 Stack
|
(v, vi) <- liftE $ fromVersion instVer Stack
|
||||||
liftE $ installStackBindist
|
liftE $ installStackBindist
|
||||||
(DownloadInfo uri Nothing "")
|
(DownloadInfo uri Nothing "")
|
||||||
(_tvVersion v)
|
(_tvVersion v)
|
||||||
(fromMaybe pfreq instPlatform)
|
|
||||||
pure vi
|
pure vi
|
||||||
)
|
)
|
||||||
>>= \case
|
>>= \case
|
||||||
@ -1399,7 +1388,7 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
|
|
||||||
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
|
||||||
@ -1414,7 +1403,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
|
||||||
)
|
)
|
||||||
@ -1430,7 +1419,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
|
||||||
)
|
)
|
||||||
@ -1446,7 +1435,7 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
|
|
||||||
let setStack' SetOptions{..} =
|
let setStack' SetOptions{..} =
|
||||||
runSetCabal (do
|
runSetCabal (do
|
||||||
v <- liftE $ fst <$> fromVersion' dls sToolVer Stack
|
v <- liftE $ fst <$> fromVersion' sToolVer Stack
|
||||||
liftE $ setStack (_tvVersion v)
|
liftE $ setStack (_tvVersion v)
|
||||||
pure v
|
pure v
|
||||||
)
|
)
|
||||||
@ -1522,7 +1511,8 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
|
|
||||||
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.|])
|
||||||
@ -1545,7 +1535,7 @@ Report bugs at <https://gitlab.haskell.org/haskell/ghcup-hs/issues>|]
|
|||||||
|
|
||||||
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
|
||||||
)
|
)
|
||||||
@ -1579,14 +1569,13 @@ 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)
|
||||||
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
|
||||||
@ -1605,8 +1594,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
|
||||||
@ -1616,14 +1605,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"))
|
||||||
|
|
||||||
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
|
||||||
@ -1640,12 +1626,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
|
||||||
@ -1677,12 +1664,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
|
||||||
@ -1697,36 +1685,40 @@ Make sure to clean up #{tmpdir} afterwards.|])
|
|||||||
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
|
||||||
@ -1769,17 +1761,14 @@ fromVersion' av SetNext tool = do
|
|||||||
. sort
|
. sort
|
||||||
$ stacks) ?? NoToolVersionSet tool
|
$ 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
|
||||||
@ -1803,9 +1792,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
|
||||||
@ -1932,11 +1927,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
|
||||||
@ -1977,10 +1971,10 @@ checkForUpdates dls pfreq = do
|
|||||||
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,51 @@
|
|||||||
# 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.14.1"
|
||||||
|
base_url="https://downloads.haskell.org/~ghcup"
|
||||||
|
|
||||||
export GHCUP_USE_XDG_DIRS
|
case "${plat}" in
|
||||||
|
MSYS*|MINGW*)
|
||||||
|
: "${GHCUP_INSTALL_BASE_PREFIX:=/c}"
|
||||||
|
GHCUP_DIR=${GHCUP_INSTALL_BASE_PREFIX}/ghcup
|
||||||
|
GHCUP_BIN=${GHCUP_INSTALL_BASE_PREFIX}/ghcup/bin
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
: "${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 +68,133 @@ 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 ${args} "$@"
|
||||||
else
|
else
|
||||||
ghcup --verbose "$@"
|
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)
|
||||||
;;
|
;;
|
||||||
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} ;;
|
_url=${base_url}/${ghver}/x86_64-apple-darwin-ghcup-${ghver} ;;
|
||||||
*) die "Unknown platform: ${_plat}"
|
MSYS*|MINGW*)
|
||||||
|
case "${arch}" in
|
||||||
|
x86_64|amd64)
|
||||||
|
_url=https://downloads.haskell.org/~ghcup/tmp/x86_64-mingw64-ghcup-7.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 +203,6 @@ 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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -155,7 +219,14 @@ 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."
|
||||||
@ -163,8 +234,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
|
||||||
@ -182,12 +253,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.
|
||||||
@ -200,21 +271,54 @@ 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}"
|
||||||
|
|
||||||
|
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_DIR"/msys64/usr/bin), $(cygpath -w "$GHCUP_DIR"/msys64/mingw64/bin)" -a "extra-include-dirs: $(cygpath -w "$GHCUP_DIR"/msys64/mingw64/include)" -a "extra-lib-dirs: $(cygpath -w "$GHCUP_DIR"/msys64/mingw64/lib)" -f init
|
||||||
|
}
|
||||||
|
|
||||||
|
case "${plat}" in
|
||||||
|
MSYS*|MINGW*)
|
||||||
|
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)."
|
||||||
|
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
|
edo cabal new-update
|
||||||
|
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" ""
|
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "Installation done!"
|
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" ""
|
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
@ -223,19 +327,25 @@ if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
|||||||
[Yy]*)
|
[Yy]*)
|
||||||
eghcup --cache install hls
|
eghcup --cache install hls
|
||||||
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
|
||||||
|
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "Do you want to install stack now?"
|
warn "Do you want to install stack now?"
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "Stack is a haskell build tool similar to cabal that is used by some projects."
|
warn "Stack is a haskell build tool similar to cabal that is used by some projects."
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "Also see https://docs.haskellstack.org/"
|
warn "Also see https://docs.haskellstack.org/"
|
||||||
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 stack_answer </dev/tty
|
read -r stack_answer </dev/tty
|
||||||
@ -244,10 +354,16 @@ if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
|||||||
[Yy]*)
|
[Yy]*)
|
||||||
eghcup --cache install stack
|
eghcup --cache install stack
|
||||||
break ;;
|
break ;;
|
||||||
[Nn]*)
|
[Nn]* | "")
|
||||||
break ;;
|
break ;;
|
||||||
*)
|
*)
|
||||||
echo "Please type YES or NO and press enter.";;
|
echo "Possible choices are:"
|
||||||
|
echo
|
||||||
|
echo "Y - Yes, install stack"
|
||||||
|
echo "N - No, don't install anything more (default)"
|
||||||
|
echo
|
||||||
|
echo "Please make your choice and press ENTER."
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -280,17 +396,20 @@ if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
|||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" ""
|
warn ""
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "Detected ${MY_SHELL} shell on your system..."
|
warn "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}\""
|
warn "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."
|
warn ""
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" ""
|
warn "[Y] Yes [N] No [?] Help (default is \"Y\")."
|
||||||
|
warn ""
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
read -r next_answer </dev/tty
|
read -r next_answer </dev/tty
|
||||||
|
|
||||||
case $next_answer in
|
case $next_answer in
|
||||||
[Yy]*)
|
[Nn]*)
|
||||||
|
_done ;;
|
||||||
|
[Yy]* | "")
|
||||||
case $MY_SHELL in
|
case $MY_SHELL in
|
||||||
"") break ;;
|
"") break ;;
|
||||||
fish)
|
fish)
|
||||||
@ -305,7 +424,7 @@ if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
|||||||
if ! grep -q "ghcup-env" "${GHCUP_PROFILE_FILE}" ; then
|
if ! grep -q "ghcup-env" "${GHCUP_PROFILE_FILE}" ; then
|
||||||
echo "[ -f \"${GHCUP_DIR}/env\" ] && source \"${GHCUP_DIR}/env\" # ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
echo "[ -f \"${GHCUP_DIR}/env\" ] && source \"${GHCUP_DIR}/env\" # ghcup-env" >> "${GHCUP_PROFILE_FILE}"
|
||||||
fi
|
fi
|
||||||
case "$(uname -s)" in
|
case "${plat}" in
|
||||||
"Darwin"|"darwin")
|
"Darwin"|"darwin")
|
||||||
if ! grep -q "ghcup-env" "${HOME}/.bash_profile" ; then
|
if ! grep -q "ghcup-env" "${HOME}/.bash_profile" ; then
|
||||||
echo "[[ -f ~/.bashrc ]] && source ~/.bashrc # ghcup-env" >> "${HOME}/.bash_profile"
|
echo "[[ -f ~/.bashrc ]] && source ~/.bashrc # ghcup-env" >> "${HOME}/.bash_profile"
|
||||||
@ -320,17 +439,24 @@ if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
|||||||
fi
|
fi
|
||||||
break ;;
|
break ;;
|
||||||
esac
|
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,"
|
warn "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."
|
warn "or type \"source ${GHCUP_DIR}/env\" to apply them in your current terminal session."
|
||||||
_done
|
_done
|
||||||
;;
|
;;
|
||||||
[Nn]*)
|
*)
|
||||||
_done ;;
|
echo "Possible choices are:"
|
||||||
*)
|
echo
|
||||||
echo "Please type YES or NO and press enter.";;
|
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
|
esac
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
_done
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# vim: tabstop=4 shiftwidth=4 expandtab
|
# vim: tabstop=4 shiftwidth=4 expandtab
|
||||||
|
194
bootstrap-haskell.ps1
Normal file
194
bootstrap-haskell.ps1
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
function Print-Msg {
|
||||||
|
param ( [Parameter(Mandatory=$true, HelpMessage='String to output')][string]$msg )
|
||||||
|
Write-Host ('{0}' -f $msg) -ForegroundColor Green
|
||||||
|
}
|
||||||
|
|
||||||
|
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 Pathe to add to Users environment')]
|
||||||
|
[string] $Path,
|
||||||
|
|
||||||
|
[ValidateSet('Machine', 'User', 'Session')]
|
||||||
|
[string] $Container = 'Session'
|
||||||
|
)
|
||||||
|
|
||||||
|
function Where-Something
|
||||||
|
{
|
||||||
|
param
|
||||||
|
(
|
||||||
|
[Parameter(Mandatory=$true, ValueFromPipeline=$true, HelpMessage='Data to filter')]
|
||||||
|
$InputObject
|
||||||
|
)
|
||||||
|
process
|
||||||
|
{
|
||||||
|
if ($InputObject)
|
||||||
|
{
|
||||||
|
$InputObject
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($Container -ne 'Session') {
|
||||||
|
$containerMapping = @{
|
||||||
|
Machine = [EnvironmentVariableTarget]::Machine
|
||||||
|
User = [EnvironmentVariableTarget]::User
|
||||||
|
}
|
||||||
|
$containerType = $containerMapping[$Container]
|
||||||
|
|
||||||
|
$persistedPaths = [Environment]::GetEnvironmentVariable('Path', $containerType) -split ';'
|
||||||
|
if ($persistedPaths -notcontains $Path) {
|
||||||
|
$persistedPaths = $persistedPaths + $Path | Where-Something
|
||||||
|
[Environment]::SetEnvironmentVariable('Path', $persistedPaths -join ';', $containerType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$envPaths = $env:Path -split ';'
|
||||||
|
if ($envPaths -notcontains $Path) {
|
||||||
|
$envPaths = $envPaths + $Path | Where-Something
|
||||||
|
$env:Path = $envPaths -join ';'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
$ErrorActionPreference = 'Stop'
|
||||||
|
|
||||||
|
$GhcupDir = "$env:HOMEDRIVE\ghcup"
|
||||||
|
$MsysDir = ('{0}\msys64' -f $GhcupDir)
|
||||||
|
$Bash = ('{0}\usr\bin\bash' -f $MsysDir)
|
||||||
|
|
||||||
|
Print-Msg -msg 'Preparing for GHCup installation...'
|
||||||
|
|
||||||
|
if (Test-Path -Path ('{0}' -f $GhcupDir)) {
|
||||||
|
$decision = $Host.UI.PromptForChoice('Install', 'GHCup is already installed, what do you want to do?', @('&Reinstall'
|
||||||
|
'&Continue'
|
||||||
|
'&Abort'), 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$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))) {
|
||||||
|
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) {
|
||||||
|
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...'
|
||||||
|
& "$Bash" -lc 'exit'
|
||||||
|
|
||||||
|
& "$env:windir\system32\taskkill.exe" /F /FI `"MODULES eq msys-2.0.dll`"
|
||||||
|
|
||||||
|
Print-Msg -msg 'Upgrading full system...'
|
||||||
|
& "$Bash" -lc 'pacman --noconfirm -Syuu'
|
||||||
|
|
||||||
|
Print-Msg -msg 'Upgrading full system twice...'
|
||||||
|
& "$Bash" -lc 'pacman --noconfirm -Syuu'
|
||||||
|
|
||||||
|
Print-Msg -msg 'Installing GHC Build Dependencies...'
|
||||||
|
& "$Bash" -lc 'pacman --noconfirm -S --needed git tar curl wget base-devel gettext binutils autoconf make libtool automake python p7zip patch unzip mingw-w64-x86_64-toolchain mingw-w64-x86_64-gcc mingw-w64-x86_64-gdb mingw-w64-x86_64-python2 mingw-w64-x86_64-python3-sphinx'
|
||||||
|
|
||||||
|
Print-Msg -msg 'Updating SSL root certificate authorities...'
|
||||||
|
& "$Bash" -lc 'pacman --noconfirm -S ca-certificates'
|
||||||
|
|
||||||
|
Print-Msg -msg 'Setting default home directory...'
|
||||||
|
& "$Bash" -lc "sed -i -e 's/db_home:.*$/db_home: windows/' /etc/nsswitch.conf"
|
||||||
|
} else {
|
||||||
|
Print-Msg -msg ('...Msys2 found in {0} ...skipping Msys2 installation.' -f $MsysDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
Print-Msg -msg 'Creating shortcuts...'
|
||||||
|
Create-Shortcut -SourceExe ('{0}\msys2_shell.cmd' -f $MsysDir) -ArgumentsToSourceExe '-mingw64' -DestinationPath ('{0}\Desktop\Mingw haskell shell.lnk' -f $HOME)
|
||||||
|
Create-Shortcut -SourceExe 'https://www.msys2.org/docs/package-management' -ArgumentsToSourceExe '' -DestinationPath ('{0}\Desktop\Mingw package management docs.url' -f $HOME)
|
||||||
|
|
||||||
|
Print-Msg -msg ('Adding {0}\bin to Users Path...' -f $GhcupDir)
|
||||||
|
Add-EnvPath -Path ('{0}\bin' -f $GhcupDir) -Container 'User'
|
||||||
|
|
||||||
|
Print-Msg -msg 'Starting GHCup installer...'
|
||||||
|
& "$Bash" -lc "export PATH=`"/c/ghcup/bin:`$PATH`" ; curl --proto =https --tlsv1.2 -sSf https://gitlab.haskell.org/haskell/ghcup-hs/-/raw/windows-support/bootstrap-haskell | bash"
|
||||||
|
# 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
|
@ -2,17 +2,19 @@ packages: ./ghcup.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
|
ghc-options: -O2 -rtsopts
|
||||||
tests: True
|
tests: True
|
||||||
flags: +tui
|
flags: +tui
|
||||||
|
|
||||||
|
source-repository-package
|
||||||
|
type: git
|
||||||
|
location: https://github.com/Bodigrim/tar
|
||||||
|
tag: ac197ec7ea4838dc2b4e22b9b888b080cedf29cf
|
||||||
|
|
||||||
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
|
||||||
|
157
ghcup-0.0.4.yaml
157
ghcup-0.0.4.yaml
@ -127,6 +127,13 @@ toolRequirements:
|
|||||||
- libffi
|
- libffi
|
||||||
- libiconv
|
- libiconv
|
||||||
notes: ''
|
notes: ''
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
distroPKGs: []
|
||||||
|
notes: On Windows, msys2 should already have been set up during the installation,
|
||||||
|
so most users should just press ENTER.
|
||||||
|
If you are installing manually, make sure to have a working mingw64 toolchain and
|
||||||
|
shell.
|
||||||
ghcupDownloads:
|
ghcupDownloads:
|
||||||
GHC:
|
GHC:
|
||||||
7.10.3:
|
7.10.3:
|
||||||
@ -170,6 +177,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/7.10.3/ghc-7.10.3-x86_64-portbld-freebsd.tar.bz2
|
dlUri: https://downloads.haskell.org/~ghc/7.10.3/ghc-7.10.3-x86_64-portbld-freebsd.tar.bz2
|
||||||
dlSubdir: ghc-7.10.3
|
dlSubdir: ghc-7.10.3
|
||||||
dlHash: 2aa396edd2bb651f4bc7eef7a396913ea24923de5aafdc76df6295333e487e48
|
dlHash: 2aa396edd2bb651f4bc7eef7a396913ea24923de5aafdc76df6295333e487e48
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/7.10.3/ghc-7.10.3-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-7.10.3
|
||||||
|
dlHash: 63e1689fc9e2809ae4d7f422b4dc810052e54c9aa2afd08746e234180e711dde
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
unknown_versioning: &ghc-7103-32-deb8
|
unknown_versioning: &ghc-7103-32-deb8
|
||||||
@ -236,6 +248,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/8.0.2/ghc-8.0.2-x86_64-portbld-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/8.0.2/ghc-8.0.2-x86_64-portbld-freebsd.tar.xz
|
||||||
dlSubdir: ghc-8.0.2
|
dlSubdir: ghc-8.0.2
|
||||||
dlHash: b36a20e5cae24d70bbb6116ae486f21811e9384f15d3892d260f02fba3e3bb8c
|
dlHash: b36a20e5cae24d70bbb6116ae486f21811e9384f15d3892d260f02fba3e3bb8c
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.0.2/ghc-8.0.2-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.0.2
|
||||||
|
dlHash: 8c42c1f4af995205b9816a1e97e2752fe758544c1f5fe77958cdcd319c9c2d53
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
'( >= 7 && < 8 )':
|
'( >= 7 && < 8 )':
|
||||||
@ -300,6 +317,11 @@ ghcupDownloads:
|
|||||||
dlSubdir: ghc-8.2.2
|
dlSubdir: ghc-8.2.2
|
||||||
dlHash: cd351c704b92b9af23994024df07de8ca7090ea7675d5c8b14b2be857a46d804
|
dlHash: cd351c704b92b9af23994024df07de8ca7090ea7675d5c8b14b2be857a46d804
|
||||||
unknown_versioning: *ghc-822-64-fbsd11
|
unknown_versioning: *ghc-822-64-fbsd11
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.2.2/ghc-8.2.2-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.2.2
|
||||||
|
dlHash: 1e033df2092aa546e763e7be63167720b32df64f76673ea1ce7ae7c9f564b223
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
'( >= 7 && < 8 )':
|
'( >= 7 && < 8 )':
|
||||||
@ -359,6 +381,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/8.4.1/ghc-8.4.1-x86_64-portbld11-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/8.4.1/ghc-8.4.1-x86_64-portbld11-freebsd.tar.xz
|
||||||
dlSubdir: ghc-8.4.1
|
dlSubdir: ghc-8.4.1
|
||||||
dlHash: e748daec098445c6190090fe32bb2817a1140553be5acd2188e1af05ad24e5aa
|
dlHash: e748daec098445c6190090fe32bb2817a1140553be5acd2188e1af05ad24e5aa
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.4.1/ghc-8.4.1-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.4.1
|
||||||
|
dlHash: 328b013fc651d34e075019107e58bb6c8a578f0155cf3ad4557e6f2661b03131
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
unknown_versioning: &ghc-841-32-deb8
|
unknown_versioning: &ghc-841-32-deb8
|
||||||
@ -414,6 +441,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/8.4.2/ghc-8.4.2-x86_64-portbld-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/8.4.2/ghc-8.4.2-x86_64-portbld-freebsd.tar.xz
|
||||||
dlSubdir: ghc-8.4.2
|
dlSubdir: ghc-8.4.2
|
||||||
dlHash: e9ed417fdf94c2ff2c6e344ed16f332bf6b591511f6442c0d9ea94854882b66c
|
dlHash: e9ed417fdf94c2ff2c6e344ed16f332bf6b591511f6442c0d9ea94854882b66c
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.4.2/ghc-8.4.2-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.4.2
|
||||||
|
dlHash: 797634aa9812fc6b2084a24ddb4fde44fa83a2f59daea82e0af81ca3dd323fde
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
unknown_versioning: &ghc-842-32-deb8
|
unknown_versioning: &ghc-842-32-deb8
|
||||||
@ -464,6 +496,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/8.4.3/ghc-8.4.3-x86_64-apple-darwin.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/8.4.3/ghc-8.4.3-x86_64-apple-darwin.tar.xz
|
||||||
dlSubdir: ghc-8.4.3
|
dlSubdir: ghc-8.4.3
|
||||||
dlHash: af0b455f6c46b9802b4b48dad996619cfa27cc6e2bf2ce5532387b4a8c00aa64
|
dlHash: af0b455f6c46b9802b4b48dad996619cfa27cc6e2bf2ce5532387b4a8c00aa64
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.4.3/ghc-8.4.3-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.4.3
|
||||||
|
dlHash: 8a83cfbf9ae84de0443c39c93b931693bdf2a6d4bf163ffb41855f80f4bf883e
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
unknown_versioning: &ghc-843-32-deb8
|
unknown_versioning: &ghc-843-32-deb8
|
||||||
@ -532,6 +569,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/8.4.4/ghc-8.4.4-x86_64-portbld-freebsd11.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/8.4.4/ghc-8.4.4-x86_64-portbld-freebsd11.tar.xz
|
||||||
dlSubdir: ghc-8.4.4
|
dlSubdir: ghc-8.4.4
|
||||||
dlHash: 44fbd142d1c355d6110595c59c760e2c73866ff9259ec85ebf814edb244d1940
|
dlHash: 44fbd142d1c355d6110595c59c760e2c73866ff9259ec85ebf814edb244d1940
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.4.4/ghc-8.4.4-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.4.4
|
||||||
|
dlHash: da29dbb0f1199611c7d5bb7b0dd6a7426ca98f67dfd6da1526b033cd3830dc05
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
unknown_versioning: &ghc-844-32-deb8
|
unknown_versioning: &ghc-844-32-deb8
|
||||||
@ -592,6 +634,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/8.6.1/ghc-8.6.1-x86_64-portbld-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/8.6.1/ghc-8.6.1-x86_64-portbld-freebsd.tar.xz
|
||||||
dlSubdir: ghc-8.6.1
|
dlSubdir: ghc-8.6.1
|
||||||
dlHash: 51403b054a3a649039ac988e1d1112561f96750bfced63df864091a3fab36f08
|
dlHash: 51403b054a3a649039ac988e1d1112561f96750bfced63df864091a3fab36f08
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.6.1/ghc-8.6.1-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.6.1
|
||||||
|
dlHash: 7316d9cb5e486460476754f872c7bac30ee2082e42f46da4342f872d10b88099
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
unknown_versioning: &ghc-861-32-deb8
|
unknown_versioning: &ghc-861-32-deb8
|
||||||
@ -638,6 +685,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/8.6.2/ghc-8.6.2-x86_64-apple-darwin.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/8.6.2/ghc-8.6.2-x86_64-apple-darwin.tar.xz
|
||||||
dlSubdir: ghc-8.6.2
|
dlSubdir: ghc-8.6.2
|
||||||
dlHash: 8ec46a25872226dd7e5cf7271e3f3450c05f32144b96e6b9cb44cc4079db50dc
|
dlHash: 8ec46a25872226dd7e5cf7271e3f3450c05f32144b96e6b9cb44cc4079db50dc
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.6.2/ghc-8.6.2-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.6.2
|
||||||
|
dlHash: 9a398e133cab09ff2610834337355d4e26c35e0665403fb9ff8db79315f74d3d
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
unknown_versioning: &ghc-862-32-deb8
|
unknown_versioning: &ghc-862-32-deb8
|
||||||
@ -702,6 +754,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/8.6.3/ghc-8.6.3-x86_64-portbld-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/8.6.3/ghc-8.6.3-x86_64-portbld-freebsd.tar.xz
|
||||||
dlSubdir: ghc-8.6.3
|
dlSubdir: ghc-8.6.3
|
||||||
dlHash: bc2419fa180f8a7808c49775987866435995df9bdd9ce08bcd38352d63ba6031
|
dlHash: bc2419fa180f8a7808c49775987866435995df9bdd9ce08bcd38352d63ba6031
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.6.3/ghc-8.6.3-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.6.3
|
||||||
|
dlHash: 2fec383904e5fa79413e9afd328faf9bc700006c8c3d4bcdd8d4f2ccf0f7fa2a
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
unknown_versioning: &ghc-863-32-deb8
|
unknown_versioning: &ghc-863-32-deb8
|
||||||
@ -752,6 +809,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/8.6.4/ghc-8.6.4-x86_64-apple-darwin.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/8.6.4/ghc-8.6.4-x86_64-apple-darwin.tar.xz
|
||||||
dlSubdir: ghc-8.6.4
|
dlSubdir: ghc-8.6.4
|
||||||
dlHash: cccb58f142fe41b601d73690809f6089f7715b6a50a09aa3d0104176ab4db09e
|
dlHash: cccb58f142fe41b601d73690809f6089f7715b6a50a09aa3d0104176ab4db09e
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.6.4/ghc-8.6.4-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.6.4
|
||||||
|
dlHash: e8d021b7a90772fc559862079da20538498d991956d7557b468ca19ddda22a08
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
unknown_versioning: &ghc-864-32-deb9
|
unknown_versioning: &ghc-864-32-deb9
|
||||||
@ -820,6 +882,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/ghcup/unofficial-bindists/ghc/8.6.5/ghc-8.6.5-x86_64-portbld-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/ghcup/unofficial-bindists/ghc/8.6.5/ghc-8.6.5-x86_64-portbld-freebsd.tar.xz
|
||||||
dlSubdir: ghc-8.6.5
|
dlSubdir: ghc-8.6.5
|
||||||
dlHash: 83a3059a630d40a98e26cb5b520354e12094a96e36ba2f5ab002dad94cf2fb37
|
dlHash: 83a3059a630d40a98e26cb5b520354e12094a96e36ba2f5ab002dad94cf2fb37
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.6.5/ghc-8.6.5-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.6.5
|
||||||
|
dlHash: 457024c6ea43bdce340af428d86319931f267089398b859b00efdfe2fd4ce93f
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
unknown_versioning: &ghc-865-32-deb9
|
unknown_versioning: &ghc-865-32-deb9
|
||||||
@ -890,6 +957,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/8.8.1/ghc-8.8.1-x86_64-apple-darwin.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/8.8.1/ghc-8.8.1-x86_64-apple-darwin.tar.xz
|
||||||
dlSubdir: ghc-8.8.1
|
dlSubdir: ghc-8.8.1
|
||||||
dlHash: 38c8917b47c31bedf58c9305dfca3abe198d8d35570366f0773c4e2948bd8abe
|
dlHash: 38c8917b47c31bedf58c9305dfca3abe198d8d35570366f0773c4e2948bd8abe
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.8.1/ghc-8.8.1-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.8.1
|
||||||
|
dlHash: 29e56e6af38017a5a76b2b6995a39d3988fa58131e4b55b62dd317ba7186ac9b
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
unknown_versioning: &ghc-881-32-deb9
|
unknown_versioning: &ghc-881-32-deb9
|
||||||
@ -949,6 +1021,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/8.8.2/ghc-8.8.2-x86_64-apple-darwin.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/8.8.2/ghc-8.8.2-x86_64-apple-darwin.tar.xz
|
||||||
dlSubdir: ghc-8.8.2
|
dlSubdir: ghc-8.8.2
|
||||||
dlHash: 25c5c1a70036abf3f22b2b19c10d26adfdb08e8f8574f89d4b2042de5947f990
|
dlHash: 25c5c1a70036abf3f22b2b19c10d26adfdb08e8f8574f89d4b2042de5947f990
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.8.2/ghc-8.8.2-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.8.2
|
||||||
|
dlHash: e25d9b16ee62cafc7387af2cd021eea676a99cd2c32b83533b016162c63065d9
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
unknown_versioning: &ghc-882-32-deb9
|
unknown_versioning: &ghc-882-32-deb9
|
||||||
@ -1013,6 +1090,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/ghcup/unofficial-bindists/ghc/8.8.3/ghc-8.8.3-x86_64-portbld-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/ghcup/unofficial-bindists/ghc/8.8.3/ghc-8.8.3-x86_64-portbld-freebsd.tar.xz
|
||||||
dlSubdir: ghc-8.8.3
|
dlSubdir: ghc-8.8.3
|
||||||
dlHash: 569719075b4d14b3875a899df522090ae31e6fe085e6dffe518e875b09a2f0be
|
dlHash: 569719075b4d14b3875a899df522090ae31e6fe085e6dffe518e875b09a2f0be
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.8.3/ghc-8.8.3-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.8.3
|
||||||
|
dlHash: e22586762af0911c06e8140f1792e3ca381a3a482a20d67b9054883038b3a422
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
unknown_versioning: &ghc-883-32-deb9
|
unknown_versioning: &ghc-883-32-deb9
|
||||||
@ -1087,6 +1169,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/ghcup/unofficial-bindists/ghc/8.8.4/ghc-8.8.4-x86_64-portbld-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/ghcup/unofficial-bindists/ghc/8.8.4/ghc-8.8.4-x86_64-portbld-freebsd.tar.xz
|
||||||
dlSubdir: ghc-8.8.4
|
dlSubdir: ghc-8.8.4
|
||||||
dlHash: 8cebe5ccf454e82acd1ff52ca57590d1ab0f3f44a981b46257ec12158c8c447e
|
dlHash: 8cebe5ccf454e82acd1ff52ca57590d1ab0f3f44a981b46257ec12158c8c447e
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.8.4
|
||||||
|
dlHash: d185055d2c8dc3bfe5b88afd59d6877eb1e722b672d1c9649f18296e148ed71f
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
unknown_versioning: &ghc-884-32-deb9
|
unknown_versioning: &ghc-884-32-deb9
|
||||||
@ -1164,6 +1251,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/ghcup/unofficial-bindists/ghc/8.10.1/ghc-8.10.1-x86_64-portbld-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/ghcup/unofficial-bindists/ghc/8.10.1/ghc-8.10.1-x86_64-portbld-freebsd.tar.xz
|
||||||
dlSubdir: ghc-8.10.1
|
dlSubdir: ghc-8.10.1
|
||||||
dlHash: e8646ec9b60fd40aa9505ee055f22f04601290ab7a1342c2cf37c34de9d3f142
|
dlHash: e8646ec9b60fd40aa9505ee055f22f04601290ab7a1342c2cf37c34de9d3f142
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.10.1/ghc-8.10.1-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.1
|
||||||
|
dlHash: 38a3166ea50cccd5bae7e1680eae3aae2b4ae31b61f82a1d8168fb821f43bd67
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
'( >= 9 && < 10 )': &ghc-8101-32-deb9
|
'( >= 9 && < 10 )': &ghc-8101-32-deb9
|
||||||
@ -1254,6 +1346,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/8.10.2/ghc-8.10.2-x86_64-unknown-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/8.10.2/ghc-8.10.2-x86_64-unknown-freebsd.tar.xz
|
||||||
dlSubdir: ghc-8.10.2
|
dlSubdir: ghc-8.10.2
|
||||||
dlHash: 9e5957f3497f4b58ecd3699568d9caaa11a47a6d7e902032c261e450fa0f6686
|
dlHash: 9e5957f3497f4b58ecd3699568d9caaa11a47a6d7e902032c261e450fa0f6686
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.10.2/ghc-8.10.2-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.2
|
||||||
|
dlHash: dcae4c173b9896e07ff048de5509aa0a4537233150e06e5ce8848303dfadc176
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
'( >= 9 && < 10 )': &ghc-8102-32-deb9
|
'( >= 9 && < 10 )': &ghc-8102-32-deb9
|
||||||
@ -1343,6 +1440,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/8.10.3/ghc-8.10.3-x86_64-portbld-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/8.10.3/ghc-8.10.3-x86_64-portbld-freebsd.tar.xz
|
||||||
dlSubdir: ghc-8.10.3
|
dlSubdir: ghc-8.10.3
|
||||||
dlHash: 749007e995104db05cf6e3ad5bc36238cab8afac8055145661e5730e8f8af040
|
dlHash: 749007e995104db05cf6e3ad5bc36238cab8afac8055145661e5730e8f8af040
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.10.3/ghc-8.10.3-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.3
|
||||||
|
dlHash: 927a6c699533a115cd49772ef2c753d9af2c13bf9f0b2d3bd13645cc6a144ee3
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
'( >= 9 && < 10 )': &ghc-8103-32-deb9
|
'( >= 9 && < 10 )': &ghc-8103-32-deb9
|
||||||
@ -1434,6 +1536,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/8.10.4/ghc-8.10.4-x86_64-portbld-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/8.10.4/ghc-8.10.4-x86_64-portbld-freebsd.tar.xz
|
||||||
dlSubdir: ghc-8.10.4
|
dlSubdir: ghc-8.10.4
|
||||||
dlHash: c9776a2ccf9629b03e967206a507fcdcb6c5189800a626e9461ababf6733c357
|
dlHash: c9776a2ccf9629b03e967206a507fcdcb6c5189800a626e9461ababf6733c357
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/8.10.4/ghc-8.10.4-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-8.10.4
|
||||||
|
dlHash: e9175a276504c3390a5e0084954e6997d56078737dbe7158049518892cf6bfb2
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
'( >= 9 && < 10 )': &ghc-8104-32-deb9
|
'( >= 9 && < 10 )': &ghc-8104-32-deb9
|
||||||
@ -1524,6 +1631,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/9.0.1/ghc-9.0.1-x86_64-portbld-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/9.0.1/ghc-9.0.1-x86_64-portbld-freebsd.tar.xz
|
||||||
dlSubdir: ghc-9.0.1
|
dlSubdir: ghc-9.0.1
|
||||||
dlHash: 9dbc06d8832cae5c9f86dd7b2db729b3748a47beb4fd4b1e62bb66119817c3c1
|
dlHash: 9dbc06d8832cae5c9f86dd7b2db729b3748a47beb4fd4b1e62bb66119817c3c1
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/9.0.1/ghc-9.0.1-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-9.0.1-x86_64-unknown-mingw32
|
||||||
|
dlHash: 4f4ab118df01cbc7e7c510096deca0cb25025339a97730de0466416296202493
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
'( >= 9 && < 10 )': &ghc-901-32-deb9
|
'( >= 9 && < 10 )': &ghc-901-32-deb9
|
||||||
@ -1614,6 +1726,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~ghc/9.2.1-alpha2/ghc-9.2.0.20210422-x86_64-apple-darwin.tar.xz
|
dlUri: https://downloads.haskell.org/~ghc/9.2.1-alpha2/ghc-9.2.0.20210422-x86_64-apple-darwin.tar.xz
|
||||||
dlSubdir: ghc-9.2.0.20210422
|
dlSubdir: ghc-9.2.0.20210422
|
||||||
dlHash: 8884c059f2b76e4c4309ff6bd7a7dde37663f751fd26220e9a2bcabb4d69a401
|
dlHash: 8884c059f2b76e4c4309ff6bd7a7dde37663f751fd26220e9a2bcabb4d69a401
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~ghc/9.2.1-alpha2/ghc-9.2.0.20210422-x86_64-unknown-mingw32.tar.xz
|
||||||
|
dlSubdir: ghc-9.0.1-x86_64-unknown-mingw32
|
||||||
|
dlHash: 33f173b754d18f26bb27f52bb77a92fd22a48675daa2b43a1879bf01dddd7e8f
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Debian:
|
Linux_Debian:
|
||||||
'( >= 9 && < 10 )': &ghc-921-alpha2-32-deb9
|
'( >= 9 && < 10 )': &ghc-921-alpha2-32-deb9
|
||||||
@ -1666,6 +1783,11 @@ ghcupDownloads:
|
|||||||
dlUri: https://downloads.haskell.org/~cabal/cabal-install-2.4.1.0/cabal-install-2.4.1.0-x86_64-portbld-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/~cabal/cabal-install-2.4.1.0/cabal-install-2.4.1.0-x86_64-portbld-freebsd.tar.xz
|
||||||
dlSubdir:
|
dlSubdir:
|
||||||
dlHash: 33b7d37ea0688c93436eac9ec139d9967687875aa1fa13f2bb73bf05a9a59a1d
|
dlHash: 33b7d37ea0688c93436eac9ec139d9967687875aa1fa13f2bb73bf05a9a59a1d
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~cabal/cabal-install-2.4.1.0/cabal-install-2.4.1.0-x86_64-unknown-mingw32.zip
|
||||||
|
dlSubdir:
|
||||||
|
dlHash: 95f233efedb1ebf0e6db015fa2f55c1ed00b9938d207ec63c066f706fb4b6373
|
||||||
A_32:
|
A_32:
|
||||||
Linux_UnknownLinux:
|
Linux_UnknownLinux:
|
||||||
unknown_versioning:
|
unknown_versioning:
|
||||||
@ -1694,6 +1816,11 @@ ghcupDownloads:
|
|||||||
unknown_versioning:
|
unknown_versioning:
|
||||||
dlUri: https://downloads.haskell.org/~cabal/cabal-install-3.0.0.0/cabal-install-3.0.0.0-x86_64-portbld-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/~cabal/cabal-install-3.0.0.0/cabal-install-3.0.0.0-x86_64-portbld-freebsd.tar.xz
|
||||||
dlHash: 2240842ab2ae7b955feb8b526aba1c7991248c803383107adf39990441294d2a
|
dlHash: 2240842ab2ae7b955feb8b526aba1c7991248c803383107adf39990441294d2a
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~cabal/cabal-install-3.0.0.0/cabal-install-3.0.0.0-x86_64-unknown-mingw32.zip
|
||||||
|
dlSubdir:
|
||||||
|
dlHash: 8889963ebef5e829d86329fdb59832c107efd117cf7862a605f2fe2d2360de1f
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Alpine:
|
Linux_Alpine:
|
||||||
unknown_versioning:
|
unknown_versioning:
|
||||||
@ -1725,6 +1852,11 @@ ghcupDownloads:
|
|||||||
unknown_versioning:
|
unknown_versioning:
|
||||||
dlUri: https://downloads.haskell.org/~cabal/cabal-install-3.2.0.0/cabal-install-3.2.0.0-x86_64-portbld-freebsd.tar.xz
|
dlUri: https://downloads.haskell.org/~cabal/cabal-install-3.2.0.0/cabal-install-3.2.0.0-x86_64-portbld-freebsd.tar.xz
|
||||||
dlHash: f1e35151cca91541b0fb4bdb3ed18f3c348038eab751845ad19c11307d66c273
|
dlHash: f1e35151cca91541b0fb4bdb3ed18f3c348038eab751845ad19c11307d66c273
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~cabal/cabal-install-3.2.0.0/cabal-install-3.2.0.0-x86_64-unknown-mingw32.zip
|
||||||
|
dlSubdir:
|
||||||
|
dlHash: 17778c3ade0482bc37f451eec326f8fce8fbe1f12b1d6aacb2e2b9e34786c054
|
||||||
A_32:
|
A_32:
|
||||||
Linux_Alpine:
|
Linux_Alpine:
|
||||||
unknown_versioning:
|
unknown_versioning:
|
||||||
@ -1759,6 +1891,11 @@ ghcupDownloads:
|
|||||||
unknown_versioning:
|
unknown_versioning:
|
||||||
dlUri: https://downloads.haskell.org/~cabal/cabal-install-3.4.0.0/cabal-install-3.4.0.0-x86_64-freebsd-12.1-release.tar.xz
|
dlUri: https://downloads.haskell.org/~cabal/cabal-install-3.4.0.0/cabal-install-3.4.0.0-x86_64-freebsd-12.1-release.tar.xz
|
||||||
dlHash: a1e2db664ec00e42a1e071a4181f6476f6e0bad321f1ddc0cf27831119f4c6d4
|
dlHash: a1e2db664ec00e42a1e071a4181f6476f6e0bad321f1ddc0cf27831119f4c6d4
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/~cabal/cabal-install-3.4.0.0/cabal-install-3.4.0.0-x86_64-windows.zip
|
||||||
|
dlSubdir:
|
||||||
|
dlHash: 860fff2d39a82d1dc0ca924a77164d0988af49c2c5f45e15d615144122beb647
|
||||||
A_32:
|
A_32:
|
||||||
Linux_UnknownLinux:
|
Linux_UnknownLinux:
|
||||||
unknown_versioning: &cabal-3400-32
|
unknown_versioning: &cabal-3400-32
|
||||||
@ -1797,6 +1934,10 @@ ghcupDownloads:
|
|||||||
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.14.1/x86_64-portbld-freebsd-ghcup-0.1.14.1
|
||||||
dlHash: 89a70980d77888dae8b9fd0f05e7a7920f421bc3bb5192da8e73fd4e7b4cb86f
|
dlHash: 89a70980d77888dae8b9fd0f05e7a7920f421bc3bb5192da8e73fd4e7b4cb86f
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/ghcup/tmp/ghcup.exe
|
||||||
|
dlHash: e6dc0b337b29164d5e4a299e572955591b1b6e5d4d11e895c8cbc05666d98ad5
|
||||||
Linux_Alpine:
|
Linux_Alpine:
|
||||||
unknown_versioning: *ghcup-64
|
unknown_versioning: *ghcup-64
|
||||||
A_32:
|
A_32:
|
||||||
@ -1833,6 +1974,10 @@ ghcupDownloads:
|
|||||||
unknown_versioning:
|
unknown_versioning:
|
||||||
dlUri: https://github.com/haskell/haskell-language-server/releases/download/1.1.0/haskell-language-server-macOS-1.1.0.tar.gz
|
dlUri: https://github.com/haskell/haskell-language-server/releases/download/1.1.0/haskell-language-server-macOS-1.1.0.tar.gz
|
||||||
dlHash: 4e89b192e2f49637d772e974f2c17b16da067ecd5912575eaa542551de97681b
|
dlHash: 4e89b192e2f49637d772e974f2c17b16da067ecd5912575eaa542551de97681b
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://downloads.haskell.org/ghcup/unofficial-bindists/hls/1.1.0/haskell-language-server-Windows-1.1.0.tar.gz
|
||||||
|
dlHash: a1d3f451e64a041aa527a25da29e4716a2de6ae347cef4ef9312fc7611e168cc
|
||||||
Linux_Alpine:
|
Linux_Alpine:
|
||||||
unknown_versioning: *hls-64
|
unknown_versioning: *hls-64
|
||||||
Stack:
|
Stack:
|
||||||
@ -1854,6 +1999,12 @@ ghcupDownloads:
|
|||||||
dlHash: f4aedfa8fbe371f77286ee97ec5c3c553842e7ae15b2952a8b8442dccba04bf0
|
dlHash: f4aedfa8fbe371f77286ee97ec5c3c553842e7ae15b2952a8b8442dccba04bf0
|
||||||
dlSubdir:
|
dlSubdir:
|
||||||
RegexDir: "stack-.*"
|
RegexDir: "stack-.*"
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://github.com/commercialhaskell/stack/releases/download/v2.5.1/stack-2.5.1-windows-x86_64.tar.gz
|
||||||
|
dlHash: 57150b422cfd42249f5e629d0eb678df6d95dabe486ced57e8298d300b940d41
|
||||||
|
dlSubdir:
|
||||||
|
RegexDir: "stack-.*"
|
||||||
Linux_Alpine:
|
Linux_Alpine:
|
||||||
unknown_versioning: *stack-251-64
|
unknown_versioning: *stack-251-64
|
||||||
2.7.1:
|
2.7.1:
|
||||||
@ -1876,6 +2027,12 @@ ghcupDownloads:
|
|||||||
dlHash: 4248c6fbc87e8a2c06f39e867eb5ef28eae0d99470137cb415356c631c0dcbf2
|
dlHash: 4248c6fbc87e8a2c06f39e867eb5ef28eae0d99470137cb415356c631c0dcbf2
|
||||||
dlSubdir:
|
dlSubdir:
|
||||||
RegexDir: "stack-.*"
|
RegexDir: "stack-.*"
|
||||||
|
Windows:
|
||||||
|
unknown_versioning:
|
||||||
|
dlUri: https://github.com/commercialhaskell/stack/releases/download/v2.7.1/stack-2.7.1-windows-x86_64.tar.gz
|
||||||
|
dlHash: 8452f5fc9235620a84863f2f68e5f681c72d0d181cde50482f178a966ee0ceb9
|
||||||
|
dlSubdir:
|
||||||
|
RegexDir: "stack-.*"
|
||||||
Linux_Alpine:
|
Linux_Alpine:
|
||||||
unknown_versioning: *stack-64
|
unknown_versioning: *stack-64
|
||||||
|
|
||||||
|
2042
ghcup-0.0.5.yaml
Normal file
2042
ghcup-0.0.5.yaml
Normal file
File diff suppressed because it is too large
Load Diff
113
ghcup.cabal
113
ghcup.cabal
@ -1,6 +1,6 @@
|
|||||||
cabal-version: 3.0
|
cabal-version: 3.0
|
||||||
name: ghcup
|
name: ghcup
|
||||||
version: 0.1.14.2
|
version: 0.1.15
|
||||||
license: LGPL-3.0-only
|
license: LGPL-3.0-only
|
||||||
license-file: LICENSE
|
license-file: LICENSE
|
||||||
copyright: Julian Ospald 2020
|
copyright: Julian Ospald 2020
|
||||||
@ -28,19 +28,23 @@ 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 +62,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 +75,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
|
||||||
@ -90,21 +101,19 @@ library
|
|||||||
, 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
|
|
||||||
, 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
|
, 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
|
||||||
@ -120,44 +129,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
|
||||||
, 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.0
|
||||||
, 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) || os(windows))
|
||||||
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
|
||||||
@ -165,6 +192,7 @@ executable ghcup
|
|||||||
default-extensions:
|
default-extensions:
|
||||||
LambdaCase
|
LambdaCase
|
||||||
MultiWayIf
|
MultiWayIf
|
||||||
|
NamedFieldPuns
|
||||||
PackageImports
|
PackageImports
|
||||||
RecordWildCards
|
RecordWildCards
|
||||||
ScopedTypeVariables
|
ScopedTypeVariables
|
||||||
@ -177,14 +205,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
|
||||||
@ -195,7 +221,7 @@ 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
|
||||||
@ -204,15 +230,19 @@ executable ghcup
|
|||||||
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 flag(tar)
|
if os(windows)
|
||||||
|
cpp-options: -DIS_WINDOWS
|
||||||
|
|
||||||
|
if (flag(tar) || os(windows))
|
||||||
cpp-options: -DTAR
|
cpp-options: -DTAR
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -224,27 +254,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
|
||||||
@ -258,13 +293,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
|
, versions ^>=4.0.1
|
||||||
, yaml ^>=0.11.4.0
|
, yaml ^>=0.11.4.0
|
||||||
|
|
||||||
if flag(tar)
|
if (flag(tar) || os(windows))
|
||||||
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
|
||||||
@ -297,9 +331,8 @@ 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
|
||||||
|
27450
golden/GHCupInfo.json
27450
golden/GHCupInfo.json
File diff suppressed because it is too large
Load Diff
677
lib/GHCup.hs
677
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,31 +204,28 @@ 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
|
liftIO $ createDirRecursive' cacheDir
|
||||||
getModTime >>= \case
|
getModTime >>= \case
|
||||||
@ -242,14 +238,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 +274,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 +323,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 +343,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 +353,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 +396,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 +442,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 +456,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 +476,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 +500,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,20 @@ 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.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 +57,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 +82,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
|
||||||
@ -96,35 +98,35 @@ getPlatform = do
|
|||||||
. versioning
|
. versioning
|
||||||
-- TODO: maybe do this somewhere else
|
-- TODO: maybe do this somewhere else
|
||||||
. getMajorVersion
|
. 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: #{pfr}|]
|
||||||
pure pfr
|
pure pfr
|
||||||
where
|
where
|
||||||
getMajorVersion = T.intercalate "." . take 2 . T.split (== '.')
|
getMajorVersion = T.intercalate "." . take 2 . T.split (== '.')
|
||||||
getFreeBSDVersion =
|
getFreeBSDVersion = lift $ fmap _stdOut $ executeOut "freebsd-version" [] Nothing
|
||||||
liftIO $ fmap _stdOut $ executeOut [rel|freebsd-version|] [] Nothing
|
getDarwinVersion = lift $ fmap _stdOut $ executeOut "sw_vers"
|
||||||
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 +149,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 +162,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 +194,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)
|
||||||
|
|
||||||
@ -88,6 +105,9 @@ data Tool = GHC
|
|||||||
| Stack
|
| Stack
|
||||||
deriving (Eq, GHC.Generic, Ord, Show, Enum, Bounded)
|
deriving (Eq, GHC.Generic, Ord, Show, Enum, Bounded)
|
||||||
|
|
||||||
|
data GlobalTool = ShimGen
|
||||||
|
deriving (Eq, GHC.Generic, Ord, Show, Enum, Bounded)
|
||||||
|
|
||||||
|
|
||||||
-- | All necessary information of a tool version, including
|
-- | All necessary information of a tool version, including
|
||||||
-- source download and per-architecture downloads.
|
-- source download and per-architecture downloads.
|
||||||
@ -157,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
|
||||||
@ -218,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
|
||||||
|
|
||||||
|
|
||||||
@ -250,48 +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 Vty.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
|
||||||
, bShowAllVersions :: Vty.Key
|
, bShowAllVersions :: Key
|
||||||
, bShowAllTools :: Vty.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'
|
||||||
, bShowAllVersions = Vty.KChar 'a'
|
, bShowAllVersions = KChar 'a'
|
||||||
, bShowAllTools = Vty.KChar 't'
|
, 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
|
||||||
@ -305,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
|
||||||
|
|
||||||
@ -326,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
|
||||||
}
|
}
|
||||||
@ -422,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
|
||||||
@ -34,7 +36,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 +43,24 @@ 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
|
#if !defined(IS_WINDOWS)
|
||||||
import HPath.IO
|
|
||||||
import Optics
|
import Optics
|
||||||
import Prelude hiding ( abs
|
import System.Directory
|
||||||
, readFile
|
#endif
|
||||||
, writeFile
|
|
||||||
)
|
|
||||||
import System.DiskSpace
|
import System.DiskSpace
|
||||||
import System.Posix.Env.ByteString ( getEnv
|
#if !defined(IS_WINDOWS)
|
||||||
, getEnvDefault
|
import System.Environment
|
||||||
)
|
#endif
|
||||||
import System.Posix.FilePath hiding ( (</>) )
|
import System.FilePath
|
||||||
import System.Posix.Temp.ByteString ( mkdtemp )
|
import System.IO.Temp
|
||||||
|
|
||||||
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 +75,116 @@ 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)
|
||||||
|
pure ("C:\\" </> "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)
|
||||||
|
pure ("C:\\" </> "ghcup")
|
||||||
|
#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)
|
||||||
|
pure ("C:\\" </> "ghcup" </> "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)
|
||||||
|
pure ("C:\\" </> "ghcup" </> "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)
|
||||||
|
pure ("C:\\" </> "ghcup" </> "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
|
||||||
@ -194,11 +207,11 @@ ghcupConfigFile :: (MonadIO m)
|
|||||||
=> Excepts '[JSONError] m UserSettings
|
=> Excepts '[JSONError] m UserSettings
|
||||||
ghcupConfigFile = do
|
ghcupConfigFile = do
|
||||||
confDir <- liftIO ghcupConfigDir
|
confDir <- liftIO ghcupConfigDir
|
||||||
let file = confDir </> [rel|config.yaml|]
|
let file = confDir </> "config.yaml"
|
||||||
bs <- liftIO $ handleIO' NoSuchThing (\_ -> pure Nothing) $ Just <$> readFile file
|
contents <- liftIO $ handleIO' NoSuchThing (\_ -> pure Nothing) $ Just <$> BS.readFile file
|
||||||
case bs of
|
case contents 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 +220,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 +232,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 +266,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 +277,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
|
240
lib/GHCup/Utils/File/Windows.hs
Normal file
240
lib/GHCup/Utils/File/Windows.hs
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
{-# 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
|
||||||
|
baseDir <- liftIO ghcupBaseDir
|
||||||
|
cEnv <- Map.fromList <$> maybe (liftIO getEnvironment) pure (env cp)
|
||||||
|
let mingWPaths = [baseDir </> "msys64" </> "usr" </> "bin"
|
||||||
|
,baseDir </> "msys64" </> "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 }
|
||||||
|
|
||||||
|
|
||||||
|
-- | 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,27 @@ 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.Directory hiding ( findFiles )
|
||||||
|
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 +66,18 @@ 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
|
createDirectoryIfMissing True 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
|
||||||
@ -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,139 @@ 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
|
||||||
|
26
stack.yaml
26
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,16 +20,18 @@ 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
|
||||||
|
- 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
|
||||||
- lzma-static-5.2.5.2@sha256:ac38dcad9ab423342a72ba48415bd75f62234e9c9e11831495b75603b5a060f6,7184
|
- lzma-static-5.2.5.2@sha256:ac38dcad9ab423342a72ba48415bd75f62234e9c9e11831495b75603b5a060f6,7184
|
||||||
- libarchive-3.0.2.1@sha256:40ebf2a278e585802427bc58826867208bb33822f63d56107a1fcc3ca04d691d,10990
|
- libarchive-3.0.2.1@sha256:40ebf2a278e585802427bc58826867208bb33822f63d56107a1fcc3ca04d691d,10990
|
||||||
- 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
|
||||||
@ -40,13 +45,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
|
||||||
|
Loading…
Reference in New Issue
Block a user