Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: build/linux/sysroot_scripts/install-sysroot.py

Issue 2272273002: Desktop Chrome OS: Build with precise sysroot (Reland) (Closed)
Patch Set: Desktop Chrome OS: Build with precise sysroot Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« build/config/sysroot.gni ('K') | « build/config/sysroot.gni ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 REVISION_AMD64 = '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba' 38
39 REVISION_ARM = '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba' 39 sysroots = {
Tom (Use chromium acct) 2016/08/25 03:09:56 Not sure if this is the most pythonic way to do th
Dirk Pranke 2016/08/25 03:27:22 Nit: It's a constant, so, SYSROOTS. Otherwise, yes
Tom (Use chromium acct) 2016/08/25 18:28:51 Done.
40 REVISION_ARM64 = '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba' 40 ('Wheezy', 'amd64'): {
41 REVISION_I386 = '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba' 41 'Revision' : '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba',
42 REVISION_MIPS = '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba' 42 'Tarball' : 'debian_wheezy_amd64_sysroot.tgz',
43 TARBALL_AMD64 = 'debian_wheezy_amd64_sysroot.tgz' 43 'Sha1Sum' : 'a7f3df28b02799fbd7675c2ab24f1924c104c0ee',
44 TARBALL_ARM = 'debian_wheezy_arm_sysroot.tgz' 44 'SysrootDir' : 'debian_wheezy_amd64-sysroot'
45 TARBALL_ARM64 = 'debian_jessie_arm64_sysroot.tgz' 45 },
46 TARBALL_I386 = 'debian_wheezy_i386_sysroot.tgz' 46 ('Wheezy', 'arm'): {
47 TARBALL_MIPS = 'debian_wheezy_mips_sysroot.tgz' 47 'Revision' : '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba',
48 TARBALL_AMD64_SHA1SUM = 'a7f3df28b02799fbd7675c2ab24f1924c104c0ee' 48 'Tarball' : 'debian_wheezy_arm_sysroot.tgz',
49 TARBALL_ARM_SHA1SUM = '2df01b8173a363977daf04e176b8c7dba5b0b933' 49 'Sha1Sum' : '2df01b8173a363977daf04e176b8c7dba5b0b933',
50 TARBALL_ARM64_SHA1SUM = 'df9270e00c258e6cd80f8172b1bfa39aafc4756f' 50 'SysrootDir' : 'debian_wheezy_arm-sysroot'
51 TARBALL_I386_SHA1SUM = 'e2c7131fa5f711de28c37fd9442e77d32abfb3ff' 51 },
52 TARBALL_MIPS_SHA1SUM = '22fe7b45b144691aeb515083025f0fceb131d724' 52 ('Wheezy', 'i386'): {
53 SYSROOT_DIR_AMD64 = 'debian_wheezy_amd64-sysroot' 53 'Revision' : '24f935a3d8cdfcdfbabd23928a42304b1ffc52ba',
54 SYSROOT_DIR_ARM = 'debian_wheezy_arm-sysroot' 54 'Tarball' : 'debian_wheezy_i386_sysroot.tgz',
55 SYSROOT_DIR_ARM64 = 'debian_jessie_arm64-sysroot' 55 'Sha1Sum' : 'e2c7131fa5f711de28c37fd9442e77d32abfb3ff',
56 SYSROOT_DIR_I386 = 'debian_wheezy_i386-sysroot' 56 'SysrootDir' : 'debian_wheezy_i386-sysroot'
57 SYSROOT_DIR_MIPS = 'debian_wheezy_mips-sysroot' 57 },
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 }
58 77
59 valid_archs = ('arm', 'arm64', 'i386', 'amd64', 'mips') 78 valid_archs = ('arm', 'arm64', 'i386', 'amd64', 'mips')
60 79
61 80
62 class Error(Exception): 81 class Error(Exception):
63 pass 82 pass
64 83
65 84
66 def GetSha1(filename): 85 def GetSha1(filename):
67 sha1 = hashlib.sha1() 86 sha1 = hashlib.sha1()
(...skipping 10 matching lines...) Expand all
78 def DetectHostArch(): 97 def DetectHostArch():
79 # Figure out host arch using build/detect_host_arch.py and 98 # Figure out host arch using build/detect_host_arch.py and
80 # set target_arch to host arch 99 # set target_arch to host arch
81 detected_host_arch = detect_host_arch.HostArch() 100 detected_host_arch = detect_host_arch.HostArch()
82 if detected_host_arch == 'x64': 101 if detected_host_arch == 'x64':
83 return 'amd64' 102 return 'amd64'
84 elif detected_host_arch == 'ia32': 103 elif detected_host_arch == 'ia32':
85 return 'i386' 104 return 'i386'
86 elif detected_host_arch == 'arm': 105 elif detected_host_arch == 'arm':
87 return 'arm' 106 return 'arm'
107 elif detected_host_arch == 'arm64':
108 return 'arm64'
88 elif detected_host_arch == 'mips': 109 elif detected_host_arch == 'mips':
89 return 'mips' 110 return 'mips'
90 111
91 raise Error('Unrecognized host arch: %s' % detected_host_arch) 112 raise Error('Unrecognized host arch: %s' % detected_host_arch)
92 113
93 114
94 def DetectTargetArch(): 115 def DetectTargetArch():
95 """Attempt for determine target architecture. 116 """Attempt for determine target architecture.
96 117
97 This works by looking for target_arch in GYP_DEFINES. 118 This works by looking for target_arch in GYP_DEFINES.
(...skipping 19 matching lines...) Expand all
117 138
118 139
119 def InstallDefaultSysroots(): 140 def InstallDefaultSysroots():
120 """Install the default set of sysroot images. 141 """Install the default set of sysroot images.
121 142
122 This includes at least the sysroot for host architecture, and the 32-bit 143 This includes at least the sysroot for host architecture, and the 32-bit
123 sysroot for building the v8 snapshot image. It can also include the cross 144 sysroot for building the v8 snapshot image. It can also include the cross
124 compile sysroot for ARM/MIPS if cross compiling environment can be detected. 145 compile sysroot for ARM/MIPS if cross compiling environment can be detected.
125 """ 146 """
126 host_arch = DetectHostArch() 147 host_arch = DetectHostArch()
127 InstallSysroot(host_arch) 148 InstallDefaultSysrootForArch(host_arch)
128 149
129 if host_arch == 'amd64': 150 if host_arch == 'amd64':
130 InstallSysroot('i386') 151 InstallDefaultSysrootForArch('i386')
152
153 # Desktop Chromium OS builds require the precise sysroot.
154 # TODO(thomasanderson): only download this when the GN arg target_os
155 # == 'chromeos', when the functionality to perform the check becomes
156 # available.
157 InstallSysroot('Precise', 'amd64')
Dirk Pranke 2016/08/25 03:27:22 Another reason we're installing this by default is
Tom (Use chromium acct) 2016/08/25 18:28:51 Done.
131 158
132 # Finally, if we can detect a non-standard target_arch such as ARM or 159 # Finally, if we can detect a non-standard target_arch such as ARM or
133 # MIPS, then install the sysroot too. 160 # MIPS, then install the sysroot too.
134 # Don't attampt to install arm64 since this is currently and android-only 161 # Don't attampt to install arm64 since this is currently and android-only
135 # architecture. 162 # architecture.
136 target_arch = DetectTargetArch() 163 target_arch = DetectTargetArch()
137 if target_arch and target_arch not in (host_arch, 'i386'): 164 if target_arch and target_arch not in (host_arch, 'i386'):
138 InstallSysroot(target_arch) 165 InstallDefaultSysrootForArch(target_arch)
139 166
140 167
141 def main(args): 168 def main(args):
142 parser = optparse.OptionParser('usage: %prog [OPTIONS]', description=__doc__) 169 parser = optparse.OptionParser('usage: %prog [OPTIONS]', description=__doc__)
143 parser.add_option('--running-as-hook', action='store_true', 170 parser.add_option('--running-as-hook', action='store_true',
144 default=False, help='Used when running from gclient hooks.' 171 default=False, help='Used when running from gclient hooks.'
145 ' Installs default sysroot images.') 172 ' Installs default sysroot images.')
146 parser.add_option('--arch', type='choice', choices=valid_archs, 173 parser.add_option('--arch', type='choice', choices=valid_archs,
147 help='Sysroot architecture: %s' % ', '.join(valid_archs)) 174 help='Sysroot architecture: %s' % ', '.join(valid_archs))
148 options, _ = parser.parse_args(args) 175 options, _ = parser.parse_args(args)
149 if options.running_as_hook and not sys.platform.startswith('linux'): 176 if options.running_as_hook and not sys.platform.startswith('linux'):
150 return 0 177 return 0
151 178
152 if options.running_as_hook: 179 if options.running_as_hook:
153 InstallDefaultSysroots() 180 InstallDefaultSysroots()
154 else: 181 else:
155 if not options.arch: 182 if not options.arch:
156 print 'You much specify either --arch or --running-as-hook' 183 print 'You much specify either --arch or --running-as-hook'
157 return 1 184 return 1
158 InstallSysroot(options.arch) 185 InstallDefaultSysrootForArch(options.arch)
159 186
160 return 0 187 return 0
161 188
189 def InstallDefaultSysrootForArch(target_arch):
190 if target_arch == 'amd64':
191 InstallSysroot('Wheezy', 'amd64')
192 elif target_arch == 'arm':
193 InstallSysroot('Wheezy', 'arm')
194 elif target_arch == 'arm64':
195 InstallSysroot('Jessie', 'arm64')
196 elif target_arch == 'i386':
197 InstallSysroot('Wheezy', 'i386')
198 elif target_arch == 'mips':
199 InstallSysroot('Wheezy', 'mips')
200 else:
201 raise Error('Unknown architecture: %s' % target_arch)
162 202
163 def InstallSysroot(target_arch): 203 def InstallSysroot(target_platform, target_arch):
164 # The sysroot directory should match the one specified in build/common.gypi. 204 # The sysroot directory should match the one specified in build/common.gypi.
165 # TODO(thestig) Consider putting this else where to avoid having to recreate 205 # TODO(thestig) Consider putting this else where to avoid having to recreate
166 # it on every build. 206 # it on every build.
167 linux_dir = os.path.dirname(SCRIPT_DIR) 207 linux_dir = os.path.dirname(SCRIPT_DIR)
168 debian_release = 'Wheezy' 208
169 if target_arch == 'amd64': 209 if (target_platform, target_arch) not in sysroots:
170 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64) 210 raise Error('No sysroot for: %s %s' % (target_platform, target_arch))
171 tarball_filename = TARBALL_AMD64 211 sysroot_dict = sysroots[(target_platform, target_arch)]
172 tarball_sha1sum = TARBALL_AMD64_SHA1SUM 212 revision = sysroot_dict['Revision']
173 revision = REVISION_AMD64 213 tarball_filename = sysroot_dict['Tarball']
174 elif target_arch == 'arm': 214 tarball_sha1sum = sysroot_dict['Sha1Sum']
175 sysroot = os.path.join(linux_dir, SYSROOT_DIR_ARM) 215 sysroot = os.path.join(linux_dir, sysroot_dict['SysrootDir'])
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)
197 216
198 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, revision, tarball_filename) 217 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, revision, tarball_filename)
199 218
200 stamp = os.path.join(sysroot, '.stamp') 219 stamp = os.path.join(sysroot, '.stamp')
201 if os.path.exists(stamp): 220 if os.path.exists(stamp):
202 with open(stamp) as s: 221 with open(stamp) as s:
203 if s.read() == url: 222 if s.read() == url:
204 print 'Debian %s %s root image already up to date: %s' % \ 223 print 'Debian %s %s root image already up to date: %s' % \
205 (debian_release, target_arch, sysroot) 224 (target_platform, target_arch, sysroot)
206 return 225 return
207 226
208 print 'Installing Debian %s %s root image: %s' % \ 227 print 'Installing Debian %s %s root image: %s' % \
209 (debian_release, target_arch, sysroot) 228 (target_platform, target_arch, sysroot)
210 if os.path.isdir(sysroot): 229 if os.path.isdir(sysroot):
211 shutil.rmtree(sysroot) 230 shutil.rmtree(sysroot)
212 os.mkdir(sysroot) 231 os.mkdir(sysroot)
213 tarball = os.path.join(sysroot, tarball_filename) 232 tarball = os.path.join(sysroot, tarball_filename)
214 print 'Downloading %s' % url 233 print 'Downloading %s' % url
215 sys.stdout.flush() 234 sys.stdout.flush()
216 sys.stderr.flush() 235 sys.stderr.flush()
217 subprocess.check_call( 236 subprocess.check_call(
218 ['curl', '--fail', '--retry', '3', '-L', url, '-o', tarball]) 237 ['curl', '--fail', '--retry', '3', '-L', url, '-o', tarball])
219 sha1sum = GetSha1(tarball) 238 sha1sum = GetSha1(tarball)
220 if sha1sum != tarball_sha1sum: 239 if sha1sum != tarball_sha1sum:
221 raise Error('Tarball sha1sum is wrong.' 240 raise Error('Tarball sha1sum is wrong.'
222 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum)) 241 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum))
223 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot]) 242 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot])
224 os.remove(tarball) 243 os.remove(tarball)
225 244
226 with open(stamp, 'w') as s: 245 with open(stamp, 'w') as s:
227 s.write(url) 246 s.write(url)
228 247
229 248
230 if __name__ == '__main__': 249 if __name__ == '__main__':
231 try: 250 try:
232 sys.exit(main(sys.argv[1:])) 251 sys.exit(main(sys.argv[1:]))
233 except Error as e: 252 except Error as e:
234 sys.stderr.write(str(e) + '\n') 253 sys.stderr.write(str(e) + '\n')
235 sys.exit(1) 254 sys.exit(1)
OLDNEW
« build/config/sysroot.gni ('K') | « build/config/sysroot.gni ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698