Unverified Commit 8dc4f73f authored by Andrey Mokhov's avatar Andrey Mokhov Committed by GitHub

Clean up remaining bits related to ghc-cabal (#658)

* Drop ghcCabal package
* Merge GhcCabal and CabalFlags builders
* Use more consistent naming
* Resolve import cycle
* Rename parseCabal to parseCabalFile
* Remove outdated references to ghc-cabal from comments
parent a804d57a
...@@ -33,6 +33,6 @@ ghc %ghcArgs% ...@@ -33,6 +33,6 @@ ghc %ghcArgs%
if %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL% if %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL%
rem Unset GHC_PACKAGE_PATH variable, as otherwise ghc-cabal complains rem Unset GHC_PACKAGE_PATH variable, as otherwise Cabal complains
set GHC_PACKAGE_PATH= set GHC_PACKAGE_PATH=
bin\hadrian %hadrianArgs% bin\hadrian %hadrianArgs%
...@@ -36,13 +36,15 @@ executable hadrian ...@@ -36,13 +36,15 @@ executable hadrian
, Hadrian.Builder.Tar , Hadrian.Builder.Tar
, Hadrian.Expression , Hadrian.Expression
, Hadrian.Haskell.Cabal , Hadrian.Haskell.Cabal
, Hadrian.Haskell.Cabal.CabalData
, Hadrian.Haskell.Cabal.PackageData , Hadrian.Haskell.Cabal.PackageData
, Hadrian.Haskell.Cabal.Parse , Hadrian.Haskell.Cabal.Parse
, Hadrian.Haskell.Cabal.Type
, Hadrian.Oracles.ArgsHash , Hadrian.Oracles.ArgsHash
, Hadrian.Oracles.DirectoryContents , Hadrian.Oracles.DirectoryContents
, Hadrian.Oracles.Path , Hadrian.Oracles.Path
, Hadrian.Oracles.TextFile , Hadrian.Oracles.TextFile
, Hadrian.Oracles.TextFile.Rules
, Hadrian.Oracles.TextFile.Type
, Hadrian.Package , Hadrian.Package
, Hadrian.Package.Type , Hadrian.Package.Type
, Hadrian.Target , Hadrian.Target
...@@ -70,13 +72,13 @@ executable hadrian ...@@ -70,13 +72,13 @@ executable hadrian
, Rules.Test , Rules.Test
, Settings , Settings
, Settings.Builders.Alex , Settings.Builders.Alex
, Settings.Builders.Cabal
, Settings.Builders.Common , Settings.Builders.Common
, Settings.Builders.Cc , Settings.Builders.Cc
, Settings.Builders.Configure , Settings.Builders.Configure
, Settings.Builders.DeriveConstants , Settings.Builders.DeriveConstants
, Settings.Builders.GenPrimopCode , Settings.Builders.GenPrimopCode
, Settings.Builders.Ghc , Settings.Builders.Ghc
, Settings.Builders.GhcCabal
, Settings.Builders.GhcPkg , Settings.Builders.GhcPkg
, Settings.Builders.Haddock , Settings.Builders.Haddock
, Settings.Builders.Happy , Settings.Builders.Happy
......
{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE InstanceSigs #-}
module Builder ( module Builder (
-- * Data types -- * Data types
ArMode (..), CcMode (..), GhcCabalMode (..), GhcMode (..), GhcPkgMode (..), HaddockMode (..), ArMode (..), CcMode (..), ConfigurationInfo (..), GhcMode (..),
SphinxMode (..), TarMode (..), Builder (..), GhcPkgMode (..), HaddockMode (..), SphinxMode (..), TarMode (..),
Builder (..),
-- * Builder properties -- * Builder properties
builderProvenance, systemBuilderPath, builderPath, isSpecified, needBuilder, builderProvenance, systemBuilderPath, builderPath, isSpecified, needBuilder,
...@@ -53,20 +54,36 @@ instance Binary GhcMode ...@@ -53,20 +54,36 @@ instance Binary GhcMode
instance Hashable GhcMode instance Hashable GhcMode
instance NFData GhcMode instance NFData GhcMode
-- | GHC cabal mode. Can configure, copy and register packages. -- | To configure a package we need two pieces of information, which we choose
data GhcCabalMode = Conf | HsColour | Check | Sdist -- to record separately for convenience.
deriving (Eq, Generic, Show) --
-- * Command line arguments to be passed to the setup script.
instance Binary GhcCabalMode --
instance Hashable GhcCabalMode -- * Package configuration flags that enable/disable certain package features.
instance NFData GhcCabalMode -- Here is an example from "Settings.Packages":
--
-- | GhcPkg can initialise a package database and register packages in it. -- > package rts
data GhcPkgMode = Init -- initialize a new database. -- > ? builder (Cabal Flags)
| Update -- update a package. -- > ? any (wayUnit Profiling) rtsWays
| Clone -- clone a package from one pkg database into another. @Copy@ is already taken by GhcCabalMode. -- > ? arg "profiling"
| Unregister -- unregister a package --
| Dependencies -- compute package dependencies. -- This instructs package configuration functions (such as 'configurePackage')
-- to enable the @profiling@ Cabal flag when processing @rts.cabal@ and
-- building RTS with profiling information.
data ConfigurationInfo = Setup | Flags deriving (Eq, Generic, Show)
instance Binary ConfigurationInfo
instance Hashable ConfigurationInfo
instance NFData ConfigurationInfo
-- TODO: Do we really need all these modes? Why do we need 'Dependencies'? We
-- can extract dependencies using the Cabal library.
-- | 'GhcPkg' can initialise a package database and register packages in it.
data GhcPkgMode = Init -- ^ Initialize a new database.
| Update -- ^ Update a package.
| Copy -- ^ Copy a package from one database to another.
| Unregister -- ^ Unregister a package.
| Dependencies -- ^ Compute package dependencies.
deriving (Eq, Generic, Show) deriving (Eq, Generic, Show)
instance Binary GhcPkgMode instance Binary GhcPkgMode
...@@ -82,21 +99,24 @@ instance Binary HaddockMode ...@@ -82,21 +99,24 @@ instance Binary HaddockMode
instance Hashable HaddockMode instance Hashable HaddockMode
instance NFData HaddockMode instance NFData HaddockMode
-- | A 'Builder' is an external command invoked in a separate process via 'cmd'. -- | A 'Builder' is a (usually external) command invoked in a separate process
-- @Ghc Stage0@ is the bootstrapping compiler. -- via 'cmd'. Here are some examples:
-- @Ghc StageN@, N > 0, is the one built in stage (N - 1). -- * 'Alex' is a lexical analyser generator that builds @Lexer.hs@ from @Lexer.x@.
-- @GhcPkg Stage0@ is the bootstrapping @GhcPkg@. -- * 'Ghc' 'Stage0' is the bootstrapping Haskell compiler used in 'Stage0'.
-- @GhcPkg Stage1@ is the one built in Stage0. -- * 'Ghc' @StageN@ (N > 0) is the GHC built in stage (N - 1) and used in @StageN@.
--
-- The 'Cabal' builder is unusual in that it does not correspond to an external
-- program but instead relies on the Cabal library for package configuration.
data Builder = Alex data Builder = Alex
| Ar ArMode Stage | Ar ArMode Stage
| Autoreconf FilePath | Autoreconf FilePath
| DeriveConstants | DeriveConstants
| Cabal ConfigurationInfo Stage
| Cc CcMode Stage | Cc CcMode Stage
| Configure FilePath | Configure FilePath
| GenApply | GenApply
| GenPrimopCode | GenPrimopCode
| Ghc GhcMode Stage | Ghc GhcMode Stage
| GhcCabal GhcCabalMode Stage
| GhcPkg GhcPkgMode Stage | GhcPkg GhcPkgMode Stage
| Haddock HaddockMode | Haddock HaddockMode
| Happy | Happy
...@@ -117,28 +137,6 @@ data Builder = Alex ...@@ -117,28 +137,6 @@ data Builder = Alex
| Tar TarMode | Tar TarMode
| Unlit | Unlit
| Xelatex | Xelatex
| CabalFlags Stage
-- ^ A \"virtual\" builder (not backed by a program),
-- used a lot in Settings.Packages, that allows us to
-- toggle cabal flags of packages depending on some `Args`
-- predicates, and then collect all those when we are about to
-- configure the said packages, in Hadrian.Haskell.Cabal.Parse,
-- so that we end up passing the appropriate flags to the Cabal
-- library. For example:
--
-- > package rts
-- > ? builder CabalFlags
-- > ? any (wayUnit Profiling) rtsWays
-- > ? arg "profiling"
--
-- (from Settings.Packages) specifies that if we're
-- processing the rts package with the `CabalFlag` builder,
-- and if we're building a profiling-enabled way of the rts,
-- then we pass the @profiling@ argument to the builder. This
-- argument is then collected by the code that performs the
-- package configuration, and @rts.cabal@ is processed as if
-- we were passing @-fprofiling@ to our build tool.
deriving (Eq, Generic, Show) deriving (Eq, Generic, Show)
instance Binary Builder instance Binary Builder
...@@ -155,7 +153,6 @@ builderProvenance = \case ...@@ -155,7 +153,6 @@ builderProvenance = \case
GenPrimopCode -> context Stage0 genprimopcode GenPrimopCode -> context Stage0 genprimopcode
Ghc _ Stage0 -> Nothing Ghc _ Stage0 -> Nothing
Ghc _ stage -> context (pred stage) ghc Ghc _ stage -> context (pred stage) ghc
GhcCabal _ _ -> context Stage1 ghcCabal
GhcPkg _ Stage0 -> Nothing GhcPkg _ Stage0 -> Nothing
GhcPkg _ _ -> context Stage0 ghcPkg GhcPkg _ _ -> context Stage0 ghcPkg
Haddock _ -> context Stage1 haddock Haddock _ -> context Stage1 haddock
...@@ -260,7 +257,7 @@ instance H.Builder Builder where ...@@ -260,7 +257,7 @@ instance H.Builder Builder where
unit $ cmd [Cwd output] [path] buildArgs unit $ cmd [Cwd output] [path] buildArgs
unit $ cmd [Cwd output] [path] buildArgs unit $ cmd [Cwd output] [path] buildArgs
GhcPkg Clone _ -> do GhcPkg Copy _ -> do
Stdout pkgDesc <- cmd [path] Stdout pkgDesc <- cmd [path]
[ "--expand-pkgroot" [ "--expand-pkgroot"
, "--no-user-package-db" , "--no-user-package-db"
......
...@@ -7,20 +7,20 @@ import Hadrian.Builder.Tar ...@@ -7,20 +7,20 @@ import Hadrian.Builder.Tar
data CcMode = CompileC | FindCDependencies data CcMode = CompileC | FindCDependencies
data GhcMode = CompileHs | CompileCWithGhc | FindHsDependencies | LinkHs data GhcMode = CompileHs | CompileCWithGhc | FindHsDependencies | LinkHs
data GhcCabalMode = Conf | HsColour | Check | Sdist data ConfigurationInfo = Setup | Flags
data GhcPkgMode = Init | Update | Clone | Unregister | Dependencies data GhcPkgMode = Init | Update | Copy | Unregister | Dependencies
data HaddockMode = BuildPackage | BuildIndex data HaddockMode = BuildPackage | BuildIndex
data Builder = Alex data Builder = Alex
| Ar ArMode Stage | Ar ArMode Stage
| Autoreconf FilePath | Autoreconf FilePath
| DeriveConstants | DeriveConstants
| Cabal ConfigurationInfo Stage
| Cc CcMode Stage | Cc CcMode Stage
| Configure FilePath | Configure FilePath
| GenApply | GenApply
| GenPrimopCode | GenPrimopCode
| Ghc GhcMode Stage | Ghc GhcMode Stage
| GhcCabal GhcCabalMode Stage
| GhcPkg GhcPkgMode Stage | GhcPkg GhcPkgMode Stage
| Haddock HaddockMode | Haddock HaddockMode
| Happy | Happy
...@@ -41,7 +41,6 @@ data Builder = Alex ...@@ -41,7 +41,6 @@ data Builder = Alex
| Tar TarMode | Tar TarMode
| Unlit | Unlit
| Xelatex | Xelatex
| CabalFlags Stage
instance Eq Builder instance Eq Builder
instance Show Builder instance Show Builder
...@@ -7,7 +7,7 @@ import System.Environment ...@@ -7,7 +7,7 @@ import System.Environment
-- for better robustness of the build system. -- for better robustness of the build system.
setupEnvironment :: IO () setupEnvironment :: IO ()
setupEnvironment = do setupEnvironment = do
-- ghc-cabal refuses to work when GHC_PACKAGE_PATH is set (e.g. by Stack) -- Cabal refuses to work when GHC_PACKAGE_PATH is set (e.g. by Stack)
unsetEnv "GHC_PACKAGE_PATH" unsetEnv "GHC_PACKAGE_PATH"
-- in MinGW if PWD is set to a Windows "C:\\" style path then configure -- in MinGW if PWD is set to a Windows "C:\\" style path then configure
......
...@@ -27,16 +27,16 @@ import {-# SOURCE #-} Builder ...@@ -27,16 +27,16 @@ import {-# SOURCE #-} Builder
import Context hiding (stage, package, way) import Context hiding (stage, package, way)
import Expression.Type import Expression.Type
import Hadrian.Expression hiding (Expr, Predicate, Args) import Hadrian.Expression hiding (Expr, Predicate, Args)
import Hadrian.Haskell.Cabal.PackageData (PackageData) import Hadrian.Haskell.Cabal.PackageData
import Hadrian.Oracles.TextFile (readPackageDataFile) import Hadrian.Oracles.TextFile
-- TODO: Get rid of partiality. -- TODO: Get rid of partiality.
-- | Get values from a configured cabal stage. -- | Get values from a configured cabal stage.
getPackageData :: (PackageData -> a) -> Expr a getPackageData :: (PackageData -> a) -> Expr a
getPackageData key = do getPackageData key = do
ctx <- getContext ctx <- getContext
Just cabal <- expr (readPackageDataFile ctx) Just packageData <- expr (readPackageData ctx)
return $ key cabal return $ key packageData
-- | Is the build currently in the provided stage? -- | Is the build currently in the provided stage?
stage :: Stage -> Predicate stage :: Stage -> Predicate
......
...@@ -3,12 +3,12 @@ module GHC ( ...@@ -3,12 +3,12 @@ module GHC (
-- * GHC packages -- * GHC packages
array, base, binary, bytestring, cabal, checkApiAnnotations, checkPpr, array, base, binary, bytestring, cabal, checkApiAnnotations, checkPpr,
compareSizes, compiler, containers, deepseq, deriveConstants, directory, compareSizes, compiler, containers, deepseq, deriveConstants, directory,
filepath, genapply, genprimopcode, ghc, ghcBoot, ghcBootTh, ghcCabal, filepath, genapply, genprimopcode, ghc, ghcBoot, ghcBootTh, ghcCompact,
ghcCompact, ghcHeap, ghci, ghcPkg, ghcPrim, ghcTags, ghcSplit, haddock, ghcHeap, ghci, ghcPkg, ghcPrim, ghcTags, ghcSplit, haddock, haskeline,
haskeline, hsc2hs, hp2ps, hpc, hpcBin, integerGmp, integerSimple, iserv, hsc2hs, hp2ps, hpc, hpcBin, integerGmp, integerSimple, iserv, libffi,
libffi, libiserv, mtl, parsec, parallel, pretty, primitive, process, rts, libiserv, mtl, parsec, parallel, pretty, primitive, process, rts, runGhc,
runGhc, stm, templateHaskell, terminfo, text, time, touchy, transformers, stm, templateHaskell, terminfo, text, time, touchy, transformers, unlit,
unlit, unix, win32, xhtml, ghcPackages, isGhcPackage, defaultPackages, unix, win32, xhtml, ghcPackages, isGhcPackage, defaultPackages,
testsuitePackages, testsuitePackages,
-- * Package information -- * Package information
...@@ -157,20 +157,17 @@ programPath context@Context {..} = do ...@@ -157,20 +157,17 @@ programPath context@Context {..} = do
pgm <- programName context pgm <- programName context
return $ path -/- pgm <.> exe return $ path -/- pgm <.> exe
-- | Some contexts are special: their packages do not have @.cabal@ metadata or -- TODO: This is no longer true -- both @hp2ps@ and @touchy@ appear to have been
-- we cannot run @ghc-cabal@ on them, e.g. because the latter hasn't been built -- Cabal-ised, so we need to drop these special cases.
-- yet (this is the case with the 'ghcCabal' package in 'Stage0'). -- | Some contexts are special: their packages do not have @.cabal@ metadata.
nonCabalContext :: Context -> Bool nonCabalContext :: Context -> Bool
nonCabalContext Context {..} = (package `elem` [ hp2ps nonCabalContext Context {..} = (package `elem` [hp2ps, touchy])
, touchy
])
|| package == ghcCabal && stage == Stage0
-- | Some program packages should not be linked with Haskell main function. -- | Some program packages should not be linked with Haskell main function.
nonHsMainPackage :: Package -> Bool nonHsMainPackage :: Package -> Bool
nonHsMainPackage = (`elem` [ghc, hp2ps, iserv, touchy, unlit]) nonHsMainPackage = (`elem` [ghc, hp2ps, iserv, touchy, unlit])
-- | Path to the autogen directory generated by @ghc-cabal@ of a given 'Context'. -- | Path to the @autogen@ directory generated when configuring a package.
autogenPath :: Context -> Action FilePath autogenPath :: Context -> Action FilePath
autogenPath context@Context {..} autogenPath context@Context {..}
| isLibrary package = autogen "build" | isLibrary package = autogen "build"
......
...@@ -44,7 +44,6 @@ genprimopcode = hsUtil "genprimopcode" ...@@ -44,7 +44,6 @@ genprimopcode = hsUtil "genprimopcode"
ghc = hsPrg "ghc-bin" `setPath` "ghc" ghc = hsPrg "ghc-bin" `setPath` "ghc"
ghcBoot = hsLib "ghc-boot" ghcBoot = hsLib "ghc-boot"
ghcBootTh = hsLib "ghc-boot-th" ghcBootTh = hsLib "ghc-boot-th"
ghcCabal = hsUtil "ghc-cabal"
ghcCompact = hsLib "ghc-compact" ghcCompact = hsLib "ghc-compact"
ghcHeap = hsLib "ghc-heap" ghcHeap = hsLib "ghc-heap"
ghci = hsLib "ghci" ghci = hsLib "ghci"
......
...@@ -17,19 +17,19 @@ import Data.Maybe ...@@ -17,19 +17,19 @@ import Data.Maybe
import Development.Shake import Development.Shake
import Context.Type import Context.Type
import Hadrian.Haskell.Cabal.Type import Hadrian.Haskell.Cabal.CabalData
import Hadrian.Package import Hadrian.Package
import Hadrian.Oracles.TextFile import Hadrian.Oracles.TextFile
-- | Read a Cabal file and return the package version. The Cabal file is tracked. -- | Read a Cabal file and return the package version. The Cabal file is tracked.
pkgVersion :: Context -> Action (Maybe String) pkgVersion :: Context -> Action (Maybe String)
pkgVersion = fmap (fmap version) . readCabalFile pkgVersion = fmap (fmap version) . readCabalData
-- | Read a Cabal file and return the package identifier, e.g. @base-4.10.0.0@. -- | Read a Cabal file and return the package identifier, e.g. @base-4.10.0.0@.
-- The Cabal file is tracked. -- The Cabal file is tracked.
pkgIdentifier :: Context -> Action String pkgIdentifier :: Context -> Action String
pkgIdentifier ctx = do pkgIdentifier ctx = do
cabal <- fromMaybe (error "Cabal file could not be read") <$> readCabalFile ctx cabal <- fromMaybe (error "Cabal file could not be read") <$> readCabalData ctx
return $ if null (version cabal) return $ if null (version cabal)
then name cabal then name cabal
else name cabal ++ "-" ++ version cabal else name cabal ++ "-" ++ version cabal
...@@ -39,8 +39,8 @@ pkgIdentifier ctx = do ...@@ -39,8 +39,8 @@ pkgIdentifier ctx = do
-- returns a crude overapproximation of actual dependencies. The Cabal file is -- returns a crude overapproximation of actual dependencies. The Cabal file is
-- tracked. -- tracked.
pkgDependencies :: Context -> Action (Maybe [PackageName]) pkgDependencies :: Context -> Action (Maybe [PackageName])
pkgDependencies = fmap (fmap (map pkgName . packageDependencies)) . readCabalFile pkgDependencies = fmap (fmap (map pkgName . packageDependencies)) . readCabalData
-- | Read a Cabal file and return the package synopsis. The Cabal file is tracked. -- | Read a Cabal file and return the package synopsis. The Cabal file is tracked.
pkgSynopsis :: Context -> Action (Maybe String) pkgSynopsis :: Context -> Action (Maybe String)
pkgSynopsis = fmap (fmap synopsis) . readCabalFile pkgSynopsis = fmap (fmap synopsis) . readCabalData
module Hadrian.Haskell.Cabal.Type where module Hadrian.Haskell.Cabal.CabalData where
import Development.Shake.Classes import Development.Shake.Classes
import Distribution.PackageDescription (GenericPackageDescription, PackageDescription) import Distribution.PackageDescription
import GHC.Generics import GHC.Generics
import Hadrian.Package.Type import Hadrian.Package.Type
-- | Haskell package metadata extracted from a Cabal file. -- | Haskell package metadata extracted from a Cabal file, without performing
data Cabal = Cabal -- the resolution of package configuration flags and associated conditionals.
-- One consequence is that 'packageDependencies' is an overappoximation of
-- actual package dependencies; for example, both @unix@ and @win32@ packages
-- may be included even if only one of them is required on the target OS.
data CabalData = CabalData
{ name :: PackageName { name :: PackageName
, version :: String , version :: String
, synopsis :: String , synopsis :: String
...@@ -15,9 +19,6 @@ data Cabal = Cabal ...@@ -15,9 +19,6 @@ data Cabal = Cabal
, packageDependencies :: [Package] , packageDependencies :: [Package]
} deriving (Eq, Show, Typeable, Generic) } deriving (Eq, Show, Typeable, Generic)
instance Binary Cabal instance Binary CabalData
instance Hashable CabalData where hashWithSalt salt = hashWithSalt salt . show
instance Hashable Cabal where instance NFData CabalData
hashWithSalt salt = hashWithSalt salt . show
instance NFData Cabal
module Hadrian.Haskell.Cabal.PackageData where module Hadrian.Haskell.Cabal.PackageData where
import Development.Shake.Classes import Development.Shake.Classes
import Hadrian.Package.Type
import GHC.Generics import GHC.Generics
import Hadrian.Package.Type
-- | Most of these fields used to be provided in @package-data.mk@ files. -- | Most of these fields used to be provided in @package-data.mk@ files.
data PackageData = PackageData data PackageData = PackageData
......
...@@ -9,10 +9,10 @@ ...@@ -9,10 +9,10 @@
-- --
-- Extracting Haskell package metadata stored in Cabal files. -- Extracting Haskell package metadata stored in Cabal files.
----------------------------------------------------------------------------- -----------------------------------------------------------------------------
module Hadrian.Haskell.Cabal.Parse module Hadrian.Haskell.Cabal.Parse (
( PackageData (..), parseCabal, parsePackageData, parseCabalPkgId PackageData (..), parseCabalFile, parsePackageData, parseCabalPkgId,
, configurePackage, copyPackage, registerPackage configurePackage, copyPackage, registerPackage
) where ) where
import Data.List.Extra import Data.List.Extra
import Development.Shake import Development.Shake
...@@ -44,8 +44,8 @@ import Context ...@@ -44,8 +44,8 @@ import Context
import Flavour import Flavour
import GHC.Packages import GHC.Packages
import Hadrian.Expression import Hadrian.Expression
import Hadrian.Haskell.Cabal.CabalData
import Hadrian.Haskell.Cabal.PackageData import Hadrian.Haskell.Cabal.PackageData
import Hadrian.Haskell.Cabal.Type
import Hadrian.Oracles.TextFile import Hadrian.Oracles.TextFile
import Hadrian.Target import Hadrian.Target
import Settings import Settings
...@@ -81,8 +81,8 @@ biModules pd = go [ comp | comp@(bi,_,_) <- ...@@ -81,8 +81,8 @@ biModules pd = go [ comp | comp@(bi,_,_) <-
-- corresponding to the 'Stage' it gets from the 'Context', and finalises the -- corresponding to the 'Stage' it gets from the 'Context', and finalises the
-- package description it got from the Cabal file with additional information -- package description it got from the Cabal file with additional information
-- such as platform, compiler version conditionals, and package flags. -- such as platform, compiler version conditionals, and package flags.
parseCabal :: Context -> Action Cabal parseCabalFile :: Context -> Action CabalData
parseCabal context@Context {..} = do parseCabalFile context@Context {..} = do
let file = unsafePkgCabalFile package let file = unsafePkgCabalFile package
-- Read the package description from the Cabal file -- Read the package description from the Cabal file
...@@ -93,7 +93,7 @@ parseCabal context@Context {..} = do ...@@ -93,7 +93,7 @@ parseCabal context@Context {..} = do
(compiler, Just platform, _pgdb) <- liftIO $ (compiler, Just platform, _pgdb) <- liftIO $
C.configure C.silent (Just hcPath) Nothing C.emptyProgramDb C.configure C.silent (Just hcPath) Nothing C.emptyProgramDb
flagList <- interpret (target context (CabalFlags stage) [] []) =<< args <$> flavour flagList <- interpret (target context (Cabal Flags stage) [] []) =<< args <$> flavour
let flags = foldr addFlag mempty flagList let flags = foldr addFlag mempty flagList
where where
addFlag :: String -> C.FlagAssignment -> C.FlagAssignment addFlag :: String -> C.FlagAssignment -> C.FlagAssignment
...@@ -111,19 +111,20 @@ parseCabal context@Context {..} = do ...@@ -111,19 +111,20 @@ parseCabal context@Context {..} = do
findPackageByName' p = fromMaybe (error msg) (findPackageByName p) findPackageByName' p = fromMaybe (error msg) (findPackageByName p)
where where
msg = "Failed to find package " ++ quote (show p) msg = "Failed to find package " ++ quote (show p)
return $ Cabal (C.unPackageName . C.pkgName . C.package $ pd) return $ CabalData (C.unPackageName . C.pkgName . C.package $ pd)
(C.display . C.pkgVersion . C.package $ pd) (C.display . C.pkgVersion . C.package $ pd)
(C.synopsis pd) gpd pd depPkgs (C.synopsis pd) gpd pd depPkgs
-- | This function runs the equivalent of @cabal configure@ using the Cabal -- TODO: Track command line arguments and package configuration flags.
-- library directly, collecting all the configuration options and flags to be -- | Configure a package using the Cabal library by collecting all the command
-- passed to Cabal before invoking it. It 'need's package database entries for -- line arguments (to be passed to the setup script) and package configuration
-- the dependencies of the package the 'Context' points to. -- flags. The function 'need's package database entries for the dependencies of
-- the package the 'Context' points to.
configurePackage :: Context -> Action () configurePackage :: Context -> Action ()
configurePackage context@Context {..} = do configurePackage context@Context {..} = do
putLoud $ "| Configure package " ++ quote (pkgName package) putLoud $ "| Configure package " ++ quote (pkgName package)
Cabal _ _ _ gpd _pd depPkgs <- unsafeReadCabalFile context CabalData _ _ _ gpd _pd depPkgs <- unsafeReadCabalData context
-- Stage packages are those we have in this stage. -- Stage packages are those we have in this stage.
stagePkgs <- stagePackages stage stagePkgs <- stagePackages stage
...@@ -152,8 +153,8 @@ configurePackage context@Context {..} = do ...@@ -152,8 +153,8 @@ configurePackage context@Context {..} = do
-- Compute the list of flags -- Compute the list of flags
-- Compute the Cabal configurartion arguments -- Compute the Cabal configurartion arguments