Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 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 """Install Debian Wheezy sysroots for building chromium. | 6 """Install Debian Wheezy sysroots for building chromium. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 # The sysroot is needed to ensure that binaries will run on Debian Wheezy, | 9 # The sysroot is needed to ensure that binaries will run on Debian Wheezy, |
| 10 # the oldest supported linux distribution. This script can be run manually but | 10 # the oldest supported linux distribution. This script can be run manually but |
| 11 # is more often run as part of gclient hooks. When run from hooks this script | 11 # is more often run as part of gclient hooks. When run from hooks this script |
| 12 # in a no-op on non-linux platforms. | 12 # in a no-op on non-linux platforms. |
| 13 | 13 |
| 14 # The sysroot image could be constructed from scratch based on the current | 14 # The sysroot image could be constructed from scratch based on the current |
| 15 # state or Debian Wheezy but for consistency we currently use a pre-built root | 15 # state or Debian Wheezy but for consistency we currently use a pre-built root |
| 16 # image. The image will normally need to be rebuilt every time chrome's build | 16 # image. The image will normally need to be rebuilt every time chrome's build |
| 17 # dependencies are changed. | 17 # dependencies are changed. |
| 18 | 18 |
| 19 import hashlib | 19 import hashlib |
| 20 import platform | 20 import platform |
| 21 import optparse | 21 import optparse |
| 22 import os | 22 import os |
| 23 import re | 23 import re |
| 24 import shutil | 24 import shutil |
| 25 import subprocess | 25 import subprocess |
| 26 import sys | 26 import sys |
| 27 import time | |
| 27 | 28 |
| 28 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 29 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 29 sys.path.append(os.path.dirname(os.path.dirname(SCRIPT_DIR))) | 30 sys.path.append(os.path.dirname(os.path.dirname(SCRIPT_DIR))) |
| 30 import detect_host_arch | 31 import detect_host_arch |
| 31 import gyp_chromium | 32 import gyp_chromium |
| 32 import gyp_environment | 33 import gyp_environment |
| 33 | 34 |
| 34 | 35 |
| 35 URL_PREFIX = 'http://commondatastorage.googleapis.com' | 36 URL_PREFIX = 'http://commondatastorage.googleapis.com' |
| 36 URL_PATH = 'chrome-linux-sysroot/toolchain' | 37 URL_PATH = 'chrome-linux-sysroot/toolchain' |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 | 129 |
| 129 # Finally, if we can detect a non-standard target_arch such as ARM or | 130 # Finally, if we can detect a non-standard target_arch such as ARM or |
| 130 # MIPS, then install the sysroot too. | 131 # MIPS, then install the sysroot too. |
| 131 # Don't attampt to install arm64 since this is currently and android-only | 132 # Don't attampt to install arm64 since this is currently and android-only |
| 132 # architecture. | 133 # architecture. |
| 133 target_arch = DetectTargetArch() | 134 target_arch = DetectTargetArch() |
| 134 if target_arch and target_arch not in (host_arch, 'i386', 'arm64'): | 135 if target_arch and target_arch not in (host_arch, 'i386', 'arm64'): |
| 135 InstallSysroot(target_arch) | 136 InstallSysroot(target_arch) |
| 136 | 137 |
| 137 | 138 |
| 138 def main(): | 139 def main(args): |
| 140 parser = optparse.OptionParser('usage: %prog [OPTIONS]', description=__doc__) | |
| 141 parser.add_option('--running-as-hook', action='store_true', | |
| 142 default=False, help='Used when running from gclient hooks.' | |
| 143 ' Installs default sysroot images.') | |
| 144 parser.add_option('--arch', type='choice', choices=valid_archs, | |
| 145 help='Sysroot architecture: %s' % ', '.join(valid_archs)) | |
| 146 options, _ = parser.parse_args(args) | |
| 139 if options.running_as_hook and not sys.platform.startswith('linux'): | 147 if options.running_as_hook and not sys.platform.startswith('linux'): |
| 140 return 0 | 148 return 0 |
| 141 | 149 |
| 142 if options.running_as_hook: | 150 if options.running_as_hook: |
| 143 InstallDefaultSysroots() | 151 InstallDefaultSysroots() |
| 144 else: | 152 else: |
| 145 if not options.arch: | 153 if not options.arch: |
| 146 print 'You much specify either --arch or --running-as-hook' | 154 raise Error('You much specify either --arch or --running-as-hook') |
| 147 return 1 | |
| 148 InstallSysroot(options.arch) | 155 InstallSysroot(options.arch) |
| 149 | 156 |
| 150 return 0 | 157 return 0 |
| 151 | 158 |
| 152 | 159 |
| 160 def DownloadURL(url, filename): | |
| 161 print 'Downloading %s' % url | |
| 162 sys.stdout.flush() | |
| 163 sys.stderr.flush() | |
| 164 | |
| 165 # Re-try download in order to mitigate network falkiness. | |
|
Lei Zhang
2016/02/17 20:49:51
typo
| |
| 166 num_retries = 3 | |
| 167 retry_wait = 5 # Doubled at each retry. | |
| 168 cmd = ['curl', '--fail', '-L', url, '-o', filename] | |
| 169 while True: | |
| 170 rtn = subprocess.call(cmd) | |
| 171 if rtn == 0: | |
| 172 return | |
| 173 elif num_retries: | |
|
Lei Zhang
2016/02/17 20:49:51
no elif / else after a return.
| |
| 174 # Curl failed. Retry | |
| 175 print 'Retrying in %d s ...' % retry_wait | |
| 176 time.sleep(retry_wait) | |
| 177 num_retries -= 1 | |
| 178 retry_wait *= 2 | |
| 179 else: | |
| 180 raise Error('download command failed (%s): %s' % (rtn, cmd)) | |
|
Lei Zhang
2016/02/17 20:49:51
%s seems to work, but shouldn't it be %d since |rt
| |
| 181 | |
| 182 | |
| 153 def InstallSysroot(target_arch): | 183 def InstallSysroot(target_arch): |
| 154 # The sysroot directory should match the one specified in build/common.gypi. | 184 # The sysroot directory should match the one specified in build/common.gypi. |
| 155 # TODO(thestig) Consider putting this else where to avoid having to recreate | 185 # TODO(thestig) Consider putting this else where to avoid having to recreate |
| 156 # it on every build. | 186 # it on every build. |
| 157 linux_dir = os.path.dirname(SCRIPT_DIR) | 187 linux_dir = os.path.dirname(SCRIPT_DIR) |
| 158 if target_arch == 'amd64': | 188 if target_arch == 'amd64': |
| 159 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64) | 189 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64) |
| 160 tarball_filename = TARBALL_AMD64 | 190 tarball_filename = TARBALL_AMD64 |
| 161 tarball_sha1sum = TARBALL_AMD64_SHA1SUM | 191 tarball_sha1sum = TARBALL_AMD64_SHA1SUM |
| 162 revision = REVISION_AMD64 | 192 revision = REVISION_AMD64 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 186 if s.read() == url: | 216 if s.read() == url: |
| 187 print 'Debian Wheezy %s root image already up-to-date: %s' % \ | 217 print 'Debian Wheezy %s root image already up-to-date: %s' % \ |
| 188 (target_arch, sysroot) | 218 (target_arch, sysroot) |
| 189 return | 219 return |
| 190 | 220 |
| 191 print 'Installing Debian Wheezy %s root image: %s' % (target_arch, sysroot) | 221 print 'Installing Debian Wheezy %s root image: %s' % (target_arch, sysroot) |
| 192 if os.path.isdir(sysroot): | 222 if os.path.isdir(sysroot): |
| 193 shutil.rmtree(sysroot) | 223 shutil.rmtree(sysroot) |
| 194 os.mkdir(sysroot) | 224 os.mkdir(sysroot) |
| 195 tarball = os.path.join(sysroot, tarball_filename) | 225 tarball = os.path.join(sysroot, tarball_filename) |
| 196 print 'Downloading %s' % url | 226 DownloadURL(url, tarball) |
| 197 sys.stdout.flush() | |
| 198 sys.stderr.flush() | |
| 199 subprocess.check_call(['curl', '--fail', '-L', url, '-o', tarball]) | |
| 200 sha1sum = GetSha1(tarball) | 227 sha1sum = GetSha1(tarball) |
| 201 if sha1sum != tarball_sha1sum: | 228 if sha1sum != tarball_sha1sum: |
| 202 raise Error('Tarball sha1sum is wrong.' | 229 raise Error('Tarball sha1sum is wrong.' |
| 203 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum)) | 230 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum)) |
| 204 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot]) | 231 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot]) |
| 205 os.remove(tarball) | 232 os.remove(tarball) |
| 206 | 233 |
| 207 with open(stamp, 'w') as s: | 234 with open(stamp, 'w') as s: |
| 208 s.write(url) | 235 s.write(url) |
| 209 | 236 |
| 210 | 237 |
| 211 if __name__ == '__main__': | 238 if __name__ == '__main__': |
| 212 parser = optparse.OptionParser('usage: %prog [OPTIONS]', description=__doc__) | 239 try: |
| 213 parser.add_option('--running-as-hook', action='store_true', | 240 sys.exit(main(sys.argv[1:])) |
| 214 default=False, help='Used when running from gclient hooks.' | 241 except Error as e: |
| 215 ' Installs default sysroot images.') | 242 sys.stderr.write(str(e) + '\n') |
| 216 parser.add_option('--arch', type='choice', choices=valid_archs, | 243 sys.exit(1) |
| 217 help='Sysroot architecture: %s' % ', '.join(valid_archs)) | |
| 218 options, _ = parser.parse_args() | |
| 219 sys.exit(main()) | |
| OLD | NEW |