OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 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 |
| 4 # found in the LICENSE file. |
| 5 |
| 6 # Script to install a Debian Wheezy sysroot for making official Google Chrome |
| 7 # Linux builds. |
| 8 # The sysroot is needed to make Chrome work for Debian Wheezy. |
| 9 # This script can be run manually but is more often run as part of gclient |
| 10 # hooks. When run from hooks this script should be a no-op on non-linux |
| 11 # platforms. |
| 12 |
| 13 # The sysroot image could be constructed from scratch based on the current |
| 14 # state or Debian Wheezy but for consistency we currently use a pre-built root |
| 15 # image. The image will normally need to be rebuilt every time chrome's build |
| 16 # dependancies are changed. |
| 17 |
| 18 import hashlib |
| 19 import platform |
| 20 import optparse |
| 21 import os |
| 22 import re |
| 23 import shutil |
| 24 import subprocess |
| 25 import sys |
| 26 |
| 27 |
| 28 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 29 URL_PREFIX = 'http://storage.googleapis.com' |
| 30 URL_PATH = 'chrome-linux-sysroot/toolchain' |
| 31 REVISION_AMD64 = 'a2d45701cb21244b9514e420950ba6ba687fb655' |
| 32 REVISION_ARM = 'a2d45701cb21244b9514e420950ba6ba687fb655' |
| 33 REVISION_I386 = 'a2d45701cb21244b9514e420950ba6ba687fb655' |
| 34 REVISION_MIPS = '7749d2957387abf225b6d45154c3ddad142148dc' |
| 35 TARBALL_AMD64 = 'debian_wheezy_amd64_sysroot.tgz' |
| 36 TARBALL_ARM = 'debian_wheezy_arm_sysroot.tgz' |
| 37 TARBALL_I386 = 'debian_wheezy_i386_sysroot.tgz' |
| 38 TARBALL_MIPS = 'debian_wheezy_mips_sysroot.tgz' |
| 39 TARBALL_AMD64_SHA1SUM = '601216c0f980e798e7131635f3dd8171b3dcbcde' |
| 40 TARBALL_ARM_SHA1SUM = '6289593b36616526562a4d85ae9c92b694b8ce7e' |
| 41 TARBALL_I386_SHA1SUM = '0090e5a4b56ab9ffb5d557da6a520195ab59b446' |
| 42 TARBALL_MIPS_SHA1SUM = '3b4d782a237db4aac185a638572a7747c1a21825' |
| 43 SYSROOT_DIR_AMD64 = 'debian_wheezy_amd64-sysroot' |
| 44 SYSROOT_DIR_ARM = 'debian_wheezy_arm-sysroot' |
| 45 SYSROOT_DIR_I386 = 'debian_wheezy_i386-sysroot' |
| 46 SYSROOT_DIR_MIPS = 'debian_wheezy_mips-sysroot' |
| 47 |
| 48 valid_archs = ('arm', 'i386', 'amd64', 'mips') |
| 49 |
| 50 |
| 51 def GetSha1(filename): |
| 52 sha1 = hashlib.sha1() |
| 53 with open(filename, 'rb') as f: |
| 54 while True: |
| 55 # Read in 1mb chunks, so it doesn't all have to be loaded into memory. |
| 56 chunk = f.read(1024*1024) |
| 57 if not chunk: |
| 58 break |
| 59 sha1.update(chunk) |
| 60 return sha1.hexdigest() |
| 61 |
| 62 |
| 63 def DetectArch(gyp_defines): |
| 64 # Check for optional target_arch and only install for that architecture. |
| 65 # If target_arch is not specified, then only install for the host |
| 66 # architecture. |
| 67 if 'target_arch=x64' in gyp_defines: |
| 68 return 'amd64' |
| 69 elif 'target_arch=ia32' in gyp_defines: |
| 70 return 'i386' |
| 71 elif 'target_arch=arm' in gyp_defines: |
| 72 return 'arm' |
| 73 elif 'target_arch=mipsel' in gyp_defines: |
| 74 return 'mips' |
| 75 |
| 76 # Figure out host arch using build/detect_host_arch.py and |
| 77 # set target_arch to host arch |
| 78 build_dir = os.path.dirname(os.path.dirname(os.path.join(SCRIPT_DIR))) |
| 79 sys.path.append(build_dir) |
| 80 import detect_host_arch |
| 81 |
| 82 detected_host_arch = detect_host_arch.HostArch() |
| 83 if detected_host_arch == 'x64': |
| 84 return 'amd64' |
| 85 elif detected_host_arch == 'ia32': |
| 86 return 'i386' |
| 87 elif detected_host_arch == 'arm': |
| 88 return 'arm' |
| 89 elif detected_host_arch == 'mips': |
| 90 return 'mips' |
| 91 else: |
| 92 print "Unknown host arch: %s" % detected_host_arch |
| 93 |
| 94 return None |
| 95 |
| 96 |
| 97 def main(): |
| 98 if options.running_as_hook and not sys.platform.startswith('linux'): |
| 99 return 0 |
| 100 |
| 101 gyp_defines = os.environ.get('GYP_DEFINES', '') |
| 102 |
| 103 if options.arch: |
| 104 target_arch = options.arch |
| 105 else: |
| 106 target_arch = DetectArch(gyp_defines) |
| 107 if not target_arch: |
| 108 print 'Unable to detect host architecture' |
| 109 return 1 |
| 110 |
| 111 if options.running_as_hook and target_arch != 'arm' and target_arch != 'mips': |
| 112 # When run from runhooks, only install the sysroot for an Official Chrome |
| 113 # Linux build, except on ARM where we always use a sysroot. |
| 114 skip_if_defined = ['branding=Chrome', 'buildtype=Official'] |
| 115 skip_if_undefined = ['chromeos=1'] |
| 116 for option in skip_if_defined: |
| 117 if option not in gyp_defines: |
| 118 return 0 |
| 119 for option in skip_if_undefined: |
| 120 if option in gyp_defines: |
| 121 return 0 |
| 122 |
| 123 # The sysroot directory should match the one specified in build/common.gypi. |
| 124 # TODO(thestig) Consider putting this else where to avoid having to recreate |
| 125 # it on every build. |
| 126 linux_dir = os.path.dirname(SCRIPT_DIR) |
| 127 if target_arch == 'amd64': |
| 128 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64) |
| 129 tarball_filename = TARBALL_AMD64 |
| 130 tarball_sha1sum = TARBALL_AMD64_SHA1SUM |
| 131 revision = REVISION_AMD64 |
| 132 elif target_arch == 'arm': |
| 133 sysroot = os.path.join(linux_dir, SYSROOT_DIR_ARM) |
| 134 tarball_filename = TARBALL_ARM |
| 135 tarball_sha1sum = TARBALL_ARM_SHA1SUM |
| 136 revision = REVISION_ARM |
| 137 elif target_arch == 'i386': |
| 138 sysroot = os.path.join(linux_dir, SYSROOT_DIR_I386) |
| 139 tarball_filename = TARBALL_I386 |
| 140 tarball_sha1sum = TARBALL_I386_SHA1SUM |
| 141 revision = REVISION_I386 |
| 142 elif target_arch == 'mips': |
| 143 sysroot = os.path.join(linux_dir, SYSROOT_DIR_MIPS) |
| 144 tarball_filename = TARBALL_MIPS |
| 145 tarball_sha1sum = TARBALL_MIPS_SHA1SUM |
| 146 revision = REVISION_MIPS |
| 147 else: |
| 148 print 'Unknown architecture: %s' % target_arch |
| 149 assert(False) |
| 150 |
| 151 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, revision, tarball_filename) |
| 152 |
| 153 stamp = os.path.join(sysroot, '.stamp') |
| 154 if os.path.exists(stamp): |
| 155 with open(stamp) as s: |
| 156 if s.read() == url: |
| 157 print 'Debian Wheezy %s root image already up-to-date: %s' % \ |
| 158 (target_arch, sysroot) |
| 159 return 0 |
| 160 |
| 161 print 'Installing Debian Wheezy %s root image: %s' % (target_arch, sysroot) |
| 162 if os.path.isdir(sysroot): |
| 163 shutil.rmtree(sysroot) |
| 164 os.mkdir(sysroot) |
| 165 tarball = os.path.join(sysroot, tarball_filename) |
| 166 print 'Downloading %s' % url |
| 167 sys.stdout.flush() |
| 168 sys.stderr.flush() |
| 169 subprocess.check_call(['curl', '--fail', '-L', url, '-o', tarball]) |
| 170 sha1sum = GetSha1(tarball) |
| 171 if sha1sum != tarball_sha1sum: |
| 172 print 'Tarball sha1sum is wrong.' |
| 173 print 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum) |
| 174 return 1 |
| 175 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot]) |
| 176 os.remove(tarball) |
| 177 |
| 178 with open(stamp, 'w') as s: |
| 179 s.write(url) |
| 180 return 0 |
| 181 |
| 182 |
| 183 if __name__ == '__main__': |
| 184 parser = optparse.OptionParser('usage: %prog [OPTIONS]') |
| 185 parser.add_option('--running-as-hook', action='store_true', |
| 186 default=False, help='Used when running from gclient hooks.' |
| 187 ' In this mode the sysroot will only ' |
| 188 'be installed for official Linux ' |
| 189 'builds or ARM Linux builds') |
| 190 parser.add_option('--arch', type='choice', choices=valid_archs, |
| 191 help='Sysroot architecture: %s' % ', '.join(valid_archs)) |
| 192 options, _ = parser.parse_args() |
| 193 sys.exit(main()) |
OLD | NEW |