version = None
testver = 1
+if sys.platform == 'win32':
+ lib_dir = os.path.join(sys.exec_prefix, "lib")
+else:
+ lib_dir = os.path.join(sys.exec_prefix, "lib", "python" + sys.version[0:3])
+
opts, tests = getopt.getopt(sys.argv[1:], "12ab:dqv:",
['all','build=','debug','quiet','version='])
elif o == '-2': testver = 2
elif o == '-a' or o == '--all': all = 1
elif o == '-b' or o == '--build': build = a
- elif o == '-d' or o == '--debug': debug = os.path.join(
- sys.exec_prefix,
- "lib",
- "python" + sys.version[0:3],
- "pdb.py")
+ elif o == '-d' or o == '--debug': debug = os.path.join(lib_dir, "pdb.py")
elif o == '-q' or o == '--quiet': printcmd = 0
elif o == '-v' or o == '--version': version = a
if os.system(cmd):
fail.append(path)
+if fail and len(tests) != 1:
+ if len(fail) == 1:
+ str = "test"
+ else:
+ str = "%d tests" % len(fail)
+ print "\nFailed the following %s:" % str
+ print "\t", string.join(fail, "\n\t")
+
sys.exit(len(fail))
exts = string.split(exts, os.pathsep)
pairs = []
for dir in path:
- for e in [None] + exts:
- pairs.append(dir, e)
+ for e in exts:
+ pairs.append((dir, e))
for dir, ext in pairs:
f = os.path.join(dir, cmd)
if not ext is None:
elif os.name == 'nt':
+ MVSdir = r'C:\Program Files\Microsoft Visual Studio'
+ MVSVCdir = r'%s\VC98' % MVSdir
+ MVSCommondir = r'%s\Common' % MVSdir
+
ConstructionEnvironment = {
'CC' : 'cl',
'CCFLAGS' : '/nologo',
'CXXCOM' : '$CXX $CXXFLAGS $_INCFLAGS /c $SOURCES /Fo$TARGET',
'LINK' : 'link',
'LINKFLAGS' : '',
- 'LINKCOM' : '$LINK $LINKFLAGS /out:$TARGET $_LIBDIRFLAGS $_LIBFLAGS $SOURCES',
+ 'LINKCOM' : '$LINK $LINKFLAGS /OUT:$TARGET $_LIBDIRFLAGS $_LIBFLAGS $SOURCES',
'AR' : 'lib',
'ARFLAGS' : '/nologo',
- 'ARCOM' : '$AR $ARFLAGS /out:$TARGET $SOURCES',
+ 'ARCOM' : '$AR $ARFLAGS /OUT:$TARGET $SOURCES',
'BUILDERS' : [Object, Program, Library],
'SCANNERS' : [CScan],
'OBJPREFIX' : '',
'PROGSUFFIX' : '.exe',
'LIBPREFIX' : '',
'LIBSUFFIX' : '.lib',
- 'LIBDIRPREFIX' : '/L',
+ 'LIBDIRPREFIX' : '/LIBPATH',
'LIBDIRSUFFIX' : '',
'LIBLINKPREFIX' : '',
'LIBLINKSUFFIX' : '$LIBSUFFIX',
'INCPREFIX' : '/I',
'INCSUFFIX' : '',
'ENV' : {
- 'PATH' : r'C:\Python20;C:\WINNT\system32;C:\WINNT;C:\Program Files\Microsoft Visual Studio\VC98\Bin\;',
+ 'INCLUDE' : r'%s\atl\include;%s\mfc\include;%s\include'
+ % (MVSVCdir, MVSVCdir, MVSVCdir),
+ 'LIB' : r'%s\mvc\lib;%s\lib'
+ % (MVSVCdir, MVSVCdir),
+ 'MSDEVDIR' : r'%s\MSDev98' % MVSCommondir,
+ 'PATH' : r'C:\Python20;C:\WINNT\system32;C:\WINNT;%s\Tools\WinNT;%s\MSDev98\Bin;%s\Tools;%s\Bin;'
+ % (MVSCommondir, MVSCommondir,
+ MVSCommondir, MVSVCdir),
'PATHEXT' : '.COM;.EXE;.BAT;.CMD',
},
}
import copy
+import os.path
import re
import types
import SCons.Util
suffix =''
self._dict[strVarAuto] = map(lambda x, suff=suffix, pref=prefix: \
- pref + str(x) + suff,
+ pref + os.path.normpath(str(x)) + suff,
src_var)
def __cmp__(self, other):
def __delitem__(self, key):
del(self.data[PathName(key)])
- if not hasattr(UserDict, 'setdefault'):
- def setdefault(self, key, value):
- try:
- return self.data[PathName(key)]
- except KeyError:
- self.data[PathName(key)] = value
- return value
+ def setdefault(self, key, value):
+ try:
+ return self.data[PathName(key)]
+ except KeyError:
+ self.data[PathName(key)] = value
+ return value
class FS:
def __init__(self, path = None):
self.Root = PathDict()
self.Top = self.__doLookup(Dir, path)
self.Top.path = '.'
- self.Top.path_ = './'
+ self.Top.path_ = os.path.join('.', '')
self.cwd = self.Top
def __doLookup(self, fsclass, name, directory=None):
# None, raise an exception.
drive, tail = os.path.splitdrive(head)
- if sys.platform is 'win32' and not drive:
- if not directory:
- raise OSError, 'No drive letter supplied for absolute path.'
- return directory.root()
- return self.Root.setdefault(drive, Dir(tail))
+ #if sys.platform is 'win32' and not drive:
+ # if not directory:
+ # raise OSError, 'No drive letter supplied for absolute path.'
+ # return directory.root()
+ dir = Dir(tail)
+ dir.path = drive + dir.path
+ dir.path_ = drive + dir.path_
+ dir.abspath = drive + dir.abspath
+ dir.abspath_ = drive + dir.abspath_
+ return self.Root.setdefault(drive, dir)
if head:
# Recursively look up our parent directories.
directory = self.__doLookup(Dir, head, directory)
usually in preparation for a call to doLookup().
If the path name is prepended with a '#', then it is unconditionally
- interpreted as replative to the top-level directory of this FS.
+ interpreted as relative to the top-level directory of this FS.
If directory is None, and name is a relative path,
then the same applies.
if directory:
self.abspath = os.path.join(directory.abspath, name)
if str(directory.path) == '.':
- self.path = os.path.join(name)
+ self.path = name
else:
self.path = os.path.join(directory.path, name)
else:
def children(self):
#XXX --random: randomize "dependencies?"
- kids = map(lambda x, s=self: s.entries[x],
- filter(lambda k: k != '.' and k != '..',
- self.entries.keys()))
+ keys = filter(lambda k: k != '.' and k != '..', self.entries.keys())
+ kids = map(lambda x, s=self: s.entries[x], keys)
def c(one, two):
if one.abspath < two.abspath:
return -1
def Dir_test(lpath, path_, abspath_, up_path_, fileSys=fs, s=sep):
dir = fileSys.Dir(string.replace(lpath, '/', s))
+ if os.sep != '/':
+ path_ = string.replace(path_, '/', os.sep)
+ abspath_ = string.replace(abspath_, '/', os.sep)
+ up_path_ = string.replace(up_path_, '/', os.sep)
+
def strip_slash(p):
- if p[-1] == '/' and len(p) > 1:
+ if p[-1] == os.sep and len(p) > 1:
p = p[:-1]
return p
path = strip_slash(path_)
abspath = strip_slash(abspath_)
up_path = strip_slash(up_path_)
- name = string.split(abspath, '/')[-1]
-
- if os.sep != '/':
- path = string.replace(path, '/', os.sep)
- path_ = string.replace(path_, '/', os.sep)
- abspath = string.replace(abspath, '/', os.sep)
- abspath_ = string.replace(abspath_, '/', os.sep)
- up_path = string.replace(up_path, '/', os.sep)
- up_path_ = string.replace(up_path_, '/', os.sep)
+ name = string.split(abspath, os.sep)[-1]
assert dir.name == name, \
"dir.name %s != expected name %s" % \
f1.build()
assert built_it
+ def match(path, expect):
+ expect = string.replace(expect, '/', os.sep)
+ assert path == expect, "path %s != expected %s" % (path, expect)
+
e1 = fs.Entry("d1")
assert e1.__class__.__name__ == 'Dir'
- assert e1.path == "d1", e1.path
- assert e1.path_ == "d1/", e1.path_
- assert e1.dir.path == ".", e1.dir.path
+ match(e1.path, "d1")
+ match(e1.path_, "d1/")
+ match(e1.dir.path, ".")
e2 = fs.Entry("d1/f1")
assert e2.__class__.__name__ == 'File'
- assert e2.path == "d1/f1", e2.path
- assert e2.path_ == "d1/f1", e2.path_
- assert e2.dir.path == "d1", e2.dir.path
+ match(e2.path, "d1/f1")
+ match(e2.path_, "d1/f1")
+ match(e2.dir.path, "d1")
e3 = fs.Entry("e3")
assert e3.__class__.__name__ == 'Entry'
- assert e3.path == "e3", e3.path
- assert e3.path_ == "e3", e3.path_
- assert e3.dir.path == ".", e3.dir.path
+ match(e3.path, "e3")
+ match(e3.path_, "e3")
+ match(e3.dir.path, ".")
e4 = fs.Entry("d1/e4")
assert e4.__class__.__name__ == 'Entry'
- assert e4.path == "d1/e4", e4.path
- assert e4.path_ == "d1/e4", e4.path_
- assert e4.dir.path == "d1", e4.dir.path
+ match(e4.path, "d1/e4")
+ match(e4.path_, "d1/e4")
+ match(e4.dir.path, "d1")
e5 = fs.Entry("e3/e5")
assert e3.__class__.__name__ == 'Dir'
- assert e3.path == "e3", e3.path
- assert e3.path_ == "e3/", e3.path_
- assert e3.dir.path == ".", e3.dir.path
+ match(e3.path, "e3")
+ match(e3.path_, "e3/")
+ match(e3.dir.path, ".")
assert e5.__class__.__name__ == 'Entry'
- assert e5.path == "e3/e5", e5.path
- assert e5.path_ == "e3/e5", e5.path_
- assert e5.dir.path == "e3", e5.dir.path
+ match(e5.path, "e3/e5")
+ match(e5.path_, "e3/e5")
+ match(e5.dir.path, "e3")
e6 = fs.Dir("d1/e4")
assert e6 is e4
assert e4.__class__.__name__ == 'Dir'
- assert e4.path == "d1/e4", e4.path
- assert e4.path_ == "d1/e4/", e4.path_
- assert e4.dir.path == "d1", e4.dir.path
+ match(e4.path, "d1/e4")
+ match(e4.path_, "d1/e4/")
+ match(e4.dir.path, "d1")
e7 = fs.File("e3/e5")
assert e7 is e5
assert e5.__class__.__name__ == 'File'
- assert e5.path == "e3/e5", e5.path
- assert e5.path_ == "e3/e5", e5.path_
- assert e5.dir.path == "e3", e5.dir.path
+ match(e5.path, "e3/e5")
+ match(e5.path_, "e3/e5")
+ match(e5.dir.path, "e3")
e8 = fs.Entry("e8")
assert e8.get_bsig() is None, e8.get_bsig()
fs.chdir(fs.Dir('subdir'))
f11 = fs.File("f11")
- assert f11.path == "subdir/f11"
+ match(f11.path, "subdir/f11")
d12 = fs.Dir("d12")
- assert d12.path_ == "subdir/d12/"
+ match(d12.path_, "subdir/d12/")
e13 = fs.Entry("subdir/e13")
- assert e13.path == "subdir/subdir/e13"
+ match(e13.path, "subdir/subdir/e13")
# Test scanning
f1.scanner = Scanner()
f1.scan()
- assert f1.depends[0].path_ == "d1/f1"
+ assert f1.depends[0].path_ == os.path.join("d1", "f1")
f1.scanner = None
f1.depends = []
f1.scanned = 0
f1.scan()
- assert f1.depends[0].path_ == "d1/f1"
+ assert f1.depends[0].path_ == os.path.join("d1", "f1")
# Test building a file whose directory is not there yet...
f1 = fs.File(test.workpath("foo/bar/baz/ack"))
"""
def __init__(self, targets=[], tasker=Task, calc=Calc()):
- self.walkers = map(SCons.Node.Walker, targets)
+ def out_of_date(node):
+ return filter(lambda x: x.get_state() != SCons.Node.up_to_date,
+ node.children())
+ self.walkers = map(lambda x, f=out_of_date: SCons.Node.Walker(x, f),
+ targets)
self.tasker = tasker
self.calc = calc
self.ready = []
bar.Program(target = 'bar', source = 'bar.c')
""" % python)
-test.write('foo.c', """
+test.write('foo.c', r"""
int
main(int argc, char *argv[])
{
}
""")
-test.write('bar.c', """
+test.write('bar.c', r"""
int
main(int argc, char *argv[])
{
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import sys
import TestSCons
+if sys.platform == 'win32':
+ _obj = '.obj'
+ fooflags = '/nologo -DFOO'
+ barflags = '/nologo -DBAR'
+else:
+ _obj = '.o'
+ fooflags = '-DFOO'
+ barflags = '-DBAR'
+
test = TestSCons.TestSCons()
test.write('SConstruct', """
-foo = Environment(CCFLAGS = '-DFOO')
-bar = Environment(CCFLAGS = '-DBAR')
-foo.Object(target = 'foo.o', source = 'prog.c')
-bar.Object(target = 'bar.o', source = 'prog.c')
-foo.Program(target = 'foo', source = 'foo.o')
-bar.Program(target = 'bar', source = 'bar.o')
-""")
+foo = Environment(CCFLAGS = '%s')
+bar = Environment(CCFLAGS = '%s')
+foo.Object(target = 'foo%s', source = 'prog.c')
+bar.Object(target = 'bar%s', source = 'prog.c')
+foo.Program(target = 'foo', source = 'foo%s')
+bar.Program(target = 'bar', source = 'bar%s')
+""" % (fooflags, barflags, _obj, _obj, _obj, _obj))
-test.write('prog.c', """
+test.write('prog.c', r"""
int
main(int argc, char *argv[])
{
test.write('SConstruct', """
bar = Environment(CCFLAGS = '-DBAR')
-bar.Object(target = 'foo.o', source = 'prog.c')
-bar.Object(target = 'bar.o', source = 'prog.c')
-bar.Program(target = 'foo', source = 'foo.o')
-bar.Program(target = 'bar', source = 'bar.o')
-""")
+bar.Object(target = 'foo%s', source = 'prog.c')
+bar.Object(target = 'bar%s', source = 'prog.c')
+bar.Program(target = 'foo', source = 'foo%s')
+bar.Program(target = 'bar', source = 'bar%s')
+""" % (_obj, _obj, _obj, _obj))
test.run(arguments = '.')
foo_in = os.path.join(dir, 'foo.in')
bar_in = os.path.join(dir, 'bar.in')
- test.write(foo_in, foo_in + "\n");
+ test.write(foo_in, dir + "/foo.in\n");
- test.write(bar_in, bar_in + "\n");
+ test.write(bar_in, dir + "/bar.in\n");
test.run(chdir = dir) # no arguments, use the Default
env.Program(target = 'prog', source = 'prog.c')
""")
-test.write('f1.c', """
+test.write('f1.c', r"""
void
f1(void)
{
}
""")
-test.write('f2a.c', """
+test.write('f2a.c', r"""
void
f2a(void)
{
}
""")
-test.write('f2b.c', """
+test.write('f2b.c', r"""
void
f2b(void)
{
}
""")
-test.write('f2c.c', """
+test.write('f2c.c', r"""
void
f2c(void)
{
}
""")
-test.write('f3a.c', """
+test.write('f3a.c', r"""
void
f3a(void)
{
}
""")
-test.write('f3b.c', """
+test.write('f3b.c', r"""
void
f3b(void)
{
}
""")
-test.write('f3c.c', """
+test.write('f3c.c', r"""
f3c(void)
{
printf("f3c.c\n");
}
""")
-test.write('prog.c', """
+test.write('prog.c', r"""
void f1(void);
void f2a(void);
void f2b(void);
}
""")
-test.run(arguments = 'prog')
+test.run(arguments = '.')
test.run(program = test.workpath('prog'),
stdout = "f1.c\nf2a.c\nf2b.c\nf2c.c\nf3a.c\nf3b.c\nf3c.c\nprog.c\n")
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import sys
import TestSCons
+if sys.platform == 'win32':
+ _obj = '.obj'
+else:
+ _obj = '.o'
+
test = TestSCons.TestSCons()
test.write('SConstruct', """
f1 = env.Object(target = 'f1', source = 'f1.c')
f2 = env.Object(target = 'f2', source = 'f2.cpp')
f3 = env.Object(target = 'f3', source = 'f3.c')
-env.Program(target = 'prog1', source = 'f1.o f2.o f3.o prog.cpp')
+env.Program(target = 'prog1', source = 'f1%s f2%s f3%s prog.cpp')
env.Program(target = 'prog2', source = [f1, f2, f3, 'prog.cpp'])
-env.Program(target = 'prog3', source = ['f1.o', f2, 'f3.o', 'prog.cpp'])
-""")
+env.Program(target = 'prog3', source = ['f1%s', f2, 'f3%s', 'prog.cpp'])
+""" % (_obj, _obj, _obj, _obj, _obj))
test.write('f1.c', """
void
env.Program(target = 'foo3', source = ['f3a.c', 'f3b.c', 'f3c.c'])
""")
-test.write('f1.c', """
+test.write('f1.c', r"""
int
main(int argc, char *argv[])
{
}
""")
-test.write('f2a.c', """
+test.write('f2a.c', r"""
void
f2a(void)
{
}
""")
-test.write('f2b.c', """
+test.write('f2b.c', r"""
void
f2b(void)
{
}
""")
-test.write('f2c.c', """
+test.write('f2c.c', r"""
extern void f2a(void);
extern void f2b(void);
int
}
""")
-test.write('f3a.c', """
+test.write('f3a.c', r"""
void
f3a(void)
{
}
""")
-test.write('f3b.c', """
+test.write('f3b.c', r"""
void
f3b(void)
{
}
""")
-test.write('f3c.c', """
+test.write('f3c.c', r"""
extern void f3a(void);
extern void f3b(void);
int
test.up_to_date(arguments = '.')
-test.write('f1.c', """
+test.write('f1.c', r"""
int
main(int argc, char *argv[])
{
}
""")
-test.write('f3b.c', """
+test.write('f3b.c', r"""
void
f3b(void)
{
test.fail_test(not (oldtime2 == os.path.getmtime(test.workpath('foo2'))))
test.fail_test(not (oldtime3 == os.path.getmtime(test.workpath('foo3'))))
-test.write('f1.c', """
+test.write('f1.c', r"""
int
main(int argc, char *argv[])
{
}
""")
-test.write('f3b.c', """
+test.write('f3b.c', r"""
void
f3b(void)
{
test.up_to_date(arguments = 'foo1 foo2 foo3')
-test.write('f1.c', """
+test.write('f1.c', r"""
int
main(int argc, char *argv[])
{
}
""")
-test.write('f3b.c', """
+test.write('f3b.c', r"""
void
f3b(void)
{
env.Program(target = 'foo1', source = 'f1.c')
""")
-test.write('f1.c', """
+test.write('f1.c', r"""
int
main(int argc, char *argv[])
{
test.write('build.py', r"""
import sys
-contents = open(sys.argv[2], 'r').read()
-file = open(sys.argv[1], 'w')
+contents = open(sys.argv[2], 'rb').read()
+file = open(sys.argv[1], 'wb')
file.write(contents)
file.close()
""")
env.B(target = 'subdir/f4.out', source = 'subdir/f4.in')
""")
-test.write('subdir/f1.in', "f1.in\n")
-test.write('subdir/f2.in', "f2.in\n")
-test.write('subdir/f3.in', "f3.in\n")
-test.write('subdir/f4.in', "f4.in\n")
+test.write(['subdir', 'f1.in'], "f1.in\n")
+test.write(['subdir', 'f2.in'], "f2.in\n")
+test.write(['subdir', 'f3.in'], "f3.in\n")
+test.write(['subdir', 'f4.in'], "f4.in\n")
test.run(arguments = 'subdir')
-test.fail_test(test.read('subdir/f1.out') != "f1.in\n")
-test.fail_test(test.read('subdir/f2.out') != "f2.in\n")
-test.fail_test(test.read('subdir/f3.out') != "f3.in\n")
-test.fail_test(test.read('subdir/f4.out') != "f4.in\n")
+test.fail_test(test.read(['subdir', 'f1.out']) != "f1.in\n")
+test.fail_test(test.read(['subdir', 'f2.out']) != "f2.in\n")
+test.fail_test(test.read(['subdir', 'f3.out']) != "f3.in\n")
+test.fail_test(test.read(['subdir', 'f4.out']) != "f4.in\n")
test.up_to_date(arguments = 'subdir')