Skip to content

Commit f45c16f

Browse files
committed
Fix run command environment
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.
1 parent 9f37325 commit f45c16f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
module Distribution.Client.CmdExec
1313
( execAction
1414
, execCommand
15+
-- Utility function exposed for run command
16+
, pathAdditions
1517
) where
1618

1719
import Distribution.Client.DistDirLayout
@@ -263,6 +265,12 @@ withTempEnvFile verbosity baseCtx buildCtx buildStatus action = do
263265
action envOverrides
264266
)
265267

268+
-- | Get paths to all dependency executables to be included in PATH.
269+
--
270+
-- The filepaths need to be passed to the executable for example
271+
-- by 'modifyProgramSearchPath' if you are using 'ProgramDb'
272+
-- or more directly by passing them to 'progInvokePathEnv'
273+
-- if you are using 'ProgramInvocation'.
266274
pathAdditions :: Verbosity -> ProjectBaseContext -> ProjectBuildContext -> IO [FilePath]
267275
pathAdditions verbosity ProjectBaseContext{..} ProjectBuildContext{..} = do
268276
info verbosity . unlines $

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import Distribution.Client.CmdErrorMessages
3535
, targetSelectorFilter
3636
, targetSelectorPluralPkgs
3737
)
38+
import Distribution.Client.CmdExec (pathAdditions)
3839
import Distribution.Client.Errors
3940
import Distribution.Client.GlobalFlags
4041
( defaultGlobalFlags
@@ -230,6 +231,9 @@ runAction flags@NixStyleFlags{..} targetAndArgs globalFlags =
230231
elaboratedPlan
231232
return (elaboratedPlan', targets)
232233

234+
-- Some dependencies may have executables. Let's put those on the PATH.
235+
extraPaths <- pathAdditions verbosity baseCtx buildCtx
236+
233237
(selectedUnitId, selectedComponent) <-
234238
-- Slight duplication with 'runProjectPreBuildPhase'.
235239
singleExeOrElse
@@ -300,6 +304,7 @@ runAction flags@NixStyleFlags{..} targetAndArgs globalFlags =
300304
dataDirsEnvironmentForPlan
301305
(distDirLayout baseCtx)
302306
elaboratedPlan
307+
, progInvokePathEnv = extraPaths
303308
}
304309
where
305310
(targetStr, args) = splitAt 1 targetAndArgs

0 commit comments

Comments
 (0)