Skip to content

Commit

Permalink
readGlobalConfig: Also consider cabal.config files in project root
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ttuegel committed Nov 13, 2017
1 parent 8c5a116 commit ee45df1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.cabal-sandbox/
cabal.sandbox.config
cabal.project.local
cabal.config.local
.ghc.environment.*
cabal-dev/
.hpc/
Expand Down
12 changes: 9 additions & 3 deletions Cabal/doc/nix-local-build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,17 @@ following sources (later entries override earlier ones):

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

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

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

4. ``cabal.project.local`` (the output of ``cabal new-configure``)
4. ``cabal.project.freeze`` (the output of ``cabal new-freeze``)

5. ``cabal.project.local`` (the output of ``cabal new-configure``)

The project configuration files ``cabal.project`` and ``cabal.project.local``
specify options for project packages only, while the global configuration files
``~/.cabal/config`` and ``cabal.config.local`` affect *all* packages.


Specifying the local packages
Expand Down
30 changes: 21 additions & 9 deletions cabal-install/Distribution/Client/ProjectConfig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import Distribution.Client.GlobalFlags
import Distribution.Client.BuildReports.Types
( ReportLevel(..) )
import Distribution.Client.Config
( loadConfig, getConfigFilePath )
( getConfigFilePath, loadConfig, loadExactConfig )

import Distribution.Solver.Types.SourcePackage
import Distribution.Solver.Types.Settings
Expand Down Expand Up @@ -410,7 +410,7 @@ renderBadProjectRoot (BadProjectRootExplicitFile projectFile) =
--
readProjectConfig :: Verbosity -> Flag FilePath -> DistDirLayout -> Rebuild ProjectConfig
readProjectConfig verbosity configFileFlag distDirLayout = do
global <- readGlobalConfig verbosity configFileFlag
global <- readGlobalConfig verbosity distDirLayout configFileFlag
local <- readProjectLocalConfig verbosity distDirLayout
freeze <- readProjectLocalFreezeConfig verbosity distDirLayout
extra <- readProjectLocalExtraConfig verbosity distDirLayout
Expand Down Expand Up @@ -539,13 +539,25 @@ writeProjectConfigFile file =
writeFile file . showProjectConfig


-- | Read the user's @~/.cabal/config@ file.
--
readGlobalConfig :: Verbosity -> Flag FilePath -> Rebuild ProjectConfig
readGlobalConfig verbosity configFileFlag = do
config <- liftIO (loadConfig verbosity configFileFlag)
configFile <- liftIO (getConfigFilePath configFileFlag)
monitorFiles [monitorFileHashed configFile]
-- | Read the user's @~/.cabal/config@ file and any @cabal.config.local@ file in the
-- project root directory.
--
readGlobalConfig
:: Verbosity
-> DistDirLayout
-> Flag FilePath
-> Rebuild ProjectConfig
readGlobalConfig verbosity layout configFileFlag = do
userConfig <- liftIO (loadConfig verbosity configFileFlag)
userConfigFile <- liftIO (getConfigFilePath configFileFlag)
let localConfigFile = distProjectRootDirectory layout </> "cabal.config.local"
localConfig <- liftIO (loadExactConfig verbosity localConfigFile)
monitorFiles
[
monitorFileHashed userConfigFile,
monitorFileHashed localConfigFile
]
let config = userConfig <> fromMaybe mempty localConfig
return (convertLegacyGlobalConfig config)

reportParseResult :: Verbosity -> String -> FilePath -> ParseResult a -> IO a
Expand Down
2 changes: 2 additions & 0 deletions cabal-install/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
stay within the load command size limits of macOSs mach-o linker.
* Use [lfxtb] letters to differentiate component kind instead of
opaque "c" in dist-dir layout.
* New config file 'cabal.config.local' to specify project-wide
global options for project commands.

2.0.0.1 Mikhail Glushenkov <mikhail.glushenkov@gmail.com> October 2017
* Support for GHC's numeric -g debug levels (#4673).
Expand Down

0 comments on commit ee45df1

Please sign in to comment.