Commit 464bb2da authored by md9ms's avatar md9ms
Browse files

Update the build system to the new PackageDescription/BuildInfo architecture

Note that while the parser supports description files without library
building and with multiple executable building, the build system does
not (yet!)
parent 775107b9
......@@ -49,7 +49,7 @@ module Distribution.Simple.Build (
import Distribution.Misc (Extension(..), extensionsToNHCFlag, extensionsToGHCFlag)
import Distribution.Setup (CompilerFlavor(..), compilerFlavor, compilerPath)
import Distribution.Package (PackageDescription(..), showPackageId)
import Distribution.Package (PackageDescription(..), BuildInfo(..), showPackageId)
import Distribution.Simple.Configure (LocalBuildInfo(..), compiler)
import Distribution.Simple.Utils (rawSystemExit, setupMessage,
die, rawSystemPathExit,
......@@ -85,15 +85,16 @@ build pref pkg_descr lbi = do
-- |FIX: For now, the target must contain a main module :(
buildNHC :: PackageDescription -> LocalBuildInfo -> IO ()
buildNHC pkg_descr lbi = do
let (unsupported, flags) = extensionsToNHCFlag (extensions pkg_descr)
let (unsupported, flags) = extensionsToNHCFlag (maybe [] extensions (library pkg_descr))
when (not $ null unsupported)
(die $ "Unsupported extension for NHC: "
++ (concat $ intersperse ", " (map show unsupported)))
rawSystemExit (compilerPath (compiler lbi))
(["-nhc98"]
++ flags
++ [ opt | (NHC,opts) <- options pkg_descr, opt <- opts ]
++ allModules pkg_descr)
++ [ opt | (NHC,opts) <- maybe [] options (library pkg_descr),
opt <- opts ]
++ maybe [] modules (library pkg_descr))
-- |Building for GHC
buildGHC :: FilePath -> PackageDescription -> LocalBuildInfo -> IO ()
......@@ -106,27 +107,28 @@ buildGHC pref pkg_descr lbi = do
rawSystemExit (compilerPath (compiler lbi)) args
-- build any C sources
when (not (null (cSources pkg_descr))) $
rawSystemExit (compilerPath (compiler lbi)) (cSources pkg_descr)
when (not (null (maybe [] cSources (library pkg_descr)))) $
rawSystemExit (compilerPath (compiler lbi)) (maybe [] cSources (library pkg_descr))
-- now, build the library
let objs = map (++objsuffix) (map dotToSep (allModules pkg_descr))
let objs = map (++objsuffix) (map dotToSep (maybe [] modules (library pkg_descr)))
lib = mkLibName pref (showPackageId (package pkg_descr))
rawSystemPathExit "ar" (["q", lib] ++ [pathJoin [pref, x] | x <- objs])
constructGHCCmdLine :: FilePath -> PackageDescription -> LocalBuildInfo -> [String]
constructGHCCmdLine pref pkg_descr lbi =
let (unsupported, flags) = extensionsToGHCFlag (extensions pkg_descr)
let (unsupported, flags) = extensionsToGHCFlag (maybe [] extensions (library pkg_descr))
in if null unsupported
then [
"--make", "-odir " ++ pref, "-hidir " ++ pref,
"-package-name", showPackageId (package pkg_descr)
]
++ flags
++ [ opt | (GHC,opts) <- options pkg_descr, opt <- opts ]
++ [ opt | (GHC,opts) <- maybe [] options (library pkg_descr),
opt <- opts ]
++ [ "-i" ++ pref ]
++ [ "-package " ++ showPackageId pkg | pkg <- packageDeps lbi ]
++ allModules pkg_descr
++ maybe [] modules (library pkg_descr)
else error $ "Unsupported extension for GHC: "
++ (concat $ intersperse ", " (map show unsupported))
......@@ -149,10 +151,9 @@ preprocessSources :: PackageDescription
preprocessSources pkg_descr lbi pref =
do
setupMessage "Preprocessing" pkg_descr
putStrLn (hsSourceDir pkg_descr)
moveSources (hsSourceDir pkg_descr) pref
(allModules pkg_descr) (mainModules pkg_descr)
["hs","lhs"]
case library pkg_descr of
Just lib -> moveSources (hsSourceDir lib) pref (modules lib) ["hs","lhs"]
Nothing -> return ()
-- Todo: includes, includeDirs
......
......@@ -53,7 +53,7 @@ module Distribution.Simple.Configure (writePersistBuildConfig,
import Distribution.Misc(Dependency(..))
import Distribution.Setup(ConfigFlags,CompilerFlavor(..), Compiler(..))
import Distribution.Package(PackageDescription(..), emptyPackageDescription,
PackageIdentifier(..)
PackageIdentifier(..), BuildInfo(..)
)
import Distribution.Simple.Utils (die, setupMessage,
findBinary, splitFilenameDir)
......@@ -111,6 +111,7 @@ configure :: PackageDescription -> ConfigFlags -> IO LocalBuildInfo
configure pkg_descr (maybe_hc_flavor, maybe_hc_path, maybe_prefix)
= do
setupMessage "Configuring" pkg_descr
let lib = library pkg_descr
-- prefix
let prefix = case maybe_prefix of
Just path -> path
......@@ -123,7 +124,7 @@ configure pkg_descr (maybe_hc_flavor, maybe_hc_path, maybe_prefix)
message $ "Using compiler: " ++ p'
message $ "Using package tool: " ++ pkg
return LocalBuildInfo{prefix=prefix, compiler=compiler,
packageDeps=map buildDepToDep (buildDepends pkg_descr)}
packageDeps=map buildDepToDep (maybe [] buildDepends lib)}
-- |Converts build dependencies to real dependencies. FIX: doesn't
-- set any version information.
......
......@@ -18,7 +18,7 @@ module Distribution.Simple.GHCPackageConfig (
localPackageConfig
) where
import Distribution.Package (PackageDescription(..), showPackageId)
import Distribution.Package (PackageDescription(..), BuildInfo(..), showPackageId)
import Distribution.Simple.Configure (LocalBuildInfo(..))
import Distribution.Simple.Install (mkImportDir)
import Distribution.Simple.Utils(pathJoin)
......@@ -44,9 +44,9 @@ mkGHCPackageConfig pkg_descr lbi
import_dirs = [mkImportDir pkg_descr lbi],
library_dirs = [mkImportDir pkg_descr lbi],
hs_libraries = ["HS"++pkg_name],
extra_libraries = extraLibs pkg_descr,
include_dirs = includeDirs pkg_descr,
c_includes = includes pkg_descr,
extra_libraries = maybe [] extraLibs (library pkg_descr),
include_dirs = maybe [] includeDirs (library pkg_descr),
c_includes = maybe [] includes (library pkg_descr),
package_deps = map showPackageId (packageDeps lbi)
}
where
......
......@@ -50,7 +50,7 @@ module Distribution.Simple.Install (
#endif
) where
import Distribution.Package (PackageDescription(..), showPackageId)
import Distribution.Package (PackageDescription(..), BuildInfo(..), showPackageId)
import Distribution.Simple.Configure(LocalBuildInfo(..))
import Distribution.Simple.Utils(setupMessage, moveSources,
mkLibName, pathJoin,
......@@ -85,7 +85,7 @@ installGHC :: FilePath -- ^install location
-> FilePath -- ^Build location
-> PackageDescription -> IO ()
installGHC pref buildPref pkg_descr
= do moveSources buildPref pref (allModules pkg_descr) (mainModules pkg_descr) ["hi"]
= do moveSources buildPref pref (maybe [] modules (library pkg_descr)) ["hi"]
copyFile (mkLibName buildPref (showPackageId (package pkg_descr)))
(mkLibName pref (showPackageId (package pkg_descr)))
......@@ -94,7 +94,7 @@ installHugs :: FilePath -- ^Install location
-> FilePath -- ^Build location
-> PackageDescription -> IO ()
installHugs pref buildPref pkg_descr
= moveSources buildPref pref (allModules pkg_descr) (mainModules pkg_descr) ["lhs", "hs"]
= moveSources buildPref pref (maybe [] modules (library pkg_descr)) ["lhs", "hs"]
-- -----------------------------------------------------------------------------
-- Installation policies
......
......@@ -47,7 +47,7 @@ module Distribution.Simple.SrcDist (
#endif
) where
import Distribution.Package(PackageDescription(..), showPackageId)
import Distribution.Package(PackageDescription(..), BuildInfo(..), showPackageId)
import Distribution.Simple.Configure(LocalBuildInfo)
import Distribution.Simple.Utils(setupMessage, moveSources, die, pathJoin)
......@@ -64,19 +64,17 @@ import HUnit (Test)
sdist :: FilePath -- ^build prefix (temp dir)
-> FilePath -- ^TargetPrefix
-> PackageDescription -> LocalBuildInfo -> IO ()
sdist tmpDir targetPref
pkg_descr@PackageDescription{allModules=mods,
mainModules=mainMods,
hsSourceDir=srcDir
} _
= do
sdist tmpDir targetPref pkg_descr _ = do
setupMessage "Building source dist for" pkg_descr
ex <- doesDirectoryExist tmpDir
let tmpLoc1 = pathJoin [tmpDir, nameVersion pkg_descr, srcDir]
let tmpLoc2 = pathJoin [tmpDir, nameVersion pkg_descr]
when ex (die $ "Source distribution already in place. please move: " ++ tmpDir)
moveSources srcDir tmpLoc1 mods mainMods ["lhs", "hs"]
moveSources "" tmpLoc2 ["Setup"] [] ["lhs", "hs"]
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"]
Nothing -> return ()
let tmpLoc2 = pathJoin [tmpDir, nameVersion pkg_descr]
moveSources "" tmpLoc2 ["Setup"] ["lhs", "hs"]
system $ "tar --directory=" ++ tmpDir ++ " -zcf " ++
(pathJoin [targetPref, tarBallName pkg_descr])
++ " " ++ (nameVersion pkg_descr)
......
......@@ -275,14 +275,13 @@ moduleToPossiblePaths searchPref s possibleSuffixes
moveSources :: FilePath -- ^build prefix (location of objects)
-> FilePath -- ^Target directory
-> [String] -- ^Modules
-> [String] -- ^Main modules
-> [String] -- ^search suffixes
-> IO ()
moveSources pref _targetDir sources mains searchSuffixes
moveSources pref _targetDir sources searchSuffixes
= do let targetDir = maybeAddSep _targetDir
createIfNotExists True targetDir
-- Create parent directories for everything:
sourceLocs <- sequence $ map moduleToFPErr (sources ++ mains)
sourceLocs <- sequence $ map moduleToFPErr sources
let sourceLocsNoPref -- get rid of the prefix, for target location.
= if null pref then sourceLocs
else map (drop ((length pref) +1)) sourceLocs
......
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