| OLD | NEW |
| 1 """SCons.Tool.swig | 1 """SCons.Tool.swig |
| 2 | 2 |
| 3 Tool-specific initialization for swig. | 3 Tool-specific initialization for swig. |
| 4 | 4 |
| 5 There normally shouldn't be any need to import this module directly. | 5 There normally shouldn't be any need to import this module directly. |
| 6 It will usually be imported through the generic SCons.Tool.Tool() | 6 It will usually be imported through the generic SCons.Tool.Tool() |
| 7 selection method. | 7 selection method. |
| 8 | 8 |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 # | 11 # |
| 12 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundat
ion | 12 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 The SCons F
oundation |
| 13 # | 13 # |
| 14 # Permission is hereby granted, free of charge, to any person obtaining | 14 # Permission is hereby granted, free of charge, to any person obtaining |
| 15 # a copy of this software and associated documentation files (the | 15 # a copy of this software and associated documentation files (the |
| 16 # "Software"), to deal in the Software without restriction, including | 16 # "Software"), to deal in the Software without restriction, including |
| 17 # without limitation the rights to use, copy, modify, merge, publish, | 17 # without limitation the rights to use, copy, modify, merge, publish, |
| 18 # distribute, sublicense, and/or sell copies of the Software, and to | 18 # distribute, sublicense, and/or sell copies of the Software, and to |
| 19 # permit persons to whom the Software is furnished to do so, subject to | 19 # permit persons to whom the Software is furnished to do so, subject to |
| 20 # the following conditions: | 20 # the following conditions: |
| 21 # | 21 # |
| 22 # The above copyright notice and this permission notice shall be included | 22 # The above copyright notice and this permission notice shall be included |
| 23 # in all copies or substantial portions of the Software. | 23 # in all copies or substantial portions of the Software. |
| 24 # | 24 # |
| 25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY | 25 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY |
| 26 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE | 26 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE |
| 27 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | 27 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 28 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | 28 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 29 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | 29 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 30 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | 30 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 31 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | 31 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 32 # | 32 # |
| 33 | 33 |
| 34 __revision__ = "src/engine/SCons/Tool/swig.py 3842 2008/12/20 22:59:52 scons" | 34 __revision__ = "src/engine/SCons/Tool/swig.py 3897 2009/01/13 06:45:54 scons" |
| 35 | 35 |
| 36 import os.path | 36 import os.path |
| 37 import re | 37 import re |
| 38 | 38 |
| 39 import SCons.Action | 39 import SCons.Action |
| 40 import SCons.Defaults | 40 import SCons.Defaults |
| 41 import SCons.Scanner | 41 import SCons.Scanner |
| 42 import SCons.Tool | 42 import SCons.Tool |
| 43 import SCons.Util | 43 import SCons.Util |
| 44 | 44 |
| 45 SwigAction = SCons.Action.Action('$SWIGCOM', '$SWIGCOMSTR') | 45 SwigAction = SCons.Action.Action('$SWIGCOM', '$SWIGCOMSTR') |
| 46 | 46 |
| 47 def swigSuffixEmitter(env, source): | 47 def swigSuffixEmitter(env, source): |
| 48 if '-c++' in SCons.Util.CLVar(env.subst("$SWIGFLAGS", source=source)): | 48 if '-c++' in SCons.Util.CLVar(env.subst("$SWIGFLAGS", source=source)): |
| 49 return '$SWIGCXXFILESUFFIX' | 49 return '$SWIGCXXFILESUFFIX' |
| 50 else: | 50 else: |
| 51 return '$SWIGCFILESUFFIX' | 51 return '$SWIGCFILESUFFIX' |
| 52 | 52 |
| 53 # Match '%module test', as well as '%module(directors="1") test' | 53 # Match '%module test', as well as '%module(directors="1") test' |
| 54 _reModule = re.compile(r'%module(?:\s*\(.*\))?\s+(.+)') | 54 # Also allow for test to be quoted (SWIG permits double quotes, but not single) |
| 55 _reModule = re.compile(r'%module(\s*\(.*\))?\s+("?)(.+)\2') |
| 56 |
| 57 def _find_modules(src): |
| 58 """Find all modules referenced by %module lines in `src`, a SWIG .i file. |
| 59 Returns a list of all modules.""" |
| 60 mnames = [] |
| 61 matches = _reModule.findall(open(src).read()) |
| 62 for m in matches: |
| 63 mnames.append(m[2]) |
| 64 return mnames |
| 55 | 65 |
| 56 def _swigEmitter(target, source, env): | 66 def _swigEmitter(target, source, env): |
| 57 swigflags = env.subst("$SWIGFLAGS", target=target, source=source) | 67 swigflags = env.subst("$SWIGFLAGS", target=target, source=source) |
| 58 flags = SCons.Util.CLVar(swigflags) | 68 flags = SCons.Util.CLVar(swigflags) |
| 59 for src in source: | 69 for src in source: |
| 60 src = str(src.rfile()) | 70 src = str(src.rfile()) |
| 61 mnames = None | 71 mnames = None |
| 62 if "-python" in flags and "-noproxy" not in flags: | 72 if "-python" in flags and "-noproxy" not in flags: |
| 63 if mnames is None: | 73 if mnames is None: |
| 64 mnames = _reModule.findall(open(src).read()) | 74 mnames = _find_modules(src) |
| 65 target.extend(map(lambda m, d=target[0].dir: | 75 target.extend(map(lambda m, d=target[0].dir: |
| 66 d.File(m + ".py"), mnames)) | 76 d.File(m + ".py"), mnames)) |
| 67 if "-java" in flags: | 77 if "-java" in flags: |
| 68 if mnames is None: | 78 if mnames is None: |
| 69 mnames = _reModule.findall(open(src).read()) | 79 mnames = _find_modules(src) |
| 70 java_files = map(lambda m: [m + ".java", m + "JNI.java"], mnames) | 80 java_files = map(lambda m: [m + ".java", m + "JNI.java"], mnames) |
| 71 java_files = SCons.Util.flatten(java_files) | 81 java_files = SCons.Util.flatten(java_files) |
| 72 outdir = env.subst('$SWIGOUTDIR', target=target, source=source) | 82 outdir = env.subst('$SWIGOUTDIR', target=target, source=source) |
| 73 if outdir: | 83 if outdir: |
| 74 java_files = map(lambda j, o=outdir: os.path.join(o, j), java_f
iles) | 84 java_files = map(lambda j, o=outdir: os.path.join(o, j), java_f
iles) |
| 75 java_files = map(env.fs.File, java_files) | 85 java_files = map(env.fs.File, java_files) |
| 76 for jf in java_files: | 86 for jf in java_files: |
| 77 t_from_s = lambda t, p, s, x: t.dir | 87 t_from_s = lambda t, p, s, x: t.dir |
| 78 SCons.Util.AddMethod(jf, t_from_s, 'target_from_source') | 88 SCons.Util.AddMethod(jf, t_from_s, 'target_from_source') |
| 79 target.extend(java_files) | 89 target.extend(java_files) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 95 | 105 |
| 96 java_file.suffix['.i'] = swigSuffixEmitter | 106 java_file.suffix['.i'] = swigSuffixEmitter |
| 97 | 107 |
| 98 java_file.add_action('.i', SwigAction) | 108 java_file.add_action('.i', SwigAction) |
| 99 java_file.add_emitter('.i', _swigEmitter) | 109 java_file.add_emitter('.i', _swigEmitter) |
| 100 | 110 |
| 101 env['SWIG'] = 'swig' | 111 env['SWIG'] = 'swig' |
| 102 env['SWIGFLAGS'] = SCons.Util.CLVar('') | 112 env['SWIGFLAGS'] = SCons.Util.CLVar('') |
| 103 env['SWIGCFILESUFFIX'] = '_wrap$CFILESUFFIX' | 113 env['SWIGCFILESUFFIX'] = '_wrap$CFILESUFFIX' |
| 104 env['SWIGCXXFILESUFFIX'] = '_wrap$CXXFILESUFFIX' | 114 env['SWIGCXXFILESUFFIX'] = '_wrap$CXXFILESUFFIX' |
| 105 env['_SWIGOUTDIR'] = '${"-outdir " + str(SWIGOUTDIR)}' | 115 env['_SWIGOUTDIR'] = r'${"-outdir \"%s\"" % SWIGOUTDIR}' |
| 106 env['SWIGPATH'] = [] | 116 env['SWIGPATH'] = [] |
| 107 env['SWIGINCPREFIX'] = '-I' | 117 env['SWIGINCPREFIX'] = '-I' |
| 108 env['SWIGINCSUFFIX'] = '' | 118 env['SWIGINCSUFFIX'] = '' |
| 109 env['_SWIGINCFLAGS'] = '$( ${_concat(SWIGINCPREFIX, SWIGPATH, SWIGINCSUF
FIX, __env__, RDirs, TARGET, SOURCE)} $)' | 119 env['_SWIGINCFLAGS'] = '$( ${_concat(SWIGINCPREFIX, SWIGPATH, SWIGINCSUF
FIX, __env__, RDirs, TARGET, SOURCE)} $)' |
| 110 env['SWIGCOM'] = '$SWIG -o $TARGET ${_SWIGOUTDIR} ${_SWIGINCFLAGS}
$SWIGFLAGS $SOURCES' | 120 env['SWIGCOM'] = '$SWIG -o $TARGET ${_SWIGOUTDIR} ${_SWIGINCFLAGS}
$SWIGFLAGS $SOURCES' |
| 111 | 121 |
| 112 expr = '^[ \t]*%[ \t]*(?:include|import|extern)[ \t]*(<|"?)([^>\s"]+)(?:>|"?
)' | 122 expr = '^[ \t]*%[ \t]*(?:include|import|extern)[ \t]*(<|"?)([^>\s"]+)(?:>|"?
)' |
| 113 scanner = SCons.Scanner.ClassicCPP("SWIGScan", ".i", "SWIGPATH", expr) | 123 scanner = SCons.Scanner.ClassicCPP("SWIGScan", ".i", "SWIGPATH", expr) |
| 114 | 124 |
| 115 env.Append(SCANNERS = scanner) | 125 env.Append(SCANNERS = scanner) |
| 116 | 126 |
| 117 def exists(env): | 127 def exists(env): |
| 118 return env.Detect(['swig']) | 128 return env.Detect(['swig']) |
| OLD | NEW |