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.
30 Usage: scons-test.py [-f zipfile] [-o outdir] [-v] [--xml] [runtest arguments]
32 -f FILE Specify input .zip FILE name
33 -o DIR, --out DIR Change output directory name to DIR
34 -v, --verbose Print file names when extracting
38 opts, args = getopt.getopt(sys.argv[1:],
40 ['file=', 'out=', 'verbose', 'xml'])
44 printname = lambda x: x
45 inputfile = 'http://scons.sourceforge.net/scons-src-latest.zip'
48 if o == '-f' or o == '--file':
50 elif o == '-o' or o == '--out':
52 elif o == '-v' or o == '--verbose':
58 startdir = os.getcwd()
60 tempfile.template = 'scons-test.'
61 tempdir = tempfile.mktemp()
63 if not os.path.exists(tempdir):
65 def cleanup(tempdir=tempdir):
68 shutil.rmtree(tempdir)
69 sys.exitfunc = cleanup
71 # Fetch the input file if it happens to be across a network somewhere.
72 # Ohmigod, does Python make this simple...
73 inputfile, headers = urllib.urlretrieve(inputfile)
75 # Unzip the header file in the output directory. We use our own code
76 # (lifted from scons-unzip.py) to make the output subdirectory name
77 # match the basename of the .zip file.
78 zf = zipfile.ZipFile(inputfile, 'r')
81 name, _ = os.path.splitext(os.path.basename(inputfile))
82 outdir = os.path.join(tempdir, name)
84 def outname(n, outdir=outdir):
87 n, tail = os.path.split(n)
93 return apply(os.path.join, l)
95 for name in zf.namelist():
97 dir = os.path.dirname(dest)
103 # if the file exists, then delete it before writing
104 # to it so that we don't end up trying to write to a symlink:
105 if os.path.isfile(dest) or os.path.islink(dest):
107 if not os.path.isdir(dest):
108 open(dest, 'w').write(zf.read(name))
112 # Load (by hand) the SCons modules we just unwrapped so we can
113 # extract their version information. Note that we have to override
114 # SCons.Script.main() with a do_nothing() function, because loading up
115 # the 'scons' script will actually try to execute SCons...
116 src_script = os.path.join(outdir, 'src', 'script')
117 src_engine = os.path.join(outdir, 'src', 'engine')
118 src_engine_SCons = os.path.join(src_engine, 'SCons')
120 fp, pname, desc = imp.find_module('SCons', [src_engine])
121 SCons = imp.load_module('SCons', fp, pname, desc)
123 fp, pname, desc = imp.find_module('Script', [src_engine_SCons])
124 SCons.Script = imp.load_module('Script', fp, pname, desc)
128 SCons.Script.main = do_nothing
130 fp, pname, desc = imp.find_module('scons', [src_script])
131 scons = imp.load_module('scons', fp, pname, desc)
134 # Default is to run all the tests by passing the -a flags to runtest.py.
138 runtest_args = string.join(args)
140 if format == '--xml':
142 print "<scons_test_run>"
144 sys_keys = ['byteorder', 'exec_prefix', 'executable', 'maxint', 'maxunicode', 'platform', 'prefix', 'version', 'version_info']
146 print " <%s>%s</%s>" % (k, sys.__dict__[k], k)
149 fmt = '%a %b %d %H:%M:%S %Y'
151 print " <gmtime>%s</gmtime>" % time.strftime(fmt, time.gmtime())
152 print " <localtime>%s</localtime>" % time.strftime(fmt, time.localtime())
155 print " <tempdir>%s</tempdir>" % tempdir
157 def print_version_info(tag, module):
159 print " <version>%s</version>" % module.__version__
160 print " <build>%s</build>" % module.__build__
161 print " <buildsys>%s</buildsys>" % module.__buildsys__
162 print " <date>%s</date>" % module.__date__
163 print " <developer>%s</developer>" % module.__developer__
167 print_version_info("script", scons)
168 print_version_info("engine", SCons)
179 'INTEL_LICENSE_FILE',
207 print " <environment>"
208 #keys = os.environ.keys()
212 value = os.environ.get(key)
215 print " <name>%s</name>" % key
216 print " <value>%s</value>" % value
218 print " </environment>"
220 command = '"%s" runtest.py -q -o - --xml %s' % (sys.executable, runtest_args)
223 print "</scons_test_run>"
227 def print_version_info(tag, module):
228 print "\t%s: v%s.%s, %s, by %s on %s" % (tag,
232 module.__developer__,
235 print "SCons by Steven Knight et al.:"
236 print_version_info("script", scons)
237 print_version_info("engine", SCons)
239 command = '"%s" runtest.py %s' % (sys.executable, runtest_args)
245 # indent-tabs-mode:nil
247 # vim: set expandtab tabstop=4 shiftwidth=4: