Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dcoutts/project-config-explici…
Browse files Browse the repository at this point in the history
…t-includes'
  • Loading branch information
23Skidoo committed Jan 3, 2018
2 parents b5f9914 + d4f80a5 commit ab585e8
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 30 deletions.
7 changes: 6 additions & 1 deletion Cabal/doc/nix-local-build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ The following settings control the behavior of the dependency solver:
Package configuration options
-----------------------------

Package options affect the building of specific packages. There are two
Package options affect the building of specific packages. There are three
ways a package option can be specified:

- They can be specified at the top-level, in which case they apply only
Expand All @@ -871,6 +871,11 @@ ways a package option can be specified:
apply to the build of the package, whether or not it is local or
external.

- They can be specified inside an ``all-packages`` stanza, in which case they
apply to all packages, local ones from the project and also external
dependencies.


For example, the following options specify that :cfg-field:`optimization`
should be turned off for all local packages, and that ``bytestring`` (possibly
an external dependency) should be built with ``-fno-state-hack``::
Expand Down
77 changes: 59 additions & 18 deletions cabal-install/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ data LegacyProjectConfig = LegacyProjectConfig {
legacyPackagesNamed :: [Dependency],

legacySharedConfig :: LegacySharedConfig,
legacyAllConfig :: LegacyPackageConfig,
legacyLocalConfig :: LegacyPackageConfig,
legacySpecificConfig :: MapMappend PackageName LegacyPackageConfig
} deriving Generic
Expand Down Expand Up @@ -226,6 +227,7 @@ convertLegacyProjectConfig
legacyPackagesNamed,
legacySharedConfig = LegacySharedConfig globalFlags configShFlags
configExFlags installSharedFlags,
legacyAllConfig,
legacyLocalConfig = LegacyPackageConfig configFlags installPerPkgFlags
haddockFlags,
legacySpecificConfig
Expand All @@ -238,15 +240,18 @@ convertLegacyProjectConfig
projectPackagesNamed = legacyPackagesNamed,

projectConfigBuildOnly = configBuildOnly,
projectConfigShared = configAllPackages,
projectConfigShared = configPackagesShared,
projectConfigProvenance = mempty,
projectConfigAllPackages = configAllPackages,
projectConfigLocalPackages = configLocalPackages,
projectConfigSpecificPackage = fmap perPackage legacySpecificConfig
}
where
configAllPackages = convertLegacyPerPackageFlags g i h
where LegacyPackageConfig g i h = legacyAllConfig
configLocalPackages = convertLegacyPerPackageFlags
configFlags installPerPkgFlags haddockFlags
configAllPackages = convertLegacyAllPackageFlags
configPackagesShared= convertLegacyAllPackageFlags
globalFlags (configFlags <> configShFlags)
configExFlags installSharedFlags
configBuildOnly = convertLegacyBuildOnlyFlags
Expand Down Expand Up @@ -436,6 +441,7 @@ convertToLegacyProjectConfig
projectPackagesOptional,
projectPackagesRepo,
projectPackagesNamed,
projectConfigAllPackages,
projectConfigLocalPackages,
projectConfigSpecificPackage
} =
Expand All @@ -445,6 +451,8 @@ convertToLegacyProjectConfig
legacyPackagesRepo = projectPackagesRepo,
legacyPackagesNamed = projectPackagesNamed,
legacySharedConfig = convertToLegacySharedConfig projectConfig,
legacyAllConfig = convertToLegacyPerPackageConfig
projectConfigAllPackages,
legacyLocalConfig = convertToLegacyAllPackageConfig projectConfig
<> convertToLegacyPerPackageConfig
projectConfigLocalPackages,
Expand Down Expand Up @@ -1030,6 +1038,7 @@ legacyPackageConfigFieldDescrs =
legacyPackageConfigSectionDescrs :: [SectionDescr LegacyProjectConfig]
legacyPackageConfigSectionDescrs =
[ packageRepoSectionDescr
, allPackagesOptionsSectionDescr
, packageSpecificOptionsSectionDescr
, liftSection
legacyLocalConfig
Expand Down Expand Up @@ -1074,26 +1083,58 @@ packageRepoSectionDescr =
}
}

-- | The definitions of all the fields that can appear in the @package pkgfoo@
-- and @all-packages@ sections of the @cabal.project@-format files.
--
packageSpecificOptionsFieldDescrs :: [FieldDescr LegacyPackageConfig]
packageSpecificOptionsFieldDescrs =
legacyPackageConfigFieldDescrs
++ programOptionsFieldDescrs
(configProgramArgs . legacyConfigureFlags)
(\args pkgconf -> pkgconf {
legacyConfigureFlags = (legacyConfigureFlags pkgconf) {
configProgramArgs = args
}
}
)
++ liftFields
legacyConfigureFlags
(\flags pkgconf -> pkgconf {
legacyConfigureFlags = flags
}
)
programLocationsFieldDescrs

-- | The definition of the @all-packages@ sections of the
-- @cabal.project@-format files. This is the one that applies to all packages
-- used anywhere by the project, locally or as dependencies.
--
allPackagesOptionsSectionDescr :: SectionDescr LegacyProjectConfig
allPackagesOptionsSectionDescr =
SectionDescr {
sectionName = "all-packages",
sectionFields = packageSpecificOptionsFieldDescrs,
sectionSubsections = [],
sectionGet = (\x->[("", x)])
. legacyAllConfig,
sectionSet =
\lineno unused pkgsconf projconf -> do
unless (null unused) $
syntaxError lineno "the section 'all-packages' takes no arguments"
return projconf {
legacyAllConfig = legacyAllConfig projconf <> pkgsconf
},
sectionEmpty = mempty
}

-- | The definition of the @package pkgfoo@ sections of the @cabal.project@-format
-- files. This section is per-package name.
--
packageSpecificOptionsSectionDescr :: SectionDescr LegacyProjectConfig
packageSpecificOptionsSectionDescr =
SectionDescr {
sectionName = "package",
sectionFields = legacyPackageConfigFieldDescrs
++ programOptionsFieldDescrs
(configProgramArgs . legacyConfigureFlags)
(\args pkgconf -> pkgconf {
legacyConfigureFlags = (legacyConfigureFlags pkgconf) {
configProgramArgs = args
}
}
)
++ liftFields
legacyConfigureFlags
(\flags pkgconf -> pkgconf {
legacyConfigureFlags = flags
}
)
programLocationsFieldDescrs,
sectionFields = packageSpecificOptionsFieldDescrs,
sectionSubsections = [],
sectionGet = \projconf ->
[ (display pkgname, pkgconf)
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.
projectConfigAllPackages :: PackageConfig,

-- | Configuration to be applied to *local* packages; i.e.,
-- any packages which are explicitly named in `cabal.project`.
projectConfigLocalPackages :: PackageConfig,
Expand Down
21 changes: 14 additions & 7 deletions cabal-install/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ rebuildInstallPlan verbosity
, ElaboratedSharedConfig )
phaseElaboratePlan ProjectConfig {
projectConfigShared,
projectConfigAllPackages,
projectConfigLocalPackages,
projectConfigSpecificPackage,
projectConfigBuildOnly
Expand Down Expand Up @@ -617,6 +618,7 @@ rebuildInstallPlan verbosity
sourcePackageHashes
defaultInstallDirs
projectConfigShared
projectConfigAllPackages
projectConfigLocalPackages
(getMapMappend projectConfigSpecificPackage)
let instantiatedPlan = instantiateInstallPlan elaboratedPlan
Expand Down Expand Up @@ -1142,6 +1144,7 @@ elaborateInstallPlan
-> InstallDirs.InstallDirTemplates
-> ProjectConfigShared
-> PackageConfig
-> PackageConfig
-> Map PackageName PackageConfig
-> LogProgress (ElaboratedInstallPlan, ElaboratedSharedConfig)
elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
Expand All @@ -1151,6 +1154,7 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
sourcePackageHashes
defaultInstallDirs
sharedPackageConfig
allPackagesConfig
localPackagesConfig
perPackageConfig = do
x <- elaboratedInstallPlan
Expand Down Expand Up @@ -1758,14 +1762,17 @@ 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 =
-- This is where we merge the options from the project config that
-- apply to all packages, all project local packages, and to specific
-- named packages
global `mappend` local `mappend` perpkg
where
local = f localPackagesConfig
global = f allPackagesConfig
local | isLocalToProject pkg
= f localPackagesConfig
| otherwise
= mempty
perpkg = maybe mempty f (Map.lookup (packageName pkg) perPackageConfig)

inplacePackageDbs = storePackageDbs
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
line, the last one is now preferred, so e.g. '-f+dev -f-dev' is
now equivalent to '-f-dev' (#4452).
* Removed support for building cabal-install with GHC < 7.10 (#4870).
* New 'all-packages' section in 'cabal.project' files that applies
options to all packages, not just those local to the project.

2.0.0.1 Mikhail Glushenkov <[email protected]> December 2017
* Support for GHC's numeric -g debug levels (#4673).
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
, projectConfigAllPackages = x9 } =
[ ProjectConfig { projectPackages = x0'
, projectPackagesOptional = x1'
, projectPackagesRepo = x2'
Expand All @@ -307,10 +309,11 @@ instance Arbitrary ProjectConfig where
, projectConfigProvenance = x6'
, projectConfigLocalPackages = x7'
, projectConfigSpecificPackage = (MapMappend
(fmap getNonMEmpty x8')) }
| ((x0', x1', x2', x3'), (x4', x5', x6', x7', x8'))
(fmap getNonMEmpty x8'))
, projectConfigAllPackages = 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 ab585e8

Please sign in to comment.