Skip to content
Permalink
Browse files

Merge pull request #3279 from mwichmann/open-file-warnings

Quiet Py3 resource warnings
  • Loading branch information...
bdbaddog committed Jan 26, 2019
2 parents 32646d6 + c3c5c76 commit e44c771cb3c0c5bd82ef3cd99d56cb47b2c4dc2c
Showing with 42 additions and 20 deletions.
  1. +4 −0 src/CHANGES.txt
  2. +23 −15 src/engine/SCons/Tool/gcc.py
  3. +15 −5 src/engine/SCons/Tool/swig.py
@@ -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

@@ -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:
@@ -135,21 +135,31 @@ def t_from_s(t, p, s, x):

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."""

0 comments on commit e44c771

Please sign in to comment.
You can’t perform that action at this time.