From 5e6d8e8ebaf7f1f88566cc25c62e6006deb15f80 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Wed, 11 Jul 2007 19:58:03 +0000 Subject: [PATCH] Merged revisions 2117-2120 via svnmerge from http://scons.tigris.org/svn/scons/branches/core ........ r2119 | garyo | 2007-07-11 08:53:36 -0500 (Wed, 11 Jul 2007) | 1 line Fixed minor cut/paste doc error ........ r2120 | stevenknight | 2007-07-11 12:42:50 -0500 (Wed, 11 Jul 2007) | 4 lines Simplify the {Add,Get,Set}Option() implementations, and initialize the OptionsParser variable with a do-nothing class, in case it's used by test scripts without normal SCons.Script.Main initialization. ........ git-svn-id: http://scons.tigris.org/svn/scons/trunk@2121 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- doc/user/command-line.in | 2 +- doc/user/command-line.sgml | 2 +- src/engine/SCons/Script/Main.py | 28 ++++++++++++++++++++++++++- src/engine/SCons/Script/SConscript.py | 4 ++-- src/engine/SCons/Script/__init__.py | 5 +++-- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/doc/user/command-line.in b/doc/user/command-line.in index b444d30f..b2cb8883 100644 --- a/doc/user/command-line.in +++ b/doc/user/command-line.in @@ -978,7 +978,7 @@ - Other values that equate to &true; include + Other values that equate to &false; include n, 0, off diff --git a/doc/user/command-line.sgml b/doc/user/command-line.sgml index 66de79cc..1bc94d75 100644 --- a/doc/user/command-line.sgml +++ b/doc/user/command-line.sgml @@ -939,7 +939,7 @@ - Other values that equate to &true; include + Other values that equate to &false; include n, 0, off diff --git a/src/engine/SCons/Script/Main.py b/src/engine/SCons/Script/Main.py index 53e51296..a3c0a514 100644 --- a/src/engine/SCons/Script/Main.py +++ b/src/engine/SCons/Script/Main.py @@ -329,13 +329,39 @@ exit_status = 0 # exit status, assume success by default num_jobs = None delayed_warnings = [] -OptionsParser = None +class FakeOptionParser: + """ + A do-nothing option parser, used for the initial OptionsParser variable. + + During normal SCons operation, the OptionsParser is created right + away by the main() function. Certain tests scripts however, can + introspect on different Tool modules, the initialization of which + can try to add a new, local option to an otherwise uninitialized + OptionsParser object. This allows that introspection to happen + without blowing up. + + """ + class FakeOptionValues: + def __getattr__(self, attr): + return None + values = FakeOptionValues() + def add_local_option(self, *args, **kw): + pass + +OptionsParser = FakeOptionParser() def AddOption(*args, **kw): if not kw.has_key('default'): kw['default'] = None result = apply(OptionsParser.add_local_option, args, kw) return result + +def GetOption(name): + return getattr(OptionsParser.values, name) + +def SetOption(name, value): + return OptionsParser.values.set_option(name, value) + # class Stats: def __init__(self): diff --git a/src/engine/SCons/Script/SConscript.py b/src/engine/SCons/Script/SConscript.py index 7326c0c8..a1856dab 100644 --- a/src/engine/SCons/Script/SConscript.py +++ b/src/engine/SCons/Script/SConscript.py @@ -469,7 +469,7 @@ class SConsEnvironment(SCons.Environment.Base): def GetOption(self, name): name = self.subst(name) - return getattr(SCons.Script.Main.OptionsParser.values, name) + return SCons.Script.Main.GetOption(name) def Help(self, text): text = self.subst(text, raw=1) @@ -525,7 +525,7 @@ class SConsEnvironment(SCons.Environment.Base): def SetOption(self, name, value): name = self.subst(name) - SCons.Script.Main.OptionsParser.values.set_option(name, value) + SCons.Script.Main.SetOption(name, value) # # diff --git a/src/engine/SCons/Script/__init__.py b/src/engine/SCons/Script/__init__.py index 8f97c418..9288b859 100644 --- a/src/engine/SCons/Script/__init__.py +++ b/src/engine/SCons/Script/__init__.py @@ -106,7 +106,10 @@ CleanTask = Main.CleanTask QuestionTask = Main.QuestionTask #PrintHelp = Main.PrintHelp #SConscriptSettableOptions = Main.SConscriptSettableOptions + AddOption = Main.AddOption +GetOption = Main.GetOption +SetOption = Main.SetOption #keep_going_on_error = Main.keep_going_on_error #print_dtree = Main.print_dtree @@ -271,12 +274,10 @@ GlobalDefaultEnvironmentFunctions = [ 'Exit', 'Export', 'GetLaunchDir', - 'GetOption', 'Help', 'Import', #'SConscript', is handled separately, below. 'SConscriptChdir', - 'SetOption', # Methods from the Environment.Base class. 'AddPostAction', -- 2.26.2