diff --git a/Cabal/doc/nix-local-build.rst b/Cabal/doc/nix-local-build.rst index 5c75bfc37f3..d3ca17823b3 100644 --- a/Cabal/doc/nix-local-build.rst +++ b/Cabal/doc/nix-local-build.rst @@ -145,11 +145,11 @@ identify the result of a build; if we compute this identifier and we find that we already have this ID built, we can just use the already built version. -The global package store is ``~/.cabal/store``; if you need to clear -your store for whatever reason (e.g., to reclaim disk space or because -the global store is corrupted), deleting this directory is safe -(``new-build`` will just rebuild everything it needs on its next -invocation). +The global package store is ``~/.cabal/store`` (configurable via +global `store-dir` option); if you need to clear your store for +whatever reason (e.g., to reclaim disk space or because the global +store is corrupted), deleting this directory is safe (``new-build`` +will just rebuild everything it needs on its next invocation). This split motivates some of the UI choices for Nix-style local build commands. For example, flags passed to ``cabal new-build`` are only @@ -641,6 +641,10 @@ package, and thus apply globally: This option cannot be specified via a ``cabal.project`` file. +.. option:: --store-dir=DIR + + Specifies the name of the directory of the global package store. + Solver configuration options ---------------------------- diff --git a/cabal-install/Distribution/Client/Config.hs b/cabal-install/Distribution/Client/Config.hs index feca016428d..92895cc7c3f 100644 --- a/cabal-install/Distribution/Client/Config.hs +++ b/cabal-install/Distribution/Client/Config.hs @@ -227,7 +227,8 @@ instance Semigroup SavedConfig where globalIgnoreSandbox = combine globalIgnoreSandbox, globalIgnoreExpiry = combine globalIgnoreExpiry, globalHttpTransport = combine globalHttpTransport, - globalNix = combine globalNix + globalNix = combine globalNix, + globalStoreDir = combine globalStoreDir } where combine = combine' savedGlobalFlags diff --git a/cabal-install/Distribution/Client/DistDirLayout.hs b/cabal-install/Distribution/Client/DistDirLayout.hs index 22d92e61962..eb186657759 100644 --- a/cabal-install/Distribution/Client/DistDirLayout.hs +++ b/cabal-install/Distribution/Client/DistDirLayout.hs @@ -1,6 +1,6 @@ {-# LANGUAGE RecordWildCards #-} --- | +-- | -- -- The layout of the .\/dist\/ directory where cabal keeps all of it's state -- and build artifacts. @@ -18,7 +18,8 @@ module Distribution.Client.DistDirLayout ( -- * 'CabalDirLayout' CabalDirLayout(..), - defaultCabalDirLayout, + mkCabalDirLayout, + defaultCabalDirLayout ) where import Data.Maybe (fromMaybe) @@ -243,12 +244,16 @@ defaultStoreDirLayout storeRoot = defaultCabalDirLayout :: FilePath -> CabalDirLayout defaultCabalDirLayout cabalDir = + mkCabalDirLayout cabalDir Nothing Nothing + +mkCabalDirLayout :: FilePath -- ^ Cabal directory + -> Maybe FilePath -- ^ Store directory + -> Maybe FilePath -- ^ Log directory + -> CabalDirLayout +mkCabalDirLayout cabalDir mstoreDir mlogDir = CabalDirLayout {..} where - - cabalStoreDirLayout = defaultStoreDirLayout (cabalDir "store") - - cabalLogsDirectory = cabalDir "logs" - - cabalWorldFile = cabalDir "world" - + cabalStoreDirLayout = + defaultStoreDirLayout (fromMaybe (cabalDir "store") mstoreDir) + cabalLogsDirectory = fromMaybe (cabalDir "logs") mlogDir + cabalWorldFile = cabalDir "world" \ No newline at end of file diff --git a/cabal-install/Distribution/Client/GlobalFlags.hs b/cabal-install/Distribution/Client/GlobalFlags.hs index 8d07ac23e7d..c668bb389fb 100644 --- a/cabal-install/Distribution/Client/GlobalFlags.hs +++ b/cabal-install/Distribution/Client/GlobalFlags.hs @@ -68,7 +68,8 @@ data GlobalFlags = GlobalFlags { globalIgnoreSandbox :: Flag Bool, globalIgnoreExpiry :: Flag Bool, -- ^ Ignore security expiry dates globalHttpTransport :: Flag String, - globalNix :: Flag Bool -- ^ Integrate with Nix + globalNix :: Flag Bool, -- ^ Integrate with Nix + globalStoreDir :: Flag FilePath } deriving Generic defaultGlobalFlags :: GlobalFlags @@ -87,7 +88,8 @@ defaultGlobalFlags = GlobalFlags { globalIgnoreSandbox = Flag False, globalIgnoreExpiry = Flag False, globalHttpTransport = mempty, - globalNix = Flag False + globalNix = Flag False, + globalStoreDir = mempty } instance Monoid GlobalFlags where diff --git a/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs b/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs index 1b084cd46db..c0942fec7b8 100644 --- a/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs +++ b/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs @@ -399,7 +399,8 @@ convertLegacyBuildOnlyFlags globalFlags configFlags globalLogsDir = projectConfigLogsDir, globalWorldFile = _, globalHttpTransport = projectConfigHttpTransport, - globalIgnoreExpiry = projectConfigIgnoreExpiry + globalIgnoreExpiry = projectConfigIgnoreExpiry, + globalStoreDir = projectConfigStoreDir } = globalFlags ConfigFlags { @@ -479,7 +480,8 @@ convertToLegacySharedConfig globalIgnoreSandbox = mempty, globalIgnoreExpiry = projectConfigIgnoreExpiry, globalHttpTransport = projectConfigHttpTransport, - globalNix = mempty + globalNix = mempty, + globalStoreDir = projectConfigStoreDir } configFlags = mempty { @@ -805,7 +807,7 @@ legacySharedConfigFieldDescrs = ] . filterFields [ "remote-repo-cache" - , "logs-dir", "ignore-expiry", "http-transport" + , "logs-dir", "store-dir", "ignore-expiry", "http-transport" ] . commandOptionsToFields ) (commandOptions (globalCommand []) ParseArgs) diff --git a/cabal-install/Distribution/Client/ProjectConfig/Types.hs b/cabal-install/Distribution/Client/ProjectConfig/Types.hs index 5a3969c41b2..c93e17c15f4 100644 --- a/cabal-install/Distribution/Client/ProjectConfig/Types.hs +++ b/cabal-install/Distribution/Client/ProjectConfig/Types.hs @@ -143,7 +143,8 @@ data ProjectConfigBuildOnly projectConfigHttpTransport :: Flag String, projectConfigIgnoreExpiry :: Flag Bool, projectConfigCacheDir :: Flag FilePath, - projectConfigLogsDir :: Flag FilePath + projectConfigLogsDir :: Flag FilePath, + projectConfigStoreDir :: Flag FilePath } deriving (Eq, Show, Generic) diff --git a/cabal-install/Distribution/Client/ProjectOrchestration.hs b/cabal-install/Distribution/Client/ProjectOrchestration.hs index 79681982bf8..c02350e1c7c 100644 --- a/cabal-install/Distribution/Client/ProjectOrchestration.hs +++ b/cabal-install/Distribution/Client/ProjectOrchestration.hs @@ -167,8 +167,7 @@ establishProjectBaseContext verbosity cliConfig = do projectRoot <- either throwIO return =<< findProjectRoot Nothing mprojectFile - let cabalDirLayout = defaultCabalDirLayout cabalDir - distDirLayout = defaultDistDirLayout projectRoot + let distDirLayout = defaultDistDirLayout projectRoot mdistDirectory (projectConfig, localPackages) <- @@ -176,7 +175,16 @@ establishProjectBaseContext verbosity cliConfig = do distDirLayout cliConfig - let buildSettings = resolveBuildTimeSettings + let ProjectConfigBuildOnly { + projectConfigLogsDir, + projectConfigStoreDir + } = projectConfigBuildOnly projectConfig + + mlogsDir = Setup.flagToMaybe projectConfigLogsDir + mstoreDir = Setup.flagToMaybe projectConfigStoreDir + cabalDirLayout = mkCabalDirLayout cabalDir mstoreDir mlogsDir + + buildSettings = resolveBuildTimeSettings verbosity cabalDirLayout projectConfig diff --git a/cabal-install/Distribution/Client/Setup.hs b/cabal-install/Distribution/Client/Setup.hs index b4280146fb7..cd942dd5b1c 100644 --- a/cabal-install/Distribution/Client/Setup.hs +++ b/cabal-install/Distribution/Client/Setup.hs @@ -368,6 +368,11 @@ globalCommand commands = CommandUI { "The location of the world file" globalWorldFile (\v flags -> flags { globalWorldFile = v }) (reqArgFlag "FILE") + + ,option [] ["store-dir"] + "The location of the nix-local-build store" + globalStoreDir (\v flags -> flags { globalStoreDir = v }) + (reqArgFlag "DIR") ] -- ------------------------------------------------------------ diff --git a/cabal-install/changelog b/cabal-install/changelog index aa7f5492e6c..1086a28c949 100644 --- a/cabal-install/changelog +++ b/cabal-install/changelog @@ -15,8 +15,10 @@ relaxation can be now limited to a specific release of a package, plus there's a now syntax for relaxing only caret-style (i.e. '^>=') dependencies (#4575, #4669). + * `--store-dir` option can be used to configure the location of + the build global build store. -2.0.0.0 Ryan Thomas July 2017 +2.0.0.2 Mikhail Glushenkov July 2017 * Removed the '--root-cmd' parameter of the 'install' command (#3356). * Deprecated 'cabal install --global' (#3356). diff --git a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs index db0f0f8dea7..3ebb857e77a 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs @@ -359,6 +359,7 @@ instance Arbitrary ProjectConfigBuildOnly where <*> arbitrary <*> (fmap getShortToken <$> arbitrary) <*> (fmap getShortToken <$> arbitrary) + <*> (fmap getShortToken <$> arbitrary) where arbitraryNumJobs = fmap (fmap getPositive) <$> arbitrary @@ -378,7 +379,8 @@ instance Arbitrary ProjectConfigBuildOnly where , projectConfigHttpTransport = x13 , projectConfigIgnoreExpiry = x14 , projectConfigCacheDir = x15 - , projectConfigLogsDir = x16 } = + , projectConfigLogsDir = x16 + , projectConfigStoreDir = x17 } = [ ProjectConfigBuildOnly { projectConfigVerbosity = x00' , projectConfigDryRun = x01' , projectConfigOnlyDeps = x02' @@ -395,7 +397,8 @@ instance Arbitrary ProjectConfigBuildOnly where , projectConfigHttpTransport = x13 , projectConfigIgnoreExpiry = x14' , projectConfigCacheDir = x15 - , projectConfigLogsDir = x16 } + , projectConfigLogsDir = x16 + , projectConfigStoreDir = x17} | ((x00', x01', x02', x03', x04'), (x05', x06', x07', x08', x09'), (x10', x11', x12', x14'))