@@ -29,6 +29,7 @@ module Distribution.Simple.Program.Run
29
29
, getProgramInvocationOutputAndErrors
30
30
, getProgramInvocationLBSAndErrors
31
31
, getEffectiveEnvironment
32
+ , getFullEnvironment
32
33
) where
33
34
34
35
import Distribution.Compat.Prelude
@@ -237,6 +238,12 @@ getProgramInvocationIODataAndErrors
237
238
-- | Return the current environment extended with the given overrides.
238
239
-- If an entry is specified twice in @overrides@, the second entry takes
239
240
-- 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'.
240
247
getEffectiveEnvironment
241
248
:: [(String , Maybe String )]
242
249
-> IO (Maybe [(String , String )])
@@ -248,6 +255,17 @@ getEffectiveEnvironment overrides =
248
255
update (var, Nothing ) = Map. delete var
249
256
update (var, Just val) = Map. insert var val
250
257
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
+
251
269
-- | Like the unix xargs program. Useful for when we've got very long command
252
270
-- lines that might overflow an OS limit on command line length and so you
253
271
-- need to invoke a command multiple times to get all the args in.
0 commit comments