Skip to content

Commit e002ad4

Browse files
committed
Wire up extra-packages to be included in the plan
So you can now add `extra-packages: foo` to the cabal.projct file and then `cabal (new-)build foo`. The extra packages are included into the install plan and they are also resolved as build targets. Currently this only uses the "any valid package name" target syntax which means you can use `foo` but not `foo:tests` or any of the other variations.
1 parent 76bcf71 commit e002ad4

File tree

5 files changed

+62
-27
lines changed

5 files changed

+62
-27
lines changed

cabal-install/Distribution/Client/ProjectConfig.hs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ import Distribution.Client.Config
6969

7070
import Distribution.Solver.Types.SourcePackage
7171
import Distribution.Solver.Types.Settings
72+
import Distribution.Solver.Types.PackageConstraint
73+
( PackageProperty(..) )
7274

7375
import Distribution.Package
7476
( PackageName, PackageId, packageId, UnitId )
@@ -884,7 +886,7 @@ mplusMaybeT ma mb = do
884886
-- paths.
885887
--
886888
readSourcePackage :: Verbosity -> ProjectPackageLocation
887-
-> Rebuild UnresolvedSourcePackage
889+
-> Rebuild (PackageSpecifier UnresolvedSourcePackage)
888890
readSourcePackage verbosity (ProjectPackageLocalCabalFile cabalFile) =
889891
readSourcePackage verbosity (ProjectPackageLocalDirectory dir cabalFile)
890892
where
@@ -894,17 +896,29 @@ readSourcePackage verbosity (ProjectPackageLocalDirectory dir cabalFile) = do
894896
monitorFiles [monitorFileHashed cabalFile]
895897
root <- askRoot
896898
pkgdesc <- liftIO $ readGenericPackageDescription verbosity (root </> cabalFile)
897-
return SourcePackage {
899+
return $ SpecificSourcePackage SourcePackage {
898900
packageInfoId = packageId pkgdesc,
899901
packageDescription = pkgdesc,
900902
packageSource = LocalUnpackedPackage (root </> dir),
901903
packageDescrOverride = Nothing
902904
}
905+
906+
readSourcePackage _ (ProjectPackageNamed (Dependency pkgname verrange)) =
907+
return $ NamedPackage pkgname [PackagePropertyVersion verrange]
908+
903909
readSourcePackage _verbosity _ =
904910
fail $ "TODO: add support for fetching and reading local tarballs, remote "
905911
++ "tarballs, remote repos and passing named packages through"
906912

907913

914+
-- TODO: add something like this, here or in the project planning
915+
-- Based on the package location, which packages will be built inplace in the
916+
-- build tree vs placed in the store. This has various implications on what we
917+
-- can do with the package, e.g. can we run tests, ghci etc.
918+
--
919+
-- packageIsLocalToProject :: ProjectPackageLocation -> Bool
920+
921+
908922
---------------------------------------------
909923
-- Checking configuration sanity
910924
--

cabal-install/Distribution/Client/ProjectOrchestration.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ import Distribution.Client.ProjectBuilding
104104
import Distribution.Client.ProjectPlanOutput
105105

106106
import Distribution.Client.Types
107-
( GenericReadyPackage(..), UnresolvedSourcePackage )
107+
( GenericReadyPackage(..), UnresolvedSourcePackage
108+
, PackageSpecifier(..) )
108109
import qualified Distribution.Client.InstallPlan as InstallPlan
109110
import Distribution.Client.TargetSelector
110111
( TargetSelector(..)
@@ -154,7 +155,7 @@ data ProjectBaseContext = ProjectBaseContext {
154155
distDirLayout :: DistDirLayout,
155156
cabalDirLayout :: CabalDirLayout,
156157
projectConfig :: ProjectConfig,
157-
localPackages :: [UnresolvedSourcePackage],
158+
localPackages :: [PackageSpecifier UnresolvedSourcePackage],
158159
buildSettings :: BuildTimeSettings
159160
}
160161

cabal-install/Distribution/Client/ProjectPlanning.hs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ sanityCheckElaboratedPackage ElaboratedConfiguredPackage{..}
292292
rebuildProjectConfig :: Verbosity
293293
-> DistDirLayout
294294
-> ProjectConfig
295-
-> IO (ProjectConfig, [UnresolvedSourcePackage])
295+
-> IO (ProjectConfig,
296+
[PackageSpecifier UnresolvedSourcePackage])
296297
rebuildProjectConfig verbosity
297298
distDirLayout@DistDirLayout {
298299
distProjectRootDirectory,
@@ -334,7 +335,8 @@ rebuildProjectConfig verbosity
334335
-- Look for all the cabal packages in the project
335336
-- some of which may be local src dirs, tarballs etc
336337
--
337-
phaseReadLocalPackages :: ProjectConfig -> Rebuild [UnresolvedSourcePackage]
338+
phaseReadLocalPackages :: ProjectConfig
339+
-> Rebuild [PackageSpecifier UnresolvedSourcePackage]
338340
phaseReadLocalPackages projectConfig = do
339341
localCabalFiles <- findProjectPackages distDirLayout projectConfig
340342
mapM (readSourcePackage verbosity) localCabalFiles
@@ -356,7 +358,7 @@ rebuildProjectConfig verbosity
356358
rebuildInstallPlan :: Verbosity
357359
-> DistDirLayout -> CabalDirLayout
358360
-> ProjectConfig
359-
-> [UnresolvedSourcePackage]
361+
-> [PackageSpecifier UnresolvedSourcePackage]
360362
-> IO ( ElaboratedInstallPlan -- with store packages
361363
, ElaboratedInstallPlan -- with source packages
362364
, ElaboratedSharedConfig )
@@ -508,7 +510,7 @@ rebuildInstallPlan verbosity
508510
--
509511
phaseRunSolver :: ProjectConfig
510512
-> (Compiler, Platform, ProgramDb)
511-
-> [UnresolvedSourcePackage]
513+
-> [PackageSpecifier UnresolvedSourcePackage]
512514
-> Rebuild (SolverInstallPlan, PkgConfigDb)
513515
phaseRunSolver projectConfig@ProjectConfig {
514516
projectConfigShared,
@@ -556,7 +558,7 @@ rebuildInstallPlan verbosity
556558
Map.fromList
557559
[ (pkgname, stanzas)
558560
| pkg <- localPackages
559-
, let pkgname = packageName pkg
561+
, let pkgname = pkgSpecifierTarget pkg
560562
testsEnabled = lookupLocalPackageConfig
561563
packageConfigTests
562564
projectConfig pkgname
@@ -578,7 +580,7 @@ rebuildInstallPlan verbosity
578580
-> (Compiler, Platform, ProgramDb)
579581
-> PkgConfigDb
580582
-> SolverInstallPlan
581-
-> [SourcePackage loc]
583+
-> [PackageSpecifier (SourcePackage loc)]
582584
-> Rebuild ( ElaboratedInstallPlan
583585
, ElaboratedSharedConfig )
584586
phaseElaboratePlan ProjectConfig {
@@ -887,7 +889,7 @@ planPackages :: Verbosity
887889
-> InstalledPackageIndex
888890
-> SourcePackageDb
889891
-> PkgConfigDb
890-
-> [UnresolvedSourcePackage]
892+
-> [PackageSpecifier UnresolvedSourcePackage]
891893
-> Map PackageName (Map OptionalStanza Bool)
892894
-> Progress String String SolverInstallPlan
893895
planPackages verbosity comp platform solver SolverSettings{..}
@@ -967,7 +969,7 @@ planPackages verbosity comp platform solver SolverSettings{..}
967969
-- enable stanza preference where the user did not specify
968970
[ PackageStanzasPreference pkgname stanzas
969971
| pkg <- localPackages
970-
, let pkgname = packageName pkg
972+
, let pkgname = pkgSpecifierTarget pkg
971973
stanzaM = Map.findWithDefault Map.empty pkgname pkgStanzasEnable
972974
stanzas = [ stanza | stanza <- [minBound..maxBound]
973975
, Map.lookup stanza stanzaM == Nothing ]
@@ -981,7 +983,7 @@ planPackages verbosity comp platform solver SolverSettings{..}
981983
(PackagePropertyStanzas stanzas))
982984
ConstraintSourceConfigFlagOrTarget
983985
| pkg <- localPackages
984-
, let pkgname = packageName pkg
986+
, let pkgname = pkgSpecifierTarget pkg
985987
stanzaM = Map.findWithDefault Map.empty pkgname pkgStanzasEnable
986988
stanzas = [ stanza | stanza <- [minBound..maxBound]
987989
, Map.lookup stanza stanzaM == Just True ]
@@ -1009,7 +1011,7 @@ planPackages verbosity comp platform solver SolverSettings{..}
10091011
| let flags = solverSettingFlagAssignment
10101012
, not (null flags)
10111013
, pkg <- localPackages
1012-
, let pkgname = packageName pkg ]
1014+
, let pkgname = pkgSpecifierTarget pkg ]
10131015

10141016
$ stdResolverParams
10151017

@@ -1018,7 +1020,7 @@ planPackages verbosity comp platform solver SolverSettings{..}
10181020
-- its own addDefaultSetupDependencies that is not appropriate for us.
10191021
basicInstallPolicy
10201022
installedPkgIndex sourcePkgDb
1021-
(map SpecificSourcePackage localPackages)
1023+
localPackages
10221024

10231025

10241026
------------------------------------------------------------------------------
@@ -1130,7 +1132,7 @@ elaborateInstallPlan
11301132
-> DistDirLayout
11311133
-> StoreDirLayout
11321134
-> SolverInstallPlan
1133-
-> [SourcePackage loc]
1135+
-> [PackageSpecifier (SourcePackage loc)]
11341136
-> Map PackageId PackageSourceHash
11351137
-> InstallDirs.InstallDirTemplates
11361138
-> ProjectConfigShared
@@ -1779,15 +1781,25 @@ elaborateInstallPlan verbosity platform compiler compilerprogdb pkgConfigDB
17791781
$ map packageId
17801782
$ SolverInstallPlan.reverseDependencyClosure
17811783
solverPlan
1782-
[ PlannedId (packageId pkg)
1783-
| pkg <- localPackages ]
1784+
(map PlannedId (Set.toList pkgsLocalToProject))
17841785

17851786
isLocalToProject :: Package pkg => pkg -> Bool
17861787
isLocalToProject pkg = Set.member (packageId pkg)
17871788
pkgsLocalToProject
17881789

17891790
pkgsLocalToProject :: Set PackageId
1790-
pkgsLocalToProject = Set.fromList [ packageId pkg | pkg <- localPackages ]
1791+
pkgsLocalToProject =
1792+
Set.fromList (catMaybes (map shouldBeLocal localPackages))
1793+
--TODO: localPackages is a misnomer, it's all project packages
1794+
-- here is where we decide which ones will be local!
1795+
where
1796+
shouldBeLocal :: PackageSpecifier (SourcePackage loc) -> Maybe PackageId
1797+
shouldBeLocal NamedPackage{} = Nothing
1798+
shouldBeLocal (SpecificSourcePackage pkg) = Just (packageId pkg)
1799+
-- TODO: It's not actually obvious for all of the
1800+
-- 'ProjectPackageLocation's that they should all be local. We might
1801+
-- need to provide the user with a choice.
1802+
-- Also, review use of SourcePackage's loc vs ProjectPackageLocation
17911803

17921804
pkgsUseSharedLibrary :: Set PackageId
17931805
pkgsUseSharedLibrary =

cabal-install/Distribution/Client/TargetSelector.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import Distribution.Version
4242
( mkVersion )
4343
import Distribution.Types.UnqualComponentName ( unUnqualComponentName )
4444
import Distribution.Client.Types
45-
( PackageLocation(..) )
45+
( PackageLocation(..), PackageSpecifier(..) )
4646

4747
import Distribution.Verbosity
4848
import Distribution.PackageDescription
@@ -202,22 +202,23 @@ instance Binary SubComponentTarget
202202
-- error if any are unrecognised. The possible target selectors are based on
203203
-- the available packages (and their locations).
204204
--
205-
readTargetSelectors :: [SourcePackage (PackageLocation a)]
205+
readTargetSelectors :: [PackageSpecifier (SourcePackage (PackageLocation a))]
206206
-> [String]
207207
-> IO (Either [TargetSelectorProblem]
208208
[TargetSelector PackageId])
209209
readTargetSelectors = readTargetSelectorsWith defaultDirActions
210210

211211
readTargetSelectorsWith :: (Applicative m, Monad m) => DirActions m
212-
-> [SourcePackage (PackageLocation a)]
212+
-> [PackageSpecifier (SourcePackage (PackageLocation a))]
213213
-> [String]
214214
-> m (Either [TargetSelectorProblem]
215215
[TargetSelector PackageId])
216216
readTargetSelectorsWith dirActions@DirActions{..} pkgs targetStrs =
217217
case parseTargetStrings targetStrs of
218218
([], utargets) -> do
219219
utargets' <- mapM (getTargetStringFileStatus dirActions) utargets
220-
pkgs' <- mapM (selectPackageInfo dirActions) pkgs
220+
pkgs' <- sequence [ selectPackageInfo dirActions pkg
221+
| SpecificSourcePackage pkg <- pkgs ]
221222
cwd <- getCurrentDirectory
222223
let (cwdPkg, otherPkgs) = selectCwdPackage cwd pkgs'
223224
case resolveTargetSelectors cwdPkg otherPkgs utargets' of

cabal-install/tests/IntegrationTests2.hs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import Distribution.Client.ProjectBuilding
1818
import Distribution.Client.ProjectOrchestration
1919
( resolveTargets, TargetProblemCommon(..), distinctTargetComponents )
2020
import Distribution.Client.Types
21-
( PackageLocation(..), UnresolvedSourcePackage )
21+
( PackageLocation(..), UnresolvedSourcePackage
22+
, PackageSpecifier(..) )
2223
import Distribution.Client.Targets
2324
( UserConstraint(..), UserConstraintScope(UserAnyQualifier) )
2425
import qualified Distribution.Client.InstallPlan as InstallPlan
@@ -370,7 +371,10 @@ testTargetSelectorAmbiguous reportSubCase = do
370371
-> [SourcePackage (PackageLocation a)]
371372
-> Assertion
372373
assertAmbiguous str tss pkgs = do
373-
res <- readTargetSelectorsWith fakeDirActions pkgs [str]
374+
res <- readTargetSelectorsWith
375+
fakeDirActions
376+
(map SpecificSourcePackage pkgs)
377+
[str]
374378
case res of
375379
Left [TargetSelectorAmbiguous _ tss'] ->
376380
sort (map snd tss') @?= sort tss
@@ -382,7 +386,10 @@ testTargetSelectorAmbiguous reportSubCase = do
382386
-> [SourcePackage (PackageLocation a)]
383387
-> Assertion
384388
assertUnambiguous str ts pkgs = do
385-
res <- readTargetSelectorsWith fakeDirActions pkgs [str]
389+
res <- readTargetSelectorsWith
390+
fakeDirActions
391+
(map SpecificSourcePackage pkgs)
392+
[str]
386393
case res of
387394
Right [ts'] -> ts' @?= ts
388395
_ -> assertFailure $ "expected Right [Target...], "
@@ -1478,7 +1485,7 @@ dirActions testdir =
14781485
type ProjDetails = (DistDirLayout,
14791486
CabalDirLayout,
14801487
ProjectConfig,
1481-
[UnresolvedSourcePackage],
1488+
[PackageSpecifier UnresolvedSourcePackage],
14821489
BuildTimeSettings)
14831490

14841491
configureProject :: FilePath -> ProjectConfig -> IO ProjDetails

0 commit comments

Comments
 (0)