Commit ec975325 authored by ijones's avatar ijones
Browse files

include unpreprocessed sources in tarball.

parent 0bb27c83
......@@ -38,7 +38,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.PreProcess (preprocessSources, knownSuffixHandlers,
PPSuffixHandler, PreProcessor)
ppSuffixes, PPSuffixHandler, PreProcessor)
where
import Distribution.PreProcess.Unlit(plain, unlit)
......@@ -74,8 +74,7 @@ preprocessSources :: PackageDescription
preprocessSources pkg_descr _ handlers =
do
setupMessage "Preprocessing" pkg_descr
-- preprocess all sources before moving them
allSources <- findAllSourceFiles pkg_descr [a | (a, _, _) <- knownSuffixHandlers]
allSources <- findAllSourceFiles pkg_descr (ppSuffixes knownSuffixHandlers)
sequence [dispatchPP src handlers | src <- allSources] -- FIX: output errors?
return ()
......@@ -105,11 +104,11 @@ findAllSourceFiles PackageDescription{executables=execs, library=lib} allSuffixe
libFiles <- case lib of
Just bi -> buildInfoSources bi allSuffixes
Nothing -> return []
return $ catMaybes ((concat exeFiles) ++ libFiles)
return $ ((concat exeFiles) ++ libFiles)
where buildInfoSources :: BuildInfo -> [String] -> IO [Maybe FilePath]
where buildInfoSources :: BuildInfo -> [String] -> IO [FilePath]
buildInfoSources BuildInfo{modules=mods, hsSourceDir=dir} suffixes
= sequence [moduleToFilePath dir modu suffixes | modu <- mods]
= sequence [moduleToFilePath dir modu suffixes | modu <- mods] >>= return . concat
-- ------------------------------------------------------------
......@@ -140,6 +139,10 @@ standardPP :: String -> PreProcessor
standardPP eName inFile outFile
= rawSystemPath eName ["-o" ++ outFile, inFile]
-- |Convinience function; get the suffixes of these preprocessors.
ppSuffixes :: [ PPSuffixHandler ] -> [String]
ppSuffixes h = [s | (s, _, _) <- h]
-- |Leave in unlit since some preprocessors can't handle literated
-- source?
knownSuffixHandlers :: [ PPSuffixHandler ]
......
......@@ -140,7 +140,7 @@ defaultMainNoRead pkg_descr
(_, args) <- parseSDistArgs args []
no_extra_flags args
localbuildinfo <- getPersistBuildConfig
sdist srcPref distPref pkg_descr localbuildinfo
sdist srcPref distPref [] pkg_descr localbuildinfo
RegisterCmd uInst -> do
(uInst, _, args) <- parseRegisterArgs uInst args []
......
......@@ -50,6 +50,7 @@ module Distribution.Simple.SrcDist (
import Distribution.Package(PackageDescription(..), BuildInfo(..), showPackageId)
import Distribution.Simple.Configure(LocalBuildInfo)
import Distribution.Simple.Utils(setupMessage, moveSources, die, pathJoin)
import Distribution.PreProcess (PPSuffixHandler, ppSuffixes, knownSuffixHandlers)
import Control.Monad(when)
import System.Cmd (system)
......@@ -63,15 +64,17 @@ import HUnit (Test)
-- on windows).
sdist :: FilePath -- ^build prefix (temp dir)
-> FilePath -- ^TargetPrefix
-> [PPSuffixHandler] -- ^ extra preprocessors (includes suffixes)
-> PackageDescription -> LocalBuildInfo -> IO ()
sdist tmpDir targetPref pkg_descr _ = do
sdist tmpDir targetPref pps pkg_descr _ = do
setupMessage "Building source dist for" pkg_descr
ex <- doesDirectoryExist tmpDir
when ex (die $ "Source distribution already in place. please move: " ++ tmpDir)
case library pkg_descr of
Just lib -> let srcDir = hsSourceDir lib
tmpLoc1 = pathJoin [tmpDir, nameVersion pkg_descr, srcDir]
in moveSources srcDir tmpLoc1 (modules lib) ["lhs", "hs"]
in moveSources srcDir tmpLoc1 (modules lib)
(ppSuffixes (knownSuffixHandlers ++ pps))
Nothing -> return ()
let tmpLoc2 = pathJoin [tmpDir, nameVersion pkg_descr]
moveSources "" tmpLoc2 ["Setup"] ["lhs", "hs"]
......
......@@ -329,12 +329,12 @@ maybeRemoveSep p = if isPathSeparator (last p) then init p else p
moduleToFilePath :: FilePath -- ^search location
-> String -- ^Module Name
-> [String] -- ^possible suffixes
-> IO (Maybe FilePath)
-> IO [FilePath]
moduleToFilePath pref s possibleSuffixes
= do let possiblePaths = moduleToPossiblePaths pref s possibleSuffixes
matchList <- sequence $ map (\x -> do y <- doesFileExist x; return (x, y)) possiblePaths
return $ listToMaybe [x | (x, True) <- matchList]
return [x | (x, True) <- matchList]
-- |Get the possible file paths based on this module name.
moduleToPossiblePaths :: FilePath -- ^search prefix
......@@ -363,7 +363,8 @@ moveSources pref _targetDir sources searchSuffixes
= do let targetDir = maybeAddSep _targetDir
createIfNotExists True targetDir
-- Create parent directories for everything:
sourceLocs <- sequence $ map moduleToFPErr sources
sourceLocs' <- sequence $ map moduleToFPErr sources
let sourceLocs = concat sourceLocs'
let sourceLocsNoPref -- get rid of the prefix, for target location.
= if null pref then sourceLocs
else map (drop ((length pref) +1)) sourceLocs
......@@ -376,11 +377,11 @@ moveSources pref _targetDir sources searchSuffixes
return ()
where moduleToFPErr m
= do p <- moduleToFilePath pref m searchSuffixes
when (isNothing p)
when (null p)
(putStrLn ("Error: Could not find module: " ++ m
++ " with any suffix: " ++ (show searchSuffixes))
>> exitWith (ExitFailure 1))
return $ fromJust p
return p
mkLibName :: FilePath -- ^file Prefix
......@@ -554,8 +555,8 @@ hunitTests
do mp1 <- moduleToFilePath "" "Distribution.Simple.Build" suffixes --exists
mp2 <- moduleToFilePath "" "Foo.Bar" suffixes -- doesn't exist
assertEqual "existing not found failed"
(Just "Distribution/Simple/Build.hs") mp1
assertEqual "not existing not nothing failed" Nothing mp2,
["Distribution/Simple/Build.hs"] mp1
assertEqual "not existing not nothing failed" [] mp2,
"moduleToPossiblePaths 1" ~: "failed" ~:
["Foo/Bar/Bang.hs","Foo/Bar/Bang.lhs"]
......
......@@ -13,8 +13,16 @@
-- preprocess them, and put them in place in the new
location. best solution, but not set up well for that right now,
since we concat together the entire filename (including module name)
** is cpp ever run yet?
** for a source tarball, do we want to include JUST the unpreprocessed sources?
** for a source tarball:?
- include the unpreprocessed sources...
- if there's a flag, --include-preprocessed-sources (or something
better) run the preprocessing phase and include both the
unpreprocessed and the preprocessed sources in the source tarball?
** if the config file isn't there, output a better error message.
** clarify description filename issues
- allow foo.hsproj?
......
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