From 0b385989b2a959af6a8ddd2c5427855380791f61 Mon Sep 17 00:00:00 2001 From: stevenknight Date: Wed, 30 Apr 2003 19:38:19 +0000 Subject: [PATCH] Test portability fixes for Cygwin. (Chad Austin) git-svn-id: http://scons.tigris.org/svn/scons/trunk@666 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- etc/TestSCons.py | 26 +++++++++++++++++++++++++- src/engine/SCons/Action.py | 3 +++ src/engine/SCons/ActionTests.py | 18 +++++++++++++++++- src/engine/SCons/EnvironmentTests.py | 27 +++++++++++++++++++++++++++ src/engine/SCons/Tool/gs.py | 2 +- test/AR.py | 6 +----- test/ARFLAGS.py | 6 +----- test/AS.py | 11 +++++------ test/ASFLAGS.py | 5 +---- test/CC.py | 6 +----- test/CPPFLAGS.py | 15 +++------------ test/CPPPATH.py | 5 +---- test/CXX.py | 6 +----- test/ENV.py | 6 ++++-- test/F77.py | 6 +----- test/F77FLAGS.py | 6 +----- test/LEX.py | 6 +----- test/LEXFLAGS.py | 6 +----- test/LIBPATH.py | 11 +++-------- test/LINK.py | 6 +----- test/LINKFLAGS.py | 6 +----- test/Program-j.py | 5 +---- test/Program.py | 5 +---- test/RANLIB.py | 5 +---- test/RANLIBFLAGS.py | 6 +----- test/SHF77.py | 9 +-------- test/SHLIBPREFIX.py | 5 +---- test/SHLIBSUFFIX.py | 5 +---- test/SHLINK.py | 9 ++------- test/SHLINKFLAGS.py | 9 ++------- test/YACC.py | 3 +-- test/YACCFLAGS.py | 3 +-- test/long-lines.py | 9 ++++++++- test/option--implicit-cache.py | 8 ++------ test/pre-post-actions.py | 5 +---- test/special-filenames.py | 17 ++++++++++------- 36 files changed, 134 insertions(+), 158 deletions(-) diff --git a/etc/TestSCons.py b/etc/TestSCons.py index f9c4edfb..4fe8b5b8 100644 --- a/etc/TestSCons.py +++ b/etc/TestSCons.py @@ -24,9 +24,33 @@ import TestCmd python = TestCmd.python_executable -if string.find(sys.platform, 'irix') != -1: +if sys.platform == 'win32': + _exe = '.exe' + _obj = '.obj' + _shobj = '.obj' + _dll = '.dll' + lib_ = '' + fortran_lib = 'g2c' +elif sys.platform == 'cygwin': + _exe = '.exe' + _obj = '.o' + _shobj = '.os' + _dll = '.dll' + lib_ = '' + fortran_lib = 'g2c' +elif string.find(sys.platform, 'irix') != -1: + _exe = '' + _obj = '.o' + _shobj = '.o' + _dll = '.so' + lib_ = 'lib' fortran_lib = 'ftn' else: + _exe = '' + _obj = '.o' + _shobj = '.os' + _dll = '.so' + lib_ = 'lib' fortran_lib = 'g2c' class TestFailed(Exception): diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index 12608504..d7be1276 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -346,6 +346,9 @@ class LazyCmdGenerator: # The variable reference substitutes to nothing. return '' + def __cmp__(self, other): + return cmp(self.__dict__, other.__dict__) + class FunctionAction(ActionBase): """Class for Python function actions.""" diff --git a/src/engine/SCons/ActionTests.py b/src/engine/SCons/ActionTests.py index 9189b4cf..4aee748a 100644 --- a/src/engine/SCons/ActionTests.py +++ b/src/engine/SCons/ActionTests.py @@ -412,11 +412,24 @@ class CommandActionTestCase(unittest.TestCase): assert c == "act.py: 'three' 'four'\n", c cmd5 = r'%s %s %s $TARGET XYZZY' % (python, act_py, outfile) + + act = SCons.Action.CommandAction(cmd5) + env5 = Environment() + if scons_env.has_key('ENV'): + env5['ENV'] = scons_env['ENV'] + PATH = scons_env['ENV'].get('PATH', '') + else: + env5['ENV'] = {} + PATH = '' + + env5['ENV']['XYZZY'] = 'xyzzy' + r = act(target = 'out5', source = [], env = env5) act = SCons.Action.CommandAction(cmd5) r = act(target = 'out5', source = [], - env = env.Copy(ENV = {'XYZZY' : 'xyzzy'})) + env = env.Copy(ENV = {'XYZZY' : 'xyzzy', + 'PATH' : PATH})) assert r == 0 c = test.read(outfile, 'r') assert c == "act.py: 'out5' 'XYZZY'\nact.py: 'xyzzy'\n", c @@ -460,6 +473,9 @@ class CommandActionTestCase(unittest.TestCase): # as "file not found" errors expect_nonexistent = 1 expect_nonexecutable = 1 + elif sys.platform == 'cygwin': + expect_nonexistent = 127 + expect_nonexecutable = 127 else: expect_nonexistent = 127 expect_nonexecutable = 126 diff --git a/src/engine/SCons/EnvironmentTests.py b/src/engine/SCons/EnvironmentTests.py index c041755d..e99ea0d0 100644 --- a/src/engine/SCons/EnvironmentTests.py +++ b/src/engine/SCons/EnvironmentTests.py @@ -54,6 +54,28 @@ def diff_env(env1, env2): s2 = s2 + "}\n" return s1 + s2 +def diff_dict(d1, d2): + s1 = "d1 = {\n" + s2 = "d2 = {\n" + d = {} + for k in d1.keys() + d2.keys(): + d[k] = None + keys = d.keys() + keys.sort() + for k in keys: + if d1.has_key(k): + if d2.has_key(k): + if d1[k] != d2[k]: + s1 = s1 + " " + repr(k) + " : " + repr(d1[k]) + "\n" + s2 = s2 + " " + repr(k) + " : " + repr(d2[k]) + "\n" + else: + s1 = s1 + " " + repr(k) + " : " + repr(d1[k]) + "\n" + elif env2.has_key(k): + s2 = s2 + " " + repr(k) + " : " + repr(d2[k]) + "\n" + s1 = s1 + "}\n" + s2 = s2 + "}\n" + return s1 + s2 + called_it = {} built_it = {} @@ -372,6 +394,11 @@ class EnvironmentTestCase(unittest.TestCase): def test_Append(self): """Test appending to construction variables in an Environment """ + + b1 = Environment()['BUILDERS'] + b2 = Environment()['BUILDERS'] + assert b1 == b2, diff_dict(b1, b2) + import UserList UL = UserList.UserList env1 = Environment(AAA = 'a', BBB = 'b', CCC = 'c', DDD = 'd', diff --git a/src/engine/SCons/Tool/gs.py b/src/engine/SCons/Tool/gs.py index 5aa83d51..79d50e4e 100644 --- a/src/engine/SCons/Tool/gs.py +++ b/src/engine/SCons/Tool/gs.py @@ -41,7 +41,7 @@ platform = SCons.Platform.platform_default() if platform == 'os2': gs = 'gsos2' -elif platform == 'cygwin' or platform == 'win32': +elif platform == 'win32': gs = 'gswin32c' else: gs = 'gs' diff --git a/test/AR.py b/test/AR.py index 57ec04d4..f077c72c 100644 --- a/test/AR.py +++ b/test/AR.py @@ -30,11 +30,7 @@ import sys import TestSCons python = TestSCons.python - -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe test = TestSCons.TestSCons() diff --git a/test/ARFLAGS.py b/test/ARFLAGS.py index 49367218..54cb463c 100644 --- a/test/ARFLAGS.py +++ b/test/ARFLAGS.py @@ -30,11 +30,7 @@ import sys import TestSCons python = TestSCons.python - -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe test = TestSCons.TestSCons() diff --git a/test/AS.py b/test/AS.py index 22eb17c2..0bafdc14 100644 --- a/test/AS.py +++ b/test/AS.py @@ -30,11 +30,7 @@ import sys import TestSCons python = TestSCons.python - -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe test = TestSCons.TestSCons() @@ -67,11 +63,14 @@ inf = None while args: a = args[0] args = args[1:] - if a[0] != '/': + if not a[0] in "/-": if not inf: inf = a continue if a[:3] == '/Fo': out = a[3:] + if a == '-o': + out = args[0] + args = args[1:] infile = open(inf, 'rb') outfile = open(out, 'wb') for l in infile.readlines(): diff --git a/test/ASFLAGS.py b/test/ASFLAGS.py index 0331aed9..d750a6a4 100644 --- a/test/ASFLAGS.py +++ b/test/ASFLAGS.py @@ -32,12 +32,11 @@ import TestSCons python = TestSCons.python test = TestSCons.TestSCons() +_exe = TestSCons._exe if sys.platform == 'win32': - _exe = '.exe' - o = ' -x' o_c = ' -x' @@ -89,8 +88,6 @@ sys.exit(0) else: - _exe = '' - o = ' -x' o_c = ' -x -c' diff --git a/test/CC.py b/test/CC.py index 93b0ed5a..ca4867b3 100644 --- a/test/CC.py +++ b/test/CC.py @@ -30,11 +30,7 @@ import sys import TestSCons python = TestSCons.python - -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe test = TestSCons.TestSCons() diff --git a/test/CPPFLAGS.py b/test/CPPFLAGS.py index d8587c66..87f5603b 100644 --- a/test/CPPFLAGS.py +++ b/test/CPPFLAGS.py @@ -30,18 +30,9 @@ import sys import TestSCons python = TestSCons.python - -if sys.platform == 'win32': - _exe = '.exe' - _obj = '.obj' - _shobj = '.obj' -else: - _exe = '' - _obj = '.o' - if string.find(sys.platform, 'irix') > -1: - _shobj = '.o' - else: - _shobj = '.os' +_exe = TestSCons._exe +_obj = TestSCons._obj +_shobj = TestSCons._shobj test = TestSCons.TestSCons() diff --git a/test/CPPPATH.py b/test/CPPPATH.py index cb650fa3..1f93bf5d 100644 --- a/test/CPPPATH.py +++ b/test/CPPPATH.py @@ -28,10 +28,7 @@ import os import sys import TestSCons -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe prog = 'prog' + _exe subdir_prog = os.path.join('subdir', 'prog' + _exe) diff --git a/test/CXX.py b/test/CXX.py index cd2c7a91..bff7708c 100644 --- a/test/CXX.py +++ b/test/CXX.py @@ -30,11 +30,7 @@ import sys import TestSCons python = TestSCons.python - -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe test = TestSCons.TestSCons() diff --git a/test/ENV.py b/test/ENV.py index f92a2d8b..31ad970b 100644 --- a/test/ENV.py +++ b/test/ENV.py @@ -37,8 +37,10 @@ bin2_build_py = test.workpath('bin2', 'build.py') test.write('SConstruct', """ import os Bld = Builder(action = r"%s build.py $TARGET $SOURCES") -env1 = Environment(ENV = {'X' : 'env1'}, BUILDERS = { 'Bld' : Bld }) -env2 = Environment(ENV = {'X' : 'env2'}, BUILDERS = { 'Bld' : Bld }) +env1 = Environment(BUILDERS = { 'Bld' : Bld }) +env2 = Environment(BUILDERS = { 'Bld' : Bld }) +env1['ENV']['X'] = 'env1' +env2['ENV']['X'] = 'env2' env1.Bld(target = 'env1.out', source = 'input') env2.Bld(target = 'env2.out', source = 'input') """ % python) diff --git a/test/F77.py b/test/F77.py index f95dee99..03467652 100644 --- a/test/F77.py +++ b/test/F77.py @@ -30,11 +30,7 @@ import sys import TestSCons python = TestSCons.python - -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe test = TestSCons.TestSCons() diff --git a/test/F77FLAGS.py b/test/F77FLAGS.py index b9147014..b72c6183 100644 --- a/test/F77FLAGS.py +++ b/test/F77FLAGS.py @@ -32,12 +32,10 @@ import TestSCons python = TestSCons.python test = TestSCons.TestSCons() - +_exe = TestSCons._exe if sys.platform == 'win32': - _exe = '.exe' - test.write('mylink.py', r""" import string import sys @@ -58,8 +56,6 @@ sys.exit(0) else: - _exe = '' - test.write('mylink.py', r""" import getopt import sys diff --git a/test/LEX.py b/test/LEX.py index 38d73fb5..90549bd9 100644 --- a/test/LEX.py +++ b/test/LEX.py @@ -31,11 +31,7 @@ import sys import TestSCons python = TestSCons.python - -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe test = TestSCons.TestSCons() diff --git a/test/LEXFLAGS.py b/test/LEXFLAGS.py index c3ae1825..ba440daa 100644 --- a/test/LEXFLAGS.py +++ b/test/LEXFLAGS.py @@ -31,11 +31,7 @@ import sys import TestSCons python = TestSCons.python - -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe test = TestSCons.TestSCons() diff --git a/test/LIBPATH.py b/test/LIBPATH.py index 2730be36..6e2a8368 100644 --- a/test/LIBPATH.py +++ b/test/LIBPATH.py @@ -29,14 +29,9 @@ import sys import os.path import time -if sys.platform == 'win32': - _exe = '.exe' - _dll = '.dll' - lib_ = '' -else: - _exe = '' - _dll = '.so' - lib_ = 'lib' +_exe = TestSCons._exe +_dll = TestSCons._dll +lib_ = TestSCons.lib_ test = TestSCons.TestSCons() diff --git a/test/LINK.py b/test/LINK.py index 982cc888..e3c21bc3 100644 --- a/test/LINK.py +++ b/test/LINK.py @@ -30,11 +30,7 @@ import sys import TestSCons python = TestSCons.python - -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe test = TestSCons.TestSCons() diff --git a/test/LINKFLAGS.py b/test/LINKFLAGS.py index d5a1e401..58efcf37 100644 --- a/test/LINKFLAGS.py +++ b/test/LINKFLAGS.py @@ -30,11 +30,7 @@ import sys import TestSCons python = TestSCons.python - -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe test = TestSCons.TestSCons() diff --git a/test/Program-j.py b/test/Program-j.py index 3e290408..fe778b33 100644 --- a/test/Program-j.py +++ b/test/Program-j.py @@ -27,10 +27,7 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" import sys import TestSCons -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe f1 = 'f1' + _exe f2 = 'f2' + _exe diff --git a/test/Program.py b/test/Program.py index b05a73a0..30301722 100644 --- a/test/Program.py +++ b/test/Program.py @@ -29,10 +29,7 @@ import sys import time import TestSCons -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe test = TestSCons.TestSCons() diff --git a/test/RANLIB.py b/test/RANLIB.py index 4879a837..cb8f1dbb 100644 --- a/test/RANLIB.py +++ b/test/RANLIB.py @@ -32,10 +32,7 @@ import TestSCons python = TestSCons.python -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe test = TestSCons.TestSCons() diff --git a/test/RANLIBFLAGS.py b/test/RANLIBFLAGS.py index 0554d4ce..fec606dd 100644 --- a/test/RANLIBFLAGS.py +++ b/test/RANLIBFLAGS.py @@ -30,11 +30,7 @@ import sys import TestSCons python = TestSCons.python - -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe test = TestSCons.TestSCons() diff --git a/test/SHF77.py b/test/SHF77.py index 23e9bf39..d78ef821 100644 --- a/test/SHF77.py +++ b/test/SHF77.py @@ -30,14 +30,7 @@ import sys import TestSCons python = TestSCons.python - -if sys.platform == 'win32': - _obj = '.obj' -else: - if string.find(sys.platform, 'irix') > -1: - _obj = '.o' - else: - _obj = '.os' +_obj = TestSCons._shobj test = TestSCons.TestSCons() diff --git a/test/SHLIBPREFIX.py b/test/SHLIBPREFIX.py index f830b682..25bca5f0 100644 --- a/test/SHLIBPREFIX.py +++ b/test/SHLIBPREFIX.py @@ -28,10 +28,7 @@ import os import sys import TestSCons -if sys.platform == 'win32': - _lib = '.dll' -else: - _lib = '.so' +_lib = TestSCons._dll test = TestSCons.TestSCons() diff --git a/test/SHLIBSUFFIX.py b/test/SHLIBSUFFIX.py index 734f6c6d..4c2d7ac6 100644 --- a/test/SHLIBSUFFIX.py +++ b/test/SHLIBSUFFIX.py @@ -28,10 +28,7 @@ import os import sys import TestSCons -if sys.platform == 'win32': - lib_ = '' -else: - lib_ = 'lib' +lib_ = TestSCons.lib_ test = TestSCons.TestSCons() diff --git a/test/SHLINK.py b/test/SHLINK.py index 3fd8e75d..7f1c63de 100644 --- a/test/SHLINK.py +++ b/test/SHLINK.py @@ -30,14 +30,9 @@ import sys import TestSCons python = TestSCons.python +lib_ = TestSCons.lib_ +_shlib = TestSCons._dll -if sys.platform == 'win32': - lib_ = '' - _shlib='.dll' -else: - lib_ = 'lib' - _shlib='.so' - test = TestSCons.TestSCons() test.write("wrapper.py", diff --git a/test/SHLINKFLAGS.py b/test/SHLINKFLAGS.py index 85ad6a3a..9a4a6ccb 100644 --- a/test/SHLINKFLAGS.py +++ b/test/SHLINKFLAGS.py @@ -30,13 +30,8 @@ import sys import TestSCons python = TestSCons.python - -if sys.platform == 'win32': - lib_ = '' - _shlib = '.dll' -else: - lib_ = 'lib' - _shlib = '.so' +lib_ = TestSCons.lib_ +_shlib = TestSCons._dll test = TestSCons.TestSCons() diff --git a/test/YACC.py b/test/YACC.py index 48549056..b44add17 100644 --- a/test/YACC.py +++ b/test/YACC.py @@ -31,13 +31,12 @@ import sys import TestSCons python = TestSCons.python +_exe = TestSCons._exe if sys.platform == 'win32': - _exe = '.exe' compiler = 'msvc' linker = 'mslink' else: - _exe = '' compiler = 'gcc' linker = 'gnulink' diff --git a/test/YACCFLAGS.py b/test/YACCFLAGS.py index 987025ff..3ed6b6b2 100644 --- a/test/YACCFLAGS.py +++ b/test/YACCFLAGS.py @@ -31,13 +31,12 @@ import sys import TestSCons python = TestSCons.python +_exe = TestSCons._exe if sys.platform == 'win32': - _exe = '.exe' compiler = 'msvc' linker = 'mslink' else: - _exe = '' compiler = 'gcc' linker = 'gnulink' diff --git a/test/long-lines.py b/test/long-lines.py index 3999f621..9d385048 100644 --- a/test/long-lines.py +++ b/test/long-lines.py @@ -32,13 +32,20 @@ import TestSCons test = TestSCons.TestSCons() -if sys.platform in ['win32', 'cygwin']: +if sys.platform == 'win32': lib_static_lib = 'static.lib' lib_shared_dll ='shared.dll' arflag_init = '/LIBPATH:' + test.workpath() arflag = ' /LIBPATH:' + test.workpath() linkflag_init = '/LIBPATH:' + test.workpath() linkflag = ' /LIBPATH:' + test.workpath() +elif sys.platform == 'cygwin': + lib_static_lib = 'libstatic.a' + lib_shared_dll ='shared.dll' + arflag_init = 'r' + arflag = 'o' + linkflag_init = '-L' + test.workpath() + linkflag = ' -L' + test.workpath() else: lib_shared_dll = 'libshared.so' lib_static_lib = 'libstatic.a' diff --git a/test/option--implicit-cache.py b/test/option--implicit-cache.py index e959856a..ac11b2a3 100644 --- a/test/option--implicit-cache.py +++ b/test/option--implicit-cache.py @@ -29,12 +29,8 @@ import sys import TestSCons import string -if sys.platform == 'win32': - _exe = '.exe' - _obj = '.obj' -else: - _exe = '' - _obj = '.o' +_exe = TestSCons._exe +_obj = TestSCons._obj prog = 'prog' + _exe subdir_prog = os.path.join('subdir', 'prog' + _exe) diff --git a/test/pre-post-actions.py b/test/pre-post-actions.py index d3139bb8..91fcb3b4 100644 --- a/test/pre-post-actions.py +++ b/test/pre-post-actions.py @@ -32,10 +32,7 @@ import stat import sys import TestSCons -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' +_exe = TestSCons._exe test = TestSCons.TestSCons() diff --git a/test/special-filenames.py b/test/special-filenames.py index d152e520..2002b37b 100644 --- a/test/special-filenames.py +++ b/test/special-filenames.py @@ -32,7 +32,7 @@ import TestSCons test = TestSCons.TestSCons() -file_names = [ +attempt_file_names = [ 'File with spaces', 'File"with"double"quotes', "File'with'single'quotes", @@ -49,17 +49,20 @@ file_names = [ "Combination '\"\n\\;<>?|*\t&" ] -if os.name == 'nt': - # Windows only supports spaces. - file_names = file_names[0:1] - test.write("cat.py", """\ import sys open(sys.argv[1], 'wb').write(open(sys.argv[2], 'rb').read()) """) -for fn in file_names: - test.write(fn + '.in', fn + '\n') +file_names = [] +for fn in attempt_file_names: + try: + test.write(fn + '.in', fn + '\n') + file_names.append(fn) + except IOError: + # if the Python interpreter can't handle it, don't bother + # testing to see if SCons can + pass def buildFileStr(fn): return "env.Build(source=r\"\"\"%s.in\"\"\", target=r\"\"\"%s.out\"\"\")" % ( fn, fn ) -- 2.26.2