Commit 5a9b0a74 authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Refactor package-data oracles.

parent 7ffb2940
......@@ -38,10 +38,11 @@ instance ShowArgs PackageData where
Synopsis file -> ("SYNOPSIS" , file, "" )
CppOpts file -> ("CPP_OPTS" , file, "" )
HsOpts file -> ("HC_OPTS" , file, "" )
fullKey = replaceSeparators '_' $ takeDirectory file ++ "_" ++ key
file' = toStandard $ normaliseEx file
res <- askOracle $ PackageDataKey (file', fullKey)
fullKey = replaceSeparators '_' $ file ++ "_" ++ key
pkgData = file </> "package-data.mk"
res <- askOracle $ PackageDataKey (pkgData, fullKey)
return $ words $ case res of
Nothing -> error $ "No key '" ++ key ++ "' in " ++ file ++ "."
Nothing -> error $ "No key '" ++ key ++ "' in "
++ toStandard pkgData ++ "."
Just "" -> defaultValue
Just value -> value
......@@ -32,17 +32,12 @@ packageRules = do
forM_ packages $ \pkg @ (Package name path todo) -> do
forM_ todo $ \todoItem @ (stage, dist, settings) -> do
action $ putNormal $ "package = " ++ name ++ ", dist = " ++ dist
-- Want top .o and .a files for the pkg/todo combo
-- TODO: Check BUILD_GHCI_LIB flag to decide if .o is needed
action $ do
alwaysRerun
let buildDir = path </> dist </> "build"
pkgData = path </> dist </> "package-data.mk"
-- need [pkgData]
[key] <- arg (PackageKey pkgData)
putNormal $ "key = " ++ key
let pathDist = path </> dist
buildDir = pathDist </> "build"
[key] <- arg (PackageKey pathDist)
let oFile = buildDir </> "Hs" ++ key <.> "o"
ways' <- ways settings
aFiles <- forM ways' $ \way -> do
......
......@@ -79,7 +79,7 @@ pathArgs key path as =
map (\a -> key ++ toStandard (normaliseEx $ path </> a)) <$> arg as
packageArgs :: Stage -> FilePath -> Args
packageArgs stage pkgData = do
packageArgs stage pathDist = do
usePackageKey <- SupportsPackageKey || stage /= Stage0
arg [ arg "-hide-all-packages"
, arg "-no-user-package-db"
......@@ -88,56 +88,56 @@ packageArgs stage pkgData = do
arg "-package-db libraries/bootstrapping.conf"
, keyArgs usePackageKey ]
where
keyArgs True = productArgs "-this-package-key" (PackageKey pkgData) <>
productArgs "-package-key" (DepKeys pkgData)
keyArgs False = productArgs "-package-name" (PackageKey pkgData) <>
productArgs "-package" (Deps pkgData)
keyArgs True = productArgs "-this-package-key" (PackageKey pathDist) <>
productArgs "-package-key" (DepKeys pathDist)
keyArgs False = productArgs "-package-name" (PackageKey pathDist) <>
productArgs "-package" (Deps pathDist)
includeArgs :: FilePath -> FilePath -> Args
includeArgs path dist =
let pkgData = toStandard $ path </> dist </> "package-data.mk"
buildDir = toStandard $ path </> dist </> "build"
let pathDist = path </> dist
buildDir = toStandard $ pathDist </> "build"
in arg [ arg "-i"
, pathArgs "-i" path $ SrcDirs pkgData
, pathArgs "-i" path $ SrcDirs pathDist
, concatArgs ["-i", "-I"]
[buildDir, toStandard $ buildDir </> "autogen"]
, pathArgs "-I" path $ IncludeDirs pkgData
, pathArgs "-I" path $ IncludeDirs pathDist
, arg "-optP-include" -- TODO: Shall we also add -cpp?
, concatArgs "-optP" $
toStandard $ buildDir </> "autogen/cabal_macros.h" ]
pkgHsSources :: FilePath -> FilePath -> Action [FilePath]
pkgHsSources path dist = do
let pkgData = path </> dist </> "package-data.mk"
dirs <- map (path </>) <$> arg (SrcDirs pkgData)
findModuleFiles pkgData dirs [".hs", ".lhs"]
let pathDist = path </> dist
dirs <- map (path </>) <$> arg (SrcDirs pathDist)
findModuleFiles pathDist dirs [".hs", ".lhs"]
-- Find objects we depend on (we don't want to depend on split objects)
-- TODO: look for non-hs objects too
pkgDepObjects :: FilePath -> FilePath -> Way -> Action [FilePath]
pkgDepObjects path dist way = do
let pkgData = path </> dist </> "package-data.mk"
buildDir = path </> dist </> "build"
dirs <- map (normaliseEx . (path </>)) <$> arg (SrcDirs pkgData)
let pathDist = path </> dist
buildDir = pathDist </> "build"
dirs <- map (normaliseEx . (path </>)) <$> arg (SrcDirs pathDist)
fmap concat $ forM dirs $ \d ->
map (toStandard . (buildDir ++) . (-<.> osuf way) . drop (length d))
<$> (findModuleFiles pkgData [d] [".hs", ".lhs"])
<$> (findModuleFiles pathDist [d] [".hs", ".lhs"])
-- Find objects that go to library
pkgLibObjects :: FilePath -> FilePath -> Stage -> Way -> Action [FilePath]
pkgLibObjects path dist stage way = do
let pkgData = path </> dist </> "package-data.mk"
buildDir = path </> dist </> "build"
let pathDist = path </> dist
buildDir = pathDist </> "build"
split <- splitObjects stage
if split
then do
let suffixes = ["_" ++ osuf way ++ "_split//*"]
findModuleFiles pkgData [buildDir] suffixes
findModuleFiles pathDist [buildDir] suffixes
else pkgDepObjects path dist way
findModuleFiles :: FilePath -> [FilePath] -> [String] -> Action [FilePath]
findModuleFiles pkgData directories suffixes = do
modPaths <- map (replaceEq '.' pathSeparator) <$> arg (Modules pkgData)
findModuleFiles pathDist directories suffixes = do
modPaths <- map (replaceEq '.' pathSeparator) <$> arg (Modules pathDist)
fileList <- forM directories $ \dir ->
forM modPaths $ \modPath ->
forM suffixes $ \suffix -> do
......
......@@ -13,15 +13,15 @@ suffixArgs way =
ghcArgs :: Package -> TodoItem -> Way -> [FilePath] -> FilePath -> Args
ghcArgs (Package _ path _) (stage, dist, _) way srcs result =
let buildDir = toStandard $ path </> dist </> "build"
pkgData = path </> dist </> "package-data.mk"
let pathDist = path </> dist
buildDir = toStandard $ pathDist </> "build"
in arg [ suffixArgs way
, wayHcArgs way
, arg SrcHcArgs
, packageArgs stage pkgData
, packageArgs stage pathDist
, includeArgs path dist
, concatArgs ["-optP"] $ CppOpts pkgData
, arg $ HsOpts pkgData
, concatArgs ["-optP"] $ CppOpts pathDist
, arg $ HsOpts pathDist
-- TODO: now we have both -O and -O2
-- <> arg ["-O2"]
, productArgs ["-odir", "-hidir", "-stubdir"] buildDir
......
......@@ -59,19 +59,17 @@ postProcessPackageData file = do
(prefix, suffix) = break (== '=') line
bootPkgConstraints :: Package -> TodoItem -> Args
bootPkgConstraints (Package _ path _) (_, dist, _) = do
let pkgData = path </> dist </> "package-data.mk"
deps <- arg $ DepNames pkgData
bootPkgConstraints :: FilePath -> Args
bootPkgConstraints pathDist = do
need [pathDist </> "package-data.mk"]
deps <- arg $ DepNames pathDist
let depsStage0 = filter ((`elem` deps) . takeBaseName)
$ libraryPackageNames Stage0
putNormal $ "depsStage0 = " ++ show depsStage0
forM depsStage0 $ \dep -> do
let depPkg = libraryPackage dep [Stage0] defaultSettings
(_, depPkgDist, _) = head $ pkgTodo depPkg
depPkgData = pkgPath depPkg </> depPkgDist
</> "package-data.mk"
[version] <- arg $ Version depPkgData
depPathDist = pkgPath depPkg </> depPkgDist
[version] <- arg $ Version depPathDist
return $ "--constraint " ++ dep ++ " == " ++ version
cabalArgs :: Package -> TodoItem -> Args
......@@ -87,7 +85,7 @@ cabalArgs pkg @ (Package _ path _) todo @ (stage, dist, settings) = arg
, libraryArgs =<< ways settings
, when (specified HsColour) $ with HsColour
, configureArgs stage settings
, when (stage == Stage0) $ bootPkgConstraints pkg todo
, when (stage == Stage0) $ bootPkgConstraints $ path </> dist
, with Gcc
, when (stage /= Stage0) $ with Ld
, with Ar
......
......@@ -8,17 +8,17 @@ argListDir = "shake/arg/buildPackageDependencies"
ghcArgs :: Package -> TodoItem -> Args
ghcArgs (Package name path _) (stage, dist, settings) =
let buildDir = toStandard $ path </> dist </> "build"
pkgData = path </> dist </> "package-data.mk"
let pathDist = path </> dist
buildDir = toStandard $ pathDist </> "build"
depFile = buildDir </> takeBaseName name <.> "m"
in arg [ arg "-M"
, packageArgs stage pkgData
, packageArgs stage pathDist
, includeArgs path dist
, concatArgs ["-optP"] $ CppOpts pkgData
, concatArgs ["-optP"] $ CppOpts pathDist
, productArgs ["-odir", "-stubdir", "-hidir"] buildDir
, arg ["-dep-makefile", depFile <.> "new"]
, productArgs "-dep-suffix" $ map wayPrefix <$> ways settings
, arg $ HsOpts pkgData
, arg $ HsOpts pathDist
, arg $ pkgHsSources path dist ]
buildRule :: Package -> TodoItem -> Rules ()
......
......@@ -38,13 +38,13 @@ ldArgs (Package _ path _) (stage, dist, _) result = do
ldRule :: Package -> TodoItem -> Rules ()
ldRule pkg @ (Package name path _) todo @ (stage, dist, _) =
let buildDir = path </> dist </> "build"
pkgData = path </> dist </> "package-data.mk"
let pathDist = path </> dist
buildDir = pathDist </> "build"
in
priority 2 $ (buildDir </> "*.o") %> \out -> do
need [argListPath argListDir pkg stage]
terseRun Ld $ ldArgs pkg todo $ toStandard out
synopsis <- unwords <$> arg (Synopsis pkgData)
synopsis <- unwords <$> arg (Synopsis pathDist)
putColoured Vivid Green $ "/--------\n| Successfully built package "
++ name ++ " (stage " ++ show stage ++ ")."
putColoured Vivid Green $ "| Package synopsis: " ++ synopsis ++ "."
......
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