From: stevenknight Date: Wed, 22 Feb 2006 03:18:38 +0000 (+0000) Subject: Portability fixes (win32) in tests and test infrastructure. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8c3d9abc4a4e31aee9000fd90792b128cfdd434e;p=scons.git Portability fixes (win32) in tests and test infrastructure. git-svn-id: http://scons.tigris.org/svn/scons/trunk@1429 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/etc/TestCmd.py b/etc/TestCmd.py index a2635c97..c3d438ce 100644 --- a/etc/TestCmd.py +++ b/etc/TestCmd.py @@ -176,8 +176,8 @@ version. # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. __author__ = "Steven Knight " -__revision__ = "TestCmd.py 0.20.D001 2006/02/16 06:28:21 knight" -__version__ = "0.20" +__revision__ = "TestCmd.py 0.21.D001 2006/02/21 21:18:43 knight" +__version__ = "0.21" import os import os.path @@ -220,31 +220,6 @@ tempfile.template = 'testcmd.' re_space = re.compile('\s') -if os.name == 'posix': - - def escape(arg): - "escape shell special characters" - slash = '\\' - special = '"$' - - arg = string.replace(arg, slash, slash+slash) - for c in special: - arg = string.replace(arg, c, slash+c) - - if re_space.search(arg): - arg = '"' + arg + '"' - return arg - -else: - - # Windows does not allow special characters in file names - # anyway, so no need for an escape function, we will just quote - # the arg. - def escape(arg): - if re_space.search(arg): - arg = '"' + arg + '"' - return arg - _Cleanup = [] def _clean(): @@ -499,6 +474,31 @@ class TestCmd: def __repr__(self): return "%x" % id(self) + if os.name == 'posix': + + def escape(self, arg): + "escape shell special characters" + slash = '\\' + special = '"$' + + arg = string.replace(arg, slash, slash+slash) + for c in special: + arg = string.replace(arg, c, slash+c) + + if re_space.search(arg): + arg = '"' + arg + '"' + return arg + + else: + + # Windows does not allow special characters in file names + # anyway, so no need for an escape function, we will just quote + # the arg. + def escape(self, arg): + if re_space.search(arg): + arg = '"' + arg + '"' + return arg + def cleanup(self, condition = None): """Removes any temporary working directories for the specified TestCmd environment. If the environment variable PRESERVE was @@ -675,12 +675,14 @@ class TestCmd: if type(arguments) == type(''): arguments = string.split(arguments) cmd.extend(arguments) - cmd_string = string.join(map(escape, cmd), ' ') + cmd_string = string.join(map(self.escape, cmd), ' ') if self.verbose: sys.stderr.write(cmd_string + "\n") try: p = popen2.Popen3(cmd, 1) except AttributeError: + if sys.platform == 'win32' and cmd_string[0] == '"': + cmd_string = '"' + cmd_string + '"' (tochild, fromchild, childerr) = os.popen3(' ' + cmd_string) if stdin: if is_List(stdin): diff --git a/etc/TestCommon.py b/etc/TestCommon.py index af38ab5f..008cf5a7 100644 --- a/etc/TestCommon.py +++ b/etc/TestCommon.py @@ -80,8 +80,8 @@ The TestCommon module also provides the following variables # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. __author__ = "Steven Knight " -__revision__ = "TestCommon.py 0.20.D001 2006/02/16 06:28:21 knight" -__version__ = "0.20" +__revision__ = "TestCommon.py 0.21.D001 2006/02/21 21:18:43 knight" +__version__ = "0.21" import os import os.path diff --git a/test/Perforce/Perforce.py b/test/Perforce/Perforce.py index 04127f51..f813f106 100644 --- a/test/Perforce/Perforce.py +++ b/test/Perforce/Perforce.py @@ -59,11 +59,15 @@ class TestPerforce(TestSCons.TestSCons): if self.p4d: self.p4portflags = ['-p', self.host + ':1777'] self.subdir('depot', ['depot', 'testme']) - args = [self.p4d, '-q', '-d'] + \ - self.p4portflags + \ - ['-J', 'Journal', - '-L', 'Log', - '-r', self.workpath('depot')] + def quote_space(a): + if ' ' in a: + a = '"%s"' % a + return a + args = map(quote_space, [self.p4d, '-q', '-d'] + \ + self.p4portflags + \ + ['-J', 'Journal', + '-L', 'Log', + '-r', self.workpath('depot')]) # We don't use self.run() because the TestCmd logic will hang # waiting for the daemon to exit, even when we pass it diff --git a/test/rebuild-generated.py b/test/rebuild-generated.py index 973fc8f8..7f8a6d57 100644 --- a/test/rebuild-generated.py +++ b/test/rebuild-generated.py @@ -93,7 +93,9 @@ osLinuxModule = env.StaticObject( test.write('main.cc', """\ int main(int, char *[]) -{} +{ + return (0); +} """) test.write('target.cc', """\