Skip to content

Commit

Permalink
Find build-tool installed programs before programs in path
Browse files Browse the repository at this point in the history
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 haskell#8972 but undone by haskell#9527.

This also renames `appendProgramSearchPath` to
`prependProgramSearchPath` to describe correctly what that function
does.

Fixes haskell#9756
  • Loading branch information
alt-romes committed Mar 1, 2024
1 parent 9025af5 commit 384c30e
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 20 deletions.
7 changes: 4 additions & 3 deletions Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cabal/src/Distribution/Simple/ConfigureScript.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Cabal/src/Distribution/Simple/Program/Db.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module Distribution.Simple.Program.Db
-- ** Query and manipulate the program db
, addKnownProgram
, addKnownPrograms
, appendProgramSearchPath
, prependProgramSearchPath
, lookupKnownProgram
, knownPrograms
, getProgramSearchPath
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cabal/src/Distribution/Simple/Program/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/CmdExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import Distribution.Simple.Program
, simpleProgram
)
import Distribution.Simple.Program.Db
( appendProgramSearchPath
( prependProgramSearchPath
, configuredPrograms
, requireProgram
)
Expand Down Expand Up @@ -168,7 +168,7 @@ execAction flags@NixStyleFlags{..} extraArgs globalFlags = do
let extraPaths = pathAdditions baseCtx buildCtx

programDb <-
appendProgramSearchPath
prependProgramSearchPath
verbosity
extraPaths
. pkgConfigCompilerProgs
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/CmdInstall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =
Expand Down
6 changes: 3 additions & 3 deletions cabal-install/src/Distribution/Client/HttpUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import Distribution.Simple.Program
import Distribution.Simple.Program.Db
( ProgramDb
, addKnownPrograms
, appendProgramSearchPath
, prependProgramSearchPath
, configureAllKnownPrograms
, emptyProgramDb
, lookupProgram
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 $
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/SetupWrapper.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ import Distribution.Simple.Program
, runDbProgram
)
import Distribution.Simple.Program.Db
( appendProgramSearchPath
( prependProgramSearchPath
)
import Distribution.Simple.Program.Find
( programSearchPathAsPATHVar
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cabal-install/src/Distribution/Client/VCS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import Distribution.Simple.Program
, simpleProgram
)
import Distribution.Simple.Program.Db
( appendProgramSearchPath
( prependProgramSearchPath
)
import Distribution.Types.SourceRepo
( KnownRepoType (..)
Expand Down Expand Up @@ -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'}
Expand Down

0 comments on commit 384c30e

Please sign in to comment.