summaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/SCons/Builder.py78
-rw-r--r--src/engine/SCons/BuilderTests.py16
-rw-r--r--src/engine/SCons/Defaults.py68
-rw-r--r--src/engine/SCons/Node/FSTests.py141
-rw-r--r--src/engine/SCons/Sig/MD5.py12
-rw-r--r--src/engine/SCons/UtilTests.py32
6 files changed, 240 insertions, 107 deletions
diff --git a/src/engine/SCons/Builder.py b/src/engine/SCons/Builder.py
index 1f4f555..1e3c9b9 100644
--- a/src/engine/SCons/Builder.py
+++ b/src/engine/SCons/Builder.py
@@ -32,6 +32,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import os
+import os.path
import SCons.Node.FS
from SCons.Util import PathList, scons_str2nodes, scons_subst
import string
@@ -39,6 +40,62 @@ import types
+if os.name == 'posix':
+
+ def spawn(cmd, args, env):
+ pid = os.fork()
+ if not pid:
+ # Child process.
+ os.execvpe(cmd, args, env)
+ else:
+ # Parent process.
+ pid, stat = os.waitpid(pid, 0)
+ ret = stat >> 8
+ return ret
+
+elif os.name == 'nt':
+
+ def pathsearch(cmd, env):
+ # In order to deal with the fact that 1.5.2 doesn't have
+ # os.spawnvpe(), roll our own PATH search.
+ if os.path.isabs(cmd):
+ if not os.path.exists(cmd):
+ exts = env['PATHEXT']
+ if type(exts) != type([]):
+ exts = string.split(exts, os.pathsep)
+ for e in exts:
+ f = cmd + e
+ if os.path.exists(f):
+ return f
+ else:
+ path = env['PATH']
+ if type(path) != type([]):
+ path = string.split(path, os.pathsep)
+ exts = env['PATHEXT']
+ if type(exts) != type([]):
+ exts = string.split(exts, os.pathsep)
+ pairs = []
+ for dir in path:
+ for e in [None] + exts:
+ pairs.append(dir, e)
+ for dir, ext in pairs:
+ f = os.path.join(dir, cmd)
+ if not ext is None:
+ f = f + ext
+ if os.path.exists(f):
+ return f
+ return cmd
+
+ def spawn(cmd, args, env):
+ try:
+ ret = os.spawnvpe(os.P_WAIT, cmd, args, env)
+ except AttributeError:
+ cmd = pathsearch(cmd, env)
+ ret = os.spawnve(os.P_WAIT, cmd, args, env)
+ return ret
+
+
+
def Builder(**kw):
"""A factory for builder objects."""
if kw.has_key('builders'):
@@ -230,20 +287,13 @@ class CommandAction(ActionBase):
self.show(cmd)
ret = 0
if execute_actions:
- pid = os.fork()
- if not pid:
- # Child process.
- args = string.split(cmd)
- try:
- ENV = kw['env']['ENV']
- except:
- import SCons.Defaults
- ENV = SCons.Defaults.ConstructionEnvironment['ENV']
- os.execvpe(args[0], args, ENV)
- else:
- # Parent process.
- pid, stat = os.waitpid(pid, 0)
- ret = stat >> 8
+ args = string.split(cmd)
+ try:
+ ENV = glob['ENV']
+ except:
+ import SCons.Defaults
+ ENV = SCons.Defaults.ConstructionEnvironment['ENV']
+ ret = spawn(args[0], args, ENV)
return ret
diff --git a/src/engine/SCons/BuilderTests.py b/src/engine/SCons/BuilderTests.py
index e84799a..a446f95 100644
--- a/src/engine/SCons/BuilderTests.py
+++ b/src/engine/SCons/BuilderTests.py
@@ -111,7 +111,9 @@ class BuilderTestCase(unittest.TestCase):
containing one of each.
"""
- cmd1 = "python %s %s xyzzy" % (act_py, outfile)
+ python = sys.executable
+
+ cmd1 = r'%s %s %s xyzzy' % (python, act_py, outfile)
builder = SCons.Builder.Builder(action = cmd1)
r = builder.execute()
@@ -119,7 +121,7 @@ class BuilderTestCase(unittest.TestCase):
c = test.read(outfile, 'r')
assert c == "act.py: xyzzy\n", c
- cmd2 = "python %s %s $target" % (act_py, outfile)
+ cmd2 = r'%s %s %s $target' % (python, act_py, outfile)
builder = SCons.Builder.Builder(action = cmd2)
r = builder.execute(target = 'foo')
@@ -127,7 +129,7 @@ class BuilderTestCase(unittest.TestCase):
c = test.read(outfile, 'r')
assert c == "act.py: foo\n", c
- cmd3 = "python %s %s ${targets}" % (act_py, outfile)
+ cmd3 = r'%s %s %s ${targets}' % (python, act_py, outfile)
builder = SCons.Builder.Builder(action = cmd3)
r = builder.execute(target = ['aaa', 'bbb'])
@@ -135,7 +137,7 @@ class BuilderTestCase(unittest.TestCase):
c = test.read(outfile, 'r')
assert c == "act.py: aaa bbb\n", c
- cmd4 = "python %s %s $sources" % (act_py, outfile)
+ cmd4 = r'%s %s %s $sources' % (python, act_py, outfile)
builder = SCons.Builder.Builder(action = cmd4)
r = builder.execute(source = ['one', 'two'])
@@ -143,7 +145,7 @@ class BuilderTestCase(unittest.TestCase):
c = test.read(outfile, 'r')
assert c == "act.py: one two\n", c
- cmd4 = "python %s %s ${sources[:2]}" % (act_py, outfile)
+ cmd4 = r'%s %s %s ${sources[:2]}' % (python, act_py, outfile)
builder = SCons.Builder.Builder(action = cmd4)
r = builder.execute(source = ['three', 'four', 'five'])
@@ -151,7 +153,7 @@ class BuilderTestCase(unittest.TestCase):
c = test.read(outfile, 'r')
assert c == "act.py: three four\n", c
- cmd5 = "python %s %s $target XYZZY" % (act_py, outfile)
+ cmd5 = r'%s %s %s $target XYZZY' % (python, act_py, outfile)
builder = SCons.Builder.Builder(action = cmd5)
r = builder.execute(target = 'out5', env = {'ENV' : {'XYZZY' : 'xyzzy'}})
@@ -190,7 +192,7 @@ class BuilderTestCase(unittest.TestCase):
c = test.read(outfile, 'r')
assert c == "class1b\n", c
- cmd2 = "python %s %s syzygy" % (act_py, outfile)
+ cmd2 = r'%s %s %s syzygy' % (python, act_py, outfile)
def function2(kw):
open(kw['out'], 'a').write("function2\n")
diff --git a/src/engine/SCons/Defaults.py b/src/engine/SCons/Defaults.py
index eeaa02a..086c1d5 100644
--- a/src/engine/SCons/Defaults.py
+++ b/src/engine/SCons/Defaults.py
@@ -33,30 +33,70 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import os
import SCons.Builder
+if os.name == 'posix':
+
+ object_suffix = '.o'
+ program_suffix = None
+ library_prefix = 'lib'
+ library_suffix = '.a'
+
+elif os.name == 'nt':
+
+ object_suffix = '.obj'
+ program_suffix = '.exe'
+ library_prefix = None
+ library_suffix = '.lib'
+
+
+
Object = SCons.Builder.Builder(name = 'Object',
- action = '$CC $CCFLAGS -c -o $target $sources',
- src_suffix='.c',
- suffix='.o')
+ action = '$CCCOM',
+ suffix = object_suffix,
+ src_suffix = '.c')
Program = SCons.Builder.Builder(name = 'Program',
- action = '$LINK $LINKFLAGS -o $target $sources',
+ action = '$LINKCOM',
+ suffix = program_suffix,
builders = [ Object ])
Library = SCons.Builder.Builder(name = 'Library',
action = 'ar r $target $sources\nranlib $target',
- prefix = 'lib',
- suffix = '.a',
+ prefix = library_prefix,
+ suffix = library_suffix,
builders = [ Object ])
-ConstructionEnvironment = {
- 'CC' : 'cc',
- 'CCFLAGS' : '',
- 'LINK' : '$CC',
- 'LINKFLAGS' : '',
- 'BUILDERS' : [Object, Program, Library],
- 'ENV' : { 'PATH' : '/usr/local/bin:/bin:/usr/bin' },
-}
+
+
+if os.name == 'posix':
+
+ ConstructionEnvironment = {
+ 'CC' : 'cc',
+ 'CCFLAGS' : '',
+ 'CCCOM' : '$CC $CCFLAGS -c -o $target $sources',
+ 'LINK' : '$CC',
+ 'LINKFLAGS' : '',
+ 'LINKCOM' : '$LINK $LINKFLAGS -o $target $sources',
+ 'BUILDERS' : [Object, Program, Library],
+ 'ENV' : { 'PATH' : '/usr/local/bin:/bin:/usr/bin' },
+ }
+
+elif os.name == 'nt':
+
+ ConstructionEnvironment = {
+ 'CC' : 'cl',
+ 'CCFLAGS' : '/nologo',
+ 'CCCOM' : '$CC $CCFLAGS /c $sources /Fo$target',
+ 'LINK' : 'link',
+ 'LINKFLAGS' : '',
+ 'LINKCOM' : '$LINK $LINKFLAGS /out:$target $sources',
+ 'BUILDERS' : [Object, Program, Library],
+ 'ENV' : {
+ 'PATH' : r'C:\Python20;C:\WINNT\system32;C:\WINNT;C:\Program Files\Microsoft Visual Studio\VC98\Bin\;',
+ 'PATHEXT' : '.COM;.EXE;.BAT;.CMD'
+ },
+ }
diff --git a/src/engine/SCons/Node/FSTests.py b/src/engine/SCons/Node/FSTests.py
index fc0a0a3..6f2a5a7 100644
--- a/src/engine/SCons/Node/FSTests.py
+++ b/src/engine/SCons/Node/FSTests.py
@@ -24,6 +24,7 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
import os
+import string
import sys
import unittest
@@ -69,70 +70,90 @@ class FSTestCase(unittest.TestCase):
fs = SCons.Node.FS.FS()
- def Dir_test(lpath, path, abspath, up_path, fileSys=fs):
- dir = fileSys.Dir(lpath)
- assert dir.path == path, "Dir.path %s != expected path %s" % \
- (dir.path, path)
- assert str(dir) == path, "str(dir) %s != expected path %s" % \
- (str(dir), path)
- assert dir.abspath == abspath, "Dir.abspath %s != expected abs. path %s" % \
- (dir.abspath, path)
- assert dir.up().path == up_path, "Dir.up().path %s != expected parent path %s" % \
- (dir.up().path, up_path)
-
- Dir_test('foo', 'foo/', sub_dir_foo, '.')
- Dir_test('foo/bar', 'foo/bar/', sub_dir_foo_bar, 'foo/')
- Dir_test('/foo', '/foo/', '/foo/', '/')
- Dir_test('/foo/bar', '/foo/bar/', '/foo/bar/', '/foo/')
- Dir_test('..', sub, sub, wp)
- Dir_test('foo/..', '.', sub_dir, sub)
- Dir_test('../foo', sub_foo, sub_foo, sub)
- Dir_test('.', '.', sub_dir, sub)
- Dir_test('./.', '.', sub_dir, sub)
- Dir_test('foo/./bar', 'foo/bar/', sub_dir_foo_bar, 'foo/')
-
d1 = fs.Dir('d1')
f1 = fs.File('f1', directory = d1)
- assert d1.current() == 0
- assert f1.current() == 0
-
- assert f1.path == 'd1/f1', "f1.path %s != d1/f1" % f1.path
- assert str(f1) == 'd1/f1', "str(f1) %s != d1/f1" % str(f1)
-
- try:
- f2 = fs.File('f1/f2', directory = d1)
- except TypeError, x:
- assert str(x) == "Tried to lookup File 'd1/f1' as a Dir.", x
- except:
- raise
-
- try:
- dir = fs.Dir('d1/f1')
- except TypeError, x:
- assert str(x) == "Tried to lookup File 'd1/f1' as a Dir.", x
- except:
- raise
-
- try:
- f2 = fs.File('d1')
- except TypeError, x:
- assert str(x) == "Tried to lookup Dir 'd1/' as a File.", x
- except:
- raise
-
- # Test Dir.children()
- dir = fs.Dir('ddd')
- fs.File('ddd/f1')
- fs.File('ddd/f2')
- fs.File('ddd/f3')
- fs.Dir('ddd/d1')
- fs.Dir('ddd/d1/f4')
- fs.Dir('ddd/d1/f5')
- kids = map(lambda x: x.path, dir.children())
- kids.sort()
- assert kids == ['ddd/d1/', 'ddd/f1', 'ddd/f2', 'ddd/f3']
+ d1_f1 = os.path.join('d1', 'f1')
+ assert f1.path == d1_f1, "f1.path %s != %s" % (f1.path, d1_f1)
+ assert str(f1) == d1_f1, "str(f1) %s != %s" % (str(f1), d1_f1)
+
+ seps = [os.sep]
+ if os.sep != '/':
+ seps = seps + ['/']
+
+ for sep in seps:
+
+ 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)
+
+ assert dir.path == path, \
+ "dir.path %s != expected path %s" % \
+ (dir.path, path)
+ assert str(dir) == path, \
+ "str(dir) %s != expected path %s" % \
+ (str(dir), path)
+ assert dir.abspath == abspath, \
+ "dir.abspath %s != expected absolute path %s" % \
+ (dir.abspath, abspath)
+ assert dir.up().path == up_path, \
+ "dir.up().path %s != expected parent path %s" % \
+ (dir.up().path, up_path)
+
+ Dir_test('foo', 'foo/', sub_dir_foo, '.')
+ Dir_test('foo/bar', 'foo/bar/', sub_dir_foo_bar, 'foo/')
+ Dir_test('/foo', '/foo/', '/foo/', '/')
+ Dir_test('/foo/bar', '/foo/bar/', '/foo/bar/', '/foo/')
+ Dir_test('..', sub, sub, wp)
+ Dir_test('foo/..', '.', sub_dir, sub)
+ Dir_test('../foo', sub_foo, sub_foo, sub)
+ Dir_test('.', '.', sub_dir, sub)
+ Dir_test('./.', '.', sub_dir, sub)
+ Dir_test('foo/./bar', 'foo/bar/', sub_dir_foo_bar, 'foo/')
+
+ try:
+ f2 = fs.File(string.join(['f1', 'f2'], sep), directory = d1)
+ except TypeError, x:
+ assert str(x) == ("Tried to lookup File '%s' as a Dir." %
+ d1_f1), x
+ except:
+ raise
+
+ try:
+ dir = fs.Dir(string.join(['d1', 'f1'], sep))
+ except TypeError, x:
+ assert str(x) == ("Tried to lookup File '%s' as a Dir." %
+ d1_f1), x
+ except:
+ raise
+
+ try:
+ f2 = fs.File('d1')
+ except TypeError, x:
+ assert str(x) == ("Tried to lookup Dir '%s' as a File." %
+ os.path.join('d1', '')), x
+ except:
+ raise
+
+ # Test Dir.children()
+ dir = fs.Dir('ddd')
+ fs.File(string.join(['ddd', 'f1'], sep))
+ fs.File(string.join(['ddd', 'f2'], sep))
+ fs.File(string.join(['ddd', 'f3'], sep))
+ fs.Dir(string.join(['ddd', 'd1'], sep))
+ fs.Dir(string.join(['ddd', 'd1', 'f4'], sep))
+ fs.Dir(string.join(['ddd', 'd1', 'f5'], sep))
+ kids = map(lambda x: x.path, dir.children())
+ kids.sort()
+ assert kids == [os.path.join('ddd', 'd1', ''),
+ os.path.join('ddd', 'f1'),
+ os.path.join('ddd', 'f2'),
+ os.path.join('ddd', 'f3')]
# Test for sub-classing of node building.
global built_it
diff --git a/src/engine/SCons/Sig/MD5.py b/src/engine/SCons/Sig/MD5.py
index 4004e23..11ba961 100644
--- a/src/engine/SCons/Sig/MD5.py
+++ b/src/engine/SCons/Sig/MD5.py
@@ -30,9 +30,19 @@ utility.
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import md5
+import imp
import string
+# Force Python to load the builtin "md5" module. If we do this with a
+# normal import statement, then case-insensitive systems (Win32) get
+# confused and thinks there's a case mismatch with *this* MD5.py module.
+file, name, desc = imp.find_module('md5')
+try:
+ md5 = imp.load_module('md5', file, name, desc)
+finally:
+ if file:
+ file.close()
+
def current(new, old):
"""Return whether a new signature is up-to-date with
respect to an old signature.
diff --git a/src/engine/SCons/UtilTests.py b/src/engine/SCons/UtilTests.py
index bbaf851..7df0c83 100644
--- a/src/engine/SCons/UtilTests.py
+++ b/src/engine/SCons/UtilTests.py
@@ -23,8 +23,10 @@
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
-import sys
+import os
import os.path
+import string
+import sys
import unittest
import SCons.Node
import SCons.Node.FS
@@ -83,35 +85,43 @@ class UtilTestCase(unittest.TestCase):
"/bar/ack.cpp",
"../foo/ack.c" ]))
+ if os.sep == '/':
+ def cvt(str):
+ return str
+ else:
+ def cvt(str):
+ return string.replace(str, '/', os.sep)
+
+
newcom = scons_subst("test $targets $sources", loc, {})
- assert newcom == "test foo/bar.exe /bar/baz.obj ../foo/baz.obj foo/blah.cpp /bar/ack.cpp ../foo/ack.c"
+ assert newcom == cvt("test foo/bar.exe /bar/baz.obj ../foo/baz.obj foo/blah.cpp /bar/ack.cpp ../foo/ack.c")
newcom = scons_subst("test ${targets[:]} ${sources[0]}", loc, {})
- assert newcom == "test foo/bar.exe /bar/baz.obj ../foo/baz.obj foo/blah.cpp"
+ assert newcom == cvt("test foo/bar.exe /bar/baz.obj ../foo/baz.obj foo/blah.cpp")
newcom = scons_subst("test ${targets[1:]}v", loc, {})
- assert newcom == "test /bar/baz.obj ../foo/baz.objv"
+ assert newcom == cvt("test /bar/baz.obj ../foo/baz.objv")
newcom = scons_subst("test $target", loc, {})
- assert newcom == "test foo/bar.exe"
+ assert newcom == cvt("test foo/bar.exe")
newcom = scons_subst("test $target$source[0]", loc, {})
- assert newcom == "test foo/bar.exe[0]"
+ assert newcom == cvt("test foo/bar.exe[0]")
newcom = scons_subst("test ${target.file}", loc, {})
- assert newcom == "test bar.exe"
+ assert newcom == cvt("test bar.exe")
newcom = scons_subst("test ${target.filebase}", loc, {})
- assert newcom == "test bar"
+ assert newcom == cvt("test bar")
newcom = scons_subst("test ${target.suffix}", loc, {})
- assert newcom == "test .exe"
+ assert newcom == cvt("test .exe")
newcom = scons_subst("test ${target.base}", loc, {})
- assert newcom == "test foo/bar"
+ assert newcom == cvt("test foo/bar")
newcom = scons_subst("test ${target.dir}", loc, {})
- assert newcom == "test foo"
+ assert newcom == cvt("test foo")