@@ -290,65 +290,63 @@ preprocessFile
290290 -- ^ fail on missing file
291291 -> IO ()
292292preprocessFile 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 )
0 commit comments