Skip to content

Commit

Permalink
Merge pull request #4623 from alexbiehl/pr/global-store-flag
Browse files Browse the repository at this point in the history
Add 'store-dir' global flag for custom store location
  • Loading branch information
23Skidoo authored Aug 9, 2017
2 parents 0fdf217 + 6d22eb2 commit 22d8e32
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 27 deletions.
14 changes: 9 additions & 5 deletions Cabal/doc/nix-local-build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
----------------------------

Expand Down
3 changes: 2 additions & 1 deletion cabal-install/Distribution/Client/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 14 additions & 9 deletions cabal-install/Distribution/Client/DistDirLayout.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{-# LANGUAGE RecordWildCards #-}

-- |
-- |
--
-- The layout of the .\/dist\/ directory where cabal keeps all of it's state
-- and build artifacts.
Expand All @@ -18,7 +18,8 @@ module Distribution.Client.DistDirLayout (

-- * 'CabalDirLayout'
CabalDirLayout(..),
defaultCabalDirLayout,
mkCabalDirLayout,
defaultCabalDirLayout
) where

import Data.Maybe (fromMaybe)
Expand Down Expand Up @@ -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"
6 changes: 4 additions & 2 deletions cabal-install/Distribution/Client/GlobalFlags.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 5 additions & 3 deletions cabal-install/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,8 @@ convertLegacyBuildOnlyFlags globalFlags configFlags
globalLogsDir = projectConfigLogsDir,
globalWorldFile = _,
globalHttpTransport = projectConfigHttpTransport,
globalIgnoreExpiry = projectConfigIgnoreExpiry
globalIgnoreExpiry = projectConfigIgnoreExpiry,
globalStoreDir = projectConfigStoreDir
} = globalFlags

ConfigFlags {
Expand Down Expand Up @@ -479,7 +480,8 @@ convertToLegacySharedConfig
globalIgnoreSandbox = mempty,
globalIgnoreExpiry = projectConfigIgnoreExpiry,
globalHttpTransport = projectConfigHttpTransport,
globalNix = mempty
globalNix = mempty,
globalStoreDir = projectConfigStoreDir
}

configFlags = mempty {
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion cabal-install/Distribution/Client/ProjectConfig/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 11 additions & 3 deletions cabal-install/Distribution/Client/ProjectOrchestration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,24 @@ 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) <-
rebuildProjectConfig verbosity
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

Expand Down
5 changes: 5 additions & 0 deletions cabal-install/Distribution/Client/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
]

-- ------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion cabal-install/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]> July 2017
2.0.0.2 Mikhail Glushenkov <[email protected]> July 2017
* Removed the '--root-cmd' parameter of the 'install' command
(#3356).
* Deprecated 'cabal install --global' (#3356).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ instance Arbitrary ProjectConfigBuildOnly where
<*> arbitrary
<*> (fmap getShortToken <$> arbitrary)
<*> (fmap getShortToken <$> arbitrary)
<*> (fmap getShortToken <$> arbitrary)
where
arbitraryNumJobs = fmap (fmap getPositive) <$> arbitrary

Expand All @@ -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'
Expand All @@ -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'))
Expand Down

0 comments on commit 22d8e32

Please sign in to comment.