Bug 774109 - Bootstrap support for OS X; r=rnewman DONTBUILD

This implements the OS X backend for the bootstrapper. It ensures that
the system is in the proper state to build Firefox by installing
required packages.

This was tested with a fresh install of OS X 10.8. Basic support for OS
X 10.6 and 10.7 is implemented, but not thorougly tested.
This commit is contained in:
Gregory Szorc 2012-09-12 21:29:20 -07:00
Родитель a273d2611c
Коммит a737815069
3 изменённых файлов: 220 добавлений и 1 удалений

Просмотреть файл

@ -2,6 +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/.
import os
class BaseBootstrapper(object):
"""Base class for system bootstrappers."""
def __init__(self):
@ -10,3 +12,15 @@ class BaseBootstrapper(object):
def install_system_packages(self):
raise NotImplemented('%s must implement install_system_packages()' %
__name__)
def which(self, name):
"""Python implementation of which.
It returns the path of an executable or None if it couldn't be found.
"""
for path in os.environ['PATH'].split(os.pathsep):
test = os.path.join(path, name)
if os.path.exists(test) and os.access(test, os.X_OK):
return test
return None

Просмотреть файл

@ -2,6 +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
import platform
import sys
@ -12,6 +14,18 @@ from mozboot.osx import OSXBootstrapper
from mozboot.ubuntu import UbuntuBootstrapper
FINISHED = '''
Your system should be ready to build Firefox! If you have not already,
obtain a copy of the source code by running:
hg clone https://hg.mozilla.org/mozilla-central
Or, if you prefer Git:
git clone git://github.com/mozilla/mozilla-central.git
'''
class Bootstrapper(object):
"""Main class that performs system bootstrap."""
@ -52,3 +66,5 @@ class Bootstrapper(object):
instance = cls(**args)
instance.install_system_packages()
print(FINISHED)

Просмотреть файл

@ -2,8 +2,89 @@
# 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
import os
import re
import subprocess
import sys
import tempfile
import urllib2
from distutils.version import StrictVersion
from mozboot.base import BaseBootstrapper
HOMEBREW_BOOTSTRAP = 'http://raw.github.com/mxcl/homebrew/go'
XCODE_APP_STORE = 'macappstore://itunes.apple.com/app/id497799835?mt=12'
XCODE_LEGACY = 'https://developer.apple.com/downloads/download.action?path=Developer_Tools/xcode_3.2.6_and_ios_sdk_4.3__final/xcode_3.2.6_and_ios_sdk_4.3.dmg'
HOMEBREW_AUTOCONF213 = 'https://raw.github.com/Homebrew/homebrew-versions/master/autoconf213.rb'
RE_CLANG_VERSION = re.compile('Apple clang version (\d+\.\d+)')
APPLE_CLANG_MINIMUM_VERSION = StrictVersion('4.0')
XCODE_REQUIRED = '''
Xcode is required to build Firefox. Please complete the install of Xcode
through the App Store.
'''
XCODE_REQUIRED_LEGACY = '''
You will need to download nad install Xcode to build Firefox.
Please complete the Xcode download and then relaunch this script.
'''
XCODE_COMMAND_LINE_TOOLS_MISSING = '''
The Xcode command line tools are required to build Firefox.
'''
INSTALL_XCODE_COMMAND_LINE_TOOLS_STEPS = '''
Perform the following steps to install the Xcode command line tools:
1) Open Xcode.app
2) Click through any first-run prompts
3) From the main Xcode menu, select Preferences (Command ,)
4) Go to the Download tab (near the right)
5) Install the "Command Line Tools"
When that has finished installing, please relaunch this script.
'''
UPGRADE_XCODE_COMMAND_LINE_TOOLS = '''
An old version of the Xcode command line tools is installed. You will need to
install a newer version in order to compile Firefox.
'''
HOMEBREW_INSTALL = '''
We will install the Homebrew package manager to install required packages.
You will be prompted to install Homebrew with its default settings. If you
would prefer to do this manually, hit CTRL+c, install Homebrew yourself, ensure
"brew" is in your $PATH, and relaunch bootstrap.
'''
HOMEBREW_XQUARTZ = '''
Homebrew needs XQuartz installed in order to build some dependencies. Please
download and install XQuartz from the following URL:
http://xquartz.macosforge.org/downloads/SL/XQuartz-2.7.3.dmg\
When that has finished, please relaunch bootstrap.
'''
HOMEBREW_PACKAGES = '''
We are now installing all required packages via Homebrew. You will see a lot of
output as packages are built.
'''
HOMEBREW_OLD_CLANG = '''
We require a newer compiler than what is provided by your version of Xcode.
We will install a modern version of Clang through Homebrew.
'''
class OSXBootstrapper(BaseBootstrapper):
def __init__(self, major, minor, point):
BaseBootstrapper.__init__(self)
@ -11,7 +92,115 @@ class OSXBootstrapper(BaseBootstrapper):
if major == 10 and minor < 6:
raise Exception('OS X 10.6 or above is required.')
self.os_version = minor
def install_system_packages(self):
raise NotImplementedError('OS X bootstrap not yet implemented.')
self.ensure_xcode()
self.ensure_homebrew()
self.ensure_homebrew_packages()
def ensure_xcode(self):
if self.os_version < 7:
if not os.path.exists('/Developer/Applications/Xcode.app'):
print(XCODE_REQUIRED_LEGACY)
subprocess.check_call(['open', XCODE_LEGACY])
sys.exit(1)
elif self.os_version >= 7:
if not os.path.exists('/Applications/Xcode.app'):
print(XCODE_REQUIRED)
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'],
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'])
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)
print(INSTALL_XCODE_COMMAND_LINE_TOOLS_STEPS)
sys.exit(1)
def ensure_homebrew(self):
if self.which('brew') is not None:
return
print(HOMEBREW_INSTALL)
bootstrap = urllib2.urlopen(url=HOMEBREW_BOOTSTRAP, timeout=20).read()
with tempfile.NamedTemporaryFile() as tf:
tf.write(bootstrap)
tf.flush()
subprocess.check_call(['ruby', tf.name])
def ensure_xquartz(self):
if os.path.exists('/Applications/Utilities/XQuartz.app'):
return
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()
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).
('python', 'python'),
('mercurial', 'mercurial'),
('git', 'git'),
('yasm', 'yasm'),
('autoconf213', HOMEBREW_AUTOCONF213),
]
printed = False
for name, package in packages:
if name in installed:
continue
if not printed:
print(HOMEBREW_PACKAGES)
printed = True
subprocess.check_call([brew, '-v', 'install', package])
if self.os_version < 7 and 'llvm' not in installed:
print(HOMEBREW_OLD_CLANG)
subprocess.check_call([brew, '-v' 'install', 'llvm',
'--with-clang', '--all-targets'])