Turn more global functions into Environment methods. (clone of 0.92.C121)
authorstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 15 Sep 2003 14:01:28 +0000 (14:01 +0000)
committerstevenknight <stevenknight@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Mon, 15 Sep 2003 14:01:28 +0000 (14:01 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@796 fdb21ef1-2011-0410-befe-b5e4ea1792b1

13 files changed:
doc/man/scons.1
src/CHANGES.txt
src/engine/SCons/Environment.py
src/engine/SCons/EnvironmentTests.py
src/engine/SCons/Script/SConscript.py
src/engine/SCons/Script/__init__.py
test/EnsureVersion.py
test/Exit.py
test/GetSetOption.py [new file with mode: 0644]
test/Help.py
test/SConscript.py
test/option--U.py
test/scan-once.py

index be966a2c78543d7758f16d0903a8ef60d3f4e941..d4655247abf25f3776c3aec72744de6ac8461f2f 100644 (file)
@@ -2282,6 +2282,8 @@ is an optional directory that will be used as the parent directory.
 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .TP
 .RI EnsurePythonVersion( major ", " minor )
+.TP
+.RI env.EnsurePythonVersion( major ", " minor )
 Ensure that the Python version is at least 
 .IR major . minor . 
 This function will
@@ -2295,6 +2297,8 @@ EnsurePythonVersion(2,2)
 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .TP
 .RI EnsureSConsVersion( major ", " minor )
+.TP
+.RI env.EnsureSConsVersion( major ", " minor )
 Ensure that the SCons version is at least 
 .IR major . minor . 
 This function will
@@ -2308,6 +2312,8 @@ EnsureSConsVersion(0,9)
 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .TP
 .RI Exit([ value ])
+.TP
+.RI env.Exit([ value ])
 This tells
 .B scons
 to exit immediately
@@ -2321,6 +2327,8 @@ is used if no value is specified.
 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .TP
 .RI Export( vars )
+.TP
+.RI env.Export( vars )
 This tells 
 .B scons
 to export a list of variables from the current
@@ -2403,11 +2411,15 @@ XXX
 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .\".TP
 .\".RI GetLaunchDir( XXX )
+.\".TP
+.\".RI env.GetLaunchDir( XXX )
 .\"XXX
 
 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .TP
 .RI GetOption( name )
+.TP
+.RI env.GetOption( name )
 This function provides a way to query a select subset of the scons command line
 options from a SConscript file. See 
 .IR SetOption () 
@@ -2416,6 +2428,8 @@ for a description of the options available.
 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .TP
 .RI Help( text )
+.TP
+.RI env.Help( text )
 This specifies help text to be printed if the 
 .B -h 
 argument is given to
@@ -2440,6 +2454,8 @@ env.Ignore('bar', ['bar1.h', 'bar2.h'])
 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .TP 
 .RI Import( vars )
+.TP 
+.RI env.Import( vars )
 This tells 
 .B scons
 to import a list of variables into the current SConscript file. This
@@ -2807,7 +2823,11 @@ for a specific subdirectory.
 .TP
 .RI SConscript( scripts ", [" exports ", " build_dir ", " src_dir ", " duplicate ])
 .TP
+.RI env.SConscript( scripts ", [" exports ", " build_dir ", " src_dir ", " duplicate ])
+.TP
 .RI SConscript(dirs= subdirs ", [name=" script ", " exports ", " build_dir ", " src_dir ", " duplicate ])
+.TP
+.RI env.SConscript(dirs= subdirs ", [name=" script ", " exports ", " build_dir ", " src_dir ", " duplicate ])
 This tells
 .B scons
 to execute
@@ -2999,6 +3019,8 @@ SConsignFile("/home/me/SCons/signatures")
 '\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
 .TP
 .RI SetOption( name ", " value )
+.TP
+.RI env.SetOption( name ", " value )
 This function provides a way to set a select subset of the scons command
 line options from a SConscript file. The options supported are: clean which
 cooresponds to -c, --clean, and --remove; implicit_cache which corresponds
index 9961c4761171a38c69daf5db41b4df142bf2c126..72491cb6f29c044ecce460356bde06ad157a9398 100644 (file)
@@ -45,8 +45,10 @@ RELEASE X.XX - XXX
 
   - Add Environment-method versions of the following global functions:
     AddPreAction(), AddPostAction(), BuildDir(), CacheDir(), Clean(),
-    Default(), FindFile(), GetBuildPath(), Local(), Repository(),
-    SConsignFile(), SourceSignatures(), TargetSignatures().
+    Default(), EnsurePythonVersion(), EnsureSConsVersion(), Exit(),
+    Export(), FindFile(), GetBuildPath(), GetOption(), Help(),
+    Import(), Local(), Repository(), SConsignFile(), SetOption(),
+    SourceSignatures(), TargetSignatures().
 
   - Add the following global functions that correspond to the same-named
     Environment methods:  AlwaysBuild(), Command(), Depends(), Ignore(),
@@ -55,6 +57,11 @@ RELEASE X.XX - XXX
   - Rearrange the man page to show construction environment methods and
     global functions in the same list, and to explain the difference.
 
+  - Rename the Environment.Environment class to Enviroment.Base.
+    Allow the wrapping interface to extend an Environment by using its own
+    subclass of Environment.Base and setting a new Environment.Environment
+    variable as the calling entry point.
+
   From Bram Moolenaar:
 
   - Split the non-SCons-specific functionality from SConf.py to a new,
index 2e95d810cb017e590218979a39ae31b14131a095..f2beb38081f679afc010bf278e56bf0f60c49f03 100644 (file)
@@ -171,7 +171,7 @@ class BuilderDict(UserDict):
         for i, v in dict.items():
             self.__setitem__(i, v)
 
-class Environment:
+class Base:
     """Base class for construction Environments.  These are
     the primary objects used to communicate dependency and
     construction information to the build engine.
@@ -847,3 +847,11 @@ class Environment:
             self._build_signature = 0
         else:
             raise SCons.Errors.UserError, "Unknown target signature type '%s'"%type
+
+# The entry point that will be used by the external world
+# to refer to a construction environment.  This allows the wrapper
+# interface to extend a construction environment for its own purposes
+# by subclassing SCons.Environment.Base and then assigning the
+# class to SCons.Environment.Environment.
+
+Environment = Base
index aa5dbac002d0ca02283d4d78ccd72c678393e6b4..36f4112c95e1412f587f5efc5bb4b9e5bebeb1ea 100644 (file)
@@ -1494,6 +1494,22 @@ class EnvironmentTestCase(unittest.TestCase):
         env.TargetSignatures('$C')
         assert env._build_signature == 0, env._build_signature
 
+    def test_Environment(type):
+        """Test setting Environment variable to an Environment.Base subclass"""
+        class MyEnv(SCons.Environment.Base):
+            def xxx(self, string):
+                return self.subst(string)
+
+        SCons.Environment.Environment = MyEnv
+
+        env = SCons.Environment.Environment(FOO = 'foo')
+
+        f = env.subst('$FOO')
+        assert f == 'foo', f
+
+        f = env.xxx('$FOO')
+        assert f == 'foo', f
+
 
 if __name__ == "__main__":
     suite = unittest.makeSuite(EnvironmentTestCase, 'test_')
index 8614235459305f97a36d774a4364b6379c07dd7c..cc9562d5925bb215dbcb5f157141c86eadb2a224 100644 (file)
@@ -212,12 +212,11 @@ def GetSConscriptFilenames(ls, kw):
 
     return (files, exports)
 
-def SConscript(*ls, **kw):
+def _SConscript(fs, *ls, **kw):
     files, exports = GetSConscriptFilenames(ls, kw)
 
-    default_fs = SCons.Node.FS.default_fs
-    top = default_fs.Top
-    sd = default_fs.SConstruct_dir.rdir()
+    top = fs.Top
+    sd = fs.SConstruct_dir.rdir()
 
     # evaluate each SConscript file
     results = []
@@ -231,14 +230,13 @@ def SConscript(*ls, **kw):
                 if isinstance(fn, SCons.Node.Node):
                     f = fn
                 else:
-                    f = default_fs.File(str(fn))
+                    f = fs.File(str(fn))
                 _file_ = None
 
                 # Change directory to the top of the source
                 # tree to make sure the os's cwd and the cwd of
-                # SCons.Node.FS.default_fs match so we can open the
-                # SConscript.
-                default_fs.chdir(top, change_os_dir=1)
+                # fs match so we can open the SConscript.
+                fs.chdir(top, change_os_dir=1)
                 if f.rexists():
                     _file_ = open(f.rstr(), "r")
                 elif f.has_src_builder():
@@ -262,17 +260,17 @@ def SConscript(*ls, **kw):
                     # where the SConstruct and SConscript files might be
                     # in different Repositories.  For now, cross that
                     # bridge when someone comes to it.
-                    ldir = default_fs.Dir(f.dir.get_path(sd))
+                    ldir = fs.Dir(f.dir.get_path(sd))
                     try:
-                        default_fs.chdir(ldir, change_os_dir=sconscript_chdir)
+                        fs.chdir(ldir, change_os_dir=sconscript_chdir)
                     except OSError:
                         # There was no local directory, so we should be
                         # able to chdir to the Repository directory.
                         # Note that we do this directly, not through
-                        # default_fs.chdir(), because we still need to
+                        # fs.chdir(), because we still need to
                         # interpret the stuff within the SConscript file
                         # relative to where we are logically.
-                        default_fs.chdir(ldir, change_os_dir=0)
+                        fs.chdir(ldir, change_os_dir=0)
                         os.chdir(f.rfile().dir.get_abspath())
 
                     # Append the SConscript directory to the beginning
@@ -295,12 +293,12 @@ def SConscript(*ls, **kw):
             sys.path = old_sys_path
             frame = stack.pop()
             try:
-                default_fs.chdir(frame.prev_dir, change_os_dir=sconscript_chdir)
+                fs.chdir(frame.prev_dir, change_os_dir=sconscript_chdir)
             except OSError:
                 # There was no local directory, so chdir to the
                 # Repository directory.  Like above, we do this
                 # directly.
-                default_fs.chdir(frame.prev_dir, change_os_dir=0)
+                fs.chdir(frame.prev_dir, change_os_dir=0)
                 os.chdir(frame.prev_dir.rdir().get_abspath())
 
             results.append(frame.retval)
@@ -355,31 +353,96 @@ def annotate(node):
 # leave this disabled until we find a more efficient mechanism.
 #SCons.Node.Annotate = annotate
 
-def Help(text):
-    HelpFunction(text)
+class SConsEnvironment(SCons.Environment.Base):
+    """An Environment subclass that contains all of the methods that
+    are particular to the wrapper SCons interface and which aren't
+    (or shouldn't be) part of the build engine itself.
+    """
 
-def Export(*vars):
-    for var in vars:
-        global_exports.update(compute_exports(var))
+    #
+    # Private functions of an SConsEnvironment.
+    #
 
-def Import(*vars):
-    try:
+    def _check_version(self, major, minor, version_string):
+        """Return 0 if 'major' and 'minor' are greater than the version
+        in 'version_string', and 1 otherwise."""
+        try:
+            v_major, v_minor, v_micro, release, serial = sys.version_info
+        except AttributeError:
+            version = string.split(string.split(version_string, ' ')[0], '.')
+            v_major = int(version[0])
+            v_minor = int(re.match('\d+', version[1]).group())
+        if major > v_major or (major == v_major and minor > v_minor):
+            return 0
+        else:
+            return 1
+
+    #
+    # Public functions of an SConsEnvironment.  These get
+    # entry points in the global name space so they can be called
+    # as global functions.
+    #
+
+    def EnsureSConsVersion(self, major, minor):
+        """Exit abnormally if the SCons version is not late enough."""
+        if not self._check_version(major,minor,SCons.__version__):
+            print "SCons %d.%d or greater required, but you have SCons %s" %(major,minor,SCons.__version__)
+            sys.exit(2)
+
+    def EnsurePythonVersion(self, major, minor):
+        """Exit abnormally if the Python version is not late enough."""
+        if not self._check_version(major,minor,sys.version):
+            v = string.split(sys.version, " ", 1)[0]
+            print "Python %d.%d or greater required, but you have Python %s" %(major,minor,v)
+            sys.exit(2)
+
+    def Exit(self, value=0):
+        sys.exit(value)
+
+    def Export(self, *vars):
         for var in vars:
-            var = SCons.Util.Split(var)
-            for v in var:
-                if v == '*':
-                    stack[-1].globals.update(global_exports)
-                    stack[-1].globals.update(stack[-1].exports)
-                else:
-                    if stack[-1].exports.has_key(v):
-                        stack[-1].globals[v] = stack[-1].exports[v]
+            global_exports.update(compute_exports(var))
+
+    def GetLaunchDir(self):
+        global launch_dir
+        return launch_dir
+
+    def GetOption(self, name):
+        name = self.subst(name)
+        return SCons.Script.ssoptions.get(name)
+
+    def Help(self, text):
+        text = self.subst(text, raw=1)
+        HelpFunction(text)
+
+    def Import(self, *vars):
+        try:
+            for var in vars:
+                var = SCons.Util.Split(var)
+                for v in var:
+                    if v == '*':
+                        stack[-1].globals.update(global_exports)
+                        stack[-1].globals.update(stack[-1].exports)
                     else:
-                        stack[-1].globals[v] = global_exports[v]
-    except KeyError,x:
-        raise SCons.Errors.UserError, "Import of non-existant variable '%s'"%x
+                        if stack[-1].exports.has_key(v):
+                            stack[-1].globals[v] = stack[-1].exports[v]
+                        else:
+                            stack[-1].globals[v] = global_exports[v]
+        except KeyError,x:
+            raise SCons.Errors.UserError, "Import of non-existant variable '%s'"%x
+
+    def SConscript(self, *ls, **kw):
+        ls = map(lambda l, self=self: self.subst(l), ls)
+        return apply(_SConscript, [self.fs,] + ls, kw)
 
-def GetLaunchDir():
-    return launch_dir
+    def SetOption(self, name, value):
+        name = self.subst(name)
+        SCons.Script.ssoptions.set(name, value)
+
+#
+#
+#
+SCons.Environment.Environment = SConsEnvironment
 
 def SetBuildSignatureType(type):
     SCons.Warnings.warn(SCons.Warnings.DeprecatedWarning,
@@ -397,33 +460,6 @@ class Options(SCons.Options.Options):
     def __init__(self, files=None, args=arguments):
         SCons.Options.Options.__init__(self, files, args)
 
-def CheckVersion(major, minor, version_string):
-    """Return 0 if 'major' and 'minor' are greater than the version
-    in 'version_string', and 1 otherwise."""
-    try:
-        v_major, v_minor, v_micro, release, serial = sys.version_info
-    except AttributeError:
-        version = string.split(string.split(version_string, ' ')[0], '.')
-        v_major = int(version[0])
-        v_minor = int(re.match('\d+', version[1]).group())
-    if major > v_major or (major == v_major and minor > v_minor):
-        return 0
-    else:
-        return 1
-
-def EnsureSConsVersion(major, minor):
-    """Exit abnormally if the SCons version is not late enough."""
-    if not CheckVersion(major,minor,SCons.__version__):
-        print "SCons %d.%d or greater required, but you have SCons %s" %(major,minor,SCons.__version__)
-        sys.exit(2)
-
-def EnsurePythonVersion(major, minor):
-    """Exit abnormally if the Python version is not late enough."""
-    if not CheckVersion(major,minor,sys.version):
-       v = string.split(sys.version, " ", 1)[0]
-        print "Python %d.%d or greater required, but you have Python %s" %(major,minor,v)
-        sys.exit(2)
-
 def GetJobs():
     SCons.Warnings.warn(SCons.Warnings.DeprecatedWarning,
                         "The GetJobs() function has been deprecated;\n" +\
@@ -437,9 +473,6 @@ def SetJobs(num):
                         "\tuse SetOption('num_jobs', num) instead.")
     SetOption('num_jobs', num)
 
-def Exit(value=0):
-    sys.exit(value)
-
 
 def Alias(name):
     alias = SCons.Node.Alias.default_ans.lookup(name)
@@ -447,12 +480,6 @@ def Alias(name):
         alias = SCons.Node.Alias.default_ans.Alias(name)
     return alias
 
-def SetOption(name, value):
-    SCons.Script.ssoptions.set(name, value)
-
-def GetOption(name):
-    return SCons.Script.ssoptions.get(name)
-
 #
 _DefaultEnvironmentProxy = None
 
@@ -495,35 +522,27 @@ def BuildDefaultGlobals():
     globals['Configure']         = SCons.SConf.SConf
     globals['CScan']             = SCons.Defaults.CScan
     globals['DefaultEnvironment'] = SCons.Defaults.DefaultEnvironment
-    globals['EnsurePythonVersion'] = EnsurePythonVersion
-    globals['EnsureSConsVersion'] = EnsureSConsVersion
     globals['Environment']       = SCons.Environment.Environment
-    globals['Exit']              = Exit
-    globals['Export']            = Export
     globals['GetCommandHandler'] = SCons.Action.GetCommandHandler
-    globals['GetJobs']           = GetJobs
-    globals['GetLaunchDir']      = GetLaunchDir
-    globals['GetOption']         = GetOption    
-    globals['Help']              = Help
-    globals['Import']            = Import
     globals['Literal']           = SCons.Util.Literal
     globals['Options']           = Options
     globals['ParseConfig']       = SCons.Util.ParseConfig
     globals['Platform']          = SCons.Platform.Platform
     globals['Return']            = Return
-    globals['SConscript']        = SConscript
     globals['SConscriptChdir']   = SConscriptChdir
     globals['Scanner']           = SCons.Scanner.Base
-    globals['SetBuildSignatureType'] = SetBuildSignatureType
     globals['SetCommandHandler'] = SCons.Action.SetCommandHandler
-    globals['SetContentSignatureType'] = SetContentSignatureType
-    globals['SetJobs']           = SetJobs
-    globals['SetOption']         = SetOption
     globals['Split']             = SCons.Util.Split
     globals['Tool']              = SCons.Tool.Tool
     globals['Value']             = SCons.Node.Python.Value
     globals['WhereIs']           = SCons.Util.WhereIs
 
+    # Deprecated functions, leave this here for now.
+    globals['GetJobs']           = GetJobs
+    globals['SetBuildSignatureType'] = SetBuildSignatureType
+    globals['SetContentSignatureType'] = SetContentSignatureType
+    globals['SetJobs']           = SetJobs
+
     class DefaultEnvironmentCall:
         """A class that implements "global function" calls of
         Environment methods by fetching the specified method from the
@@ -567,7 +586,20 @@ def BuildDefaultGlobals():
         'TargetSignatures',
     ]
 
-    for name in EnvironmentMethods:
+    SConsEnvironmentMethods = [
+        'EnsurePythonVersion',
+        'EnsureSConsVersion',
+        'Exit',
+        'Export',
+        'GetLaunchDir',
+        'GetOption',
+        'Help',
+        'Import',
+        'SConscript',
+        'SetOption',
+    ]
+
+    for name in EnvironmentMethods + SConsEnvironmentMethods:
         globals[name] = DefaultEnvironmentCall(name)
 
     return globals
index 61e75611ce1c641e3ffdc2037e841765d8c8be74..ee8a4fa33f8143c46846c3759da01e6fc8224209 100644 (file)
@@ -695,6 +695,7 @@ class SConscriptSettableOptions:
 
 def _main(args, parser):
     targets = []
+    fs = SCons.Node.FS.default_fs
 
     # Enable deprecated warnings by default.
     SCons.Warnings._warningOut = _scons_internal_warning
@@ -730,11 +731,11 @@ def _main(args, parser):
         SCons.Action.print_actions = None
     if options.cache_disable:
         def disable(self): pass
-        SCons.Node.FS.default_fs.CacheDir = disable
+        fs.CacheDir = disable
     if options.cache_force:
-        SCons.Node.FS.default_fs.cache_force = 1
+        fs.cache_force = 1
     if options.cache_show:
-        SCons.Node.FS.default_fs.cache_show = 1
+        fs.cache_show = 1
     if options.directory:
         cdir = _create_path(options.directory)
         try:
@@ -766,7 +767,7 @@ def _main(args, parser):
         else:
             raise SCons.Errors.UserError, "No SConstruct file found."
 
-    SCons.Node.FS.default_fs.set_toplevel_dir(os.getcwd())
+    fs.set_toplevel_dir(os.getcwd())
 
     scripts = []
     if options.file:
@@ -789,10 +790,10 @@ def _main(args, parser):
         raise SCons.Errors.UserError, "No SConstruct file found."
 
     if scripts[0] == "-":
-        d = SCons.Node.FS.default_fs.getcwd()
+        d = fs.getcwd()
     else:
-        d = SCons.Node.FS.default_fs.File(scripts[0]).dir
-    SCons.Node.FS.default_fs.set_SConstruct_dir(d)
+        d = fs.File(scripts[0]).dir
+    fs.set_SConstruct_dir(d)
 
     class Unbuffered:
         def __init__(self, file):
@@ -810,14 +811,14 @@ def _main(args, parser):
 
     global repositories
     for rep in repositories:
-        SCons.Node.FS.default_fs.Repository(rep)
+        fs.Repository(rep)
 
     progress_display("scons: Reading SConscript files ...")
     try:
         start_time = time.time()
         try:
             for script in scripts:
-                SCons.Script.SConscript.SConscript(script)
+                SCons.Script.SConscript._SConscript(fs, script)
         except SCons.Errors.StopError, e:
             # We had problems reading an SConscript file, such as it
             # couldn't be copied in to the BuildDir.  Since we're just
@@ -837,7 +838,7 @@ def _main(args, parser):
         sys.exit(0)
     progress_display("scons: done reading SConscript files.")
 
-    SCons.Node.FS.default_fs.chdir(SCons.Node.FS.default_fs.Top)
+    fs.chdir(fs.Top)
 
     if options.help_msg:
         # They specified -h, but there was no Help() inside the
@@ -855,7 +856,7 @@ def _main(args, parser):
         # used -u, -U or -D, we have to look up targets relative
         # to the top, but we build whatever they specified.
         if target_top:
-            lookup_top = SCons.Node.FS.default_fs.Dir(target_top)
+            lookup_top = fs.Dir(target_top)
             target_top = None
     else:
         # There are no targets specified on the command line,
@@ -864,7 +865,7 @@ def _main(args, parser):
         if target_top:
             if options.climb_up == 1:
                 # -u, local directory and below
-                target_top = SCons.Node.FS.default_fs.Dir(target_top)
+                target_top = fs.Dir(target_top)
                 lookup_top = target_top
             elif options.climb_up == 2:
                 # -D, all Default() targets
@@ -872,7 +873,7 @@ def _main(args, parser):
                 lookup_top = None
             elif options.climb_up == 3:
                 # -U, local SConscript Default() targets
-                target_top = SCons.Node.FS.default_fs.Dir(target_top)
+                target_top = fs.Dir(target_top)
                 def check_dir(x, target_top=target_top):
                     if hasattr(x, 'cwd') and not x.cwd is None:
                         cwd = x.cwd.srcnode()
@@ -893,7 +894,7 @@ def _main(args, parser):
 
         targets = SCons.Environment.DefaultTargets
         if targets is None:
-            targets = [SCons.Node.FS.default_fs.Dir('.')]
+            targets = [fs.Dir('.')]
 
     if not targets:
         sys.stderr.write("scons: *** No targets specified and no Default() targets found.  Stop.\n")
@@ -905,9 +906,7 @@ def _main(args, parser):
         else:
             node = SCons.Node.Alias.default_ans.lookup(x)
             if node is None:
-                node = SCons.Node.FS.default_fs.Entry(x,
-                                                      directory = ltop,
-                                                      create = 1)
+                node = fs.Entry(x, directory=ltop, create=1)
         if ttop and not node.is_under(ttop):
             if isinstance(node, SCons.Node.FS.Dir) and ttop.is_under(node):
                 node = ttop
index 4c67e836eb48748482efac4b0a8ba9f83bed6f09..e670295d7ec41ff68bff4df91a80bbce8ae9d8da 100644 (file)
@@ -51,8 +51,9 @@ sys.exit(0)
 else:
     test.write('SConstruct', """
 import sys
+env = Environment()
 EnsurePythonVersion(0,0)
-EnsureSConsVersion(0,0)
+env.EnsureSConsVersion(0,0)
 sys.exit(0)
 """)
 
@@ -60,7 +61,8 @@ sys.exit(0)
 
     test.write('SConstruct', """
 import sys
-EnsurePythonVersion(0,0)
+env = Environment()
+env.EnsurePythonVersion(0,0)
 EnsureSConsVersion(2000,0)
 sys.exit(0)
 """)
index 298808453702a01adc1aaf259fb9c7edcaaf022c..686cdb37fac55a762cb884985a0574661f67b1f2 100644 (file)
@@ -40,13 +40,24 @@ subdir_foo_in = os.path.join('subdir', 'foo.in')
 subdir_foo_out = os.path.join('subdir', 'foo.out')
 
 test.write('SConstruct', """\
-print "SConstruct"
+print "SConstruct, Exit()"
 Exit()
 """)
 
 test.run(stdout = """\
 scons: Reading SConscript files ...
-SConstruct
+SConstruct, Exit()
+""")
+
+test.write('SConstruct', """\
+env = Environment()
+print "SConstruct, env.Exit()"
+env.Exit()
+""")
+
+test.run(stdout = """\
+scons: Reading SConscript files ...
+SConstruct, env.Exit()
 """)
 
 test.write('SConstruct', """\
diff --git a/test/GetSetOption.py b/test/GetSetOption.py
new file mode 100644 (file)
index 0000000..4c1fadd
--- /dev/null
@@ -0,0 +1,53 @@
+#!/usr/bin/env python
+#
+# __COPYRIGHT__
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+
+__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+
+"""
+Test getting and setting options through global functions
+"""
+
+import TestSCons
+
+test = TestSCons.TestSCons()
+
+test.write('SConstruct', """
+env = Environment()
+option_list = ['clean', 'implicit_cache', 'max_drift', 'num_jobs']
+val = 1
+for option in option_list:
+    SetOption(option, val)
+    o = env.GetOption(option)
+    assert o == val, "%s %s != %s" % (option, o, val)
+    val = val + 1
+for option in option_list:
+    env.SetOption(option, val)
+    o = GetOption(option)
+    assert o == val, "%s %s != %s" % (option, o, val)
+    val = val + 1
+""")
+
+test.run(arguments = '.')
+
+test.pass_test()
index d88b715cd295819fb0a78b17046d30cb32ee40c6..ea356ba9690c73c1010bbc7c2d7801d686082146 100644 (file)
@@ -44,4 +44,20 @@ Use scons -H for help about command-line options.
 
 test.run(arguments = '-h', stdout = expect)
 
+test.write('SConstruct', r"""
+env = Environment(MORE='more', HELP='help')
+env.Help("\nEven $MORE\n$HELP text!\n")
+""")
+
+expect = """scons: Reading SConscript files ...
+scons: done reading SConscript files.
+
+Even more
+help text!
+
+Use scons -H for help about command-line options.
+"""
+
+test.run(arguments = '-h', stdout = expect)
+
 test.pass_test()
index 7ebffc3214897c1757431b82fea20a6ebdb281c3..d889c441a5a213404d2403f285281bfc04210a40 100644 (file)
@@ -363,4 +363,25 @@ test.run(arguments = ".",
          stdout = test.wrap_stdout(read_str = "`white space/SConscript'\n",
                                    build_str = "scons: `.' is up to date.\n"))
 
+# Test calling SConscript through a construction environment.
+test.subdir('sub')
+test.write("SConstruct", """\
+env = Environment(SUBDIR='sub')
+print "SConstruct"
+x = 'xxx'
+env.Export("x")
+env.SConscript('$SUBDIR/SConscript')
+""")
+
+test.write(['sub', 'SConscript'], """\
+env = Environment()
+env.Import("x")
+print "sub/SConscript"
+print "x =", x
+""")
+
+test.run(arguments = ".",
+         stdout = test.wrap_stdout(read_str = "SConstruct\nsub/SConscript\nx = xxx\n",
+                                   build_str = "scons: `.' is up to date.\n"))
+
 test.pass_test()
index 4fb77a3820a2840b216495cafb4deb1bde6967f3..45ba97c3e60c34586e88e23f85f755b85c9430c0 100644 (file)
@@ -72,7 +72,7 @@ test.write(['sub2', 'bar.in'], "sub2/bar.in\n")
 test.write(['sub3', 'baz.in'], "sub3/baz.in\n")
 test.write('xxx.in', "xxx.in\n")
 
-test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath('sub1'))
+test.write('SConscript', """assert GetLaunchDir() == r'%s'\n"""%test.workpath('sub1'))
 test.run(arguments = '-U foo.out', chdir = 'sub1')
 
 test.fail_test(not os.path.exists(test.workpath('sub1', 'foo.out')))
@@ -84,7 +84,10 @@ test.fail_test(os.path.exists(test.workpath('sub2/xxx.out')))
 
 test.unlink(['sub1', 'foo.out'])
 
-test.write('SConscript', """assert GetLaunchDir() == r'%s'"""%test.workpath('sub1'))
+test.write('SConscript', """\
+env = Environment()
+assert env.GetLaunchDir() == r'%s'
+"""%test.workpath('sub1'))
 test.run(arguments = '-U',
          chdir = 'sub1',
          stderr = "scons: *** No targets specified and no Default() targets found.  Stop.\n",
index 8a468b4d7b43e2d45e80ea590453c1487fefcbbd..cf08f5e480b40647fa019613cff73a28136865ba 100644 (file)
@@ -168,11 +168,10 @@ import os
 import string
 import re
 import SCons.Environment
-import SCons.Script.SConscript
 
 def Subdirs(env, dirlist):
     for file in _subconf_list(dirlist):
-        SCons.Script.SConscript.SConscript(file, "env")
+        env.SConscript(file, "env")
 
 def _subconf_list(dirlist):
     return map(lambda x: os.path.join(x, "SConscript"), string.split(dirlist))