diff --git a/python/mozboot/bin/bootstrap.py b/python/mozboot/bin/bootstrap.py index cd5cf8920e46..0e2c3e1c286e 100755 --- a/python/mozboot/bin/bootstrap.py +++ b/python/mozboot/bin/bootstrap.py @@ -10,7 +10,9 @@ # bootstrap support. It does this through various means, including fetching # content from the upstream source repository. -from __future__ import print_function, unicode_literals +# If we add unicode_literals, optparse breaks on Python 2.6.1 (which is needed +# to support OS X 10.6). +from __future__ import print_function import os import shutil diff --git a/python/mozboot/mozboot/base.py b/python/mozboot/mozboot/base.py index 96de676ba18a..66b998f920f1 100644 --- a/python/mozboot/mozboot/base.py +++ b/python/mozboot/mozboot/base.py @@ -52,3 +52,23 @@ class BaseBootstrapper(object): command.extend(packages) self.run_as_root(command) + + def check_output(self, *args, **kwargs): + """Run subprocess.check_output even if Python doesn't provide it.""" + fn = getattr(subprocess, 'check_output', BaseBootstrapper._check_output) + + return fn(*args, **kwargs) + + @staticmethod + def _check_output(*args, **kwargs): + """Python 2.6 compatible implementation of subprocess.check_output.""" + proc = subprocess.Popen(stdout=subprocess.PIPE, *args, **kwargs) + output, unused_err = proc.communicate() + retcode = proc.poll() + if retcode: + cmd = kwargs.get('args', args[0]) + e = subprocess.CalledProcessError(retcode, cmd) + e.output = output + raise e + + return output diff --git a/python/mozboot/mozboot/bootstrap.py b/python/mozboot/mozboot/bootstrap.py index 1a8fb623109a..9b4b9567d068 100644 --- a/python/mozboot/mozboot/bootstrap.py +++ b/python/mozboot/mozboot/bootstrap.py @@ -2,7 +2,8 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this file, # You can obtain one at http://mozilla.org/MPL/2.0/. -from __future__ import print_function, unicode_literals +# If we add unicode_literals, Python 2.6.1 (required for OS X 10.6) breaks. +from __future__ import print_function import platform import sys diff --git a/python/mozboot/mozboot/osx.py b/python/mozboot/mozboot/osx.py index e17347a2df66..483d8b8ada4d 100644 --- a/python/mozboot/mozboot/osx.py +++ b/python/mozboot/mozboot/osx.py @@ -119,7 +119,7 @@ class OSXBootstrapper(BaseBootstrapper): # Once Xcode is installed, you need to agree to the license before you can # use it. try: - output = subprocess.check_output(['/usr/bin/xcrun', 'clang'], + output = self.check_output(['/usr/bin/xcrun', 'clang'], stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: if 'license' in e.output: @@ -135,7 +135,7 @@ class OSXBootstrapper(BaseBootstrapper): print(INSTALL_XCODE_COMMAND_LINE_TOOLS_STEPS) sys.exit(1) - output = subprocess.check_output(['/usr/bin/clang', '--version']) + output = self.check_output(['/usr/bin/clang', '--version']) match = RE_CLANG_VERSION.search(output) if match is None: raise Exception('Could not determine Clang version.') @@ -170,7 +170,7 @@ class OSXBootstrapper(BaseBootstrapper): brew = self.which('brew') assert brew is not None - installed = subprocess.check_output([brew, 'list']).split() + installed = self.check_output([brew, 'list']).split() if 'python' not in installed: self.ensure_xquartz()