diff options
author | lloyd <[email protected]> | 2012-03-14 13:56:42 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-03-14 13:56:42 +0000 |
commit | 8c2806ff858482a54110c7a105e63e5bb12b7771 (patch) | |
tree | 8478e1cf1332d47708454874c50f7dd353fd7d1e /configure.py | |
parent | 7f0c020ee0aa07f544381037e25bfc7eb02518cd (diff) |
In Python 3 subprocess returns bytes instead of strings. We can
convert using bytes.decode, but that's not available in Python 2.5 and
there doesn't seem to be a good way to test for it at runtime. Instead
use a slight hack of calling subprocess with universal_newlines=True,
which causes Py3k subprocess to assume the output is UTF-8 and decode
accordingly (this should be fine in these cases since monotone will
output a hex string and GCC will just output a version number). On
Python 2 it's mostly ignored (especially as we call strip on the
result anyway).
Diffstat (limited to 'configure.py')
-rwxr-xr-x | configure.py | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/configure.py b/configure.py index 123c91259..d7325f52b 100755 --- a/configure.py +++ b/configure.py @@ -45,20 +45,27 @@ def get_vc_revision(): try: mtn = subprocess.Popen(['mtn', 'automate', 'heads'], stdout=subprocess.PIPE, - stderr=subprocess.PIPE) + stderr=subprocess.PIPE, + universal_newlines=True) (stdout, stderr) = mtn.communicate() - if(stderr != ''): - logging.debug('Error getting rev from monotone - %s' % (stderr)) + if mtn.returncode != 0: + logging.debug('Error getting rev from monotone - %d (%s)' + % (mtn.returncode, stderr)) return 'unknown' - logging.debug('Monotone reported revision ' + stdout.strip()) + rev = str(stdout).strip() + logging.debug('Monotone reported revision %s' % (rev)) - return 'mtn:' + stdout.strip() + return 'mtn:' + rev except OSError as e: logging.debug('Error getting rev from monotone - %s' % (e[1])) return 'unknown' + except Exception as e: + logging.debug('Error getting rev from monotone - %s' % (e)) + return 'unknown' + class BuildConfigurationInformation(object): @@ -1756,12 +1763,19 @@ def main(argv = None): def get_gcc_version(gcc_bin): try: - subproc_result = subprocess.Popen( + gcc_proc = subprocess.Popen( gcc_bin.split(' ') + ['-dumpversion'], stdout=subprocess.PIPE, - stderr=subprocess.PIPE).communicate() + stderr=subprocess.PIPE, + universal_newlines=True) + + (stdout, stderr) = gcc_proc.communicate() + + if gcc_proc.returncode != 0: + logging.warning("GCC returned non-zero result %s" % (stderr)) + return None - gcc_version = ''.join(map(str, subproc_result)).strip() + gcc_version = stdout.strip() logging.info('Detected gcc version %s' % (gcc_version)) return gcc_version |