2
2
{-# LANGUAGE NamedFieldPuns #-}
3
3
{-# LANGUAGE RecordWildCards #-}
4
4
{-# LANGUAGE ScopedTypeVariables #-}
5
+ {-# LANGUAGE TupleSections #-}
5
6
6
7
-- | cabal-install CLI command: build
7
8
module Distribution.Client.CmdInstall
@@ -104,6 +105,7 @@ import Distribution.Client.Types
104
105
, PackageSpecifier (.. )
105
106
, SourcePackageDb (.. )
106
107
, UnresolvedSourcePackage
108
+ , pkgSpecifierTarget
107
109
)
108
110
import Distribution.Client.Types.OverwritePolicy
109
111
( OverwritePolicy (.. )
@@ -371,7 +373,7 @@ installAction flags@NixStyleFlags{extraFlags = clientInstallFlags', ..} targetSt
371
373
372
374
-- First, we need to learn about what's available to be installed.
373
375
localBaseCtx <-
374
- establishProjectBaseContext reducedVerbosity cliConfig InstallCommand
376
+ establishProjectBaseContext reducedVerbosity baseCliConfig InstallCommand
375
377
let localDistDirLayout = distDirLayout localBaseCtx
376
378
pkgDb <-
377
379
projectConfigWithBuilderRepoContext
@@ -432,7 +434,7 @@ installAction flags@NixStyleFlags{extraFlags = clientInstallFlags', ..} targetSt
432
434
withoutProject globalConfig = do
433
435
tss <- traverse (parseWithoutProjectTargetSelector verbosity) targetStrings'
434
436
let
435
- projectConfig = globalConfig <> cliConfig
437
+ projectConfig = globalConfig <> baseCliConfig
436
438
437
439
ProjectConfigBuildOnly
438
440
{ projectConfigLogsDir
@@ -478,10 +480,17 @@ installAction flags@NixStyleFlags{extraFlags = clientInstallFlags', ..} targetSt
478
480
479
481
return (packageSpecifiers, uris, packageTargets, projectConfig)
480
482
481
- (specs, uris, targetSelectors, config ) <-
483
+ (specs, uris, targetSelectors, baseConfig ) <-
482
484
withProjectOrGlobalConfig verbosity ignoreProject globalConfigFlag withProject withoutProject
483
485
486
+ -- We compute the base context again to determine packages available in the
487
+ -- project to be installed, so we can list the available package names when
488
+ -- the "all:..." variants of the target selectors are used.
489
+ localPkgs <- localPackages <$> establishProjectBaseContext verbosity baseConfig InstallCommand
490
+
484
491
let
492
+ config = addLocalConfigToPkgs baseConfig (map pkgSpecifierTarget specs ++ concatMap (targetPkgNames localPkgs) targetSelectors)
493
+
485
494
ProjectConfig
486
495
{ projectConfigBuildOnly =
487
496
ProjectConfigBuildOnly
@@ -631,8 +640,7 @@ installAction flags@NixStyleFlags{extraFlags = clientInstallFlags', ..} targetSt
631
640
globalFlags
632
641
flags{configFlags = configFlags'}
633
642
clientInstallFlags'
634
- cliConfig = addLocalConfigToTargets baseCliConfig targetStrings
635
- globalConfigFlag = projectConfigConfigFile (projectConfigShared cliConfig)
643
+ globalConfigFlag = projectConfigConfigFile (projectConfigShared baseCliConfig)
636
644
637
645
-- Do the install action for each executable in the install configuration.
638
646
traverseInstall :: InstallAction -> InstallCfg -> IO ()
@@ -641,17 +649,35 @@ installAction flags@NixStyleFlags{extraFlags = clientInstallFlags', ..} targetSt
641
649
actionOnExe <- action v overwritePolicy <$> prepareExeInstall cfg
642
650
traverse_ actionOnExe . Map. toList $ targetsMap buildCtx
643
651
644
- -- | Treat all direct targets of install command as local packages: #8637
645
- addLocalConfigToTargets :: ProjectConfig -> [String ] -> ProjectConfig
646
- addLocalConfigToTargets config targetStrings =
652
+ -- | Treat all direct targets of install command as local packages: #8637 and later #7297, #8909, #7236.
653
+ addLocalConfigToPkgs :: ProjectConfig -> [PackageName ] -> ProjectConfig
654
+ addLocalConfigToPkgs config pkgs =
647
655
config
648
656
{ projectConfigSpecificPackage =
649
657
projectConfigSpecificPackage config
650
658
<> MapMappend (Map. fromList targetPackageConfigs)
651
659
}
652
660
where
653
661
localConfig = projectConfigLocalPackages config
654
- targetPackageConfigs = map (\ x -> (mkPackageName x, localConfig)) targetStrings
662
+ targetPackageConfigs = map (,localConfig) pkgs
663
+
664
+ targetPkgNames
665
+ :: [PackageSpecifier UnresolvedSourcePackage ]
666
+ -- ^ The local packages, to resolve 'TargetAllPackages' selectors
667
+ -> TargetSelector
668
+ -> [PackageName ]
669
+ targetPkgNames localPkgs = \ case
670
+ TargetPackage _ pkgIds _ -> map pkgName pkgIds
671
+ TargetPackageNamed name _ -> [name]
672
+ TargetAllPackages _ -> map pkgSpecifierTarget localPkgs
673
+ -- Note how the target may select a component only, but we will always apply
674
+ -- the local flags to the whole package in which that component is contained.
675
+ -- The reason is that our finest level of configuration is per-package, so
676
+ -- there is no interface to configure options to a component only. It is not
677
+ -- trivial to say whether we could indeed support per-component configuration
678
+ -- because of legacy packages which we may always have to build whole.
679
+ TargetComponent pkgId _ _ -> [pkgName pkgId]
680
+ TargetComponentUnknown name _ _ -> [name]
655
681
656
682
-- | Verify that invalid config options were not passed to the install command.
657
683
--
0 commit comments