ghcup-hs/.gitlab/script/ghcup_version.sh

309 lines
9.8 KiB
Bash
Raw Normal View History

2022-05-13 08:32:44 +00:00
#!/usr/bin/env bash
2020-04-15 07:45:18 +00:00
set -eux
. "$( cd "$(dirname "$0")" ; pwd -P )/../ghcup_env"
mkdir -p "$CI_PROJECT_DIR"/.local/bin
2021-05-14 21:09:45 +00:00
CI_PROJECT_DIR=$(pwd)
2022-05-13 08:32:44 +00:00
2020-04-15 07:45:18 +00:00
ecabal() {
2021-05-14 21:09:45 +00:00
cabal "$@"
2020-04-15 07:45:18 +00:00
}
2021-07-24 14:36:31 +00:00
raw_eghcup() {
ghcup -v -c "$@"
}
2020-04-15 13:07:37 +00:00
eghcup() {
2021-05-14 21:09:45 +00:00
if [ "${OS}" = "WINDOWS" ] ; then
2021-09-04 13:27:57 +00:00
ghcup -v -c -s file:/$CI_PROJECT_DIR/data/metadata/ghcup-${JSON_VERSION}.yaml "$@"
2021-05-14 21:09:45 +00:00
else
2021-09-04 13:27:57 +00:00
ghcup -v -c -s file://$CI_PROJECT_DIR/data/metadata/ghcup-${JSON_VERSION}.yaml "$@"
2021-05-14 21:09:45 +00:00
fi
2020-04-15 13:07:37 +00:00
}
2020-04-15 07:45:18 +00:00
2021-07-24 14:36:31 +00:00
if [ "${OS}" = "WINDOWS" ] ; then
GHCUP_DIR="${GHCUP_INSTALL_BASE_PREFIX}"/ghcup
else
GHCUP_DIR="${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup
fi
2020-04-29 21:01:51 +00:00
git describe --always
### build
2022-05-14 15:58:11 +00:00
rm -rf "${GHCUP_DIR}"/share
2020-04-15 07:45:18 +00:00
ecabal update
if [ "${OS}" = "DARWIN" ] ; then
2020-07-06 20:39:16 +00:00
ecabal build -w ghc-${GHC_VERSION} -ftui
2020-09-13 19:13:42 +00:00
ecabal test -w ghc-${GHC_VERSION} -ftui ghcup-test
ecabal haddock -w ghc-${GHC_VERSION} -ftui
2020-08-11 10:12:15 +00:00
elif [ "${OS}" = "LINUX" ] ; then
2021-02-24 14:19:29 +00:00
if [ "${ARCH}" = "32" ] ; then
2021-08-24 18:18:14 +00:00
ecabal build -w ghc-${GHC_VERSION} -finternal-downloader -ftui
ecabal test -w ghc-${GHC_VERSION} -finternal-downloader -ftui ghcup-test
ecabal haddock -w ghc-${GHC_VERSION} -finternal-downloader -ftui
2020-08-11 10:12:15 +00:00
else
ecabal build -w ghc-${GHC_VERSION} -finternal-downloader -ftui
2020-09-13 19:13:42 +00:00
ecabal test -w ghc-${GHC_VERSION} -finternal-downloader -ftui ghcup-test
ecabal haddock -w ghc-${GHC_VERSION} -finternal-downloader -ftui
2021-08-24 08:54:25 +00:00
2021-08-24 18:18:14 +00:00
if [ "${ARCH}" = "64" ] ; then
# doctest
curl -sL https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal-docspec/cabal-docspec-0.0.0.20210228_p1.tar.bz2 > cabal-docspec.tar.bz2
echo '3a10f6fec16dbd18efdd331b1cef5d2d342082da42f5b520726d1fa6a3990d12 cabal-docspec.tar.bz2' | sha256sum -c -
tar -xjf cabal-docspec.tar.bz2 cabal-docspec
mv cabal-docspec "$CI_PROJECT_DIR"/.local/bin/cabal-docspec
rm -f cabal-docspec.tar.bz2
chmod a+x "$CI_PROJECT_DIR"/.local/bin/cabal-docspec
cabal-docspec -XCPP -XTypeSynonymInstances -XOverloadedStrings -XPackageImports --check-properties
fi
2020-08-11 10:12:15 +00:00
fi
elif [ "${OS}" = "FREEBSD" ] ; then
ecabal build -w ghc-${GHC_VERSION} -finternal-downloader -ftui --constraint="zip +disable-zstd"
ecabal test -w ghc-${GHC_VERSION} -finternal-downloader -ftui --constraint="zip +disable-zstd" ghcup-test
ecabal haddock -w ghc-${GHC_VERSION} -finternal-downloader -ftui --constraint="zip +disable-zstd"
2021-05-14 21:09:45 +00:00
elif [ "${OS}" = "WINDOWS" ] ; then
ecabal build -w ghc-${GHC_VERSION}
ecabal test -w ghc-${GHC_VERSION} ghcup-test
ecabal haddock -w ghc-${GHC_VERSION}
else
2020-07-06 20:39:16 +00:00
ecabal build -w ghc-${GHC_VERSION} -finternal-downloader -ftui
2020-09-13 19:13:42 +00:00
ecabal test -w ghc-${GHC_VERSION} -finternal-downloader -ftui ghcup-test
ecabal haddock -w ghc-${GHC_VERSION} -finternal-downloader -ftui
2020-04-15 07:45:18 +00:00
fi
2020-07-21 23:11:37 +00:00
2021-06-13 12:43:00 +00:00
if [ "${OS}" = "WINDOWS" ] ; then
ext=".exe"
else
ext=''
fi
cp "$(ecabal new-exec -w ghc-${GHC_VERSION} --verbose=0 --offline sh -- -c 'command -v ghcup')" "$CI_PROJECT_DIR"/.local/bin/ghcup${ext}
### cleanup
2021-07-24 14:36:31 +00:00
rm -rf "${GHCUP_DIR}"
2020-04-15 07:45:18 +00:00
### manual cli based testing
2020-04-18 15:29:44 +00:00
eghcup --numeric-version
2020-04-15 07:45:18 +00:00
2021-07-15 20:40:45 +00:00
eghcup install ghc ${GHC_VERSION}
2022-05-13 08:32:44 +00:00
ls -lah "$(eghcup whereis -d ghc ${GHC_VERSION})"
[ "`$(eghcup whereis ghc ${GHC_VERSION}) --numeric-version`" = "${GHC_VERSION}" ]
[ "`eghcup run --ghc ${GHC_VERSION} -- ghc --numeric-version`" = "${GHC_VERSION}" ]
2021-07-15 20:40:45 +00:00
eghcup set ghc ${GHC_VERSION}
eghcup install cabal ${CABAL_VERSION}
2022-05-13 08:32:44 +00:00
[ "`$(eghcup whereis cabal ${CABAL_VERSION}) --numeric-version`" = "${CABAL_VERSION}" ]
2021-09-19 11:50:51 +00:00
eghcup unset cabal
2022-05-11 22:17:46 +00:00
"$GHCUP_BIN"/cabal --version && exit 1 || echo yes
2021-09-19 11:50:51 +00:00
eghcup set cabal ${CABAL_VERSION}
2022-05-13 08:32:44 +00:00
[ "`$(eghcup whereis cabal ${CABAL_VERSION}) --numeric-version`" = "${CABAL_VERSION}" ]
[ "`eghcup run --cabal ${CABAL_VERSION} -- cabal --numeric-version`" = "${CABAL_VERSION}" ]
2022-02-10 17:31:38 +00:00
2022-02-11 18:24:39 +00:00
if [ "${OS}" != "FREEBSD" ] ; then
if [ "${ARCH}" = "64" ] ; then
eghcup run --ghc 8.10.7 --cabal 3.4.1.0 --hls 1.6.1.0 --stack 2.7.3 --install --bindir "$(pwd)/.bin"
if [ "${OS}" == "WINDOWS" ] ; then
expected=$(cat "$( cd "$(dirname "$0")" ; pwd -P )/../ghcup-run.files.windows" | sort)
else
expected=$(cat "$( cd "$(dirname "$0")" ; pwd -P )/../ghcup-run.files" | sort)
fi
actual=$(cd ".bin" && find . | sort)
[ "${actual}" = "${expected}" ]
unset actual expected
rm -rf .bin
2022-02-10 20:49:19 +00:00
fi
fi
2020-04-15 07:45:18 +00:00
cabal --version
2020-04-15 13:07:37 +00:00
eghcup debug-info
2020-04-15 07:45:18 +00:00
2021-07-24 14:36:31 +00:00
# also test etags
2020-04-15 13:07:37 +00:00
eghcup list
eghcup list -t ghc
eghcup list -t cabal
2020-04-15 07:45:18 +00:00
ghc_ver=$(ghc --numeric-version)
2020-04-15 07:45:18 +00:00
ghc --version
2021-06-09 17:45:23 +00:00
ghc-${ghc_ver} --version
if [ "${OS}" != "WINDOWS" ] ; then
ghci --version
ghci-${ghc_ver} --version
fi
2020-04-15 07:45:18 +00:00
2021-06-15 12:00:30 +00:00
if [ "${OS}" = "DARWIN" ] && [ "${ARCH}" = "ARM64" ] ; then
echo
else
# test installing new ghc doesn't mess with currently set GHC
# https://gitlab.haskell.org/haskell/ghcup-hs/issues/7
if [ "${OS}" = "LINUX" ] ; then
2021-07-19 14:49:18 +00:00
eghcup --downloader=wget prefetch ghc 8.10.3
eghcup --offline install ghc 8.10.3
if [ "${ARCH}" = "64" ] ; then
expected=$(cat "$( cd "$(dirname "$0")" ; pwd -P )/../ghc-8.10.3-linux.files" | sort)
2022-02-11 17:51:16 +00:00
actual=$(cd "${GHCUP_DIR}/ghc/8.10.3/" && find . | sort)
[ "${actual}" = "${expected}" ]
unset actual expected
fi
elif [ "${OS}" = "WINDOWS" ] ; then
eghcup prefetch ghc 8.10.3
eghcup --offline install ghc 8.10.3
expected=$(cat "$( cd "$(dirname "$0")" ; pwd -P )/../ghc-8.10.3-windows.files" | sort)
2022-02-11 17:51:16 +00:00
actual=$(cd "${GHCUP_DIR}/ghc/8.10.3/" && find . | sort)
[ "${actual}" = "${expected}" ]
unset actual expected
else
2021-07-19 14:49:18 +00:00
eghcup prefetch ghc 8.10.3
eghcup --offline install ghc 8.10.3
2021-06-15 12:00:30 +00:00
fi
[ "$(ghc --numeric-version)" = "${ghc_ver}" ]
2021-07-19 14:49:18 +00:00
eghcup --offline set 8.10.3
2021-06-15 12:00:30 +00:00
eghcup set 8.10.3
[ "$(ghc --numeric-version)" = "8.10.3" ]
eghcup set ${GHC_VERSION}
[ "$(ghc --numeric-version)" = "${ghc_ver}" ]
2021-09-19 11:50:51 +00:00
eghcup unset ghc
2022-05-11 22:17:46 +00:00
"$GHCUP_BIN"/ghc --numeric-version && exit 1 || echo yes
2021-09-19 11:50:51 +00:00
eghcup set ${GHC_VERSION}
2021-07-19 14:49:18 +00:00
eghcup --offline rm 8.10.3
2021-06-15 12:00:30 +00:00
[ "$(ghc --numeric-version)" = "${ghc_ver}" ]
2021-09-19 11:50:51 +00:00
2022-05-11 16:35:17 +00:00
ls -lah "$GHCUP_BIN"
2021-06-15 12:00:30 +00:00
if [ "${OS}" = "DARWIN" ] ; then
eghcup install hls
$(eghcup whereis hls) --version
2021-05-14 22:31:36 +00:00
eghcup install stack
$(eghcup whereis stack) --version
2021-06-15 12:00:30 +00:00
elif [ "${OS}" = "LINUX" ] ; then
if [ "${ARCH}" = "64" ] ; then
eghcup install hls
haskell-language-server-wrapper --version
2021-09-19 11:50:51 +00:00
eghcup unset hls
2022-05-11 22:17:46 +00:00
"$GHCUP_BIN"/haskell-language-server-wrapper --version && exit 1 || echo yes
2021-06-15 12:00:30 +00:00
eghcup install stack
stack --version
2022-05-11 22:17:46 +00:00
eghcup unset stack
"$GHCUP_BIN"/stack --version && exit 1 || echo yes
2021-06-15 12:00:30 +00:00
fi
fi
fi
2022-02-10 17:31:38 +00:00
2021-07-15 11:32:48 +00:00
# check that lazy loading works for 'whereis'
2021-09-04 13:27:57 +00:00
cp "$CI_PROJECT_DIR/data/metadata/ghcup-${JSON_VERSION}.yaml" "$CI_PROJECT_DIR/data/metadata/ghcup-${JSON_VERSION}.yaml.bak"
echo '**' > "$CI_PROJECT_DIR/data/metadata/ghcup-${JSON_VERSION}.yaml"
2021-07-15 11:32:48 +00:00
eghcup whereis ghc $(ghc --numeric-version)
2021-09-04 13:27:57 +00:00
mv -f "$CI_PROJECT_DIR/data/metadata/ghcup-${JSON_VERSION}.yaml.bak" "$CI_PROJECT_DIR/data/metadata/ghcup-${JSON_VERSION}.yaml"
2020-04-15 13:36:03 +00:00
eghcup rm $(ghc --numeric-version)
2021-03-07 10:59:45 +00:00
# https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/116
2021-05-14 21:09:45 +00:00
if [ "${OS}" = "LINUX" ] ; then
if [ "${ARCH}" = "64" ] ; then
2022-05-16 16:03:19 +00:00
eghcup install cabal -u https://downloads.haskell.org/~ghcup/unofficial-bindists/cabal/3.7.0.0-pre20220407/cabal-install-3.7-x86_64-linux-alpine.tar.xz 3.4.0.0-rc4
2021-05-14 21:09:45 +00:00
eghcup rm cabal 3.4.0.0-rc4
fi
fi
2021-03-07 10:59:45 +00:00
2022-05-12 11:17:40 +00:00
eghcup gc -c
2021-07-24 14:36:31 +00:00
sha_sum() {
if [ "${OS}" = "FREEBSD" ] ; then
sha256 "$@"
else
sha256sum "$@"
fi
}
# test etags
rm -f "${GHCUP_DIR}/cache/ghcup-${JSON_VERSION}.yaml"
raw_eghcup -s https://www.haskell.org/ghcup/data/ghcup-${JSON_VERSION}.yaml list
# snapshot yaml and etags file
etag=$(cat "${GHCUP_DIR}/cache/ghcup-${JSON_VERSION}.yaml.etags")
sha=$(sha_sum "${GHCUP_DIR}/cache/ghcup-${JSON_VERSION}.yaml")
# invalidate access time timer, which is 5minutes, so we re-download
touch -a -m -t '199901010101' "${GHCUP_DIR}/cache/ghcup-${JSON_VERSION}.yaml"
# redownload same file with some newlines added
raw_eghcup -s https://www.haskell.org/ghcup/exp/ghcup-${JSON_VERSION}.yaml list
# snapshot new yaml and etags file
etag2=$(cat "${GHCUP_DIR}/cache/ghcup-${JSON_VERSION}.yaml.etags")
sha2=$(sha_sum "${GHCUP_DIR}/cache/ghcup-${JSON_VERSION}.yaml")
# compare
[ "${etag}" != "${etag2}" ]
[ "${sha}" != "${sha2}" ]
# invalidate access time timer, which is 5minutes, but don't expect a re-download
touch -a -m -t '199901010101' "${GHCUP_DIR}/cache/ghcup-${JSON_VERSION}.yaml"
# this time, we expect the same hash and etag
raw_eghcup -s https://www.haskell.org/ghcup/exp/ghcup-${JSON_VERSION}.yaml list
etag3=$(cat "${GHCUP_DIR}/cache/ghcup-${JSON_VERSION}.yaml.etags")
sha3=$(sha_sum "${GHCUP_DIR}/cache/ghcup-${JSON_VERSION}.yaml")
[ "${etag2}" = "${etag3}" ]
[ "${sha2}" = "${sha3}" ]
2021-08-11 10:24:51 +00:00
# test isolated installs
eghcup install ghc -i "$(pwd)/isolated" 8.10.5
[ "$(isolated/bin/ghc --numeric-version)" = "8.10.5" ]
! eghcup install ghc -i "$(pwd)/isolated" 8.10.5
if [ "${ARCH}" = "64" ] ; then
if [ "${OS}" = "LINUX" ] || [ "${OS}" = "WINDOWS" ] ; then
eghcup install cabal -i "$(pwd)/isolated" 3.4.0.0
[ "$(isolated/cabal --numeric-version)" = "3.4.0.0" ]
eghcup install stack -i "$(pwd)/isolated" 2.7.3
[ "$(isolated/stack --numeric-version)" = "2.7.3" ]
eghcup install hls -i "$(pwd)/isolated" 1.3.0
[ "$(isolated/haskell-language-server-wrapper --numeric-version)" = "1.3.0" ] ||
[ "$(isolated/haskell-language-server-wrapper --numeric-version)" = "1.3.0.0" ]
# test that isolated installs don't clean up target directory
cat <<EOF > "${GHCUP_BIN}/gmake"
#!/bin/bash
exit 1
EOF
chmod +x "${GHCUP_BIN}/gmake"
mkdir isolated_tainted/
touch isolated_tainted/lol
! eghcup install ghc -i "$(pwd)/isolated_tainted" 8.10.5 --force
[ -e "$(pwd)/isolated_tainted/lol" ]
rm "${GHCUP_BIN}/gmake"
2021-08-11 10:24:51 +00:00
fi
fi
2021-07-15 11:32:48 +00:00
2020-04-15 13:07:37 +00:00
eghcup upgrade
eghcup upgrade -f
2020-04-15 07:45:18 +00:00
2022-05-19 22:46:50 +00:00
# test that doing fishy symlinks into GHCup dir doesn't cause weird stuff on 'ghcup nuke'
2022-05-16 15:14:40 +00:00
mkdir no_nuke/
mkdir no_nuke/bar
echo 'foo' > no_nuke/file
echo 'bar' > no_nuke/bar/file
ln -s "$CI_PROJECT_DIR"/no_nuke/ "${GHCUP_DIR}"/cache/no_nuke
ln -s "$CI_PROJECT_DIR"/no_nuke/ "${GHCUP_DIR}"/logs/no_nuke
2021-06-15 12:00:30 +00:00
# nuke
eghcup nuke
2021-07-24 14:36:31 +00:00
[ ! -e "${GHCUP_DIR}" ]
2022-05-16 15:14:40 +00:00
# make sure nuke doesn't resolve symlinks
[ -e "$CI_PROJECT_DIR"/no_nuke/file ]
[ -e "$CI_PROJECT_DIR"/no_nuke/bar/file ]