summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMats Wichmann <mats@linux.com>2019-01-25 19:35:54 (GMT)
committerMats Wichmann <mats@linux.com>2019-01-25 20:26:04 (GMT)
commitc3c5c76704eb6847d270c154d672b402aa8a28b0 (patch)
tree52797b10d3da6b479029efb75c153e7e70beba1c
parent32646d6a66884e501aaffdf92b7022a543403a0b (diff)
downloadSCons-c3c5c76704eb6847d270c154d672b402aa8a28b0.zip
SCons-c3c5c76704eb6847d270c154d672b402aa8a28b0.tar.gz
SCons-c3c5c76704eb6847d270c154d672b402aa8a28b0.tar.bz2
Quiet Py3 resource warnings
Later Pythons (3.6+) enable warnings by default (needed a command line option before then), so some tools give off warnings now. This change quiets the warnings from the gcc, g++ and swig tools. Signed-off-by: Mats Wichmann <mats@linux.com>
-rwxr-xr-xsrc/CHANGES.txt4
-rw-r--r--src/engine/SCons/Tool/gcc.py38
-rw-r--r--src/engine/SCons/Tool/swig.py20
3 files changed, 42 insertions, 20 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt
index 9c7e3b1..94592f5 100755
--- a/src/CHANGES.txt
+++ b/src/CHANGES.txt
@@ -11,6 +11,10 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
- Whatever John Doe did.
+ From Mats Wichmann:
+ - Quiet open file ResourceWarnings on Python >= 3.6 caused by
+ not using a context manager around Popen.stdout
+
RELEASE 3.0.4 - Mon, 20 Jan 2019 22:49:27 +0000
diff --git a/src/engine/SCons/Tool/gcc.py b/src/engine/SCons/Tool/gcc.py
index fabcc96..79b64f0 100644
--- a/src/engine/SCons/Tool/gcc.py
+++ b/src/engine/SCons/Tool/gcc.py
@@ -68,32 +68,40 @@ def exists(env):
def detect_version(env, cc):
"""Return the version of the GNU compiler, or None if it is not a GNU compiler."""
+ version = None
cc = env.subst(cc)
if not cc:
- return None
- version = None
+ return version
+
+ # -dumpversion was added in GCC 3.0. As long as we're supporting
+ # GCC versions older than that, we should use --version and a
+ # regular expression.
# pipe = SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['-dumpversion'],
pipe = SCons.Action._subproc(env, SCons.Util.CLVar(cc) + ['--version'],
stdin='devnull',
stderr='devnull',
stdout=subprocess.PIPE)
- # -dumpversion was added in GCC 3.0. As long as we're supporting
- # GCC versions older than that, we should use --version and a
- # regular expression.
- # line = pipe.stdout.read().strip()
+ if pipe.wait() != 0:
+ return version
+
+ with pipe.stdout:
+ # -dumpversion variant:
+ # line = pipe.stdout.read().strip()
+ # --version variant:
+ line = SCons.Util.to_str(pipe.stdout.readline())
+ # Non-GNU compiler's output (like AIX xlc's) may exceed the stdout buffer:
+ # So continue with reading to let the child process actually terminate.
+ while SCons.Util.to_str(pipe.stdout.readline()):
+ pass
+
+ # -dumpversion variant:
# if line:
- # version = line
- line = SCons.Util.to_str(pipe.stdout.readline())
+ # version = line
+ # --version variant:
match = re.search(r'[0-9]+(\.[0-9]+)+', line)
if match:
version = match.group(0)
- # Non-GNU compiler's output (like AIX xlc's) may exceed the stdout buffer:
- # So continue with reading to let the child process actually terminate.
- while SCons.Util.to_str(pipe.stdout.readline()):
- pass
- ret = pipe.wait()
- if ret != 0:
- return None
+
return version
# Local Variables:
diff --git a/src/engine/SCons/Tool/swig.py b/src/engine/SCons/Tool/swig.py
index 08881a0..77cfe1d 100644
--- a/src/engine/SCons/Tool/swig.py
+++ b/src/engine/SCons/Tool/swig.py
@@ -135,21 +135,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())
+ with pipe.stdout:
+ out = SCons.Util.to_str(pipe.stdout.read())
+
match = re.search('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."""