Bug 792202 - Make mozboot work with Python 2.6.1; r=jhammel DONTBUILD
authorGregory Szorc <gps@mozilla.com>
Tue, 18 Sep 2012 14:45:21 -0700
changeset 107458 e2f161ca30bc3e2afcf3b9fee6c70c529a69f6ad
parent 107444 e4757379b99a45135be2606b20bc14c6695f0495
child 107459 fc68881025176ddfc67d5de53780cd9dc3f3bda0
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewersjhammel
bugs792202
milestone18.0a1
Bug 792202 - Make mozboot work with Python 2.6.1; r=jhammel DONTBUILD Python 2.6.1 is what ships on OS X 10.6 and we want to support mozboot there. We include 3 fixes: 1) optparse doesn't like unicode as its initial argument 2) __init__(**kwargs) doesn't like unicode keys 3) subprocess does not have check_output We took the easy solution of removing unicode_literals. This should have no significant consequences.
python/mozboot/bin/bootstrap.py
python/mozboot/mozboot/base.py
python/mozboot/mozboot/bootstrap.py
python/mozboot/mozboot/osx.py
--- a/python/mozboot/bin/bootstrap.py
+++ b/python/mozboot/bin/bootstrap.py
@@ -5,17 +5,19 @@
 
 # This script provides one-line bootstrap support to configure systems to build
 # the tree.
 #
 # The role of this script is to load the Python modules containing actual
 # 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
 import sys
 import tempfile
 import urllib2
 
 from optparse import OptionParser
--- a/python/mozboot/mozboot/base.py
+++ b/python/mozboot/mozboot/base.py
@@ -47,8 +47,28 @@ class BaseBootstrapper(object):
 
         self.run_as_root(command)
 
     def apt_install(self, *packages):
         command = ['apt-get', 'install']
         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
--- a/python/mozboot/mozboot/bootstrap.py
+++ b/python/mozboot/mozboot/bootstrap.py
@@ -1,13 +1,14 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # 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
 
 from mozboot.centos import CentOSBootstrapper
 from mozboot.fedora import FedoraBootstrapper
 from mozboot.mint import MintBootstrapper
 from mozboot.osx import OSXBootstrapper
--- a/python/mozboot/mozboot/osx.py
+++ b/python/mozboot/mozboot/osx.py
@@ -114,33 +114,33 @@ class OSXBootstrapper(BaseBootstrapper):
                 subprocess.check_call(['open', XCODE_APP_STORE])
 
                 print('Once the install has finished, please relaunch this script.')
                 sys.exit(1)
 
         # 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:
                  xcodebuild = self.which('xcodebuild')
                  subprocess.check_call([xcodebuild, '-license'])
 
         # Even then we're not done! We need to install the Xcode command line tools.
         # As of Mountain Lion, apparently the only way to do this is to go through a
         # menu dialog inside Xcode itself. We're not making this up.
         if self.os_version >= 7:
             if not os.path.exists('/usr/bin/clang'):
                 print(XCODE_COMMAND_LINE_TOOLS_MISSING)
                 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.')
 
             version = StrictVersion(match.group(1))
 
             if version < APPLE_CLANG_MINIMUM_VERSION:
                 print(UPGRADE_XCODE_COMMAND_LINE_TOOLS)
@@ -165,17 +165,17 @@ class OSXBootstrapper(BaseBootstrapper):
 
         print(HOMEBREW_XQUARTZ)
         sys.exit(1)
 
     def ensure_homebrew_packages(self):
         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()
 
         packages = [
             # We need to install Python because Mercurial requires the Python
             # development headers which are missing from OS X (at least on
             # 10.8).