From 384c30e3a6327c08f56445f112cef6274b454a29 Mon Sep 17 00:00:00 2001 From: Rodrigo Mesquita Date: Fri, 1 Mar 2024 14:39:32 +0000 Subject: [PATCH] Find build-tool installed programs before programs in path We must consider the path to the installed build-tool before the path to existing versions of the build tool in paths such as `extra-prog-path` or in the system path. This was previously fixed by #8972 but undone by #9527. This also renames `appendProgramSearchPath` to `prependProgramSearchPath` to describe correctly what that function does. Fixes #9756 --- Cabal/src/Distribution/Simple/Configure.hs | 7 ++++--- Cabal/src/Distribution/Simple/ConfigureScript.hs | 2 +- Cabal/src/Distribution/Simple/Program/Db.hs | 6 +++--- Cabal/src/Distribution/Simple/Program/Types.hs | 2 +- cabal-install/src/Distribution/Client/CmdExec.hs | 4 ++-- cabal-install/src/Distribution/Client/CmdInstall.hs | 4 ++-- cabal-install/src/Distribution/Client/HttpUtils.hs | 6 +++--- cabal-install/src/Distribution/Client/ProjectPlanning.hs | 2 +- cabal-install/src/Distribution/Client/SetupWrapper.hs | 4 ++-- cabal-install/src/Distribution/Client/VCS.hs | 4 ++-- 10 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Cabal/src/Distribution/Simple/Configure.hs b/Cabal/src/Distribution/Simple/Configure.hs index 4324d67a095..6d2ff25c321 100644 --- a/Cabal/src/Distribution/Simple/Configure.hs +++ b/Cabal/src/Distribution/Simple/Configure.hs @@ -85,7 +85,7 @@ import Distribution.Simple.PackageIndex (InstalledPackageIndex, lookupUnitId) import qualified Distribution.Simple.PackageIndex as PackageIndex import Distribution.Simple.PreProcess import Distribution.Simple.Program -import Distribution.Simple.Program.Db (appendProgramSearchPath, lookupProgramByName) +import Distribution.Simple.Program.Db (prependProgramSearchPath, modifyProgramSearchPath, lookupProgramByName) import Distribution.Simple.Setup.Common as Setup import Distribution.Simple.Setup.Config as Setup import Distribution.Simple.Utils @@ -1236,13 +1236,14 @@ mkPromisedDepsSet comps = Map.fromList [((pn, CLibName ln), cid) | GivenComponen -- arguments. mkProgramDb :: ConfigFlags -> ProgramDb -> IO ProgramDb mkProgramDb cfg initialProgramDb = do - programDb <- appendProgramSearchPath (fromFlagOrDefault normal (configVerbosity cfg)) searchpath initialProgramDb + programDb <- modifyProgramSearchPath (getProgramSearchPath initialProgramDb ++) <$> + prependProgramSearchPath (fromFlagOrDefault normal (configVerbosity cfg)) searchpath initialProgramDb pure . userSpecifyArgss (configProgramArgs cfg) . userSpecifyPaths (configProgramPaths cfg) $ programDb where - searchpath = fromNubList $ configProgramPathExtra cfg + searchpath = fromNubList (configProgramPathExtra cfg) -- Note. We try as much as possible to _prepend_ rather than postpend the extra-prog-path -- so that we can override the system path. However, in a v2-build, at this point, the "system" path diff --git a/Cabal/src/Distribution/Simple/ConfigureScript.hs b/Cabal/src/Distribution/Simple/ConfigureScript.hs index 2572f4949c1..b7a7f16da25 100644 --- a/Cabal/src/Distribution/Simple/ConfigureScript.hs +++ b/Cabal/src/Distribution/Simple/ConfigureScript.hs @@ -169,7 +169,7 @@ runConfigureScript verbosity flags lbi = do maybeHostFlag = if hp == buildPlatform then [] else ["--host=" ++ show (pretty hp)] args' = configureFile' : args ++ ["CC=" ++ ccProgShort] ++ maybeHostFlag shProg = simpleProgram "sh" - progDb <- appendProgramSearchPath verbosity extraPath emptyProgramDb + progDb <- prependProgramSearchPath verbosity extraPath emptyProgramDb shConfiguredProg <- lookupProgram shProg `fmap` configureProgram verbosity shProg progDb diff --git a/Cabal/src/Distribution/Simple/Program/Db.hs b/Cabal/src/Distribution/Simple/Program/Db.hs index 4b02a7e6f2e..f48ee190186 100644 --- a/Cabal/src/Distribution/Simple/Program/Db.hs +++ b/Cabal/src/Distribution/Simple/Program/Db.hs @@ -34,7 +34,7 @@ module Distribution.Simple.Program.Db -- ** Query and manipulate the program db , addKnownProgram , addKnownPrograms - , appendProgramSearchPath + , prependProgramSearchPath , lookupKnownProgram , knownPrograms , getProgramSearchPath @@ -225,12 +225,12 @@ modifyProgramSearchPath f db = -- | Modify the current 'ProgramSearchPath' used by the 'ProgramDb' -- by appending the provided extra paths. Also logs the added paths -- in info verbosity. -appendProgramSearchPath +prependProgramSearchPath :: Verbosity -> [FilePath] -> ProgramDb -> IO ProgramDb -appendProgramSearchPath verbosity extraPaths db = +prependProgramSearchPath verbosity extraPaths db = if not $ null extraPaths then do logExtraProgramSearchPath verbosity extraPaths diff --git a/Cabal/src/Distribution/Simple/Program/Types.hs b/Cabal/src/Distribution/Simple/Program/Types.hs index f1b42f63853..53105b6c9a3 100644 --- a/Cabal/src/Distribution/Simple/Program/Types.hs +++ b/Cabal/src/Distribution/Simple/Program/Types.hs @@ -97,7 +97,7 @@ type ProgArg = String -- We also use this path to set the environment when running child processes. -- -- The @ProgramDb@ is created with a @ProgramSearchPath@ to which we --- @appendProgramSearchPath@ to add the ones that come from cli flags and from +-- @prependProgramSearchPath@ to add the ones that come from cli flags and from -- configurations. Then each of the programs that are configured in the db -- inherits the same path as part of @configureProgram@. type ProgramSearchPath = [ProgramSearchPathEntry] diff --git a/cabal-install/src/Distribution/Client/CmdExec.hs b/cabal-install/src/Distribution/Client/CmdExec.hs index 82fada98463..1d323dece95 100644 --- a/cabal-install/src/Distribution/Client/CmdExec.hs +++ b/cabal-install/src/Distribution/Client/CmdExec.hs @@ -76,7 +76,7 @@ import Distribution.Simple.Program , simpleProgram ) import Distribution.Simple.Program.Db - ( appendProgramSearchPath + ( prependProgramSearchPath , configuredPrograms , requireProgram ) @@ -168,7 +168,7 @@ execAction flags@NixStyleFlags{..} extraArgs globalFlags = do let extraPaths = pathAdditions baseCtx buildCtx programDb <- - appendProgramSearchPath + prependProgramSearchPath verbosity extraPaths . pkgConfigCompilerProgs diff --git a/cabal-install/src/Distribution/Client/CmdInstall.hs b/cabal-install/src/Distribution/Client/CmdInstall.hs index 7b89b0ac302..c425e0644cb 100644 --- a/cabal-install/src/Distribution/Client/CmdInstall.hs +++ b/cabal-install/src/Distribution/Client/CmdInstall.hs @@ -154,7 +154,7 @@ import Distribution.Simple.GHC import qualified Distribution.Simple.InstallDirs as InstallDirs import qualified Distribution.Simple.PackageIndex as PI import Distribution.Simple.Program.Db - ( appendProgramSearchPath + ( prependProgramSearchPath , defaultProgramDb , userSpecifyArgss , userSpecifyPaths @@ -426,7 +426,7 @@ installAction flags@NixStyleFlags{extraFlags, configFlags, installFlags, project hcPath = flagToMaybe projectConfigHcPath hcPkg = flagToMaybe projectConfigHcPkg - configProgDb <- appendProgramSearchPath verbosity ((fromNubList packageConfigProgramPathExtra) ++ (fromNubList projectConfigProgPathExtra)) defaultProgramDb + configProgDb <- prependProgramSearchPath verbosity ((fromNubList packageConfigProgramPathExtra) ++ (fromNubList projectConfigProgPathExtra)) defaultProgramDb let -- ProgramDb with directly user specified paths preProgDb = diff --git a/cabal-install/src/Distribution/Client/HttpUtils.hs b/cabal-install/src/Distribution/Client/HttpUtils.hs index 39bd264c744..f01c2df28e8 100644 --- a/cabal-install/src/Distribution/Client/HttpUtils.hs +++ b/cabal-install/src/Distribution/Client/HttpUtils.hs @@ -46,7 +46,7 @@ import Distribution.Simple.Program import Distribution.Simple.Program.Db ( ProgramDb , addKnownPrograms - , appendProgramSearchPath + , prependProgramSearchPath , configureAllKnownPrograms , emptyProgramDb , lookupProgram @@ -408,7 +408,7 @@ configureTransport verbosity extraPath (Just name) = case find (\(name', _, _, _) -> name' == name) supportedTransports of Just (_, mprog, _tls, mkTrans) -> do - baseProgDb <- appendProgramSearchPath verbosity extraPath emptyProgramDb + baseProgDb <- prependProgramSearchPath verbosity extraPath emptyProgramDb progdb <- case mprog of Nothing -> return emptyProgramDb Just prog -> snd <$> requireProgram verbosity prog baseProgDb @@ -424,7 +424,7 @@ configureTransport verbosity extraPath Nothing = do -- for all the transports except plain-http we need to try and find -- their external executable - baseProgDb <- appendProgramSearchPath verbosity extraPath emptyProgramDb + baseProgDb <- prependProgramSearchPath verbosity extraPath emptyProgramDb progdb <- configureAllKnownPrograms verbosity $ addKnownPrograms diff --git a/cabal-install/src/Distribution/Client/ProjectPlanning.hs b/cabal-install/src/Distribution/Client/ProjectPlanning.hs index f779001dc91..6344249a8a6 100644 --- a/cabal-install/src/Distribution/Client/ProjectPlanning.hs +++ b/cabal-install/src/Distribution/Client/ProjectPlanning.hs @@ -471,7 +471,7 @@ configureCompiler ) $ do liftIO $ info verbosity "Compiler settings changed, reconfiguring..." - progdb <- liftIO $ appendProgramSearchPath verbosity (fromNubList packageConfigProgramPathExtra) defaultProgramDb + progdb <- liftIO $ prependProgramSearchPath verbosity (fromNubList packageConfigProgramPathExtra) defaultProgramDb let progdb' = userSpecifyPaths (Map.toList (getMapLast packageConfigProgramPaths)) progdb result@(_, _, progdb'') <- liftIO $ diff --git a/cabal-install/src/Distribution/Client/SetupWrapper.hs b/cabal-install/src/Distribution/Client/SetupWrapper.hs index eba9b833d9d..b3174c96751 100644 --- a/cabal-install/src/Distribution/Client/SetupWrapper.hs +++ b/cabal-install/src/Distribution/Client/SetupWrapper.hs @@ -89,7 +89,7 @@ import Distribution.Simple.Program , runDbProgram ) import Distribution.Simple.Program.Db - ( appendProgramSearchPath + ( prependProgramSearchPath ) import Distribution.Simple.Program.Find ( programSearchPathAsPATHVar @@ -539,7 +539,7 @@ invoke verbosity path args options = do Nothing -> return () Just logHandle -> info verbosity $ "Redirecting build log to " ++ show logHandle - progDb <- appendProgramSearchPath verbosity (useExtraPathEnv options) (useProgramDb options) + progDb <- prependProgramSearchPath verbosity (useExtraPathEnv options) (useProgramDb options) searchpath <- programSearchPathAsPATHVar $ getProgramSearchPath progDb diff --git a/cabal-install/src/Distribution/Client/VCS.hs b/cabal-install/src/Distribution/Client/VCS.hs index f3403029827..7c071de31eb 100644 --- a/cabal-install/src/Distribution/Client/VCS.hs +++ b/cabal-install/src/Distribution/Client/VCS.hs @@ -62,7 +62,7 @@ import Distribution.Simple.Program , simpleProgram ) import Distribution.Simple.Program.Db - ( appendProgramSearchPath + ( prependProgramSearchPath ) import Distribution.Types.SourceRepo ( KnownRepoType (..) @@ -206,7 +206,7 @@ configureVCS -> VCS Program -> IO (VCS ConfiguredProgram) configureVCS verbosity progPaths vcs@VCS{vcsProgram = prog} = do - progPath <- appendProgramSearchPath verbosity progPaths emptyProgramDb + progPath <- prependProgramSearchPath verbosity progPaths emptyProgramDb asVcsConfigured <$> requireProgram verbosity prog progPath where asVcsConfigured (prog', _) = vcs{vcsProgram = prog'}