scons icon indicating copy to clipboard operation
scons copied to clipboard

DefaultEnvironment arguments

Open bdbaddog opened this issue 7 years ago • 1 comments

This issue was originally created at: 2009-09-08 14:37:37. This issue was reported by: wiedeman. wiedeman said at 2009-09-08 14:37:37

There are inconsistencies in the usage of DefaultEnvironment(). Greg Noel brought up the following example:

DefaultEnvironment(FOO="bar")
DefaultEnvironment(BAZ="quux")
env = DefaultEnvironment().Clone()
print(env["FOO"])
print(env["BAZ"])  # traceback

The last print statement fails with a traceback. In my view there are 2 ways this could be solved:

  1. traceback at the second call to DefaultEnvironment with an error that only the first call to DefaultEnvironment may have arguments.
  2. The second call behaves like env.Replace(...)

Not sure which one is better.

wiedeman said at 2009-09-08 14:38:34

change subcomponent from doc to scons

gregnoel said at 2009-12-09 12:11:00

Bug party triage. Some parameters, such as 'platform', are impossible to change after the initial call, so be consistent and make all of them illegal after the initial call by throwing an error.

bdbaddog avatar Jan 02 '18 13:01 bdbaddog

Just piling on - DefaultEnvironment has a singleton-type behavior, so calls beyond the first don't look at any override arguments, and it just returns the already constructed environment. In fact, after a recent doc change, manpage says so now:

The default environment is a singleton: the keyword arguments are used only on the first call; on subsequent calls the already-constructed object is returned and any keyword arguments are silently ignored.

It wouldn't be that hard to issue some kind of warning, as the original function is replaced with a stub once it has run initially:

# Lazily instantiate the default environment so the overhead of creating       
# it doesn't apply when it's not needed.                                       
def _fetch_DefaultEnvironment(*args, **kwargs):                                
    """Returns the already-created default construction environment."""        
    return _default_env                                                        

If this is worth doing, could add a check:

    if args or kwargs:
        # warn about ignored

not sure it is worth doing.

Assigning just for the question (so it doesn't get lost).

mwichmann avatar Dec 18 '23 19:12 mwichmann