diff --git a/cabal-install/Distribution/Client/ProjectConfig.hs b/cabal-install/Distribution/Client/ProjectConfig.hs index f4d4ef42c86..26a16c18064 100644 --- a/cabal-install/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/Distribution/Client/ProjectConfig.hs @@ -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 @@ -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 @@ -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 diff --git a/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs b/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs index 7bb99f7835c..dd1b39eafcf 100644 --- a/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs +++ b/cabal-install/Distribution/Client/ProjectConfig/Legacy.hs @@ -270,7 +270,7 @@ convertLegacyAllPackageFlags globalFlags configFlags ProjectConfigShared{..} where GlobalFlags { - globalConfigFile = _, -- TODO: [required feature] + globalConfigFile = projectConfigConfigFile, globalSandboxConfigFile = _, -- ?? globalRemoteRepos = projectConfigRemoteRepos, globalLocalRepos = projectConfigLocalRepos @@ -466,7 +466,7 @@ convertToLegacySharedConfig globalFlags = GlobalFlags { globalVersion = mempty, globalNumericVersion = mempty, - globalConfigFile = mempty, + globalConfigFile = projectConfigConfigFile, globalSandboxConfigFile = mempty, globalConstraintsFile = mempty, globalRemoteRepos = projectConfigRemoteRepos, diff --git a/cabal-install/Distribution/Client/ProjectConfig/Types.hs b/cabal-install/Distribution/Client/ProjectConfig/Types.hs index 6dd6be5d23d..0ff1caecf9b 100644 --- a/cabal-install/Distribution/Client/ProjectConfig/Types.hs +++ b/cabal-install/Distribution/Client/ProjectConfig/Types.hs @@ -154,6 +154,7 @@ data ProjectConfigBuildOnly data ProjectConfigShared = ProjectConfigShared { projectConfigDistDir :: Flag FilePath, + projectConfigConfigFile :: Flag FilePath, projectConfigProjectFile :: Flag FilePath, projectConfigHcFlavor :: Flag CompilerFlavor, projectConfigHcPath :: Flag FilePath, diff --git a/cabal-install/Distribution/Client/ProjectPlanning.hs b/cabal-install/Distribution/Client/ProjectPlanning.hs index a36745e50c3..d8cd7f457c9 100644 --- a/cabal-install/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/Distribution/Client/ProjectPlanning.hs @@ -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 @@ -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 diff --git a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs index ee37cb37289..08ac3277f73 100644 --- a/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs +++ b/cabal-install/tests/UnitTests/Distribution/Client/ProjectConfig.hs @@ -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". @@ -391,6 +392,7 @@ instance Arbitrary ProjectConfigShared where ProjectConfigShared <$> arbitraryFlag arbitraryShortToken <*> arbitraryFlag arbitraryShortToken + <*> arbitraryFlag arbitraryShortToken <*> arbitrary <*> arbitraryFlag arbitraryShortToken <*> arbitraryFlag arbitraryShortToken @@ -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' @@ -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