Bring CVS back in sync.
[scons.git] / SConstruct
index ec03578857dba5b4af63ab29f7d91bc2600d4220..7dfc9354dcbe97ae4a0ee0fc8913015c289441c8 100644 (file)
@@ -4,7 +4,7 @@
 # See the README file for an overview of how SCons is built and tested.
 #
 
-copyright_years = '2001, 2002, 2003'
+copyright_years = '2001, 2002, 2003, 2004'
 
 #
 # __COPYRIGHT__
@@ -32,6 +32,7 @@ copyright_years = '2001, 2002, 2003'
 import distutils.util
 import os
 import os.path
+import re
 import socket
 import stat
 import string
@@ -39,11 +40,13 @@ import sys
 import time
 
 project = 'scons'
-default_version = '0.93'
-copyright = "Copyright (c) %s Steven Knight" % copyright_years
+default_version = '0.96'
+copyright = "Copyright (c) %s The SCons Foundation" % copyright_years
 
 Default('.')
 
+SConsignFile()
+
 #
 # An internal "whereis" routine to figure out if a given program
 # is available on this system.
@@ -104,13 +107,14 @@ elif aesub:
 else:
     revision = default_version
 
-a = string.split(revision, '.')
-arr = [a[0]]
-for s in a[1:]:
-    if len(s) == 1:
-        s = '0' + s
-    arr.append(s)
-revision = string.join(arr, '.')
+# This is old code that adds an initial "0" to revision numbers < 10.
+#a = string.split(revision, '.')
+#arr = [a[0]]
+#for s in a[1:]:
+#    if len(s) == 1:
+#        s = '0' + s
+#    arr.append(s)
+#revision = string.join(arr, '.')
 
 # Here's how we'd turn the calculated $revision into our package $version.
 # This makes it difficult to coordinate with other files (debian/changelog
@@ -146,8 +150,6 @@ for key in ['AEGIS_PROJECT', 'LOGNAME', 'PYTHONPATH']:
     if os.environ.has_key(key):
         ENV[key] = os.environ[key]
 
-lib_project = os.path.join("lib", project)
-
 cwd_build = os.path.join(os.getcwd(), "build")
 
 test_deb_dir          = os.path.join(cwd_build, "test-deb")
@@ -164,11 +166,11 @@ unpack_zip_dir        = os.path.join(cwd_build, "unpack-zip")
 
 if platform == "win32":
     tar_hflag = ''
-    python_project_subinst_dir = None
+    python_project_subinst_dir = os.path.join("Lib", "site-packages", project)
     project_script_subinst_dir = 'Scripts'
 else:
     tar_hflag = 'h'
-    python_project_subinst_dir = lib_project
+    python_project_subinst_dir = os.path.join("lib", project)
     project_script_subinst_dir = 'bin'
 
 
@@ -227,27 +229,60 @@ def SCons_revision(target, source, env):
     """
     t = str(target[0])
     s = source[0].rstr()
-    inf = open(s, 'rb')
-    outf = open(t, 'wb')
-    for line in inf.readlines():
-        # Note:  We construct the __*__ substitution strings here
-        # so that they don't get replaced when this file gets
-        # copied into the tree for packaging.
-        line = string.replace(line, '__BUILD'     + '__', env['BUILD'])
-        line = string.replace(line, '__BUILDSYS'  + '__', env['BUILDSYS'])
-        line = string.replace(line, '__COPYRIGHT' + '__', env['COPYRIGHT'])
-        line = string.replace(line, '__DATE'      + '__', env['DATE'])
-        line = string.replace(line, '__DEVELOPER' + '__', env['DEVELOPER'])
-        line = string.replace(line, '__FILE'      + '__', str(source[0]))
-        line = string.replace(line, '__REVISION'  + '__', env['REVISION'])
-        line = string.replace(line, '__VERSION'   + '__', env['VERSION'])
-        line = string.replace(line, '__NULL'      + '__', '')
-        outf.write(line)
-    inf.close()
-    outf.close()
+    contents = open(s, 'rb').read()
+    # Note:  We construct the __*__ substitution strings here
+    # so that they don't get replaced when this file gets
+    # copied into the tree for packaging.
+    contents = string.replace(contents, '__BUILD'     + '__', env['BUILD'])
+    contents = string.replace(contents, '__BUILDSYS'  + '__', env['BUILDSYS'])
+    contents = string.replace(contents, '__COPYRIGHT' + '__', env['COPYRIGHT'])
+    contents = string.replace(contents, '__DATE'      + '__', env['DATE'])
+    contents = string.replace(contents, '__DEVELOPER' + '__', env['DEVELOPER'])
+    contents = string.replace(contents, '__FILE'      + '__', str(source[0]))
+    contents = string.replace(contents, '__REVISION'  + '__', env['REVISION'])
+    contents = string.replace(contents, '__VERSION'   + '__', env['VERSION'])
+    contents = string.replace(contents, '__NULL'      + '__', '')
+    open(t, 'wb').write(contents)
     os.chmod(t, os.stat(s)[0])
 
-revbuilder = Builder(action = Action(SCons_revision, varlist=['VERSION']))
+revbuilder = Builder(action = Action(SCons_revision,
+                                     varlist=['COPYRIGHT', 'VERSION']))
+
+def soelim(target, source, env):
+    """
+    Interpolate files included in [gnt]roff source files using the
+    .so directive.
+
+    This behaves somewhat like the soelim(1) wrapper around groff, but
+    makes us independent of whether the actual underlying implementation
+    includes an soelim() command or the corresponding command-line option
+    to groff(1).  The key behavioral difference is that this doesn't
+    recursively include .so files from the include file.  Not yet, anyway.
+    """
+    t = str(target[0])
+    s = str(source[0])
+    dir, f = os.path.split(s)
+    tfp = open(t, 'w')
+    sfp = open(s, 'r')
+    for line in sfp.readlines():
+        if line[:4] in ['.so ', "'so "]:
+            sofile = os.path.join(dir, line[4:-1])
+            tfp.write(open(sofile, 'r').read())
+        else:
+            tfp.write(line)
+    sfp.close()
+    tfp.close()
+
+def soscan(node, env, path):
+    c = node.get_contents()
+    return re.compile(r"^[\.']so\s+(\S+)", re.M).findall(c)
+
+soelimbuilder = Builder(action = Action(soelim),
+                        source_scanner = Scanner(soscan))
+
+# When copying local files from a Repository (Aegis),
+# just make copies, don't symlink them.
+SetOption('duplicate', 'copy')
 
 env = Environment(
                    ENV                 = ENV,
@@ -283,20 +318,24 @@ env = Environment(
                    UNPACK_TAR_GZ_DIR   = unpack_tar_gz_dir,
                    UNPACK_ZIP_DIR      = unpack_zip_dir,
 
-                   BUILDERS            = { 'SCons_revision' : revbuilder },
+                   BUILDERS            = { 'SCons_revision' : revbuilder,
+                                           'SOElim' : soelimbuilder },
 
-                   PYTHON              = sys.executable
+                   PYTHON              = sys.executable,
+                   PYTHONFLAGS         = '-tt',
                  )
 
+Version_values = [Value(version), Value(build_id)]
+
 #
 # Define SCons packages.
 #
 # In the original, more complicated packaging scheme, we were going
 # to have separate packages for:
 #
-#      python-scons    only the build engine
-#      scons-script    only the script
-#      scons           the script plus the build engine
+#       python-scons    only the build engine
+#       scons-script    only the script
+#       scons           the script plus the build engine
 #
 # We're now only delivering a single "scons" package, but this is still
 # "built" as two sub-packages (the build engine and the script), so
@@ -330,6 +369,12 @@ python_scons = {
         'filemap'       : {
                             'LICENSE.txt' : '../LICENSE.txt'
                           },
+
+        'buildermap'    : {},
+
+        'explicit_deps' : {
+                            'SCons/__init__.py' : Version_values,
+                          },
 }
 
 #
@@ -365,6 +410,7 @@ python_scons = {
 #        'filemap'      : {
 #                            'LICENSE.txt' : '../LICENSE.txt',
 #                          },
+#        'buildermap'    : {},
 #}
 #
 
@@ -393,10 +439,22 @@ scons_script = {
                           ],
 
         'filemap'       : {
-                            'LICENSE.txt' : '../LICENSE.txt',
-                            'scons'       : 'scons.py',
-                            'sconsign'    : 'sconsign.py',
-                           }
+                            'LICENSE.txt'       : '../LICENSE.txt',
+                            'scons'             : 'scons.py',
+                            'sconsign'          : 'sconsign.py',
+                           },
+
+        'buildermap'    : {},
+
+        'extra_rpm_files' : [
+                            'scons-' + version,
+                            'sconsign-' + version,
+                          ],
+
+        'explicit_deps' : {
+                            'scons'       : Version_values,
+                            'sconsign'    : Version_values,
+                          },
 }
 
 scons = {
@@ -427,13 +485,18 @@ scons = {
                           ],
 
         'filemap'       : {
-                            'scons.1' : '../doc/man/scons.1',
-                            'sconsign.1' : '../doc/man/sconsign.1',
+                            'scons.1' : '../build/doc/man/scons.1',
+                            'sconsign.1' : '../build/doc/man/sconsign.1',
+                          },
+
+        'buildermap'    : {
+                            'scons.1' : env.SOElim,
+                            'sconsign.1' : env.SOElim,
                           },
 
-        'subpkgs'      : [ python_scons, scons_script ],
+        'subpkgs'       : [ python_scons, scons_script ],
 
-        'subinst_dirs' : {
+        'subinst_dirs'  : {
                              'python-' + project : python_project_subinst_dir,
                              project + '-script' : project_script_subinst_dir,
                            },
@@ -516,14 +579,18 @@ for p in [ scons ]:
                 rpm_files.append(r)
                 if f[-3:] == ".py":
                     rpm_files.append(r + 'c')
-            if isubdir:
-                files = map(lambda x, i=isubdir: os.path.join(i, x), files)
+            for f in sp.get('extra_rpm_files', []):
+                r = os.path.join(sp['rpm_dir'], f)
+                rpm_files.append(r)
+            files = map(lambda x, i=isubdir: os.path.join(i, x), files)
             dst_files.extend(files)
-            for k in sp['filemap'].keys():
-                f = sp['filemap'][k]
+            for k, f in sp['filemap'].items():
                 if f:
-                    k = os.path.join(sp['src_subdir'], k)
-                    p['filemap'][k] = os.path.join(sp['src_subdir'], f)
+                    k = os.path.join(ssubdir, k)
+                    p['filemap'][k] = os.path.join(ssubdir, f)
+            for f, deps in sp['explicit_deps'].items():
+                f = os.path.join(build, ssubdir, f)
+                env.Depends(f, deps)
 
     #
     # Now that we have the "normal" source files, add those files
@@ -539,7 +606,9 @@ for p in [ scons ]:
     #
     for b in src_files:
         s = p['filemap'].get(b, b)
-        env.SCons_revision(os.path.join(build, b), os.path.join(src, s))
+        builder = p['buildermap'].get(b, env.SCons_revision)
+        x = builder(os.path.join(build, b), os.path.join(src, s))
+        Local(x)
 
     #
     # NOW, finally, we can create the MANIFEST, which we do
@@ -552,7 +621,7 @@ for p in [ scons ]:
 
     def write_src_files(target, source, **kw):
         global src_files
-       src_files.sort()
+        src_files.sort()
         f = open(str(target[0]), 'wb')
         for file in src_files:
             f.write(file + "\n")
@@ -589,7 +658,7 @@ for p in [ scons ]:
         #
         # We'd like to replace the last three lines with the following:
         #
-        #      tar zxf $SOURCES -C $UNPACK_TAR_GZ_DIR
+        #       tar zxf $SOURCES -C $UNPACK_TAR_GZ_DIR
         #
         # but that gives heartburn to Cygwin's tar, so work around it
         # with separate zcat-tar-rm commands.
@@ -598,10 +667,10 @@ for p in [ scons ]:
                                          os.path.join(u, pv, x),
                                   src_files)
         env.Command(unpack_tar_gz_files, tar_gz, [
-                    "rm -rf %s" % os.path.join(unpack_tar_gz_dir, pkg_version),
+                    Delete(os.path.join(unpack_tar_gz_dir, pkg_version)),
                     "$ZCAT $SOURCES > .temp",
                     "tar xf .temp -C $UNPACK_TAR_GZ_DIR",
-                    "rm -f .temp",
+                    Delete(".temp"),
         ])
 
         #
@@ -619,12 +688,42 @@ for p in [ scons ]:
         #
         dfiles = map(lambda x, d=test_tar_gz_dir: os.path.join(d, x), dst_files)
         env.Command(dfiles, unpack_tar_gz_files, [
-            "rm -rf %s" % os.path.join(unpack_tar_gz_dir, pkg_version, 'build'),
-            "rm -rf $TEST_TAR_GZ_DIR",
-            "$PYTHON %s install --prefix=$TEST_TAR_GZ_DIR" % \
+            Delete(os.path.join(unpack_tar_gz_dir, pkg_version, 'build')),
+            Delete("$TEST_TAR_GZ_DIR"),
+            '$PYTHON $PYTHONFLAGS "%s" install "--prefix=$TEST_TAR_GZ_DIR" --standalone-lib' % \
                 os.path.join(unpack_tar_gz_dir, pkg_version, 'setup.py'),
         ])
 
+        #
+        # Generate portage files for submission to Gentoo Linux.
+        #
+        gentoo = os.path.join('build', 'gentoo')
+        ebuild = os.path.join(gentoo, 'scons-%s.ebuild' % version)
+        digest = os.path.join(gentoo, 'files', 'digest-scons-%s' % version)
+        env.Command(ebuild, os.path.join('gentoo', 'scons.ebuild.in'), SCons_revision)
+        def Digestify(target, source, env):
+            import md5
+            def hexdigest(s):
+                """Return a signature as a string of hex characters.
+                """
+                # NOTE:  This routine is a method in the Python 2.0 interface
+                # of the native md5 module, but we want SCons to operate all
+                # the way back to at least Python 1.5.2, which doesn't have it.
+                h = string.hexdigits
+                r = ''
+                for c in s:
+                    i = ord(c)
+                    r = r + h[(i >> 4) & 0xF] + h[i & 0xF]
+                return r
+            src = source[0].rfile()
+            contents = open(str(src)).read()
+            sig = hexdigest(md5.new(contents).digest())
+            bytes = os.stat(str(src))[6]
+            open(str(target[0]), 'w').write("MD5 %s %s %d\n" % (sig,
+                                                                src.name,
+                                                                bytes))
+        env.Command(digest, tar_gz, Digestify)
+
     if zipit:
 
         distutils_formats.append('zip')
@@ -643,8 +742,8 @@ for p in [ scons ]:
                                src_files)
 
         env.Command(unpack_zip_files, zip, [
-            "rm -rf %s" % os.path.join(unpack_zip_dir, pkg_version),
-            unzipit
+            Delete(os.path.join(unpack_zip_dir, pkg_version)),
+            unzipit,
         ])
 
         #
@@ -662,9 +761,9 @@ for p in [ scons ]:
         #
         dfiles = map(lambda x, d=test_zip_dir: os.path.join(d, x), dst_files)
         env.Command(dfiles, unpack_zip_files, [
-            "rm -rf %s" % os.path.join(unpack_zip_dir, pkg_version, 'build'),
-            "rm -rf $TEST_ZIP_DIR",
-            "$PYTHON %s install --prefix=$TEST_ZIP_DIR" % \
+            Delete(os.path.join(unpack_zip_dir, pkg_version, 'build')),
+            Delete("$TEST_ZIP_DIR"),
+            '$PYTHON $PYTHONFLAGS "%s" install "--prefix=$TEST_ZIP_DIR" --standalone-lib' % \
                 os.path.join(unpack_zip_dir, pkg_version, 'setup.py'),
         ])
 
@@ -672,6 +771,8 @@ for p in [ scons ]:
         topdir = os.path.join(os.getcwd(), build, 'build',
                               'bdist.' + platform, 'rpm')
 
+        buildroot = os.path.join(os.getcwd(), 'build', 'rpm-buildroot')
+
         BUILDdir = os.path.join(topdir, 'BUILD', pkg + '-' + version)
         RPMSdir = os.path.join(topdir, 'RPMS', 'noarch')
         SOURCESdir = os.path.join(topdir, 'SOURCES')
@@ -705,7 +806,7 @@ for p in [ scons ]:
         Local(sourcefile)
 
         targets = [ noarch_rpm, src_rpm ]
-        cmd = "$RPMBUILD --define '_topdir $(%s$)' -ba $SOURCES" % topdir
+        cmd = "$RPMBUILD --define '_topdir $(%s$)' --buildroot %s -ba $SOURCES" % (topdir, buildroot)
         if not os.path.isdir(BUILDdir):
             cmd = ("$( mkdir -p %s; $)" % BUILDdir) + cmd
         env.Command(targets, specfile, cmd)
@@ -744,56 +845,26 @@ for p in [ scons ]:
                     "dpkg --fsys-tarfile $SOURCES | (cd $TEST_DEB_DIR && tar -xf -)")
 
 
-    #
-    # Generate portage files for submission to Gentoo Linux.
-    #
-    gentoo = os.path.join('build', 'gentoo')
-    ebuild = os.path.join(gentoo, 'scons-%s.ebuild' % version)
-    digest = os.path.join(gentoo, 'files', 'digest-scons-%s' % version)
-    env.Command(ebuild, os.path.join('gentoo', 'scons.ebuild.in'), SCons_revision)
-    def Digestify(target, source, env):
-        import md5
-       def hexdigest(s):
-           """Return a signature as a string of hex characters.
-           """
-           # NOTE:  This routine is a method in the Python 2.0 interface
-           # of the native md5 module, but we want SCons to operate all
-           # the way back to at least Python 1.5.2, which doesn't have it.
-           h = string.hexdigits
-           r = ''
-           for c in s:
-               i = ord(c)
-               r = r + h[(i >> 4) & 0xF] + h[i & 0xF]
-           return r
-        src = source[0].rfile()
-        contents = open(str(src)).read()
-        sig = hexdigest(md5.new(contents).digest())
-        bytes = os.stat(str(src))[6]
-        open(str(target[0]), 'w').write("MD5 %s %s %d\n" % (sig,
-                                                            src.name,
-                                                            bytes))
-    env.Command(digest, tar_gz, Digestify)
-
     #
     # Use the Python distutils to generate the appropriate packages.
     #
     commands = [
-        "rm -rf %s" % os.path.join(build, 'build', 'lib'),
-        "rm -rf %s" % os.path.join(build, 'build', 'scripts'),
+        Delete(os.path.join(build, 'build', 'lib')),
+        Delete(os.path.join(build, 'build', 'scripts')),
     ]
 
     if distutils_formats:
-        commands.append("rm -rf %s" % os.path.join(build,
-                                                   'build',
-                                                   'bdist.' + platform,
-                                                   'dumb'))
+        commands.append(Delete(os.path.join(build,
+                                            'build',
+                                            'bdist.' + platform,
+                                            'dumb')))
         for format in distutils_formats:
-            commands.append("$PYTHON $SETUP_PY bdist_dumb -f %s" % format)
+            commands.append("$PYTHON $PYTHONFLAGS $SETUP_PY bdist_dumb -f %s" % format)
 
-        commands.append("$PYTHON $SETUP_PY sdist --formats=%s" %  \
+        commands.append("$PYTHON $PYTHONFLAGS $SETUP_PY sdist --formats=%s" %  \
                             string.join(distutils_formats, ','))
 
-    commands.append("$PYTHON $SETUP_PY bdist_wininst")
+    commands.append("$PYTHON $PYTHONFLAGS $SETUP_PY bdist_wininst")
 
     env.Command(distutils_targets, build_src_files, commands)
 
@@ -812,13 +883,15 @@ for p in [ scons ]:
     local_zip = os.path.join('build', 'dist', "%s.zip" % s_l_v)
 
     commands = [
-        "rm -rf %s" % local,
-        "$PYTHON $SETUP_PY install --install-script=%s --install-lib=%s --no-compile" % \
+        Delete(local),
+        '$PYTHON $PYTHONFLAGS $SETUP_PY install "--install-script=%s" "--install-lib=%s" --no-install-man --no-compile --standalone-lib --no-version-script' % \
                                                 (cwd_local, cwd_local_slv),
     ]
 
     for script in scripts:
-        commands.append("mv %s/%s %s/%s.py" % (local, script, local, script))
+        #commands.append("mv %s/%s %s/%s.py" % (local, script, local, script))
+        local_script = os.path.join(local, script)
+        commands.append(Move(local_script + '.py', local_script))
 
     rf = filter(lambda x: not x in scripts, raw_files)
     rf = map(lambda x, slv=s_l_v: os.path.join(slv, x), rf)
@@ -844,25 +917,25 @@ for p in [ scons ]:
         unpack_targets = map(lambda x, d=test_local_tar_gz_dir:
                                     os.path.join(d, x),
                              rf)
-        commands = ["rm -rf %s" % test_local_tar_gz_dir,
-                    "mkdir %s" % test_local_tar_gz_dir,
+        commands = [Delete(test_local_tar_gz_dir),
+                    Mkdir(test_local_tar_gz_dir),
                     "cd %s && tar xzf $( ${SOURCE.abspath} $)" % test_local_tar_gz_dir]
 
         env.Command(unpack_targets, local_tar_gz, commands)
 
     if zipit:
-        zipenv = env.Copy(CD = local, PSV = '.')
-        zipenv.Command(local_zip, local_targets, zipit)
+        env.Command(local_zip, local_targets, zipit,
+                    CD = local, PSV = '.')
 
         unpack_targets = map(lambda x, d=test_local_zip_dir:
                                     os.path.join(d, x),
                              rf)
-        commands = ["rm -rf %s" % test_local_zip_dir,
-                    "mkdir %s" % test_local_zip_dir,
+        commands = [Delete(test_local_zip_dir),
+                    Mkdir(test_local_zip_dir),
                     unzipit]
 
-        zipenv = env.Copy(UNPACK_ZIP_DIR = test_local_zip_dir)
-        zipenv.Command(unpack_targets, local_zip, unzipit)
+        env.Command(unpack_targets, local_zip, unzipit,
+                    UNPACK_ZIP_DIR = test_local_zip_dir)
 
     #
     # And, lastly, install the appropriate packages in the
@@ -901,7 +974,7 @@ if change:
 
     cmd = "aegis -list -terse pf 2>/dev/null"
     pf = map(lambda x: x[:-1], os.popen(cmd, "r").readlines())
-    cmd = "aegis -list -terse cf 2>/dev/null"
+    cmd = "aegis -list -terse -c %s cf 2>/dev/null" % change
     cf = map(lambda x: x[:-1], os.popen(cmd, "r").readlines())
     u = {}
     for f in pf + cf:
@@ -911,7 +984,9 @@ if change:
             del u[f]
         except KeyError:
             pass
-    sfiles = filter(lambda x: x[-9:] != '.aeignore' and x[-9:] != '.sconsign',
+    sfiles = filter(lambda x: x[-9:] != '.aeignore' and
+                              x[-9:] != '.sconsign' and
+                              x[-10:] != '.cvsignore',
                     u.keys())
 
     if sfiles:
@@ -931,10 +1006,9 @@ if change:
 
         b_ps_files = map(lambda x, d=b_ps: os.path.join(d, x), sfiles)
         cmds = [
-            "rm -rf %s" % b_psv,
-            "cp -rp %s %s" % (b_ps, b_psv),
-            "find %s -name .sconsign -exec rm {} \\;" % b_psv,
-            "touch $TARGET",
+            Delete(b_psv),
+            Copy(b_psv, b_ps),
+            Touch("$TARGET"),
         ]
 
         env.Command(b_psv_stamp, src_deps + b_ps_files, cmds)
@@ -956,15 +1030,15 @@ if change:
             #
             # We'd like to replace the last three lines with the following:
             #
-            #  tar zxf $SOURCES -C $UNPACK_TAR_GZ_DIR
+            #   tar zxf $SOURCES -C $UNPACK_TAR_GZ_DIR
             #
             # but that gives heartburn to Cygwin's tar, so work around it
             # with separate zcat-tar-rm commands.
             env.Command(unpack_tar_gz_files, src_tar_gz, [
-                "rm -rf %s" % os.path.join(unpack_tar_gz_dir, psv),
+                Delete(os.path.join(unpack_tar_gz_dir, psv)),
                 "$ZCAT $SOURCES > .temp",
                 "tar xf .temp -C $UNPACK_TAR_GZ_DIR",
-                "rm -f .temp",
+                Delete(".temp"),
             ])
 
             #
@@ -982,32 +1056,34 @@ if change:
             #
             dfiles = map(lambda x, d=test_src_tar_gz_dir: os.path.join(d, x),
                             dst_files)
-            ENV = env.Dictionary('ENV')
-            ENV['SCONS_LIB_DIR'] = os.path.join(unpack_tar_gz_dir, psv, 'src', 'engine')
+            scons_lib_dir = os.path.join(unpack_tar_gz_dir, psv, 'src', 'engine')
+            ENV = env.Dictionary('ENV').copy()
+            ENV['SCONS_LIB_DIR'] = scons_lib_dir
             ENV['USERNAME'] = developer
-            env.Copy(ENV = ENV).Command(dfiles, unpack_tar_gz_files, [
-                "rm -rf %s" % os.path.join(unpack_tar_gz_dir,
-                                           psv,
-                                           'build',
-                                           'scons',
-                                           'build'),
-                "rm -rf $TEST_SRC_TAR_GZ_DIR",
-                "cd %s && $PYTHON %s %s" % \
+            env.Command(dfiles, unpack_tar_gz_files,
+                [
+                Delete(os.path.join(unpack_tar_gz_dir,
+                                    psv,
+                                    'build',
+                                    'scons',
+                                    'build')),
+                Delete("$TEST_SRC_TAR_GZ_DIR"),
+                'cd "%s" && $PYTHON $PYTHONFLAGS "%s" "%s"' % \
                     (os.path.join(unpack_tar_gz_dir, psv),
                      os.path.join('src', 'script', 'scons.py'),
                      os.path.join('build', 'scons')),
-                "$PYTHON %s install --prefix=$TEST_SRC_TAR_GZ_DIR" % \
+                '$PYTHON $PYTHONFLAGS "%s" install "--prefix=$TEST_SRC_TAR_GZ_DIR" --standalone-lib' % \
                     os.path.join(unpack_tar_gz_dir,
                                  psv,
                                  'build',
                                  'scons',
                                  'setup.py'),
-            ])
+                ],
+                ENV = ENV)
 
         if zipit:
 
-            zipenv = env.Copy(CD = 'build', PSV = psv)
-            zipenv.Command(src_zip, b_psv_stamp, zipit)
+            env.Command(src_zip, b_psv_stamp, zipit, CD = 'build', PSV = psv)
 
             #
             # Unpack the archive into build/unpack/scons-{version}.
@@ -1017,7 +1093,7 @@ if change:
                                       sfiles)
 
             env.Command(unpack_zip_files, src_zip, [
-                "rm -rf %s" % os.path.join(unpack_zip_dir, psv),
+                Delete(os.path.join(unpack_zip_dir, psv)),
                 unzipit
             ])
 
@@ -1036,24 +1112,27 @@ if change:
             #
             dfiles = map(lambda x, d=test_src_zip_dir: os.path.join(d, x),
                             dst_files)
-            ENV = env.Dictionary('ENV')
-            ENV['SCONS_LIB_DIR'] = os.path.join(unpack_zip_dir, psv, 'src', 'engine')
+            scons_lib_dir = os.path.join(unpack_zip_dir, psv, 'src', 'engine')
+            ENV = env.Dictionary('ENV').copy()
+            ENV['SCONS_LIB_DIR'] = scons_lib_dir
             ENV['USERNAME'] = developer
-            env.Copy(ENV = ENV).Command(dfiles, unpack_zip_files, [
-                "rm -rf %s" % os.path.join(unpack_zip_dir,
-                                           psv,
-                                           'build',
-                                           'scons',
-                                           'build'),
-                "rm -rf $TEST_SRC_ZIP_DIR",
-                "cd %s && $PYTHON %s %s" % \
+            env.Command(dfiles, unpack_zip_files,
+                [
+                Delete(os.path.join(unpack_zip_dir,
+                                    psv,
+                                    'build',
+                                    'scons',
+                                    'build')),
+                Delete("$TEST_SRC_ZIP_DIR"),
+                'cd "%s" && $PYTHON $PYTHONFLAGS "%s" "%s"' % \
                     (os.path.join(unpack_zip_dir, psv),
                      os.path.join('src', 'script', 'scons.py'),
                      os.path.join('build', 'scons')),
-                "$PYTHON %s install --prefix=$TEST_SRC_ZIP_DIR" % \
+                '$PYTHON $PYTHONFLAGS "%s" install "--prefix=$TEST_SRC_ZIP_DIR" --standalone-lib' % \
                     os.path.join(unpack_zip_dir,
                                  psv,
                                  'build',
                                  'scons',
                                  'setup.py'),
-            ])
+                ],
+                ENV = ENV)