From fe620835bed78b7d0920d150accab708734872e4 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 6 Jun 2022 20:18:10 +0200 Subject: [PATCH 1/6] Fix 'ghcup run' on windows, fixes #375 --- lib/GHCup/Prelude/Process/Windows.hs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/GHCup/Prelude/Process/Windows.hs b/lib/GHCup/Prelude/Process/Windows.hs index 17c75ac..fb9b255 100644 --- a/lib/GHCup/Prelude/Process/Windows.hs +++ b/lib/GHCup/Prelude/Process/Windows.hs @@ -206,6 +206,13 @@ exec :: MonadIO m -> Maybe [(String, String)] -- ^ optional environment -> m (Either ProcessError ()) exec exe args chdir env = do + -- https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/375 + forM_ (Map.fromList <$> env) $ \cEnv -> do + let paths = ["PATH", "Path"] + curPaths = (\x -> maybe [] splitSearchPath (Map.lookup x cEnv)) =<< paths + newPath = intercalate [searchPathSeparator] curPaths + setEnv "PATH" "" + setEnv "Path" newPath cp <- createProcessWithMingwPath ((proc exe args) { cwd = chdir, env = env }) exit_code <- liftIO $ withCreateProcess cp $ \_ _ _ p -> waitForProcess p pure $ toProcessError exe args exit_code From bf0e5b37ca6149b8f1794afe8f8d0734dc6000e9 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 6 Jun 2022 20:22:45 +0200 Subject: [PATCH 2/6] Test issue #375 --- .gitlab/script/ghcup_version.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.gitlab/script/ghcup_version.sh b/.gitlab/script/ghcup_version.sh index 6cabc69..5dfc8a9 100755 --- a/.gitlab/script/ghcup_version.sh +++ b/.gitlab/script/ghcup_version.sh @@ -97,6 +97,7 @@ rm -rf "${GHCUP_DIR}" eghcup --numeric-version eghcup install ghc ${GHC_VERSION} +eghcup unset ghc ${GHC_VERSION} 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}" ] @@ -105,9 +106,13 @@ eghcup install cabal ${CABAL_VERSION} [ "`$(eghcup whereis cabal ${CABAL_VERSION}) --numeric-version`" = "${CABAL_VERSION}" ] eghcup unset cabal "$GHCUP_BIN"/cabal --version && exit 1 || echo yes -eghcup set cabal ${CABAL_VERSION} -[ "`$(eghcup whereis cabal ${CABAL_VERSION}) --numeric-version`" = "${CABAL_VERSION}" ] + +# make sure no cabal is set when running 'ghcup run' to check that PATH propagages properly +# https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/375 [ "`eghcup run --cabal ${CABAL_VERSION} -- cabal --numeric-version`" = "${CABAL_VERSION}" ] +eghcup set cabal ${CABAL_VERSION} + +[ "`$(eghcup whereis cabal ${CABAL_VERSION}) --numeric-version`" = "${CABAL_VERSION}" ] if [ "${OS}" != "FREEBSD" ] ; then if [ "${ARCH}" = "64" ] ; then From 0ce9b5d35257046ab78388106165078d8b9f761a Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 6 Jun 2022 21:03:28 +0200 Subject: [PATCH 3/6] Fix test --- .gitlab/script/ghcup_version.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab/script/ghcup_version.sh b/.gitlab/script/ghcup_version.sh index 5dfc8a9..d6d03e2 100755 --- a/.gitlab/script/ghcup_version.sh +++ b/.gitlab/script/ghcup_version.sh @@ -101,6 +101,7 @@ eghcup unset ghc ${GHC_VERSION} 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}" ] +[ "`ghcup run --ghc ${GHC_VERSION} -- ghc -e 'Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)'`" = "`$(ghcup whereis ghc ${GHC_VERSION}) -e 'Control.Monad.join (Control.Monad.fmap System.IO.putStr System.Environment.getExecutablePath)'`" ] eghcup set ghc ${GHC_VERSION} eghcup install cabal ${CABAL_VERSION} [ "`$(eghcup whereis cabal ${CABAL_VERSION}) --numeric-version`" = "${CABAL_VERSION}" ] From aae3f31c50d2c27a5339b9bec106cbb0c6fb1578 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 6 Jun 2022 22:51:04 +0200 Subject: [PATCH 4/6] Fix bootstrap-haskell picking system cabal --- scripts/bootstrap/bootstrap-haskell | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/bootstrap/bootstrap-haskell b/scripts/bootstrap/bootstrap-haskell index 69f1528..6d8e2b5 100755 --- a/scripts/bootstrap/bootstrap-haskell +++ b/scripts/bootstrap/bootstrap-haskell @@ -133,6 +133,15 @@ _eghcup() { fi } +ecabal() { + edo _ecabal "$@" +} + +_ecabal() { + # shellcheck disable=SC2086 + "${GHCUP_BIN}/cabal" "$@" +} + _done() { echo echo "===============================================================================" @@ -537,7 +546,7 @@ adjust_cabal_config() { else cabal_bin="$HOME/AppData/Roaming/cabal/bin" fi - edo cabal user-config -a "extra-prog-path: $(cygpath -w "$GHCUP_BIN"), $(cygpath -w "$cabal_bin"), $(cygpath -w "$GHCUP_MSYS2"/usr/bin), $(cygpath -w "$GHCUP_MSYS2"/mingw64/bin)" -a "extra-include-dirs: $(cygpath -w "$GHCUP_MSYS2"/mingw64/include)" -a "extra-lib-dirs: $(cygpath -w "$GHCUP_MSYS2"/mingw64/lib)" -f init + ecabal user-config -a "extra-prog-path: $(cygpath -w "$GHCUP_BIN"), $(cygpath -w "$cabal_bin"), $(cygpath -w "$GHCUP_MSYS2"/usr/bin), $(cygpath -w "$GHCUP_MSYS2"/mingw64/bin)" -a "extra-include-dirs: $(cygpath -w "$GHCUP_MSYS2"/mingw64/include)" -a "extra-lib-dirs: $(cygpath -w "$GHCUP_MSYS2"/mingw64/lib)" -f init } ask_cabal_config_init() { @@ -763,7 +772,7 @@ if [ -z "${BOOTSTRAP_HASKELL_MINIMAL}" ] ; then do_cabal_config_init $ask_cabal_config_init_answer - edo cabal update --ignore-project + ecabal update --ignore-project else # don't install ghc and cabal case "${plat}" in MSYS*|MINGW*) From 565bb59f45883bf95c690aa7e53816b70f088c2a Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 6 Jun 2022 22:54:00 +0200 Subject: [PATCH 5/6] Fix ghcup_bootstrap test --- .gitlab/script/ghcup_bootstrap.sh | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/.gitlab/script/ghcup_bootstrap.sh b/.gitlab/script/ghcup_bootstrap.sh index 44e31a1..838f09e 100755 --- a/.gitlab/script/ghcup_bootstrap.sh +++ b/.gitlab/script/ghcup_bootstrap.sh @@ -6,20 +6,10 @@ set -eux mkdir -p "$CI_PROJECT_DIR"/.local/bin -ecabal() { - cabal "$@" -} - -eghcup() { - ghcup -v -c -s file://$(pwd)/ghcup-${JSON_VERSION}.yaml "$@" -} - git describe --always ### build -ecabal update - export BOOTSTRAP_HASKELL_NONINTERACTIVE=yes export BOOTSTRAP_HASKELL_GHC_VERSION=$GHC_VERSION export BOOTSTRAP_HASKELL_CABAL_VERSION=$CABAL_VERSION From d1c72cdff42689366754c00c7e6754842be60f1c Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 6 Jun 2022 23:02:21 +0200 Subject: [PATCH 6/6] Add --mingw-path switch to 'ghcup run' --- app/ghcup/GHCup/OptParse/Run.hs | 8 +++++++- lib/GHCup/Prelude/Process/Windows.hs | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/ghcup/GHCup/OptParse/Run.hs b/app/ghcup/GHCup/OptParse/Run.hs index 90938f6..4275839 100644 --- a/app/ghcup/GHCup/OptParse/Run.hs +++ b/app/ghcup/GHCup/OptParse/Run.hs @@ -18,6 +18,7 @@ import GHCup.Prelude import GHCup.Prelude.File #ifdef IS_WINDOWS import GHCup.Prelude.Process +import GHCup.Prelude.Process.Windows ( execNoMinGW ) #endif import GHCup.Prelude.Logger import GHCup.Prelude.String.QQ @@ -58,6 +59,7 @@ import qualified System.Posix.Process as SPP data RunOptions = RunOptions { runAppendPATH :: Bool , runInstTool' :: Bool + , runMinGWPath :: Bool , runGHCVer :: Maybe ToolVersion , runCabalVer :: Maybe ToolVersion , runHLSVer :: Maybe ToolVersion @@ -82,6 +84,8 @@ runOpts = (short 'a' <> long "append" <> help "Append bin/ dir to PATH instead of prepending (this means that e.g. a system installation may take precedence)") <*> switch (short 'i' <> long "install" <> help "Install the tool, if missing") + <*> switch + (short 'm' <> long "mingw-path" <> help "On windows, add mingw64 PATHs to environment (does nothing on unix)") <*> optional (option (eitherReader toolVersionEither) @@ -249,7 +253,9 @@ run RunOptions{..} runAppState leanAppstate runLogger = do void $ liftIO $ SPP.executeFile cmd True args (Just newEnv) pure ExitSuccess #else - r' <- runLeanRUN leanAppstate $ liftE $ lEM @_ @'[ProcessError] $ exec cmd args Nothing (Just newEnv) + r' <- if runMinGWPath + then runLeanRUN leanAppstate $ liftE $ lEM @_ @'[ProcessError] $ exec cmd args Nothing (Just newEnv) + else runLeanRUN leanAppstate $ liftE $ lEM @_ @'[ProcessError] $ execNoMinGW cmd args Nothing (Just newEnv) case r' of VRight _ -> pure ExitSuccess VLeft e -> do diff --git a/lib/GHCup/Prelude/Process/Windows.hs b/lib/GHCup/Prelude/Process/Windows.hs index fb9b255..8ccbde0 100644 --- a/lib/GHCup/Prelude/Process/Windows.hs +++ b/lib/GHCup/Prelude/Process/Windows.hs @@ -217,6 +217,25 @@ exec exe args chdir env = do exit_code <- liftIO $ withCreateProcess cp $ \_ _ _ p -> waitForProcess p pure $ toProcessError exe args exit_code +-- | Like 'exec', except doesn't add msys2 stuff to PATH. +execNoMinGW :: 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 ()) +execNoMinGW exe args chdir env = do + -- https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/375 + forM_ (Map.fromList <$> env) $ \cEnv -> do + let paths = ["PATH", "Path"] + curPaths = (\x -> maybe [] splitSearchPath (Map.lookup x cEnv)) =<< paths + newPath = intercalate [searchPathSeparator] curPaths + setEnv "PATH" "" + setEnv "Path" newPath + let cp = (proc exe args) { cwd = chdir, env = env } + exit_code <- liftIO $ withCreateProcess cp $ \_ _ _ p -> waitForProcess p + pure $ toProcessError exe args exit_code + -- | Thin wrapper around `executeFile`. execShell :: MonadIO m