This script runs swarming_xcode_install on the bots.  It should be run when 
we need to upgrade all the swarming testers.  It:
  1) Packages two python files into an isolate.
  2) Runs the isolate on swarming machines that satisfy certain dimensions.

This version will remove Xcode9-b4 and replace it with Xcode 9.

Bug: 
Change-Id: Ia86f4d963b43af175445da428be8920899e7e05e
Reviewed-on: https://chromium-review.googlesource.com/641379
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Reviewed-by: Erik Chen <erikchen@chromium.org>
Reviewed-by: Sergey Berezin <sergeyberezin@chromium.org>
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#502238}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: ae7265ca4bbe7bce5d1f13d8856ec06513883813
This commit is contained in:
Justin Cohen 2017-09-15 13:17:50 +00:00 коммит произвёл Commit Bot
Родитель 37e2f9c9d3
Коммит 8ecbba65cf
3 изменённых файлов: 148 добавлений и 12 удалений

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

@ -129,7 +129,7 @@ def LoadPlist(path):
os.unlink(name)
def FinalizeUnpack(target_os):
def FinalizeUnpack(output_dir, target_os):
"""Use xcodebuild to accept new toolchain license and run first launch
installers if necessary. Don't accept the license if a newer license has
already been accepted. This only works if xcodebuild and xcode-select are
@ -137,9 +137,8 @@ def FinalizeUnpack(target_os):
# Check old license
try:
target_license_plist_path = \
os.path.join(TOOLCHAIN_BUILD_DIR % target_os,
*['Contents','Resources','LicenseInfo.plist'])
target_license_plist_path = os.path.join(
output_dir, 'Contents','Resources','LicenseInfo.plist')
target_license_plist = LoadPlist(target_license_plist_path)
build_type = target_license_plist['licenseType']
build_version = target_license_plist['licenseID']
@ -162,16 +161,14 @@ def FinalizeUnpack(target_os):
pass
print "Accepting license."
target_version_plist_path = \
os.path.join(TOOLCHAIN_BUILD_DIR % target_os,
*['Contents','version.plist'])
target_version_plist_path = os.path.join(
output_dir, 'Contents','version.plist')
target_version_plist = LoadPlist(target_version_plist_path)
short_version_string = target_version_plist['CFBundleShortVersionString']
old_path = subprocess.Popen(['/usr/bin/xcode-select', '-p'],
stdout=subprocess.PIPE).communicate()[0].strip()
try:
build_dir = os.path.join(
TOOLCHAIN_BUILD_DIR % target_os, 'Contents/Developer')
build_dir = os.path.join(output_dir, 'Contents/Developer')
subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', build_dir])
subprocess.check_call(['sudo', '/usr/bin/xcodebuild', '-license', 'accept'])
@ -219,9 +216,10 @@ def DownloadHermeticBuild(target_os, toolchain_version, toolchain_filename):
print 'Using local toolchain for %s.' % target_os
return 0
toolchain_output_path = TOOLCHAIN_BUILD_DIR % target_os
if ReadStampFile(target_os) == toolchain_version:
print 'Toolchain (%s) is already up to date.' % toolchain_version
FinalizeUnpack(target_os)
FinalizeUnpack(toolchain_output_path, target_os)
return 0
if not CanAccessToolchainBucket():
@ -238,8 +236,8 @@ def DownloadHermeticBuild(target_os, toolchain_version, toolchain_filename):
try:
toolchain_file = toolchain_filename % toolchain_version
toolchain_full_url = TOOLCHAIN_URL + toolchain_file
DownloadAndUnpack(toolchain_full_url, TOOLCHAIN_BUILD_DIR % target_os)
FinalizeUnpack(target_os)
DownloadAndUnpack(toolchain_full_url, toolchain_output_path)
FinalizeUnpack(toolchain_output_path, target_os)
print 'Toolchain %s unpacked.' % toolchain_version
WriteStampFile(target_os, toolchain_version)

74
run_swarming_xcode_install.py Executable file
Просмотреть файл

@ -0,0 +1,74 @@
#!/usr/bin/env python
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
This script runs swarming_xcode_install on the bots. It should be run when we
need to upgrade all the swarming testers. It:
1) Packages two python files into an isolate.
2) Runs the isolate on swarming machines that satisfy certain dimensions.
Example usage:
$ ./build/run_swarming_xcode_install.py --luci_path ~/work/luci-py \
--swarming-server touch-swarming.appspot.com \
--isolate-server touch-isolate.appspot.com
"""
import argparse
import os
import shutil
import subprocess
import sys
import tempfile
def main():
parser = argparse.ArgumentParser(
description='Run swarming_xcode_install on the bots.')
parser.add_argument('--luci_path', required=True, type=os.path.abspath)
parser.add_argument('--swarming-server', required=True, type=str)
parser.add_argument('--isolate-server', required=True, type=str)
parser.add_argument('--batches', type=int, default=25,
help="Run xcode install in batches of size |batches|.")
args = parser.parse_args()
script_dir = os.path.dirname(os.path.abspath(__file__))
tmp_dir = tempfile.mkdtemp(prefix='swarming_xcode')
try:
print 'Making isolate.'
shutil.copyfile(os.path.join(script_dir, 'swarming_xcode_install.py'),
os.path.join(tmp_dir, 'swarming_xcode_install.py'))
shutil.copyfile(os.path.join(script_dir, 'mac_toolchain.py'),
os.path.join(tmp_dir, 'mac_toolchain.py'))
luci_client = os.path.join(args.luci_path, 'client')
cmd = [
sys.executable, os.path.join(luci_client, 'isolateserver.py'), 'archive',
'-I', args.isolate_server, tmp_dir,
]
isolate_hash = subprocess.check_output(cmd).split()[0]
print 'Running swarming_xcode_install.'
# TODO(crbug.com/765361): The dimensions below should be updated once
# swarming for iOS is fleshed out, likely removing xcode_version 9 and
# adding different dimensions.
luci_tools = os.path.join(luci_client, 'tools')
cmd = [
sys.executable, os.path.join(luci_tools, 'run_on_bots.py'),
'--swarming', args.swarming_server, '--isolate-server',
args.isolate_server, '--priority', '20', '--dimension', 'pool',
'Chrome', '--dimension', 'xcode_version', '9.0', '--batches',
args.batches, '--name', 'run_swarming_xcode_install', '--', isolate_hash,
'python', 'swarming_xcode_install.py',
]
subprocess.check_call(cmd)
print 'All tasks completed.'
finally:
shutil.rmtree(tmp_dir)
return 0
if __name__ == '__main__':
sys.exit(main())

64
swarming_xcode_install.py Executable file
Просмотреть файл

@ -0,0 +1,64 @@
#!/usr/bin/env python
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Script used to install Xcode on the swarming bots.
"""
import os
import shutil
import subprocess
import sys
import tarfile
import tempfile
import mac_toolchain
VERSION = '9A235'
URL = 'gs://chrome-mac-sdk/ios-toolchain-9A235-1.tgz'
REMOVE_DIR = '/Applications/Xcode9.0-Beta4.app/'
OUTPUT_DIR = '/Applications/Xcode9.0.app/'
def main():
# Check if it's already installed.
if os.path.exists(OUTPUT_DIR):
env = os.environ.copy()
env['DEVELOPER_DIR'] = OUTPUT_DIR
cmd = ['xcodebuild', '-version']
found_version = \
subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE).communicate()[0]
if VERSION in found_version:
print "Xcode %s already installed" % VERSION
sys.exit(0)
# Confirm old dir is there first.
if not os.path.exists(REMOVE_DIR):
print "Failing early since %s isn't there." % REMOVE_DIR
sys.exit(1)
# Download Xcode.
with tempfile.NamedTemporaryFile() as temp:
env = os.environ.copy()
env['PATH'] += ":/b/depot_tools"
subprocess.check_call(['gsutil.py', 'cp', URL, temp.name], env=env)
if os.path.exists(OUTPUT_DIR):
shutil.rmtree(OUTPUT_DIR)
if not os.path.exists(OUTPUT_DIR):
os.makedirs(OUTPUT_DIR)
tarfile.open(mode='r:gz', name=temp.name).extractall(path=OUTPUT_DIR)
# Accept license, call runFirstLaunch.
mac_toolchain.FinalizeUnpack(OUTPUT_DIR, 'ios')
# Set new Xcode as default.
subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', OUTPUT_DIR])
if os.path.exists(REMOVE_DIR):
shutil.rmtree(REMOVE_DIR)
if __name__ == '__main__':
sys.exit(main())