Commit 79bc4c9d authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Add comments, do minor refactoring.

parent 91a8babe
......@@ -64,11 +64,13 @@ instance ShowArgs MultiPackageData where
HsArgs path -> ("HC_OPTS" , path, "" )
CcArgs path -> ("CC_OPTS" , path, "" )
CSrcs path -> ("C_SRCS" , path, "" )
DepIncludeDirs path -> ("DEP_LIB_REL_DIRS", path, "" )
DepIncludeDirs path -> ("DEP_INCLUDE_DIRS_SINGLE_QUOTED"
, path, "")
fullKey = replaceSeparators '_' $ path ++ "_" ++ key
pkgData = path </> "package-data.mk"
unquote = dropWhile (== '\'') . dropWhileEnd (== '\'')
res <- askOracle $ PackageDataKey (pkgData, fullKey)
return $ words $ case res of
return $ map unquote $ words $ case res of
Nothing -> error $ "No key '" ++ key ++ "' in "
++ unifyPath pkgData ++ "."
Just "" -> defaultValue
......
......@@ -7,17 +7,6 @@ import Package.Library
import Package.Dependencies
import Targets
-- See Package.Base for definitions of basic types
packages :: [Package]
packages = map lib $ libraryPackages
where
lib name =
libraryPackage
name
[s | s <- [Stage0 ..], name `elem` (libraryPackagesInStage s)]
defaultSettings
-- Rule buildPackageX is defined in module Package.X
buildPackage :: Package -> TodoItem -> Rules ()
buildPackage = buildPackageData
......@@ -29,21 +18,25 @@ packageRules :: Rules ()
packageRules = do
-- TODO: control targets from command line arguments
forM_ packages $ \pkg @ (Package name path todo) -> do
-- The package list (targetPackages) is defined in Targets.hs
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.
-- TODO: Check BUILD_GHCI_LIB flag to decide if .o is needed
-- TODO: move this into buildPackage
action $ do
let pathDist = path </> dist
buildDir = pathDist </> "build"
[key] <- arg (PackageKey pathDist)
key <- showArg (PackageKey pathDist)
let oFile = buildDir </> "Hs" ++ key <.> "o"
ways' <- ways settings
aFiles <- forM ways' $ \way -> do
libFiles <- forM ways' $ \way -> do
extension <- libsuf way
return $ buildDir </> "libHs" ++ key <.> extension
need $ [oFile] ++ aFiles
need $ [oFile] ++ libFiles
-- Build rules for the package
buildPackage pkg todoItem
......@@ -5,7 +5,7 @@ module Package.Base (
module Util,
module Oracles,
Package (..), Settings (..), TodoItem (..),
defaultSettings, libraryPackage,
defaultSettings, libraryPackage, standardLibrary,
commonCcArgs, commonLdArgs, commonCppArgs, commonCcWarninigArgs,
pathArgs, packageArgs, includeGhcArgs, pkgHsSources,
pkgDepHsObjects, pkgLibHsObjects, pkgCObjects,
......@@ -37,7 +37,11 @@ defaultSettings stage =
Settings mempty mempty mempty mempty mempty True (defaultWays stage)
-- Stage is the stage of the GHC that we use to build the package
-- FilePath is the directory to put the build results
-- FilePath is the directory to put the build results (relative to pkgPath)
-- The typical structure of that directory is:
-- * build/ : contains compiled object code
-- * doc/ : produced by haddock
-- * package-data.mk : contains output of ghc-cabal applied to package.cabal
-- Settings may be different for different combinations of Stage & FilePath
type TodoItem = (Stage, FilePath, Settings)
......@@ -59,6 +63,9 @@ libraryPackage name stages settings =
, settings stage)
| stage <- stages ]
standardLibrary :: String -> [Stage] -> Package
standardLibrary name stages = libraryPackage name stages defaultSettings
commonCcArgs :: Args
commonCcArgs = when Validating $ args ["-Werror", "-Wall"]
......
......@@ -48,7 +48,14 @@ configureArgs stage settings =
-- Prepare a given 'packaga-data.mk' file for parsing by readConfigFile:
-- 1) Drop lines containing '$'
-- For example, get rid of
-- libraries/Win32_dist-install_CMM_SRCS := $(addprefix cbits/,$(notdir ...
-- Reason: we don't need them and we can't parse them.
-- 2) Replace '/' and '\' with '_' before '='
-- For example libraries/deepseq/dist-install_VERSION = 1.4.0.0
-- is replaced by libraries_deepseq_dist-install_VERSION = 1.4.0.0
-- Reason: Shake's built-in makefile parser doesn't recognise slashes
postProcessPackageData :: FilePath -> Action ()
postProcessPackageData file = do
pkgData <- (filter ('$' `notElem`) . lines) <$> liftIO (readFile file)
......@@ -60,9 +67,8 @@ postProcessPackageData file = do
bootPkgConstraints :: Args
bootPkgConstraints = args $ do
forM (libraryPackagesInStage Stage0) $ \name -> do
let path = pkgPath $ libraryPackage name [Stage0] defaultSettings
baseName = takeBaseName name
forM (targetPackagesInStage Stage0) $ \pkg @ (Package name path _) -> do
let baseName = takeBaseName name
cabal = path </> baseName <.> "cabal"
need [cabal]
content <- lines <$> liftIO (readFile cabal)
......@@ -111,7 +117,9 @@ buildRule pkg @ (Package name path _) 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 </>) <$>
[ "package-data.mk"
, "haddock-prologue.txt"
......@@ -123,6 +131,8 @@ buildRule pkg @ (Package name path _) todo @ (stage, dist, settings) =
] &%> \_ -> do
need [cabal]
when (doesFileExist $ configure <.> "ac") $ need [configure]
-- GhcCabal will run the configure script, so we depend on it
-- We still don't know who build the configure script from configure.ac
run GhcCabal $ cabalArgs pkg todo
when (registerPackage settings) $
run (GhcPkg stage) $ ghcPkgArgs pkg todo
......@@ -133,10 +143,12 @@ 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.
need $ ["shake/src/Package/Data.hs"] ++ sourceDependecies
cabalList <- argList GhcCabal $ cabalArgs pkg todo
ghcPkgList <- argList (GhcPkg stage) $ ghcPkgArgs pkg todo
writeFileChanged out $ cabalList ++ "\n" ++ ghcPkgList
-- How to build package-data.mk using GhcCabal to process package.cabal
buildPackageData :: Package -> TodoItem -> Rules ()
buildPackageData = argListRule <> buildRule
module Targets (libraryPackages, libraryPackagesInStage) where
module Targets (targetPackages, targetPackagesInStage) where
import Base
import Package.Base
-- 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)
libraryPackagesInStage :: Stage -> [String]
libraryPackagesInStage Stage0 =
[ "bin-package-db"
, "binary"
, "Cabal/Cabal"
, "hoopl"
, "hpc"
, "transformers" ]
libraryPackagesInStage Stage1 =
libraryPackagesInStage Stage0 ++
[ "array"
, "bytestring"
, "containers"
, "deepseq"
, "directory"
, "filepath"
, "ghc-prim"
, "parallel"
, "pretty"
, "stm"
, "template-haskell" ]
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]
]
libraryPackagesInStage _ = []
targetPackagesInStage :: Stage -> [Package]
targetPackagesInStage stage = filter inStage targetPackages
where
inStage (Package _ _ todoItems) = any matchStage todoItems
matchStage (todoStage, _, _) = todoStage == stage
libraryPackages :: [String]
libraryPackages = nub $ concatMap libraryPackagesInStage [Stage0 ..]
-- Note [Cabal package weirdness]
-- Find out if we can move the contents to just Cabal/
-- What is Cabal/cabal-install? Do we need it?
......@@ -30,12 +30,16 @@ data WayUnit = Profiling
| Dynamic
deriving Eq
-- TODO: think about Booleans instead of a list of ways.
data Way = Way
{
tag :: String, -- e.g., "thr_p"
units :: [WayUnit] -- e.g., [Threaded, Profiling]
}
deriving Eq
instance Eq Way where
-- The tag is fully determined by the units
a == b = units a == units b
vanilla = Way "v" []
profiling = Way "p" [Profiling]
......@@ -43,6 +47,9 @@ logging = Way "l" [Logging]
parallel = Way "mp" [Parallel]
granSim = Way "gm" [GranSim]
isVanilla :: Way -> Bool
isVanilla = null . units
-- RTS only ways
-- TODO: do we need to define *only* these? Shall we generalise/simplify?
threaded = Way "thr" [Threaded]
......@@ -91,8 +98,8 @@ wayHcArgs (Way _ units) = args
args ["-ticky", "-DTICKY_TICKY"] ]
wayPrefix :: Way -> String
wayPrefix way | way == vanilla = ""
| otherwise = tag way ++ "_"
wayPrefix way | isVanilla way = ""
| otherwise = tag way ++ "_"
hisuf, osuf, hcsuf, obootsuf, ssuf :: Way -> String
osuf = (++ "o" ) . wayPrefix
......@@ -105,15 +112,21 @@ obootsuf = (++ "o-boot") . wayPrefix
-- from other suffixes. For example, in the profiling way it used to be
-- "_p.a" instead of ".p_a" which is how other suffixes work. I decided
-- to make all suffixes consistent: ".way_extension".
-- TODO: find out why we need version number in the dynamic suffix
-- The current theory: dynamic libraries are eventually placed in a single
-- giant directory in the load path of the dynamic linker, and hence we must
-- distinguish different versions of GHC. In contrast static libraries live
-- in their own per-package directory and hence do not need a unique filename.
-- We also need to respect the system's dynamic extension, e.g. .dll or .so.
-- TODO: fix the extension
libsuf :: Way -> Action String
libsuf way = do
let staticSuffix = wayPrefix $ dropDynamic way
if Dynamic `notElem` units way
then return $ staticSuffix ++ "a"
else do
extension <- showArg DynamicExtension
version <- showArg ProjectVersion
return $ staticSuffix ++ "-ghc" ++ version ++ extension
libsuf way | Dynamic `notElem` units way
= return $ wayPrefix way ++ "a" -- e.g., p_a
| otherwise
= 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
-- 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