Commit c677b049 authored by Andrey Mokhov's avatar Andrey Mokhov
Browse files

Simplify Package.

parent 61a085c0
......@@ -6,22 +6,24 @@ module Oracles.PackageDeps (
) where
import Base
import Package
import Oracles.Base
import Data.Maybe
import qualified Data.HashMap.Strict as Map
import Control.Applicative
newtype PackageDepsKey = PackageDepsKey String
newtype PackageDepsKey = PackageDepsKey PackageName
deriving (Show, Typeable, Eq, Hashable, Binary, NFData)
-- packageDeps depFile objFile is an action that looks up dependencies of an
-- object file (objFile) in a generated dependecy file (depFile).
packageDeps :: String -> Action [String]
-- packageDeps name is an action that given a package looks up its dependencies
-- in Base.packageDependencies file. The dependencies need to be computed by
-- scanning package cabal files (see Rules.Cabal).
packageDeps :: Package -> Action [PackageName]
packageDeps pkg = do
res <- askOracle $ PackageDepsKey pkg
res <- askOracle . PackageDepsKey . pkgName $ pkg
return . fromMaybe [] $ res
-- Oracle for 'path/dist/*.deps' files
-- Oracle for the package dependencies file
packageDepsOracle :: Rules ()
packageDepsOracle = do
deps <- newCache $ \_ -> do
......
{-# LANGUAGE DeriveGeneric #-}
module Package (Package (..), library, topLevel, setCabal) where
module Package (
Package (..), PackageName, pkgCabalPath,
library, topLevel, setPath
) where
import Base
import Util
import Data.Function
import GHC.Generics
-- It is helpful to distinguish package names from strings.
type PackageName = String
-- pkgPath is the path to the source code relative to the root
data Package = Package
{
pkgName :: String, -- Examples: "deepseq", "Cabal/Cabal"
pkgPath :: FilePath, -- "libraries/deepseq", "libraries/Cabal/Cabal"
pkgCabal :: FilePath -- "deepseq.cabal", "Cabal.cabal" (relative)
pkgName :: PackageName, -- Examples: "ghc", "Cabal"
pkgPath :: FilePath -- "compiler", "libraries/Cabal/Cabal"
}
deriving Generic
-- Relative path to cabal file, e.g.: "libraries/Cabal/Cabal/Cabal.cabal"
pkgCabalPath :: Package -> FilePath
pkgCabalPath pkg = pkgPath pkg -/- pkgName pkg <.> "cabal"
instance Show Package where
show = pkgName
......@@ -25,16 +34,14 @@ instance Eq Package where
instance Ord Package where
compare = compare `on` pkgName
-- TODO: check if unifyPath is actually needed
library :: String -> Package
library name =
Package name ("libraries" -/- name) (name <.> "cabal")
library :: PackageName -> Package
library name = Package name ("libraries" -/- name)
topLevel :: String -> Package
topLevel name = Package name name (name <.> "cabal")
topLevel :: PackageName -> Package
topLevel name = Package name name
setCabal :: Package -> FilePath -> Package
setCabal pkg cabalName = pkg { pkgCabal = cabalName }
setPath :: Package -> FilePath -> Package
setPath pkg path = pkg { pkgPath = path }
-- Instances for storing in the Shake database
instance Binary Package
......
module Rules.Cabal (cabalRules) where
import Base
import Util
import Stage
import Package hiding (pkgName, library)
import Package hiding (library)
import Expression hiding (package)
import Settings.Packages
import Data.List
......@@ -19,12 +18,12 @@ cabalRules = do
bootPackageConstraints %> \file -> do
pkgs <- interpret (stageTarget Stage0) packages
constraints <- forM (sort pkgs) $ \pkg -> do
let cabal = pkgPath pkg -/- pkgCabal pkg
let cabal = pkgCabalPath pkg
need [cabal]
description <- liftIO $ readPackageDescription silent cabal
let identifier = package . packageDescription $ description
version = showVersion . pkgVersion $ identifier
PackageName name = pkgName identifier
PackageName name = Distribution.Package.pkgName identifier
return $ name ++ " == " ++ version
writeFileChanged file . unlines $ constraints
......@@ -32,13 +31,13 @@ cabalRules = do
packageDependencies %> \file -> do
pkgs <- interpret (stageTarget Stage1) packages
pkgDeps <- forM (sort pkgs) $ \pkg -> do
let cabal = pkgPath pkg -/- pkgCabal pkg
let cabal = pkgCabalPath pkg
need [cabal]
description <- liftIO $ readPackageDescription silent cabal
let deps = collectDeps . condLibrary $ description
depNames = [ name | Dependency (PackageName name) _ <- deps ]
return . unwords $ (dropExtension $ pkgCabal pkg) : sort depNames
writeFileChanged file $ unlines pkgDeps
return . unwords $ Package.pkgName pkg : sort depNames
writeFileChanged file . unlines $ pkgDeps
collectDeps :: Maybe (CondTree v [Dependency] a) -> [Dependency]
collectDeps Nothing = []
......
......@@ -13,7 +13,6 @@ import Settings.TargetDirectory
import Rules.Actions
import Rules.Resources
import Data.List
import Data.Maybe
import Control.Applicative
import Control.Monad.Extra
......@@ -23,7 +22,7 @@ buildPackageData (Resources ghcCabal ghcPkg) target = do
let stage = Target.stage target
pkg = Target.package target
path = targetPath stage pkg
cabal = pkgPath pkg -/- pkgCabal pkg
cabal = pkgCabalPath pkg
configure = pkgPath pkg -/- "configure"
(path -/-) <$>
......@@ -35,17 +34,16 @@ buildPackageData (Resources ghcCabal ghcPkg) target = do
-- TODO: Is this needed? Also check out Paths_cpsa.hs.
-- , "build" -/- "autogen" -/- ("Paths_" ++ name) <.> "hs"
] &%> \files -> do
-- We configure packages in the order of their dependencies
deps <- packageDeps . dropExtension . pkgCabal $ pkg
pkgs <- interpret target packages
let depPkgs = concatMap (maybeToList . findPackage pkgs) deps
-- GhcCabal may run the configure script, so we depend on it
-- We don't know who built the configure script from configure.ac
needConfigure <- doesFileExist $ configure <.> "ac"
whenM (doesFileExist $ configure <.> "ac") $ need [configure]
need $ [ configure | needConfigure ] ++
[ targetPath stage p -/- "package-data.mk" | p <- depPkgs ]
-- We configure packages in the order of their dependencies
deps <- packageDeps pkg
pkgs <- interpret target packages
let cmp pkg = compare (pkgName pkg)
depPkgs = intersectOrd cmp (sort pkgs) deps
need [ targetPath stage p -/- "package-data.mk" | p <- depPkgs ]
buildWithResources [(ghcCabal, 1)] $
fullTarget target [cabal] GhcCabal files
......@@ -57,10 +55,6 @@ buildPackageData (Resources ghcCabal ghcPkg) target = do
postProcessPackageData $ path -/- "package-data.mk"
-- Given a package name findPackage attempts to find it a given package list
findPackage :: [Package] -> String -> Maybe Package
findPackage pkgs name = find (\pkg -> dropExtension (pkgCabal pkg) == name) pkgs
-- Prepare a given 'packaga-data.mk' file for parsing by readConfigFile:
-- 1) Drop lines containing '$'
-- For example, get rid of
......@@ -70,7 +64,6 @@ findPackage pkgs name = find (\pkg -> dropExtension (pkgCabal pkg) == name) pkgs
-- 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)
......
......@@ -40,8 +40,8 @@ base = library "base"
binPackageDb = library "bin-package-db"
binary = library "binary"
bytestring = library "bytestring"
cabal = library "Cabal/Cabal" `setCabal` "Cabal.cabal"
compiler = topLevel "compiler" `setCabal` "ghc.cabal"
cabal = library "Cabal" `setPath` "libraries/Cabal/Cabal"
compiler = topLevel "ghc" `setPath` "compiler"
containers = library "containers"
deepseq = library "deepseq"
directory = library "directory"
......@@ -51,7 +51,7 @@ haskeline = library "haskeline"
hoopl = library "hoopl"
hpc = library "hpc"
integerGmp = library "integer-gmp"
integerGmp2 = library "integer-gmp2" `setCabal` "integer-gmp.cabal"
integerGmp2 = library "integer-gmp" `setPath` "libraries/integer-gmp2"
integerSimple = library "integer-simple"
parallel = library "parallel"
pretty = library "pretty"
......@@ -65,8 +65,3 @@ transformers = library "transformers"
unix = library "unix"
win32 = library "Win32"
xhtml = library "xhtml"
-- Note [Cabal name weirdness]
-- Find out if we can move the contents to just Cabal/
-- What is Cabal/cabal-install? Do we need it?
-- A related question about gmp2 -- let's rename the cabal file?
......@@ -125,10 +125,11 @@ customPackageArgs = do
[ package integerGmp2 ?
mconcat [ windowsHost ? builder GhcCabal ?
arg "--configure-option=--with-intree-gmp"
, appendCcArgs ["-Ilibraries/integer-gmp2/gmp"] ]
, appendCcArgs ["-I" ++ pkgPath integerGmp2 -/- "gmp"] ]
, package base ?
builder GhcCabal ? arg ("--flags=" ++ pkgName integerLibrary)
builder GhcCabal ?
arg ("--flags=" ++ takeFileName (pkgPath integerLibrary))
, package ghcPrim ?
builder GhcCabal ? arg "--flag=include-ghc-prim"
......
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