Commit 9129e8bc authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Decouple buildPackageData and registerPackage rules.

See #200.
parent c1364e54
......@@ -62,6 +62,7 @@ executable ghc-shake
, Rules.Package
, Rules.Perl
, Rules.Program
, Rules.Register
, Rules.Resources
, Rules.Wrappers.Ghc
, Rules.Wrappers.GhcPkg
......
......@@ -6,7 +6,6 @@ import Base
import Expression
import GHC
import Oracles
import Predicates (registerPackage)
import Rules.Actions
import Rules.Generate
import Rules.Libffi
......@@ -29,14 +28,14 @@ buildPackageData rs target @ (PartialTarget stage pkg) = do
orderOnly $ generatedDependencies stage pkg
-- GhcCabal may run the configure script, so we depend on it
-- We don't know who built the configure script from configure.ac
whenM (doesFileExist $ configure <.> "ac") $ need [configure]
-- We configure packages in the order of their dependencies
-- Before we configure a package its dependencies need to be registered
deps <- packageDeps pkg
pkgs <- interpretPartial target getPackages
let depPkgs = matchPackageNames (sort pkgs) deps
orderOnly $ map (pkgDataFile stage) depPkgs
depConfs <- traverse (pkgConfFile stage) depPkgs
orderOnly depConfs
-- TODO: get rid of this, see #113
let inTreeMk = oldPath -/- takeFileName dataFile
......@@ -52,23 +51,6 @@ buildPackageData rs target @ (PartialTarget stage pkg) = do
forM_ autogenFiles $ \file -> do
copyFile (oldPath -/- file) (targetPath stage pkg -/- file)
-- ghc-pkg produces inplace-pkg-config when run on packages with
-- library components only
when (isLibrary pkg) .
whenM (interpretPartial target registerPackage) $ do
-- Post-process inplace-pkg-config. TODO: remove, see #113, #148
let fixPkgConf = unlines
. map (replace oldPath (targetPath stage pkg)
. replace (replaceSeparators '\\' $ oldPath)
(targetPath stage pkg) )
. lines
fixFile (oldPath -/- "inplace-pkg-config") fixPkgConf
buildWithResources [(resGhcPkg rs, 1)] $
fullTarget target (GhcPkg stage) [cabalFile] []
postProcessPackageData stage pkg dataFile
-- TODO: PROGNAME was $(CrossCompilePrefix)hp2ps
......@@ -141,7 +123,7 @@ buildPackageData rs target @ (PartialTarget stage pkg) = do
[ "C_SRCS = "
++ unwords (cSrcs ++ cmmSrcs ++ sSrcs ++ extraSrcs)
, "CC_OPTS = " ++ unwords includes
, "COMPONENT_ID = " ++ "rts" ]
, "COMPONENT_ID = rts" ]
writeFileChanged mk contents
putSuccess $ "| Successfully generated '" ++ mk ++ "'."
......
......@@ -26,7 +26,8 @@ buildPackageDocumentation _ target @ (PartialTarget stage pkg) =
-- HsColour sources
whenM (specified HsColour) $ do
need [cabalFile, pkgDataFile stage pkg ]
pkgConf <- pkgConfFile stage pkg
need [ cabalFile, pkgConf ] -- TODO: check if need pkgConf
build $ fullTarget target GhcCabalHsColour [cabalFile] []
-- Build Haddock documentation
......
module Rules.Package (buildPackage) where
import Base
import Rules.Compile
import Rules.Data
import Rules.Dependencies
import Rules.Documentation
import Rules.Generate
import Rules.Library
import Rules.Program
import qualified Rules.Compile
import qualified Rules.Data
import qualified Rules.Dependencies
import qualified Rules.Documentation
import qualified Rules.Generate
import qualified Rules.Library
import qualified Rules.Program
import qualified Rules.Register
import Rules.Resources
import Target
buildPackage :: Resources -> PartialTarget -> Rules ()
buildPackage = mconcat
[ buildPackageData
, buildPackageDependencies
, generatePackageCode
, compilePackage
, buildPackageLibrary
, buildPackageDocumentation
, buildProgram ]
[ Rules.Compile.compilePackage
, Rules.Data.buildPackageData
, Rules.Dependencies.buildPackageDependencies
, Rules.Documentation.buildPackageDocumentation
, Rules.Generate.generatePackageCode
, Rules.Library.buildPackageLibrary
, Rules.Program.buildProgram
, Rules.Register.registerPackage ]
module Rules.Register (registerPackage) where
import Data.Char
import Base
import Expression
import GHC
import Rules.Actions
import Rules.Resources
import Settings
-- matchPkgConf :: FilePath -> Bool
-- matchPkgConf file =
-- Build package-data.mk by using GhcCabal to process pkgCabal file
registerPackage :: Resources -> PartialTarget -> Rules ()
registerPackage rs target @ (PartialTarget stage pkg) = do
let oldPath = pkgPath pkg -/- targetDirectory stage pkg -- TODO: remove, #113
pkgConf = packageDbDirectory stage -/- pkgNameString pkg
match f = case stripPrefix (pkgConf ++ "-") f of
Nothing -> False
Just suf -> dropWhile (\c -> isDigit c || c == '.') suf == "conf"
when (stage <= Stage1) $ match ?> \_ -> do
-- This produces pkgConfig. TODO: Add explicit tracking
need [pkgDataFile stage pkg]
-- Post-process inplace-pkg-config. TODO: remove, see #113, #148
let pkgConfig = oldPath -/- "inplace-pkg-config"
fixPkgConf = unlines
. map (replace oldPath (targetPath stage pkg)
. replace (replaceSeparators '\\' $ oldPath)
(targetPath stage pkg) )
. lines
fixFile pkgConfig fixPkgConf
buildWithResources [(resGhcPkg rs, 1)] $
fullTarget target (GhcPkg stage) [pkgConfig] []
Supports Markdown
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