From 57a356b8284d1b52bdd24009700ce90a7bf5593d Mon Sep 17 00:00:00 2001 From: Greg Noel Date: Sun, 17 May 2009 15:54:14 +0000 Subject: Issue 2229, fix, tests, doc --- doc/man/scons.1 | 12 +++++--- src/engine/SCons/Script/SConscript.py | 3 +- test/SConscript/variables.py | 52 ++++++++--------------------------- 3 files changed, 22 insertions(+), 45 deletions(-) diff --git a/doc/man/scons.1 b/doc/man/scons.1 index 593d416..03e4076 100644 --- a/doc/man/scons.1 +++ b/doc/man/scons.1 @@ -3669,9 +3669,10 @@ so subsequent calls to will over-write previous exports that have the same name. Multiple variable names can be passed to .BR Export () -as separate arguments or as a list. A dictionary can be used to map -variables to a different name when exported. Both local variables and -global variables can be exported. +as separate arguments or as a list. +Keyword arguments can be used to provide names and their values. +A dictionary can be used to map variables to a different name when exported. +Both local variables and global variables can be exported. Examples: @@ -3687,7 +3688,10 @@ Export("env", "package") # Make env and package available for all SConscript files: Export(["env", "package"]) -# Make env available using the name debug:. +# Make env available using the name debug: +Export(debug = env) + +# Make env available using the name debug: Export({"debug":env}) .EE diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py index 9a67e67..a34278a 100644 --- a/src/engine/SCons/Script/SConscript.py +++ b/src/engine/SCons/Script/SConscript.py @@ -491,9 +491,10 @@ class SConsEnvironment(SCons.Environment.Base): def Exit(self, value=0): sys.exit(value) - def Export(self, *vars): + def Export(self, *vars, **kw): for var in vars: global_exports.update(compute_exports(self.Split(var))) + global_exports.update(kw) def GetLaunchDir(self): global launch_dir diff --git a/test/SConscript/variables.py b/test/SConscript/variables.py index dd51155..828a62c 100644 --- a/test/SConscript/variables.py +++ b/test/SConscript/variables.py @@ -33,6 +33,13 @@ import TestSCons test = TestSCons.TestSCons() +# SConscript to detect if exported variables are intact +test.write("SConscript", """ +Import(['x', 'y']) +assert x == 'x' +assert y == 'zoom' +""") + # Test exporting all global variables as a list of keys: test.write("SConstruct", """ x = 'x' @@ -41,12 +48,6 @@ Export(globals().keys()) SConscript('SConscript') """) -test.write("SConscript", """ -Import(['x', 'y']) -assert x == 'x' -assert y == 'zoom' -""") - test.run(arguments = ".") # Test exporting all global variables as a list of keys in SConscript call: @@ -56,12 +57,6 @@ y = 'zoom' SConscript('SConscript', globals().keys()) """) -test.write("SConscript", """ -Import(['x', 'y']) -assert x == 'x' -assert y == 'zoom' -""") - test.run(arguments = ".") # Test exporting all global variables as a dictionary: @@ -72,12 +67,6 @@ Export(globals()) SConscript('SConscript') """) -test.write("SConscript", """ -Import(['x', 'y']) -assert x == 'x' -assert y == 'zoom' -""") - test.run(arguments = ".") # Test exporting all global variables as dictionary in SConscript call: @@ -87,10 +76,11 @@ y = 'zoom' SConscript('SConscript', globals()) """) -test.write("SConscript", """ -Import(['x', 'y']) -assert x == 'x' -assert y == 'zoom' +test.run(arguments = ".") + +# Test exporting variables as keywords: +test.write("SConstruct", """ +Export(x = 'x', y = 'zoom') """) test.run(arguments = ".") @@ -106,12 +96,6 @@ f() SConscript('SConscript') """) -test.write("SConscript", """ -Import(['x', 'y']) -assert x == 'x' -assert y == 'zoom' -""") - test.run(arguments = ".") # Test export of local variables in SConscript call: @@ -123,12 +107,6 @@ def f(): f() """) -test.write("SConscript", """ -Import(['x', 'y']) -assert x == 'x' -assert y == 'zoom' -""") - test.run(arguments = ".") # Test export of local variables as a dictionary: @@ -142,12 +120,6 @@ f() SConscript('SConscript') """) -test.write("SConscript", """ -Import(['x', 'y']) -assert x == 'x' -assert y == 'zoom' -""") - test.run(arguments = ".") # Test importing all variables: -- cgit v0.12