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

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

Issue 2272273002: Desktop Chrome OS: Build with precise sysroot (Reland) (Closed)
Patch Set: Update license check scripts 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
« no previous file with comments | « build/config/sysroot.gni ('k') | tools/checklicenses/checklicenses.py » ('j') | 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 = {
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 17 matching lines...) Expand all
115 136
116 return None 137 return None
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.
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.
125 """ 151 """
126 host_arch = DetectHostArch() 152 host_arch = DetectHostArch()
127 InstallSysroot(host_arch) 153 InstallDefaultSysrootForArch(host_arch)
128 154
129 if host_arch == 'amd64': 155 if host_arch == 'amd64':
130 InstallSysroot('i386') 156 InstallDefaultSysrootForArch('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')
131 163
132 # Finally, if we can detect a non-standard target_arch such as ARM or 164 # Finally, if we can detect a non-standard target_arch such as ARM or
133 # MIPS, then install the sysroot too. 165 # MIPS, then install the sysroot too.
134 # Don't attampt to install arm64 since this is currently and android-only 166 # Don't attampt to install arm64 since this is currently and android-only
135 # architecture. 167 # architecture.
136 target_arch = DetectTargetArch() 168 target_arch = DetectTargetArch()
137 if target_arch and target_arch not in (host_arch, 'i386'): 169 if target_arch and target_arch not in (host_arch, 'i386'):
138 InstallSysroot(target_arch) 170 InstallDefaultSysrootForArch(target_arch)
139 171
140 172
141 def main(args): 173 def main(args):
142 parser = optparse.OptionParser('usage: %prog [OPTIONS]', description=__doc__) 174 parser = optparse.OptionParser('usage: %prog [OPTIONS]', description=__doc__)
143 parser.add_option('--running-as-hook', action='store_true', 175 parser.add_option('--running-as-hook', action='store_true',
144 default=False, help='Used when running from gclient hooks.' 176 default=False, help='Used when running from gclient hooks.'
145 ' Installs default sysroot images.') 177 ' Installs default sysroot images.')
146 parser.add_option('--arch', type='choice', choices=valid_archs, 178 parser.add_option('--arch', type='choice', choices=valid_archs,
147 help='Sysroot architecture: %s' % ', '.join(valid_archs)) 179 help='Sysroot architecture: %s' % ', '.join(valid_archs))
148 options, _ = parser.parse_args(args) 180 options, _ = parser.parse_args(args)
149 if options.running_as_hook and not sys.platform.startswith('linux'): 181 if options.running_as_hook and not sys.platform.startswith('linux'):
150 return 0 182 return 0
151 183
152 if options.running_as_hook: 184 if options.running_as_hook:
153 InstallDefaultSysroots() 185 InstallDefaultSysroots()
154 else: 186 else:
155 if not options.arch: 187 if not options.arch:
156 print 'You much specify either --arch or --running-as-hook' 188 print 'You much specify either --arch or --running-as-hook'
157 return 1 189 return 1
158 InstallSysroot(options.arch) 190 InstallDefaultSysrootForArch(options.arch)
159 191
160 return 0 192 return 0
161 193
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)
162 207
163 def InstallSysroot(target_arch): 208 def InstallSysroot(target_platform, target_arch):
164 # The sysroot directory should match the one specified in build/common.gypi. 209 # 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 210 # TODO(thestig) Consider putting this else where to avoid having to recreate
166 # it on every build. 211 # it on every build.
167 linux_dir = os.path.dirname(SCRIPT_DIR) 212 linux_dir = os.path.dirname(SCRIPT_DIR)
168 debian_release = 'Wheezy' 213
169 if target_arch == 'amd64': 214 if (target_platform, target_arch) not in SYSROOTS:
170 sysroot = os.path.join(linux_dir, SYSROOT_DIR_AMD64) 215 raise Error('No sysroot for: %s %s' % (target_platform, target_arch))
171 tarball_filename = TARBALL_AMD64 216 sysroot_dict = SYSROOTS[(target_platform, target_arch)]
172 tarball_sha1sum = TARBALL_AMD64_SHA1SUM 217 revision = sysroot_dict['Revision']
173 revision = REVISION_AMD64 218 tarball_filename = sysroot_dict['Tarball']
174 elif target_arch == 'arm': 219 tarball_sha1sum = sysroot_dict['Sha1Sum']
175 sysroot = os.path.join(linux_dir, SYSROOT_DIR_ARM) 220 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 221
198 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, revision, tarball_filename) 222 url = '%s/%s/%s/%s' % (URL_PREFIX, URL_PATH, revision, tarball_filename)
199 223
200 stamp = os.path.join(sysroot, '.stamp') 224 stamp = os.path.join(sysroot, '.stamp')
201 if os.path.exists(stamp): 225 if os.path.exists(stamp):
202 with open(stamp) as s: 226 with open(stamp) as s:
203 if s.read() == url: 227 if s.read() == url:
204 print 'Debian %s %s root image already up to date: %s' % \ 228 print 'Debian %s %s root image already up to date: %s' % \
205 (debian_release, target_arch, sysroot) 229 (target_platform, target_arch, sysroot)
206 return 230 return
207 231
208 print 'Installing Debian %s %s root image: %s' % \ 232 print 'Installing Debian %s %s root image: %s' % \
209 (debian_release, target_arch, sysroot) 233 (target_platform, target_arch, sysroot)
210 if os.path.isdir(sysroot): 234 if os.path.isdir(sysroot):
211 shutil.rmtree(sysroot) 235 shutil.rmtree(sysroot)
212 os.mkdir(sysroot) 236 os.mkdir(sysroot)
213 tarball = os.path.join(sysroot, tarball_filename) 237 tarball = os.path.join(sysroot, tarball_filename)
214 print 'Downloading %s' % url 238 print 'Downloading %s' % url
215 sys.stdout.flush() 239 sys.stdout.flush()
216 sys.stderr.flush() 240 sys.stderr.flush()
217 subprocess.check_call( 241 subprocess.check_call(
218 ['curl', '--fail', '--retry', '3', '-L', url, '-o', tarball]) 242 ['curl', '--fail', '--retry', '3', '-L', url, '-o', tarball])
219 sha1sum = GetSha1(tarball) 243 sha1sum = GetSha1(tarball)
220 if sha1sum != tarball_sha1sum: 244 if sha1sum != tarball_sha1sum:
221 raise Error('Tarball sha1sum is wrong.' 245 raise Error('Tarball sha1sum is wrong.'
222 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum)) 246 'Expected %s, actual: %s' % (tarball_sha1sum, sha1sum))
223 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot]) 247 subprocess.check_call(['tar', 'xf', tarball, '-C', sysroot])
224 os.remove(tarball) 248 os.remove(tarball)
225 249
226 with open(stamp, 'w') as s: 250 with open(stamp, 'w') as s:
227 s.write(url) 251 s.write(url)
228 252
229 253
230 if __name__ == '__main__': 254 if __name__ == '__main__':
231 try: 255 try:
232 sys.exit(main(sys.argv[1:])) 256 sys.exit(main(sys.argv[1:]))
233 except Error as e: 257 except Error as e:
234 sys.stderr.write(str(e) + '\n') 258 sys.stderr.write(str(e) + '\n')
235 sys.exit(1) 259 sys.exit(1)
OLDNEW
« no previous file with comments | « build/config/sysroot.gni ('k') | tools/checklicenses/checklicenses.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698