Commit 8a860e62 authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Add remaining library packages to Targets.hs.

parent 2c7003a0
......@@ -19,6 +19,7 @@ import Oracles.Option
-- Ghc StageN, N > 0, is the one built on stage (N - 1)
-- GhcPkg Stage0 is the bootstrapping GhcPkg
-- GhcPkg StageN, N > 0, is the one built on stage 0 (TODO: need only Stage1?)
-- TODO: add Cpp and Haddock builders
data Builder = Ar
| Ld
| Alex
......
......@@ -19,15 +19,15 @@ packageRules = do
-- TODO: control targets from command line arguments
-- The package list (targetPackages) is defined in Targets.hs
forM_ targetPackages $ \pkg @ (Package name path todo) -> do
forM_ targetPackages $ \pkg @ (Package name path _ todo) -> do
forM_ todo $ \todoItem @ (stage, dist, settings) -> do
-- Want top .o and .a files for the pkg/todo combo
-- We build *only one* vanilla .o file (not sure why)
-- We build .way_a file for each way.
-- We build .way_a file for each way (or its dynamic version).
-- TODO: Check BUILD_GHCI_LIB flag to decide if .o is needed
-- TODO: move this into buildPackage
action $ do
action $ when (buildWhen settings) $ do
let pathDist = path </> dist
buildDir = pathDist </> "build"
key <- showArg (PackageKey pathDist)
......
......@@ -5,7 +5,7 @@ module Package.Base (
module Util,
module Oracles,
Package (..), Settings (..), TodoItem (..),
defaultSettings, libraryPackage, standardLibrary,
defaultSettings, standardLibrary, customLibrary, customNameLibrary,
commonCcArgs, commonLdArgs, commonCppArgs, commonCcWarninigArgs,
pathArgs, packageArgs,
includeGccArgs, includeGhcArgs, pkgHsSources,
......@@ -24,18 +24,28 @@ import qualified System.Directory as S
data Settings = Settings
{
customConfArgs :: Args,
customCcArgs :: Args,
customLdArgs :: Args,
customCppArgs :: Args,
customDllArgs :: Args,
registerPackage :: Bool,
ways :: Action [Way]
}
customConfArgs :: Args, -- custom args for configure
customCcArgs :: Args, -- custom args for Gcc
customLdArgs :: Args, -- custom args for Ld
customCppArgs :: Args, -- custom args for C preprocessor
customDllArgs :: Args, -- custom dll args
registerPackage :: Bool, -- do we need to call ghc-pkg update?
ways :: Action [Way], -- ways to build
buildWhen :: Condition -- skip the package if need be, e.g.
} -- don't build unix on Windows
defaultSettings :: Stage -> Settings
defaultSettings stage =
Settings mempty mempty mempty mempty mempty True (defaultWays stage)
defaultSettings stage = Settings
{
customConfArgs = mempty,
customCcArgs = mempty,
customLdArgs = mempty,
customCppArgs = mempty,
customDllArgs = mempty,
registerPackage = True,
ways = defaultWays stage,
buildWhen = return True
}
-- Stage is the stage of the GHC that we use to build the package
-- FilePath is the directory to put the build results (relative to pkgPath)
......@@ -49,23 +59,35 @@ type TodoItem = (Stage, FilePath, Settings)
-- pkgPath is the path to the source code relative to the root
data Package = Package
{
pkgName :: String, -- For example: "deepseq"
pkgPath :: FilePath, -- "libraries/deepseq"
pkgTodo :: [TodoItem] -- [(Stage1, "dist-install", defaultSettings)]
pkgName :: String, -- For example: "deepseq"
pkgPath :: FilePath, -- "libraries/deepseq"
pkgCabal :: FilePath, -- "libraries/deepseq/deepseq.cabal"
pkgTodo :: [TodoItem] -- [(Stage1, "dist-install", defaultSettings)]
}
libraryPackage :: String -> [Stage] -> (Stage -> Settings) -> Package
libraryPackage name stages settings =
libraryPackage :: String -> String -> [Stage] -> (Stage -> Settings) -> Package
libraryPackage name cabalName stages settings =
Package
name
(unifyPath $ "libraries" </> name)
(unifyPath $ "libraries" </> name </> cabalName <.> "cabal")
[ (stage
, if stage == Stage0 then "dist-boot" else "dist-install"
, settings stage)
| stage <- stages ]
standardLibrary :: String -> [Stage] -> Package
standardLibrary name stages = libraryPackage name stages defaultSettings
standardLibrary name stages = libraryPackage name name stages defaultSettings
customLibrary :: String -> [Stage] -> (Settings -> Settings) -> Package
customLibrary name stages traits = libraryPackage name name stages settings
where
settings = traits . defaultSettings
customNameLibrary :: String -> [Stage]
-> (String, Settings -> Settings) -> Package
customNameLibrary name stages (cabalName, traits) =
libraryPackage name cabalName stages (traits . defaultSettings)
commonCcArgs :: Args
commonCcArgs = when Validating $ args ["-Werror", "-Wall"]
......@@ -133,7 +155,8 @@ pkgDepHsObjects :: FilePath -> FilePath -> Way -> Action [FilePath]
pkgDepHsObjects path dist way = do
let pathDist = path </> dist
buildDir = pathDist </> "build"
dirs <- map (unifyPath . (path </>)) <$> args (SrcDirs pathDist)
dirs <- map (dropWhileEnd isPathSeparator . unifyPath . (path </>))
<$> args (SrcDirs pathDist)
fmap concat $ forM dirs $ \d ->
map (unifyPath . (buildDir ++) . (-<.> osuf way) . drop (length d))
<$> (findModuleFiles pathDist [d] [".hs", ".lhs"])
......@@ -210,5 +233,5 @@ argList = argListWithComment ""
-- Path to argument list for a given Package/Stage combination
argListPath :: FilePath -> Package -> Stage -> FilePath
argListPath dir (Package name _ _) stage =
argListPath dir (Package name _ _ _) stage =
dir </> takeBaseName name ++ " (stage " ++ show stage ++ ")" <.> "txt"
......@@ -11,7 +11,7 @@ suffixArgs way =
return ["-hisuf", hisuf way, "-osuf", osuf way, "-hcsuf", hcsuf way]
ghcArgs :: Package -> TodoItem -> Way -> [FilePath] -> FilePath -> Args
ghcArgs (Package _ path _) (stage, dist, _) way srcs result =
ghcArgs (Package _ path _ _) (stage, dist, _) way srcs result =
let pathDist = path </> dist
buildDir = unifyPath $ pathDist </> "build"
in args [ suffixArgs way
......@@ -29,7 +29,7 @@ ghcArgs (Package _ path _) (stage, dist, _) way srcs result =
, args ["-o", result] ]
gccArgs :: Package -> TodoItem -> [FilePath] -> FilePath -> Args
gccArgs (Package _ path _) (_, dist, _) srcs result =
gccArgs (Package _ path _ _) (_, dist, _) srcs result =
let pathDist = path </> dist
in args [ args $ CcArgs pathDist
, commonCcArgs
......@@ -45,7 +45,7 @@ compileC pkg todo @ (stage, _, _) deps obj = do
run (Gcc stage) $ gccArgs pkg todo srcs obj
compileHaskell :: Package -> TodoItem -> FilePath -> Way -> Action ()
compileHaskell pkg @ (Package _ path _) todo @ (stage, dist, _) obj way = do
compileHaskell pkg @ (Package _ path _ _) todo @ (stage, dist, _) obj way = do
let buildDir = unifyPath $ path </> dist </> "build"
-- TODO: keep only vanilla dependencies in 'haskell.deps'
deps <- args $ DependencyList (buildDir </> "haskell.deps") obj
......@@ -54,7 +54,7 @@ compileHaskell pkg @ (Package _ path _) todo @ (stage, dist, _) obj way = do
run (Ghc stage) $ ghcArgs pkg todo way srcs obj
buildRule :: Package -> TodoItem -> Rules ()
buildRule pkg @ (Package name path _) todo @ (stage, dist, _) =
buildRule pkg @ (Package name path _ _) todo @ (stage, dist, _) =
let buildDir = unifyPath $ path </> dist </> "build"
cDepFile = buildDir </> "c.deps"
in
......
......@@ -67,14 +67,13 @@ postProcessPackageData file = do
bootPkgConstraints :: Args
bootPkgConstraints = args $ do
forM (targetPackagesInStage Stage0) $ \pkg @ (Package name path _) -> do
let baseName = takeBaseName name
cabal = path </> baseName <.> "cabal"
forM (targetPackagesInStage Stage0) $ \pkg @ (Package _ _ cabal _) -> do
let depName = takeBaseName cabal
need [cabal]
content <- lines <$> liftIO (readFile cabal)
let versionLines = filter (("ersion:" `isPrefixOf`) . drop 1) content
case versionLines of
[versionLine] -> args ["--constraint", baseName ++ " == "
[versionLine] -> args ["--constraint", depName ++ " == "
++ dropWhile (not . isDigit) versionLine ]
_ -> redError $ "Cannot determine package version in '"
++ unifyPath cabal ++ "'."
......@@ -85,7 +84,7 @@ bootPackageDb = do
arg $ unifyPath $ "--package-db=" ++ top </> "libraries/bootstrapping.conf"
cabalArgs :: Package -> TodoItem -> Args
cabalArgs pkg @ (Package _ path _) todo @ (stage, dist, settings) = args
cabalArgs pkg @ (Package _ path _ _) todo @ (stage, dist, settings) = args
[ args ["configure", path, dist]
-- this is a positional argument, hence:
-- * if it is empty, we need to emit one empty string argument
......@@ -106,18 +105,16 @@ cabalArgs pkg @ (Package _ path _) todo @ (stage, dist, settings) = args
, with Happy ] -- TODO: reorder with's
ghcPkgArgs :: Package -> TodoItem -> Args
ghcPkgArgs (Package _ path _) (stage, dist, _) = args $
ghcPkgArgs (Package _ path _ _) (stage, dist, _) = args $
[ arg "update"
, arg "--force"
, arg $ unifyPath $ path </> dist </> "inplace-pkg-config"
, when (stage == Stage0) bootPackageDb ]
buildRule :: Package -> TodoItem -> Rules ()
buildRule pkg @ (Package name path _) todo @ (stage, dist, settings) =
buildRule pkg @ (Package name path cabal _) todo @ (stage, dist, settings) =
let pathDist = path </> dist
configure = path </> "configure"
cabal = path </> takeBaseName name <.> "cabal"
-- takeBaseName: see Note [Cabal package wierdness] in Targets.hs
in
-- All these files are produced by a single run of GhcCabal
(pathDist </>) <$>
......@@ -143,7 +140,7 @@ buildRule pkg @ (Package name path _) todo @ (stage, dist, settings) =
argListRule :: Package -> TodoItem -> Rules ()
argListRule pkg todo @ (stage, _, _) =
(argListPath argListDir pkg stage) %> \out -> do
-- TODO: depend on ALL source files.
-- TODO: depend on ALL source files
need $ ["shake/src/Package/Data.hs"] ++ sourceDependecies
cabalList <- argList GhcCabal $ cabalArgs pkg todo
ghcPkgList <- argList (GhcPkg stage) $ ghcPkgArgs pkg todo
......
......@@ -7,7 +7,7 @@ argListDir :: FilePath
argListDir = "shake/arg/buildPackageDependencies"
ghcArgs :: Package -> TodoItem -> Args
ghcArgs (Package name path _) (stage, dist, settings) =
ghcArgs (Package name path _ _) (stage, dist, settings) =
let pathDist = path </> dist
buildDir = unifyPath $ pathDist </> "build"
depFile = buildDir </> "haskell.deps"
......@@ -43,11 +43,11 @@ ghcArgs (Package name path _) (stage, dist, settings) =
-- TODO: handle custom $1_$2_MKDEPENDC_OPTS and
gccArgs :: FilePath -> Package -> TodoItem -> Args
gccArgs sourceFile (Package _ path _) (stage, dist, _) =
gccArgs sourceFile (Package _ path _ _) (stage, dist, _) =
let pathDist = path </> dist
buildDir = pathDist </> "build"
depFile = buildDir </> takeFileName sourceFile <.> "deps"
in args [ arg "-MM"
in args [ args ["-MM", "-E"] -- TODO: add a Cpp Builder instead
, args $ CcArgs pathDist
, commonCcArgs
, commonCcWarninigArgs
......@@ -57,7 +57,7 @@ gccArgs sourceFile (Package _ path _) (stage, dist, _) =
, arg $ unifyPath sourceFile ]
buildRule :: Package -> TodoItem -> Rules ()
buildRule pkg @ (Package name path _) todo @ (stage, dist, settings) = do
buildRule pkg @ (Package name path _ _) todo @ (stage, dist, settings) = do
let pathDist = path </> dist
buildDir = pathDist </> "build"
......
......@@ -19,7 +19,7 @@ ldArgs stage objs result = args [ args $ ConfLdLinkerArgs stage
, args objs ]
arRule :: Package -> TodoItem -> Rules ()
arRule pkg @ (Package _ path _) todo @ (stage, dist, _) =
arRule pkg @ (Package _ path _ _) todo @ (stage, dist, _) =
let buildDir = path </> dist </> "build"
in
(buildDir <//> "*a") %> \out -> do
......@@ -37,7 +37,7 @@ arRule pkg @ (Package _ path _) todo @ (stage, dist, _) =
need [argListPath argListDir pkg stage]
ldRule :: Package -> TodoItem -> Rules ()
ldRule pkg @ (Package name path _) todo @ (stage, dist, _) =
ldRule pkg @ (Package name path _ _) todo @ (stage, dist, _) =
let pathDist = path </> dist
buildDir = pathDist </> "build"
in
......@@ -55,7 +55,7 @@ ldRule pkg @ (Package name path _) todo @ (stage, dist, _) =
need [argListPath argListDir pkg stage]
argListRule :: Package -> TodoItem -> Rules ()
argListRule pkg @ (Package _ path _) todo @ (stage, dist, settings) =
argListRule pkg @ (Package _ path _ _) todo @ (stage, dist, settings) =
(argListPath argListDir pkg stage) %> \out -> do
need $ ["shake/src/Package/Library.hs"] ++ sourceDependecies
cObjsV <- pkgCObjects path dist vanilla
......
module Targets (targetPackages, targetPackagesInStage) where
{-# LANGUAGE NoImplicitPrelude #-}
module Targets (
targetPackages, targetPackagesInStage,
IntegerLibrary (..), integerLibrary,
buildHaddock
) where
import Package.Base
data IntegerLibrary = IntegerGmp | IntegerGmp2 | IntegerSimple
instance Show IntegerLibrary where
show library = case library of
IntegerGmp -> "integer-gmp"
IntegerGmp2 -> "integer-gmp2"
IntegerSimple -> "integer-simple"
integerLibrary :: IntegerLibrary
integerLibrary = IntegerGmp2
buildHaddock :: Bool
buildHaddock = True
-- These are the packages we build:
-- TODO: this should eventually be removed and replaced by the top-level
-- target, i.e. GHC (and perhaps, something else)
targetPackages :: [Package]
targetPackages = [ standardLibrary "array" [Stage1]
, standardLibrary "bin-package-db" [Stage0, Stage1]
, standardLibrary "binary" [Stage0, Stage1]
, standardLibrary "bytestring" [Stage1]
-- see Note [Cabal package weirdness]
, standardLibrary "Cabal/Cabal" [Stage0, Stage1]
, standardLibrary "containers" [Stage1]
, standardLibrary "deepseq" [Stage1]
, standardLibrary "directory" [Stage1]
, standardLibrary "filepath" [Stage1]
, standardLibrary "hoopl" [Stage0, Stage1]
, standardLibrary "hpc" [Stage0, Stage1]
, standardLibrary "ghc-prim" [Stage1]
, standardLibrary "parallel" [Stage1]
, standardLibrary "pretty" [Stage1]
, standardLibrary "stm" [Stage1]
, standardLibrary "template-haskell" [Stage1]
, standardLibrary "transformers" [Stage0, Stage1]
]
targetPackages =
[ standardLibrary "array" [ Stage1]
--, customLibrary "base" [ Stage1] baseConfArgs
, standardLibrary "bin-package-db" [Stage0, Stage1]
, standardLibrary "binary" [Stage0, Stage1]
, standardLibrary "bytestring" [ Stage1]
-- see Note [Cabal package weirdness]
, customNameLibrary "Cabal/Cabal" [Stage0, Stage1] cabalTraits
, standardLibrary "containers" [ Stage1]
, standardLibrary "deepseq" [ Stage1]
, standardLibrary "directory" [ Stage1]
, standardLibrary "filepath" [ Stage1]
, customLibrary "ghc-prim" [ Stage1] ghcPrimConfArgs
, standardLibrary "haskeline" [ Stage1]
, standardLibrary "hoopl" [Stage0, Stage1]
, standardLibrary "hpc" [Stage0, Stage1]
, customNameLibrary (show integerLibrary) [ Stage1] integerLibTraits
, standardLibrary "parallel" [ Stage1]
, standardLibrary "pretty" [ Stage1]
, standardLibrary "primitive" [ Stage1]
, standardLibrary "process" [ Stage1]
, standardLibrary "stm" [ Stage1]
, standardLibrary "template-haskell" [ Stage1]
, customLibrary "terminfo" [Stage0, Stage1] whenTerminfo
, standardLibrary "time" [ Stage1]
, standardLibrary "transformers" [Stage0, Stage1]
, customLibrary "unix" [ Stage1] whenUnix
, customLibrary "Win32" [ Stage1] whenWin32
, customLibrary "xhtml" [ Stage1] whenXhtml
]
baseConfArgs :: Settings -> Settings
baseConfArgs settings =
settings { customConfArgs = arg $ "--flags=" ++ show integerLibrary }
cabalTraits :: (String, Settings -> Settings)
cabalTraits = ("Cabal", id) -- change cabalName, keep the other settings intact
ghcPrimConfArgs :: Settings -> Settings
ghcPrimConfArgs settings =
settings { customConfArgs = arg "--flag=include-ghc-prim" }
integerLibTraits :: (String, Settings -> Settings)
integerLibTraits = (cabalName, traits)
where
cabalName = case integerLibrary of
IntegerGmp -> "integer-gmp"
IntegerGmp2 -> "integer-gmp" -- Indeed, why make life easier?
IntegerSimple -> "integer-simple"
traits settings = settings
{
customCcArgs = arg "-Ilibraries/integer-gmp2/gmp"
}
whenTerminfo :: Settings -> Settings
whenTerminfo settings = settings
{
buildWhen = do
os <- showArg TargetOs
not windowsHost && (os /= "ios")
}
whenUnix :: Settings -> Settings
whenUnix settings = settings { buildWhen = not windowsHost }
whenWin32 :: Settings -> Settings
whenWin32 settings = settings { buildWhen = windowsHost }
whenXhtml :: Settings -> Settings
whenXhtml settings = settings { buildWhen = return buildHaddock }
targetPackagesInStage :: Stage -> [Package]
targetPackagesInStage stage = filter inStage targetPackages
where
inStage (Package _ _ todoItems) = any matchStage todoItems
inStage (Package _ _ _ todoItems) = any matchStage todoItems
matchStage (todoStage, _, _) = todoStage == stage
-- Note [Cabal package weirdness]
......
......@@ -126,7 +126,8 @@ libsuf way | Dynamic `notElem` units way
= do extension <- showArg DynamicExtension -- e.g., .dll or .so
version <- showArg ProjectVersion -- e.g., 7.11.20141222
let suffix = wayPrefix $ dropDynamic way
return $ suffix ++ "-ghc" ++ version ++ extension -- e.g. p_-ghc7.11.20141222.dll
-- e.g., p_ghc7.11.20141222.dll (the result)
return $ suffix ++ "ghc" ++ version ++ extension
-- TODO: This may be slow -- optimise if overhead is significant.
dropDynamic :: Way -> Way
......
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