Skip to content

Commit

Permalink
Apply global configuration to all packages in project commands
Browse files Browse the repository at this point in the history
The global configuration in ~/.cabal/config or CABAL_CONFIG should be applied to
all packages, even in the project (new-*) commands. Previously, package
configuration fields applied only to packages in the actual project. A new
field (projectConfigGlobalPackages) is added to ProjectConfig to track the
global package configuration.

See also: haskell#3883, haskell#4646
  • Loading branch information
ttuegel committed Nov 15, 2017
1 parent 00889bc commit b2a2dbe
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 17 deletions.
7 changes: 4 additions & 3 deletions cabal-install/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,9 @@ convertLegacyGlobalConfig
savedHaddockFlags = haddockFlags
} =
mempty {
projectConfigShared = configAllPackages,
projectConfigLocalPackages = configLocalPackages,
projectConfigBuildOnly = configBuildOnly
projectConfigShared = configAllPackages,
projectConfigGlobalPackages = configLocalPackages,
projectConfigBuildOnly = configBuildOnly
}
where
--TODO: [code cleanup] eliminate use of default*Flags here and specify the
Expand Down Expand Up @@ -240,6 +240,7 @@ convertLegacyProjectConfig
projectConfigBuildOnly = configBuildOnly,
projectConfigShared = configAllPackages,
projectConfigProvenance = mempty,
projectConfigGlobalPackages = mempty,
projectConfigLocalPackages = configLocalPackages,
projectConfigSpecificPackage = fmap perPackage legacySpecificConfig
}
Expand Down
4 changes: 4 additions & 0 deletions cabal-install/Distribution/Client/ProjectConfig/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ data ProjectConfig
projectConfigShared :: ProjectConfigShared,
projectConfigProvenance :: Set ProjectConfigProvenance,

-- | Configuration to be applied to all packages,
-- whether named in `cabal.project` or not.
projectConfigGlobalPackages :: PackageConfig,

-- | Configuration to be applied to *local* packages; i.e.,
-- any packages which are explicitly named in `cabal.project`.
projectConfigLocalPackages :: PackageConfig,
Expand Down
23 changes: 14 additions & 9 deletions cabal-install/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ rebuildInstallPlan verbosity
, ElaboratedSharedConfig )
phaseElaboratePlan ProjectConfig {
projectConfigShared,
projectConfigGlobalPackages,
projectConfigLocalPackages,
projectConfigSpecificPackage,
projectConfigBuildOnly
Expand Down Expand Up @@ -613,6 +614,7 @@ rebuildInstallPlan verbosity
sourcePackageHashes
defaultInstallDirs
projectConfigShared
projectConfigGlobalPackages
projectConfigLocalPackages
(getMapMappend projectConfigSpecificPackage)
let instantiatedPlan = instantiateInstallPlan elaboratedPlan
Expand Down Expand Up @@ -1138,6 +1140,7 @@ elaborateInstallPlan
-> InstallDirs.InstallDirTemplates
-> ProjectConfigShared
-> PackageConfig
-> PackageConfig
-> Map PackageName PackageConfig
-> LogProgress (ElaboratedInstallPlan, ElaboratedSharedConfig)
elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
Expand All @@ -1146,7 +1149,8 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
solverPlan localPackages
sourcePackageHashes
defaultInstallDirs
sharedPackageConfig
sharedConfig
globalPackagesConfig
localPackagesConfig
perPackageConfig = do
x <- elaboratedInstallPlan
Expand Down Expand Up @@ -1240,7 +1244,7 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
-- For ease of testing, we let per-component builds be toggled
-- at the top level
cuz_flag
| fromFlagOrDefault True (projectConfigPerComponent sharedPackageConfig)
| fromFlagOrDefault True (projectConfigPerComponent sharedConfig)
= []
| otherwise = cuz "you passed --disable-per-component"

Expand Down Expand Up @@ -1754,14 +1758,15 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB

lookupPerPkgOption :: (Package pkg, Monoid m)
=> pkg -> (PackageConfig -> m) -> m
lookupPerPkgOption pkg f
-- the project config specifies values that apply to packages local to
-- but by default non-local packages get all default config values
-- the project, and can specify per-package values for any package,
| isLocalToProject pkg = local `mappend` perpkg
| otherwise = perpkg
lookupPerPkgOption pkg f = mconcat [global, local, perpkg]
where
local = f localPackagesConfig
local
-- the project config specifies values that apply to packages local to
-- but by default non-local packages get all default config values
-- the project, and can specify per-package values for any package,
| isLocalToProject pkg = f localPackagesConfig
| otherwise = mempty
global = f globalPackagesConfig
perpkg = maybe mempty f (Map.lookup (packageName pkg) perPackageConfig)

inplacePackageDbs = storePackageDbs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ instance Arbitrary ProjectConfig where
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> arbitrary
<*> (MapMappend . fmap getNonMEmpty . Map.fromList
<$> shortListOf 3 arbitrary)
-- package entries with no content are equivalent to
Expand All @@ -297,7 +298,8 @@ instance Arbitrary ProjectConfig where
, projectConfigShared = x5
, projectConfigProvenance = x6
, projectConfigLocalPackages = x7
, projectConfigSpecificPackage = x8 } =
, projectConfigSpecificPackage = x8
, projectConfigGlobalPackages = x9 } =
[ ProjectConfig { projectPackages = x0'
, projectPackagesOptional = x1'
, projectPackagesRepo = x2'
Expand All @@ -306,11 +308,12 @@ instance Arbitrary ProjectConfig where
, projectConfigShared = x5'
, projectConfigProvenance = x6'
, projectConfigLocalPackages = x7'
, projectConfigSpecificPackage = (MapMappend
(fmap getNonMEmpty x8')) }
| ((x0', x1', x2', x3'), (x4', x5', x6', x7', x8'))
, projectConfigSpecificPackage =
MapMappend (fmap getNonMEmpty x8')
, projectConfigGlobalPackages = x9' }
| ((x0', x1', x2', x3'), (x4', x5', x6', x7', x8', x9'))
<- shrink ((x0, x1, x2, x3),
(x4, x5, x6, x7, fmap NonMEmpty (getMapMappend x8)))
(x4, x5, x6, x7, fmap NonMEmpty (getMapMappend x8), x9))
]

newtype PackageLocationString
Expand Down

0 comments on commit b2a2dbe

Please sign in to comment.