From: stevenknight Date: Tue, 7 May 2002 21:52:15 +0000 (+0000) Subject: Add a better PATH search to the tests. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4d66070bc731765fca44a3068cb3be5fbe81eb0b;p=scons.git Add a better PATH search to the tests. git-svn-id: http://scons.tigris.org/svn/scons/trunk@367 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- diff --git a/etc/TestCmd.py b/etc/TestCmd.py index 2d1c9325..06e324f7 100644 --- a/etc/TestCmd.py +++ b/etc/TestCmd.py @@ -41,23 +41,36 @@ or incorrect permissions). # AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. -from string import join, split - __author__ = "Steven Knight " __revision__ = "TestCmd.py 0.D002 2001/08/31 14:56:12 software" __version__ = "0.02" -from types import * - import os import os.path import popen2 import re import shutil import stat +import string import sys import tempfile import traceback +import types + +try: + from UserString import UserString +except ImportError: + class UserString: + pass + +if hasattr(types, 'UnicodeType'): + def is_String(e): + return type(e) is types.StringType \ + or type(e) is types.UnicodeType \ + or isinstance(e, UserString) +else: + def is_String(e): + return type(e) is types.StringType or isinstance(e, UserString) tempfile.template = 'testcmd.' @@ -161,10 +174,10 @@ def pass_test(self = None, condition = 1, function = None): def match_exact(lines = None, matches = None): """ """ - if not type(lines) is ListType: - lines = split(lines, "\n") - if not type(matches) is ListType: - matches = split(matches, "\n") + if not type(lines) is types.ListType: + lines = string.split(lines, "\n") + if not type(matches) is types.ListType: + matches = string.split(matches, "\n") if len(lines) != len(matches): return for i in range(len(lines)): @@ -175,10 +188,10 @@ def match_exact(lines = None, matches = None): def match_re(lines = None, res = None): """ """ - if not type(lines) is ListType: - lines = split(lines, "\n") - if not type(res) is ListType: - res = split(res, "\n") + if not type(lines) is types.ListType: + lines = string.split(lines, "\n") + if not type(res) is types.ListType: + res = string.split(res, "\n") if len(lines) != len(res): return for i in range(len(lines)): @@ -190,12 +203,53 @@ def match_re_dotall(lines = None, res = None): """ """ if not type(lines) is type(""): - lines = join(lines, "\n") + lines = string.join(lines, "\n") if not type(res) is type(""): - res = join(res, "\n") + res = string.join(res, "\n") if re.compile("^" + res + "$", re.DOTALL).match(lines): return 1 +if sys.platform == 'win32': + + def where_is(file, path=None, pathext=None): + if path is None: + path = os.environ['PATH'] + if is_String(path): + path = string.split(path, os.pathsep) + if pathext is None: + pathext = os.environ['PATHEXT'] + if is_String(pathext): + pathext = string.split(pathext, os.pathsep) + for ext in pathext: + if string.lower(ext) == string.lower(file[-len(ext):]): + pathext = [''] + break + for dir in path: + f = os.path.join(dir, file) + for ext in pathext: + fext = f + ext + if os.path.isfile(fext): + return fext + return None + +else: + + def where_is(file, path=None, pathext=None): + if path is None: + path = os.environ['PATH'] + if is_String(path): + path = string.split(path, os.pathsep) + for dir in path: + f = os.path.join(dir, file) + if os.path.isfile(f): + try: + st = os.stat(f) + except: + continue + if stat.S_IMODE(st[stat.ST_MODE]) & 0111: + return f + return None + class TestCmd: """Class TestCmd """ @@ -372,7 +426,7 @@ class TestCmd: be specified; it must begin with an 'r'. The default is 'rb' (binary read). """ - if type(file) is ListType: + if type(file) is types.ListType: file = apply(os.path.join, tuple(file)) if not os.path.isabs(file): file = os.path.join(self.workdir, file) @@ -416,7 +470,7 @@ class TestCmd: except AttributeError: (tochild, fromchild, childerr) = os.popen3(cmd) if stdin: - if type(stdin) is ListType: + if type(stdin) is types.ListType: for line in stdin: tochild.write(line) else: @@ -432,7 +486,7 @@ class TestCmd: raise else: if stdin: - if type(stdin) is ListType: + if type(stdin) is types.ListType: for line in stdin: p.tochild.write(line) else: @@ -487,7 +541,7 @@ class TestCmd: for sub in subdirs: if sub is None: continue - if type(sub) is ListType: + if type(sub) is types.ListType: sub = apply(os.path.join, tuple(sub)) new = os.path.join(self.workdir, sub) try: @@ -505,7 +559,7 @@ class TestCmd: assumed to be under the temporary working directory unless it is an absolute path name. """ - if type(file) is ListType: + if type(file) is types.ListType: file = apply(os.path.join, tuple(file)) if not os.path.isabs(file): file = os.path.join(self.workdir, file) @@ -517,6 +571,15 @@ class TestCmd: """ self.verbose = verbose + def where_is(self, file, path=None, pathext=None): + """Find an executable file. + """ + if type(file) is types.ListType: + file = apply(os.path.join, tuple(file)) + if not os.path.isabs(file): + file = where_is(file, path, pathext) + return file + def workdir_set(self, path): """Creates a temporary working directory with the specified path name. If the path is a null string (''), a unique @@ -590,7 +653,7 @@ class TestCmd: exist. The I/O mode for the file may be specified; it must begin with a 'w'. The default is 'wb' (binary write). """ - if type(file) is ListType: + if type(file) is types.ListType: file = apply(os.path.join, tuple(file)) if not os.path.isabs(file): file = os.path.join(self.workdir, file) diff --git a/test/DVIPDF.py b/test/DVIPDF.py index 69108e17..d22cfd8b 100644 --- a/test/DVIPDF.py +++ b/test/DVIPDF.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -104,12 +99,7 @@ test.fail_test(test.read('test2.pdf') != "This is a .tex test.\n") -dvipdf = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'dvipdf' + _exe) - if os.path.exists(l): - dvipdf = l - break +dvipdf = test.where_is('dvipdf') if dvipdf: diff --git a/test/DVIPDFFLAGS.py b/test/DVIPDFFLAGS.py index 6d653181..e6f91463 100644 --- a/test/DVIPDFFLAGS.py +++ b/test/DVIPDFFLAGS.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -110,12 +105,7 @@ test.fail_test(test.read('test2.pdf') != " -x\nThis is a .tex test.\n") -dvipdf = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'dvipdf' + _exe) - if os.path.exists(l): - dvipdf = l - break +dvipdf = test.where_is('dvipdf') if dvipdf: diff --git a/test/DVIPS.py b/test/DVIPS.py index 91900be7..b3bdebc3 100644 --- a/test/DVIPS.py +++ b/test/DVIPS.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -119,12 +114,7 @@ test.fail_test(test.read('test4.ps') != "This is a .latex test.\n") -dvips = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'dvips' + _exe) - if os.path.exists(l): - dvips = l - break +dvips = test.where_is('dvips') if dvips: diff --git a/test/DVIPSFLAGS.py b/test/DVIPSFLAGS.py index e043e755..664b5329 100644 --- a/test/DVIPSFLAGS.py +++ b/test/DVIPSFLAGS.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -126,12 +121,7 @@ test.fail_test(test.read('test4.ps') != " -x\nThis is a .latex test.\n") -dvips = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'dvips' + _exe) - if os.path.exists(l): - dvips = l - break +dvips = test.where_is('dvips') if dvips: diff --git a/test/F77.py b/test/F77.py index 964682d2..65484988 100644 --- a/test/F77.py +++ b/test/F77.py @@ -167,12 +167,7 @@ test.fail_test(test.read('test6' + _exe) != "This is a .FPP file.\n") -g77 = None -for dir in string.split(os.environ['PATH'], os.pathsep): - g = os.path.join(dir, 'g77' + _exe) - if os.path.exists(g): - g77 = g - break +g77 = test.where_is('g77') if g77: diff --git a/test/F77FLAGS.py b/test/F77FLAGS.py index 5241e7b5..e4d1f8cf 100644 --- a/test/F77FLAGS.py +++ b/test/F77FLAGS.py @@ -179,12 +179,7 @@ test.fail_test(test.read('test6' + _exe) != "%s\nThis is a .FPP file.\n" % o) -g77 = None -for dir in string.split(os.environ['PATH'], os.pathsep): - g = os.path.join(dir, 'g77' + _exe) - if os.path.exists(g): - g77 = g - break +g77 = test.where_is('g77') if g77: diff --git a/test/LATEX.py b/test/LATEX.py index 9ac74f53..440054d2 100644 --- a/test/LATEX.py +++ b/test/LATEX.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -75,12 +70,7 @@ test.fail_test(test.read('test2.dvi') != "This is a .latex test.\n") -latex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'latex' + _exe) - if os.path.exists(l): - latex = l - break +latex = test.where_is('latex') if latex: diff --git a/test/LATEXFLAGS.py b/test/LATEXFLAGS.py index c366c8a7..5ad4d955 100644 --- a/test/LATEXFLAGS.py +++ b/test/LATEXFLAGS.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -81,12 +76,7 @@ test.fail_test(test.read('test2.dvi') != " -t\nThis is a .latex test.\n") -latex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'latex' + _exe) - if os.path.exists(l): - latex = l - break +latex = test.where_is('latex') if latex: diff --git a/test/LEX.py b/test/LEX.py index 59a887d1..88c0a2de 100644 --- a/test/LEX.py +++ b/test/LEX.py @@ -74,12 +74,7 @@ test.run(program = test.workpath('aaa' + _exe), stdout = "mylex.py\naaa.l\n") -lex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'lex' + _exe) - if os.path.exists(l): - lex = l - break +lex = test.where_is('lex') if lex: diff --git a/test/LEXFLAGS.py b/test/LEXFLAGS.py index b4154952..e807774c 100644 --- a/test/LEXFLAGS.py +++ b/test/LEXFLAGS.py @@ -77,12 +77,7 @@ test.run(program = test.workpath('aaa' + _exe), stdout = " -x -t\naaa.l\n") -lex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'lex' + _exe) - if os.path.exists(l): - lex = l - break +lex = test.where_is('lex') if lex: diff --git a/test/PDFLATEX.py b/test/PDFLATEX.py index a64f1581..f665d0f8 100644 --- a/test/PDFLATEX.py +++ b/test/PDFLATEX.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -75,12 +70,7 @@ test.fail_test(not os.path.exists(test.workpath('test2.pdf'))) -pdflatex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'pdflatex' + _exe) - if os.path.exists(l): - pdflatex = l - break +pdflatex = test.where_is('pdflatex') if pdflatex: diff --git a/test/PDFLATEXFLAGS.py b/test/PDFLATEXFLAGS.py index 1693b567..6ddd41a7 100644 --- a/test/PDFLATEXFLAGS.py +++ b/test/PDFLATEXFLAGS.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -81,12 +76,7 @@ test.fail_test(not os.path.exists(test.workpath('test2.pdf'))) -pdflatex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - l = os.path.join(dir, 'pdflatex' + _exe) - if os.path.exists(l): - pdflatex = l - break +pdflatex = test.where_is('pdflatex') if pdflatex: diff --git a/test/PDFTEX.py b/test/PDFTEX.py index 41024c4f..4fe53416 100644 --- a/test/PDFTEX.py +++ b/test/PDFTEX.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -68,12 +63,7 @@ test.fail_test(not os.path.exists(test.workpath('test.pdf'))) -pdftex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - t = os.path.join(dir, 'pdftex' + _exe) - if os.path.exists(t): - pdftex = t - break +pdftex = test.where_is('pdftex') if pdftex: diff --git a/test/PDFTEXFLAGS.py b/test/PDFTEXFLAGS.py index 59d67bef..aa5cc9f2 100644 --- a/test/PDFTEXFLAGS.py +++ b/test/PDFTEXFLAGS.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -74,12 +69,7 @@ test.fail_test(not os.path.exists(test.workpath('test.pdf'))) -pdftex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - t = os.path.join(dir, 'pdftex' + _exe) - if os.path.exists(t): - pdftex = t - break +pdftex = test.where_is('pdftex') if pdftex: diff --git a/test/RANLIB.py b/test/RANLIB.py index 12ae2128..14708e01 100644 --- a/test/RANLIB.py +++ b/test/RANLIB.py @@ -37,15 +37,10 @@ if sys.platform == 'win32': else: _exe = '' -ranlib = None -for dir in string.split(os.environ['PATH'], os.pathsep): - r = os.path.join(dir, 'ranlib' + _exe) - if os.path.exists(r): - ranlib = r - break - test = TestSCons.TestSCons() +ranlib = test.where_is('ranlib') + test.no_result(not ranlib) test.write("wrapper.py", diff --git a/test/RANLIBFLAGS.py b/test/RANLIBFLAGS.py index 752f6857..b3e94510 100644 --- a/test/RANLIBFLAGS.py +++ b/test/RANLIBFLAGS.py @@ -36,15 +36,10 @@ if sys.platform == 'win32': else: _exe = '' -ranlib = None -for dir in string.split(os.environ['PATH'], os.pathsep): - r = os.path.join(dir, 'ranlib' + _exe) - if os.path.exists(r): - ranlib = r - break - test = TestSCons.TestSCons() +ranlib = test.where_is('ranlib') + test.no_result(not ranlib) test.write("wrapper.py", diff --git a/test/SHF77.py b/test/SHF77.py index 43c64858..cffd94d1 100644 --- a/test/SHF77.py +++ b/test/SHF77.py @@ -169,12 +169,7 @@ test.fail_test(test.read('test6' + _exe) != "This is a .FPP file.\n") -g77 = None -for dir in string.split(os.environ['PATH'], os.pathsep): - g = os.path.join(dir, 'g77' + _exe) - if os.path.exists(g): - g77 = g - break +g77 = test.where_is('g77') if g77: diff --git a/test/SHF77FLAGS.py b/test/SHF77FLAGS.py index cb1e6f68..231fea26 100644 --- a/test/SHF77FLAGS.py +++ b/test/SHF77FLAGS.py @@ -185,12 +185,7 @@ test.fail_test(test.read('test6' + _exe) != "%s\nThis is a .FPP file.\n" % o) -g77 = None -for dir in string.split(os.environ['PATH'], os.pathsep): - g = os.path.join(dir, 'g77' + _exe) - if os.path.exists(g): - g77 = g - break +g77 = test.where_is('g77') if g77: diff --git a/test/TEX.py b/test/TEX.py index 9b442c97..bcdd62e0 100644 --- a/test/TEX.py +++ b/test/TEX.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -68,12 +63,7 @@ test.fail_test(test.read('test.dvi') != "This is a test.\n") -tex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - t = os.path.join(dir, 'tex' + _exe) - if os.path.exists(t): - tex = t - break +tex = test.where_is('tex') if tex: diff --git a/test/TEXFLAGS.py b/test/TEXFLAGS.py index 4cc08d3e..1f7121f4 100644 --- a/test/TEXFLAGS.py +++ b/test/TEXFLAGS.py @@ -32,11 +32,6 @@ import TestSCons python = sys.executable -if sys.platform == 'win32': - _exe = '.exe' -else: - _exe = '' - test = TestSCons.TestSCons() @@ -74,12 +69,7 @@ test.fail_test(test.read('test.dvi') != " -x\nThis is a test.\n") -tex = None -for dir in string.split(os.environ['PATH'], os.pathsep): - t = os.path.join(dir, 'tex' + _exe) - if os.path.exists(t): - tex = t - break +tex = test.where_is('tex') if tex: diff --git a/test/YACC.py b/test/YACC.py index 8fea904d..2868085e 100644 --- a/test/YACC.py +++ b/test/YACC.py @@ -80,12 +80,7 @@ test.run(program = test.workpath('aaa' + _exe), stdout = "myyacc.py\naaa.y\n") -yacc = None -for dir in string.split(os.environ['PATH'], os.pathsep): - y = os.path.join(dir, 'yacc' + _exe) - if os.path.exists(y): - yacc = y - break +yacc = test.where_is('yacc') if yacc: diff --git a/test/YACCFLAGS.py b/test/YACCFLAGS.py index 10c29ca0..288696ba 100644 --- a/test/YACCFLAGS.py +++ b/test/YACCFLAGS.py @@ -80,12 +80,7 @@ test.run(program = test.workpath('aaa' + _exe), stdout = " -x\naaa.y\n") -yacc = None -for dir in string.split(os.environ['PATH'], os.pathsep): - y = os.path.join(dir, 'yacc' + _exe) - if os.path.exists(y): - yacc = y - break +yacc = test.where_is('yacc') if yacc: