@@ -29,6 +29,7 @@ module Distribution.Simple.Program.Run
2929 , getProgramInvocationOutputAndErrors
3030 , getProgramInvocationLBSAndErrors
3131 , getEffectiveEnvironment
32+ , getFullEnvironment
3233 ) where
3334
3435import Distribution.Compat.Prelude
@@ -237,6 +238,12 @@ getProgramInvocationIODataAndErrors
237238-- | Return the current environment extended with the given overrides.
238239-- If an entry is specified twice in @overrides@, the second entry takes
239240-- precedence.
241+ --
242+ -- getEffectiveEnvironment returns 'Nothing' when there are no overrides.
243+ -- It returns an argument that is suitable to pass directly to 'CreateProcess' to
244+ -- override the environment.
245+ -- If you need the full environment to manipulate further, even when there are no overrides,
246+ -- then call 'getFullEnvironment'.
240247getEffectiveEnvironment
241248 :: [(String , Maybe String )]
242249 -> IO (Maybe [(String , String )])
@@ -248,6 +255,17 @@ getEffectiveEnvironment overrides =
248255 update (var, Nothing ) = Map. delete var
249256 update (var, Just val) = Map. insert var val
250257
258+ -- | Like 'getEffectiveEnvironment', but when no overrides are specified,
259+ -- returns the full environment instead of 'Nothing'.
260+ getFullEnvironment
261+ :: [(String , Maybe String )]
262+ -> IO [(String , String )]
263+ getFullEnvironment overrides = do
264+ menv <- getEffectiveEnvironment overrides
265+ case menv of
266+ Just env -> return env
267+ Nothing -> getEnvironment
268+
251269-- | Like the unix xargs program. Useful for when we've got very long command
252270-- lines that might overflow an OS limit on command line length and so you
253271-- need to invoke a command multiple times to get all the args in.
0 commit comments