[commit: packages/Cabal] ghc-head: Allow the Program programPostConf to update all settings, including env (34a2c8c)
git at git.haskell.org
git at git.haskell.org
Mon Aug 26 23:29:38 CEST 2013
Repository : ssh://git@git.haskell.org/Cabal
On branch : ghc-head
Link : http://git.haskell.org/?p=packages/Cabal.git;a=commit;h=34a2c8cfe4efe716b4b4c81923496b422ec9a844
>---------------------------------------------------------------
commit 34a2c8cfe4efe716b4b4c81923496b422ec9a844
Author: Duncan Coutts <duncan at community.haskell.org>
Date: Sat Aug 10 21:34:30 2013 +0100
Allow the Program programPostConf to update all settings, including env
So rather than only returning the default args it can adjust any of the
ConfiguredProgram settings, including programDefaultArgs as now but now
also the programOverrideArgs and the new programOverrideEnv.
>---------------------------------------------------------------
34a2c8cfe4efe716b4b4c81923496b422ec9a844
Cabal/Distribution/Simple/GHC.hs | 39 +++++++++++++++++-----------
Cabal/Distribution/Simple/LHC.hs | 17 +++++++-----
Cabal/Distribution/Simple/Program/Db.hs | 5 +---
Cabal/Distribution/Simple/Program/Types.hs | 9 +++----
4 files changed, 39 insertions(+), 31 deletions(-)
diff --git a/Cabal/Distribution/Simple/GHC.hs b/Cabal/Distribution/Simple/GHC.hs
index 924b2ac..0500465 100644
--- a/Cabal/Distribution/Simple/GHC.hs
+++ b/Cabal/Distribution/Simple/GHC.hs
@@ -97,7 +97,7 @@ import Distribution.Package
( Package(..), PackageName(..) )
import qualified Distribution.ModuleName as ModuleName
import Distribution.Simple.Program
- ( Program(..), ConfiguredProgram(..), ProgramConfiguration, ProgArg
+ ( Program(..), ConfiguredProgram(..), ProgramConfiguration
, ProgramLocation(..), rawSystemProgram
, rawSystemProgramStdout, rawSystemProgramStdoutConf
, getProgramInvocationOutput
@@ -125,7 +125,7 @@ import Distribution.Text
import Language.Haskell.Extension (Language(..), Extension(..)
,KnownExtension(..))
-import Control.Monad ( unless, when, liftM )
+import Control.Monad ( unless, when )
import Data.Char ( isSpace )
import Data.List
import Data.Maybe ( catMaybes, fromMaybe )
@@ -338,11 +338,15 @@ configureToolchain ghcProg ghcInfo =
[(args, "")] -> args
_ -> [] -- XXX Should should be an error really
- configureGcc :: Verbosity -> ConfiguredProgram -> IO [ProgArg]
- configureGcc v cp = liftM (++ (ccFlags ++ gccLinkerFlags))
- $ configureGcc' v cp
+ configureGcc :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
+ configureGcc v gccProg = do
+ gccProg' <- configureGcc' v gccProg
+ return gccProg' {
+ programDefaultArgs = programDefaultArgs gccProg'
+ ++ ccFlags ++ gccLinkerFlags
+ }
- configureGcc' :: Verbosity -> ConfiguredProgram -> IO [ProgArg]
+ configureGcc' :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
configureGcc'
| isWindows = \_ gccProg -> case programLocation gccProg of
-- if it's found on system then it means we're using the result
@@ -352,15 +356,20 @@ configureToolchain ghcProg ghcInfo =
-- various files:
FoundOnSystem {}
| ghcVersion < Version [6,11] [] ->
- return ["-B" ++ libDir, "-I" ++ includeDir]
- _ -> return []
- | otherwise = \_ _ -> return []
-
- configureLd :: Verbosity -> ConfiguredProgram -> IO [ProgArg]
- configureLd v cp = liftM (++ ldLinkerFlags) $ configureLd' v cp
+ return gccProg { programDefaultArgs = ["-B" ++ libDir,
+ "-I" ++ includeDir] }
+ _ -> return gccProg
+ | otherwise = \_ gccProg -> return gccProg
+
+ configureLd :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
+ configureLd v ldProg = do
+ ldProg' <- configureLd' v ldProg
+ return ldProg' {
+ programDefaultArgs = programDefaultArgs ldProg' ++ ldLinkerFlags
+ }
-- we need to find out if ld supports the -x flag
- configureLd' :: Verbosity -> ConfiguredProgram -> IO [ProgArg]
+ configureLd' :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
configureLd' verbosity ldProg = do
tempDir <- getTemporaryDirectory
ldx <- withTempFile tempDir ".c" $ \testcfile testchnd ->
@@ -378,8 +387,8 @@ configureToolchain ghcProg ghcInfo =
`catchIO` (\_ -> return False)
`catchExit` (\_ -> return False)
if ldx
- then return ["-x"]
- else return []
+ then return ldProg { programDefaultArgs = ["-x"] }
+ else return ldProg
getLanguages :: Verbosity -> ConfiguredProgram -> IO [(Language, Flag)]
getLanguages _ ghcProg
diff --git a/Cabal/Distribution/Simple/LHC.hs b/Cabal/Distribution/Simple/LHC.hs
index 81b2d1a..6697de3 100644
--- a/Cabal/Distribution/Simple/LHC.hs
+++ b/Cabal/Distribution/Simple/LHC.hs
@@ -189,19 +189,22 @@ configureToolchain lhcProg =
programFindLocation prog verbosity
| otherwise = programFindLocation prog
- configureGcc :: Verbosity -> ConfiguredProgram -> IO [ProgArg]
+ configureGcc :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
configureGcc
| isWindows = \_ gccProg -> case programLocation gccProg of
-- if it's found on system then it means we're using the result
-- of programFindLocation above rather than a user-supplied path
-- that means we should add this extra flag to tell ghc's gcc
-- where it lives and thus where gcc can find its various files:
- FoundOnSystem {} -> return ["-B" ++ libDir, "-I" ++ includeDir]
- UserSpecified {} -> return []
- | otherwise = \_ _ -> return []
+ FoundOnSystem {} -> return gccProg {
+ programDefaultArgs = ["-B" ++ libDir,
+ "-I" ++ includeDir]
+ }
+ UserSpecified {} -> return gccProg
+ | otherwise = \_ gccProg -> return gccProg
-- we need to find out if ld supports the -x flag
- configureLd :: Verbosity -> ConfiguredProgram -> IO [ProgArg]
+ configureLd :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
configureLd verbosity ldProg = do
tempDir <- getTemporaryDirectory
ldx <- withTempFile tempDir ".c" $ \testcfile testchnd ->
@@ -219,8 +222,8 @@ configureToolchain lhcProg =
`catchIO` (\_ -> return False)
`catchExit` (\_ -> return False)
if ldx
- then return ["-x"]
- else return []
+ then return ldProg { programDefaultArgs = ["-x"] }
+ else return ldProg
getLanguages :: Verbosity -> ConfiguredProgram -> IO [(Language, Flag)]
getLanguages _ _ = return [(Haskell98, "")]
diff --git a/Cabal/Distribution/Simple/Program/Db.hs b/Cabal/Distribution/Simple/Program/Db.hs
index 14efacc..c41897f 100644
--- a/Cabal/Distribution/Simple/Program/Db.hs
+++ b/Cabal/Distribution/Simple/Program/Db.hs
@@ -294,10 +294,7 @@ configureProgram verbosity prog conf = do
programOverrideEnv = [],
programLocation = location
}
- extraArgs <- programPostConf prog verbosity configuredProg
- let configuredProg' = configuredProg {
- programDefaultArgs = extraArgs
- }
+ configuredProg' <- programPostConf prog verbosity configuredProg
return (updateConfiguredProgs (Map.insert name configuredProg') conf)
diff --git a/Cabal/Distribution/Simple/Program/Types.hs b/Cabal/Distribution/Simple/Program/Types.hs
index dfa6b6c..f816817 100644
--- a/Cabal/Distribution/Simple/Program/Types.hs
+++ b/Cabal/Distribution/Simple/Program/Types.hs
@@ -53,10 +53,9 @@ data Program = Program {
programFindVersion :: Verbosity -> FilePath -> IO (Maybe Version),
-- | A function to do any additional configuration after we have
- -- located the program (and perhaps identified its version). It is
- -- allowed to return additional flags that will be passed to the
- -- program on every invocation.
- programPostConf :: Verbosity -> ConfiguredProgram -> IO [ProgArg]
+ -- located the program (and perhaps identified its version). For example
+ -- it could add args, or environment vars.
+ programPostConf :: Verbosity -> ConfiguredProgram -> IO ConfiguredProgram
}
type ProgArg = String
@@ -119,7 +118,7 @@ simpleProgram name = Program {
programName = name,
programFindLocation = \v -> findProgramLocation v name,
programFindVersion = \_ _ -> return Nothing,
- programPostConf = \_ _ -> return []
+ programPostConf = \_ p -> return p
}
-- | Make a simple 'ConfiguredProgram'.
More information about the ghc-commits
mailing list