From b8ca8f0d93b8c57fb671292412c4f6a29a3b7ce7 Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Sat, 14 Dec 2019 20:58:59 +0200 Subject: [PATCH 1/2] Implement cabal install -z Resolve #5919 Resolve #6410 Add `withProjectOrGlobalConfigIgn` to unify the behaviour with `-z` in `cabal repl` --- .../Distribution/Client/CmdInstall.hs | 20 +++++++++++++++---- .../Client/CmdInstall/ClientInstallFlags.hs | 8 +++++++- cabal-install/Distribution/Client/CmdRepl.hs | 13 ++++-------- cabal-install/Distribution/Client/Config.hs | 13 ++++++------ .../Distribution/Client/ProjectConfig.hs | 19 ++++++++++++++++++ .../Distribution/Client/ProjectConfig.hs | 1 + 6 files changed, 54 insertions(+), 20 deletions(-) diff --git a/cabal-install/Distribution/Client/CmdInstall.hs b/cabal-install/Distribution/Client/CmdInstall.hs index 7481f1554cb..b5a71d1e35b 100644 --- a/cabal-install/Distribution/Client/CmdInstall.hs +++ b/cabal-install/Distribution/Client/CmdInstall.hs @@ -73,7 +73,7 @@ import Distribution.Client.IndexUtils ( getSourcePackages, getInstalledPackages ) import Distribution.Client.ProjectConfig ( readGlobalConfig, projectConfigWithBuilderRepoContext - , resolveBuildTimeSettings, withProjectOrGlobalConfig ) + , resolveBuildTimeSettings, withProjectOrGlobalConfigIgn ) import Distribution.Client.ProjectPlanning ( storePackageInstallDirs' ) import qualified Distribution.Simple.InstallDirs as InstallDirs @@ -249,6 +249,7 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags targetFilter = if installLibs then Just LibKind else Just ExeKind targetStrings' = if null targetStrings then ["."] else targetStrings + withProject :: IO ([PackageSpecifier UnresolvedSourcePackage], [TargetSelector], ProjectConfig) withProject = do let verbosity' = lessVerbose verbosity @@ -369,6 +370,7 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags return (specs ++ packageSpecifiers, selectors ++ packageTargets, projectConfig localBaseCtx) + withoutProject :: ProjectConfig -> IO ([PackageSpecifier pkg], [TargetSelector], ProjectConfig) withoutProject globalConfig = do let parsePkg pkgName @@ -420,8 +422,11 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags packageTargets = flip TargetPackageNamed Nothing . pkgName <$> packageIds return (packageSpecifiers, packageTargets, projectConfig) - (specs, selectors, config) <- withProjectOrGlobalConfig verbosity globalConfigFlag - withProject withoutProject + let + ignoreProject = fromFlagOrDefault False (cinstIgnoreProject clientInstallFlags) + + (specs, selectors, config) <- + withProjectOrGlobalConfigIgn ignoreProject verbosity globalConfigFlag withProject withoutProject home <- getHomeDirectory let @@ -513,6 +518,13 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags -- installables correctly. For that, we need a place to put a -- temporary dist directory. globalTmp <- getTemporaryDirectory + + -- if we are installing executables, we shouldn't take into account + -- environment specifiers. + let envSpecs' :: [PackageSpecifier a] + envSpecs' | installLibs = envSpecs + | otherwise = [] + withTempDirectory verbosity globalTmp @@ -522,7 +534,7 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags verbosity config tmpDir - (envSpecs ++ specs) + (envSpecs' ++ specs) InstallCommand buildCtx <- diff --git a/cabal-install/Distribution/Client/CmdInstall/ClientInstallFlags.hs b/cabal-install/Distribution/Client/CmdInstall/ClientInstallFlags.hs index 3ab39c7f10f..8071aef664b 100644 --- a/cabal-install/Distribution/Client/CmdInstall/ClientInstallFlags.hs +++ b/cabal-install/Distribution/Client/CmdInstall/ClientInstallFlags.hs @@ -27,7 +27,8 @@ data InstallMethod = InstallMethodCopy instance Binary InstallMethod data ClientInstallFlags = ClientInstallFlags - { cinstInstallLibs :: Flag Bool + { cinstInstallLibs :: Flag Bool + , cinstIgnoreProject :: Flag Bool , cinstEnvironmentPath :: Flag FilePath , cinstOverwritePolicy :: Flag OverwritePolicy , cinstInstallMethod :: Flag InstallMethod @@ -46,6 +47,7 @@ instance Binary ClientInstallFlags defaultClientInstallFlags :: ClientInstallFlags defaultClientInstallFlags = ClientInstallFlags { cinstInstallLibs = toFlag False + , cinstIgnoreProject = toFlag False , cinstEnvironmentPath = mempty , cinstOverwritePolicy = mempty , cinstInstallMethod = mempty @@ -58,6 +60,10 @@ clientInstallOptions _ = "Install libraries rather than executables from the target package." cinstInstallLibs (\v flags -> flags { cinstInstallLibs = v }) trueArg + , option "z" ["ignore-project"] + "Ignore local project configuration" + cinstIgnoreProject (\v flags -> flags { cinstIgnoreProject = v }) + trueArg , option [] ["package-env", "env"] "Set the environment file that may be modified." cinstEnvironmentPath (\pf flags -> flags { cinstEnvironmentPath = pf }) diff --git a/cabal-install/Distribution/Client/CmdRepl.hs b/cabal-install/Distribution/Client/CmdRepl.hs index 3eaaab25e34..da907921d2c 100644 --- a/cabal-install/Distribution/Client/CmdRepl.hs +++ b/cabal-install/Distribution/Client/CmdRepl.hs @@ -30,15 +30,13 @@ import qualified Distribution.Client.InstallPlan as InstallPlan import Distribution.Client.ProjectBuilding ( rebuildTargetsDryRun, improveInstallPlanWithUpToDatePackages ) import Distribution.Client.ProjectConfig - ( ProjectConfig(..), withProjectOrGlobalConfig - , projectConfigConfigFile, readGlobalConfig ) + ( ProjectConfig(..), withProjectOrGlobalConfigIgn + , projectConfigConfigFile ) import Distribution.Client.ProjectOrchestration import Distribution.Client.ProjectPlanning ( ElaboratedSharedConfig(..), ElaboratedInstallPlan ) import Distribution.Client.ProjectPlanning.Types ( elabOrderExeDependencies ) -import Distribution.Client.RebuildMonad - ( runRebuild ) import Distribution.Client.Setup ( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags ) import qualified Distribution.Client.Setup as Client @@ -223,11 +221,8 @@ replAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags, r with = withProject cliConfig verbosity targetStrings without config = withoutProject (config <> cliConfig) verbosity targetStrings - (baseCtx, targetSelectors, finalizer, replType) <- if ignoreProject - then do - globalConfig <- runRebuild "" $ readGlobalConfig verbosity globalConfigFlag - without globalConfig - else withProjectOrGlobalConfig verbosity globalConfigFlag with without + (baseCtx, targetSelectors, finalizer, replType) <- + withProjectOrGlobalConfigIgn ignoreProject verbosity globalConfigFlag with without when (buildSettingOnlyDeps (buildSettings baseCtx)) $ die' verbosity $ "The repl command does not support '--only-dependencies'. " diff --git a/cabal-install/Distribution/Client/Config.hs b/cabal-install/Distribution/Client/Config.hs index c3082fe1a8b..cc3abced976 100644 --- a/cabal-install/Distribution/Client/Config.hs +++ b/cabal-install/Distribution/Client/Config.hs @@ -337,12 +337,13 @@ instance Semigroup SavedConfig where combine = combine' savedInstallFlags lastNonEmptyNL = lastNonEmptyNL' savedInstallFlags - combinedSavedClientInstallFlags = ClientInstallFlags { - cinstInstallLibs = combine cinstInstallLibs, - cinstEnvironmentPath = combine cinstEnvironmentPath, - cinstOverwritePolicy = combine cinstOverwritePolicy, - cinstInstallMethod = combine cinstInstallMethod, - cinstInstalldir = combine cinstInstalldir + combinedSavedClientInstallFlags = ClientInstallFlags + { cinstInstallLibs = combine cinstInstallLibs + , cinstIgnoreProject = combine cinstIgnoreProject + , cinstEnvironmentPath = combine cinstEnvironmentPath + , cinstOverwritePolicy = combine cinstOverwritePolicy + , cinstInstallMethod = combine cinstInstallMethod + , cinstInstalldir = combine cinstInstalldir } where combine = combine' savedClientInstallFlags diff --git a/cabal-install/Distribution/Client/ProjectConfig.hs b/cabal-install/Distribution/Client/ProjectConfig.hs index fc96ca7a5c3..34d845b52a3 100644 --- a/cabal-install/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/Distribution/Client/ProjectConfig.hs @@ -28,6 +28,7 @@ module Distribution.Client.ProjectConfig ( readGlobalConfig, readProjectLocalFreezeConfig, withProjectOrGlobalConfig, + withProjectOrGlobalConfigIgn, writeProjectLocalExtraConfig, writeProjectLocalFreezeConfig, writeProjectConfigFile, @@ -451,6 +452,24 @@ renderBadProjectRoot :: BadProjectRoot -> String renderBadProjectRoot (BadProjectRootExplicitFile projectFile) = "The given project file '" ++ projectFile ++ "' does not exist." +-- | Like 'withProjectOrGlobalConfig', with an additional boolean +-- which tells to ignore local project. +-- +-- Used to implement -z / --ignore-project behaviour +-- +withProjectOrGlobalConfigIgn + :: Bool -- ^ whether to ignore local project + -> Verbosity + -> Flag FilePath + -> IO a + -> (ProjectConfig -> IO a) + -> IO a +withProjectOrGlobalConfigIgn True verbosity gcf _with without = do + globalConfig <- runRebuild "" $ readGlobalConfig verbosity gcf + without globalConfig +withProjectOrGlobalConfigIgn False verbosity gcf with without = + withProjectOrGlobalConfig verbosity gcf with without + withProjectOrGlobalConfig :: Verbosity -> Flag FilePath -> IO a diff --git a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs index 360b9f5533f..15e1b51ab65 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs @@ -364,6 +364,7 @@ instance Arbitrary ClientInstallFlags where arbitrary = ClientInstallFlags <$> arbitrary + <*> arbitrary <*> arbitraryFlag arbitraryShortToken <*> arbitrary <*> arbitrary From 9089b0e3bb1f3a9dae5dde8a46e2bb508480388a Mon Sep 17 00:00:00 2001 From: Oleg Grenrus Date: Sat, 14 Dec 2019 21:47:47 +0200 Subject: [PATCH 2/2] Add 5919 and 6410 (cabal install improvements) mentions to changelog --- cabal-install/changelog | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cabal-install/changelog b/cabal-install/changelog index 0e955fd7aec..9050cbdaeaa 100644 --- a/cabal-install/changelog +++ b/cabal-install/changelog @@ -7,6 +7,11 @@ ([#6385](https://github.com/haskell/cabal/pull/6385)) * Update `setupMinCabalVersionConstraint` for GHC-8.8 ([#6217](https://github.com/haskell/cabal/pull/6217)) + * Implement `cabal install --ignore-project` + ([#5919](https://github.com/haskell/cabal/issues/5919)) + * `cabal install executable` solver isn't affected by default + environment contents + ([#6410](https://github.com/haskell/cabal/issues/6410)) * Use `lukko` for file locking ([#6345](https://github.com/haskell/cabal/pull/6345)) * Use `hackage-security-0.6`