Commit 0bb27c83 authored by ijones's avatar ijones
Browse files

implemented in-place building. fixed related bug

** now the sources are built in-place, not moved to dist before being built
** the bug was that for executables, the build was not putting the .o and .hi files in the right place.
parent 81b7fae4
......@@ -44,8 +44,7 @@ module Distribution.PreProcess (preprocessSources, knownSuffixHandlers,
import Distribution.PreProcess.Unlit(plain, unlit)
import Distribution.Package (PackageDescription(..), BuildInfo(..), Executable(..))
import Distribution.Simple.Configure (LocalBuildInfo(..))
import Distribution.Simple.Utils (setupMessage,moveSources, pathJoin,
withLib, rawSystemPath, splitFilePath,
import Distribution.Simple.Utils (setupMessage, rawSystemPath, splitFilePath,
joinFilenameDir, joinExt, moduleToFilePath)
import System.Exit (ExitCode(..))
......@@ -70,21 +69,15 @@ type PPSuffixHandler
preprocessSources :: PackageDescription
-> LocalBuildInfo
-> [PPSuffixHandler] -- ^ preprocessors to try
-> FilePath {- ^ Directory to put preprocessed
sources in -}
-> IO ()
preprocessSources pkg_descr _ handlers pref =
preprocessSources pkg_descr _ handlers =
do
setupMessage "Preprocessing" pkg_descr
-- preprocess all sources before moving them
allSources <- findAllSourceFiles pkg_descr [a | (a, _, _) <- knownSuffixHandlers]
sequence [dispatchPP src handlers | src <- allSources] -- FIX: output errors?
-- move sources into place
withLib pkg_descr $ \lib ->
moveSources (hsSourceDir lib) (pathJoin [pref, hsSourceDir lib]) (modules lib) ["hs","lhs"]
sequence_ [ moveSources (hsSourceDir exeBi) (pathJoin [pref, hsSourceDir exeBi]) (modules exeBi) ["hs","lhs"]
| Executable _ _ exeBi <- executables pkg_descr]
return ()
dispatchPP :: FilePath -> [ PPSuffixHandler ] -> IO ExitCode
dispatchPP p handlers
......
......@@ -79,7 +79,7 @@ build :: FilePath -- ^Build location
-> PackageDescription -> LocalBuildInfo -> IO ()
build pref pkg_descr lbi = do
createIfNotExists True pref
preprocessSources pkg_descr lbi knownSuffixHandlers pref
preprocessSources pkg_descr lbi knownSuffixHandlers
setupMessage "Building" pkg_descr
case compilerFlavor (compiler lbi) of
GHC -> buildGHC pref pkg_descr lbi
......@@ -107,12 +107,13 @@ buildGHC pref pkg_descr lbi = do
unless pkgConfExists $ writeFile pkgConf "[]\n"
-- Build lib
withLib pkg_descr $ \buildInfo' -> do
createIfNotExists True (pathJoin [pref, hsSourceDir buildInfo'])
let args = ["-package-conf", pkgConf,
"-package-name", pkgName (package pkg_descr),
"-odir", pathJoin [pref, hsSourceDir buildInfo'],
"-hidir", pathJoin [pref, hsSourceDir buildInfo']
]
++ constructGHCCmdLine pref buildInfo' (packageDeps lbi)
++ constructGHCCmdLine buildInfo' (packageDeps lbi)
++ modules buildInfo'
unless (null (modules buildInfo')) $
rawSystemExit ghcPath args
......@@ -131,19 +132,22 @@ buildGHC pref pkg_descr lbi = do
rawSystemPathExit "ar" (["q", lib] ++ [pathJoin [pref, x] | x <- hObjs ++ cObjs])
-- build any executables
sequence_ [ do let args = ["-package-conf", pkgConf,
sequence_ [ do createIfNotExists True (pathJoin [pref, hsSourceDir exeBi])
let args = ["-package-conf", pkgConf,
"-odir", pathJoin [pref, hsSourceDir exeBi],
"-hidir", pathJoin [pref, hsSourceDir exeBi],
"-o", pathJoin [pref, hsSourceDir exeBi, exeName']
]
++ constructGHCCmdLine pref exeBi (exeDeps exeName' lbi)
++ [pathJoin [pref, hsSourceDir exeBi, modPath]]
++ constructGHCCmdLine exeBi (exeDeps exeName' lbi)
++ [pathJoin [hsSourceDir exeBi, modPath]]
rawSystemExit ghcPath args
| Executable exeName' modPath exeBi <- executables pkg_descr]
constructGHCCmdLine :: FilePath -> BuildInfo -> [PackageIdentifier] -> [String]
constructGHCCmdLine pref buildInfo' deps =
constructGHCCmdLine :: BuildInfo -> [PackageIdentifier] -> [String]
constructGHCCmdLine buildInfo' deps =
-- Unsupported extensions have already been checked by configure
let flags = snd $ extensionsToGHCFlag (extensions buildInfo')
in [ "--make", "-i" ++ pathJoin [pref, hsSourceDir buildInfo'] ]
in [ "--make", "-i" ++ hsSourceDir buildInfo' ]
++ nub (flags ++ [ opt | (GHC,opts) <- options buildInfo', opt <- opts ])
++ (concat [ ["-package", pkgName pkg] | pkg <- deps ])
......
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