| 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 sysroots for building chromium. | 6 """Install Debian 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. For ARM64 linux, we have Debian | 10 # the oldest supported linux distribution. For ARM64 linux, we have Debian |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 | 28 |
| 29 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 29 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 30 sys.path.append(os.path.dirname(os.path.dirname(SCRIPT_DIR))) | 30 sys.path.append(os.path.dirname(os.path.dirname(SCRIPT_DIR))) |
| 31 import detect_host_arch | 31 import detect_host_arch |
| 32 import gyp_chromium | 32 import gyp_chromium |
| 33 import gyp_environment | 33 import gyp_environment |
| 34 | 34 |
| 35 | 35 |
| 36 URL_PREFIX = 'https://commondatastorage.googleapis.com' | 36 URL_PREFIX = 'https://commondatastorage.googleapis.com' |
| 37 URL_PATH = 'chrome-linux-sysroot/toolchain' | 37 URL_PATH = 'chrome-linux-sysroot/toolchain' |
| 38 | 38 REVISION_AMD64 = '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba' |
| 39 SYSROOTS = { | 39 REVISION_ARM = '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba' |
| 40 ('Wheezy', 'amd64'): { | 40 REVISION_ARM64 = '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba' |
| 41 'Revision' : '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba', | 41 REVISION_I386 = '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba' |
| 42 'Tarball' : 'debian_wheezy_amd64_sysroot.tgz', | 42 REVISION_MIPS = '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba' |
| 43 'Sha1Sum' : 'a7f3df28b02799fbd7675c2ab24f1924c104c0ee', | 43 TARBALL_AMD64 = 'debian_wheezy_amd64_sysroot.tgz' |
| 44 'SysrootDir' : 'debian_wheezy_amd64-sysroot' | 44 TARBALL_ARM = 'debian_wheezy_arm_sysroot.tgz' |
| 45 }, | 45 TARBALL_ARM64 = 'debian_jessie_arm64_sysroot.tgz' |
| 46 ('Wheezy', 'arm'): { | 46 TARBALL_I386 = 'debian_wheezy_i386_sysroot.tgz' |
| 47 'Revision' : '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba', | 47 TARBALL_MIPS = 'debian_wheezy_mips_sysroot.tgz' |
| 48 'Tarball' : 'debian_wheezy_arm_sysroot.tgz', | 48 TARBALL_AMD64_SHA1SUM = 'a7f3df28b02799fbd7675c2ab24f1924c104c0ee' |
| 49 'Sha1Sum' : '2df01b8173a363977daf04e176b8c7dba5b0b933', | 49 TARBALL_ARM_SHA1SUM = '2df01b8173a363977daf04e176b8c7dba5b0b933' |
| 50 'SysrootDir' : 'debian_wheezy_arm-sysroot' | 50 TARBALL_ARM64_SHA1SUM = 'df9270e00c258e6cd80f8172b1bfa39aafc4756f' |
| 51 }, | 51 TARBALL_I386_SHA1SUM = 'e2c7131fa5f711de28c37fd9442e77d32abfb3ff' |
| 52 ('Wheezy', 'i386'): { | 52 TARBALL_MIPS_SHA1SUM = '22fe7b45b144691aeb515083025f0fceb131d724' |
| 53 'Revision' : '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba', | 53 SYSROOT_DIR_AMD64 = 'debian_wheezy_amd64-sysroot' |
| 54 'Tarball' : 'debian_wheezy_i386_sysroot.tgz', | 54 SYSROOT_DIR_ARM = 'debian_wheezy_arm-sysroot' |
| 55 'Sha1Sum' : 'e2c7131fa5f711de28c37fd9442e77d32abfb3ff', | 55 SYSROOT_DIR_ARM64 = 'debian_jessie_arm64-sysroot' |
| 56 'SysrootDir' : 'debian_wheezy_i386-sysroot' | 56 SYSROOT_DIR_I386 = 'debian_wheezy_i386-sysroot' |
| 57 }, | 57 SYSROOT_DIR_MIPS = 'debian_wheezy_mips-sysroot' |
| 58 ('Wheezy', 'mips'): { | |
| 59 'Revision' : '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba', | |
| 60 'Tarball' : 'debian_wheezy_mips_sysroot.tgz', | |
| 61 'Sha1Sum' : '22fe7b45b144691aeb515083025f0fceb131d724', | |
| 62 'SysrootDir' : 'debian_wheezy_mips-sysroot' | |
| 63 }, | |
| 64 ('Jessie', 'arm64'): { | |
| 65 'Revision' : '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba', | |
| 66 'Tarball' : 'debian_jessie_arm64_sysroot.tgz', | |
| 67 'Sha1Sum' : 'df9270e00c258e6cd80f8172b1bfa39aafc4756f', | |
| 68 'SysrootDir' : 'debian_jessie_arm64-sysroot' | |
| 69 }, | |
| 70 ('Precise', 'amd64'): { | |
| 71 'Revision' : '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba', | |
| 72 'Tarball' : 'ubuntu_precise_amd64_sysroot.tgz', | |
| 73 'Sha1Sum' : '67985675e64e1d3cf6574088f36f89092ae9e86b', | |
| 74 'SysrootDir' : 'ubuntu_precise_amd64-sysroot' | |
| 75 } | |
| 76 } | |
| 77 | 58 |
| 78 valid_archs = ('arm', 'arm64', 'i386', 'amd64', 'mips') | 59 valid_archs = ('arm', 'arm64', 'i386', 'amd64', 'mips') |
| 79 | 60 |
| 80 | 61 |
| 81 class Error(Exception): | 62 class Error(Exception): |
| 82 pass | 63 pass |
| 83 | 64 |
| 84 | 65 |
| 85 def GetSha1(filename): | 66 def GetSha1(filename): |
| 86 sha1 = hashlib.sha1() | 67 sha1 = hashlib.sha1() |
| (...skipping 10 matching lines...) Expand all Loading... |
| 97 def DetectHostArch(): | 78 def DetectHostArch(): |
| 98 # Figure out host arch using build/detect_host_arch.py and | 79 # Figure out host arch using build/detect_host_arch.py and |
| 99 # set target_arch to host arch | 80 # set target_arch to host arch |
| 100 detected_host_arch = detect_host_arch.HostArch() | 81 detected_host_arch = detect_host_arch.HostArch() |
| 101 if detected_host_arch == 'x64': | 82 if detected_host_arch == 'x64': |
| 102 return 'amd64' | 83 return 'amd64' |
| 103 elif detected_host_arch == 'ia32': | 84 elif detected_host_arch == 'ia32': |
| 104 return 'i386' | 85 return 'i386' |
| 105 elif detected_host_arch == 'arm': | 86 elif detected_host_arch == 'arm': |
| 106 return 'arm' | 87 return 'arm' |
| 107 elif detected_host_arch == 'arm64': | |
| 108 return 'arm64' | |
| 109 elif detected_host_arch == 'mips': | 88 elif detected_host_arch == 'mips': |
| 110 return 'mips' | 89 return 'mips' |
| 111 | 90 |
| 112 raise Error('Unrecognized host arch: %s' % detected_host_arch) | 91 raise Error('Unrecognized host arch: %s' % detected_host_arch) |
| 113 | 92 |
| 114 | 93 |
| 115 def DetectTargetArch(): | 94 def DetectTargetArch(): |
| 116 """Attempt for determine target architecture. | 95 """Attempt for determine target architecture. |
| 117 | 96 |
| 118 This works by looking for target_arch in GYP_DEFINES. | 97 This works by looking for target_arch in GYP_DEFINES. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 136 | 115 |
| 137 return None | 116 return None |
| 138 | 117 |
| 139 | 118 |
| 140 def InstallDefaultSysroots(): | 119 def InstallDefaultSysroots(): |
| 141 """Install the default set of sysroot images. | 120 """Install the default set of sysroot images. |
| 142 | 121 |
| 143 This includes at least the sysroot for host architecture, and the 32-bit | 122 This includes at least the sysroot for host architecture, and the 32-bit |
| 144 sysroot for building the v8 snapshot image. It can also include the cross | 123 sysroot for building the v8 snapshot image. It can also include the cross |
| 145 compile sysroot for ARM/MIPS if cross compiling environment can be detected. | 124 compile sysroot for ARM/MIPS if cross compiling environment can be detected. |
| 146 | |
| 147 Another reason we're installing this by default is so that developers can | |
| 148 compile and run on our supported platforms without having to worry about | |
| 149 flipping things back and forth and whether the sysroots have been downloaded | |
| 150 or not. | |
| 151 """ | 125 """ |
| 152 host_arch = DetectHostArch() | 126 host_arch = DetectHostArch() |
| 153 InstallDefaultSysrootForArch(host_arch) | 127 InstallSysroot(host_arch) |
| 154 | 128 |
| 155 if host_arch == 'amd64': | 129 if host_arch == 'amd64': |
| 156 InstallDefaultSysrootForArch('i386') | 130 InstallSysroot('i386') |
| 157 | |
| 158 # Desktop Chromium OS builds require the precise sysroot. | |
| 159 # TODO(thomasanderson): only download this when the GN arg target_os | |
| 160 # == 'chromeos', when the functionality to perform the check becomes | |
| 161 # available. | |
| 162 InstallSysroot('Precise', 'amd64') | |
| 163 | 131 |
| 164 # Finally, if we can detect a non-standard target_arch such as ARM or | 132 # Finally, if we can detect a non-standard target_arch such as ARM or |
| 165 # MIPS, then install the sysroot too. | 133 # MIPS, then install the sysroot too. |
| 166 # Don't attampt to install arm64 since this is currently and android-only | 134 # Don't attampt to install arm64 since this is currently and android-only |
| 167 # architecture. | 135 # architecture. |
| 168 target_arch = DetectTargetArch() | 136 target_arch = DetectTargetArch() |
| 169 if target_arch and target_arch not in (host_arch, 'i386'): | 137 if target_arch and target_arch not in (host_arch, 'i386'): |
| 170 InstallDefaultSysrootForArch(target_arch) | 138 InstallSysroot(target_arch) |
| 171 | 139 |
| 172 | 140 |
| 173 def main(args): | 141 def main(args): |
| 174 parser = optparse.OptionParser('usage: %prog [OPTIONS]', description=__doc__) | 142 parser = optparse.OptionParser('usage: %prog [OPTIONS]', description=__doc__) |
| 175 parser.add_option('--running-as-hook', action='store_true', | 143 parser.add_option('--running-as-hook', action='store_true', |
| 176 default=False, help='Used when running from gclient hooks.' | 144 default=False, help='Used when running from gclient hooks.' |
| 177 ' Installs default sysroot images.') | 145 ' Installs default sysroot images.') |
| 178 parser.add_option('--arch', type='choice', choices=valid_archs, | 146 parser.add_option('--arch', type='choice', choices=valid_archs, |
| 179 help='Sysroot architecture: %s' % ', '.join(valid_archs)) | 147 help='Sysroot architecture: %s' % ', '.join(valid_archs)) |
| 180 options, _ = parser.parse_args(args) | 148 options, _ = parser.parse_args(args) |
| 181 if options.running_as_hook and not sys.platform.startswith('linux'): | 149 if options.running_as_hook and not sys.platform.startswith('linux'): |
| 182 return 0 | 150 return 0 |
| 183 | 151 |
| 184 if options.running_as_hook: | 152 if options.running_as_hook: |
| 185 InstallDefaultSysroots() | 153 InstallDefaultSysroots() |
| 186 else: | 154 else: |
| 187 if not options.arch: | 155 if not options.arch: |
| 188 print 'You much specify either --arch or --running-as-hook' | 156 print 'You much specify either --arch or --running-as-hook' |
| 189 return 1 | 157 return 1 |
| 190 InstallDefaultSysrootForArch(options.arch) | 158 InstallSysroot(options.arch) |
| 191 | 159 |
| 192 return 0 | 160 return 0 |
| 193 | 161 |
| 194 def InstallDefaultSysrootForArch(target_arch): | |
| 195 if target_arch == 'amd64': | |
| 196 InstallSysroot('Wheezy', 'amd64') | |
| 197 elif target_arch == 'arm': | |
| 198 InstallSysroot('Wheezy', 'arm') | |
| 199 elif target_arch == 'arm64': | |
| 200 InstallSysroot('Jessie', 'arm64') | |
| 201 elif target_arch == 'i386': | |
| 202 InstallSysroot('Wheezy', 'i386') | |
| 203 elif target_arch == 'mips': | |
| 204 InstallSysroot('Wheezy', 'mips') | |
| 205 else: | |
| 206 raise Error('Unknown architecture: %s' % target_arch) | |
| 207 | 162 |
| 208 def InstallSysroot(target_platform, target_arch): | 163 def InstallSysroot(target_arch): |
| 209 # The sysroot directory should match the one specified in build/common.gypi. | 164 # The sysroot directory should match the one specified in build/common.gypi. |
| 210 # TODO(thestig) Consider putting this else where to avoid having to recreate | 165 # TODO(thestig) Consider putting this else where to avoid having to recreate |
| 211 # it on every build. | 166 # it on every build. |
| 212 linux_dir = os.path.dirname(SCRIPT_DIR) | 167 linux_dir = os.path.dirname(SCRIPT_DIR) |
| 213 | 168 debian_release = 'Wheezy' |
| 214 if (target_platform, target_arch) not in SYSROOTS: | 169 if target_arch == 'amd64': |
| 215 raise Error('No sysroot for: %s %s' % (target_platform, target_arch)) | 170 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64) |
| 216 sysroot_dict = SYSROOTS[(target_platform, target_arch)] | 171 tarball_filename = TARBALL_AMD64 |
| 217 revision = sysroot_dict['Revision'] | 172 tarball_sha1sum = TARBALL_AMD64_SHA1SUM |
| 218 tarball_filename = sysroot_dict['Tarball'] | 173 revision = REVISION_AMD64 |
| 219 tarball_sha1sum = sysroot_dict['Sha1Sum'] | 174 elif target_arch == 'arm': |
| 220 sysroot = os.path.join(linux_dir, sysroot_dict['SysrootDir']) | 175 sysroot = os.path.join(linux_dir, SYSROOT_DIR_ARM) |
| 176 tarball_filename = TARBALL_ARM |
| 177 tarball_sha1sum = TARBALL_ARM_SHA1SUM |
| 178 revision = REVISION_ARM |
| 179 elif target_arch == 'arm64': |
| 180 debian_release = 'Jessie' |
| 181 sysroot = os.path.join(linux_dir, SYSROOT_DIR_ARM64) |
| 182 tarball_filename = TARBALL_ARM64 |
| 183 tarball_sha1sum = TARBALL_ARM64_SHA1SUM |
| 184 revision = REVISION_ARM64 |
| 185 elif target_arch == 'i386': |
| 186 sysroot = os.path.join(linux_dir, SYSROOT_DIR_I386) |
| 187 tarball_filename = TARBALL_I386 |
| 188 tarball_sha1sum = TARBALL_I386_SHA1SUM |
| 189 revision = REVISION_I386 |
| 190 elif target_arch == 'mips': |
| 191 sysroot = os.path.join(linux_dir, SYSROOT_DIR_MIPS) |
| 192 tarball_filename = TARBALL_MIPS |
| 193 tarball_sha1sum = TARBALL_MIPS_SHA1SUM |
| 194 revision = REVISION_MIPS |
| 195 else: |
| 196 raise Error('Unknown architecture: %s' % target_arch) |
| 221 | 197 |
| 222 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, revision, tarball_filename) | 198 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, revision, tarball_filename) |
| 223 | 199 |
| 224 stamp = os.path.join(sysroot, '.stamp') | 200 stamp = os.path.join(sysroot, '.stamp') |
| 225 if os.path.exists(stamp): | 201 if os.path.exists(stamp): |
| 226 with open(stamp) as s: | 202 with open(stamp) as s: |
| 227 if s.read() == url: | 203 if s.read() == url: |
| 228 print 'Debian %s %s root image already up to date: %s' % \ | 204 print 'Debian %s %s root image already up to date: %s' % \ |
| 229 (target_platform, target_arch, sysroot) | 205 (debian_release, target_arch, sysroot) |
| 230 return | 206 return |
| 231 | 207 |
| 232 print 'Installing Debian %s %s root image: %s' % \ | 208 print 'Installing Debian %s %s root image: %s' % \ |
| 233 (target_platform, target_arch, sysroot) | 209 (debian_release, target_arch, sysroot) |
| 234 if os.path.isdir(sysroot): | 210 if os.path.isdir(sysroot): |
| 235 shutil.rmtree(sysroot) | 211 shutil.rmtree(sysroot) |
| 236 os.mkdir(sysroot) | 212 os.mkdir(sysroot) |
| 237 tarball = os.path.join(sysroot, tarball_filename) | 213 tarball = os.path.join(sysroot, tarball_filename) |
| 238 print 'Downloading %s' % url | 214 print 'Downloading %s' % url |
| 239 sys.stdout.flush() | 215 sys.stdout.flush() |
| 240 sys.stderr.flush() | 216 sys.stderr.flush() |
| 241 subprocess.check_call( | 217 subprocess.check_call( |
| 242 ['curl', '--fail', '--retry', '3', '-L', url, '-o', tarball]) | 218 ['curl', '--fail', '--retry', '3', '-L', url, '-o', tarball]) |
| 243 sha1sum = GetSha1(tarball) | 219 sha1sum = GetSha1(tarball) |
| 244 if sha1sum != tarball_sha1sum: | 220 if sha1sum != tarball_sha1sum: |
| 245 raise Error('Tarball sha1sum is wrong.' | 221 raise Error('Tarball sha1sum is wrong.' |
| 246 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum)) | 222 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum)) |
| 247 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot]) | 223 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot]) |
| 248 os.remove(tarball) | 224 os.remove(tarball) |
| 249 | 225 |
| 250 with open(stamp, 'w') as s: | 226 with open(stamp, 'w') as s: |
| 251 s.write(url) | 227 s.write(url) |
| 252 | 228 |
| 253 | 229 |
| 254 if __name__ == '__main__': | 230 if __name__ == '__main__': |
| 255 try: | 231 try: |
| 256 sys.exit(main(sys.argv[1:])) | 232 sys.exit(main(sys.argv[1:])) |
| 257 except Error as e: | 233 except Error as e: |
| 258 sys.stderr.write(str(e) + '\n') | 234 sys.stderr.write(str(e) + '\n') |
| 259 sys.exit(1) | 235 sys.exit(1) |
| OLD | NEW |