Skip to content

Commit

Permalink
Fix run command environment
Browse files Browse the repository at this point in the history
Reuse Exec command logic for getting paths to all dependency binaries
and add those to PATH. As far as I understand, this can only add more
than `build-tool-depends` required.
  • Loading branch information
xsebek committed Oct 21, 2023
1 parent 9f37325 commit 8ac9633
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cabal-install/src/Distribution/Client/CmdExec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
module Distribution.Client.CmdExec
( execAction
, execCommand
-- Utility function exposed for run command
, pathAdditions
) where

import Distribution.Client.DistDirLayout
Expand Down Expand Up @@ -263,6 +265,12 @@ withTempEnvFile verbosity baseCtx buildCtx buildStatus action = do
action envOverrides
)

-- | Get paths to all dependency executables to be included in PATH.
--
-- The filepaths need to be passed to the executable for example
-- by 'modifyProgramSearchPath' if you are using 'ProgramDb'
-- or more directly by passing them to 'progInvokePathEnv'
-- if you are using 'ProgramInvocation'.
pathAdditions :: Verbosity -> ProjectBaseContext -> ProjectBuildContext -> IO [FilePath]
pathAdditions verbosity ProjectBaseContext{..} ProjectBuildContext{..} = do
info verbosity . unlines $
Expand Down
5 changes: 5 additions & 0 deletions cabal-install/src/Distribution/Client/CmdRun.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Distribution.Client.CmdErrorMessages
, targetSelectorFilter
, targetSelectorPluralPkgs
)
import Distribution.Client.CmdExec (pathAdditions)
import Distribution.Client.Errors
import Distribution.Client.GlobalFlags
( defaultGlobalFlags
Expand Down Expand Up @@ -230,6 +231,9 @@ runAction flags@NixStyleFlags{..} targetAndArgs globalFlags =
elaboratedPlan
return (elaboratedPlan', targets)

-- Some dependencies may have executables. Let's put those on the PATH.
extraPaths <- pathAdditions verbosity baseCtx buildCtx

(selectedUnitId, selectedComponent) <-
-- Slight duplication with 'runProjectPreBuildPhase'.
singleExeOrElse
Expand Down Expand Up @@ -300,6 +304,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 dependencies to PATH,
just like Exec and Test commands.

}

0 comments on commit 8ac9633

Please sign in to comment.