Commit e3be330a authored by Andrey Mokhov's avatar Andrey Mokhov

Simplify handling of non-Cabal contexts

parent 72a08b0e
......@@ -3,7 +3,7 @@ module Expression (
-- * Expressions
Expr, DiffExpr, fromDiffExpr,
-- ** Operators
apply, append, arg, remove, removePair,
apply, append, arg, remove,
appendSub, appendSubD, filterSub, removeSub,
-- ** Evaluation
interpret, interpretInContext, interpretDiff,
......@@ -80,16 +80,6 @@ append x = apply (<> x)
remove :: Eq a => [a] -> DiffExpr [a]
remove xs = apply $ filter (`notElem` xs)
-- | Remove given pair of elements from a list expression.
-- Example: removePair "-flag" "b" ["-flag", "a", "-flag", "b"] = ["-flag", "a"]
removePair :: Eq a => a -> a -> DiffExpr [a]
removePair x y = apply filterPair
where
filterPair (z1 : z2 : zs) = if x == z1 && y == z2
then filterPair zs
else z1 : filterPair (z2 : zs)
filterPair zs = zs
-- | Apply a predicate to an expression.
applyPredicate :: Monoid a => Predicate -> Expr a -> Expr a
applyPredicate predicate expr = do
......
......@@ -9,7 +9,7 @@ module GHC (
parallel, pretty, primitive, process, rts, runGhc, stm, templateHaskell,
terminfo, time, touchy, transformers, unlit, unix, win32, xhtml,
defaultKnownPackages, builderProvenance, programName
defaultKnownPackages, builderProvenance, programName, nonCabalContext
) where
import Builder
......@@ -123,3 +123,10 @@ programName Context {..}
| package == hpcBin = "hpc"
| package == runGhc = "runhaskell"
| otherwise = pkgNameString package
-- | Some contexts are special: their packages do have @.cabal@ metadata or
-- we cannot run @ghc-cabal@ on them, e.g. because the latter hasn't been built
-- yet (this is the case with the 'ghcCabal' package in 'Stage0').
nonCabalContext :: Context -> Bool
nonCabalContext Context {..} = (package `elem` [hp2ps, rts, touchy, unlit])
|| package == ghcCabal && stage == Stage0
......@@ -52,16 +52,8 @@ buildPackageData context@Context {..} = do
let oldPath = top -/- path </> "build"
fixFile conf $ unlines . map (replace oldPath path) . lines
-- TODO: PROGNAME was $(CrossCompilePrefix)hp2ps.
priority 2.0 $ do
when (package `elem` [hp2ps, rts, touchy, unlit]) $ dataFile %>
generatePackageData context
-- Bootstrapping `ghcCabal`: although `ghcCabal` is a proper cabal
-- package, we cannot generate the corresponding `package-data.mk` file
-- by running by running `ghcCabal`, because it has not yet been built.
when (package == ghcCabal && stage == Stage0) $ dataFile %>
generatePackageData context
priority 2.0 $ when (nonCabalContext context) $ dataFile %>
generatePackageData context
generatePackageData :: Context -> FilePath -> Action ()
generatePackageData context@Context {..} file = do
......
......@@ -5,7 +5,6 @@ import Settings.Packages.Rts
import Target
import Util
-- TODO: Why copy these include files into rts? Keep in libffi!
libffiDependencies :: [FilePath]
libffiDependencies = (rtsBuildPath -/-) <$> [ "ffi.h", "ffitarget.h" ]
......
module Settings.Builders.Ghc (ghcBuilderArgs, ghcMBuilderArgs, commonGhcArgs) where
import Flavour
import GHC
import Settings.Builders.Common
ghcBuilderArgs :: Args
......@@ -106,7 +107,6 @@ packageGhcArgs = do
, isLibrary pkg ? arg (thisArg ++ compId)
, append $ map ("-package-id " ++) pkgDepIds ]
-- TODO: Improve handling of "cabal_macros.h".
includeGhcArgs :: Args
includeGhcArgs = do
pkg <- getPackage
......@@ -120,5 +120,6 @@ includeGhcArgs = do
, cIncludeArgs
, arg $ "-I" ++ generatedPath
, arg $ "-optc-I" ++ generatedPath
, arg "-optP-include"
, arg $ "-optP" ++ autogenPath context -/- "cabal_macros.h" ]
, (not $ nonCabalContext context) ?
append [ "-optP-include"
, "-optP" ++ autogenPath context -/- "cabal_macros.h" ] ]
......@@ -4,14 +4,12 @@ import Base
import GHC
import Oracles.Config.Setting
import Predicate
import Settings.Path
ghcCabalPackageArgs :: Args
ghcCabalPackageArgs = package ghcCabal ?
builder Ghc ? mconcat [ ghcCabalBootArgs
, remove ["-no-auto-link-packages"] ]
-- Boostrapping ghcCabal
-- TODO: do we need -DCABAL_VERSION=$(CABAL_VERSION)?
ghcCabalBootArgs :: Args
ghcCabalBootArgs = stage0 ? do
......@@ -23,7 +21,6 @@ ghcCabalBootArgs = stage0 ? do
, pretty, process, time ]
, notM windowsHost ? append [unix]
, windowsHost ? append [win32] ]
context <- getContext
mconcat
[ append [ "-package " ++ pkgNameString pkg | pkg <- cabalDeps ]
, arg "--make"
......@@ -31,7 +28,6 @@ ghcCabalBootArgs = stage0 ? do
, arg "-DBOOTSTRAPPING"
, arg "-DMIN_VERSION_binary_0_8_0"
, arg "-DGENERICS"
, removePair "-optP-include" $ "-optP" ++ autogenPath context -/- "cabal_macros.h"
, arg "-optP-include"
, arg $ "-optP" ++ pkgPath ghcCabal -/- "cabal_macros_boot.h"
, arg "-ilibraries/Cabal/Cabal"
......
module Settings.Packages.Hp2ps (hp2psPackageArgs) where
import Base
import GHC
import Predicate
import Settings
hp2psPackageArgs :: Args
hp2psPackageArgs = package hp2ps ? do
path <- getBuildPath
let cabalMacros = path -/- "build/autogen/cabal_macros.h"
hp2psPackageArgs = package hp2ps ?
builder Ghc ? mconcat [ arg "-no-hs-main"
, remove ["-hide-all-packages"]
, removePair "-optP-include" $ "-optP" ++ cabalMacros ]
, remove ["-hide-all-packages"] ]
module Settings.Packages.Touchy (touchyPackageArgs) where
import Base
import GHC
import Predicate
import Settings
touchyPackageArgs :: Args
touchyPackageArgs = package touchy ? do
path <- getBuildPath
let cabalMacros = path -/- "build/autogen/cabal_macros.h"
touchyPackageArgs = package touchy ?
builder Ghc ? mconcat [ arg "-no-hs-main"
, remove ["-hide-all-packages"]
, removePair "-optP-include" $ "-optP" ++ cabalMacros ]
, remove ["-hide-all-packages"] ]
module Settings.Packages.Unlit (unlitPackageArgs) where
import Base
import GHC
import Predicate
import Settings
unlitPackageArgs :: Args
unlitPackageArgs = package unlit ? do
path <- getBuildPath
let cabalMacros = path -/- "build/autogen/cabal_macros.h"
unlitPackageArgs = package unlit ?
builder Ghc ? mconcat [ arg "-no-hs-main"
, remove ["-hide-all-packages"]
, removePair "-optP-include" $ "-optP" ++ cabalMacros ]
, remove ["-hide-all-packages"] ]
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