From 581f8e93d12c3951543ebbe28a99b1f598fc01fe Mon Sep 17 00:00:00 2001 From: Patrick Dougherty Date: Sat, 18 Feb 2023 11:03:46 -0600 Subject: [PATCH 1/2] Apply command line flags to install packages (#8637) --- .../src/Distribution/Client/CmdInstall.hs | 23 +++++++++++++++---- changelog.d/issue-8637 | 13 +++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 changelog.d/issue-8637 diff --git a/cabal-install/src/Distribution/Client/CmdInstall.hs b/cabal-install/src/Distribution/Client/CmdInstall.hs index cd1254b5fe1..94a4737a24d 100644 --- a/cabal-install/src/Distribution/Client/CmdInstall.hs +++ b/cabal-install/src/Distribution/Client/CmdInstall.hs @@ -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 @@ -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 ) @@ -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'@. diff --git a/changelog.d/issue-8637 b/changelog.d/issue-8637 new file mode 100644 index 00000000000..b584e187761 --- /dev/null +++ b/changelog.d/issue-8637 @@ -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. + +} From 9fb6f526cc30125d0252568ec82a6e1e93c90097 Mon Sep 17 00:00:00 2001 From: gbaz Date: Thu, 23 Feb 2023 14:22:30 -0500 Subject: [PATCH 2/2] remove expectBroken on NonIgnoredConfigs test --- .../PackageTests/LinkerOptions/NonignoredConfigs/cabal.test.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/cabal.test.hs b/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/cabal.test.hs index 2e8dac23a20..9da924366f4 100644 --- a/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/cabal.test.hs +++ b/cabal-testsuite/PackageTests/LinkerOptions/NonignoredConfigs/cabal.test.hs @@ -50,7 +50,7 @@ linkConfigFlags Dynamic = lrun :: [Linking] lrun = [Static, Dynamic, Static, Dynamic] -main = cabalTest . expectBroken 8744 $ do +main = cabalTest $ do -- Skip if on Windows, since my default Chocolatey Windows setup (and the CI -- server setup at the time, presumably) lacks support for dynamic builds -- since the base package appears to be static only, lacking e.g. ‘.dyn_o’