diff --git a/src/Stack/Setup.hs b/src/Stack/Setup.hs index fcf4d2046d..8e4f464ffe 100644 --- a/src/Stack/Setup.hs +++ b/src/Stack/Setup.hs @@ -91,7 +91,7 @@ import Stack.Types.Docker import Stack.Types.SourceMap import Stack.Types.Version import qualified System.Directory as D -import System.Environment (getExecutablePath, lookupEnv, getEnvironment) +import System.Environment (getExecutablePath, lookupEnv) import System.IO.Error (isPermissionError) import System.FilePath (searchPathSeparator) import qualified System.FilePath as FP @@ -441,21 +441,18 @@ ensureCompilerAndMsys => SetupOpts -> RIO env (CompilerPaths, ExtraDirs) ensureCompilerAndMsys sopts = do + getSetupInfo' <- memoizeRef getSetupInfo + mmsys2Tool <- ensureMsys sopts getSetupInfo' + msysPaths <- maybe (pure Nothing) (fmap Just . extraDirs) mmsys2Tool + actual <- either throwIO pure $ wantedToActual $ soptsWantedCompiler sopts didWarn <- warnUnsupportedCompiler $ getGhcVersion actual - getSetupInfo' <- memoizeRef getSetupInfo (cp, ghcPaths) <- ensureCompiler sopts getSetupInfo' warnUnsupportedCompilerCabal cp didWarn - mmsys2Tool <- ensureMsys sopts getSetupInfo' - paths <- - case mmsys2Tool of - Nothing -> pure ghcPaths - Just msys2Tool -> do - msys2Paths <- extraDirs msys2Tool - pure $ ghcPaths <> msys2Paths + let paths = maybe ghcPaths (ghcPaths <>) msysPaths pure (cp, paths) -- | See @@ -607,7 +604,9 @@ ensureCompiler sopts getSetupInfo' = do wc <- either throwIO (pure . whichCompiler) $ wantedToActual wanted hook <- ghcInstallHook - hookIsExecutable <- handleIO (\_ -> pure False) $ executable <$> getPermissions hook + hookIsExecutable <- if osIsWindows + then pure True -- can't really detect executable on windows, only file extension + else handleIO (\_ -> pure False) $ executable <$> getPermissions hook Platform expectedArch _ <- view platformL @@ -658,10 +657,10 @@ runGHCInstallHook runGHCInstallHook sopts hook = do logDebug "Getting hook installed compiler version" let wanted = soptsWantedCompiler sopts - curEnv <- Map.fromList . map (T.pack *** T.pack) <$> liftIO getEnvironment - let newEnv = Map.union (wantedCompilerToEnv wanted) curEnv - pCtx <- mkProcessContext newEnv - (exit, out) <- withProcessContext pCtx $ proc "sh" [toFilePath hook] readProcessStdout + menv0 <- view processContextL + menv <- mkProcessContext (Map.union (wantedCompilerToEnv wanted) $ + removeHaskellEnvVars (view envVarsL menv0)) + (exit, out) <- withProcessContext menv $ proc "sh" [toFilePath hook] readProcessStdout case exit of ExitSuccess -> do let ghcPath = stripNewline . TL.unpack . TL.decodeUtf8With T.lenientDecode $ out diff --git a/test/integration/tests/ghc-install-hooks/Main.hs b/test/integration/tests/ghc-install-hooks/Main.hs index 271c259449..491eb11761 100644 --- a/test/integration/tests/ghc-install-hooks/Main.hs +++ b/test/integration/tests/ghc-install-hooks/Main.hs @@ -4,4 +4,4 @@ import StackTest import Control.Monad (unless) main :: IO () -main = unless isWindows $ rawSystem "bash" ["run.sh"] >>= throwIO +main = rawSystem "sh" ["run.sh"] >>= throwIO diff --git a/test/integration/tests/ghc-install-hooks/files/run.sh b/test/integration/tests/ghc-install-hooks/files/run.sh index a27bee9420..0d4196566e 100755 --- a/test/integration/tests/ghc-install-hooks/files/run.sh +++ b/test/integration/tests/ghc-install-hooks/files/run.sh @@ -1,6 +1,6 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh -set -exuo pipefail +set -exu stack_bin=$("$STACK_EXE" path --resolver ghc-8.6.5 --compiler-bin) @@ -8,7 +8,7 @@ export STACK_ROOT=$(pwd)/fake-root mkdir -p "${STACK_ROOT}"/hooks -echo "echo ${stack_bin}/ghc" > "${STACK_ROOT}"/hooks/ghc-install.sh +echo "echo '${stack_bin}/ghc'" > "${STACK_ROOT}"/hooks/ghc-install.sh chmod +x "${STACK_ROOT}"/hooks/ghc-install.sh "$STACK_EXE" --no-install-ghc --resolver ghc-8.6.5 ghc -- --info