Commit 33754a88 authored by refold's avatar refold
Browse files

Add two new fields to package environment file.

Adds two new fields: 'constraints' and 'preferences'. Example:

```
constraints: foo ==1.0,
             foo +use_blah -use_blurb

preferences: bar ==2.0, baz ==3.0
```
parent 026f9ca3
...@@ -24,7 +24,8 @@ import Distribution.Client.Config ( SavedConfig(..), commentSavedConfig, ...@@ -24,7 +24,8 @@ import Distribution.Client.Config ( SavedConfig(..), commentSavedConfig,
configFieldDescriptions, configFieldDescriptions,
installDirsFields, defaultCompiler ) installDirsFields, defaultCompiler )
import Distribution.Client.ParseUtils ( parseFields, ppFields, ppSection ) import Distribution.Client.ParseUtils ( parseFields, ppFields, ppSection )
import Distribution.Client.Setup ( GlobalFlags(..), InstallFlags(..) ) import Distribution.Client.Setup ( GlobalFlags(..), ConfigExFlags(..)
, InstallFlags(..) )
import Distribution.Simple.Compiler ( PackageDB(..) ) import Distribution.Simple.Compiler ( PackageDB(..) )
import Distribution.Simple.InstallDirs ( InstallDirs(..), PathTemplate, import Distribution.Simple.InstallDirs ( InstallDirs(..), PathTemplate,
toPathTemplate ) toPathTemplate )
...@@ -32,6 +33,7 @@ import Distribution.Simple.Setup ( Flag(..), ConfigFlags(..), ...@@ -32,6 +33,7 @@ import Distribution.Simple.Setup ( Flag(..), ConfigFlags(..),
fromFlagOrDefault, toFlag ) fromFlagOrDefault, toFlag )
import Distribution.Simple.Utils ( notice, warn, lowercase ) import Distribution.Simple.Utils ( notice, warn, lowercase )
import Distribution.ParseUtils ( FieldDescr(..), ParseResult(..), import Distribution.ParseUtils ( FieldDescr(..), ParseResult(..),
commaListField,
liftField, lineNo, locatedErrorMsg, liftField, lineNo, locatedErrorMsg,
parseFilePathQ, readFields, parseFilePathQ, readFields,
showPWarning, simpleField, warning ) showPWarning, simpleField, warning )
...@@ -48,15 +50,14 @@ import Text.PrettyPrint ( ($+$) ) ...@@ -48,15 +50,14 @@ import Text.PrettyPrint ( ($+$) )
import qualified Text.PrettyPrint as Disp import qualified Text.PrettyPrint as Disp
import qualified Distribution.Compat.ReadP as Parse import qualified Distribution.Compat.ReadP as Parse
import qualified Distribution.ParseUtils as ParseUtils ( Field(..) ) import qualified Distribution.ParseUtils as ParseUtils ( Field(..) )
import qualified Distribution.Text as Text
-- --
-- * Configuration saved in the package environment file -- * Configuration saved in the package environment file
-- --
-- TODO: add a 'constraints' field (really needed? there is already -- TODO: would be nice to remove duplication between D.C.PackageEnvironment and
-- 'constraint'), remove duplication between D.C.PackageEnvironment and -- D.C.Config.
-- D.C.Config
data PackageEnvironment = PackageEnvironment { data PackageEnvironment = PackageEnvironment {
pkgEnvInherit :: Flag FilePath, pkgEnvInherit :: Flag FilePath,
pkgEnvSavedConfig :: SavedConfig pkgEnvSavedConfig :: SavedConfig
...@@ -192,17 +193,45 @@ pkgEnvFieldDescrs = [ ...@@ -192,17 +193,45 @@ pkgEnvFieldDescrs = [
simpleField "inherit" simpleField "inherit"
(fromFlagOrDefault Disp.empty . fmap Disp.text) (optional parseFilePathQ) (fromFlagOrDefault Disp.empty . fmap Disp.text) (optional parseFilePathQ)
pkgEnvInherit (\v pkgEnv -> pkgEnv { pkgEnvInherit = v }) pkgEnvInherit (\v pkgEnv -> pkgEnv { pkgEnvInherit = v })
-- FIXME: Should we make these fields part of ~/.cabal/config ?
, commaListField "constraints"
Text.disp Text.parse
(configExConstraints . savedConfigureExFlags . pkgEnvSavedConfig)
(\v pkgEnv -> updateConfigureExFlags pkgEnv
(\flags -> flags { configExConstraints = v }))
, commaListField "preferences"
Text.disp Text.parse
(configPreferences . savedConfigureExFlags . pkgEnvSavedConfig)
(\v pkgEnv -> updateConfigureExFlags pkgEnv
(\flags -> flags { configPreferences = v }))
] ]
++ map toPkgEnv configFieldDescriptions ++ map toPkgEnv configFieldDescriptions'
where where
optional = Parse.option mempty . fmap toFlag optional = Parse.option mempty . fmap toFlag
configFieldDescriptions' :: [FieldDescr SavedConfig]
configFieldDescriptions' = filter
(\(FieldDescr name _ _) -> name /= "preference" && name /= "constraint")
configFieldDescriptions
toPkgEnv :: FieldDescr SavedConfig -> FieldDescr PackageEnvironment toPkgEnv :: FieldDescr SavedConfig -> FieldDescr PackageEnvironment
toPkgEnv fieldDescr = toPkgEnv fieldDescr =
liftField pkgEnvSavedConfig liftField pkgEnvSavedConfig
(\savedConfig pkgEnv -> pkgEnv { pkgEnvSavedConfig = savedConfig}) (\savedConfig pkgEnv -> pkgEnv { pkgEnvSavedConfig = savedConfig})
fieldDescr fieldDescr
updateConfigureExFlags :: PackageEnvironment
-> (ConfigExFlags -> ConfigExFlags)
-> PackageEnvironment
updateConfigureExFlags pkgEnv f = pkgEnv {
pkgEnvSavedConfig = (pkgEnvSavedConfig pkgEnv) {
savedConfigureExFlags = f . savedConfigureExFlags . pkgEnvSavedConfig
$ pkgEnv
}
}
-- | Read the package environment file. -- | Read the package environment file.
readPackageEnvironmentFile :: PackageEnvironment -> FilePath readPackageEnvironmentFile :: PackageEnvironment -> FilePath
-> IO (Maybe (ParseResult PackageEnvironment)) -> IO (Maybe (ParseResult PackageEnvironment))
......
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