3 # A script that takes an scons-src-{version}.zip file, unwraps it in
4 # a temporary location, and calls runtest.py to execute one or more of
7 # The default is to download the latest scons-src archive from the SCons
8 # web site, and to execute all of the tests.
10 # With a little more work, this will become the basis of an automated
11 # testing and reporting system that anyone will be able to use to
12 # participate in testing SCons on their system and regularly reporting
13 # back the results. A --xml option is a stab at gathering a lot of
14 # relevant information about the system, the Python version, etc.,
15 # so that problems on different platforms can be identified sooner.
28 # try Python 3.x style
29 from urllib.request import urlretrieve
31 # nope, must be 2.x; this hack is equivalent
33 # protect import from fixer
34 urlretrieve = imp.load_module('urllib',
35 *imp.find_module('urllib')).urlretrieve
38 Usage: scons-test.py [-f zipfile] [-o outdir] [-v] [--xml] [runtest arguments]
40 -f FILE Specify input .zip FILE name
41 -o DIR, --out DIR Change output directory name to DIR
42 -v, --verbose Print file names when extracting
46 opts, args = getopt.getopt(sys.argv[1:],
48 ['file=', 'out=', 'verbose', 'xml'])
52 printname = lambda x: x
53 inputfile = 'http://scons.sourceforge.net/scons-src-latest.zip'
56 if o == '-f' or o == '--file':
58 elif o == '-o' or o == '--out':
60 elif o == '-v' or o == '--verbose':
66 startdir = os.getcwd()
68 tempfile.template = 'scons-test.'
69 tempdir = tempfile.mktemp()
71 if not os.path.exists(tempdir):
73 def cleanup(tempdir=tempdir):
76 shutil.rmtree(tempdir)
77 sys.exitfunc = cleanup
79 # Fetch the input file if it happens to be across a network somewhere.
80 # Ohmigod, does Python make this simple...
81 inputfile, headers = urlretrieve(inputfile)
83 # Unzip the header file in the output directory. We use our own code
84 # (lifted from scons-unzip.py) to make the output subdirectory name
85 # match the basename of the .zip file.
86 zf = zipfile.ZipFile(inputfile, 'r')
89 name, _ = os.path.splitext(os.path.basename(inputfile))
90 outdir = os.path.join(tempdir, name)
92 def outname(n, outdir=outdir):
95 n, tail = os.path.split(n)
101 return os.path.join(*l)
103 for name in zf.namelist():
105 dir = os.path.dirname(dest)
111 # if the file exists, then delete it before writing
112 # to it so that we don't end up trying to write to a symlink:
113 if os.path.isfile(dest) or os.path.islink(dest):
115 if not os.path.isdir(dest):
116 open(dest, 'w').write(zf.read(name))
120 # Load (by hand) the SCons modules we just unwrapped so we can
121 # extract their version information. Note that we have to override
122 # SCons.Script.main() with a do_nothing() function, because loading up
123 # the 'scons' script will actually try to execute SCons...
124 src_script = os.path.join(outdir, 'src', 'script')
125 src_engine = os.path.join(outdir, 'src', 'engine')
126 src_engine_SCons = os.path.join(src_engine, 'SCons')
128 fp, pname, desc = imp.find_module('SCons', [src_engine])
129 SCons = imp.load_module('SCons', fp, pname, desc)
131 fp, pname, desc = imp.find_module('Script', [src_engine_SCons])
132 SCons.Script = imp.load_module('Script', fp, pname, desc)
136 SCons.Script.main = do_nothing
138 fp, pname, desc = imp.find_module('scons', [src_script])
139 scons = imp.load_module('scons', fp, pname, desc)
142 # Default is to run all the tests by passing the -a flags to runtest.py.
146 runtest_args = ' '.join(args)
148 if format == '--xml':
150 print "<scons_test_run>"
152 sys_keys = ['byteorder', 'exec_prefix', 'executable', 'maxint', 'maxunicode', 'platform', 'prefix', 'version', 'version_info']
154 print " <%s>%s</%s>" % (k, sys.__dict__[k], k)
157 fmt = '%a %b %d %H:%M:%S %Y'
159 print " <gmtime>%s</gmtime>" % time.strftime(fmt, time.gmtime())
160 print " <localtime>%s</localtime>" % time.strftime(fmt, time.localtime())
163 print " <tempdir>%s</tempdir>" % tempdir
165 def print_version_info(tag, module):
167 print " <version>%s</version>" % module.__version__
168 print " <build>%s</build>" % module.__build__
169 print " <buildsys>%s</buildsys>" % module.__buildsys__
170 print " <date>%s</date>" % module.__date__
171 print " <developer>%s</developer>" % module.__developer__
175 print_version_info("script", scons)
176 print_version_info("engine", SCons)
187 'INTEL_LICENSE_FILE',
215 print " <environment>"
216 for key in sorted(environ_keys):
217 value = os.environ.get(key)
220 print " <name>%s</name>" % key
221 print " <value>%s</value>" % value
223 print " </environment>"
225 command = '"%s" runtest.py -q -o - --xml %s' % (sys.executable, runtest_args)
228 print "</scons_test_run>"
232 def print_version_info(tag, module):
233 print "\t%s: v%s.%s, %s, by %s on %s" % (tag,
237 module.__developer__,
240 print "SCons by Steven Knight et al.:"
241 print_version_info("script", scons)
242 print_version_info("engine", SCons)
244 command = '"%s" runtest.py %s' % (sys.executable, runtest_args)
250 # indent-tabs-mode:nil
252 # vim: set expandtab tabstop=4 shiftwidth=4: