Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport install z to 3.0 #6429

Merged
merged 2 commits into from
Dec 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions cabal-install/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -522,7 +534,7 @@ installAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags
verbosity
config
tmpDir
(envSpecs ++ specs)
(envSpecs' ++ specs)
InstallCommand

buildCtx <-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,6 +47,7 @@ instance Binary ClientInstallFlags
defaultClientInstallFlags :: ClientInstallFlags
defaultClientInstallFlags = ClientInstallFlags
{ cinstInstallLibs = toFlag False
, cinstIgnoreProject = toFlag False
, cinstEnvironmentPath = mempty
, cinstOverwritePolicy = mempty
, cinstInstallMethod = mempty
Expand All @@ -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 })
Expand Down
13 changes: 4 additions & 9 deletions cabal-install/Distribution/Client/CmdRepl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'. "
Expand Down
13 changes: 7 additions & 6 deletions cabal-install/Distribution/Client/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions cabal-install/Distribution/Client/ProjectConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module Distribution.Client.ProjectConfig (
readGlobalConfig,
readProjectLocalFreezeConfig,
withProjectOrGlobalConfig,
withProjectOrGlobalConfigIgn,
writeProjectLocalExtraConfig,
writeProjectLocalFreezeConfig,
writeProjectConfigFile,
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions cabal-install/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ instance Arbitrary ClientInstallFlags where
arbitrary =
ClientInstallFlags
<$> arbitrary
<*> arbitrary
<*> arbitraryFlag arbitraryShortToken
<*> arbitrary
<*> arbitrary
Expand Down