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 # Script to install a Debian Wheezy sysroot for making official Google Chrome | 6 # Script to install a Debian Wheezy sysroot for making official Google Chrome |
7 # Linux builds. | 7 # Linux builds. |
8 # The sysroot is needed to make Chrome work for Debian Wheezy. | 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 | 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 | 10 # hooks. When run from hooks this script should be a no-op on non-linux |
(...skipping 13 matching lines...) Expand all Loading... | |
24 import subprocess | 24 import subprocess |
25 import sys | 25 import sys |
26 | 26 |
27 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) | 27 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
28 sys.path.append(os.path.dirname(os.path.dirname(os.path.join(SCRIPT_DIR)))) | 28 sys.path.append(os.path.dirname(os.path.dirname(os.path.join(SCRIPT_DIR)))) |
29 import detect_host_arch | 29 import detect_host_arch |
30 import gyp_chromium | 30 import gyp_chromium |
31 import gyp_environment | 31 import gyp_environment |
32 | 32 |
33 | 33 |
34 # Its existence signifies an Android checkout. | |
35 ANDROID_ONLY_DIR = os.path.join(SCRIPT_DIR, os.pardir, os.pardir, os.pardir, | |
36 'third_party', 'android_tools') | |
37 | |
34 URL_PREFIX = 'http://storage.googleapis.com' | 38 URL_PREFIX = 'http://storage.googleapis.com' |
35 URL_PATH = 'chrome-linux-sysroot/toolchain' | 39 URL_PATH = 'chrome-linux-sysroot/toolchain' |
36 REVISION_AMD64 = '402274e42cb72fde4f48a4bb01664d0ad4533c69' | 40 REVISION_AMD64 = '402274e42cb72fde4f48a4bb01664d0ad4533c69' |
37 REVISION_ARM = '402274e42cb72fde4f48a4bb01664d0ad4533c69' | 41 REVISION_ARM = '402274e42cb72fde4f48a4bb01664d0ad4533c69' |
38 REVISION_I386 = '402274e42cb72fde4f48a4bb01664d0ad4533c69' | 42 REVISION_I386 = '402274e42cb72fde4f48a4bb01664d0ad4533c69' |
39 REVISION_MIPS = '402274e42cb72fde4f48a4bb01664d0ad4533c69' | 43 REVISION_MIPS = '402274e42cb72fde4f48a4bb01664d0ad4533c69' |
40 TARBALL_AMD64 = 'debian_wheezy_amd64_sysroot.tgz' | 44 TARBALL_AMD64 = 'debian_wheezy_amd64_sysroot.tgz' |
41 TARBALL_ARM = 'debian_wheezy_arm_sysroot.tgz' | 45 TARBALL_ARM = 'debian_wheezy_arm_sysroot.tgz' |
42 TARBALL_I386 = 'debian_wheezy_i386_sysroot.tgz' | 46 TARBALL_I386 = 'debian_wheezy_i386_sysroot.tgz' |
43 TARBALL_MIPS = 'debian_wheezy_mips_sysroot.tgz' | 47 TARBALL_MIPS = 'debian_wheezy_mips_sysroot.tgz' |
(...skipping 14 matching lines...) Expand all Loading... | |
58 with open(filename, 'rb') as f: | 62 with open(filename, 'rb') as f: |
59 while True: | 63 while True: |
60 # Read in 1mb chunks, so it doesn't all have to be loaded into memory. | 64 # Read in 1mb chunks, so it doesn't all have to be loaded into memory. |
61 chunk = f.read(1024*1024) | 65 chunk = f.read(1024*1024) |
62 if not chunk: | 66 if not chunk: |
63 break | 67 break |
64 sha1.update(chunk) | 68 sha1.update(chunk) |
65 return sha1.hexdigest() | 69 return sha1.hexdigest() |
66 | 70 |
67 | 71 |
68 def DetectArch(gyp_defines, is_android): | 72 def DetectArch(gyp_defines): |
69 # Check for optional target_arch and only install for that architecture. | 73 # Check for optional target_arch and only install for that architecture. |
70 # If target_arch is not specified, then only install for the host | 74 # If target_arch is not specified, then only install for the host |
71 # architecture. | 75 # architecture. |
72 target_arch = gyp_defines.get('target_arch') | 76 target_arch = gyp_defines.get('target_arch') |
73 if target_arch == 'x64': | 77 if target_arch == 'x64': |
74 return 'amd64' | 78 return 'amd64' |
75 elif target_arch == 'ia32': | 79 elif target_arch == 'ia32': |
76 return 'i386' | 80 return 'i386' |
77 elif target_arch == 'arm': | 81 elif target_arch == 'arm': |
78 return 'arm' | 82 return 'arm' |
79 elif target_arch == 'arm64': | 83 elif target_arch == 'arm64': |
80 return 'arm64' | 84 return 'arm64' |
81 elif target_arch == 'mipsel': | 85 elif target_arch == 'mipsel': |
82 return 'mips' | 86 return 'mips' |
83 elif target_arch: | 87 elif target_arch: |
84 raise Exception('Unrecognized target_arch: %s' % target_arch) | 88 raise Exception('Unrecognized target_arch: %s' % target_arch) |
85 | 89 |
86 if is_android: | |
87 return 'arm' | |
88 | |
89 # Figure out host arch using build/detect_host_arch.py and | 90 # Figure out host arch using build/detect_host_arch.py and |
90 # set target_arch to host arch | 91 # set target_arch to host arch |
91 detected_host_arch = detect_host_arch.HostArch() | 92 detected_host_arch = detect_host_arch.HostArch() |
92 if detected_host_arch == 'x64': | 93 if detected_host_arch == 'x64': |
93 return 'amd64' | 94 return 'amd64' |
94 elif detected_host_arch == 'ia32': | 95 elif detected_host_arch == 'ia32': |
95 return 'i386' | 96 return 'i386' |
96 elif detected_host_arch == 'arm': | 97 elif detected_host_arch == 'arm': |
97 return 'arm' | 98 return 'arm' |
98 elif detected_host_arch == 'mips': | 99 elif detected_host_arch == 'mips': |
99 return 'mips' | 100 return 'mips' |
100 else: | 101 else: |
101 print "Unknown host arch: %s" % detected_host_arch | 102 print "Unknown host arch: %s" % detected_host_arch |
102 | 103 |
103 return None | 104 return None |
104 | 105 |
105 | 106 |
106 def main(): | 107 def main(): |
107 if options.running_as_hook and not sys.platform.startswith('linux'): | 108 if options.running_as_hook and not sys.platform.startswith('linux'): |
108 return 0 | 109 return 0 |
109 | 110 |
111 # TODO(agrieve): Make this script not depend on GYP_DEFINES so that it works | |
112 # with GN as well. | |
110 gyp_environment.SetEnvironment() | 113 gyp_environment.SetEnvironment() |
111 supplemental_includes = gyp_chromium.GetSupplementalFiles() | 114 supplemental_includes = gyp_chromium.GetSupplementalFiles() |
112 gyp_defines = gyp_chromium.GetGypVars(supplemental_includes) | 115 gyp_defines = gyp_chromium.GetGypVars(supplemental_includes) |
113 is_android = gyp_defines.get('OS') == 'android' | |
114 | |
115 if (options.running_as_hook and (not is_android) and | |
116 (gyp_defines.get('chromeos') or gyp_defines.get('use_sysroot') == '0')): | |
117 return 0 | |
118 | 116 |
119 if options.arch: | 117 if options.arch: |
120 target_arch = options.arch | 118 target_arch = options.arch |
121 else: | 119 else: |
122 target_arch = DetectArch(gyp_defines, is_android) | 120 if os.path.exists(ANDROID_ONLY_DIR): |
Dirk Pranke
2015/12/04 00:55:08
nit: I'd change line 119 to 'elif os.path.exist(..
agrieve
2015/12/04 15:26:54
Done.
| |
123 if not target_arch: | 121 # 32-bit Android builds (the default for target_os="android") require a |
124 print 'Unable to detect target architecture' | 122 # 32-bit host sysroot for the v8 snapshot, and a 64-bit sysroot for host |
125 return 1 | 123 # tools. |
126 | |
127 if is_android: | |
128 # 32-bit Android builds require a 32-bit host sysroot for the v8 snapshot. | |
129 if '64' not in target_arch: | |
130 ret = _InstallSysroot('i386') | 124 ret = _InstallSysroot('i386') |
131 if ret: | 125 if ret: |
132 return ret | 126 return ret |
133 # Always need host sysroot (which we assume is x64). | 127 target_arch = 'amd64' |
134 target_arch = 'amd64' | 128 else: |
129 target_arch = DetectArch(gyp_defines) | |
130 if not target_arch: | |
131 print 'Unable to detect target architecture' | |
132 return 1 | |
135 | 133 |
136 return _InstallSysroot(target_arch) | 134 return _InstallSysroot(target_arch) |
137 | 135 |
138 | 136 |
139 def _InstallSysroot(target_arch): | 137 def _InstallSysroot(target_arch): |
140 # The sysroot directory should match the one specified in build/common.gypi. | 138 # The sysroot directory should match the one specified in build/common.gypi. |
141 # TODO(thestig) Consider putting this else where to avoid having to recreate | 139 # TODO(thestig) Consider putting this else where to avoid having to recreate |
142 # it on every build. | 140 # it on every build. |
143 linux_dir = os.path.dirname(SCRIPT_DIR) | 141 linux_dir = os.path.dirname(SCRIPT_DIR) |
144 if target_arch == 'amd64': | 142 if target_arch == 'amd64': |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 parser = optparse.OptionParser('usage: %prog [OPTIONS]') | 199 parser = optparse.OptionParser('usage: %prog [OPTIONS]') |
202 parser.add_option('--running-as-hook', action='store_true', | 200 parser.add_option('--running-as-hook', action='store_true', |
203 default=False, help='Used when running from gclient hooks.' | 201 default=False, help='Used when running from gclient hooks.' |
204 ' In this mode the sysroot will only ' | 202 ' In this mode the sysroot will only ' |
205 'be installed for official Linux ' | 203 'be installed for official Linux ' |
206 'builds or ARM Linux builds') | 204 'builds or ARM Linux builds') |
207 parser.add_option('--arch', type='choice', choices=valid_archs, | 205 parser.add_option('--arch', type='choice', choices=valid_archs, |
208 help='Sysroot architecture: %s' % ', '.join(valid_archs)) | 206 help='Sysroot architecture: %s' % ', '.join(valid_archs)) |
209 options, _ = parser.parse_args() | 207 options, _ = parser.parse_args() |
210 sys.exit(main()) | 208 sys.exit(main()) |
OLD | NEW |