Skip to content

Commit 16b4e2a

Browse files
committed
Take CWD into account in preprocessor hs-boot hack
This commit fixes an oversight in runPreProcessorWithHsBootHack, which did not correctly take into account the working directory. This could lead to situations in which we failed to apply the hack. Recall that this hack is for situations when one has both an hs-boot file and a file in need of preprocessing, such as: Foo.y Foo.hs-boot or Bar.hsc Bar.hs-boot Failing to apply the hack essentially meant that GHC would not be able to see the hs-boot file, which caused build failures.
1 parent ffaa46b commit 16b4e2a

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

Cabal/src/Distribution/Simple/PreProcess.hs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ preprocessFile mbWorkDir searchLoc buildLoc forSDist baseFile verbosity builtinS
345345
createDirectoryIfMissingVerbose verbosity True destDir
346346
runPreProcessorWithHsBootHack
347347
pp
348-
(getSymbolicPath $ psrcLoc, getSymbolicPath $ psrcRelFile)
349-
(getSymbolicPath $ buildLoc, srcStem <.> "hs")
348+
(psrcLoc, getSymbolicPath $ psrcRelFile)
349+
(buildLoc, srcStem <.> "hs")
350350
where
351351
i = interpretSymbolicPath mbWorkDir -- See Note [Symbolic paths] in Distribution.Utils.Path
352352
buildAsSrcLoc :: SymbolicPath Pkg (Dir Source)
@@ -361,20 +361,25 @@ preprocessFile mbWorkDir searchLoc buildLoc forSDist baseFile verbosity builtinS
361361
pp
362362
(inBaseDir, inRelativeFile)
363363
(outBaseDir, outRelativeFile) = do
364+
-- Preprocessors are expected to take into account the working
365+
-- directory, e.g. using runProgramCwd with a working directory
366+
-- computed with mbWorkDirLBI.
367+
-- Hence the use of 'getSymbolicPath' here.
364368
runPreProcessor
365369
pp
366-
(inBaseDir, inRelativeFile)
367-
(outBaseDir, outRelativeFile)
370+
(getSymbolicPath $ inBaseDir, inRelativeFile)
371+
(getSymbolicPath $ outBaseDir, outRelativeFile)
368372
verbosity
369373

370-
exists <- doesFileExist inBoot
371-
when exists $ copyFileVerbose verbosity inBoot outBoot
372-
where
374+
-- Here we interact directly with the file system, so we must
375+
-- interpret symbolic paths with respect to the working directory.
376+
let
377+
inFile = normalise (i inBaseDir </> inRelativeFile)
378+
outFile = normalise (i outBaseDir </> outRelativeFile)
373379
inBoot = replaceExtension inFile "hs-boot"
374380
outBoot = replaceExtension outFile "hs-boot"
375-
376-
inFile = normalise (inBaseDir </> inRelativeFile)
377-
outFile = normalise (outBaseDir </> outRelativeFile)
381+
exists <- doesFileExist inBoot
382+
when exists $ copyFileVerbose verbosity inBoot outBoot
378383

379384
-- ------------------------------------------------------------
380385

0 commit comments

Comments
 (0)