Skip to content

Commit 8b3bccd

Browse files
committed
readGlobalConfig: Also consider cabal.config files in project root
If there is a cabal.config.local file in the project root directory, readGlobalConfig reads it after ~/.cabal/config. This is intended to allow the user to specify site-specific global options on a per-project basis. Global options cannot be specified in cabal.project.local, which applies options only to packages in the project. See also: haskell#3883 haskell#4646
1 parent b1845ef commit 8b3bccd

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.cabal-sandbox/
33
cabal.sandbox.config
44
cabal.project.local
5+
cabal.config.local
56
.ghc.environment.*
67
cabal-dev/
78
.hpc/

Cabal/doc/nix-local-build.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,11 +481,17 @@ following sources (later entries override earlier ones):
481481

482482
1. ``~/.cabal/config`` (the user-wide global configuration)
483483

484-
2. ``cabal.project`` (the project configuratoin)
484+
2. ``cabal.config.local`` (the project-wide global configuration)
485485

486-
3. ``cabal.project.freeze`` (the output of ``cabal new-freeze``)
486+
3. ``cabal.project`` (the project configuration)
487487

488-
4. ``cabal.project.local`` (the output of ``cabal new-configure``)
488+
4. ``cabal.project.freeze`` (the output of ``cabal new-freeze``)
489+
490+
5. ``cabal.project.local`` (the output of ``cabal new-configure``)
491+
492+
The project configuration files ``cabal.project`` and ``cabal.project.local``
493+
specify options for project packages only, while the global configuration files
494+
``~/.cabal/config`` and ``cabal.config.local`` affect *all* packages.
489495

490496

491497
Specifying the local packages

cabal-install/Distribution/Client/ProjectConfig.hs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import Distribution.Client.GlobalFlags
6666
import Distribution.Client.BuildReports.Types
6767
( ReportLevel(..) )
6868
import Distribution.Client.Config
69-
( loadConfig, getConfigFilePath )
69+
( getConfigFilePath, loadConfig, loadExactConfig )
7070

7171
import Distribution.Solver.Types.SourcePackage
7272
import Distribution.Solver.Types.Settings
@@ -413,7 +413,7 @@ renderBadProjectRoot (BadProjectRootExplicitFile projectFile) =
413413
--
414414
readProjectConfig :: Verbosity -> Flag FilePath -> DistDirLayout -> Rebuild ProjectConfig
415415
readProjectConfig verbosity configFileFlag distDirLayout = do
416-
global <- readGlobalConfig verbosity configFileFlag
416+
global <- readGlobalConfig verbosity distDirLayout configFileFlag
417417
local <- readProjectLocalConfig verbosity distDirLayout
418418
freeze <- readProjectLocalFreezeConfig verbosity distDirLayout
419419
extra <- readProjectLocalExtraConfig verbosity distDirLayout
@@ -542,13 +542,25 @@ writeProjectConfigFile file =
542542
writeFile file . showProjectConfig
543543

544544

545-
-- | Read the user's @~/.cabal/config@ file.
546-
--
547-
readGlobalConfig :: Verbosity -> Flag FilePath -> Rebuild ProjectConfig
548-
readGlobalConfig verbosity configFileFlag = do
549-
config <- liftIO (loadConfig verbosity configFileFlag)
550-
configFile <- liftIO (getConfigFilePath configFileFlag)
551-
monitorFiles [monitorFileHashed configFile]
545+
-- | Read the user's @~/.cabal/config@ file and any @cabal.config.local@ file in the
546+
-- project root directory.
547+
--
548+
readGlobalConfig
549+
:: Verbosity
550+
-> DistDirLayout
551+
-> Flag FilePath
552+
-> Rebuild ProjectConfig
553+
readGlobalConfig verbosity layout configFileFlag = do
554+
userConfig <- liftIO (loadConfig verbosity configFileFlag)
555+
userConfigFile <- liftIO (getConfigFilePath configFileFlag)
556+
let localConfigFile = distProjectRootDirectory layout </> "cabal.config.local"
557+
localConfig <- liftIO (loadExactConfig verbosity localConfigFile)
558+
monitorFiles
559+
[
560+
monitorFileHashed userConfigFile,
561+
monitorFileHashed localConfigFile
562+
]
563+
let config = userConfig <> fromMaybe mempty localConfig
552564
return (convertLegacyGlobalConfig config)
553565

554566
reportParseResult :: Verbosity -> String -> FilePath -> ParseResult a -> IO a

cabal-install/changelog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
stay within the load command size limits of macOSs mach-o linker.
3636
* Use [lfxtb] letters to differentiate component kind instead of
3737
opaque "c" in dist-dir layout.
38+
* New config file 'cabal.config.local' to specify project-wide
39+
global options for project commands.
3840

3941
2.0.0.1 Mikhail Glushenkov <[email protected]> October 2017
4042
* Support for GHC's numeric -g debug levels (#4673).

0 commit comments

Comments
 (0)