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.
29 Usage: scons-test.py [-f zipfile] [-o outdir] [-v] [--xml] [runtest arguments]
31 -f FILE Specify input .zip FILE name
32 -o DIR, --out DIR Change output directory name to DIR
33 -v, --verbose Print file names when extracting
37 opts, args = getopt.getopt(sys.argv[1:],
39 ['file=', 'out=', 'verbose', 'xml'])
43 printname = lambda x: x
44 inputfile = 'http://scons.sourceforge.net/scons-src-latest.zip'
47 if o == '-f' or o == '--file':
49 elif o == '-o' or o == '--out':
51 elif o == '-v' or o == '--verbose':
57 startdir = os.getcwd()
59 tempfile.template = 'scons-test.'
60 tempdir = tempfile.mktemp()
62 if not os.path.exists(tempdir):
64 def cleanup(tempdir=tempdir):
67 shutil.rmtree(tempdir)
68 sys.exitfunc = cleanup
70 # Fetch the input file if it happens to be across a network somewhere.
71 # Ohmigod, does Python make this simple...
72 inputfile, headers = urllib.urlretrieve(inputfile)
74 # Unzip the header file in the output directory. We use our own code
75 # (lifted from scons-unzip.py) to make the output subdirectory name
76 # match the basename of the .zip file.
77 zf = zipfile.ZipFile(inputfile, 'r')
80 name, _ = os.path.splitext(os.path.basename(inputfile))
81 outdir = os.path.join(tempdir, name)
83 def outname(n, outdir=outdir):
86 n, tail = os.path.split(n)
92 return os.path.join(*l)
94 for name in zf.namelist():
96 dir = os.path.dirname(dest)
102 # if the file exists, then delete it before writing
103 # to it so that we don't end up trying to write to a symlink:
104 if os.path.isfile(dest) or os.path.islink(dest):
106 if not os.path.isdir(dest):
107 open(dest, 'w').write(zf.read(name))
111 # Load (by hand) the SCons modules we just unwrapped so we can
112 # extract their version information. Note that we have to override
113 # SCons.Script.main() with a do_nothing() function, because loading up
114 # the 'scons' script will actually try to execute SCons...
115 src_script = os.path.join(outdir, 'src', 'script')
116 src_engine = os.path.join(outdir, 'src', 'engine')
117 src_engine_SCons = os.path.join(src_engine, 'SCons')
119 fp, pname, desc = imp.find_module('SCons', [src_engine])
120 SCons = imp.load_module('SCons', fp, pname, desc)
122 fp, pname, desc = imp.find_module('Script', [src_engine_SCons])
123 SCons.Script = imp.load_module('Script', fp, pname, desc)
127 SCons.Script.main = do_nothing
129 fp, pname, desc = imp.find_module('scons', [src_script])
130 scons = imp.load_module('scons', fp, pname, desc)
133 # Default is to run all the tests by passing the -a flags to runtest.py.
137 runtest_args = ' '.join(args)
139 if format == '--xml':
141 print "<scons_test_run>"
143 sys_keys = ['byteorder', 'exec_prefix', 'executable', 'maxint', 'maxunicode', 'platform', 'prefix', 'version', 'version_info']
145 print " <%s>%s</%s>" % (k, sys.__dict__[k], k)
148 fmt = '%a %b %d %H:%M:%S %Y'
150 print " <gmtime>%s</gmtime>" % time.strftime(fmt, time.gmtime())
151 print " <localtime>%s</localtime>" % time.strftime(fmt, time.localtime())
154 print " <tempdir>%s</tempdir>" % tempdir
156 def print_version_info(tag, module):
158 print " <version>%s</version>" % module.__version__
159 print " <build>%s</build>" % module.__build__
160 print " <buildsys>%s</buildsys>" % module.__buildsys__
161 print " <date>%s</date>" % module.__date__
162 print " <developer>%s</developer>" % module.__developer__
166 print_version_info("script", scons)
167 print_version_info("engine", SCons)
178 'INTEL_LICENSE_FILE',
206 print " <environment>"
207 #keys = os.environ.keys()
211 value = os.environ.get(key)
214 print " <name>%s</name>" % key
215 print " <value>%s</value>" % value
217 print " </environment>"
219 command = '"%s" runtest.py -q -o - --xml %s' % (sys.executable, runtest_args)
222 print "</scons_test_run>"
226 def print_version_info(tag, module):
227 print "\t%s: v%s.%s, %s, by %s on %s" % (tag,
231 module.__developer__,
234 print "SCons by Steven Knight et al.:"
235 print_version_info("script", scons)
236 print_version_info("engine", SCons)
238 command = '"%s" runtest.py %s' % (sys.executable, runtest_args)
244 # indent-tabs-mode:nil
246 # vim: set expandtab tabstop=4 shiftwidth=4: