Skip to content

Commit 78871b0

Browse files
authored
Merge pull request #11820 from haskell/revert-t10534
Revert "Merge pull request #10534
2 parents b3ca561 + 353dd57 commit 78871b0

2 files changed

Lines changed: 58 additions & 59 deletions

File tree

Cabal/src/Distribution/Simple/PreProcess.hs

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -290,65 +290,63 @@ preprocessFile
290290
-- ^ fail on missing file
291291
-> IO ()
292292
preprocessFile mbWorkDir searchLoc buildLoc forSDist baseFile verbosity builtinSuffixes handlers failOnMissing = do
293-
bsrcFiles <- findFileCwdWithExtension mbWorkDir builtinSuffixes (searchLoc ++ [buildAsSrcLoc]) baseFile
294-
case bsrcFiles of
295-
-- found a non-processable file in one of the source dirs
296-
Just _ -> do
297-
pure ()
293+
-- look for files in the various source dirs with this module name
294+
-- and a file extension of a known preprocessor
295+
psrcFiles <- findFileCwdWithExtension' mbWorkDir (map fst handlers) searchLoc baseFile
296+
case psrcFiles of
297+
-- no preprocessor file exists, look for an ordinary source file
298+
-- just to make sure one actually exists at all for this module.
299+
300+
-- Note [Dodgy build dirs for preprocessors]
301+
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
302+
-- By looking in the target/output build dir too, we allow
303+
-- source files to appear magically in the target build dir without
304+
-- any corresponding "real" source file. This lets custom Setup.hs
305+
-- files generate source modules directly into the build dir without
306+
-- the rest of the build system being aware of it (somewhat dodgy)
298307
Nothing -> do
299-
-- look for files in the various source dirs with this module name
300-
-- and a file extension of a known preprocessor
301-
psrcFiles <- findFileCwdWithExtension' mbWorkDir (map fst handlers) searchLoc baseFile
302-
case psrcFiles of
303-
-- no preprocessor file exists, look for an ordinary source file
304-
-- just to make sure one actually exists at all for this module.
305-
306-
-- Note [Dodgy build dirs for preprocessors]
307-
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
308-
-- By looking in the target/output build dir too, we allow
309-
-- source files to appear magically in the target build dir without
310-
-- any corresponding "real" source file. This lets custom Setup.hs
311-
-- files generate source modules directly into the build dir without
312-
-- the rest of the build system being aware of it (somewhat dodgy)
313-
Nothing ->
314-
when failOnMissing $ do
315-
dieWithException verbosity $
316-
CantFindSourceForPreProcessFile $
317-
"can't find source for "
318-
++ getSymbolicPath baseFile
319-
++ " in "
320-
++ intercalate ", " (map getSymbolicPath searchLoc)
321-
Just (psrcLoc, psrcRelFile) -> do
322-
let (srcStem, ext) = splitExtension $ getSymbolicPath psrcRelFile
323-
psrcFile = psrcLoc </> psrcRelFile
324-
pp =
325-
fromMaybe
326-
(error "Distribution.Simple.PreProcess: Just expected")
327-
(lookup (Suffix $ safeTail ext) handlers)
328-
-- Preprocessing files for 'sdist' is different from preprocessing
329-
-- for 'build'. When preprocessing for sdist we preprocess to
330-
-- avoid that the user has to have the preprocessors available.
331-
-- ATM, we don't have a way to specify which files are to be
332-
-- preprocessed and which not, so for sdist we only process
333-
-- platform independent files and put them into the 'buildLoc'
334-
-- (which we assume is set to the temp. directory that will become
335-
-- the tarball).
336-
-- TODO: eliminate sdist variant, just supply different handlers
337-
when (not forSDist || forSDist && platformIndependent pp) $ do
338-
-- look for existing pre-processed source file in the dest dir to
339-
-- see if we really have to re-run the preprocessor.
340-
ppsrcFiles <- findFileCwdWithExtension mbWorkDir builtinSuffixes [buildAsSrcLoc] baseFile
341-
recomp <- case ppsrcFiles of
342-
Nothing -> return True
343-
Just ppsrcFile ->
344-
i psrcFile `moreRecentFile` i ppsrcFile
345-
when recomp $ do
346-
let destDir = i buildLoc </> takeDirectory srcStem
347-
createDirectoryIfMissingVerbose verbosity True destDir
348-
runPreProcessorWithHsBootHack
349-
pp
350-
(psrcLoc, getSymbolicPath psrcRelFile)
351-
(buildLoc, srcStem <.> "hs")
308+
bsrcFiles <- findFileCwdWithExtension mbWorkDir builtinSuffixes (buildAsSrcLoc : searchLoc) baseFile
309+
case (bsrcFiles, failOnMissing) of
310+
(Nothing, True) ->
311+
dieWithException verbosity $
312+
CantFindSourceForPreProcessFile $
313+
"can't find source for "
314+
++ getSymbolicPath baseFile
315+
++ " in "
316+
++ intercalate ", " (map getSymbolicPath searchLoc)
317+
_ -> return ()
318+
-- found a pre-processable file in one of the source dirs
319+
Just (psrcLoc, psrcRelFile) -> do
320+
let (srcStem, ext) = splitExtension $ getSymbolicPath psrcRelFile
321+
psrcFile = psrcLoc </> psrcRelFile
322+
pp =
323+
fromMaybe
324+
(error "Distribution.Simple.PreProcess: Just expected")
325+
(lookup (Suffix $ safeTail ext) handlers)
326+
-- Preprocessing files for 'sdist' is different from preprocessing
327+
-- for 'build'. When preprocessing for sdist we preprocess to
328+
-- avoid that the user has to have the preprocessors available.
329+
-- ATM, we don't have a way to specify which files are to be
330+
-- preprocessed and which not, so for sdist we only process
331+
-- platform independent files and put them into the 'buildLoc'
332+
-- (which we assume is set to the temp. directory that will become
333+
-- the tarball).
334+
-- TODO: eliminate sdist variant, just supply different handlers
335+
when (not forSDist || forSDist && platformIndependent pp) $ do
336+
-- look for existing pre-processed source file in the dest dir to
337+
-- see if we really have to re-run the preprocessor.
338+
ppsrcFiles <- findFileCwdWithExtension mbWorkDir builtinSuffixes [buildAsSrcLoc] baseFile
339+
recomp <- case ppsrcFiles of
340+
Nothing -> return True
341+
Just ppsrcFile ->
342+
i psrcFile `moreRecentFile` i ppsrcFile
343+
when recomp $ do
344+
let destDir = i buildLoc </> takeDirectory srcStem
345+
createDirectoryIfMissingVerbose verbosity True destDir
346+
runPreProcessorWithHsBootHack
347+
pp
348+
(psrcLoc, getSymbolicPath psrcRelFile)
349+
(buildLoc, srcStem <.> "hs")
352350
where
353351
i = interpretSymbolicPath mbWorkDir -- See Note [Symbolic paths] in Distribution.Utils.Path
354352
buildAsSrcLoc :: SymbolicPath Pkg (Dir Source)

cabal-testsuite/PackageTests/AutogenModules/MainIsExe/cabal.out

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ Failed to build MainIsExe-0.1-inplace-Exe. The exception was:
1111
Error: [Cabal-7554]
1212
can't find source for MyDummy in ., cabal.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/MainIsExe-0.1/x/Exe/build/Exe/autogen, cabal.dist/work/./dist/build/<ARCH>/ghc-<GHCVER>/MainIsExe-0.1/x/Exe/build/global-autogen
1313
CallStack (from HasCallStack):
14-
dieWithException, called at src/Distribution/Simple/PreProcess.hs:315:13 in Cabal-3.17.0.0-inplace:Distribution.Simple.PreProcess
14+
dieWithException, called at src/Distribution/Simple/PreProcess.hs:311:11 in Cabal-3.17.0.0-inplace:Distribution.Simple.PreProcess
15+
1516

0 commit comments

Comments
 (0)