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 f45c16f
Show file tree
Hide file tree
Showing 2 changed files with 13 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

0 comments on commit f45c16f

Please sign in to comment.