Skip to content

Commit 8b587c3

Browse files
authored
Remove undesirable warnings about duplicate configs. (#11181)
* Reduce duplicate config warnings. Now only warns about duplicate configs when a configuration file has not been explicitly provided by the user. Fixes #11023. * Use proper verbosity. * Off-by-case.
1 parent 6b990ba commit 8b587c3

File tree

5 files changed

+30
-22
lines changed

5 files changed

+30
-22
lines changed

cabal-install/src/Distribution/Client/CmdPath.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ pathAction flags@NixStyleFlags{extraFlags = pathFlags'} cliTargetStrings globalF
250250
pure $ Just $ mkCompilerInfo configuredCompilerProg compiler
251251

252252
paths <- for (fromFlagOrDefault [] $ pathDirectories pathFlags) $ \p -> do
253-
t <- getPathLocation baseCtx p
253+
t <- getPathLocation verbosity baseCtx p
254254
pure (pathName p, t)
255255

256256
let pathOutputs =
@@ -272,20 +272,20 @@ pathAction flags@NixStyleFlags{extraFlags = pathFlags'} cliTargetStrings globalF
272272
-- | Find the FilePath location for common configuration paths.
273273
--
274274
-- TODO: this should come from a common source of truth to avoid code path divergence
275-
getPathLocation :: ProjectBaseContext -> ConfigPath -> IO FilePath
276-
getPathLocation _ ConfigPathCacheHome =
275+
getPathLocation :: Verbosity -> ProjectBaseContext -> ConfigPath -> IO FilePath
276+
getPathLocation _ _ ConfigPathCacheHome =
277277
defaultCacheHome
278-
getPathLocation baseCtx ConfigPathRemoteRepoCache =
278+
getPathLocation _ baseCtx ConfigPathRemoteRepoCache =
279279
pure $ buildSettingCacheDir (buildSettings baseCtx)
280-
getPathLocation baseCtx ConfigPathLogsDir =
280+
getPathLocation _ baseCtx ConfigPathLogsDir =
281281
pure $ cabalLogsDirectory (cabalDirLayout baseCtx)
282-
getPathLocation baseCtx ConfigPathStoreDir =
282+
getPathLocation _ baseCtx ConfigPathStoreDir =
283283
fromFlagOrDefault
284284
defaultStoreDir
285285
(pure <$> projectConfigStoreDir (projectConfigShared (projectConfig baseCtx)))
286-
getPathLocation baseCtx ConfigPathConfigFile =
287-
getConfigFilePath (projectConfigConfigFile (projectConfigShared (projectConfig baseCtx)))
288-
getPathLocation baseCtx ConfigPathInstallDir =
286+
getPathLocation verbosity baseCtx ConfigPathConfigFile =
287+
getConfigFilePath verbosity (projectConfigConfigFile (projectConfigShared (projectConfig baseCtx)))
288+
getPathLocation _ baseCtx ConfigPathInstallDir =
289289
fromFlagOrDefault
290290
defaultInstallPath
291291
(pure <$> cinstInstalldir (projectConfigClientInstallFlags $ projectConfigBuildOnly (projectConfig baseCtx)))

cabal-install/src/Distribution/Client/Config.hs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,6 @@ defaultHackageRemoteRepoKeyThreshold = 3
953953
-- use 'loadRawConfig'.
954954
loadConfig :: Verbosity -> Flag FilePath -> IO SavedConfig
955955
loadConfig verbosity configFileFlag = do
956-
warnOnTwoConfigs verbosity
957956
config <- loadRawConfig verbosity configFileFlag
958957
extendToEffectiveConfig config
959958

@@ -980,7 +979,7 @@ extendToEffectiveConfig config = do
980979
-- effective configuration.
981980
loadRawConfig :: Verbosity -> Flag FilePath -> IO SavedConfig
982981
loadRawConfig verbosity configFileFlag = do
983-
(source, configFile) <- getConfigFilePathAndSource configFileFlag
982+
(source, configFile) <- getConfigFilePathAndSource verbosity configFileFlag
984983
minp <- readConfigFile mempty configFile
985984
case minp of
986985
Nothing -> do
@@ -1023,17 +1022,28 @@ data ConfigFileSource
10231022

10241023
-- | Returns the config file path, without checking that the file exists.
10251024
-- The order of precedence is: input flag, CABAL_CONFIG, default location.
1026-
getConfigFilePath :: Flag FilePath -> IO FilePath
1027-
getConfigFilePath = fmap snd . getConfigFilePathAndSource
1025+
getConfigFilePath :: Verbosity -> Flag FilePath -> IO FilePath
1026+
getConfigFilePath verbosity configFilePath = fmap snd $ getConfigFilePathAndSource verbosity configFilePath
10281027

1029-
getConfigFilePathAndSource :: Flag FilePath -> IO (ConfigFileSource, FilePath)
1030-
getConfigFilePathAndSource configFileFlag =
1028+
getConfigFilePathAndSource :: Verbosity -> Flag FilePath -> IO (ConfigFileSource, FilePath)
1029+
getConfigFilePathAndSource verbosity configFileFlag =
10311030
getSource sources
10321031
where
1032+
defaultSource = do
1033+
cfg <- defaultConfigFile
1034+
-- We only warn on two configs when the user has not explicitly indicated
1035+
-- a preference (using any of CABAL_CONFIG, CABAL_DIR, or the --config
1036+
-- option).
1037+
dir <- lookupEnv "CABAL_DIR"
1038+
case dir of
1039+
Nothing -> warnOnTwoConfigs verbosity
1040+
Just _ -> return ()
1041+
return $ Just cfg
1042+
10331043
sources =
10341044
[ (CommandlineOption, return . flagToMaybe $ configFileFlag)
10351045
, (EnvironmentVariable, lookup "CABAL_CONFIG" `liftM` getEnvironment)
1036-
, (Default, Just `liftM` defaultConfigFile)
1046+
, (Default, defaultSource)
10371047
]
10381048

10391049
getSource [] = error "no config file path candidate found."
@@ -1991,7 +2001,7 @@ userConfigUpdate verbosity globalFlags extraLines = do
19912001
extraConfig <- parseExtraLines verbosity extraLines
19922002
newConfig <- initialSavedConfig
19932003
commentConf <- commentSavedConfig
1994-
cabalFile <- getConfigFilePath $ globalConfigFile globalFlags
2004+
cabalFile <- getConfigFilePath verbosity $ globalConfigFile globalFlags
19952005
let backup = cabalFile ++ ".backup"
19962006
notice verbosity $ "Renaming " ++ cabalFile ++ " to " ++ backup ++ "."
19972007
renameFile cabalFile backup

cabal-install/src/Distribution/Client/Main.hs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,7 +1465,7 @@ userConfigAction ucflags extraArgs globalFlags = do
14651465
extraLines = fromFlag (userConfigAppendLines ucflags)
14661466
case extraArgs of
14671467
("init" : _) -> do
1468-
path <- configFile
1468+
path <- getConfigFilePath verbosity (globalConfigFile globalFlags)
14691469
fileExists <- doesFileExist path
14701470
if (not fileExists || (fileExists && frc))
14711471
then void $ createDefaultConfigFile verbosity extraLines path
@@ -1475,8 +1475,6 @@ userConfigAction ucflags extraArgs globalFlags = do
14751475
-- Error handling.
14761476
[] -> dieWithException verbosity SpecifySubcommand
14771477
_ -> dieWithException verbosity $ UnknownUserConfigSubcommand extraArgs
1478-
where
1479-
configFile = getConfigFilePath (globalConfigFile globalFlags)
14801478

14811479
-- | Used as an entry point when cabal-install needs to invoke itself
14821480
-- as a setup script. This can happen e.g. when doing parallel builds.

cabal-install/src/Distribution/Client/ProjectConfig.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ writeProjectConfigFile file =
10091009
readGlobalConfig :: Verbosity -> Flag FilePath -> Rebuild ProjectConfig
10101010
readGlobalConfig verbosity configFileFlag = do
10111011
config <- liftIO (loadConfig verbosity configFileFlag)
1012-
configFile <- liftIO (getConfigFilePath configFileFlag)
1012+
configFile <- liftIO (getConfigFilePath verbosity configFileFlag)
10131013
monitorFiles [monitorFileHashed configFile]
10141014
return (convertLegacyGlobalConfig config)
10151015

cabal-install/src/Distribution/Client/ProjectPlanning.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ rebuildProjectConfig
376376
let fileMonitorProjectConfig = newFileMonitor (distProjectCacheFile "config")
377377

378378
fileMonitorProjectConfigKey <- do
379-
configPath <- getConfigFilePath projectConfigConfigFile
379+
configPath <- getConfigFilePath verbosity projectConfigConfigFile
380380
return
381381
( configPath
382382
, distProjectFile ""

0 commit comments

Comments
 (0)