From b2a2dbe340e00e8f4b4403f45df4f2c26f98ff7a Mon Sep 17 00:00:00 2001 From: Thomas Tuegel Date: Wed, 25 Oct 2017 14:25:37 -0500 Subject: [PATCH] Apply global configuration to all packages in project commands 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: #3883, #4646 --- .../Client/ProjectConfig/Legacy.hs | 7 +++--- .../Client/ProjectConfig/Types.hs | 4 ++++ .../Distribution/Client/ProjectPlanning.hs | 23 +++++++++++-------- .../Distribution/Client/ProjectConfig.hs | 13 +++++++---- 4 files changed, 30 insertions(+), 17 deletions(-) diff --git a/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs b/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs index f584040c64c..8375d25cb5e 100644 --- a/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs +++ b/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs @@ -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 @@ -240,6 +240,7 @@ convertLegacyProjectConfig projectConfigBuildOnly = configBuildOnly, projectConfigShared = configAllPackages, projectConfigProvenance = mempty, + projectConfigGlobalPackages = mempty, projectConfigLocalPackages = configLocalPackages, projectConfigSpecificPackage = fmap perPackage legacySpecificConfig } diff --git a/cabal-install/Distribution/Client/ProjectConfig/Types.hs b/cabal-install/Distribution/Client/ProjectConfig/Types.hs index c93e17c15f4..7ebe463ca61 100644 --- a/cabal-install/Distribution/Client/ProjectConfig/Types.hs +++ b/cabal-install/Distribution/Client/ProjectConfig/Types.hs @@ -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, diff --git a/cabal-install/Distribution/Client/ProjectPlanning.hs b/cabal-install/Distribution/Client/ProjectPlanning.hs index bb93c286229..3eccb0fad9b 100644 --- a/cabal-install/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/Distribution/Client/ProjectPlanning.hs @@ -586,6 +586,7 @@ rebuildInstallPlan verbosity , ElaboratedSharedConfig ) phaseElaboratePlan ProjectConfig { projectConfigShared, + projectConfigGlobalPackages, projectConfigLocalPackages, projectConfigSpecificPackage, projectConfigBuildOnly @@ -613,6 +614,7 @@ rebuildInstallPlan verbosity sourcePackageHashes defaultInstallDirs projectConfigShared + projectConfigGlobalPackages projectConfigLocalPackages (getMapMappend projectConfigSpecificPackage) let instantiatedPlan = instantiateInstallPlan elaboratedPlan @@ -1138,6 +1140,7 @@ elaborateInstallPlan -> InstallDirs.InstallDirTemplates -> ProjectConfigShared -> PackageConfig + -> PackageConfig -> Map PackageName PackageConfig -> LogProgress (ElaboratedInstallPlan, ElaboratedSharedConfig) elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB @@ -1146,7 +1149,8 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB solverPlan localPackages sourcePackageHashes defaultInstallDirs - sharedPackageConfig + sharedConfig + globalPackagesConfig localPackagesConfig perPackageConfig = do x <- elaboratedInstallPlan @@ -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" @@ -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 diff --git a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs index 4124c4e51c0..e554e20b79b 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs @@ -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 @@ -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' @@ -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