summaryrefslogtreecommitdiff
path: root/engine/SCons/Tool/swig.py
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2019-07-12 17:48:12 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2019-07-12 17:48:12 +0200
commit19712e5025e3cf6a33fccd0738f04e018d55025f (patch)
tree25683461da536e1e7ffee70279780b4f3586142f /engine/SCons/Tool/swig.py
parentcd2ab5002aa2359575088bbc3183a9a91cc50c31 (diff)
New upstream version 3.0.5upstream/3.0.5
Diffstat (limited to 'engine/SCons/Tool/swig.py')
-rw-r--r--engine/SCons/Tool/swig.py42
1 files changed, 33 insertions, 9 deletions
diff --git a/engine/SCons/Tool/swig.py b/engine/SCons/Tool/swig.py
index 7007a92..a8d6400 100644
--- a/engine/SCons/Tool/swig.py
+++ b/engine/SCons/Tool/swig.py
@@ -10,7 +10,7 @@ selection method.
from __future__ import print_function
#
-# Copyright (c) 2001 - 2017 The SCons Foundation
+# Copyright (c) 2001 - 2019 The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -32,9 +32,10 @@ from __future__ import print_function
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
-__revision__ = "src/engine/SCons/Tool/swig.py 74b2c53bc42290e911b334a6b44f187da698a668 2017/11/14 13:16:53 bdbaddog"
+__revision__ = "src/engine/SCons/Tool/swig.py a56bbd8c09fb219ab8a9673330ffcd55279219d0 2019-03-26 23:16:31 bdeegan"
import os.path
+import sys
import re
import subprocess
@@ -69,7 +70,9 @@ def _find_modules(src):
directors = 0
mnames = []
try:
- matches = _reModule.findall(open(src).read())
+ with open(src) as f:
+ data = f.read()
+ matches = _reModule.findall(data)
except IOError:
# If the file's not yet generated, guess the module name from the file stem
matches = []
@@ -134,21 +137,31 @@ def _swigEmitter(target, source, env):
def _get_swig_version(env, swig):
"""Run the SWIG command line tool to get and return the version number"""
+ version = None
swig = env.subst(swig)
+ if not swig:
+ return version
pipe = SCons.Action._subproc(env, SCons.Util.CLVar(swig) + ['-version'],
stdin = 'devnull',
stderr = 'devnull',
stdout = subprocess.PIPE)
- if pipe.wait() != 0: return
+ if pipe.wait() != 0:
+ return version
# MAYBE: out = SCons.Util.to_str (pipe.stdout.read())
- out = SCons.Util.to_str(pipe.stdout.read())
- match = re.search('SWIG Version\s+(\S+).*', out, re.MULTILINE)
+ with pipe.stdout:
+ out = SCons.Util.to_str(pipe.stdout.read())
+
+ match = re.search(r'SWIG Version\s+(\S+).*', out, re.MULTILINE)
if match:
- if verbose: print("Version is:%s"%match.group(1))
- return match.group(1)
+ version = match.group(1)
+ if verbose:
+ print("Version is: %s" % version)
else:
- if verbose: print("Unable to detect version: [%s]"%out)
+ if verbose:
+ print("Unable to detect version: [%s]" % out)
+
+ return version
def generate(env):
"""Add Builders and construction variables for swig to an Environment."""
@@ -169,6 +182,17 @@ def generate(env):
java_file.add_action('.i', SwigAction)
java_file.add_emitter('.i', _swigEmitter)
+ from SCons.Platform.mingw import MINGW_DEFAULT_PATHS
+ from SCons.Platform.cygwin import CYGWIN_DEFAULT_PATHS
+
+ if sys.platform == 'win32':
+ swig = SCons.Tool.find_program_path(env, 'swig', default_paths=MINGW_DEFAULT_PATHS + CYGWIN_DEFAULT_PATHS + [r'C:\ProgramData\chocolatey\bin'] )
+ if swig:
+ swig_bin_dir = os.path.dirname(swig)
+ env.AppendENVPath('PATH', swig_bin_dir)
+ else:
+ SCons.Warnings.Warning('swig tool requested, but binary not found in ENV PATH')
+
if 'SWIG' not in env:
env['SWIG'] = env.Detect(swigs) or swigs[0]
env['SWIGVERSION'] = _get_swig_version(env, env['SWIG'])