Skip to content

Commit

Permalink
backport: Find build-tool installed programs before programs in path (#…
Browse files Browse the repository at this point in the history
…9767)

* Find build-tool installed programs before programs in path (BP)

A backport of 443c890 (#9762)

---------

Co-authored-by: brandon s allbery kf8nh <allbery.b@gmail.com>
Co-authored-by: Gershom Bazerman <gershom@arista.com>
  • Loading branch information
3 people authored Mar 11, 2024
1 parent 3f82401 commit ce72f63
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 3 deletions.
6 changes: 4 additions & 2 deletions Cabal/src/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import Distribution.Simple.Program
import Distribution.Simple.Setup as Setup
import Distribution.Simple.BuildTarget
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Program.Db (appendProgramSearchPath)
import Distribution.Simple.Program.Db (appendProgramSearchPath, modifyProgramSearchPath)
import Distribution.Simple.Utils
import Distribution.System
import Distribution.Types.PackageVersionConstraint
Expand Down Expand Up @@ -850,7 +850,9 @@ configure (pkg_descr0, pbi) cfg = do
-- arguments.
mkProgramDb :: ConfigFlags -> ProgramDb -> IO ProgramDb
mkProgramDb cfg initialProgramDb = do
programDb <- appendProgramSearchPath (fromFlagOrDefault normal (configVerbosity cfg)) searchpath initialProgramDb
programDb <-
modifyProgramSearchPath (getProgramSearchPath initialProgramDb ++)
<$> appendProgramSearchPath (fromFlagOrDefault normal (configVerbosity cfg)) searchpath initialProgramDb
pure
. userSpecifyArgss (configProgramArgs cfg)
. userSpecifyPaths (configProgramPaths cfg)
Expand Down
5 changes: 4 additions & 1 deletion cabal-install/src/Distribution/Client/ProjectPlanning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3394,7 +3394,10 @@ setupHsScriptOptions (ReadyPackage elab@ElaboratedConfiguredPackage{..})
useDistPref = builddir,
useLoggingHandle = Nothing, -- this gets set later
useWorkingDir = Just srcdir,
useExtraPathEnv = elabExeDependencyPaths elab,
useExtraPathEnv = elabExeDependencyPaths elab ++ elabProgramPathExtra,
-- note that the above adds the extra-prog-path directly following the elaborated
-- dep paths, so that it overrides the normal path, but _not_ the elaborated extensions
-- for build-tools-depends.
useExtraEnvOverrides = dataDirsEnvironmentForPlan distdir plan,
useWin32CleanHack = False, --TODO: [required eventually]
forceExternalSetupMethod = isParallelBuild,
Expand Down
14 changes: 14 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T9756/OK.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{-# LANGUAGE TemplateHaskell #-}
module OK where

import Data.List
import System.Process
import Language.Haskell.TH

$(do
out <- runIO $ readProcess "mybuilder" [] ""
if "0.2.0.0" `isInfixOf` out then
[d| x = () |]
else
error ("Expecting Version 0.2.0.0, but got: " ++ out)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cabal-version: 1.12
name: cabal-bug-build-tool
version: 0
build-type: Simple

library
exposed-modules: OK
default-language: Haskell2010
build-depends: base, template-haskell, process
build-tool-depends: mybuilder:mybuilder >=0.2.0.0
27 changes: 27 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T9756/cabal.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# cabal v2-update
Downloading the latest package list from test-local-repo
# cabal v2-install
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- mybuilder-0.1.0.0 (exe:mybuilder) (requires build)
Configuring executable 'mybuilder' for mybuilder-0.1.0.0..
Preprocessing executable 'mybuilder' for mybuilder-0.1.0.0..
Building executable 'mybuilder' for mybuilder-0.1.0.0..
Installing executable mybuilder in <PATH>
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.
Symlinking 'mybuilder' to '<ROOT>/cabal.dist/install/mybuilder'
# cabal v2-build
Resolving dependencies...
Build profile: -w ghc-<GHCVER> -O1
In order, the following will be built:
- mybuilder-0.2.0.0 (exe:mybuilder) (requires build)
- cabal-bug-build-tool-0 (lib) (first run)
Configuring executable 'mybuilder' for mybuilder-0.2.0.0..
Preprocessing executable 'mybuilder' for mybuilder-0.2.0.0..
Building executable 'mybuilder' for mybuilder-0.2.0.0..
Installing executable mybuilder in <PATH>
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.
Configuring library for cabal-bug-build-tool-0..
Preprocessing library for cabal-bug-build-tool-0..
Building library for cabal-bug-build-tool-0..
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
13 changes: 13 additions & 0 deletions cabal-testsuite/PackageTests/Regression/T9756/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Test.Cabal.Prelude

-- We are testing if the build-tools program is found in path before programs e.g. in extra-prog-path or the system path
-- For that, we need
-- * A repo with a build tool that is up to date
-- * An older version of the build tool in the extra-prog-path
-- * A project that requires the more up-to-date version of the build-tool

main = cabalTest $ withRepo "repo" $ do
dir <- testWorkDir <$> getTestEnv
cabal "v2-install" ["mybuilder-0.1.0.0", "--installdir=" ++ dir ++ "/install", "--overwrite-policy=always"]
cabal "v2-build" ["cabal-bug-build-tool", "--extra-prog-path=" ++ dir ++ "/install"]

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Revision history for mybuilder0100

## 0.1.0.0 -- YYYY-mm-dd

* First version. Released on an unsuspecting world.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main :: IO ()
main = putStrLn "0.1.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cabal-version: 3.0
name: mybuilder
version: 0.1.0.0
license: NONE
author: Rodrigo Mesquita
maintainer: rodrigo.m.mesquita@gmail.com
build-type: Simple
extra-doc-files: CHANGELOG.md

common warnings
ghc-options: -Wall

executable mybuilder
import: warnings
main-is: Main.hs
build-depends: base
hs-source-dirs: app
default-language: Haskell2010
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Revision history for mybuilder0100

## 0.1.0.0 -- YYYY-mm-dd

* First version. Released on an unsuspecting world.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Main where

main :: IO ()
main = putStrLn "0.2.0.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
cabal-version: 3.0
name: mybuilder
version: 0.2.0.0
license: NONE
author: Rodrigo Mesquita
maintainer: rodrigo.m.mesquita@gmail.com
build-type: Simple
extra-doc-files: CHANGELOG.md

common warnings
ghc-options: -Wall

executable mybuilder
import: warnings
main-is: Main.hs
build-depends: base
hs-source-dirs: app
default-language: Haskell2010

0 comments on commit ce72f63

Please sign in to comment.