Skip to content

Commit

Permalink
Merge pull request #3279 from mwichmann/open-file-warnings
Browse files Browse the repository at this point in the history
Quiet Py3 resource warnings
  • Loading branch information
bdbaddog authored Jan 26, 2019
2 parents 32646d6 + c3c5c76 commit e44c771
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
38 changes: 23 additions & 15 deletions src/engine/SCons/Tool/gcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 15 additions & 5 deletions src/engine/SCons/Tool/swig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit e44c771

Please sign in to comment.