Commit af3362ec authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Simplify smartCopySources using findFileWithExtension' and copyFiles

Previously it used moduleToFilePath2 which returns all the locations in which
a source file is found, in different search dirs and with different extensions
and it just collected all these locations. This is totally bogus since we do
not want to copy multiple source files per-module, only one of them could have
been used to be pre-processed into the final source module. This is one
example of how almost every use of moduleToFilePath is convoluted or broken.
This function it still used for too many different purposes, witness the two
flags to customise its behaviour which at all call sites are constants.
parent c6fdd93a
......@@ -412,25 +412,21 @@ smartCopySources :: Verbosity -- ^verbosity
-> Bool -- ^Preserve directory structure
-> IO ()
smartCopySources verbosity srcDirs targetDir sources searchSuffixes exitIfNone preserveDirs
= do createDirectoryIfMissingVerbose verbosity True targetDir
allLocations <- mapM moduleToFPErr sources
let copies = [(srcDir </> name,
= do allLocations <- mapM moduleToFPErr sources
let copies = [(srcDir,
if preserveDirs
then targetDir </> srcDir </> name
else targetDir </> name) |
(srcDir, name) <- concat allLocations]
-- Create parent directories for everything:
mapM_ (createDirectoryIfMissingVerbose verbosity True) $ nub $
[takeDirectory targetFile | (_, targetFile) <- copies]
-- Put sources into place:
sequence_ [copyFileVerbose verbosity srcFile destFile |
(srcFile, destFile) <- copies]
then srcDir </> name
else name)
| Just (srcDir, name) <- allLocations]
copyFiles verbosity targetDir copies
where moduleToFPErr m
= do p <- moduleToFilePath2 srcDirs m searchSuffixes
when (null p && exitIfNone)
(die ("Error: Could not find module: " ++ m
++ " with any suffix: " ++ (show searchSuffixes)))
return p
= do p <- findFileWithExtension' searchSuffixes srcDirs (dotToSep m)
case p of
Nothing | exitIfNone ->
die $ "Error: Could not find module: " ++ m
++ " with any suffix: " ++ show searchSuffixes
_ -> return p
createDirectoryIfMissingVerbose :: Verbosity -> Bool -> FilePath -> IO ()
createDirectoryIfMissingVerbose verbosity parentsToo dir = do
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment