Compare commits
11 Commits
v0.1.6
...
http-clien
| Author | SHA1 | Date | |
|---|---|---|---|
| 6260816ed1 | |||
| f46c8bdd6f | |||
| 4c4266dd8c | |||
| e8336bbc8a | |||
| 0f69c73e0e | |||
| e348de8dc4 | |||
| 55a3ba9be2 | |||
| 51b29b81b0 | |||
| 3c2e0334b7 | |||
| 0679626514 | |||
| 5035051135 |
@@ -19,7 +19,7 @@ if [ "${OS}" = "LINUX" ] ; then
|
|||||||
if [ "${BIT}" = "32" ] ; then
|
if [ "${BIT}" = "32" ] ; then
|
||||||
ecabal build -w ghc-${GHC_VERSION} --ghc-options='-split-sections -optl-static' -ftui -ftar
|
ecabal build -w ghc-${GHC_VERSION} --ghc-options='-split-sections -optl-static' -ftui -ftar
|
||||||
else
|
else
|
||||||
ecabal build -w ghc-${GHC_VERSION} --ghc-options='-split-sections -optl-static' -ftui
|
ecabal build -w ghc-${GHC_VERSION} --ghc-options='-split-sections -optl-static' -ftui -finternal-downloader
|
||||||
fi
|
fi
|
||||||
elif [ "${OS}" = "FREEBSD" ] ; then
|
elif [ "${OS}" = "FREEBSD" ] ; then
|
||||||
ecabal build -w ghc-${GHC_VERSION} --ghc-options='-split-sections' --constraint="zlib static" -ftui
|
ecabal build -w ghc-${GHC_VERSION} --ghc-options='-split-sections' --constraint="zlib static" -ftui
|
||||||
|
|||||||
@@ -205,13 +205,10 @@ install' AppState {..} (_, ListResult {..}) = do
|
|||||||
#if !defined(TAR)
|
#if !defined(TAR)
|
||||||
, ArchiveResult
|
, ArchiveResult
|
||||||
#endif
|
#endif
|
||||||
, DistroNotFound
|
|
||||||
, FileDoesNotExistError
|
, FileDoesNotExistError
|
||||||
, CopyError
|
, CopyError
|
||||||
, NoCompatibleArch
|
|
||||||
, NoDownload
|
, NoDownload
|
||||||
, NotInstalled
|
, NotInstalled
|
||||||
, NoCompatiblePlatform
|
|
||||||
, BuildFailed
|
, BuildFailed
|
||||||
, TagNotFound
|
, TagNotFound
|
||||||
, DigestError
|
, DigestError
|
||||||
|
|||||||
@@ -29,15 +29,16 @@ download_ghcup() {
|
|||||||
_plat="$(uname -s)"
|
_plat="$(uname -s)"
|
||||||
_arch=$(uname -m)
|
_arch=$(uname -m)
|
||||||
_ghver="0.1.6"
|
_ghver="0.1.6"
|
||||||
|
_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)
|
||||||
_url=https://downloads.haskell.org/~ghcup/${_ghver}/x86_64-linux-ghcup-${_ghver}
|
_url=${_base_url}/${_ghver}/x86_64-linux-ghcup-${_ghver}
|
||||||
;;
|
;;
|
||||||
i*86)
|
i*86)
|
||||||
_url=https://downloads.haskell.org/~ghcup/${_ghver}/i386-linux-ghcup-${_ghver}
|
_url=${_base_url}/${_ghver}/i386-linux-ghcup-${_ghver}
|
||||||
;;
|
;;
|
||||||
*) die "Unknown architecture: ${_arch}"
|
*) die "Unknown architecture: ${_arch}"
|
||||||
;;
|
;;
|
||||||
@@ -53,7 +54,7 @@ download_ghcup() {
|
|||||||
*) die "Unknown architecture: ${_arch}"
|
*) die "Unknown architecture: ${_arch}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
_url=https://downloads.haskell.org/~ghcup/${_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
|
||||||
@@ -65,14 +66,14 @@ download_ghcup() {
|
|||||||
*) die "Unknown architecture: ${_arch}"
|
*) die "Unknown architecture: ${_arch}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
_url=https://downloads.haskell.org/~ghcup/${_ghver}/x86_64-apple-darwin-ghcup-${_ghver} ;;
|
_url=${_base_url}/${_ghver}/x86_64-apple-darwin-ghcup-${_ghver} ;;
|
||||||
*) die "Unknown platform: ${_plat}"
|
*) die "Unknown platform: ${_plat}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
edo curl -Lf "${_url}" > "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin/ghcup
|
edo curl -Lf "${_url}" > "${GHCUP_INSTALL_BASE_PREFIX}"/.ghcup/bin/ghcup
|
||||||
|
|
||||||
unset _plat _arch _url _ghver
|
unset _plat _arch _url _ghver _base_url
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -129,10 +130,10 @@ if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
|||||||
read -r answer </dev/tty
|
read -r answer </dev/tty
|
||||||
fi
|
fi
|
||||||
|
|
||||||
eghcup --cache install "${BOOTSTRAP_HASKELL_GHC_VERSION}"
|
eghcup --cache install ghc "${BOOTSTRAP_HASKELL_GHC_VERSION}"
|
||||||
|
|
||||||
eghcup set "${BOOTSTRAP_HASKELL_GHC_VERSION}"
|
eghcup set ghc "${BOOTSTRAP_HASKELL_GHC_VERSION}"
|
||||||
eghcup --cache install-cabal "${BOOTSTRAP_HASKELL_CABAL_VERSION}"
|
eghcup --cache install cabal "${BOOTSTRAP_HASKELL_CABAL_VERSION}"
|
||||||
|
|
||||||
edo cabal new-update
|
edo cabal new-update
|
||||||
|
|
||||||
@@ -163,6 +164,9 @@ if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
*/fish) # login shell is fish
|
||||||
|
GHCUP_PROFILE_FILE="$HOME/.config/fish/config.fish"
|
||||||
|
MY_SHELL="fish" ;;
|
||||||
*) exit 0 ;;
|
*) exit 0 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
@@ -178,7 +182,16 @@ if [ -z "${BOOTSTRAP_HASKELL_NONINTERACTIVE}" ] ; then
|
|||||||
|
|
||||||
case $next_answer in
|
case $next_answer in
|
||||||
[Yy]*)
|
[Yy]*)
|
||||||
echo "[ -f \"\${GHCUP_INSTALL_BASE_PREFIX:=\$HOME}/.ghcup/env\" ] && source \"\${GHCUP_INSTALL_BASE_PREFIX:=\$HOME}/.ghcup/env\"" >> "${GHCUP_PROFILE_FILE}"
|
case $MY_SHELL in
|
||||||
|
"") break ;;
|
||||||
|
fish)
|
||||||
|
echo "set -q GHCUP_INSTALL_BASE_PREFIX[1]; or set GHCUP_INSTALL_BASE_PREFIX \$HOME" >> "${GHCUP_PROFILE_FILE}"
|
||||||
|
echo "test -f \$GHCUP_INSTALL_BASE_PREFIX/.ghcup/env ; and set -gx PATH \$HOME/.cabal/bin \$GHCUP_INSTALL_BASE_PREFIX/.ghcup/bin \$PATH" >> "${GHCUP_PROFILE_FILE}"
|
||||||
|
break ;;
|
||||||
|
*)
|
||||||
|
echo "[ -f \"\${GHCUP_INSTALL_BASE_PREFIX:=\$HOME}/.ghcup/env\" ] && source \"\${GHCUP_INSTALL_BASE_PREFIX:=\$HOME}/.ghcup/env\"" >> "${GHCUP_PROFILE_FILE}"
|
||||||
|
break ;;
|
||||||
|
esac
|
||||||
printf "\\033[0;35m%s\\033[0m\\n" "OK! ${GHCUP_PROFILE_FILE} has been modified. Restart your terminal for the changes to take effect,"
|
printf "\\033[0;35m%s\\033[0m\\n" "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_INSTALL_BASE_PREFIX}/.ghcup/env\" to apply them in your current terminal session."
|
printf "\\033[0;35m%s\\033[0m\\n" "or type \"source ${GHCUP_INSTALL_BASE_PREFIX}/.ghcup/env\" to apply them in your current terminal session."
|
||||||
exit 0;;
|
exit 0;;
|
||||||
|
|||||||
142
ghcup-0.0.2.json
142
ghcup-0.0.2.json
@@ -1250,6 +1250,136 @@
|
|||||||
"base-4.13.0.0"
|
"base-4.13.0.0"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"8.8.4": {
|
||||||
|
"viArch": {
|
||||||
|
"A_64": {
|
||||||
|
"Linux_Debian": {
|
||||||
|
"unknown_versioning": {
|
||||||
|
"dlHash": "4862559d221153caf978f4bf2c15a82c114d1e1f43b298b2ecff2ac94b586d20",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-deb9-linux.tar.xz"
|
||||||
|
},
|
||||||
|
"8": {
|
||||||
|
"dlHash": "51a36892f1264744195274187298d13ac62bce2da86d4ddf76d8054ab90f2feb",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-deb8-linux.tar.xz"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Linux_Ubuntu": {
|
||||||
|
"unknown_versioning": {
|
||||||
|
"dlHash": "f32e37f8aa03e74bad533ae02f62dc27a4521e78199576af490888ba34b515db",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-fedora27-linux.tar.xz"
|
||||||
|
},
|
||||||
|
"16.04": {
|
||||||
|
"dlHash": "4862559d221153caf978f4bf2c15a82c114d1e1f43b298b2ecff2ac94b586d20",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-deb9-linux.tar.xz"
|
||||||
|
},
|
||||||
|
"18.04": {
|
||||||
|
"dlHash": "4862559d221153caf978f4bf2c15a82c114d1e1f43b298b2ecff2ac94b586d20",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-deb9-linux.tar.xz"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Darwin": {
|
||||||
|
"unknown_versioning": {
|
||||||
|
"dlHash": "e80a789e9d8cfb41dd87f3284b75432427c4461c1731d220d04ead8733ccdb5e",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-apple-darwin.tar.xz"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Linux_RedHat": {
|
||||||
|
"unknown_versioning": {
|
||||||
|
"dlHash": "a12aa4b1fd3c64240a8a6d15196d33e1c0e0d55b51ff78c387242126d0ef7910",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-centos7-linux.tar.xz"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Linux_UnknownLinux": {
|
||||||
|
"unknown_versioning": {
|
||||||
|
"dlHash": "f32e37f8aa03e74bad533ae02f62dc27a4521e78199576af490888ba34b515db",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-fedora27-linux.tar.xz"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Linux_Mint": {
|
||||||
|
"unknown_versioning": {
|
||||||
|
"dlHash": "4862559d221153caf978f4bf2c15a82c114d1e1f43b298b2ecff2ac94b586d20",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-deb9-linux.tar.xz"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Linux_Fedora": {
|
||||||
|
"unknown_versioning": {
|
||||||
|
"dlHash": "f32e37f8aa03e74bad533ae02f62dc27a4521e78199576af490888ba34b515db",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-fedora27-linux.tar.xz"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Linux_CentOS": {
|
||||||
|
"unknown_versioning": {
|
||||||
|
"dlHash": "a12aa4b1fd3c64240a8a6d15196d33e1c0e0d55b51ff78c387242126d0ef7910",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-centos7-linux.tar.xz"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Linux_AmazonLinux": {
|
||||||
|
"unknown_versioning": {
|
||||||
|
"dlHash": "a12aa4b1fd3c64240a8a6d15196d33e1c0e0d55b51ff78c387242126d0ef7910",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-centos7-linux.tar.xz"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"A_32": {
|
||||||
|
"FreeBSD": {
|
||||||
|
"unknown_versioning": {
|
||||||
|
"dlHash": "8cebe5ccf454e82acd1ff52ca57590d1ab0f3f44a981b46257ec12158c8c447e",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://files.hasufell.de/ghc/ghc-8.8.4-x86_64-portbld-freebsd.tar.xz"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Linux_Debian": {
|
||||||
|
"unknown_versioning": {
|
||||||
|
"dlHash": "43dd954910c9027694312cef0aabc7774d102d0422b7172802cfb72f7d5da3a0",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-i386-deb9-linux.tar.xz"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Linux_Ubuntu": {
|
||||||
|
"unknown_versioning": {
|
||||||
|
"dlHash": "43dd954910c9027694312cef0aabc7774d102d0422b7172802cfb72f7d5da3a0",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-i386-deb9-linux.tar.xz"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Linux_UnknownLinux": {
|
||||||
|
"unknown_versioning": {
|
||||||
|
"dlHash": "43dd954910c9027694312cef0aabc7774d102d0422b7172802cfb72f7d5da3a0",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-i386-deb9-linux.tar.xz"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Linux_Mint": {
|
||||||
|
"unknown_versioning": {
|
||||||
|
"dlHash": "43dd954910c9027694312cef0aabc7774d102d0422b7172802cfb72f7d5da3a0",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-i386-deb9-linux.tar.xz"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"viSourceDL": {
|
||||||
|
"dlHash": "f0505e38b2235ff9f1090b51f44d6c8efd371068e5a6bb42a2a6d8b67b5ffc2d",
|
||||||
|
"dlSubdir": "ghc-8.8.4",
|
||||||
|
"dlUri": "https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-src.tar.xz"
|
||||||
|
},
|
||||||
|
"viChangeLog": "https://downloads.haskell.org/~ghc/8.8.4/docs/html/users_guide/8.8.4-notes.html",
|
||||||
|
"viTags": [
|
||||||
|
"base-4.13.0.0"
|
||||||
|
]
|
||||||
|
},
|
||||||
"8.4.3": {
|
"8.4.3": {
|
||||||
"viArch": {
|
"viArch": {
|
||||||
"A_64": {
|
"A_64": {
|
||||||
@@ -2327,23 +2457,23 @@
|
|||||||
"A_64": {
|
"A_64": {
|
||||||
"FreeBSD": {
|
"FreeBSD": {
|
||||||
"unknown_versioning": {
|
"unknown_versioning": {
|
||||||
"dlHash": "52707d89c3a4114b577855612d915c1e10295c4354e7e641b4a37a90c34fea53",
|
"dlHash": "6bbfb1047691ff3ae9249e8805cf9f37bab30a008dae130cb2a4b3aa5253e6e5",
|
||||||
"dlSubdir": null,
|
"dlSubdir": null,
|
||||||
"dlUri": "https://downloads.haskell.org/ghcup/0.1.6/x86_64-portbld-freebsd-ghcup-0.1.6"
|
"dlUri": "https://downloads.haskell.org/~ghcup/0.1.6/x86_64-portbld-freebsd-ghcup-0.1.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Darwin": {
|
"Darwin": {
|
||||||
"unknown_versioning": {
|
"unknown_versioning": {
|
||||||
"dlHash": "bbf56b5820f97b5ee15d292803a2df06922d31b396f9322459f9e3782e78d59c",
|
"dlHash": "1e025e66d7f7b75d94f17a7da6120efd7e2df918a8eac88c4711ed11d2aac4ec",
|
||||||
"dlSubdir": null,
|
"dlSubdir": null,
|
||||||
"dlUri": "https://downloads.haskell.org/ghcup/0.1.6/x86_64-apple-darwin-ghcup-0.1.6"
|
"dlUri": "https://downloads.haskell.org/~ghcup/0.1.6/x86_64-apple-darwin-ghcup-0.1.6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Linux_UnknownLinux": {
|
"Linux_UnknownLinux": {
|
||||||
"unknown_versioning": {
|
"unknown_versioning": {
|
||||||
"dlHash": "bdbec0cdf4c8511c4082dd83993d15034c0fbcb5722ecf418c1cee40667da8af",
|
"dlHash": "bdbec0cdf4c8511c4082dd83993d15034c0fbcb5722ecf418c1cee40667da8af",
|
||||||
"dlSubdir": null,
|
"dlSubdir": null,
|
||||||
"dlUri": "https://downloads.haskell.org/ghcup/0.1.6/x86_64-linux-ghcup-0.1.6"
|
"dlUri": "https://downloads.haskell.org/~ghcup/0.1.6/x86_64-linux-ghcup-0.1.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -2352,7 +2482,7 @@
|
|||||||
"unknown_versioning": {
|
"unknown_versioning": {
|
||||||
"dlHash": "0366ed6c00862c3c002cdefc3e37523ad80e655387956c7ab58b268aaa6fae5d",
|
"dlHash": "0366ed6c00862c3c002cdefc3e37523ad80e655387956c7ab58b268aaa6fae5d",
|
||||||
"dlSubdir": null,
|
"dlSubdir": null,
|
||||||
"dlUri": "https://downloads.haskell.org/ghcup/0.1.6/i386-linux-ghcup-0.1.6"
|
"dlUri": "https://downloads.haskell.org/~ghcup/0.1.6/i386-linux-ghcup-0.1.6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
27
ghcup.cabal
27
ghcup.cabal
@@ -105,11 +105,14 @@ common hpath-io
|
|||||||
common hpath-posix
|
common hpath-posix
|
||||||
build-depends: hpath-posix >=0.13.2
|
build-depends: hpath-posix >=0.13.2
|
||||||
|
|
||||||
common http-io-streams
|
common http-client
|
||||||
build-depends: http-io-streams >=0.1.2.0
|
build-depends: http-client >=0.7.1
|
||||||
|
|
||||||
common io-streams
|
common http-client-openssl
|
||||||
build-depends: io-streams >=1.5
|
build-depends: http-client-openssl >=0.3.1.0
|
||||||
|
|
||||||
|
common http-types
|
||||||
|
build-depends: http-types >=0.12.3
|
||||||
|
|
||||||
common libarchive
|
common libarchive
|
||||||
build-depends: libarchive >= 2.2.5.0
|
build-depends: libarchive >= 2.2.5.0
|
||||||
@@ -120,6 +123,9 @@ common lzma
|
|||||||
common megaparsec
|
common megaparsec
|
||||||
build-depends: megaparsec >=8.0.0
|
build-depends: megaparsec >=8.0.0
|
||||||
|
|
||||||
|
common monad-control
|
||||||
|
build-depends: monad-control >=1.0.2.3
|
||||||
|
|
||||||
common monad-logger
|
common monad-logger
|
||||||
build-depends: monad-logger >=0.3.31
|
build-depends: monad-logger >=0.3.31
|
||||||
|
|
||||||
@@ -189,6 +195,9 @@ common time
|
|||||||
common transformers
|
common transformers
|
||||||
build-depends: transformers >=0.5
|
build-depends: transformers >=0.5
|
||||||
|
|
||||||
|
common transformers-base
|
||||||
|
build-depends: transformers-base >=0.4.4
|
||||||
|
|
||||||
common os-release
|
common os-release
|
||||||
build-depends: os-release >=1.0.0
|
build-depends: os-release >=1.0.0
|
||||||
|
|
||||||
@@ -263,6 +272,7 @@ library
|
|||||||
, hpath-posix
|
, hpath-posix
|
||||||
, lzma
|
, lzma
|
||||||
, megaparsec
|
, megaparsec
|
||||||
|
, monad-control
|
||||||
, monad-logger
|
, monad-logger
|
||||||
, mtl
|
, mtl
|
||||||
, optics
|
, optics
|
||||||
@@ -282,6 +292,7 @@ library
|
|||||||
, text
|
, text
|
||||||
, time
|
, time
|
||||||
, transformers
|
, transformers
|
||||||
|
, transformers-base
|
||||||
, os-release
|
, os-release
|
||||||
, unix
|
, unix
|
||||||
, unix-bytestring
|
, unix-bytestring
|
||||||
@@ -299,7 +310,6 @@ library
|
|||||||
GHCup.Data.GHCupInfo
|
GHCup.Data.GHCupInfo
|
||||||
GHCup.Data.ToolRequirements
|
GHCup.Data.ToolRequirements
|
||||||
GHCup.Download
|
GHCup.Download
|
||||||
GHCup.Download.Utils
|
|
||||||
GHCup.Errors
|
GHCup.Errors
|
||||||
GHCup.Platform
|
GHCup.Platform
|
||||||
GHCup.Requirements
|
GHCup.Requirements
|
||||||
@@ -323,10 +333,11 @@ library
|
|||||||
if flag(internal-downloader)
|
if flag(internal-downloader)
|
||||||
import:
|
import:
|
||||||
HsOpenSSL
|
HsOpenSSL
|
||||||
, http-io-streams
|
, http-client
|
||||||
, io-streams
|
, http-client-openssl
|
||||||
|
, http-types
|
||||||
, terminal-progress-bar
|
, terminal-progress-bar
|
||||||
exposed-modules: GHCup.Download.IOStreams
|
exposed-modules: GHCup.Download.Internal
|
||||||
cpp-options: -DINTERNAL_DOWNLOADER
|
cpp-options: -DINTERNAL_DOWNLOADER
|
||||||
|
|
||||||
if flag(tar)
|
if flag(tar)
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ import Data.Versions
|
|||||||
import Data.Word8
|
import Data.Word8
|
||||||
import GHC.IO.Exception
|
import GHC.IO.Exception
|
||||||
import HPath
|
import HPath
|
||||||
import HPath.IO
|
import HPath.IO hiding ( hideError )
|
||||||
import Haskus.Utils.Variant.Excepts
|
import Haskus.Utils.Variant.Excepts
|
||||||
import Optics
|
import Optics
|
||||||
import Prelude hiding ( abs
|
import Prelude hiding ( abs
|
||||||
|
|||||||
@@ -846,6 +846,56 @@ ghc_883_64_freebsd = DownloadInfo
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-----------------
|
||||||
|
--[ GHC 8.8.4 ]--
|
||||||
|
-----------------
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
ghc_884_64_deb8 :: DownloadInfo
|
||||||
|
ghc_884_64_deb8 = DownloadInfo
|
||||||
|
[uri|https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-deb8-linux.tar.xz|]
|
||||||
|
(Just [rel|ghc-8.8.4|])
|
||||||
|
"51a36892f1264744195274187298d13ac62bce2da86d4ddf76d8054ab90f2feb"
|
||||||
|
|
||||||
|
ghc_884_64_deb9 :: DownloadInfo
|
||||||
|
ghc_884_64_deb9 = DownloadInfo
|
||||||
|
[uri|https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-deb9-linux.tar.xz|]
|
||||||
|
(Just [rel|ghc-8.8.4|])
|
||||||
|
"4862559d221153caf978f4bf2c15a82c114d1e1f43b298b2ecff2ac94b586d20"
|
||||||
|
|
||||||
|
ghc_884_32_deb9 :: DownloadInfo
|
||||||
|
ghc_884_32_deb9 = DownloadInfo
|
||||||
|
[uri|https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-i386-deb9-linux.tar.xz|]
|
||||||
|
(Just [rel|ghc-8.8.4|])
|
||||||
|
"43dd954910c9027694312cef0aabc7774d102d0422b7172802cfb72f7d5da3a0"
|
||||||
|
|
||||||
|
ghc_884_64_fedora :: DownloadInfo
|
||||||
|
ghc_884_64_fedora = DownloadInfo
|
||||||
|
[uri|https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-fedora27-linux.tar.xz|]
|
||||||
|
(Just [rel|ghc-8.8.4|])
|
||||||
|
"f32e37f8aa03e74bad533ae02f62dc27a4521e78199576af490888ba34b515db"
|
||||||
|
|
||||||
|
ghc_884_64_centos :: DownloadInfo
|
||||||
|
ghc_884_64_centos = DownloadInfo
|
||||||
|
[uri|https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-centos7-linux.tar.xz|]
|
||||||
|
(Just [rel|ghc-8.8.4|])
|
||||||
|
"a12aa4b1fd3c64240a8a6d15196d33e1c0e0d55b51ff78c387242126d0ef7910"
|
||||||
|
|
||||||
|
ghc_884_64_darwin :: DownloadInfo
|
||||||
|
ghc_884_64_darwin = DownloadInfo
|
||||||
|
[uri|https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-x86_64-apple-darwin.tar.xz|]
|
||||||
|
(Just [rel|ghc-8.8.4|])
|
||||||
|
"e80a789e9d8cfb41dd87f3284b75432427c4461c1731d220d04ead8733ccdb5e"
|
||||||
|
|
||||||
|
ghc_884_64_freebsd :: DownloadInfo
|
||||||
|
ghc_884_64_freebsd = DownloadInfo
|
||||||
|
[uri|https://files.hasufell.de/ghc/ghc-8.8.4-x86_64-portbld-freebsd.tar.xz|]
|
||||||
|
(Just [rel|ghc-8.8.4|])
|
||||||
|
"8cebe5ccf454e82acd1ff52ca57590d1ab0f3f44a981b46257ec12158c8c447e"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-----------------
|
-----------------
|
||||||
--[ GHC 8.10.1 ]--
|
--[ GHC 8.10.1 ]--
|
||||||
-----------------
|
-----------------
|
||||||
@@ -1041,30 +1091,30 @@ cabal_3200_64_alpine = DownloadInfo
|
|||||||
|
|
||||||
ghcup_016_32_linux :: DownloadInfo
|
ghcup_016_32_linux :: DownloadInfo
|
||||||
ghcup_016_32_linux = DownloadInfo
|
ghcup_016_32_linux = DownloadInfo
|
||||||
[uri|https://downloads.haskell.org/ghcup/0.1.6/i386-linux-ghcup-0.1.6|]
|
[uri|https://downloads.haskell.org/~ghcup/0.1.6/i386-linux-ghcup-0.1.6|]
|
||||||
Nothing
|
Nothing
|
||||||
"0366ed6c00862c3c002cdefc3e37523ad80e655387956c7ab58b268aaa6fae5d"
|
"0366ed6c00862c3c002cdefc3e37523ad80e655387956c7ab58b268aaa6fae5d"
|
||||||
|
|
||||||
|
|
||||||
ghcup_016_64_linux :: DownloadInfo
|
ghcup_016_64_linux :: DownloadInfo
|
||||||
ghcup_016_64_linux = DownloadInfo
|
ghcup_016_64_linux = DownloadInfo
|
||||||
[uri|https://downloads.haskell.org/ghcup/0.1.6/x86_64-linux-ghcup-0.1.6|]
|
[uri|https://downloads.haskell.org/~ghcup/0.1.6/x86_64-linux-ghcup-0.1.6|]
|
||||||
Nothing
|
Nothing
|
||||||
"bdbec0cdf4c8511c4082dd83993d15034c0fbcb5722ecf418c1cee40667da8af"
|
"bdbec0cdf4c8511c4082dd83993d15034c0fbcb5722ecf418c1cee40667da8af"
|
||||||
|
|
||||||
|
|
||||||
ghcup_016_64_freebsd :: DownloadInfo
|
ghcup_016_64_freebsd :: DownloadInfo
|
||||||
ghcup_016_64_freebsd = DownloadInfo
|
ghcup_016_64_freebsd = DownloadInfo
|
||||||
[uri|https://downloads.haskell.org/ghcup/0.1.6/x86_64-portbld-freebsd-ghcup-0.1.6|]
|
[uri|https://downloads.haskell.org/~ghcup/0.1.6/x86_64-portbld-freebsd-ghcup-0.1.6|]
|
||||||
Nothing
|
Nothing
|
||||||
"52707d89c3a4114b577855612d915c1e10295c4354e7e641b4a37a90c34fea53"
|
"6bbfb1047691ff3ae9249e8805cf9f37bab30a008dae130cb2a4b3aa5253e6e5"
|
||||||
|
|
||||||
|
|
||||||
ghcup_016_64_darwin10_13 :: DownloadInfo
|
ghcup_016_64_darwin10_13 :: DownloadInfo
|
||||||
ghcup_016_64_darwin10_13 = DownloadInfo
|
ghcup_016_64_darwin10_13 = DownloadInfo
|
||||||
[uri|https://downloads.haskell.org/ghcup/0.1.6/x86_64-apple-darwin-ghcup-0.1.6|]
|
[uri|https://downloads.haskell.org/~ghcup/0.1.6/x86_64-apple-darwin-ghcup-0.1.6|]
|
||||||
Nothing
|
Nothing
|
||||||
"bbf56b5820f97b5ee15d292803a2df06922d31b396f9322459f9e3782e78d59c"
|
"1e025e66d7f7b75d94f17a7da6120efd7e2df918a8eac88c4711ed11d2aac4ec"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1653,7 +1703,7 @@ ghcupDownloads = M.fromList
|
|||||||
)
|
)
|
||||||
, (Darwin , M.fromList [(Nothing, ghc_865_64_darwin)])
|
, (Darwin , M.fromList [(Nothing, ghc_865_64_darwin)])
|
||||||
, (Linux Alpine, M.fromList [(Nothing, ghc_865_64_musl)])
|
, (Linux Alpine, M.fromList [(Nothing, ghc_865_64_musl)])
|
||||||
, (FreeBSD, M.fromList [(Nothing, ghc_865_64_freebsd)])
|
, (FreeBSD , M.fromList [(Nothing, ghc_865_64_freebsd)])
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
, ( A_32
|
, ( A_32
|
||||||
@@ -1832,6 +1882,59 @@ ghcupDownloads = M.fromList
|
|||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
, ( [vver|8.8.4|]
|
||||||
|
, VersionInfo
|
||||||
|
[Base [pver|4.13.0.0|]]
|
||||||
|
(Just
|
||||||
|
[uri|https://downloads.haskell.org/~ghc/8.8.4/docs/html/users_guide/8.8.4-notes.html|]
|
||||||
|
)
|
||||||
|
(Just $ DownloadInfo
|
||||||
|
[uri|https://downloads.haskell.org/~ghc/8.8.4/ghc-8.8.4-src.tar.xz|]
|
||||||
|
(Just [rel|ghc-8.8.4|])
|
||||||
|
"f0505e38b2235ff9f1090b51f44d6c8efd371068e5a6bb42a2a6d8b67b5ffc2d"
|
||||||
|
)
|
||||||
|
$ M.fromList
|
||||||
|
[ ( A_64
|
||||||
|
, M.fromList
|
||||||
|
[ ( Linux UnknownLinux
|
||||||
|
, M.fromList [(Nothing, ghc_884_64_fedora)]
|
||||||
|
)
|
||||||
|
, (Linux Fedora, M.fromList [(Nothing, ghc_884_64_fedora)])
|
||||||
|
, (Linux CentOS, M.fromList [(Nothing, ghc_884_64_centos)])
|
||||||
|
, (Linux RedHat, M.fromList [(Nothing, ghc_884_64_centos)])
|
||||||
|
, ( Linux AmazonLinux
|
||||||
|
, M.fromList [(Nothing, ghc_884_64_centos)]
|
||||||
|
)
|
||||||
|
, ( Linux Ubuntu
|
||||||
|
, M.fromList
|
||||||
|
[ (Nothing , ghc_884_64_fedora)
|
||||||
|
, (Just [vers|16.04|], ghc_884_64_deb9)
|
||||||
|
, (Just [vers|18.04|], ghc_884_64_deb9)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
, (Linux Mint, M.fromList [(Nothing, ghc_884_64_deb9)])
|
||||||
|
, ( Linux Debian
|
||||||
|
, M.fromList
|
||||||
|
[ (Nothing , ghc_884_64_deb9)
|
||||||
|
, (Just [vers|8|], ghc_884_64_deb8)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
, (Darwin, M.fromList [(Nothing, ghc_884_64_darwin)])
|
||||||
|
]
|
||||||
|
)
|
||||||
|
, ( A_32
|
||||||
|
, M.fromList
|
||||||
|
[ ( Linux UnknownLinux
|
||||||
|
, M.fromList [(Nothing, ghc_884_32_deb9)]
|
||||||
|
)
|
||||||
|
, (Linux Ubuntu, M.fromList [(Nothing, ghc_884_32_deb9)])
|
||||||
|
, (Linux Mint , M.fromList [(Nothing, ghc_884_32_deb9)])
|
||||||
|
, (Linux Debian, M.fromList [(Nothing, ghc_884_32_deb9)])
|
||||||
|
, (FreeBSD , M.fromList [(Nothing, ghc_884_64_freebsd)])
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
, ( [vver|8.10.1|]
|
, ( [vver|8.10.1|]
|
||||||
, VersionInfo
|
, VersionInfo
|
||||||
[Latest, Base [pver|4.14.0.0|]]
|
[Latest, Base [pver|4.14.0.0|]]
|
||||||
|
|||||||
@@ -12,8 +12,7 @@
|
|||||||
module GHCup.Download where
|
module GHCup.Download where
|
||||||
|
|
||||||
#if defined(INTERNAL_DOWNLOADER)
|
#if defined(INTERNAL_DOWNLOADER)
|
||||||
import GHCup.Download.IOStreams
|
import GHCup.Download.Internal
|
||||||
import GHCup.Download.Utils
|
|
||||||
#endif
|
#endif
|
||||||
import GHCup.Errors
|
import GHCup.Errors
|
||||||
import GHCup.Types
|
import GHCup.Types
|
||||||
@@ -50,7 +49,7 @@ import Data.Versions
|
|||||||
import Data.Word8
|
import Data.Word8
|
||||||
import GHC.IO.Exception
|
import GHC.IO.Exception
|
||||||
import HPath
|
import HPath
|
||||||
import HPath.IO as HIO
|
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
|
||||||
@@ -233,16 +232,20 @@ getDownloads urlSource = do
|
|||||||
#if !defined(INTERNAL_DOWNLOADER)
|
#if !defined(INTERNAL_DOWNLOADER)
|
||||||
pure Nothing
|
pure Nothing
|
||||||
#else
|
#else
|
||||||
headers <-
|
Settings{..} <- lift ask
|
||||||
handleIO (\_ -> pure mempty)
|
case downloader of
|
||||||
$ liftE
|
Internal -> do
|
||||||
$ ( catchAllE
|
headers <-
|
||||||
(\_ ->
|
handleIO (\_ -> pure mempty)
|
||||||
pure mempty :: Excepts '[] m1 (M.Map (CI ByteString) ByteString)
|
$ liftE
|
||||||
|
$ ( catchAllE
|
||||||
|
(\_ ->
|
||||||
|
pure mempty :: Excepts '[] m1 (M.Map (CI ByteString) ByteString)
|
||||||
|
)
|
||||||
|
$ getHead uri'
|
||||||
)
|
)
|
||||||
$ getHead uri'
|
pure $ parseModifiedHeader headers
|
||||||
)
|
_ -> pure Nothing
|
||||||
pure $ parseModifiedHeader headers
|
|
||||||
|
|
||||||
parseModifiedHeader :: (M.Map (CI ByteString) ByteString) -> Maybe UTCTime
|
parseModifiedHeader :: (M.Map (CI ByteString) ByteString) -> Maybe UTCTime
|
||||||
parseModifiedHeader headers =
|
parseModifiedHeader headers =
|
||||||
@@ -339,9 +342,7 @@ download dli dest mfn
|
|||||||
liftE $ lEM @_ @'[ProcessError] $ liftIO $ exec "wget" True
|
liftE $ lEM @_ @'[ProcessError] $ liftIO $ exec "wget" True
|
||||||
(o' ++ ["-O", toFilePath destFile , serializeURIRef' $ view dlUri dli]) Nothing Nothing
|
(o' ++ ["-O", toFilePath destFile , serializeURIRef' $ view dlUri dli]) Nothing Nothing
|
||||||
#if defined(INTERNAL_DOWNLOADER)
|
#if defined(INTERNAL_DOWNLOADER)
|
||||||
Internal -> do
|
Internal -> liftE $ downloadToFile (_dlUri dli) destFile
|
||||||
(https, host, fullPath, port) <- liftE $ uriToQuadruple (view dlUri dli)
|
|
||||||
liftE $ downloadToFile https host fullPath port destFile
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
liftE $ checkDigest dli destFile
|
liftE $ checkDigest dli destFile
|
||||||
@@ -408,10 +409,8 @@ downloadBS :: (MonadReader Settings m, MonadCatch m, MonadIO m, MonadLogger m)
|
|||||||
m
|
m
|
||||||
L.ByteString
|
L.ByteString
|
||||||
downloadBS uri'
|
downloadBS uri'
|
||||||
| scheme == "https"
|
| scheme == "https" || scheme == "http"
|
||||||
= dl True
|
= dl
|
||||||
| scheme == "http"
|
|
||||||
= dl False
|
|
||||||
| scheme == "file"
|
| scheme == "file"
|
||||||
= liftIOException doesNotExistErrorType (FileDoesNotExistError path)
|
= liftIOException doesNotExistErrorType (FileDoesNotExistError path)
|
||||||
$ (liftIO $ RD.readFile path)
|
$ (liftIO $ RD.readFile path)
|
||||||
@@ -421,11 +420,7 @@ downloadBS uri'
|
|||||||
where
|
where
|
||||||
scheme = view (uriSchemeL' % schemeBSL') uri'
|
scheme = view (uriSchemeL' % schemeBSL') uri'
|
||||||
path = view pathL' uri'
|
path = view pathL' uri'
|
||||||
#if defined(INTERNAL_DOWNLOADER)
|
dl = do
|
||||||
dl https = do
|
|
||||||
#else
|
|
||||||
dl _ = do
|
|
||||||
#endif
|
|
||||||
lift $ $(logDebug) [i|downloading: #{serializeURIRef' uri'}|]
|
lift $ $(logDebug) [i|downloading: #{serializeURIRef' uri'}|]
|
||||||
lift getDownloader >>= \case
|
lift getDownloader >>= \case
|
||||||
Curl -> do
|
Curl -> do
|
||||||
@@ -445,9 +440,7 @@ downloadBS uri'
|
|||||||
pure $ L.fromStrict stdout
|
pure $ L.fromStrict stdout
|
||||||
CapturedProcess (ExitFailure i') _ _ -> throwE $ NonZeroExit i' (toFilePath exe) args
|
CapturedProcess (ExitFailure i') _ _ -> throwE $ NonZeroExit i' (toFilePath exe) args
|
||||||
#if defined(INTERNAL_DOWNLOADER)
|
#if defined(INTERNAL_DOWNLOADER)
|
||||||
Internal -> do
|
Internal -> liftE $ downloadBS' uri'
|
||||||
(_, host', fullPath', port') <- liftE $ uriToQuadruple uri'
|
|
||||||
liftE $ downloadBS' https host' fullPath' port'
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,253 +0,0 @@
|
|||||||
{-# LANGUAGE DataKinds #-}
|
|
||||||
{-# LANGUAGE DeriveGeneric #-}
|
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
|
||||||
{-# LANGUAGE QuasiQuotes #-}
|
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
|
||||||
{-# LANGUAGE TypeApplications #-}
|
|
||||||
{-# LANGUAGE TypeFamilies #-}
|
|
||||||
|
|
||||||
|
|
||||||
module GHCup.Download.IOStreams where
|
|
||||||
|
|
||||||
|
|
||||||
import GHCup.Download.Utils
|
|
||||||
import GHCup.Errors
|
|
||||||
import GHCup.Types.Optics
|
|
||||||
import GHCup.Types.JSON ( )
|
|
||||||
import GHCup.Utils.File
|
|
||||||
import GHCup.Utils.Prelude
|
|
||||||
|
|
||||||
import Control.Applicative
|
|
||||||
import Control.Exception.Safe
|
|
||||||
import Control.Monad
|
|
||||||
import Control.Monad.Reader
|
|
||||||
import Data.ByteString ( ByteString )
|
|
||||||
import Data.ByteString.Builder
|
|
||||||
import Data.CaseInsensitive ( CI )
|
|
||||||
import Data.IORef
|
|
||||||
import Data.Maybe
|
|
||||||
import Data.Text.Read
|
|
||||||
import HPath
|
|
||||||
import HPath.IO as HIO
|
|
||||||
import Haskus.Utils.Variant.Excepts
|
|
||||||
import Network.Http.Client hiding ( URL )
|
|
||||||
import Optics
|
|
||||||
import Prelude hiding ( abs
|
|
||||||
, readFile
|
|
||||||
, writeFile
|
|
||||||
)
|
|
||||||
import "unix" System.Posix.IO.ByteString
|
|
||||||
hiding ( fdWrite )
|
|
||||||
import "unix-bytestring" System.Posix.IO.ByteString
|
|
||||||
( fdWrite )
|
|
||||||
import System.ProgressBar
|
|
||||||
import URI.ByteString
|
|
||||||
|
|
||||||
import qualified Data.ByteString as BS
|
|
||||||
import qualified Data.ByteString.Lazy as L
|
|
||||||
import qualified Data.Map.Strict as M
|
|
||||||
import qualified System.IO.Streams as Streams
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
----------------------------
|
|
||||||
--[ Low-level (non-curl) ]--
|
|
||||||
----------------------------
|
|
||||||
|
|
||||||
|
|
||||||
-- | Load the result of this download into memory at once.
|
|
||||||
downloadBS' :: MonadIO m
|
|
||||||
=> Bool -- ^ https?
|
|
||||||
-> ByteString -- ^ host (e.g. "www.example.com")
|
|
||||||
-> ByteString -- ^ path (e.g. "/my/file") including query
|
|
||||||
-> Maybe Int -- ^ optional port (e.g. 3000)
|
|
||||||
-> Excepts
|
|
||||||
'[ HTTPStatusError
|
|
||||||
, URIParseError
|
|
||||||
, UnsupportedScheme
|
|
||||||
, NoLocationHeader
|
|
||||||
, TooManyRedirs
|
|
||||||
]
|
|
||||||
m
|
|
||||||
(L.ByteString)
|
|
||||||
downloadBS' https host path port = do
|
|
||||||
bref <- liftIO $ newIORef (mempty :: Builder)
|
|
||||||
let stepper bs = modifyIORef bref (<> byteString bs)
|
|
||||||
downloadInternal False https host path port stepper
|
|
||||||
liftIO (readIORef bref <&> toLazyByteString)
|
|
||||||
|
|
||||||
|
|
||||||
downloadToFile :: (MonadMask m, MonadIO m)
|
|
||||||
=> Bool -- ^ https?
|
|
||||||
-> ByteString -- ^ host (e.g. "www.example.com")
|
|
||||||
-> ByteString -- ^ path (e.g. "/my/file") including query
|
|
||||||
-> Maybe Int -- ^ optional port (e.g. 3000)
|
|
||||||
-> Path Abs -- ^ destination file to create and write to
|
|
||||||
-> Excepts '[DownloadFailed] m ()
|
|
||||||
downloadToFile https host fullPath port destFile = do
|
|
||||||
fd <- liftIO $ createRegularFileFd newFilePerms destFile
|
|
||||||
let stepper = fdWrite fd
|
|
||||||
flip finally (liftIO $ closeFd fd)
|
|
||||||
$ reThrowAll DownloadFailed $ downloadInternal True https host fullPath port stepper
|
|
||||||
|
|
||||||
|
|
||||||
downloadInternal :: MonadIO m
|
|
||||||
=> Bool -- ^ whether to show a progress bar
|
|
||||||
-> Bool -- ^ https?
|
|
||||||
-> ByteString -- ^ host
|
|
||||||
-> ByteString -- ^ path with query
|
|
||||||
-> Maybe Int -- ^ optional port
|
|
||||||
-> (ByteString -> IO a) -- ^ the consuming step function
|
|
||||||
-> Excepts
|
|
||||||
'[ HTTPStatusError
|
|
||||||
, URIParseError
|
|
||||||
, UnsupportedScheme
|
|
||||||
, NoLocationHeader
|
|
||||||
, TooManyRedirs
|
|
||||||
]
|
|
||||||
m
|
|
||||||
()
|
|
||||||
downloadInternal = go (5 :: Int)
|
|
||||||
|
|
||||||
where
|
|
||||||
go redirs progressBar https host path port consumer = do
|
|
||||||
r <- liftIO $ withConnection' https host port action
|
|
||||||
veitherToExcepts r >>= \case
|
|
||||||
Just r' ->
|
|
||||||
if redirs > 0 then followRedirectURL r' else throwE TooManyRedirs
|
|
||||||
Nothing -> pure ()
|
|
||||||
where
|
|
||||||
action c = do
|
|
||||||
let q = buildRequest1 $ http GET path
|
|
||||||
|
|
||||||
sendRequest c q emptyBody
|
|
||||||
|
|
||||||
receiveResponse
|
|
||||||
c
|
|
||||||
(\r i' -> runE $ do
|
|
||||||
let scode = getStatusCode r
|
|
||||||
if
|
|
||||||
| scode >= 200 && scode < 300 -> downloadStream r i' >> pure Nothing
|
|
||||||
| scode >= 300 && scode < 400 -> case getHeader r "Location" of
|
|
||||||
Just r' -> pure $ Just $ r'
|
|
||||||
Nothing -> throwE NoLocationHeader
|
|
||||||
| otherwise -> throwE $ HTTPStatusError scode
|
|
||||||
)
|
|
||||||
|
|
||||||
followRedirectURL bs = case parseURI strictURIParserOptions bs of
|
|
||||||
Right uri' -> do
|
|
||||||
(https', host', fullPath', port') <- liftE $ uriToQuadruple uri'
|
|
||||||
go (redirs - 1) progressBar https' host' fullPath' port' consumer
|
|
||||||
Left e -> throwE e
|
|
||||||
|
|
||||||
downloadStream r i' = do
|
|
||||||
let size = case getHeader r "Content-Length" of
|
|
||||||
Just x' -> case decimal $ decUTF8Safe x' of
|
|
||||||
Left _ -> 0
|
|
||||||
Right (r', _) -> r'
|
|
||||||
Nothing -> 0
|
|
||||||
|
|
||||||
mpb <- if progressBar
|
|
||||||
then Just <$> (liftIO $ newProgressBar defStyle 10 (Progress 0 size ()))
|
|
||||||
else pure Nothing
|
|
||||||
|
|
||||||
outStream <- liftIO $ Streams.makeOutputStream
|
|
||||||
(\case
|
|
||||||
Just bs -> do
|
|
||||||
forM_ mpb $ \pb -> incProgress pb (BS.length bs)
|
|
||||||
void $ consumer bs
|
|
||||||
Nothing -> pure ()
|
|
||||||
)
|
|
||||||
liftIO $ Streams.connect i' outStream
|
|
||||||
|
|
||||||
|
|
||||||
getHead :: (MonadCatch m, MonadIO m)
|
|
||||||
=> URI
|
|
||||||
-> Excepts
|
|
||||||
'[ HTTPStatusError
|
|
||||||
, URIParseError
|
|
||||||
, UnsupportedScheme
|
|
||||||
, NoLocationHeader
|
|
||||||
, TooManyRedirs
|
|
||||||
, ProcessError
|
|
||||||
]
|
|
||||||
m
|
|
||||||
(M.Map (CI ByteString) ByteString)
|
|
||||||
getHead uri' | scheme == "https" = head' True
|
|
||||||
| scheme == "http" = head' False
|
|
||||||
| otherwise = throwE UnsupportedScheme
|
|
||||||
|
|
||||||
where
|
|
||||||
scheme = view (uriSchemeL' % schemeBSL') uri'
|
|
||||||
head' https = do
|
|
||||||
(_, host', fullPath', port') <- liftE $ uriToQuadruple uri'
|
|
||||||
liftE $ headInternal https host' fullPath' port'
|
|
||||||
|
|
||||||
|
|
||||||
headInternal :: MonadIO m
|
|
||||||
=> Bool -- ^ https?
|
|
||||||
-> ByteString -- ^ host
|
|
||||||
-> ByteString -- ^ path with query
|
|
||||||
-> Maybe Int -- ^ optional port
|
|
||||||
-> Excepts
|
|
||||||
'[ HTTPStatusError
|
|
||||||
, URIParseError
|
|
||||||
, UnsupportedScheme
|
|
||||||
, TooManyRedirs
|
|
||||||
, NoLocationHeader
|
|
||||||
]
|
|
||||||
m
|
|
||||||
(M.Map (CI ByteString) ByteString)
|
|
||||||
headInternal = go (5 :: Int)
|
|
||||||
|
|
||||||
where
|
|
||||||
go redirs https host path port = do
|
|
||||||
r <- liftIO $ withConnection' https host port action
|
|
||||||
veitherToExcepts r >>= \case
|
|
||||||
Left r' ->
|
|
||||||
if redirs > 0 then followRedirectURL r' else throwE TooManyRedirs
|
|
||||||
Right hs -> pure hs
|
|
||||||
where
|
|
||||||
|
|
||||||
action c = do
|
|
||||||
let q = buildRequest1 $ http HEAD path
|
|
||||||
|
|
||||||
sendRequest c q emptyBody
|
|
||||||
|
|
||||||
unsafeReceiveResponse
|
|
||||||
c
|
|
||||||
(\r _ -> runE $ do
|
|
||||||
let scode = getStatusCode r
|
|
||||||
if
|
|
||||||
| scode >= 200 && scode < 300 -> do
|
|
||||||
let headers = getHeaderMap r
|
|
||||||
pure $ Right $ headers
|
|
||||||
| scode >= 300 && scode < 400 -> case getHeader r "Location" of
|
|
||||||
Just r' -> pure $ Left $ r'
|
|
||||||
Nothing -> throwE NoLocationHeader
|
|
||||||
| otherwise -> throwE $ HTTPStatusError scode
|
|
||||||
)
|
|
||||||
|
|
||||||
followRedirectURL bs = case parseURI strictURIParserOptions bs of
|
|
||||||
Right uri' -> do
|
|
||||||
(https', host', fullPath', port') <- liftE $ uriToQuadruple uri'
|
|
||||||
go (redirs - 1) https' host' fullPath' port'
|
|
||||||
Left e -> throwE e
|
|
||||||
|
|
||||||
|
|
||||||
withConnection' :: Bool
|
|
||||||
-> ByteString
|
|
||||||
-> Maybe Int
|
|
||||||
-> (Connection -> IO a)
|
|
||||||
-> IO a
|
|
||||||
withConnection' https host port action = bracket acquire closeConnection action
|
|
||||||
|
|
||||||
where
|
|
||||||
acquire = case https of
|
|
||||||
True -> do
|
|
||||||
ctx <- baselineContextSSL
|
|
||||||
openConnectionSSL ctx host (fromIntegral $ fromMaybe 443 port)
|
|
||||||
False -> openConnection host (fromIntegral $ fromMaybe 80 port)
|
|
||||||
214
lib/GHCup/Download/Internal.hs
Normal file
214
lib/GHCup/Download/Internal.hs
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
{-# LANGUAGE CPP #-}
|
||||||
|
{-# LANGUAGE DataKinds #-}
|
||||||
|
{-# LANGUAGE DeriveGeneric #-}
|
||||||
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
|
{-# LANGUAGE TemplateHaskell #-}
|
||||||
|
{-# LANGUAGE TypeApplications #-}
|
||||||
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
|
|
||||||
|
|
||||||
|
module GHCup.Download.Internal where
|
||||||
|
|
||||||
|
|
||||||
|
import GHCup.Errors
|
||||||
|
import GHCup.Types.Optics
|
||||||
|
import GHCup.Types.JSON ( )
|
||||||
|
import GHCup.Utils.File
|
||||||
|
import GHCup.Utils.Prelude
|
||||||
|
|
||||||
|
import Control.Applicative
|
||||||
|
import Control.Exception.Safe
|
||||||
|
import Control.Monad
|
||||||
|
import Control.Monad.Reader
|
||||||
|
import Data.ByteString ( ByteString )
|
||||||
|
import Data.ByteString.Builder
|
||||||
|
import Data.CaseInsensitive ( CI )
|
||||||
|
import Data.IORef
|
||||||
|
import Data.Maybe
|
||||||
|
import Data.Text.Read
|
||||||
|
import HPath
|
||||||
|
import HPath.IO as HIO
|
||||||
|
import Haskus.Utils.Variant.Excepts
|
||||||
|
import Network.HTTP.Client
|
||||||
|
import Network.HTTP.Client.OpenSSL
|
||||||
|
import Network.HTTP.Types.Status
|
||||||
|
import Network.HTTP.Types.Header
|
||||||
|
import Optics
|
||||||
|
import Prelude hiding ( abs
|
||||||
|
, readFile
|
||||||
|
, writeFile
|
||||||
|
)
|
||||||
|
import "unix" System.Posix.IO.ByteString
|
||||||
|
hiding ( fdWrite )
|
||||||
|
import "unix-bytestring" System.Posix.IO.ByteString
|
||||||
|
( fdWrite )
|
||||||
|
import System.ProgressBar
|
||||||
|
import URI.ByteString
|
||||||
|
|
||||||
|
import qualified Data.ByteString as BS
|
||||||
|
import qualified Data.ByteString.Lazy as L
|
||||||
|
import qualified Data.Map.Strict as M
|
||||||
|
import qualified Data.Text as T
|
||||||
|
import qualified OpenSSL.Session as SSL
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
----------------------------
|
||||||
|
--[ Low-level (non-curl) ]--
|
||||||
|
----------------------------
|
||||||
|
|
||||||
|
|
||||||
|
-- | Load the result of this download into memory at once.
|
||||||
|
downloadBS' :: (MonadThrow m, MonadIO m)
|
||||||
|
=> URI
|
||||||
|
-> Excepts
|
||||||
|
'[HTTPStatusError]
|
||||||
|
m
|
||||||
|
(L.ByteString)
|
||||||
|
downloadBS' uri' = do
|
||||||
|
bref <- liftIO $ newIORef (mempty :: Builder)
|
||||||
|
-- TODO: performance
|
||||||
|
let stepper bs = modifyIORef bref (<> byteString bs)
|
||||||
|
downloadInternal False
|
||||||
|
(T.unpack . decUTF8Safe . serializeURIRef' $ uri')
|
||||||
|
stepper
|
||||||
|
liftIO (readIORef bref <&> toLazyByteString)
|
||||||
|
|
||||||
|
|
||||||
|
downloadToFile :: (MonadMask m, MonadIO m)
|
||||||
|
=> URI
|
||||||
|
-> Path Abs -- ^ destination file to create and write to
|
||||||
|
-> Excepts '[DownloadFailed] m ()
|
||||||
|
downloadToFile uri' destFile = do
|
||||||
|
fd <- liftIO $ createRegularFileFd newFilePerms destFile
|
||||||
|
let stepper = fdWrite fd
|
||||||
|
flip finally (liftIO $ closeFd fd)
|
||||||
|
$ reThrowAll DownloadFailed
|
||||||
|
$ downloadInternal True
|
||||||
|
(T.unpack . decUTF8Safe . serializeURIRef' $ uri')
|
||||||
|
stepper
|
||||||
|
|
||||||
|
|
||||||
|
downloadInternal :: (MonadThrow m, MonadIO m)
|
||||||
|
=> Bool -- ^ whether to show a progress bar
|
||||||
|
-> String
|
||||||
|
-> (ByteString -> IO a) -- ^ the consuming step function
|
||||||
|
-> Excepts
|
||||||
|
'[HTTPStatusError]
|
||||||
|
m
|
||||||
|
()
|
||||||
|
downloadInternal progressBar uri' consumer = lEM $ liftIO $ withConnection' action
|
||||||
|
where
|
||||||
|
action :: (MonadThrow m, MonadIO m) => Manager -> m (Either HTTPStatusError ())
|
||||||
|
action m = do
|
||||||
|
request <- parseRequest ("GET " <> uri')
|
||||||
|
liftIO $ withResponse
|
||||||
|
request
|
||||||
|
m
|
||||||
|
(\r -> do
|
||||||
|
let scode = statusCode . responseStatus $ r
|
||||||
|
if
|
||||||
|
| scode >= 200 && scode < 300 ->
|
||||||
|
let headers = M.fromList . responseHeaders $ r
|
||||||
|
in fmap Right $ liftIO $ downloadStream (responseBody r) headers
|
||||||
|
| otherwise -> pure $ Left $ HTTPStatusError scode
|
||||||
|
)
|
||||||
|
|
||||||
|
downloadStream :: BodyReader -> M.Map HeaderName ByteString -> IO ()
|
||||||
|
downloadStream br headers = do
|
||||||
|
let size = case M.lookup "Content-Length" headers of
|
||||||
|
Just x' -> case decimal $ decUTF8Safe x' of
|
||||||
|
Left _ -> 0
|
||||||
|
Right (r', _) -> r'
|
||||||
|
Nothing -> 0
|
||||||
|
|
||||||
|
mpb <- if progressBar
|
||||||
|
then Just <$> (liftIO $ newProgressBar defStyle 10 (Progress 0 size ()))
|
||||||
|
else pure Nothing
|
||||||
|
|
||||||
|
loop mpb
|
||||||
|
|
||||||
|
where
|
||||||
|
loop mpb = do
|
||||||
|
bs <- brRead br
|
||||||
|
if BS.length bs == 0 then pure () else do
|
||||||
|
void $ consumer bs
|
||||||
|
forM_ mpb $ \pb -> incProgress pb (BS.length bs)
|
||||||
|
loop mpb
|
||||||
|
|
||||||
|
|
||||||
|
getHead :: (MonadCatch m, MonadIO m)
|
||||||
|
=> URI
|
||||||
|
-> Excepts
|
||||||
|
'[HTTPStatusError, UnsupportedScheme]
|
||||||
|
m
|
||||||
|
(M.Map (CI ByteString) ByteString)
|
||||||
|
getHead uri' | scheme == "https" || scheme == "http" = head'
|
||||||
|
| otherwise = throwE UnsupportedScheme
|
||||||
|
|
||||||
|
where
|
||||||
|
scheme = view (uriSchemeL' % schemeBSL') uri'
|
||||||
|
head' =
|
||||||
|
liftE $ headInternal (T.unpack . decUTF8Safe . serializeURIRef' $ uri')
|
||||||
|
|
||||||
|
|
||||||
|
headInternal :: (MonadThrow m, MonadIO m)
|
||||||
|
=> String
|
||||||
|
-> Excepts
|
||||||
|
'[HTTPStatusError]
|
||||||
|
m
|
||||||
|
(M.Map (CI ByteString) ByteString)
|
||||||
|
headInternal uri' = lEM $ liftIO $ withConnection' action
|
||||||
|
where
|
||||||
|
action :: (MonadThrow m, MonadIO m)
|
||||||
|
=> Manager
|
||||||
|
-> m (Either HTTPStatusError (M.Map (CI ByteString) ByteString))
|
||||||
|
action m = do
|
||||||
|
request <- parseRequest ("HEAD " <> uri')
|
||||||
|
liftIO $ withResponse
|
||||||
|
request
|
||||||
|
m
|
||||||
|
(\r -> do
|
||||||
|
let scode = statusCode . responseStatus $ r
|
||||||
|
if
|
||||||
|
| scode >= 200 && scode < 300 -> do
|
||||||
|
let headers = responseHeaders r
|
||||||
|
pure $ Right $ M.fromList $ headers
|
||||||
|
| otherwise -> pure $ Left (HTTPStatusError scode)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
withConnection' :: (Manager -> IO a) -> IO a
|
||||||
|
withConnection' action = do
|
||||||
|
mg <- newManager $ opensslManagerSettings baselineContextSSL
|
||||||
|
withOpenSSL (action mg)
|
||||||
|
|
||||||
|
|
||||||
|
baselineContextSSL :: IO SSL.SSLContext
|
||||||
|
baselineContextSSL = withOpenSSL $ do
|
||||||
|
ctx <- SSL.context
|
||||||
|
SSL.contextSetDefaultCiphers ctx
|
||||||
|
#if defined(darwin_HOST_OS)
|
||||||
|
SSL.contextSetVerificationMode ctx SSL.VerifyNone
|
||||||
|
#elif defined(mingw32_HOST_OS)
|
||||||
|
SSL.contextSetVerificationMode ctx SSL.VerifyNone
|
||||||
|
#elif defined(freebsd_HOST_OS)
|
||||||
|
SSL.contextSetCAFile ctx "/usr/local/etc/ssl/cert.pem"
|
||||||
|
SSL.contextSetVerificationMode ctx $ SSL.VerifyPeer True True Nothing
|
||||||
|
#elif defined(openbsd_HOST_OS)
|
||||||
|
SSL.contextSetCAFile ctx "/etc/ssl/cert.pem"
|
||||||
|
SSL.contextSetVerificationMode ctx $ SSL.VerifyPeer True True Nothing
|
||||||
|
#else
|
||||||
|
fedora <- doesDirectoryExist [abs|/etc/pki/tls|]
|
||||||
|
if fedora
|
||||||
|
then do
|
||||||
|
SSL.contextSetCAFile ctx "/etc/pki/tls/certs/ca-bundle.crt"
|
||||||
|
else do
|
||||||
|
SSL.contextSetCADirectory ctx "/etc/ssl/certs"
|
||||||
|
SSL.contextSetVerificationMode ctx $ SSL.VerifyPeer True True Nothing
|
||||||
|
#endif
|
||||||
|
return ctx
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
{-# LANGUAGE DataKinds #-}
|
|
||||||
{-# LANGUAGE DeriveGeneric #-}
|
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
|
||||||
{-# LANGUAGE OverloadedStrings #-}
|
|
||||||
{-# LANGUAGE QuasiQuotes #-}
|
|
||||||
{-# LANGUAGE TemplateHaskell #-}
|
|
||||||
{-# LANGUAGE TypeApplications #-}
|
|
||||||
{-# LANGUAGE TypeFamilies #-}
|
|
||||||
|
|
||||||
|
|
||||||
module GHCup.Download.Utils where
|
|
||||||
|
|
||||||
|
|
||||||
import GHCup.Errors
|
|
||||||
import GHCup.Types.Optics
|
|
||||||
import GHCup.Types.JSON ( )
|
|
||||||
import GHCup.Utils.Prelude
|
|
||||||
|
|
||||||
import Control.Applicative
|
|
||||||
import Control.Monad
|
|
||||||
import Data.ByteString ( ByteString )
|
|
||||||
import Data.Maybe
|
|
||||||
import Haskus.Utils.Variant.Excepts
|
|
||||||
import Optics
|
|
||||||
import Prelude hiding ( abs
|
|
||||||
, readFile
|
|
||||||
, writeFile
|
|
||||||
)
|
|
||||||
import URI.ByteString
|
|
||||||
|
|
||||||
import qualified Data.Binary.Builder as B
|
|
||||||
import qualified Data.ByteString as BS
|
|
||||||
import qualified Data.ByteString.Lazy as L
|
|
||||||
|
|
||||||
|
|
||||||
-- | Extracts from a URI type: (https?, host, path+query, port)
|
|
||||||
uriToQuadruple :: Monad m
|
|
||||||
=> URI
|
|
||||||
-> Excepts
|
|
||||||
'[UnsupportedScheme]
|
|
||||||
m
|
|
||||||
(Bool, ByteString, ByteString, Maybe Int)
|
|
||||||
uriToQuadruple URI {..} = do
|
|
||||||
let scheme = view schemeBSL' uriScheme
|
|
||||||
|
|
||||||
host <-
|
|
||||||
preview (_Just % authorityHostL' % hostBSL') uriAuthority
|
|
||||||
?? UnsupportedScheme
|
|
||||||
|
|
||||||
https <- if
|
|
||||||
| scheme == "https" -> pure True
|
|
||||||
| scheme == "http" -> pure False
|
|
||||||
| otherwise -> throwE UnsupportedScheme
|
|
||||||
|
|
||||||
let queryBS =
|
|
||||||
BS.intercalate "&"
|
|
||||||
. fmap (\(x, y) -> encodeQuery x <> "=" <> encodeQuery y)
|
|
||||||
$ (queryPairs uriQuery)
|
|
||||||
port =
|
|
||||||
preview (_Just % authorityPortL' % _Just % portNumberL') uriAuthority
|
|
||||||
fullpath = if BS.null queryBS then uriPath else uriPath <> "?" <> queryBS
|
|
||||||
pure (https, host, fullpath, port)
|
|
||||||
where encodeQuery = L.toStrict . B.toLazyByteString . urlEncodeQuery
|
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ import Data.Versions
|
|||||||
import Data.Word8
|
import Data.Word8
|
||||||
import GHC.IO.Exception
|
import GHC.IO.Exception
|
||||||
import HPath
|
import HPath
|
||||||
import HPath.IO
|
import HPath.IO hiding ( hideError )
|
||||||
import Haskus.Utils.Variant.Excepts
|
import Haskus.Utils.Variant.Excepts
|
||||||
import Optics
|
import Optics
|
||||||
import Prelude hiding ( abs
|
import Prelude hiding ( abs
|
||||||
|
|||||||
@@ -14,17 +14,20 @@ import Control.Exception ( evaluate )
|
|||||||
import Control.Exception.Safe
|
import Control.Exception.Safe
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
import Control.Monad.Reader
|
import Control.Monad.Reader
|
||||||
|
import Control.Monad.Trans.State.Strict
|
||||||
import Data.ByteString ( ByteString )
|
import Data.ByteString ( ByteString )
|
||||||
import Data.Foldable
|
import Data.Foldable
|
||||||
import Data.Functor
|
import Data.Functor
|
||||||
import Data.IORef
|
import Data.IORef
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
import Data.Sequence ( Seq, (|>) )
|
||||||
import Data.Text ( Text )
|
import Data.Text ( Text )
|
||||||
import Data.Void
|
import Data.Void
|
||||||
|
import Data.Word8
|
||||||
import GHC.IO.Exception
|
import GHC.IO.Exception
|
||||||
import HPath
|
import HPath
|
||||||
import HPath.IO
|
import HPath.IO hiding ( hideError )
|
||||||
import Optics
|
import Optics hiding ((<|), (|>))
|
||||||
import System.Console.Pretty
|
import System.Console.Pretty
|
||||||
import System.Console.Regions
|
import System.Console.Regions
|
||||||
import System.IO.Error
|
import System.IO.Error
|
||||||
@@ -40,6 +43,7 @@ import Text.Regex.Posix
|
|||||||
|
|
||||||
|
|
||||||
import qualified Control.Exception as EX
|
import qualified Control.Exception as EX
|
||||||
|
import qualified Data.Sequence as Sq
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
import qualified Data.Text.Encoding as E
|
import qualified Data.Text.Encoding as E
|
||||||
import qualified System.Posix.Process.ByteString
|
import qualified System.Posix.Process.ByteString
|
||||||
@@ -53,6 +57,7 @@ import qualified "unix-bytestring" System.Posix.IO.ByteString
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- | Bool signals whether the regions should be cleaned.
|
-- | Bool signals whether the regions should be cleaned.
|
||||||
data StopThread = StopThread Bool
|
data StopThread = StopThread Bool
|
||||||
deriving Show
|
deriving Show
|
||||||
@@ -113,115 +118,140 @@ execLogged :: (MonadReader Settings m, MonadIO m, MonadThrow m)
|
|||||||
-> Maybe [(ByteString, ByteString)] -- ^ optional environment
|
-> Maybe [(ByteString, ByteString)] -- ^ optional environment
|
||||||
-> m (Either ProcessError ())
|
-> m (Either ProcessError ())
|
||||||
execLogged exe spath args lfile chdir env = do
|
execLogged exe spath args lfile chdir env = do
|
||||||
Settings{..} <- ask
|
Settings {..} <- ask
|
||||||
ldir <- liftIO ghcupLogsDir
|
ldir <- liftIO ghcupLogsDir
|
||||||
logfile <- (ldir </>) <$> parseRel (toFilePath lfile <> ".log")
|
logfile <- (ldir </>) <$> parseRel (toFilePath lfile <> ".log")
|
||||||
liftIO $ bracket (createFile (toFilePath logfile) newFilePerms) closeFd (action verbose)
|
liftIO $ bracket (createFile (toFilePath logfile) newFilePerms)
|
||||||
|
closeFd
|
||||||
|
(action verbose)
|
||||||
where
|
where
|
||||||
action verbose fd = do
|
action verbose fd = do
|
||||||
actionWithPipes $ \(stdoutRead, stdoutWrite) -> do
|
actionWithPipes $ \(stdoutRead, stdoutWrite) -> do
|
||||||
-- start the thread that logs to stdout in a region
|
-- start the thread that logs to stdout
|
||||||
done <- newEmptyMVar
|
pState <- newEmptyMVar
|
||||||
tid <-
|
done <- newEmptyMVar
|
||||||
forkIO
|
void
|
||||||
|
$ forkOS
|
||||||
$ EX.handle (\(_ :: StopThread) -> pure ())
|
$ EX.handle (\(_ :: StopThread) -> pure ())
|
||||||
$ EX.handle (\(_ :: IOException) -> pure ())
|
$ EX.handle (\(_ :: IOException) -> pure ())
|
||||||
$ flip finally (putMVar done ())
|
$ flip finally (putMVar done ())
|
||||||
$ (if verbose then tee fd stdoutRead else printToRegion fd stdoutRead 6)
|
$ (if verbose
|
||||||
|
then tee fd stdoutRead
|
||||||
|
else printToRegion fd stdoutRead 6 pState
|
||||||
|
)
|
||||||
|
|
||||||
-- fork our subprocess
|
-- fork the subprocess
|
||||||
pid <- SPPB.forkProcess $ do
|
pid <- SPPB.forkProcess $ do
|
||||||
void $ dupTo stdoutWrite stdOutput
|
void $ dupTo stdoutWrite stdOutput
|
||||||
void $ dupTo stdoutWrite stdError
|
void $ dupTo stdoutWrite stdError
|
||||||
closeFd stdoutWrite
|
|
||||||
closeFd stdoutRead
|
closeFd stdoutRead
|
||||||
|
closeFd stdoutWrite
|
||||||
|
|
||||||
-- execute the action
|
-- execute the action
|
||||||
maybe (pure ()) (changeWorkingDirectory . toFilePath) chdir
|
maybe (pure ()) (changeWorkingDirectory . toFilePath) chdir
|
||||||
SPPB.executeFile exe spath args env
|
void $ SPPB.executeFile exe spath args env
|
||||||
|
|
||||||
closeFd stdoutWrite
|
closeFd stdoutWrite
|
||||||
|
|
||||||
-- wait for the subprocess to finish
|
-- wait for the subprocess to finish
|
||||||
e <- SPPB.getProcessStatus True True pid >>= \case
|
e <- toProcessError exe args <$!> SPPB.getProcessStatus True True pid
|
||||||
i@(Just (SPPB.Exited _)) -> pure $ toProcessError exe args i
|
putMVar pState (either (const False) (const True) e)
|
||||||
i -> pure $ toProcessError exe args i
|
|
||||||
|
|
||||||
-- make sure the logging thread stops
|
|
||||||
case e of
|
|
||||||
Left _ -> EX.throwTo tid (StopThread False)
|
|
||||||
Right _ -> EX.throwTo tid (StopThread True)
|
|
||||||
takeMVar done
|
takeMVar done
|
||||||
|
|
||||||
closeFd stdoutRead
|
closeFd stdoutRead
|
||||||
|
|
||||||
pure e
|
pure e
|
||||||
|
|
||||||
tee fileFd fdIn = do
|
tee :: Fd -> Fd -> IO ()
|
||||||
flip finally (readTilEOF lineAction fdIn) -- make sure the last few lines don't get cut off
|
tee fileFd fdIn = readTilEOF lineAction fdIn
|
||||||
$ do
|
|
||||||
hideError eofErrorType $ readTilEOF lineAction fdIn
|
|
||||||
forever (threadDelay 5000)
|
|
||||||
|
|
||||||
where
|
where
|
||||||
|
lineAction :: ByteString -> IO ()
|
||||||
lineAction bs' = do
|
lineAction bs' = do
|
||||||
void $ SPIB.fdWrite fileFd (bs' <> "\n")
|
void $ SPIB.fdWrite fileFd (bs' <> "\n")
|
||||||
void $ SPIB.fdWrite stdOutput (bs' <> "\n")
|
void $ SPIB.fdWrite stdOutput (bs' <> "\n")
|
||||||
|
|
||||||
-- Reads fdIn and logs the output in a continous scrolling area
|
-- Reads fdIn and logs the output in a continous scrolling area
|
||||||
-- of 'size' terminal lines. Also writes to a log file.
|
-- of 'size' terminal lines. Also writes to a log file.
|
||||||
printToRegion fileFd fdIn size = do
|
printToRegion :: Fd -> Fd -> Int -> MVar Bool -> IO ()
|
||||||
ref <- newIORef ([] :: [ByteString])
|
printToRegion fileFd fdIn size pState = do
|
||||||
displayConsoleRegions $ do
|
void $ displayConsoleRegions $ do
|
||||||
rs <- sequence . replicate size . openConsoleRegion $ Linear
|
rs <-
|
||||||
flip finally (readTilEOF (lineAction ref rs) fdIn) -- make sure the last few lines don't get cut off
|
liftIO
|
||||||
|
. fmap Sq.fromList
|
||||||
|
. sequence
|
||||||
|
. replicate size
|
||||||
|
. openConsoleRegion
|
||||||
|
$ Linear
|
||||||
|
flip runStateT mempty
|
||||||
$ handle
|
$ handle
|
||||||
(\(StopThread b) -> do
|
(\(ex :: SomeException) -> do
|
||||||
when b (forM_ rs closeConsoleRegion)
|
ps <- liftIO $ takeMVar pState
|
||||||
EX.throw (StopThread b)
|
when (ps == True) (forM_ rs (liftIO . closeConsoleRegion))
|
||||||
|
throw ex
|
||||||
)
|
)
|
||||||
$ do
|
$ readTilEOF (lineAction rs) fdIn
|
||||||
hideError eofErrorType $ readTilEOF (lineAction ref rs) fdIn
|
|
||||||
-- wait for explicit stop from the parent to signal what cleanup to run
|
|
||||||
forever (threadDelay 5000)
|
|
||||||
|
|
||||||
where
|
where
|
||||||
-- action to perform line by line
|
-- action to perform line by line
|
||||||
-- TODO: do this with vty for efficiency
|
-- TODO: do this with vty for efficiency
|
||||||
lineAction ref rs bs' = do
|
lineAction :: (MonadMask m, MonadIO m)
|
||||||
modifyIORef' ref (swapRegs bs')
|
=> Seq ConsoleRegion
|
||||||
regs <- readIORef ref
|
-> ByteString
|
||||||
void $ SPIB.fdWrite fileFd (bs' <> "\n")
|
-> StateT (Seq ByteString) m ()
|
||||||
forM (zip regs rs) $ \(bs, r) -> do
|
lineAction rs = \bs' -> do
|
||||||
setConsoleRegion r $ do
|
void $ liftIO $ SPIB.fdWrite fileFd (bs' <> "\n")
|
||||||
w <- consoleWidth
|
modify (swapRegs bs')
|
||||||
return
|
regs <- get
|
||||||
. T.pack
|
liftIO $ forM_ (Sq.zip regs rs) $ \(bs, r) -> setConsoleRegion r $ do
|
||||||
. color Blue
|
w <- consoleWidth
|
||||||
. T.unpack
|
return
|
||||||
. decUTF8Safe
|
. T.pack
|
||||||
. trim w
|
. color Blue
|
||||||
. (\b -> "[ " <> toFilePath lfile <> " ] " <> b)
|
. T.unpack
|
||||||
$ bs
|
. decUTF8Safe
|
||||||
|
. trim w
|
||||||
|
. (\b -> "[ " <> toFilePath lfile <> " ] " <> b)
|
||||||
|
$ bs
|
||||||
|
|
||||||
swapRegs bs regs | length regs < size = regs ++ [bs]
|
swapRegs :: a -> Seq a -> Seq a
|
||||||
| otherwise = tail regs ++ [bs]
|
swapRegs bs = \regs -> if
|
||||||
|
| Sq.length regs < size -> regs |> bs
|
||||||
|
| otherwise -> Sq.drop 1 regs |> bs
|
||||||
|
|
||||||
-- trim output line to terminal width
|
-- trim output line to terminal width
|
||||||
trim w bs | BS.length bs > w && w > 5 = BS.take (w - 4) bs <> "..."
|
trim :: Int -> ByteString -> ByteString
|
||||||
| otherwise = bs
|
trim w = \bs -> if
|
||||||
|
| BS.length bs > w && w > 5 -> BS.take (w - 4) bs <> "..."
|
||||||
|
| otherwise -> bs
|
||||||
|
|
||||||
-- read an entire line from the file descriptor (removes the newline char)
|
-- read an entire line from the file descriptor (removes the newline char)
|
||||||
readLine fd' = do
|
readLine :: MonadIO m => Fd -> ByteString -> m (ByteString, ByteString)
|
||||||
bs <- SPIB.fdRead fd' 1
|
readLine fd = go
|
||||||
if
|
where
|
||||||
| bs == "\n" -> pure ""
|
go inBs = do
|
||||||
| bs == "" -> pure ""
|
bs <-
|
||||||
| otherwise -> fmap (bs <>) $ readLine fd'
|
liftIO
|
||||||
|
$ handleIO (\e -> if isEOFError e then pure "" else ioError e)
|
||||||
|
$ SPIB.fdRead fd 512
|
||||||
|
let nbs = BS.append inBs bs
|
||||||
|
(line, rest) = BS.span (/= _lf) nbs
|
||||||
|
if
|
||||||
|
| BS.length rest /= 0 -> pure (line, BS.tail rest)
|
||||||
|
| BS.length line == 0 -> pure (mempty, mempty)
|
||||||
|
| otherwise -> (\(l, r) -> (line <> l, r)) <$!> go mempty
|
||||||
|
|
||||||
readTilEOF action' fd' = do
|
readTilEOF :: MonadIO m => (ByteString -> m a) -> Fd -> m ()
|
||||||
bs <- readLine fd'
|
readTilEOF ~action' fd' = go mempty
|
||||||
void $ action' bs
|
where
|
||||||
readTilEOF action' fd'
|
go bs' = do
|
||||||
|
(bs, rest) <- readLine fd' bs'
|
||||||
|
if
|
||||||
|
| BS.length bs == 0 -> liftIO
|
||||||
|
$ ioError (mkIOError eofErrorType "" Nothing Nothing)
|
||||||
|
| otherwise -> do
|
||||||
|
void $ action' bs
|
||||||
|
go rest
|
||||||
|
|
||||||
|
|
||||||
-- | Capture the stdout and stderr of the given action, which
|
-- | Capture the stdout and stderr of the given action, which
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
|
{-# OPTIONS_GHC -Wno-orphans #-}
|
||||||
|
|
||||||
{-# LANGUAGE DataKinds #-}
|
{-# LANGUAGE DataKinds #-}
|
||||||
{-# LANGUAGE DeriveLift #-}
|
{-# LANGUAGE DeriveLift #-}
|
||||||
{-# LANGUAGE FlexibleContexts #-}
|
{-# LANGUAGE FlexibleContexts #-}
|
||||||
{-# LANGUAGE FlexibleInstances #-}
|
{-# LANGUAGE FlexibleInstances #-}
|
||||||
{-# LANGUAGE QuasiQuotes #-}
|
{-# LANGUAGE QuasiQuotes #-}
|
||||||
|
{-# LANGUAGE MultiParamTypeClasses #-}
|
||||||
|
{-# LANGUAGE UndecidableInstances #-}
|
||||||
{-# LANGUAGE ScopedTypeVariables #-}
|
{-# LANGUAGE ScopedTypeVariables #-}
|
||||||
{-# LANGUAGE TypeApplications #-}
|
{-# LANGUAGE TypeApplications #-}
|
||||||
{-# LANGUAGE TypeFamilies #-}
|
{-# LANGUAGE TypeFamilies #-}
|
||||||
@@ -13,8 +17,10 @@ module GHCup.Utils.Prelude where
|
|||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import Control.Exception.Safe
|
import Control.Exception.Safe
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
import Control.Monad.Base
|
||||||
import Control.Monad.IO.Class
|
import Control.Monad.IO.Class
|
||||||
import Control.Monad.Trans.Class ( lift )
|
import Control.Monad.Trans.Class ( lift )
|
||||||
|
import Control.Monad.Trans.Control
|
||||||
import Data.Bifunctor
|
import Data.Bifunctor
|
||||||
import Data.ByteString ( ByteString )
|
import Data.ByteString ( ByteString )
|
||||||
import Data.String
|
import Data.String
|
||||||
@@ -165,6 +171,11 @@ liftIOException errType ex =
|
|||||||
. lift
|
. lift
|
||||||
|
|
||||||
|
|
||||||
|
-- | Uses safe-exceptions.
|
||||||
|
hideError :: (MonadIO m, MonadCatch m) => IOErrorType -> m () -> m ()
|
||||||
|
hideError err = handleIO (\e -> if err == ioeGetErrorType e then pure () else liftIO . ioError $ e)
|
||||||
|
|
||||||
|
|
||||||
hideErrorDef :: [IOErrorType] -> a -> IO a -> IO a
|
hideErrorDef :: [IOErrorType] -> a -> IO a -> IO a
|
||||||
hideErrorDef errs def =
|
hideErrorDef errs def =
|
||||||
handleIO (\e -> if ioeGetErrorType e `elem` errs then pure def else ioError e)
|
handleIO (\e -> if ioeGetErrorType e `elem` errs then pure def else ioError e)
|
||||||
@@ -259,3 +270,40 @@ decUTF8Safe = E.decodeUtf8With E.lenientDecode
|
|||||||
|
|
||||||
decUTF8Safe' :: L.ByteString -> Text
|
decUTF8Safe' :: L.ByteString -> Text
|
||||||
decUTF8Safe' = TL.toStrict . TLE.decodeUtf8With E.lenientDecode
|
decUTF8Safe' = TL.toStrict . TLE.decodeUtf8With E.lenientDecode
|
||||||
|
|
||||||
|
|
||||||
|
instance MonadBaseControl b m => MonadBaseControl b (Excepts e m) where
|
||||||
|
type StM (Excepts e m) a = ComposeSt (Excepts e) m a
|
||||||
|
liftBaseWith = defaultLiftBaseWith
|
||||||
|
restoreM = defaultRestoreM
|
||||||
|
{-# INLINABLE liftBaseWith #-}
|
||||||
|
{-# INLINABLE restoreM #-}
|
||||||
|
|
||||||
|
instance MonadTransControl (Excepts e) where
|
||||||
|
type StT (Excepts e) a = VEither e a
|
||||||
|
liftWith f = veitherMToExcepts <$> liftM return $ f $ runE
|
||||||
|
restoreT = veitherMToExcepts
|
||||||
|
{-# INLINABLE liftWith #-}
|
||||||
|
{-# INLINABLE restoreT #-}
|
||||||
|
|
||||||
|
instance MonadBase b m => MonadBase b (Excepts e m) where
|
||||||
|
liftBase = liftBaseDefault
|
||||||
|
{-# INLINABLE liftBase #-}
|
||||||
|
|
||||||
|
instance MonadBaseControl (VEither e) (VEither e) where
|
||||||
|
type StM (VEither e) a = a
|
||||||
|
liftBaseWith f = f id
|
||||||
|
restoreM = return
|
||||||
|
{-# INLINABLE liftBaseWith #-}
|
||||||
|
{-# INLINABLE restoreM #-}
|
||||||
|
|
||||||
|
instance MonadBase (VEither e) (VEither e) where
|
||||||
|
liftBase = id
|
||||||
|
{-# INLINABLE liftBase #-}
|
||||||
|
|
||||||
|
|
||||||
|
veitherMToExcepts :: Monad m => m (VEither es a) -> Excepts es m a
|
||||||
|
veitherMToExcepts ma = do
|
||||||
|
ve <- lift ma
|
||||||
|
veitherToExcepts ve
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user