Skip to content

Commit 8f5ec4e

Browse files
authored
Merge pull request #10991 from mpickering/wip/ppHsBootCWD
Take working directory into account in preprocessor hs-boot hack
2 parents bb61f80 + 825d13d commit 8f5ec4e

File tree

8 files changed

+69
-10
lines changed

8 files changed

+69
-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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
cabal-version: 3.0
2+
name: dep
3+
version: 0.1.0.0
4+
license: BSD-3-Clause
5+
author: sheaf
6+
maintainer: sheaf
7+
category: Testing
8+
build-type: Simple
9+
description: Testing the preprocessor hs-boot hack
10+
11+
library
12+
hs-source-dirs: src
13+
exposed-modules: DepA, DepB, DepC
14+
build-depends: base
15+
default-language: Haskell2010
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module DepA where
2+
3+
import {-# SOURCE #-} DepB
4+
5+
data A = A B
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module DepB where
2+
3+
data B
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module DepB where
2+
3+
import DepA
4+
5+
data B = B A
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module DepC where
2+
3+
import DepB
4+
5+
data C = C B
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Test.Cabal.Prelude
2+
3+
-- Test the hs-boot hack respects working directory
4+
main = setupTest . recordMode DoNotRecord $ withDirectory "dep" $ do
5+
void $ setup' "configure" []
6+
void $ setup' "build" []

changelog.d/pr-10991.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
synopsis: "Take --working-dir into account in runPreProcessorWithHsBootHack"
3+
packages: [Cabal]
4+
prs: 10991
5+
issues: [11000]
6+
---
7+
8+
The preprocessor hs-boot hack handles the situation in which a file to be
9+
preprocessed is supplied alongside an hs-boot file, e.g. Foo.x and Foo.hs-boot
10+
are given together.
11+
12+
This code now respects the --working-dir Cabal global argument. This fixes
13+
build failures of the form:
14+
15+
attempting to use module `Foo` (Foo.hs-boot) which is not loaded

0 commit comments

Comments
 (0)