Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1244)

Unified Diff: build/mac_toolchain.py

Issue 1759793003: Scripts to upload and update the mac toolchain. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment typo Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « DEPS ('k') | build/package_mac_toolchain.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/mac_toolchain.py
diff --git a/build/mac_toolchain.py b/build/mac_toolchain.py
new file mode 100755
index 0000000000000000000000000000000000000000..b1591554c056ec5120ed8b72885ef2e9ddb0df17
--- /dev/null
+++ b/build/mac_toolchain.py
@@ -0,0 +1,154 @@
+#!/usr/bin/env python
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
Paweł Hajdan Jr. 2016/03/04 07:57:09 nit: 2016, no (c)
justincohen 2016/03/04 16:46:44 Done.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Download necessary mac toolchain files under certain conditions. If
+xcode-select is already set and points to an external folder
+(e.g. /Application/Xcode.app), this script only runs if the GYP_DEFINE
+|force_mac_toolchain| is set. To override the values in
+|TOOLCHAIN_REVISION|-|TOOLCHAIN_SUB_REVISION| below, GYP_DEFINE
+mac_toolchain_revision can be used instead.
+
+This script will only run on machines with the following programs added to a
+sudoers list:
+ /usr/bin/xcode-select
+ /usr/bin/xcodebuild
+
+Otherwise user input would be required to complete the script. Perhaps future
+versions can be modified to allow for user input on developer machines.
+"""
+
+import os
+import shutil
+import subprocess
+import sys
+import tarfile
+import time
+import tempfile
+import urllib2
+
+# Update sys.path to import gyp.
+script_dir = os.path.dirname(os.path.realpath(__file__))
+chrome_src = os.path.abspath(os.path.join(script_dir, os.pardir))
+sys.path.insert(0, os.path.join(chrome_src, 'tools', 'gyp', 'pylib'))
+import gyp
+
+# This can be changed after running /build/package_mac_toolchain.py.
+TOOLCHAIN_REVISION = '7C68'
+TOOLCHAIN_SUB_REVISION = 1
+TOOLCHAIN_VERSION = "%s-%s" % (TOOLCHAIN_REVISION, TOOLCHAIN_SUB_REVISION)
+
+BASE_DIR = os.path.abspath(os.path.dirname(__file__))
+TOOLCHAIN_BUILD_DIR = os.path.join(BASE_DIR, 'mac_files', 'Xcode.app')
+STAMP_FILE = os.path.join(BASE_DIR, 'mac_files', 'toolchain_build_revision')
+TOOLCHAIN_URL = 'gs://chrome-mac-sdk/'
+
+def ReadStampFile():
+ """Return the contents of the stamp file, or '' if it doesn't exist."""
+ try:
+ with open(STAMP_FILE, 'r') as f:
+ return f.read().rstrip()
+ except IOError:
+ return ''
+
+
+def WriteStampFile(s):
+ """Write s to the stamp file."""
+ EnsureDirExists(os.path.dirname(STAMP_FILE))
+ with open(STAMP_FILE, 'w') as f:
+ f.write(s)
+ f.write('\n')
+
+
+def EnsureDirExists(path):
+ if not os.path.exists(path):
+ os.makedirs(path)
+
+
+def DownloadAndUnpack(url, output_dir):
+ """Decompresses |url| into a cleared |output_dir|."""
+ temp_name = tempfile.mktemp(prefix='mac_toolchain')
+ print 'Downloading new toolchain.'
+ subprocess.check_call(['gsutil.py', 'cp', url, temp_name])
+ if os.path.exists(output_dir):
+ print 'Deleting old toolchain.'
+ shutil.rmtree(output_dir)
+ EnsureDirExists(output_dir)
+ print 'Unpacking new toolchain.'
+ tarfile.open(mode='r:gz', name=temp_name).extractall(path=output_dir)
+ os.unlink(temp_name)
Paweł Hajdan Jr. 2016/03/04 07:57:10 Shouldn't this be in try-finally?
justincohen 2016/03/04 16:46:44 Good catch, Done.
+
+
+def CanAccessToolchainBucket():
+ """Checks whether the user has access to |TOOLCHAIN_URL|."""
+ proc = subprocess.Popen(['gsutil.py', 'ls', TOOLCHAIN_URL],
+ stdout=subprocess.PIPE)
+ proc.communicate()
+ return proc.returncode == 0
+
+
+def SwitchToolchain(directory):
+ """Use xcode-select to select new toolchain and accept license. This only
+ works if both xcode-select and xcodebuild are in sudoers."""
+ print 'Setting xcode-select to %s.' % directory
+ subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', directory])
+ subprocess.check_call(['sudo', '/usr/bin/xcodebuild', '-license', 'accept'])
+
+
+def main():
+ gyp_defines = gyp.NameValueListToDict(gyp.ShlexEnv('GYP_DEFINES'))
+ force_pull = 'force_mac_toolchain' in gyp_defines
+ toolchain_revision = gyp_defines.get('mac_toolchain_revision',
+ TOOLCHAIN_VERSION)
+
+ # Don't update the toolchain if there's already one installed outside of the
+ # expected location for a Chromium mac toolchain, unless |force_pull| is set.
+ proc = subprocess.Popen(['xcode-select', '-p'], stdout=subprocess.PIPE)
+ xcode_select_dir = proc.communicate()[0]
+ rc = proc.returncode
+ if not force_pull and rc == 0 and TOOLCHAIN_BUILD_DIR not in xcode_select_dir:
+ print 'Using local toolchain.'
+ return 0
+
+ if ReadStampFile() == toolchain_revision:
+ print 'Toolchain (%s) is already up to date.' % toolchain_revision
+ SwitchToolchain(TOOLCHAIN_BUILD_DIR)
+ return 0
+
+ # This script cannot complete if xcode-select and xcodebuild are not in
+ # sudoers.
+ proc = subprocess.Popen(['sudo', '-l'], stdout=subprocess.PIPE)
+ output = proc.communicate()[0]
+ cmds = ['xcode-select', 'xcodebuild']
+ if not all(x in output for x in cmds):
+ print 'xcode-select and xcodebuild must be present in sudoers.'
+
+ if not CanAccessToolchainBucket():
+ print 'Cannot access toolchain bucket.'
+ return 0
+
+ # Reset the stamp file in case the build is unsuccessful.
+ WriteStampFile('')
+
+ toolchain_file = "%s.tgz" % toolchain_revision
+ toolchain_full_url = TOOLCHAIN_URL + toolchain_file
+
+ print 'Updating toolchain to %s...' % toolchain_revision
+ try:
+ toolchain_file = "toolchain-%s.tgz" % toolchain_revision
+ toolchain_full_url = TOOLCHAIN_URL + toolchain_file
+ DownloadAndUnpack(toolchain_full_url, TOOLCHAIN_BUILD_DIR)
+ SwitchToolchain(TOOLCHAIN_BUILD_DIR)
+
+ print 'Toolchain %s unpacked.' % toolchain_revision
+ WriteStampFile(toolchain_revision)
+
+ return 0
+ except:
+ print 'Failed to download toolchain %s.' % toolchain_file
+ print 'Exiting.'
Paweł Hajdan Jr. 2016/03/04 07:57:09 Whoa, that seems to totally hide what was the exce
+ return 1
+
+if __name__ == '__main__':
+ sys.exit(main())
« no previous file with comments | « DEPS ('k') | build/package_mac_toolchain.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698