Skip to content

Commit

Permalink
Merge pull request #4649 from alexbiehl/pr/config-file
Browse files Browse the repository at this point in the history
Allow --config-file flag for new-build
  • Loading branch information
ezyang authored Aug 1, 2017
2 parents 16ed0bd + 4c10611 commit 8a5f625
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 deletions.
19 changes: 8 additions & 11 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, defaultConfigFile )
( loadConfig, getConfigFilePath )

import Distribution.Solver.Types.SourcePackage
import Distribution.Solver.Types.Settings
Expand Down Expand Up @@ -413,9 +413,9 @@ renderBadProjectRoot (BadProjectRootExplicitFile projectFile) =
-- | Read all the config relevant for a project. This includes the project
-- file if any, plus other global config.
--
readProjectConfig :: Verbosity -> DistDirLayout -> Rebuild ProjectConfig
readProjectConfig verbosity distDirLayout = do
global <- readGlobalConfig verbosity
readProjectConfig :: Verbosity -> Flag FilePath -> DistDirLayout -> Rebuild ProjectConfig
readProjectConfig verbosity configFileFlag distDirLayout = do
global <- readGlobalConfig verbosity configFileFlag
local <- readProjectLocalConfig verbosity distDirLayout
freeze <- readProjectLocalFreezeConfig verbosity distDirLayout
extra <- readProjectLocalExtraConfig verbosity distDirLayout
Expand Down Expand Up @@ -546,15 +546,12 @@ writeProjectConfigFile file =

-- | Read the user's @~/.cabal/config@ file.
--
readGlobalConfig :: Verbosity -> Rebuild ProjectConfig
readGlobalConfig verbosity = do
config <- liftIO (loadConfig verbosity mempty)
configFile <- liftIO defaultConfigFile
readGlobalConfig :: Verbosity -> Flag FilePath -> Rebuild ProjectConfig
readGlobalConfig verbosity configFileFlag = do
config <- liftIO (loadConfig verbosity configFileFlag)
configFile <- liftIO (getConfigFilePath configFileFlag)
monitorFiles [monitorFileHashed configFile]
return (convertLegacyGlobalConfig config)
--TODO: do this properly, there's several possible locations
-- and env vars, and flags for selecting the global config


reportParseResult :: Verbosity -> String -> FilePath -> ParseResult a -> IO a
reportParseResult verbosity _filetype filename (ParseOk warnings x) = do
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/Distribution/Client/ProjectConfig/Legacy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ convertLegacyAllPackageFlags globalFlags configFlags
ProjectConfigShared{..}
where
GlobalFlags {
globalConfigFile = _, -- TODO: [required feature]
globalConfigFile = projectConfigConfigFile,
globalSandboxConfigFile = _, -- ??
globalRemoteRepos = projectConfigRemoteRepos,
globalLocalRepos = projectConfigLocalRepos
Expand Down Expand Up @@ -466,7 +466,7 @@ convertToLegacySharedConfig
globalFlags = GlobalFlags {
globalVersion = mempty,
globalNumericVersion = mempty,
globalConfigFile = mempty,
globalConfigFile = projectConfigConfigFile,
globalSandboxConfigFile = mempty,
globalConstraintsFile = mempty,
globalRemoteRepos = projectConfigRemoteRepos,
Expand Down
1 change: 1 addition & 0 deletions cabal-install/Distribution/Client/ProjectConfig/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ data ProjectConfigBuildOnly
data ProjectConfigShared
= ProjectConfigShared {
projectConfigDistDir :: Flag FilePath,
projectConfigConfigFile :: Flag FilePath,
projectConfigProjectFile :: Flag FilePath,
projectConfigHcFlavor :: Flag CompilerFlavor,
projectConfigHcPath :: Flag FilePath,
Expand Down
6 changes: 5 additions & 1 deletion cabal-install/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ rebuildProjectConfig verbosity
return (projectConfig <> cliConfig, localPackages)

where
ProjectConfigShared {
projectConfigConfigFile
} = projectConfigShared cliConfig

fileMonitorProjectConfig = newFileMonitor (distProjectCacheFile "config")

-- Read the cabal.project (or implicit config) and combine it with
Expand All @@ -325,7 +329,7 @@ rebuildProjectConfig verbosity
createDirectoryIfMissingVerbose verbosity True distDirectory
createDirectoryIfMissingVerbose verbosity True distProjectCacheDirectory

readProjectConfig verbosity distDirLayout
readProjectConfig verbosity projectConfigConfigFile distDirLayout

-- Look for all the cabal packages in the project
-- some of which may be local src dirs, tarballs etc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ hackProjectConfigShared :: ProjectConfigShared -> ProjectConfigShared
hackProjectConfigShared config =
config {
projectConfigProjectFile = mempty, -- not present within project files
projectConfigConfigFile = mempty, -- dito
projectConfigConstraints =
--TODO: [required eventually] parse ambiguity in constraint
-- "pkgname -any" as either any version or disabled flag "any".
Expand Down Expand Up @@ -391,6 +392,7 @@ instance Arbitrary ProjectConfigShared where
ProjectConfigShared
<$> arbitraryFlag arbitraryShortToken
<*> arbitraryFlag arbitraryShortToken
<*> arbitraryFlag arbitraryShortToken
<*> arbitrary
<*> arbitraryFlag arbitraryShortToken
<*> arbitraryFlag arbitraryShortToken
Expand Down Expand Up @@ -433,7 +435,8 @@ instance Arbitrary ProjectConfigShared where
, projectConfigStrongFlags = x18
, projectConfigAllowBootLibInstalls = x19
, projectConfigPerComponent = x20
, projectConfigIndependentGoals = x21 } =
, projectConfigIndependentGoals = x21
, projectConfigConfigFile = x22 } =
[ ProjectConfigShared { projectConfigDistDir = x00'
, projectConfigProjectFile = x01'
, projectConfigHcFlavor = x02'
Expand All @@ -455,18 +458,19 @@ instance Arbitrary ProjectConfigShared where
, projectConfigStrongFlags = x18'
, projectConfigAllowBootLibInstalls = x19'
, projectConfigPerComponent = x20'
, projectConfigIndependentGoals = x21' }
, projectConfigIndependentGoals = x21'
, projectConfigConfigFile = x22' }
| ((x00', x01', x02', x03', x04'),
(x05', x06', x07', x08', x09'),
(x10', x11', x12', x13', x14'),
(x15', x16', x17', x18', x19'),
x20', x21')
x20', x21', x22')
<- shrink
((x00, x01, x02, fmap NonEmpty x03, fmap NonEmpty x04),
(x05, x06, x07, x08, preShrink_Constraints x09),
(x10, x11, x12, x13, x14),
(x15, x16, x17, x18, x19),
x20, x21)
x20, x21, x22)
]
where
preShrink_Constraints = map fst
Expand Down

0 comments on commit 8a5f625

Please sign in to comment.