Skip to content

Commit

Permalink
Honor build-tool-depends in CmdRun
Browse files Browse the repository at this point in the history
Similarly to CmdExec and CmdTest, get paths to all dependency binaries
and add those to PATH. Unlike CmdExec, add just the explicitly required
paths.
  • Loading branch information
xsebek committed Oct 22, 2023
1 parent 9f37325 commit 2692de6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cabal-install/src/Distribution/Client/CmdExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ withTempEnvFile verbosity baseCtx buildCtx buildStatus action = do
action envOverrides
)

-- | Get paths to all dependency executables to be included in PATH and log them.
pathAdditions :: Verbosity -> ProjectBaseContext -> ProjectBuildContext -> IO [FilePath]
pathAdditions verbosity ProjectBaseContext{..} ProjectBuildContext{..} = do
info verbosity . unlines $
Expand All @@ -274,6 +275,7 @@ pathAdditions verbosity ProjectBaseContext{..} ProjectBuildContext{..} = do
S.toList $
binDirectories distDirLayout elaboratedShared elaboratedPlanToExecute

-- | Get paths to all dependency executables to be included in PATH.
binDirectories
:: DistDirLayout
-> ElaboratedSharedConfig
Expand Down
8 changes: 8 additions & 0 deletions cabal-install/src/Distribution/Client/CmdRun.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import Distribution.Client.ProjectPlanning
)
import Distribution.Client.ProjectPlanning.Types
( dataDirsEnvironmentForPlan
, elabExeDependencyPaths
)
import Distribution.Client.ScriptUtils
( AcceptNoTargets (..)
Expand Down Expand Up @@ -275,6 +276,12 @@ runAction flags@NixStyleFlags{..} targetAndArgs globalFlags =
dieWithException verbosity $
MultipleMatchingExecutables exeName (fmap (\p -> " - in package " ++ prettyShow (elabUnitId p)) elabPkgs)

-- Some dependencies may have executables. Let's put those on the PATH.
let extraPaths = elabExeDependencyPaths pkg
info verbosity . unlines $
"Including the following directories in PATH:"
: extraPaths

let defaultExePath =
binDirectoryFor
(distDirLayout baseCtx)
Expand All @@ -300,6 +307,7 @@ runAction flags@NixStyleFlags{..} targetAndArgs globalFlags =
dataDirsEnvironmentForPlan
(distDirLayout baseCtx)
elaboratedPlan
, progInvokePathEnv = extraPaths
}
where
(targetStr, args) = splitAt 1 targetAndArgs
Expand Down
11 changes: 11 additions & 0 deletions changelog.d/pr-9341
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
synopsis: Fix run command environment
packages: cabal-install
prs: #9341
issues: #8391

description: {

- The Run command will now add binary paths of dependencies
(build-tool-depends) to PATH, just like Exec and Test commands.

}

0 comments on commit 2692de6

Please sign in to comment.