Skip to content

Commit ee45df1

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: #3883 #4646
1 parent 8c5a116 commit ee45df1

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
@@ -467,11 +467,17 @@ following sources (later entries override earlier ones):
467467

468468
1. ``~/.cabal/config`` (the user-wide global configuration)
469469

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

472-
3. ``cabal.project.freeze`` (the output of ``cabal new-freeze``)
472+
3. ``cabal.project`` (the project configuration)
473473

474-
4. ``cabal.project.local`` (the output of ``cabal new-configure``)
474+
4. ``cabal.project.freeze`` (the output of ``cabal new-freeze``)
475+
476+
5. ``cabal.project.local`` (the output of ``cabal new-configure``)
477+
478+
The project configuration files ``cabal.project`` and ``cabal.project.local``
479+
specify options for project packages only, while the global configuration files
480+
``~/.cabal/config`` and ``cabal.config.local`` affect *all* packages.
475481

476482

477483
Specifying the local packages

cabal-install/Distribution/Client/ProjectConfig.hs

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

7070
import Distribution.Solver.Types.SourcePackage
7171
import Distribution.Solver.Types.Settings
@@ -410,7 +410,7 @@ renderBadProjectRoot (BadProjectRootExplicitFile projectFile) =
410410
--
411411
readProjectConfig :: Verbosity -> Flag FilePath -> DistDirLayout -> Rebuild ProjectConfig
412412
readProjectConfig verbosity configFileFlag distDirLayout = do
413-
global <- readGlobalConfig verbosity configFileFlag
413+
global <- readGlobalConfig verbosity distDirLayout configFileFlag
414414
local <- readProjectLocalConfig verbosity distDirLayout
415415
freeze <- readProjectLocalFreezeConfig verbosity distDirLayout
416416
extra <- readProjectLocalExtraConfig verbosity distDirLayout
@@ -539,13 +539,25 @@ writeProjectConfigFile file =
539539
writeFile file . showProjectConfig
540540

541541

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

551563
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
@@ -30,6 +30,8 @@
3030
stay within the load command size limits of macOSs mach-o linker.
3131
* Use [lfxtb] letters to differentiate component kind instead of
3232
opaque "c" in dist-dir layout.
33+
* New config file 'cabal.config.local' to specify project-wide
34+
global options for project commands.
3335

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

0 commit comments

Comments
 (0)