Commit 3461e46c authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Remove redundant argument to build rules.

parent 95b6614a
......@@ -10,7 +10,6 @@ import Targets
import Settings
import Package
import Expression
import UserSettings
import Rules.Package
-- generateTargets needs package-data.mk files of all target packages
......@@ -19,7 +18,7 @@ generateTargets :: Rules ()
generateTargets = action $
forM_ [Stage0 ..] $ \stage -> do
let env = defaultEnvironment { getStage = stage }
pkgs <- interpretDiff env $ targetPackages <> userPackages
pkgs <- interpretDiff env packages
forM_ pkgs $ \pkg -> do
let dir = targetDirectory stage pkg
need [pkgPath pkg </> dir </> "package-data.mk"]
......@@ -31,4 +30,4 @@ packageRules =
forM_ [Stage0, Stage1] $ \stage -> do
forM_ allPackages $ \pkg -> do
let env = defaultEnvironment { getStage = stage, getPackage = pkg }
buildPackage env (targetWays <> userWays) (settings <> userSettings)
buildPackage env
......@@ -2,112 +2,15 @@ module Rules.Data (
cabalSettings, ghcPkgSettings, buildPackageData
) where
import Ways hiding (parallel)
import Base hiding (arg, args, Args)
import Package
import Expression hiding (when, liftIO)
import Oracles.Base
import Oracles.Flag (when)
import Oracles.Builder
import Targets
import Switches
import Expression.Settings
import Settings
import Util
-- TODO: Isn't vanilla always built? If yes, some conditions are redundant.
librarySettings :: Ways -> Settings
librarySettings waysExpression = do
ways <- fromDiff waysExpression
ghcInterpreter <- ghcWithInterpreter
dynamicPrograms <- dynamicGhcPrograms
append [ if vanilla `elem` ways
then "--enable-library-vanilla"
else "--disable-library-vanilla"
, if vanilla `elem` ways && ghcInterpreter && not dynamicPrograms
then "--enable-library-for-ghci"
else "--disable-library-for-ghci"
, if profiling `elem` ways
then "--enable-library-profiling"
else "--disable-library-profiling"
, if dynamic `elem` ways
then "--enable-shared"
else "--disable-shared" ]
configureSettings :: Settings
configureSettings = do
let conf key = appendSubD $ "--configure-option=" ++ key
stage <- asks getStage
mconcat
[ conf "CFLAGS" ccSettings
, conf "LDFLAGS" ldSettings
, conf "CPPFLAGS" cppSettings
, appendSubD "--gcc-options" $ ccSettings <> ldSettings
, conf "--with-iconv-includes" $ argConfig "iconv-include-dirs"
, conf "--with-iconv-libraries" $ argConfig "iconv-lib-dirs"
, conf "--with-gmp-includes" $ argConfig "gmp-include-dirs"
, conf "--with-gmp-libraries" $ argConfig "gmp-lib-dirs"
-- TODO: why TargetPlatformFull and not host?
, crossCompiling ? (conf "--host" $ argConfig "target-platform-full")
, conf "--with-cc" . argM . showArg $ Gcc stage ]
bootPackageDbSettings :: Settings
bootPackageDbSettings = do
sourcePath <- lift $ askConfig "ghc-source-path"
arg $ "--package-db=" ++ sourcePath </> "libraries/bootstrapping.conf"
dllSettings :: Settings
dllSettings = arg ""
with' :: Builder -> Settings
with' builder = appendM $ with builder
packageConstraints :: Settings
packageConstraints = do
pkgs <- fromDiff targetPackages
constraints <- lift $ forM pkgs $ \pkg -> do
let cabal = pkgPath pkg </> pkgCabal pkg
prefix = dropExtension (pkgCabal pkg) ++ " == "
need [cabal]
content <- lines <$> liftIO (readFile cabal)
let vs = filter (("ersion:" `isPrefixOf`) . drop 1) content
case vs of
[v] -> return $ prefix ++ dropWhile (not . isDigit) v
_ -> redError $ "Cannot determine package version in '"
++ cabal ++ "'."
args $ concatMap (\c -> ["--constraint", c]) $ constraints
cabalSettings :: Settings
cabalSettings = do
stage <- asks getStage
pkg <- asks getPackage
mconcat [ arg "configure"
, arg $ pkgPath pkg
, arg $ targetDirectory stage pkg
, dllSettings
, with' $ Ghc stage
, with' $ GhcPkg stage
, customConfigureSettings
, Expression.stage Stage0 ? bootPackageDbSettings
, librarySettings targetWays
, configKeyNonEmpty "hscolour" ? with' HsColour -- TODO: generalise?
, configureSettings
, Expression.stage Stage0 ? packageConstraints
, with' $ Gcc stage
, notStage Stage0 ? with' Ld
, with' Ar
, with' Alex
, with' Happy ] -- TODO: reorder with's
ghcPkgSettings :: Settings
ghcPkgSettings = do
stage <- asks getStage
pkg <- asks getPackage
let dir = pkgPath pkg </> targetDirectory stage pkg
mconcat [ arg "update"
, arg "--force"
, Expression.stage Stage0 ? bootPackageDbSettings
, arg $ dir </> "inplace-pkg-config" ]
-- Prepare a given 'packaga-data.mk' file for parsing by readConfigFile:
-- 1) Drop lines containing '$'
-- For example, get rid of
......@@ -132,8 +35,8 @@ postProcessPackageData file = do
-- * otherwise, we must collapse it into one space-separated string
-- Build package-data.mk by using GhcCabal to process pkgCabal file
buildPackageData :: Environment -> Ways -> Settings -> Rules ()
buildPackageData env ways settings =
buildPackageData :: Environment -> Rules ()
buildPackageData env =
let stage = getStage env
pkg = getPackage env
dir = pkgPath pkg </> targetDirectory stage pkg
......@@ -152,13 +55,13 @@ buildPackageData env ways settings =
need [pkgPath pkg </> pkgCabal pkg]
-- We still don't know who built the configure script from configure.ac
when (doesFileExist $ configure <.> "ac") $ need [configure]
run' env GhcCabal settings
run' env GhcCabal
-- TODO: when (registerPackage settings) $
run' env (GhcPkg stage) settings
run' env (GhcPkg stage)
postProcessPackageData $ dir </> "package-data.mk"
run' :: Environment -> Builder -> Settings -> Action ()
run' env builder settings = do
run' :: Environment -> Builder -> Action ()
run' env builder = do
args <- interpret (env {getBuilder = builder}) $ fromDiff settings
putColoured Green (show args)
run builder args
......@@ -191,24 +94,3 @@ run' env builder settings = do
-- buildSettings = + builder Gcc ? ccSettings
-- builder Gcc ? "-tricky-flag"
ccSettings :: Settings
ccSettings = do
let gccGe46 = liftM not gccLt46
mconcat
[ package integerLibrary ? arg "-Ilibraries/integer-gmp2/gmp"
, builder GhcCabal ? argStagedConfig "conf-cc-args"
, validating ? mconcat
[ notBuilder GhcCabal ? arg "-Werror"
, arg "-Wall"
, gccIsClang ??
( arg "-Wno-unknown-pragmas" <>
gccGe46 ? windowsHost ? arg "-Werror=unused-but-set-variable"
, gccGe46 ? arg "-Wno-error=inline" )]
]
ldSettings :: Settings
ldSettings = builder GhcCabal ? argStagedConfig "conf-gcc-linker-args"
cppSettings :: Settings
cppSettings = builder GhcCabal ? argStagedConfig "conf-cpp-args"
......@@ -5,7 +5,6 @@ module Rules.Package (
import Base
import Rules.Data
import Expression
import Expression.Settings
buildPackage :: Environment -> Ways -> Settings -> Rules ()
buildPackage :: Environment -> Rules ()
buildPackage = buildPackageData
{-# LANGUAGE NoImplicitPrelude, FlexibleInstances #-}
{-# LANGUAGE FlexibleInstances #-}
module Settings (
settings
settings, ways, packages,
cabalSettings, ghcPkgSettings
) where
import Base hiding (arg, args, Args)
import Rules.Data
import Oracles.Builder
import Expression
import Ways
import Util
import Targets
import Package
import Switches
import Oracles.Base
import UserSettings
import Expression hiding (when, liftIO)
import Expression.Settings
settings :: Settings
settings = do
settings = defaultSettings <> userSettings
ways :: Ways
ways = targetWays <> userWays
packages :: Packages
packages = targetPackages <> userPackages
defaultSettings :: Settings
defaultSettings = do
stage <- asks getStage
mconcat [ builder GhcCabal ? cabalSettings
, builder (GhcPkg stage) ? ghcPkgSettings ]
-- Builder settings
-- TODO: Isn't vanilla always built? If yes, some conditions are redundant.
librarySettings :: Settings
librarySettings = do
ways <- fromDiff Settings.ways
ghcInterpreter <- ghcWithInterpreter
dynamicPrograms <- dynamicGhcPrograms
append [ if vanilla `elem` ways
then "--enable-library-vanilla"
else "--disable-library-vanilla"
, if vanilla `elem` ways && ghcInterpreter && not dynamicPrograms
then "--enable-library-for-ghci"
else "--disable-library-for-ghci"
, if profiling `elem` ways
then "--enable-library-profiling"
else "--disable-library-profiling"
, if dynamic `elem` ways
then "--enable-shared"
else "--disable-shared" ]
configureSettings :: Settings
configureSettings = do
let conf key = appendSubD $ "--configure-option=" ++ key
stage <- asks getStage
mconcat
[ conf "CFLAGS" ccSettings
, conf "LDFLAGS" ldSettings
, conf "CPPFLAGS" cppSettings
, appendSubD "--gcc-options" $ ccSettings <> ldSettings
, conf "--with-iconv-includes" $ argConfig "iconv-include-dirs"
, conf "--with-iconv-libraries" $ argConfig "iconv-lib-dirs"
, conf "--with-gmp-includes" $ argConfig "gmp-include-dirs"
, conf "--with-gmp-libraries" $ argConfig "gmp-lib-dirs"
-- TODO: why TargetPlatformFull and not host?
, crossCompiling ? (conf "--host" $ argConfig "target-platform-full")
, conf "--with-cc" . argM . showArg $ Gcc stage ]
bootPackageDbSettings :: Settings
bootPackageDbSettings = do
sourcePath <- lift $ askConfig "ghc-source-path"
arg $ "--package-db=" ++ sourcePath </> "libraries/bootstrapping.conf"
dllSettings :: Settings
dllSettings = arg ""
with' :: Builder -> Settings
with' builder = appendM $ with builder
packageConstraints :: Settings
packageConstraints = do
pkgs <- fromDiff targetPackages
constraints <- lift $ forM pkgs $ \pkg -> do
let cabal = pkgPath pkg </> pkgCabal pkg
prefix = dropExtension (pkgCabal pkg) ++ " == "
need [cabal]
content <- lines <$> liftIO (readFile cabal)
let vs = filter (("ersion:" `isPrefixOf`) . drop 1) content
case vs of
[v] -> return $ prefix ++ dropWhile (not . isDigit) v
_ -> redError $ "Cannot determine package version in '"
++ cabal ++ "'."
args $ concatMap (\c -> ["--constraint", c]) $ constraints
cabalSettings :: Settings
cabalSettings = do
stage <- asks getStage
pkg <- asks getPackage
mconcat [ arg "configure"
, arg $ pkgPath pkg
, arg $ targetDirectory stage pkg
, dllSettings
, with' $ Ghc stage
, with' $ GhcPkg stage
, customConfigureSettings
, Expression.stage Stage0 ? bootPackageDbSettings
, librarySettings
, configKeyNonEmpty "hscolour" ? with' HsColour -- TODO: generalise?
, configureSettings
, Expression.stage Stage0 ? packageConstraints
, with' $ Gcc stage
, notStage Stage0 ? with' Ld
, with' Ar
, with' Alex
, with' Happy ] -- TODO: reorder with's
ghcPkgSettings :: Settings
ghcPkgSettings = do
stage <- asks getStage
pkg <- asks getPackage
let dir = pkgPath pkg </> targetDirectory stage pkg
mconcat [ arg "update"
, arg "--force"
, Expression.stage Stage0 ? bootPackageDbSettings
, arg $ dir </> "inplace-pkg-config" ]
ccSettings :: Settings
ccSettings = do
let gccGe46 = liftM not gccLt46
mconcat
[ package integerLibrary ? arg "-Ilibraries/integer-gmp2/gmp"
, builder GhcCabal ? argStagedConfig "conf-cc-args"
, validating ? mconcat
[ notBuilder GhcCabal ? arg "-Werror"
, arg "-Wall"
, gccIsClang ??
( arg "-Wno-unknown-pragmas" <>
gccGe46 ? windowsHost ? arg "-Werror=unused-but-set-variable"
, gccGe46 ? arg "-Wno-error=inline" )]
]
ldSettings :: Settings
ldSettings = builder GhcCabal ? argStagedConfig "conf-gcc-linker-args"
cppSettings :: Settings
cppSettings = builder GhcCabal ? argStagedConfig "conf-cpp-args"
module Targets (
targetWays, targetPackages, targetDirectory, allPackages,
targetWays, targetPackages, targetDirectory,
allPackages,
customConfigureSettings,
array, base, binPackageDb, binary, bytestring, cabal, compiler, containers,
deepseq, directory, filepath, ghcPrim, haskeline, hoopl, hpc,
......
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