Skip to content

Commit 2da7e9b

Browse files
committed
Fix hook running on windows
1 parent e0f9507 commit 2da7e9b

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

src/Stack/Setup.hs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ import Stack.Types.Docker
9797
import Stack.Types.SourceMap
9898
import Stack.Types.Version
9999
import qualified System.Directory as D
100-
import System.Environment (getExecutablePath, lookupEnv, getEnvironment)
100+
import System.Environment (getExecutablePath, lookupEnv)
101101
import System.IO.Error (isPermissionError)
102102
import System.FilePath (searchPathSeparator)
103103
import qualified System.FilePath as FP
@@ -447,21 +447,18 @@ ensureCompilerAndMsys
447447
=> SetupOpts
448448
-> RIO env (CompilerPaths, ExtraDirs)
449449
ensureCompilerAndMsys sopts = do
450+
getSetupInfo' <- memoizeRef getSetupInfo
451+
mmsys2Tool <- ensureMsys sopts getSetupInfo'
452+
msysPaths <- maybe (pure Nothing) (fmap Just . extraDirs) mmsys2Tool
453+
450454
actual <- either throwIO pure $ wantedToActual $ soptsWantedCompiler sopts
451455
didWarn <- warnUnsupportedCompiler $ getGhcVersion actual
452456

453-
getSetupInfo' <- memoizeRef getSetupInfo
454457
(cp, ghcPaths) <- ensureCompiler sopts getSetupInfo'
455458

456459
warnUnsupportedCompilerCabal cp didWarn
457460

458-
mmsys2Tool <- ensureMsys sopts getSetupInfo'
459-
paths <-
460-
case mmsys2Tool of
461-
Nothing -> pure ghcPaths
462-
Just msys2Tool -> do
463-
msys2Paths <- extraDirs msys2Tool
464-
pure $ ghcPaths <> msys2Paths
461+
let paths = maybe ghcPaths (ghcPaths <>) msysPaths
465462
pure (cp, paths)
466463

467464
-- | See <https://github.com/commercialhaskell/stack/issues/4246>
@@ -613,7 +610,9 @@ ensureCompiler sopts getSetupInfo' = do
613610
wc <- either throwIO (pure . whichCompiler) $ wantedToActual wanted
614611

615612
hook <- ghcInstallHook
616-
hookIsExecutable <- handleIO (\_ -> pure False) $ executable <$> getPermissions hook
613+
hookIsExecutable <- handleIO (\_ -> pure False) $ if osIsWindows
614+
then doesFileExist hook -- can't really detect executable on windows, only file extension
615+
else executable <$> getPermissions hook
617616

618617
Platform expectedArch _ <- view platformL
619618

@@ -664,10 +663,10 @@ runGHCInstallHook
664663
runGHCInstallHook sopts hook = do
665664
logDebug "Getting hook installed compiler version"
666665
let wanted = soptsWantedCompiler sopts
667-
curEnv <- Map.fromList . map (T.pack *** T.pack) <$> liftIO getEnvironment
668-
let newEnv = Map.union (wantedCompilerToEnv wanted) curEnv
669-
pCtx <- mkProcessContext newEnv
670-
(exit, out) <- withProcessContext pCtx $ proc "sh" [toFilePath hook] readProcessStdout
666+
menv0 <- view processContextL
667+
menv <- mkProcessContext (Map.union (wantedCompilerToEnv wanted) $
668+
removeHaskellEnvVars (view envVarsL menv0))
669+
(exit, out) <- withProcessContext menv $ proc "sh" [toFilePath hook] readProcessStdout
671670
case exit of
672671
ExitSuccess -> do
673672
let ghcPath = stripNewline . TL.unpack . TL.decodeUtf8With T.lenientDecode $ out

test/integration/tests/ghc-install-hooks/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ import StackTest
44
import Control.Monad (unless)
55

66
main :: IO ()
7-
main = unless isWindows $ rawSystem "bash" ["run.sh"] >>= throwIO
7+
main = rawSystem "sh" ["run.sh"] >>= throwIO

test/integration/tests/ghc-install-hooks/files/run.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env sh
22

3-
set -exuo pipefail
3+
set -exu
44

55
stack_bin=$("$STACK_EXE" path --resolver ghc-8.6.5 --compiler-bin)
66

77
export STACK_ROOT=$(pwd)/fake-root
88

99
mkdir -p "${STACK_ROOT}"/hooks
1010

11-
echo "echo ${stack_bin}/ghc" > "${STACK_ROOT}"/hooks/ghc-install.sh
11+
echo "echo '${stack_bin}/ghc'" > "${STACK_ROOT}"/hooks/ghc-install.sh
1212
chmod +x "${STACK_ROOT}"/hooks/ghc-install.sh
1313

1414
"$STACK_EXE" --no-install-ghc --resolver ghc-8.6.5 ghc -- --info

0 commit comments

Comments
 (0)