From: stevenknight Date: Fri, 4 Mar 2005 02:44:26 +0000 (+0000) Subject: Fix Fedora Core 3 test portability. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=77fd55ad5f6b9f820b8966cf117acc9b7fe6c473;p=scons.git Fix Fedora Core 3 test portability. git-svn-id: http://scons.tigris.org/svn/scons/trunk@1240 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/etc/TestSCons.py b/etc/TestSCons.py index 28f882ba..f3f39599 100644 --- a/etc/TestSCons.py +++ b/etc/TestSCons.py @@ -138,7 +138,21 @@ class TestSCons(TestCommon): kw['workdir'] = '' apply(TestCommon.__init__, [self], kw) - def detect(self, var, prog=None): + def Environment(self, ENV=None, *args, **kw): + """ + Return a construction Environment that optionally overrides + the default external environment with the specified ENV. + """ + import SCons.Environment + import SCons.Errors + if not ENV is None: + kw['ENV'] = ENV + try: + return apply(SCons.Environment.Environment, args, kw) + except (SCons.Errors.UserError, SCons.Errors.InternalError): + return None + + def detect(self, var, prog=None, ENV=None): """ Detect a program named 'prog' by first checking the construction variable named 'var' and finally searching the path used by @@ -147,9 +161,7 @@ class TestSCons(TestCommon): prog is None, then the value of the environment variable will be used as prog. """ - - import SCons.Environment - env = SCons.Environment.Environment() + env = self.Environment(ENV) try: if prog is None: prog = env[var] @@ -157,26 +169,34 @@ class TestSCons(TestCommon): except KeyError: return None - def detect_tool(self, tool, prog=None): + def detect_tool(self, tool, prog=None, ENV=None): """ Given a tool (i.e., tool specification that would be passed - to the "tools=" parameter of Environment()) and one a program that + to the "tools=" parameter of Environment()) and a program that corresponds to that tool, return true if and only if we can find that tool using Environment.Detect(). - By default, progs is set to the value passed into the tools parameter. + By default, prog is set to the value passed into the tools parameter. """ if not prog: prog = tool - import SCons.Environment - import SCons.Errors - try: - env=SCons.Environment.Environment(tools=[tool]) - except (SCons.Errors.UserError, SCons.Errors.InternalError): + env = self.Environment(ENV, tools=[tool]) + if env is None: return None return env.Detect([prog]) + def where_is(self, prog, path=None): + """ + Given a program, search for it in the specified external PATH, + or in the actual external PATH is none is specified. + """ + import SCons.Environment + env = SCons.Environment.Environment() + if path is None: + path = os.environ['PATH'] + return env.WhereIs(prog, path) + def wrap_stdout(self, build_str = "", read_str = "", error = 0, cleaning = 0): """Wraps standard output string(s) in the normal "Reading ... done" and "Building ... done" strings @@ -222,6 +242,33 @@ class TestSCons(TestCommon): kw['match'] = self.match_re_dotall apply(self.run, [], kw) + def java_ENV(self): + """ + Return a default external environment that uses a local Java SDK + in preference to whatever's found in the default PATH. + """ + import SCons.Environment + env = SCons.Environment.Environment() + java_path = [ + '/usr/local/j2sdk1.4.2/bin', + '/usr/local/j2sdk1.4.1/bin', + '/usr/local/j2sdk1.3.1/bin', + '/usr/local/j2sdk1.3.0/bin', + '/usr/local/j2sdk1.2.2/bin', + '/usr/local/j2sdk1.2/bin', + '/usr/local/j2sdk1.1.8/bin', + '/usr/local/j2sdk1.1.7/bin', + '/usr/local/j2sdk1.1.6/bin', + '/usr/local/j2sdk1.1.5/bin', + '/usr/local/j2sdk1.1.4/bin', + '/usr/local/j2sdk1.1.3/bin', + '/usr/local/j2sdk1.1.2/bin', + '/usr/local/j2sdk1.1.1/bin', + env['ENV']['PATH'], + ] + env['ENV']['PATH'] = string.join(java_path, os.pathsep) + return env['ENV'] + # In some environments, $AR will generate a warning message to stderr # if the library doesn't previously exist and is being created. One # way to fix this is to tell AR to be quiet (sometimes the 'c' flag), diff --git a/src/engine/SCons/Tool/javac.py b/src/engine/SCons/Tool/javac.py index e6a0fc37..8741c23a 100644 --- a/src/engine/SCons/Tool/javac.py +++ b/src/engine/SCons/Tool/javac.py @@ -61,6 +61,9 @@ def emit_java_classes(target, source, env): java_files = filter(lambda n, js=js: _my_normcase(n[-len(js):]) == js, names) + # The on-disk entries come back in arbitrary order. Sort them + # so our target and source lists are determinate. + java_files.sort() mydir = dirnode.Dir(dirname) java_paths = map(lambda f, d=mydir: d.File(f), java_files) arg.extend(java_paths) diff --git a/test/Builder-factories.py b/test/Builder-factories.py index 8bdcd3a1..41f83a2c 100644 --- a/test/Builder-factories.py +++ b/test/Builder-factories.py @@ -48,7 +48,9 @@ MakeDirectory = Builder(action=mkdir, target_factory=Dir) def collect(env, source, target): out = open(str(target[0]), 'wb') dir = str(source[0]) - for f in os.listdir(dir): + files = os.listdir(dir) + files.sort() + for f in files: f = os.path.join(dir, f) out.write(open(f, 'r').read()) out.close() diff --git a/test/Java/JAR.py b/test/Java/JAR.py index ea512134..42f2c5af 100644 --- a/test/Java/JAR.py +++ b/test/Java/JAR.py @@ -119,29 +119,23 @@ test.run(arguments='classes.jar') test.must_match('classes.jar', 'cvfm classes.jar foo.mf -C testdir bar.class\n') -if test.detect_tool('javac'): - where_javac = test.detect('JAVAC', 'javac') +ENV = test.java_ENV() + +if test.detect_tool('javac', ENV=ENV): + where_javac = test.detect('JAVAC', 'javac', ENV=ENV) else: - import SCons.Environment - env = SCons.Environment.Environment() - where_javac = env.WhereIs('javac', os.environ['PATH']) - if not where_javac: - where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin') - if not where_javac: - print "Could not find Java javac, skipping test(s)." - test.pass_test(1) - -if test.detect_tool('jar'): - where_jar = test.detect('JAR', 'jar') + where_javac = test.where_is('javac') +if not where_javac: + print "Could not find Java javac, skipping test(s)." + test.pass_test(1) + +if test.detect_tool('jar', ENV=ENV): + where_jar = test.detect('JAR', 'jar', ENV=ENV) else: - import SCons.Environment - env = SCons.Environment.Environment() - where_jar = env.WhereIs('jar', os.environ['PATH']) - if not where_jar: - where_jar = env.WhereIs('jar', '/usr/local/j2sdk1.3.1/bin') - if not where_jar: - print "Could not find Java jar, skipping test(s)." - test.pass_test(1) + where_jar = test.where_is('jar') +if not where_jar: + print "Could not find Java jar, skipping test(s)." + test.pass_test(1) test.write("wrapper.py", """\ diff --git a/test/Java/JARFLAGS.py b/test/Java/JARFLAGS.py index 7e3669da..9a846ecd 100644 --- a/test/Java/JARFLAGS.py +++ b/test/Java/JARFLAGS.py @@ -32,29 +32,23 @@ test = TestSCons.TestSCons() test.subdir('src') -if test.detect_tool('javac'): - where_javac = test.detect('JAVAC', 'javac') +ENV = test.java_ENV() + +if test.detect_tool('javac', ENV=ENV): + where_javac = test.detect('JAVAC', 'javac', ENV=ENV) else: - import SCons.Environment - env = SCons.Environment.Environment() - where_javac = env.WhereIs('javac', os.environ['PATH']) - if not where_javac: - where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin') - if not where_javac: - print "Could not find Java javac, skipping test(s)." - test.pass_test(1) - -if test.detect_tool('jar'): - where_jar = test.detect('JAR', 'jar') + where_javac = test.where_is('javac') +if not where_javac: + print "Could not find Java javac, skipping test(s)." + test.pass_test(1) + +if test.detect_tool('jar', ENV=ENV): + where_jar = test.detect('JAR', 'jar', ENV=ENV) else: - import SCons.Environment - env = SCons.Environment.Environment() - where_jar = env.WhereIs('jar', os.environ['PATH']) - if not where_jar: - where_jar = env.WhereIs('jar', '/usr/local/j2sdk1.3.1/bin') - if not where_jar: - print "Could not find Java jar, skipping test(s)." - test.pass_test(1) + where_javac = test.where_is('jar') +if not where_jar: + print "Could not find Java jar, skipping test(s)." + test.pass_test(1) test.write('SConstruct', """ env = Environment(tools = ['javac', 'jar'], diff --git a/test/Java/JAVAC.py b/test/Java/JAVAC.py index 779045fd..a89ed528 100644 --- a/test/Java/JAVAC.py +++ b/test/Java/JAVAC.py @@ -91,18 +91,17 @@ line 3 test.must_match('test2.class', "test2.JAVA\nline 3\n") -if test.detect_tool('javac'): - where_javac = test.detect('JAVAC', 'javac') + +ENV = test.java_ENV() + +if test.detect_tool('javac', ENV=ENV): + where_javac = test.detect('JAVAC', 'javac', ENV=ENV) else: - import SCons.Environment - env = SCons.Environment.Environment() - where_javac = env.WhereIs('javac', os.environ['PATH']) - if not where_javac: - where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin') - if not where_javac: - print "Could not find Java, skipping test(s)." - test.pass_test(1) - + where_javac = test.where_is('javac') +if not where_javac: + print "Could not find Java javac, skipping test(s)." + test.pass_test(1) + test.write("wrapper.py", """\ diff --git a/test/Java/JAVACFLAGS.py b/test/Java/JAVACFLAGS.py index ef084cd5..d0ab8479 100644 --- a/test/Java/JAVACFLAGS.py +++ b/test/Java/JAVACFLAGS.py @@ -30,17 +30,15 @@ import TestSCons test = TestSCons.TestSCons() -if test.detect_tool('javac'): - where_javac = test.detect('JAVAC', 'javac') +ENV = test.java_ENV() + +if test.detect_tool('javac', ENV=ENV): + where_javac = test.detect('JAVAC', 'javac', ENV=ENV) else: - import SCons.Environment - env = SCons.Environment.Environment() - where_javac = env.WhereIs('javac', os.environ['PATH']) - if not where_javac: - where_javac = env.WhereIs('javac', '/usr/local/j2sdk1.3.1/bin') - if not where_javac: - print "Could not find Java javac, skipping test(s)." - test.pass_test(1) + where_javac = test.where_is('javac') +if not where_javac: + print "Could not find Java javac, skipping test(s)." + test.pass_test(1) test.subdir('src') diff --git a/test/SWIG/SWIG.py b/test/SWIG/SWIG.py index af76d6c4..21a6a186 100644 --- a/test/SWIG/SWIG.py +++ b/test/SWIG/SWIG.py @@ -121,15 +121,15 @@ if swig: version = sys.version[:3] # see also sys.prefix documentation # handle testing on other platforms: + ldmodule_prefix = '_' + frameworks = '' - ldmodule_prefix = '' platform_sys_prefix = sys.prefix if sys.platform == 'darwin': # OS X has a built-in Python but no static libpython # so you should link to it using apple's 'framework' scheme. # (see top of file for further explanation) frameworks = '-framework Python' - ldmodule_prefix = '_' platform_sys_prefix = '/System/Library/Frameworks/Python.framework/Versions/%s/' % version test.write("wrapper.py", @@ -191,7 +191,7 @@ extern char *bar_string(); test.run(arguments = ldmodule_prefix+'foo' + _dll) - test.fail_test(os.path.exists(test.workpath('wrapper.out'))) + test.must_not_exist(test.workpath('wrapper.out')) test.run(program = python, stdin = """\ import foo @@ -204,7 +204,7 @@ This is foo.c! test.run(arguments = ldmodule_prefix+'bar' + _dll) - test.fail_test(test.read('wrapper.out') != "wrapper.py\n") + test.must_match('wrapper.out', "wrapper.py\n") test.run(program = python, stdin = """\ import foo diff --git a/test/TAR/TARFLAGS.py b/test/TAR/TARFLAGS.py index 58642412..fcf7394f 100644 --- a/test/TAR/TARFLAGS.py +++ b/test/TAR/TARFLAGS.py @@ -49,7 +49,9 @@ for opt, arg in cmd_opts: else: opt_string = opt_string + ' ' + opt def process(outfile, name): if os.path.isdir(name): - for entry in os.listdir(name): + entries = os.listdir(name) + entries.sort() + for entry in entries: process(outfile, os.path.join(name, entry)) else: outfile.write(open(name, 'rb').read())