Skip to content

Commit 84c30c2

Browse files
alt-romesMikolaj
authored andcommitted
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
1 parent b48a620 commit 84c30c2

File tree

21 files changed

+144
-23
lines changed

21 files changed

+144
-23
lines changed

Cabal/src/Distribution/Simple/Configure.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ import Distribution.Simple.PackageIndex (InstalledPackageIndex, lookupUnitId)
8585
import qualified Distribution.Simple.PackageIndex as PackageIndex
8686
import Distribution.Simple.PreProcess
8787
import Distribution.Simple.Program
88-
import Distribution.Simple.Program.Db (appendProgramSearchPath, lookupProgramByName)
88+
import Distribution.Simple.Program.Db (lookupProgramByName, modifyProgramSearchPath, prependProgramSearchPath)
8989
import Distribution.Simple.Setup.Common as Setup
9090
import Distribution.Simple.Setup.Config as Setup
9191
import Distribution.Simple.Utils
@@ -1236,13 +1236,15 @@ mkPromisedDepsSet comps = Map.fromList [((pn, CLibName ln), cid) | GivenComponen
12361236
-- arguments.
12371237
mkProgramDb :: ConfigFlags -> ProgramDb -> IO ProgramDb
12381238
mkProgramDb cfg initialProgramDb = do
1239-
programDb <- appendProgramSearchPath (fromFlagOrDefault normal (configVerbosity cfg)) searchpath initialProgramDb
1239+
programDb <-
1240+
modifyProgramSearchPath (getProgramSearchPath initialProgramDb ++) -- We need to have the paths to programs installed by build-tool-depends before all other paths
1241+
<$> prependProgramSearchPath (fromFlagOrDefault normal (configVerbosity cfg)) searchpath initialProgramDb
12401242
pure
12411243
. userSpecifyArgss (configProgramArgs cfg)
12421244
. userSpecifyPaths (configProgramPaths cfg)
12431245
$ programDb
12441246
where
1245-
searchpath = fromNubList $ configProgramPathExtra cfg
1247+
searchpath = fromNubList (configProgramPathExtra cfg)
12461248

12471249
-- Note. We try as much as possible to _prepend_ rather than postpend the extra-prog-path
12481250
-- so that we can override the system path. However, in a v2-build, at this point, the "system" path

Cabal/src/Distribution/Simple/ConfigureScript.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ runConfigureScript verbosity flags lbi = do
169169
maybeHostFlag = if hp == buildPlatform then [] else ["--host=" ++ show (pretty hp)]
170170
args' = configureFile' : args ++ ["CC=" ++ ccProgShort] ++ maybeHostFlag
171171
shProg = simpleProgram "sh"
172-
progDb <- appendProgramSearchPath verbosity extraPath emptyProgramDb
172+
progDb <- prependProgramSearchPath verbosity extraPath emptyProgramDb
173173
shConfiguredProg <-
174174
lookupProgram shProg
175175
`fmap` configureProgram verbosity shProg progDb

Cabal/src/Distribution/Simple/Program/Db.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module Distribution.Simple.Program.Db
3434
-- ** Query and manipulate the program db
3535
, addKnownProgram
3636
, addKnownPrograms
37-
, appendProgramSearchPath
37+
, prependProgramSearchPath
3838
, lookupKnownProgram
3939
, knownPrograms
4040
, getProgramSearchPath
@@ -223,14 +223,14 @@ modifyProgramSearchPath f db =
223223
setProgramSearchPath (f $ getProgramSearchPath db) db
224224

225225
-- | Modify the current 'ProgramSearchPath' used by the 'ProgramDb'
226-
-- by appending the provided extra paths. Also logs the added paths
226+
-- by prepending the provided extra paths. Also logs the added paths
227227
-- in info verbosity.
228-
appendProgramSearchPath
228+
prependProgramSearchPath
229229
:: Verbosity
230230
-> [FilePath]
231231
-> ProgramDb
232232
-> IO ProgramDb
233-
appendProgramSearchPath verbosity extraPaths db =
233+
prependProgramSearchPath verbosity extraPaths db =
234234
if not $ null extraPaths
235235
then do
236236
logExtraProgramSearchPath verbosity extraPaths

Cabal/src/Distribution/Simple/Program/Types.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ type ProgArg = String
9797
-- We also use this path to set the environment when running child processes.
9898
--
9999
-- The @ProgramDb@ is created with a @ProgramSearchPath@ to which we
100-
-- @appendProgramSearchPath@ to add the ones that come from cli flags and from
100+
-- @prependProgramSearchPath@ to add the ones that come from cli flags and from
101101
-- configurations. Then each of the programs that are configured in the db
102102
-- inherits the same path as part of @configureProgram@.
103103
type ProgramSearchPath = [ProgramSearchPathEntry]

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ import Distribution.Simple.Program
7676
, simpleProgram
7777
)
7878
import Distribution.Simple.Program.Db
79-
( appendProgramSearchPath
80-
, configuredPrograms
79+
( configuredPrograms
80+
, prependProgramSearchPath
8181
, requireProgram
8282
)
8383
import Distribution.Simple.Program.Run
@@ -168,7 +168,7 @@ execAction flags@NixStyleFlags{..} extraArgs globalFlags = do
168168
let extraPaths = pathAdditions baseCtx buildCtx
169169

170170
programDb <-
171-
appendProgramSearchPath
171+
prependProgramSearchPath
172172
verbosity
173173
extraPaths
174174
. pkgConfigCompilerProgs

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ import Distribution.Simple.GHC
154154
import qualified Distribution.Simple.InstallDirs as InstallDirs
155155
import qualified Distribution.Simple.PackageIndex as PI
156156
import Distribution.Simple.Program.Db
157-
( appendProgramSearchPath
158-
, defaultProgramDb
157+
( defaultProgramDb
158+
, prependProgramSearchPath
159159
, userSpecifyArgss
160160
, userSpecifyPaths
161161
)
@@ -426,7 +426,7 @@ installAction flags@NixStyleFlags{extraFlags, configFlags, installFlags, project
426426
hcPath = flagToMaybe projectConfigHcPath
427427
hcPkg = flagToMaybe projectConfigHcPkg
428428

429-
configProgDb <- appendProgramSearchPath verbosity ((fromNubList packageConfigProgramPathExtra) ++ (fromNubList projectConfigProgPathExtra)) defaultProgramDb
429+
configProgDb <- prependProgramSearchPath verbosity ((fromNubList packageConfigProgramPathExtra) ++ (fromNubList projectConfigProgPathExtra)) defaultProgramDb
430430
let
431431
-- ProgramDb with directly user specified paths
432432
preProgDb =

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ import Distribution.Simple.Program
4646
import Distribution.Simple.Program.Db
4747
( ProgramDb
4848
, addKnownPrograms
49-
, appendProgramSearchPath
5049
, configureAllKnownPrograms
5150
, emptyProgramDb
5251
, lookupProgram
52+
, prependProgramSearchPath
5353
, requireProgram
5454
)
5555
import Distribution.Simple.Program.Run
@@ -408,7 +408,7 @@ configureTransport verbosity extraPath (Just name) =
408408

409409
case find (\(name', _, _, _) -> name' == name) supportedTransports of
410410
Just (_, mprog, _tls, mkTrans) -> do
411-
baseProgDb <- appendProgramSearchPath verbosity extraPath emptyProgramDb
411+
baseProgDb <- prependProgramSearchPath verbosity extraPath emptyProgramDb
412412
progdb <- case mprog of
413413
Nothing -> return emptyProgramDb
414414
Just prog -> snd <$> requireProgram verbosity prog baseProgDb
@@ -424,7 +424,7 @@ configureTransport verbosity extraPath Nothing = do
424424

425425
-- for all the transports except plain-http we need to try and find
426426
-- their external executable
427-
baseProgDb <- appendProgramSearchPath verbosity extraPath emptyProgramDb
427+
baseProgDb <- prependProgramSearchPath verbosity extraPath emptyProgramDb
428428
progdb <-
429429
configureAllKnownPrograms verbosity $
430430
addKnownPrograms

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ configureCompiler
471471
)
472472
$ do
473473
liftIO $ info verbosity "Compiler settings changed, reconfiguring..."
474-
progdb <- liftIO $ appendProgramSearchPath verbosity (fromNubList packageConfigProgramPathExtra) defaultProgramDb
474+
progdb <- liftIO $ prependProgramSearchPath verbosity (fromNubList packageConfigProgramPathExtra) defaultProgramDb
475475
let progdb' = userSpecifyPaths (Map.toList (getMapLast packageConfigProgramPaths)) progdb
476476
result@(_, _, progdb'') <-
477477
liftIO $

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ import Distribution.Simple.Program
8989
, runDbProgram
9090
)
9191
import Distribution.Simple.Program.Db
92-
( appendProgramSearchPath
92+
( prependProgramSearchPath
9393
)
9494
import Distribution.Simple.Program.Find
9595
( programSearchPathAsPATHVar
@@ -539,7 +539,7 @@ invoke verbosity path args options = do
539539
Nothing -> return ()
540540
Just logHandle -> info verbosity $ "Redirecting build log to " ++ show logHandle
541541

542-
progDb <- appendProgramSearchPath verbosity (useExtraPathEnv options) (useProgramDb options)
542+
progDb <- prependProgramSearchPath verbosity (useExtraPathEnv options) (useProgramDb options)
543543

544544
searchpath <-
545545
programSearchPathAsPATHVar $ getProgramSearchPath progDb

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import Distribution.Simple.Program
6262
, simpleProgram
6363
)
6464
import Distribution.Simple.Program.Db
65-
( appendProgramSearchPath
65+
( prependProgramSearchPath
6666
)
6767
import Distribution.Types.SourceRepo
6868
( KnownRepoType (..)
@@ -206,7 +206,7 @@ configureVCS
206206
-> VCS Program
207207
-> IO (VCS ConfiguredProgram)
208208
configureVCS verbosity progPaths vcs@VCS{vcsProgram = prog} = do
209-
progPath <- appendProgramSearchPath verbosity progPaths emptyProgramDb
209+
progPath <- prependProgramSearchPath verbosity progPaths emptyProgramDb
210210
asVcsConfigured <$> requireProgram verbosity prog progPath
211211
where
212212
asVcsConfigured (prog', _) = vcs{vcsProgram = prog'}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{-# LANGUAGE TemplateHaskell #-}
2+
module OK where
3+
4+
import Data.List
5+
import System.Process
6+
import Language.Haskell.TH
7+
8+
$(do
9+
out <- runIO $ readProcess "mybuilder" [] ""
10+
if "0.2.0.0" `isInfixOf` out then
11+
[d| x = () |]
12+
else
13+
error ("Expecting Version 0.2.0.0, but got: " ++ out)
14+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cabal-version: 1.12
2+
name: cabal-bug-build-tool
3+
version: 0
4+
build-type: Simple
5+
6+
library
7+
exposed-modules: OK
8+
default-language: Haskell2010
9+
build-depends: base, template-haskell, process
10+
build-tool-depends: mybuilder:mybuilder >=0.2.0.0
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# cabal v2-update
2+
Downloading the latest package list from test-local-repo
3+
# cabal v2-install
4+
Resolving dependencies...
5+
Build profile: -w ghc-<GHCVER> -O1
6+
In order, the following will be built:
7+
- mybuilder-0.1.0.0 (exe:mybuilder) (requires build)
8+
Configuring executable 'mybuilder' for mybuilder-0.1.0.0...
9+
Preprocessing executable 'mybuilder' for mybuilder-0.1.0.0...
10+
Building executable 'mybuilder' for mybuilder-0.1.0.0...
11+
Installing executable mybuilder in <PATH>
12+
Warning: The directory <ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>/incoming/new-<RAND><ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>/<PACKAGE>-<HASH>/bin is not in the system search path.
13+
Symlinking 'mybuilder' to '<ROOT>/cabal.dist/install/mybuilder'
14+
# cabal v2-build
15+
Resolving dependencies...
16+
Build profile: -w ghc-<GHCVER> -O1
17+
In order, the following will be built:
18+
- mybuilder-0.2.0.0 (exe:mybuilder) (requires build)
19+
- cabal-bug-build-tool-0 (lib) (first run)
20+
Configuring executable 'mybuilder' for mybuilder-0.2.0.0...
21+
Preprocessing executable 'mybuilder' for mybuilder-0.2.0.0...
22+
Building executable 'mybuilder' for mybuilder-0.2.0.0...
23+
Installing executable mybuilder in <PATH>
24+
Warning: The directory <ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>/incoming/new-<RAND><ROOT>/cabal.dist/home/.cabal/store/ghc-<GHCVER>/<PACKAGE>-<HASH>/bin is not in the system search path.
25+
Configuring library for cabal-bug-build-tool-0...
26+
Preprocessing library for cabal-bug-build-tool-0...
27+
Building library for cabal-bug-build-tool-0...
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Test.Cabal.Prelude
2+
3+
-- We are testing if the build-tools program is found in path before programs e.g. in extra-prog-path or the system path
4+
-- For that, we need
5+
-- * A repo with a build tool that is up to date
6+
-- * An older version of the build tool in the extra-prog-path
7+
-- * A project that requires the more up-to-date version of the build-tool
8+
9+
main = cabalTest $ withRepo "repo" $ do
10+
dir <- testWorkDir <$> getTestEnv
11+
cabal "v2-install" ["mybuilder-0.1.0.0", "--installdir=" ++ dir ++ "/install", "--overwrite-policy=always"]
12+
cabal "v2-build" ["cabal-bug-build-tool", "--extra-prog-path=" ++ dir ++ "/install"]
13+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for mybuilder0100
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Main where
2+
3+
main :: IO ()
4+
main = putStrLn "0.1.0.0"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cabal-version: 3.0
2+
name: mybuilder
3+
version: 0.1.0.0
4+
license: NONE
5+
author: Rodrigo Mesquita
6+
maintainer: [email protected]
7+
build-type: Simple
8+
extra-doc-files: CHANGELOG.md
9+
10+
common warnings
11+
ghc-options: -Wall
12+
13+
executable mybuilder
14+
import: warnings
15+
main-is: Main.hs
16+
build-depends: base
17+
hs-source-dirs: app
18+
default-language: Haskell2010
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Revision history for mybuilder0100
2+
3+
## 0.1.0.0 -- YYYY-mm-dd
4+
5+
* First version. Released on an unsuspecting world.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module Main where
2+
3+
main :: IO ()
4+
main = putStrLn "0.2.0.0"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
cabal-version: 3.0
2+
name: mybuilder
3+
version: 0.2.0.0
4+
license: NONE
5+
author: Rodrigo Mesquita
6+
maintainer: [email protected]
7+
build-type: Simple
8+
extra-doc-files: CHANGELOG.md
9+
10+
common warnings
11+
ghc-options: -Wall
12+
13+
executable mybuilder
14+
import: warnings
15+
main-is: Main.hs
16+
build-depends: base
17+
hs-source-dirs: app
18+
default-language: Haskell2010

0 commit comments

Comments
 (0)