Commit 6ea81518 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Finish moving GenericPackageDescription into PackageDescription module

and fix up remaing imports.
hcOptions is back in the PackageDescription module but with a different type.
GenericPackageDescription now derives Show as having the separate pretty
printer is inconvenient and in any case it is incomplete.
parent ff04b336
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.PackageDescription.Types
-- Module : Distribution.PackageDescription
-- Copyright : Isaac Jones 2003-2005
--
-- Maintainer : Isaac Jones <ijones@syntaxpolice.org>
......@@ -39,10 +39,9 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.PackageDescription.Types (
module Distribution.PackageDescription (
-- * Package descriptions
PackageDescription(..),
GenericPackageDescription(..),
emptyPackageDescription,
BuildType(..),
......@@ -65,22 +64,27 @@ module Distribution.PackageDescription.Types (
emptyBuildInfo,
allBuildInfo,
unionBuildInfo,
hcOptions,
-- ** Supplementary build information
HookedBuildInfo,
emptyHookedBuildInfo,
updatePackageDescription,
-- * package configuration
GenericPackageDescription(..),
Flag(..), CondTree(..), ConfVar(..), ConfFlag(..), Condition(..),
) where
import Data.List (nub)
import Data.Monoid (Monoid(mempty, mappend))
import Text.PrettyPrint.HughesPJ
import Distribution.Package (PackageIdentifier(PackageIdentifier))
import Distribution.Version (Version(Version), VersionRange(AnyVersion))
import Distribution.License (License(AllRightsReserved))
import Distribution.Version (Dependency)
import Distribution.Version (Dependency, showVersionRange)
import Distribution.Compiler (CompilerFlavor)
import Distribution.Configuration (CondTree, ConfVar, Flag)
import Distribution.Simple.Utils (currentDir)
import Language.Haskell.Extension (Extension)
......@@ -146,16 +150,6 @@ emptyPackageDescription
extraTmpFiles = []
}
data GenericPackageDescription =
GenericPackageDescription {
packageDescription :: PackageDescription,
genPackageFlags :: [Flag],
condLibrary :: Maybe (CondTree ConfVar [Dependency] Library),
condExecutables :: [(String, CondTree ConfVar [Dependency] Executable)]
}
--deriving (Show)
-- | The type of build system used by this package.
data BuildType
= Simple -- ^ calls @Distribution.Simple.defaultMain@
......@@ -335,6 +329,12 @@ type HookedBuildInfo = (Maybe BuildInfo, [(String, BuildInfo)])
emptyHookedBuildInfo :: HookedBuildInfo
emptyHookedBuildInfo = (Nothing, [])
-- |Select options for a particular Haskell compiler.
hcOptions :: CompilerFlavor -> BuildInfo -> [String]
hcOptions hc bi = [ opt | (hc',opts) <- options bi
, hc' == hc
, opt <- opts ]
-- ------------------------------------------------------------
-- * Utils
-- ------------------------------------------------------------
......@@ -390,3 +390,107 @@ unionBuildInfo b1 b2
where
combine :: (Eq a) => (BuildInfo -> [a]) -> [a]
combine f = nub $ f b1 ++ f b2
-- ---------------------------------------------------------------------------
-- The GenericPackageDescription type
data GenericPackageDescription =
GenericPackageDescription {
packageDescription :: PackageDescription,
genPackageFlags :: [Flag],
condLibrary :: Maybe (CondTree ConfVar [Dependency] Library),
condExecutables :: [(String, CondTree ConfVar [Dependency] Executable)]
}
deriving (Show)
{-
-- XXX: I think we really want a PPrint or Pretty or ShowPretty class.
instance Show GenericPackageDescription where
show (GenericPackageDescription pkg flgs mlib exes) =
showPackageDescription pkg ++ "\n" ++
(render $ vcat $ map ppFlag flgs) ++ "\n" ++
render (maybe empty (\l -> showStanza "Library" (ppCondTree l showDeps)) mlib)
++ "\n" ++
(render $ vcat $
map (\(n,ct) -> showStanza ("Executable " ++ n) (ppCondTree ct showDeps)) exes)
where
ppFlag (MkFlag name desc dflt) =
showStanza ("Flag " ++ name)
((if (null desc) then empty else
text ("Description: " ++ desc)) $+$
text ("Default: " ++ show dflt))
showDeps = fsep . punctuate comma . map showDependency
showStanza h b = text h <+> lbrace $+$ nest 2 b $+$ rbrace
-}
-- | A flag can represent a feature to be included, or a way of linking
-- a target against its dependencies, or in fact whatever you can think of.
data Flag = MkFlag
{ flagName :: String
, flagDescription :: String
, flagDefault :: Bool
}
instance Show Flag where show (MkFlag n _ _) = n
-- | A @ConfFlag@ represents an user-defined flag
data ConfFlag = ConfFlag String
deriving Eq
-- | A @ConfVar@ represents the variable type used.
data ConfVar = OS String
| Arch String
| Flag ConfFlag
| Impl String VersionRange
deriving Eq
instance Show ConfVar where
show (OS n) = "os(" ++ n ++ ")"
show (Arch n) = "arch(" ++ n ++ ")"
show (Flag (ConfFlag f)) = "flag(" ++ f ++ ")"
show (Impl c v) = "impl(" ++ c ++ " " ++ showVersionRange v ++ ")"
-- | A boolean expression parameterized over the variable type used.
data Condition c = Var c
| Lit Bool
| CNot (Condition c)
| COr (Condition c) (Condition c)
| CAnd (Condition c) (Condition c)
instance Show c => Show (Condition c) where
show c = render $ ppCond c
-- | Pretty print a @Condition@.
ppCond :: Show c => Condition c -> Doc
ppCond (Var x) = text (show x)
ppCond (Lit b) = text (show b)
ppCond (CNot c) = char '!' <> parens (ppCond c)
ppCond (COr c1 c2) = parens $ sep [ppCond c1, text "||" <+> ppCond c2]
ppCond (CAnd c1 c2) = parens $ sep [ppCond c1, text "&&" <+> ppCond c2]
data CondTree v c a = CondNode
{ condTreeData :: a
, condTreeConstraints :: c
, condTreeComponents :: [( Condition v
, CondTree v c a
, Maybe (CondTree v c a))]
}
deriving Show
{-
instance (Show v, Show c) => Show (CondTree v c a) where
show t = render $ ppCondTree t (text . show)
ppCondTree :: Show v => CondTree v c a -> (c -> Doc) -> Doc
ppCondTree (CondNode _dat cs ifs) ppD =
(text "build-depends: " <+>
ppD cs)
$+$
(vcat $ map ppIf ifs)
where
ppIf (c,thenTree,mElseTree) =
((text "if" <+> ppCond c <> colon) $$
nest 2 (ppCondTree thenTree ppD))
$+$ (maybe empty (\t -> text "else: " $$ nest 2 (ppCondTree t ppD))
mElseTree)
-}
{-# LANGUAGE CPP #-}
{-# OPTIONS_GHC -cpp #-}
{-# OPTIONS_NHC98 -cpp #-}
{-# OPTIONS_JHC -fcpp #-}
-----------------------------------------------------------------------------
-- |
-- Module : Distribution.PackageDescription.QA
......@@ -46,7 +42,6 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}
module Distribution.PackageDescription.QA (
cabalVersion,
sanityCheckPackage,
-- * Quality Assurance
......@@ -58,24 +53,17 @@ import Data.Maybe (isNothing, catMaybes)
import Control.Monad (when,unless)
import System.Directory (doesFileExist)
import Distribution.PackageDescription.Types
import Distribution.PackageDescription
import Distribution.PackageDescription.Parse
import Distribution.Compiler(CompilerFlavor(..))
import Distribution.License (License(..))
import Distribution.Simple.Utils (cabalVersion)
import Text.PrettyPrint.HughesPJ
import Distribution.Version (Version(..), withinRange, showVersionRange)
import Distribution.Package (PackageIdentifier(..))
import System.FilePath (takeExtension)
-- We only get our own version number when we're building with ourselves
cabalVersion :: Version
#ifdef CABAL_VERSION
cabalVersion = Version [CABAL_VERSION] []
#else
cabalVersion = error "Cabal was not bootstrapped correctly"
#endif
-- ------------------------------------------------------------
-- * Sanity Checking
-- ------------------------------------------------------------
......
......@@ -70,6 +70,13 @@ import Distribution.Simple.Compiler hiding (Flag)
import Distribution.Simple.UserHooks
import Distribution.Package --must not specify imports, since we're exporting moule.
import Distribution.PackageDescription
( PackageDescription(..), GenericPackageDescription
, updatePackageDescription, hasLibs
, HookedBuildInfo, emptyHookedBuildInfo )
import Distribution.PackageDescription.Parse
( readPackageDescription, readHookedBuildInfo )
import Distribution.PackageDescription.Configuration
( flattenPackageDescription )
import Distribution.Simple.Program
( ProgramConfiguration, defaultProgramConfiguration, addKnownProgram
, userSpecifyArgs )
......
......@@ -61,10 +61,13 @@ import Distribution.Package
( PackageIdentifier(..), showPackageId )
import Distribution.PackageDescription
( PackageDescription(..), GenericPackageDescription(..)
, Library(..), Executable(..), BuildInfo(..), finalizePackageDescription
, HookedBuildInfo, sanityCheckPackage, updatePackageDescription
, setupMessage, satisfyDependency, hasLibs
, Library(..), hasLibs, Executable(..), BuildInfo(..)
, HookedBuildInfo, updatePackageDescription
, allBuildInfo, emptyBuildInfo, unionBuildInfo )
import Distribution.PackageDescription.Configuration
( finalizePackageDescription, satisfyDependency )
import Distribution.PackageDescription.QA
( sanityCheckPackage )
import Distribution.ParseUtils
( showDependency )
import Distribution.Simple.Program
......
......@@ -564,7 +564,7 @@ ghcOptions lbi bi odir
then ["-stubdir", odir] else [])
++ (concat [ ["-package", showPackageId pkg] | pkg <- packageDeps lbi ])
++ (if withOptimization lbi then ["-O"] else [])
++ hcOptions GHC (options bi)
++ hcOptions GHC bi
++ extensionsToFlags c (extensions bi)
where c = compiler lbi
......
......@@ -49,7 +49,11 @@ module Distribution.Simple.Haddock (
import Distribution.Compat.ReadP(readP_to_S)
import Distribution.Package (showPackageId)
import Distribution.PackageDescription
import Distribution.ParseUtils(Field(..), readFields, parseCommaList, parseFilePathQ)
(PackageDescription(..), BuildInfo(..), hcOptions,
Library(..), hasLibs, withLib,
Executable(..), withExe)
import Distribution.ParseUtils (Field(..), ParseResult(..), readFields,
parseCommaList, parseFilePathQ)
import Distribution.Simple.Program(ConfiguredProgram(..), requireProgram,
lookupProgram, programPath, ghcPkgProgram,
hscolourProgram, haddockProgram, rawSystemProgram, rawSystemProgramStdoutConf,
......@@ -297,7 +301,7 @@ ghcSimpleOptions lbi bi mockDir
= ["-hide-all-packages"]
++ (concat [ ["-package", showPackageId pkg] | pkg <- packageDeps lbi ])
++ ["-i"]
++ hcOptions GHC (options bi)
++ hcOptions GHC bi
++ ["-i" ++ autogenModulesDir lbi]
++ ["-i" ++ l | l <- nub (hsSourceDirs bi)]
++ ["-i" ++ mockDir]
......
......@@ -45,10 +45,8 @@ module Distribution.Simple.Hugs (
) where
import Distribution.PackageDescription
( PackageDescription(..), BuildInfo(..),
withLib,
Executable(..), withExe, Library(..),
libModules, hcOptions )
( PackageDescription(..), BuildInfo(..), hcOptions,
Executable(..), withExe, Library(..), withLib, libModules )
import Distribution.Simple.Compiler ( Compiler(..), CompilerFlavor(..), Flag )
import Distribution.Simple.Program ( ProgramConfiguration, userMaybeSpecifyPath,
requireProgram, rawSystemProgramConf,
......@@ -187,7 +185,7 @@ build pkg_descr lbi verbosity = do
copyModule cppAll bi srcFile destFile = do
createDirectoryIfMissingVerbose verbosity True (takeDirectory destFile)
(exts, opts, _) <- getOptionsFromSource srcFile
let ghcOpts = hcOptions GHC opts
let ghcOpts = [ op | (GHC, ops) <- opts, op <- ops ]
if cppAll || CPP `elem` exts || "-cpp" `elem` ghcOpts then do
runSimplePreProcessor (ppCpp bi lbi) srcFile destFile verbosity
return ()
......@@ -210,7 +208,7 @@ build pkg_descr lbi verbosity = do
compileFFI :: BuildInfo -> FilePath -> FilePath -> IO ()
compileFFI bi modDir file = do
(_, opts, file_incs) <- getOptionsFromSource file
let ghcOpts = hcOptions GHC opts
let ghcOpts = [ op | (GHC, ops) <- opts, op <- ops ]
let pkg_incs = ["\"" ++ inc ++ "\"" | inc <- includes bi]
let incs = nub (sort (file_incs ++ includeOpts ghcOpts ++ pkg_incs))
let pathFlag = "-P" ++ modDir ++ [searchPathSeparator]
......@@ -369,7 +367,7 @@ install verbosity libDir installProgDir binDir targetProgDir buildPref (progpref
let targetName = "\"" ++ (targetDir </> hugsMainFilename exe) ++ "\""
-- FIX (HUGS): use extensions, and options from file too?
-- see http://hackage.haskell.org/trac/hackage/ticket/43
let hugsOptions = hcOptions Hugs (options (buildInfo exe))
let hugsOptions = hcOptions Hugs (buildInfo exe)
let baseExeFile = progprefix ++ (exeName exe) ++ progsuffix
let exeFile = case os of
Windows _ -> binDir </> baseExeFile <.> ".bat"
......
......@@ -142,7 +142,7 @@ constructJHCCmdLine :: LocalBuildInfo -> BuildInfo -> FilePath -> Verbosity -> [
constructJHCCmdLine lbi bi _odir verbosity =
(if verbosity >= deafening then ["-v"] else [])
++ extensionsToFlags (compiler lbi) (extensions bi)
++ hcOptions JHC (options bi)
++ hcOptions JHC bi
++ ["--noauto","-i-"]
++ ["-i", autogenModulesDir lbi]
++ concat [["-i", l] | l <- nub (hsSourceDirs bi)]
......
......@@ -145,7 +145,7 @@ build pkg_descr lbi verbosity = do
++ nhcVerbosityOptions verbosity
++ ["-d", targetDir, "-hidir", targetDir]
++ extensionFlags
++ maybe [] (hcOptions NHC . options . libBuildInfo)
++ maybe [] (hcOptions NHC . libBuildInfo)
(library pkg_descr)
++ concat [ ["-package", pkgName pkg] | pkg <- packageDeps lbi ]
++ inFiles
......@@ -203,7 +203,7 @@ build pkg_descr lbi verbosity = do
++ nhcVerbosityOptions verbosity
++ ["-d", targetDir, "-hidir", targetDir]
++ extensionFlags
++ maybe [] (hcOptions NHC . options . libBuildInfo)
++ maybe [] (hcOptions NHC . libBuildInfo)
(library pkg_descr)
++ concat [ ["-package", pkgName pkg] | pkg <- packageDeps lbi ]
++ inFiles
......
......@@ -21,11 +21,9 @@ import Distribution.Simple.Utils
import Distribution.Simple.Configure
( configCompiler, getInstalledPackages,
configDependency )
import Distribution.PackageDescription
( readPackageDescription,
GenericPackageDescription(packageDescription),
PackageDescription(..),
BuildType(..), cabalVersion )
import Distribution.PackageDescription
( PackageDescription(..), GenericPackageDescription(..), BuildType(..) )
import Distribution.PackageDescription.Parse ( readPackageDescription )
import Distribution.Simple.BuildPaths ( distPref, exeExtension )
import Distribution.Simple.Program ( ProgramConfiguration,
emptyProgramConfiguration,
......
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