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

Unified Diff: build/mac_toolchain.py

Issue 2626063002: Allow using the same checkout to build both iOS and macOS. (Closed)
Patch Set: Address nitpick. Created 3 years, 11 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 | « .gitignore ('k') | build/toolchain/toolchain.gni » ('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
index c0e5e7f5beb03dd2cd574bf00d90b94a36a7207a..c4de86f91e37c30c1447c5a46b44c65b70e1b2cd 100755
--- a/build/mac_toolchain.py
+++ b/build/mac_toolchain.py
@@ -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':
- return 0
-
- if not _UseHermeticToolchain():
- print 'Using local toolchain.'
+def DownloadHermeticBuild(target_os, default_version, toolchain_filename):
+ if not _UseHermeticToolchain(target_os):
+ print 'Using local toolchain for %s.' % target_os
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())
« no previous file with comments | « .gitignore ('k') | build/toolchain/toolchain.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698