Skip to content

Commit

Permalink
Per-component new-build support (no Custom support yet).
Browse files Browse the repository at this point in the history
A bit of a megapatch.  Here's what's in it:

* First, a few miscellaneous utility functions and reexports
  in Cabal.  I could have split these into a separate commit
  but I was too lazy to.

* Distribution.Client.Install got refactored:
  instead of using PackageFixedDeps, it uses PackageInstalled
  instead.  That's because the install plan was NOT using
  ComponentDeps in any nontrivial way. And it shouldn't.
  So use a more specific type-class.  I also removed the
  invariant checking and error reporting because it was
  being annoying (we check the invariants already in
  SolverInstallPlan).

* Look at Distribution.Client.ProjectPlanning.Types.
  This contains the primary type change: ElaboratedConfiguredPackage
  is now EITHER a monolithic ElaboratedPackage, or a per-component
  ElaboratedComponent (it should get renamed but I didn't do that
  in this patch.)  These are what we're going to store in our
  plans: if a package we're building has a Setup script which supports
  per-component builds, we'll explode it into a component.  Otherwise
  we'll keep it as a package.  We'll see codepaths for both
  throughout.

* OK, so the expansion happens in ProjectPlanning, mostly in
  'elaborateAndExpandSolverPackage'.  You should review the
  package hash computation code closely.  When we can separate
  components, we compute a hash for each INDEPENDENTLY.  This
  is good: we get more sharing.

* We need to adjust the target resolution and pruning code
  in ProjectOrchestration and ProjectPlanning.  I did a dumb
  but easy idea: if a user mentions 'packagename' in a
  target name, I spray the PackageTarget on every
  possibly relevant IPID in buildTargets', and then pare
  it down later.

* And of course there's code in ProjectBuilding to actual
  do a configure and then build.

Custom doesn't work yet because I need to give them their own
separate component, and teach Cabal how to build them specially.

Signed-off-by: Edward Z. Yang <[email protected]>
  • Loading branch information
ezyang committed Aug 2, 2016
1 parent bd66238 commit 5ae3520
Show file tree
Hide file tree
Showing 24 changed files with 770 additions and 391 deletions.
5 changes: 5 additions & 0 deletions Cabal/Distribution/Package.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ module Distribution.Package (
UnitId(..),
mkUnitId,
mkLegacyUnitId,
unitIdComponentId,
getHSLibraryName,
InstalledPackageId, -- backwards compat

Expand Down Expand Up @@ -176,6 +177,10 @@ mkUnitId = SimpleUnitId . ComponentId
mkLegacyUnitId :: PackageId -> UnitId
mkLegacyUnitId = SimpleUnitId . ComponentId . display

-- | Extract 'ComponentId' from 'UnitId'.
unitIdComponentId :: UnitId -> ComponentId
unitIdComponentId (SimpleUnitId cid) = cid

-- ------------------------------------------------------------
-- * Package source dependencies
-- ------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions Cabal/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ module Distribution.Simple.Configure (configure,
tryGetPersistBuildConfig,
maybeGetPersistBuildConfig,
findDistPref, findDistPrefOrDefault,
mkComponentsGraph,
getInternalPackages,
computeComponentId,
computeCompatPackageKey,
computeCompatPackageName,
Expand Down
9 changes: 9 additions & 0 deletions Cabal/Distribution/Types/PackageDescription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module Distribution.Types.PackageDescription (
updatePackageDescription,
pkgComponents,
pkgBuildableComponents,
enabledComponents,
lookupComponent,
getComponent,
) where
Expand All @@ -57,6 +58,7 @@ import Distribution.Types.Benchmark

import Distribution.Types.Component
import Distribution.Types.ComponentName
import Distribution.Types.ComponentEnabledSpec
import Distribution.Types.SetupBuildInfo
import Distribution.Types.BuildInfo
import Distribution.Types.BuildType
Expand Down Expand Up @@ -346,6 +348,13 @@ pkgComponents pkg =
pkgBuildableComponents :: PackageDescription -> [Component]
pkgBuildableComponents = filter componentBuildable . pkgComponents

-- | A list of all components in the package that are enabled.
--
-- @since 2.0.0.0
--
enabledComponents :: PackageDescription -> ComponentEnabledSpec -> [Component]
enabledComponents pkg enabled = filter (componentEnabled enabled) $ pkgBuildableComponents pkg

lookupComponent :: PackageDescription -> ComponentName -> Maybe Component
lookupComponent pkg CLibName = fmap CLib (library pkg)
lookupComponent pkg (CSubLibName name) =
Expand Down
1 change: 1 addition & 0 deletions cabal-install/Distribution/Client/CmdBuild.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ buildAction (configFlags, configExFlags, installFlags, haddockFlags)
-- repl targets (as opposed to say repl or haddock targets).
selectBuildTargets =
selectTargets
verbosity
BuildDefaultComponents
BuildSpecificComponent

10 changes: 5 additions & 5 deletions cabal-install/Distribution/Client/CmdFreeze.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ module Distribution.Client.CmdFreeze (
) where

import Distribution.Client.ProjectPlanning
( ElaboratedInstallPlan, rebuildInstallPlan )
import Distribution.Client.ProjectConfig
( ProjectConfig(..), ProjectConfigShared(..)
, commandLineFlagsToProjectConfig, writeProjectLocalFreezeConfig
, findProjectRoot )
import Distribution.Client.ProjectPlanning.Types
( ElaboratedConfiguredPackage(..) )
import Distribution.Client.Targets
( UserConstraint(..) )
import Distribution.Solver.Types.ConstraintSource
Expand Down Expand Up @@ -149,16 +147,18 @@ projectFreezeConstraints plan =
flagAssignments =
Map.fromList
[ (pkgname, flags)
| InstallPlan.Configured pkg <- InstallPlan.toList plan
, let flags = pkgFlagAssignment pkg
| InstallPlan.Configured pkg_or_comp <- InstallPlan.toList plan
, let pkg = getElaboratedPackage pkg_or_comp
flags = pkgFlagAssignment pkg
pkgname = packageName pkg
, not (null flags) ]

localPackages :: Map PackageName ()
localPackages =
Map.fromList
[ (packageName pkg, ())
| InstallPlan.Configured pkg <- InstallPlan.toList plan
| InstallPlan.Configured pkg_or_comp <- InstallPlan.toList plan
, let pkg = getElaboratedPackage pkg_or_comp
, pkgLocalToProject pkg
]

1 change: 1 addition & 0 deletions cabal-install/Distribution/Client/CmdRepl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ replAction (configFlags, configExFlags, installFlags, haddockFlags)
-- repl targets (as opposed to say build or haddock targets).
selectReplTargets =
selectTargets
verbosity
ReplDefaultComponent
ReplSpecificComponent

5 changes: 2 additions & 3 deletions cabal-install/Distribution/Client/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ import Distribution.Solver.Types.ConstraintSource
import Distribution.Solver.Types.LabeledPackageConstraint
import Distribution.Solver.Types.OptionalStanza
import qualified Distribution.Solver.Types.PackageIndex as SourcePackageIndex
import Distribution.Solver.Types.PackageFixedDeps
import Distribution.Solver.Types.PkgConfigDb
( PkgConfigDb, readPkgConfigDb )
import Distribution.Solver.Types.SourcePackage as SourcePackage
Expand Down Expand Up @@ -612,12 +611,12 @@ packageStatus installedPkgIndex cpkg =
changes :: Installed.InstalledPackageInfo
-> ReadyPackage
-> [MergeResult PackageIdentifier PackageIdentifier]
changes pkg pkg' = filter changed $
changes pkg (ReadyPackage pkg') = filter changed $
mergeBy (comparing packageName)
-- deps of installed pkg
(resolveInstalledIds $ Installed.depends pkg)
-- deps of configured pkg
(resolveInstalledIds $ CD.nonSetupDeps (depends pkg'))
(resolveInstalledIds $ map confInstId (CD.nonSetupDeps (confPkgDeps pkg')))

-- convert to source pkg ids via index
resolveInstalledIds :: [UnitId] -> [PackageIdentifier]
Expand Down
Loading

0 comments on commit 5ae3520

Please sign in to comment.