Skip to content

Commit a564828

Browse files
authored
Merge pull request #5577 from commercialhaskell/better-find-executables
Use findExecutablesInDirectories during stack setup
2 parents 2a392ac + 1769e3b commit a564828

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ Bug fixes:
3131
* When building the sanity check for a new GHC install, make sure to clear
3232
`GHC_PACKAGE_PATH`.
3333
* Specifying GHC RTS flags in the `stack.yaml` no longer fails with an error. [#5568](https://github.com/commercialhaskell/stack/pull/5568)
34+
* `stack setup` will look in sandboxed directories for executables, not
35+
relying on `findExecutables. See
36+
[GHC issue 20074](https://gitlab.haskell.org/ghc/ghc/-/issues/20074)
3437

3538
## v2.7.1
3639

src/Stack/Setup.hs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,15 +667,26 @@ ensureSandboxedCompiler sopts getSetupInfo' = do
667667
WCGhc version -> pure ["ghc-" ++ versionString version, "ghc"]
668668
WCGhcGit{} -> pure ["ghc"]
669669
WCGhcjs{} -> throwIO GhcjsNotSupported
670+
671+
-- Previously, we used findExecutable to locate these executables. This was
672+
-- actually somewhat sloppy, as it could discover executables outside of the
673+
-- sandbox. This led to a specific issue on Windows with GHC 9.0.1. See
674+
-- https://gitlab.haskell.org/ghc/ghc/-/issues/20074. Instead, now, we look
675+
-- on the paths specified only.
670676
let loop [] = do
671677
logError $ "Looked for sandboxed compiler named one of: " <> displayShow names
672678
logError $ "Could not find it on the paths " <> displayShow (edBins paths)
673679
throwString "Could not find sandboxed compiler"
674680
loop (x:xs) = do
675-
res <- findExecutable x
681+
res <- liftIO $ D.findExecutablesInDirectories (map toFilePath (edBins paths)) x
676682
case res of
677-
Left _ -> loop xs
678-
Right y -> parseAbsFile y
683+
[] -> loop xs
684+
compiler:rest -> do
685+
unless (null rest) $ do
686+
logWarn "Found multiple candidate compilers:"
687+
for_ res $ \y -> logWarn $ "- " <> fromString y
688+
logWarn $ "This usually indicates a failed installation. Trying anyway with " <> fromString compiler
689+
parseAbsFile compiler
679690
compiler <- withProcessContext menv $ do
680691
compiler <- loop names
681692

0 commit comments

Comments
 (0)