Skip to content

Commit ce72f63

Browse files
alt-romesgeekosaurgbaz
authored
backport: Find build-tool installed programs before programs in path (#9767)
* Find build-tool installed programs before programs in path (BP) A backport of 443c890 (#9762) --------- Co-authored-by: brandon s allbery kf8nh <[email protected]> Co-authored-by: Gershom Bazerman <[email protected]>
1 parent 3f82401 commit ce72f63

File tree

13 files changed

+127
-3
lines changed

13 files changed

+127
-3
lines changed

Cabal/src/Distribution/Simple/Configure.hs

+4-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import Distribution.Simple.Program
7676
import Distribution.Simple.Setup as Setup
7777
import Distribution.Simple.BuildTarget
7878
import Distribution.Simple.LocalBuildInfo
79-
import Distribution.Simple.Program.Db (appendProgramSearchPath)
79+
import Distribution.Simple.Program.Db (appendProgramSearchPath, modifyProgramSearchPath)
8080
import Distribution.Simple.Utils
8181
import Distribution.System
8282
import Distribution.Types.PackageVersionConstraint
@@ -850,7 +850,9 @@ configure (pkg_descr0, pbi) cfg = do
850850
-- arguments.
851851
mkProgramDb :: ConfigFlags -> ProgramDb -> IO ProgramDb
852852
mkProgramDb cfg initialProgramDb = do
853-
programDb <- appendProgramSearchPath (fromFlagOrDefault normal (configVerbosity cfg)) searchpath initialProgramDb
853+
programDb <-
854+
modifyProgramSearchPath (getProgramSearchPath initialProgramDb ++)
855+
<$> appendProgramSearchPath (fromFlagOrDefault normal (configVerbosity cfg)) searchpath initialProgramDb
854856
pure
855857
. userSpecifyArgss (configProgramArgs cfg)
856858
. userSpecifyPaths (configProgramPaths cfg)

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -3394,7 +3394,10 @@ setupHsScriptOptions (ReadyPackage elab@ElaboratedConfiguredPackage{..})
33943394
useDistPref = builddir,
33953395
useLoggingHandle = Nothing, -- this gets set later
33963396
useWorkingDir = Just srcdir,
3397-
useExtraPathEnv = elabExeDependencyPaths elab,
3397+
useExtraPathEnv = elabExeDependencyPaths elab ++ elabProgramPathExtra,
3398+
-- note that the above adds the extra-prog-path directly following the elaborated
3399+
-- dep paths, so that it overrides the normal path, but _not_ the elaborated extensions
3400+
-- for build-tools-depends.
33983401
useExtraEnvOverrides = dataDirsEnvironmentForPlan distdir plan,
33993402
useWin32CleanHack = False, --TODO: [required eventually]
34003403
forceExternalSetupMethod = isParallelBuild,
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+
)
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
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..
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
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+
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.
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"
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
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.
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"
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)