Allow using the same checkout to build both iOS and macOS.
As it is possible to specify multiple value for target_os in .gclient, update the script build/mac_toolchain.py to download the file for the hermetic build on all those OSes. Change the path where the hermetic files are downloaded to use different path for each OS. BUG=680069 Review-Url: https://codereview.chromium.org/2626063002 Cr-Original-Commit-Position: refs/heads/master@{#443198} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: aacc2845873563b3361c0c9b2a7bec6ead4cd155
This commit is contained in:
Родитель
7607e3c996
Коммит
33c60b2baa
|
@ -40,34 +40,34 @@ REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|||
GCLIENT_CONFIG = os.path.join(os.path.dirname(REPO_ROOT), '.gclient')
|
||||
|
||||
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_BUILD_DIR = os.path.join(BASE_DIR, '%s_files', 'Xcode.app')
|
||||
STAMP_FILE = os.path.join(BASE_DIR, '%s_files', 'toolchain_build_revision')
|
||||
TOOLCHAIN_URL = 'gs://chrome-mac-sdk/'
|
||||
|
||||
def IsIOSPlatform():
|
||||
def GetPlatforms():
|
||||
default_target_os = ["mac"]
|
||||
try:
|
||||
env = {}
|
||||
execfile(GCLIENT_CONFIG, env, env)
|
||||
if 'ios' in env.get('target_os', []):
|
||||
return True
|
||||
return env.get('target_os', default_target_os)
|
||||
except:
|
||||
pass
|
||||
return False
|
||||
return default_target_os
|
||||
|
||||
|
||||
def ReadStampFile():
|
||||
def ReadStampFile(target_os):
|
||||
"""Return the contents of the stamp file, or '' if it doesn't exist."""
|
||||
try:
|
||||
with open(STAMP_FILE, 'r') as f:
|
||||
with open(STAMP_FILE % target_os, 'r') as f:
|
||||
return f.read().rstrip()
|
||||
except IOError:
|
||||
return ''
|
||||
|
||||
|
||||
def WriteStampFile(s):
|
||||
def WriteStampFile(target_os, s):
|
||||
"""Write s to the stamp file."""
|
||||
EnsureDirExists(os.path.dirname(STAMP_FILE))
|
||||
with open(STAMP_FILE, 'w') as f:
|
||||
EnsureDirExists(os.path.dirname(STAMP_FILE % target_os))
|
||||
with open(STAMP_FILE % target_os, 'w') as f:
|
||||
f.write(s)
|
||||
f.write('\n')
|
||||
|
||||
|
@ -101,6 +101,7 @@ def CanAccessToolchainBucket():
|
|||
proc.communicate()
|
||||
return proc.returncode == 0
|
||||
|
||||
|
||||
def LoadPlist(path):
|
||||
"""Loads Plist at |path| and returns it as a dictionary."""
|
||||
fd, name = tempfile.mkstemp()
|
||||
|
@ -112,7 +113,7 @@ def LoadPlist(path):
|
|||
os.unlink(name)
|
||||
|
||||
|
||||
def AcceptLicense():
|
||||
def AcceptLicense(target_os):
|
||||
"""Use xcodebuild to accept new toolchain license if necessary. Don't accept
|
||||
the license if a newer license has already been accepted. This only works if
|
||||
xcodebuild and xcode-select are passwordless in sudoers."""
|
||||
|
@ -120,7 +121,7 @@ def AcceptLicense():
|
|||
# Check old license
|
||||
try:
|
||||
target_license_plist_path = \
|
||||
os.path.join(TOOLCHAIN_BUILD_DIR,
|
||||
os.path.join(TOOLCHAIN_BUILD_DIR % target_os,
|
||||
*['Contents','Resources','LicenseInfo.plist'])
|
||||
target_license_plist = LoadPlist(target_license_plist_path)
|
||||
build_type = target_license_plist['licenseType']
|
||||
|
@ -147,17 +148,17 @@ def AcceptLicense():
|
|||
old_path = subprocess.Popen(['/usr/bin/xcode-select', '-p'],
|
||||
stdout=subprocess.PIPE).communicate()[0].strip()
|
||||
try:
|
||||
build_dir = os.path.join(TOOLCHAIN_BUILD_DIR, 'Contents/Developer')
|
||||
build_dir = os.path.join(
|
||||
TOOLCHAIN_BUILD_DIR % target_os, 'Contents/Developer')
|
||||
subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', build_dir])
|
||||
subprocess.check_call(['sudo', '/usr/bin/xcodebuild', '-license', 'accept'])
|
||||
finally:
|
||||
subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', old_path])
|
||||
|
||||
|
||||
def _UseHermeticToolchain():
|
||||
def _UseHermeticToolchain(target_os):
|
||||
current_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
script_path = os.path.join(current_dir, 'mac/should_use_hermetic_xcode.py')
|
||||
target_os = 'ios' if IsIOSPlatform() else 'mac'
|
||||
proc = subprocess.Popen([script_path, target_os], stdout=subprocess.PIPE)
|
||||
return '1' in proc.stdout.readline()
|
||||
|
||||
|
@ -186,27 +187,17 @@ def RequestGsAuthentication():
|
|||
sys.exit(1)
|
||||
|
||||
|
||||
def main():
|
||||
if sys.platform != 'darwin':
|
||||
def DownloadHermeticBuild(target_os, default_version, toolchain_filename):
|
||||
if not _UseHermeticToolchain(target_os):
|
||||
print 'Using local toolchain for %s.' % target_os
|
||||
return 0
|
||||
|
||||
if not _UseHermeticToolchain():
|
||||
print 'Using local toolchain.'
|
||||
return 0
|
||||
|
||||
if IsIOSPlatform():
|
||||
default_version = IOS_TOOLCHAIN_VERSION
|
||||
toolchain_filename = 'ios-toolchain-%s.tgz'
|
||||
else:
|
||||
default_version = MAC_TOOLCHAIN_VERSION
|
||||
toolchain_filename = 'toolchain-%s.tgz'
|
||||
|
||||
toolchain_version = os.environ.get('MAC_TOOLCHAIN_REVISION',
|
||||
default_version)
|
||||
|
||||
if ReadStampFile() == toolchain_version:
|
||||
if ReadStampFile(target_os) == toolchain_version:
|
||||
print 'Toolchain (%s) is already up to date.' % toolchain_version
|
||||
AcceptLicense()
|
||||
AcceptLicense(target_os)
|
||||
return 0
|
||||
|
||||
if not CanAccessToolchainBucket():
|
||||
|
@ -214,7 +205,7 @@ def main():
|
|||
return 1
|
||||
|
||||
# Reset the stamp file in case the build is unsuccessful.
|
||||
WriteStampFile('')
|
||||
WriteStampFile(target_os, '')
|
||||
|
||||
toolchain_file = '%s.tgz' % toolchain_version
|
||||
toolchain_full_url = TOOLCHAIN_URL + toolchain_file
|
||||
|
@ -223,11 +214,11 @@ def main():
|
|||
try:
|
||||
toolchain_file = toolchain_filename % toolchain_version
|
||||
toolchain_full_url = TOOLCHAIN_URL + toolchain_file
|
||||
DownloadAndUnpack(toolchain_full_url, TOOLCHAIN_BUILD_DIR)
|
||||
AcceptLicense()
|
||||
DownloadAndUnpack(toolchain_full_url, TOOLCHAIN_BUILD_DIR % target_os)
|
||||
AcceptLicense(target_os)
|
||||
|
||||
print 'Toolchain %s unpacked.' % toolchain_version
|
||||
WriteStampFile(toolchain_version)
|
||||
WriteStampFile(target_os, toolchain_version)
|
||||
return 0
|
||||
except Exception as e:
|
||||
print 'Failed to download toolchain %s.' % toolchain_file
|
||||
|
@ -235,5 +226,26 @@ def main():
|
|||
print 'Exiting.'
|
||||
return 1
|
||||
|
||||
|
||||
def main():
|
||||
if sys.platform != 'darwin':
|
||||
return 0
|
||||
|
||||
for target_os in GetPlatforms():
|
||||
if target_os == 'ios':
|
||||
default_version = IOS_TOOLCHAIN_VERSION
|
||||
toolchain_filename = 'ios-toolchain-%s.tgz'
|
||||
else:
|
||||
default_version = MAC_TOOLCHAIN_VERSION
|
||||
toolchain_filename = 'toolchain-%s.tgz'
|
||||
|
||||
return_value = DownloadHermeticBuild(
|
||||
target_os, default_version, toolchain_filename)
|
||||
if return_value:
|
||||
return return_value
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
|
|
|
@ -45,7 +45,7 @@ declare_args() {
|
|||
# The path to the hermetic install of Xcode. Only relevant when
|
||||
# use_system_xcode = false.
|
||||
hermetic_xcode_path =
|
||||
rebase_path("//build/mac_files/Xcode.app", "", root_build_dir)
|
||||
rebase_path("//build/${target_os}_files/Xcode.app", "", root_build_dir)
|
||||
|
||||
declare_args() {
|
||||
if (is_clang) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче