Skip to content

Commit

Permalink
Apply command line flags to install packages (#8637)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickdoc committed Feb 18, 2023
1 parent ecc92a3 commit b4faa29
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
23 changes: 18 additions & 5 deletions cabal-install/src/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import Distribution.Client.Types
, SourcePackageDb(..) )
import qualified Distribution.Client.InstallPlan as InstallPlan
import Distribution.Package
( Package(..), PackageName, unPackageName )
( Package(..), PackageName, mkPackageName, unPackageName )
import Distribution.Types.PackageId
( PackageIdentifier(..) )
import Distribution.Client.ProjectConfig
Expand All @@ -53,6 +53,7 @@ import Distribution.Client.ProjectFlags (ProjectFlags (..))
import Distribution.Client.ProjectConfig.Types
( ProjectConfig(..), ProjectConfigShared(..)
, ProjectConfigBuildOnly(..), PackageConfig(..)
, MapMappend(..)
, getMapLast, getMapMappend, projectConfigLogsDir
, projectConfigStoreDir, projectConfigBuildOnly
, projectConfigConfigFile )
Expand Down Expand Up @@ -430,12 +431,24 @@ installAction flags@NixStyleFlags { extraFlags = clientInstallFlags', .. } targe
configFlags' = disableTestsBenchsByDefault configFlags
verbosity = fromFlagOrDefault normal (configVerbosity configFlags')
ignoreProject = flagIgnoreProject projectFlags
cliConfig = commandLineFlagsToProjectConfig
globalFlags
flags { configFlags = configFlags' }
clientInstallFlags'
baseCliConfig = commandLineFlagsToProjectConfig
globalFlags
flags { configFlags = configFlags' }
clientInstallFlags'
cliConfig = addLocalConfigToTargets baseCliConfig targetStrings
globalConfigFlag = projectConfigConfigFile (projectConfigShared cliConfig)

-- | Treat all direct targets of install command as local packages: #8637
addLocalConfigToTargets :: ProjectConfig -> [String] -> ProjectConfig
addLocalConfigToTargets config targetStrings
= config {
projectConfigSpecificPackage = projectConfigSpecificPackage config
<> MapMappend (Map.fromList targetPackageConfigs)
}
where
localConfig = projectConfigLocalPackages config
targetPackageConfigs = map (\x -> (mkPackageName x, localConfig)) targetStrings

-- | Verify that invalid config options were not passed to the install command.
--
-- If an invalid configuration is found the command will @die'@.
Expand Down
13 changes: 13 additions & 0 deletions changelog.d/issue-8637
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
synopsis: Apply command line flags to install packages
packages: cabal-install
prs: #8779
issues: #8637

description: {

- Command line flags usually only apply to "local" packages (packages specified
in the cabal.project). This change causes the v2-install command to ignore
that distinction to better match the expected behavior for packages specified
directly in the command.

}

0 comments on commit b4faa29

Please sign in to comment.