Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow --config-file flag for new-build #4649

Merged
merged 3 commits into from
Aug 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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