except KeyError:
return None
+ def Detect(self, progs):
+ """Return the first available program in progs.
+ """
+ path = None
+ pathext = None
+ if self.has_key('ENV'):
+ if self['ENV'].has_key('PATH'):
+ path = self['ENV']['PATH']
+ if self['ENV'].has_key('PATHEXT'):
+ pathext = self['ENV']['PATHEXT']
+ if not SCons.Util.is_List(progs):
+ progs = [ progs ]
+ for prog in progs:
+ path = SCons.Util.WhereIs(prog, path, pathext)
+ if path: return prog
+ return None
+
class VarInterpolator:
def __init__(self, dest, src, prefix, suffix):
self.dest = dest
__revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
+import os
import string
import sys
+import TestCmd
import unittest
from SCons.Environment import *
assert dict['_CPPINCFLAGS'][17] == '$)', \
dict['_CPPINCFLAGS'][17]
+ def test_Detect(self):
+ """Test Detect()ing tools"""
+ test = TestCmd.TestCmd(workdir = '')
+ test.subdir('sub1', 'sub2')
+ test.write(['sub1', 'xxx.exe'], "sub1/xxx.exe\n")
+ test.write(['sub2', 'xxx.exe'], "sub2/xxx.exe\n")
+ sub1 = test.workpath('sub1')
+ sub2 = test.workpath('sub2')
+ env = Environment(ENV = { 'PATH' : [sub1, sub2] })
+ x = env.Detect('xxx.exe')
+ assert x is None, x
+
+ sub2_xxx_exe = test.workpath('sub2', 'xxx.exe')
+ os.chmod(sub2_xxx_exe, 0755)
+
+ env = Environment(ENV = { 'PATH' : [sub1, sub2] })
+ x = env.Detect('xxx.exe')
+ assert x == 'xxx.exe'
+
+ sub1_xxx_exe = test.workpath('sub1', 'xxx.exe')
+ os.chmod(sub1_xxx_exe, 0755)
+
+ x = env.Detect('xxx.exe')
+ assert x == 'xxx.exe'
+
+ env = Environment(ENV = { 'PATH' : [] })
+ x = env.Detect('xxx.exe')
+ assert x is None, x
def test_platform(self):
"""Test specifying a platform callable when instantiating."""
class ToolTestCase(unittest.TestCase):
def test_Tool(self):
"""Test the Tool() function"""
- # FIXME - this might fail, since there might be no C++ compiler on the system.
- # How do we handle this?
+ class Environment:
+ def __init__(self):
+ self.dict = {}
+ def Detect(self, progs):
+ if not SCons.Util.is_List(progs):
+ progs = [ progs ]
+ return progs[0]
+ def __getitem__(self, key):
+ return self.dict[key]
+ def __setitem__(self, key, val):
+ self.dict[key] = val
+ env = Environment()
+ env['BUILDERS'] = {}
+ env['ENV'] = {}
t = SCons.Tool.Tool('g++')
- env= { 'BUILDERS' : {}, 'ENV' : {} }
t(env, 'foo')
assert (env['CXX'] == 'c++' or env['CXX'] == 'g++'), env['CXX']
assert env['CXXFLAGS'] == '$CCFLAGS', env['CXXFLAGS']
arcom = '$AR $ARFLAGS $TARGET $SOURCES'
ranlib = 'ranlib'
- if SCons.Util.Detect([ranlib], env):
+ if env.Detect(ranlib):
arcom = arcom + '\n$RANLIB $RANLIBFLAGS $TARGET'
env['AR'] = 'ar'
env['SHLINKCOM'] = '$SHLINK $SHLINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
def exists(env):
- return SCons.Util.Detect(['ar'], env)
+ return env.Detect('ar')
env['PDFCOM'] = '$DVIPDF $DVIPDFFLAGS $SOURCES $TARGET'
def exists(env):
- return SCons.Util.Detect(['dvipdf'], env)
+ return env.Detect('dvipdf')
env['PSCOM'] = '$DVIPS $DVIPSFLAGS -o $TARGET $SOURCES'
def exists(env):
- return SCons.Util.Detect(['dvips'], env)
+ return env.Detect('dvips')
static_obj.add_action(suffix, SCons.Defaults.CXXAction)
shared_obj.add_action(suffix, SCons.Defaults.ShCXXAction)
- env['CXX'] = SCons.Util.Detect(compilers, env) or 'c++'
+ env['CXX'] = env.Detect(compilers) or 'c++'
env['CXXFLAGS'] = '$CCFLAGS'
env['CXXCOM'] = '$CXX $CXXFLAGS $CPPFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES'
env['SHCXX'] = '$CXX'
env['CXXFILESUFFIX'] = '.cc'
def exists(env):
- return SCons.Util.Detect(compilers, env)
+ return env.Detect(compilers)
static_obj.add_action(suffix, SCons.Defaults.F77PPAction)
shared_obj.add_action(suffix, SCons.Defaults.ShF77PPAction)
- env['F77'] = SCons.Util.Detect(compilers, env) or 'g77'
+ env['F77'] = env.Detect(compilers) or 'g77'
env['F77FLAGS'] = ''
env['F77COM'] = '$F77 $F77FLAGS $_F77INCFLAGS -c -o $TARGET $SOURCES'
env['F77PPCOM'] = '$F77 $F77FLAGS $CPPFLAGS $_F77INCFLAGS -c -o $TARGET $SOURCES'
env['SHF77PPCOM'] = '$SHF77 $SHF77FLAGS $CPPFLAGS $_F77INCFLAGS -c -o $TARGET $SOURCES'
def exists(env):
- return SCons.Util.Detect(compilers, env)
+ return env.Detect(compilers)
for suffix in ASPPSuffixes:
static_obj.add_action(suffix, SCons.Defaults.ASPPAction)
- env['AS'] = SCons.Util.Detect(assemblers, env) or 'as'
+ env['AS'] = env.Detect(assemblers) or 'as'
env['ASFLAGS'] = ''
env['ASCOM'] = '$AS $ASFLAGS -o $TARGET $SOURCES'
env['ASPPCOM'] = '$CC $ASFLAGS $CPPFLAGS -o $TARGET $SOURCES'
def exists(env):
- return SCons.Util.Detect(assemblers, env)
+ return env.Detect(assemblers)
static_obj.add_action(suffix, SCons.Defaults.CAction)
shared_obj.add_action(suffix, SCons.Defaults.ShCAction)
- env['CC'] = SCons.Util.Detect(compilers, env) or 'cc'
+ env['CC'] = env.Detect(compilers) or 'cc'
env['CCFLAGS'] = ''
env['CCCOM'] = '$CC $CCFLAGS $CPPFLAGS $_CPPINCFLAGS -c -o $TARGET $SOURCES'
env['SHCC'] = '$CC'
env['CFILESUFFIX'] = '.c'
def exists(env):
- return SCons.Util.Detect(compilers, env)
+ return env.Detect(compilers)
env['SHLINKFLAGS'] = '$LINKFLAGS -shared'
env['SHLINKCOM'] = '$SHLINK $SHLINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
env['SHLIBEMITTER']= None
- env['LINK'] = SCons.Util.Detect(linkers, env) or 'c++'
+ env['LINK'] = env.Detect(linkers) or 'c++'
env['LINKFLAGS'] = ''
env['LINKCOM'] = '$LINK $LINKFLAGS -o $TARGET $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
env['LIBDIRPREFIX']='-L'
env['LIBLINKSUFFIX']=''
def exists(env):
- return SCons.Util.Detect(linkers, env)
+ return env.Detect(linkers)
env['CXXFILESUFFIX'] = '.cc'
def exists(env):
- return SCons.Util.Detect(['icc'], env)
+ return env.Detect('icc')
env['SHF77PPCOM'] = '$SHF77 $SHF77FLAGS $CPPFLAGS $_F77INCFLAGS /c $SOURCES /Fo$TARGET'
def exists(env):
- return SCons.Util.Detect(['ifl'], env)
+ return env.Detect('ifl')
env['LIBLINKSUFFIX']='$LIBSUFFIX'
def exists(env):
- return SCons.Util.Detect(['ilink'], env)
+ return env.Detect('ilink')
env['LATEXCOM'] = '$LATEX $LATEXFLAGS $SOURCES'
def exists(env):
- return SCons.Util.Detect(['latex'], env)
+ return env.Detect('latex')
env['LEXCOM'] = '$LEX $LEXFLAGS -t $SOURCES > $TARGET'
def exists(env):
- return SCons.Util.Detect(['lex'], env)
+ return env.Detect('lex')
env['ARCOM'] = '$AR $ARFLAGS /OUT:$TARGET $SOURCES'
def exists(env):
- return SCons.Util.Detect(['lib'], env)
+ return env.Detect('lib')
env['ASPPCOM'] = '$CC $ASFLAGS $CPPFLAGS /c /Fo$TARGET $SOURCES'
def exists(env):
- return SCons.Util.Detect(['ml'], env)
+ return env.Detect('ml')
env['ENV']['PATH'] = exe_path
def exists(env):
- return SCons.Util.Detect(['link'], env)
+ return env.Detect('link')
env['CXXFILESUFFIX'] = '.cc'
def exists(env):
- return SCons.Util.Detect(['cl'], env)
+ return env.Detect('cl')
env['ASPPCOM'] = '$CC $ASFLAGS $CPPFLAGS -c -o $TARGET $SOURCES'
def exists(env):
- return SCons.Util.Detect(['nasm'], env)
+ return env.Detect('nasm')
env['PDFLATEXCOM'] = '$PDFLATEX $PDFLATEXFLAGS $SOURCES $TARGET'
def exists(env):
- return SCons.Util.Detect(['pdflatex'], env)
+ return env.Detect('pdflatex')
env['PDFTEXCOM'] = '$PDFTEX $PDFTEXFLAGS $SOURCES $TARGET'
def exists(env):
- return SCons.Util.Detect(['pdftex'], env)
+ return env.Detect('pdftex')
bld = TarBuilder
env['BUILDERS']['Tar'] = bld
- env['TAR'] = SCons.Util.Detect(tars, env) or 'gtar'
+ env['TAR'] = env.Detect(tars) or 'gtar'
env['TARFLAGS'] = '-c'
env['TARCOM'] = '$TAR $TARFLAGS -f $TARGET $SOURCES'
env['TARSUFFIX'] = '.tar'
def exists(env):
- return SCons.Util.Detect(tars, env)
+ return env.Detect(tars)
env['TEXCOM'] = '$TEX $TEXFLAGS $SOURCES'
def exists(env):
- return SCons.Util.Detect(['tex'], env)
+ return env.Detect('tex')
env['YACCCOM'] = '$YACC $YACCFLAGS -o $TARGET $SOURCES'
def exists(env):
- return SCons.Util.Detect(['yacc'], env)
+ return env.Detect('yacc')
if stat.S_IMODE(st[stat.ST_MODE]) & 0111:
return f
return None
-
-def Detect(progs, env=None):
- "Return the first available program in progs"
- path = None
- pathext = None
- if env and env.has_key('ENV'):
- if env['ENV'].has_key('PATH'):
- path = env['ENV']['PATH']
- if env['ENV'].has_key('PATHEXT'):
- pathext = env['ENV']['PATHEXT']
- for prog in progs:
- path = WhereIs(prog, path, pathext)
- if path: return prog
- return None