Skip to content

Commit

Permalink
Fix #6267 Avoid *.hi and *.o in stack-exe-src directory
Browse files Browse the repository at this point in the history
  • Loading branch information
mpilgrem committed Oct 2, 2023
1 parent 3b9c797 commit 483c4fb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ Major changes:

Behavior changes:

* Stack does not leave `*.hi` or `*.o` files in the `setup-exe-src` directory of
the Stack root, and deletes any corresponding to a `setup-<hash>.hs` or
`setup-shim-<hash>.hs` file, to avoid GHC issue
[#21250](https://gitlab.haskell.org/ghc/ghc/-/issues/21250).

Other enhancements:

* Add flag `--no-init` to Stack's `new` command to skip the initialisation of
Expand Down
31 changes: 28 additions & 3 deletions src/Stack/Build/Execute.hs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,12 @@ getSetupExe setupHs setupShimHs tmpdir = do
, toFilePath setupShimHs
, "-o"
, toFilePath tmpOutputPath
-- See https://github.com/commercialhaskell/stack/issues/6267. As
-- corrupt *.hi and/or *.o files can be problematic, we aim to
-- to leave none behind. This can be dropped when Stack drops
-- support for the problematic versions of GHC.
, "-no-keep-hi-files"
, "-no-keep-o-files"
]
compilerPath <- getCompilerPath
withWorkingDir (toFilePath tmpdir) $
Expand Down Expand Up @@ -462,16 +468,35 @@ withExecuteEnv bopts boptsCli baseConfigOpts locals globalPackages snapshotPacka
view stackRootL config </>
relDirSetupExeSrc
ensureDir setupSrcDir
setupFileName <- parseRelFile ("setup-" ++ simpleSetupHash ++ ".hs")
let setupStub = "setup-" ++ simpleSetupHash
setupFileName <- parseRelFile (setupStub ++ ".hs")
setupHiName <- parseRelFile (setupStub ++ ".hi")
setupOName <- parseRelFile (setupStub ++ ".o")
let setupHs = setupSrcDir </> setupFileName
setupHi = setupSrcDir </> setupHiName
setupO = setupSrcDir </> setupOName
setupHsExists <- doesFileExist setupHs
unless setupHsExists $ writeBinaryFileAtomic setupHs simpleSetupCode
setupShimFileName <-
parseRelFile ("setup-shim-" ++ simpleSetupHash ++ ".hs")
-- See https://github.com/commercialhaskell/stack/issues/6267. Remove any
-- historical *.hi or *.o files. This can be dropped when Stack drops
-- support for the problematic versions of GHC.
ignoringAbsence (removeFile setupHi)
ignoringAbsence (removeFile setupO)
let setupShimStub = "setup-shim-" ++ simpleSetupHash
setupShimFileName <- parseRelFile (setupShimStub ++ ".hs")
setupShimHiName <- parseRelFile (setupShimStub ++ ".hi")
setupShimOName <- parseRelFile (setupShimStub ++ ".o")
let setupShimHs = setupSrcDir </> setupShimFileName
setupShimHi = setupSrcDir </> setupShimHiName
setupShimO = setupSrcDir </> setupShimOName
setupShimHsExists <- doesFileExist setupShimHs
unless setupShimHsExists $
writeBinaryFileAtomic setupShimHs setupGhciShimCode
-- See https://github.com/commercialhaskell/stack/issues/6267. Remove any
-- historical *.hi or *.o files. This can be dropped when Stack drops
-- support for the problematic versions of GHC.
ignoringAbsence (removeFile setupShimHi)
ignoringAbsence (removeFile setupShimO)
setupExe <- getSetupExe setupHs setupShimHs tmpdir

cabalPkgVer <- view cabalVersionL
Expand Down

0 comments on commit 483c4fb

Please sign in to comment.