Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. | 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Download necessary mac toolchain files under certain conditions. If | 6 """Download necessary mac toolchain files under certain conditions. If |
| 7 xcode-select is already set and points to an external folder | 7 xcode-select is already set and points to an external folder |
| 8 (e.g. /Application/Xcode.app), this script only runs if the GYP_DEFINE | 8 (e.g. /Application/Xcode.app), this script only runs if the GYP_DEFINE |
| 9 |force_mac_toolchain| is set. To override the values in | 9 |force_mac_toolchain| is set. To override the values in |
| 10 |TOOLCHAIN_REVISION|-|TOOLCHAIN_SUB_REVISION| below, GYP_DEFINE | 10 |TOOLCHAIN_REVISION|-|TOOLCHAIN_SUB_REVISION| below, GYP_DEFINE |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 """Loads Plist at |path| and returns it as a dictionary.""" | 102 """Loads Plist at |path| and returns it as a dictionary.""" |
| 103 fd, name = tempfile.mkstemp() | 103 fd, name = tempfile.mkstemp() |
| 104 try: | 104 try: |
| 105 subprocess.check_call(['plutil', '-convert', 'xml1', '-o', name, path]) | 105 subprocess.check_call(['plutil', '-convert', 'xml1', '-o', name, path]) |
| 106 with os.fdopen(fd, 'r') as f: | 106 with os.fdopen(fd, 'r') as f: |
| 107 return plistlib.readPlist(f) | 107 return plistlib.readPlist(f) |
| 108 finally: | 108 finally: |
| 109 os.unlink(name) | 109 os.unlink(name) |
| 110 | 110 |
| 111 | 111 |
| 112 def AcceptLicense(directory): | 112 def AcceptLicense(): |
|
justincohen
2016/05/11 13:52:21
and remove this.
| |
| 113 """Use xcodebuild to accept new toolchain license if necessary. Don't accept | 113 """Use xcodebuild to accept new toolchain license if necessary. Don't accept |
| 114 the license if a newer license has already been accepted. This only works if | 114 the license if a newer license has already been accepted. This only works if |
| 115 xcodebuild and xcode-select are passwordless in sudoers.""" | 115 xcodebuild and xcode-select are passwordless in sudoers.""" |
| 116 | 116 |
| 117 # Check old license | 117 # Check old license |
| 118 try: | 118 try: |
| 119 target_license_plist_path = \ | 119 target_license_plist_path = \ |
| 120 os.path.join(TOOLCHAIN_BUILD_DIR, | 120 os.path.join(TOOLCHAIN_BUILD_DIR, |
| 121 *['Contents','Resources','LicenseInfo.plist']) | 121 *['Contents','Resources','LicenseInfo.plist']) |
| 122 target_license_plist = LoadPlist(target_license_plist_path) | 122 target_license_plist = LoadPlist(target_license_plist_path) |
| 123 build_type = target_license_plist['licenseType'] | 123 build_type = target_license_plist['licenseType'] |
| 124 build_version = target_license_plist['licenseID'] | 124 build_version = target_license_plist['licenseID'] |
| 125 | 125 |
| 126 accepted_license_plist = LoadPlist( | 126 accepted_license_plist = LoadPlist( |
| 127 '/Library/Preferences/com.apple.dt.Xcode.plist') | 127 '/Library/Preferences/com.apple.dt.Xcode.plist') |
| 128 agreed_to_key = 'IDELast%sLicenseAgreedTo' % build_type | 128 agreed_to_key = 'IDELast%sLicenseAgreedTo' % build_type |
| 129 last_license_agreed_to = accepted_license_plist[agreed_to_key] | 129 last_license_agreed_to = accepted_license_plist[agreed_to_key] |
| 130 | 130 |
| 131 # Historically all Xcode build numbers have been in the format of AANNNN, so | 131 # Historically all Xcode build numbers have been in the format of AANNNN, so |
| 132 # a simple string compare works. If Xcode's build numbers change this may | 132 # a simple string compare works. If Xcode's build numbers change this may |
| 133 # need a more complex compare. | 133 # need a more complex compare. |
| 134 if build_version <= last_license_agreed_to: | 134 if build_version <= last_license_agreed_to: |
| 135 # Don't accept the license of older toolchain builds, this will break the | 135 # Don't accept the license of older toolchain builds, this will break the |
| 136 # license of newer builds. | 136 # license of newer builds. |
| 137 return | 137 return |
| 138 except (subprocess.CalledProcessError, KeyError) as e: | 138 except (subprocess.CalledProcessError, KeyError): |
| 139 # If there's never been a license of type |build_type| accepted, | 139 # If there's never been a license of type |build_type| accepted, |
| 140 # |target_license_plist_path| or |agreed_to_key| may not exist. | 140 # |target_license_plist_path| or |agreed_to_key| may not exist. |
| 141 pass | 141 pass |
| 142 | 142 |
| 143 print "Accepting license." | 143 print "Accepting license." |
| 144 old_path = subprocess.Popen(['/usr/bin/xcode-select', '-p'], | 144 old_path = subprocess.Popen(['/usr/bin/xcode-select', '-p'], |
| 145 stdout=subprocess.PIPE).communicate()[0].strip() | 145 stdout=subprocess.PIPE).communicate()[0].strip() |
| 146 try: | 146 try: |
| 147 build_dir = os.path.join(TOOLCHAIN_BUILD_DIR, 'Contents/Developer') | 147 build_dir = os.path.join(TOOLCHAIN_BUILD_DIR, 'Contents/Developer') |
| 148 subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', build_dir]) | 148 subprocess.check_call(['sudo', '/usr/bin/xcode-select', '-s', build_dir]) |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 169 | 169 |
| 170 # TODO(justincohen): Add support for GN per crbug.com/570091 | 170 # TODO(justincohen): Add support for GN per crbug.com/570091 |
| 171 if UseLocalMacSDK(): | 171 if UseLocalMacSDK(): |
| 172 print 'Using local toolchain.' | 172 print 'Using local toolchain.' |
| 173 return 0 | 173 return 0 |
| 174 | 174 |
| 175 toolchain_revision = os.environ.get('MAC_TOOLCHAIN_REVISION', | 175 toolchain_revision = os.environ.get('MAC_TOOLCHAIN_REVISION', |
| 176 TOOLCHAIN_VERSION) | 176 TOOLCHAIN_VERSION) |
| 177 if ReadStampFile() == toolchain_revision: | 177 if ReadStampFile() == toolchain_revision: |
| 178 print 'Toolchain (%s) is already up to date.' % toolchain_revision | 178 print 'Toolchain (%s) is already up to date.' % toolchain_revision |
| 179 AcceptLicense(TOOLCHAIN_BUILD_DIR) | 179 AcceptLicense(TOOLCHAIN_BUILD_DIR) |
|
justincohen
2016/05/11 13:52:21
probably makes more sense to remove the param.
tikuta
2016/05/12 02:02:33
Done.
| |
| 180 return 0 | 180 return 0 |
| 181 | 181 |
| 182 if not CanAccessToolchainBucket(): | 182 if not CanAccessToolchainBucket(): |
| 183 print 'Cannot access toolchain bucket.' | 183 print 'Cannot access toolchain bucket.' |
| 184 return 0 | 184 return 0 |
| 185 | 185 |
| 186 # Reset the stamp file in case the build is unsuccessful. | 186 # Reset the stamp file in case the build is unsuccessful. |
| 187 WriteStampFile('') | 187 WriteStampFile('') |
| 188 | 188 |
| 189 toolchain_file = '%s.tgz' % toolchain_revision | 189 toolchain_file = '%s.tgz' % toolchain_revision |
| 190 toolchain_full_url = TOOLCHAIN_URL + toolchain_file | 190 toolchain_full_url = TOOLCHAIN_URL + toolchain_file |
| 191 | 191 |
| 192 print 'Updating toolchain to %s...' % toolchain_revision | 192 print 'Updating toolchain to %s...' % toolchain_revision |
| 193 try: | 193 try: |
| 194 toolchain_file = 'toolchain-%s.tgz' % toolchain_revision | 194 toolchain_file = 'toolchain-%s.tgz' % toolchain_revision |
| 195 toolchain_full_url = TOOLCHAIN_URL + toolchain_file | 195 toolchain_full_url = TOOLCHAIN_URL + toolchain_file |
| 196 DownloadAndUnpack(toolchain_full_url, TOOLCHAIN_BUILD_DIR) | 196 DownloadAndUnpack(toolchain_full_url, TOOLCHAIN_BUILD_DIR) |
| 197 AcceptLicense(TOOLCHAIN_BUILD_DIR) | 197 AcceptLicense(TOOLCHAIN_BUILD_DIR) |
|
justincohen
2016/05/11 13:52:21
and here
tikuta
2016/05/12 02:02:33
Done.
| |
| 198 | 198 |
| 199 print 'Toolchain %s unpacked.' % toolchain_revision | 199 print 'Toolchain %s unpacked.' % toolchain_revision |
| 200 WriteStampFile(toolchain_revision) | 200 WriteStampFile(toolchain_revision) |
| 201 return 0 | 201 return 0 |
| 202 except: | 202 except Exception as e: |
| 203 print 'Failed to download toolchain %s.' % toolchain_file | 203 print 'Failed to download toolchain %s.' % toolchain_file |
| 204 print 'Exception %s' % e | |
| 204 print 'Exiting.' | 205 print 'Exiting.' |
| 205 return 1 | 206 return 1 |
| 206 | 207 |
| 207 if __name__ == '__main__': | 208 if __name__ == '__main__': |
| 208 sys.exit(main()) | 209 sys.exit(main()) |
| OLD | NEW |