blob: 53689056af521dc25faa0c3a56f99ee088f6df14 [file] [log] [blame]
Primiano Tucciae2879e2017-09-27 11:02:09 +09001#!/usr/bin/env python
2# Copyright (C) 2017 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import argparse
17import hashlib
18import logging
19import os
20import shutil
Primiano Tucci0825bc82017-09-28 18:50:23 +010021import subprocess
Primiano Tucciae2879e2017-09-27 11:02:09 +090022import sys
23import urllib
24import zipfile
25
Primiano Tuccid7750452017-09-29 14:38:51 +010026from collections import namedtuple
27
Primiano Tucci636ede12017-10-30 16:03:07 +000028# When adding a new git dependency here please also add a corresponding entry in
29# .travis.yml under the "cache:" section.
30
Primiano Tuccib60d4b02017-11-10 11:03:00 +000031# The format for the deps below is the following:
32# (target_folder, source_url, sha1, target_platform)
33# |source_url| can be either a git repo or a http url.
34# If a git repo, |sha1| is the committish that will be checked out.
35# If a http url, |sha1| is the shasum of the original file.
36# If the url is a .zip or .tgz file it will be automatically deflated under
37# |target_folder|, taking care of stripping the root folder if it's a single
38# root (to avoid ending up with buildtools/protobuf/protobuf-1.2.3/... and have
39# instead just buildtools/protobuf).
40# |target_platform| is either 'darwin', 'linux2' or 'all' and applies the dep
41# only on the given platform (ask python why linux2 and not just linux).
42
Primiano Tuccid7750452017-09-29 14:38:51 +010043# Dependencies required to build code on the host or when targeting desktop OS.
44BUILD_DEPS_HOST = [
Primiano Tucciae2879e2017-09-27 11:02:09 +090045 # GN
46 ('buildtools/mac/gn',
Primiano Tuccic2eb5102018-05-15 10:40:01 +010047 'https://storage.googleapis.com/chromium-gn/9be792dd9010ce303a9c3a497a67bcc5ac8c7666',
48 '9be792dd9010ce303a9c3a497a67bcc5ac8c7666',
Primiano Tucciae2879e2017-09-27 11:02:09 +090049 'darwin'
50 ),
51 ('buildtools/linux64/gn',
Primiano Tuccic2eb5102018-05-15 10:40:01 +010052 'https://storage.googleapis.com/chromium-gn/2f27ff0b6118e5886df976da5effa6003d19d1ce',
53 '2f27ff0b6118e5886df976da5effa6003d19d1ce',
Primiano Tucciae2879e2017-09-27 11:02:09 +090054 'linux2'
55 ),
56
Primiano Tucci104bd6d2017-10-12 00:10:24 +020057 # clang-format
58 ('buildtools/mac/clang-format',
59 'https://storage.googleapis.com/chromium-clang-format/0679b295e2ce2fce7919d1e8d003e497475f24a3',
60 '0679b295e2ce2fce7919d1e8d003e497475f24a3',
61 'darwin'
62 ),
63 ('buildtools/linux64/clang-format',
64 'https://storage.googleapis.com/chromium-clang-format/5349d1954e17f6ccafb6e6663b0f13cdb2bb33c8',
65 '5349d1954e17f6ccafb6e6663b0f13cdb2bb33c8',
66 'linux2'
67 ),
68 # Keep the SHA1 in sync with |clang_format_rev| in chromium //buildtools/DEPS.
69 ('buildtools/clang_format/script',
70 'https://chromium.googlesource.com/chromium/llvm-project/cfe/tools/clang-format.git',
71 '0653eee0c81ea04715c635dd0885e8096ff6ba6d',
72 'all'
73 ),
74
Primiano Tucciae2879e2017-09-27 11:02:09 +090075 # Ninja
76 ('buildtools/mac/ninja',
77 'https://storage.googleapis.com/fuchsia-build/fuchsia/ninja/mac/a1db595e824c50cf565fbf0af2437fd91b7babf4',
78 'a1db595e824c50cf565fbf0af2437fd91b7babf4',
79 'darwin'
80 ),
81 ('buildtools/linux64/ninja',
82 'https://storage.googleapis.com/fuchsia-build/fuchsia/ninja/linux64/d35b36c84a09f7e38b25947cafada10e8bf835bc',
83 'd35b36c84a09f7e38b25947cafada10e8bf835bc',
84 'linux2'
85 ),
86
Primiano Tuccid7750452017-09-29 14:38:51 +010087 # Keep in sync with Android's //external/googletest/README.version.
88 ('buildtools/googletest.zip',
89 'https://github.com/google/googletest/archive/ff07a5de0e81580547f1685e101194ed1a4fcd56.zip',
90 'c7edec7d7e6db1fc37a20710de9c4d89e3a3893b',
91 'all'
92 ),
93
94 # Keep in sync with Android's //external/protobuf/README.version.
95 ('buildtools/protobuf.zip',
96 'https://github.com/google/protobuf/releases/download/v3.0.0-beta-3/protobuf-cpp-3.0.0-beta-3.zip',
97 '3caec60aa9d8eefc8c3c3201b6b8ca19935edb89',
98 'all'
99 ),
100
Primiano Tuccib60d4b02017-11-10 11:03:00 +0000101 # libc++, libc++abi and libunwind for Linux where we need to rebuild the C++
102 # lib from sources. Keep the SHA1s in sync with Chrome's src/buildtools/DEPS.
Primiano Tuccid7750452017-09-29 14:38:51 +0100103 ('buildtools/libcxx',
104 'https://chromium.googlesource.com/chromium/llvm-project/libcxx.git',
Primiano Tuccic2eb5102018-05-15 10:40:01 +0100105 'ece1de8658d749e19c12cacd4458cc330eca94e3',
Primiano Tuccid7750452017-09-29 14:38:51 +0100106 'all'
107 ),
108 ('buildtools/libcxxabi',
109 'https://chromium.googlesource.com/chromium/llvm-project/libcxxabi.git',
Primiano Tuccic2eb5102018-05-15 10:40:01 +0100110 '05a73941f3fb177c4a891d4ff2a4ed5785e3b80c',
Primiano Tuccid7750452017-09-29 14:38:51 +0100111 'all'
112 ),
Primiano Tucci7278dea2017-10-31 11:50:32 +0000113 ('buildtools/libunwind',
114 'https://chromium.googlesource.com/external/llvm.org/libunwind.git',
Primiano Tuccic2eb5102018-05-15 10:40:01 +0100115 '0f3cbe4123f8afacd646bd4f5414aa6528ef8129',
Primiano Tucci7278dea2017-10-31 11:50:32 +0000116 'all'
117 ),
Hector Dearman88a10112017-10-12 11:07:10 +0100118
Primiano Tuccib60d4b02017-11-10 11:03:00 +0000119 # Keep the revision in sync with Chrome's CLANG_REVISION in
120 # tools/clang/scripts/update.py.
121 ('buildtools/clang.tgz',
Primiano Tuccic2eb5102018-05-15 10:40:01 +0100122 'https://commondatastorage.googleapis.com/chromium-browser-clang/Linux_x64/clang-331747-1.tgz',
123 '973073ca36ae9194019705ec7677852a30c4b54e',
Primiano Tuccib60d4b02017-11-10 11:03:00 +0000124 'linux2'
125 ),
126
Hector Dearman88a10112017-10-12 11:07:10 +0100127 # Benchmarking tool.
128 ('buildtools/benchmark.zip',
Lalit Magantic99d93c2018-03-22 15:09:30 +0000129 'https://github.com/google/benchmark/archive/v1.3.0.zip',
130 'f387e0df37d54bfd5be239e8d0d3ea2e2c3e34f4',
Hector Dearman88a10112017-10-12 11:07:10 +0100131 'all'
132 ),
Primiano Tucci38faa6f2018-04-01 20:12:08 +0200133
134 # Libbacktrace, for stacktraces in Linux/Android debug builds.
135 ('buildtools/libbacktrace.zip',
136 'https://github.com/ianlancetaylor/libbacktrace/archive/177940370e4a6b2509e92a0aaa9749184e64af43.zip',
137 'b723fe9d671d1ab54df1297f6afbf2893a41c3ea',
138 'all'
139 ),
Lalit Maganti6fe26e62018-05-23 12:14:38 +0100140
141 # Sqlite for the trace processing library.
142 ('buildtools/sqlite.zip',
143 'https://storage.googleapis.com/perfetto/sqlite-amalgamation-3230100.zip',
144 '98729f2c2d57d166e3d6d9862744c1d66388e286',
145 'all'
146 ),
Primiano Tucci0d72a312018-08-07 14:42:45 +0100147
148 # JsonCpp for legacy json import. Used only by the trace processor in
149 # standalone builds.
150 ('buildtools/jsoncpp.zip',
151 'https://github.com/open-source-parsers/jsoncpp/archive/1.0.0.zip',
152 '3219e26f2e249bb46b7d688478208c7ec138fea4',
153 'all'
154 ),
Florian Mayer475bd7e2018-08-07 20:04:03 +0100155
Florian Mayerf8335662018-08-08 11:30:32 +0100156 # These dependencies are for libunwindstack, which is used by src/profiling.
157 ('buildtools/android-core',
Florian Mayer475bd7e2018-08-07 20:04:03 +0100158 'https://android.googlesource.com/platform/system/core.git',
Florian Mayerb64d6b12018-08-30 10:46:30 -0700159 'ec004eb1b376d2d9008829a25f47ac3fcfd728ab',
Florian Mayer475bd7e2018-08-07 20:04:03 +0100160 'all'
161 ),
162
163 ('buildtools/lzma',
164 'https://android.googlesource.com/platform/external/lzma.git',
165 '7851dce6f4ca17f5caa1c93a4e0a45686b1d56c3',
166 'all'
167 ),
Hector Dearman7f71d0e2018-08-09 11:26:10 +0100168
Florian Mayerb64d6b12018-08-30 10:46:30 -0700169 ('buildtools/bionic',
170 'https://android.googlesource.com/platform/bionic.git',
171 '3fd45bba4857fdbf320b6e89d2ae0569d9463bf5',
172 'all'
173 ),
174
Hector Dearman7f71d0e2018-08-09 11:26:10 +0100175 # Example traces for regression tests.
176 ('buildtools/test_data.zip',
177 'https://storage.googleapis.com/perfetto/test-data-20180808.zip',
178 '4adec454b60a943dd58603d4be80d42b2db62cbd',
179 'all',
180 ),
Primiano Tuccid7750452017-09-29 14:38:51 +0100181]
182
183# Dependencies required to build Android code.
184# URLs and SHA1s taken from:
185# - https://dl.google.com/android/repository/repository-11.xml
186# - https://dl.google.com/android/repository/sys-img/android/sys-img.xml
187BUILD_DEPS_ANDROID = [
Primiano Tucciae2879e2017-09-27 11:02:09 +0900188 # Android NDK
189 ('buildtools/ndk.zip',
Florian Mayeraa5316b2018-08-20 17:45:12 -0700190 'https://dl.google.com/android/repository/android-ndk-r17b-darwin-x86_64.zip',
191 'f990aafaffec0b583d2c5420bfa622e52ac14248',
Primiano Tucciae2879e2017-09-27 11:02:09 +0900192 'darwin'
193 ),
194 ('buildtools/ndk.zip',
Florian Mayeraa5316b2018-08-20 17:45:12 -0700195 'https://dl.google.com/android/repository/android-ndk-r17b-linux-x86_64.zip',
196 'dd5762ee7ef4995ad04fe0c45a608c344d99ca9f',
Primiano Tucciae2879e2017-09-27 11:02:09 +0900197 'linux2'
198 ),
Primiano Tuccid7750452017-09-29 14:38:51 +0100199]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900200
Primiano Tuccid7750452017-09-29 14:38:51 +0100201# Dependencies required to run Android tests.
202TEST_DEPS_ANDROID = [
Lalit Maganti367fcd52018-02-05 16:06:13 +0000203 # Android emulator images.
204 ('buildtools/aosp-arm.zip',
205 'https://storage.googleapis.com/perfetto/aosp-02022018-arm.zip',
206 'a480d5e7d3ca888b0a58fe15ce76b1791537429a',
Primiano Tuccie7ca7c62018-04-07 08:28:03 +0200207 'all'
Primiano Tucciae2879e2017-09-27 11:02:09 +0900208 ),
209
Primiano Tuccid7750452017-09-29 14:38:51 +0100210 # platform-tools.zip contains adb binaries.
211 ('buildtools/android_sdk/platform-tools.zip',
212 'https://dl.google.com/android/repository/platform-tools_r26.0.0-darwin.zip',
213 'e75b6137dc444f777eb02f44a6d9819b3aabff82',
214 'darwin'
215 ),
216 ('buildtools/android_sdk/platform-tools.zip',
217 'https://dl.google.com/android/repository/platform-tools_r26.0.0-linux.zip',
218 '00de8a6631405b617c10f68cd11ff2e1cd528e23',
219 'linux2'
Primiano Tucciae2879e2017-09-27 11:02:09 +0900220 ),
Primiano Tucci0825bc82017-09-28 18:50:23 +0100221
Lalit Maganti367fcd52018-02-05 16:06:13 +0000222 # Android emulator binaries.
223 ('buildtools/emulator',
224 'https://android.googlesource.com/platform/prebuilts/android-emulator.git',
225 '4b260028dc27bc92c39bee9129cb2ba839970956',
226 'all'
Primiano Tucci0825bc82017-09-28 18:50:23 +0100227 ),
Primiano Tuccid7750452017-09-29 14:38:51 +0100228]
Primiano Tucciae2879e2017-09-27 11:02:09 +0900229
Primiano Tucci4bdc4c42018-05-10 15:52:33 +0100230UI_DEPS = [
231 ('buildtools/nodejs.tgz',
Primiano Tuccidca96092018-05-31 11:47:16 +0100232 'https://storage.googleapis.com/perfetto/node-v10.3.0-darwin-x64.tar.gz',
233 '6d9a122785f38c256add3b25f74adf125497861a',
Primiano Tucci4bdc4c42018-05-10 15:52:33 +0100234 'darwin'
235 ),
236 ('buildtools/nodejs.tgz',
Primiano Tuccidca96092018-05-31 11:47:16 +0100237 'https://storage.googleapis.com/perfetto/node-v10.3.0-linux-x64.tar.xz',
238 '118f6ea19f75089b3f12ac2ddfce357bff872b5e',
Primiano Tucci4bdc4c42018-05-10 15:52:33 +0100239 'linux2'
240 ),
241 ('buildtools/emsdk/emscripten.tgz',
242 'https://storage.googleapis.com/perfetto/emscripten-1.37.40.tar.gz',
243 '588c28221321ebbdfc8e3a6f47ea6106f589669b',
244 'all'
245 ),
246 ('buildtools/emsdk/llvm.tgz',
247 'https://storage.googleapis.com/perfetto/emscripten-llvm-e1.37.40-darwin.tar.gz',
248 '7a894ef0a52821c62f6abaac552dc4ce5d424607',
249 'darwin'
250 ),
251 ('buildtools/emsdk/llvm.tgz',
Primiano Tuccife199902018-06-04 12:33:04 +0200252 'https://storage.googleapis.com/perfetto/emscripten-llvm-e1.37.40-static-linux.tar.gz',
253 '478501b9b7a14884e546c84efe209a90052cbb07',
Primiano Tucci4bdc4c42018-05-10 15:52:33 +0100254 'linux2'
255 ),
256]
257
Primiano Tucciae2879e2017-09-27 11:02:09 +0900258ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
259
260
261def ReadFile(path):
262 if not os.path.exists(path):
263 return None
264 with open(path) as f:
265 return f.read().strip()
266
267
Primiano Tucci0825bc82017-09-28 18:50:23 +0100268def MkdirRecursive(path):
269 # Works with both relative and absolute paths
270 cwd = '/' if path.startswith('/') else ROOT_DIR
271 for part in path.split('/'):
Primiano Tucciae2879e2017-09-27 11:02:09 +0900272 cwd = os.path.join(cwd, part)
273 if not os.path.exists(cwd):
274 os.makedirs(cwd)
275 else:
276 assert(os.path.isdir(cwd))
277
278
279def HashLocalFile(path):
280 if not os.path.exists(path):
281 return None
282 with open(path, 'rb') as f:
283 return hashlib.sha1(f.read()).hexdigest()
284
285
286def ExtractZipfilePreservePermissions(zf, info, path):
287 zf.extract(info.filename, path=path)
288 target_path = os.path.join(path, info.filename)
289 min_acls = 0o755 if info.filename.endswith('/') else 0o644
290 os.chmod(target_path, (info.external_attr >> 16L) | min_acls)
291
292
Primiano Tucci0825bc82017-09-28 18:50:23 +0100293def IsGitRepoCheckoutOutAtRevision(path, revision):
294 return ReadFile(os.path.join(path, '.git', 'HEAD')) == revision
295
296
297def CheckoutGitRepo(path, git_url, revision):
298 if IsGitRepoCheckoutOutAtRevision(path, revision):
299 return
300 if os.path.exists(path):
301 shutil.rmtree(path)
302 MkdirRecursive(path)
303 logging.info('Fetching %s @ %s into %s', git_url, revision, path)
Lalit Maganti367fcd52018-02-05 16:06:13 +0000304 subprocess.check_call(['git', 'init', path], cwd=path)
305 subprocess.check_call(
306 ['git', 'fetch', '--depth', '1', git_url, revision], cwd=path)
Primiano Tucci0825bc82017-09-28 18:50:23 +0100307 subprocess.check_call(['git', 'checkout', revision, '--quiet'], cwd=path)
308 assert(IsGitRepoCheckoutOutAtRevision(path, revision))
309
Deepanjan Royacf8c072018-07-13 11:37:04 -0400310def InstallNodeModules():
311 ui_dir = os.path.join(ROOT_DIR, 'ui')
312 logging.info("Running npm install in {0}".format(ui_dir))
313 subprocess.check_call(
314 [os.path.join(ui_dir, 'npm'), 'install', '--no-save'],
315 cwd=os.path.join(ROOT_DIR, 'ui'))
Primiano Tucci0825bc82017-09-28 18:50:23 +0100316
Primiano Tucciae2879e2017-09-27 11:02:09 +0900317def Main():
318 parser = argparse.ArgumentParser()
Primiano Tuccid7750452017-09-29 14:38:51 +0100319 parser.add_argument('--no-android', action='store_true')
Primiano Tucci4bdc4c42018-05-10 15:52:33 +0100320 parser.add_argument('--ui', action='store_true')
Primiano Tucciae2879e2017-09-27 11:02:09 +0900321 args = parser.parse_args()
Primiano Tuccid7750452017-09-29 14:38:51 +0100322 deps = BUILD_DEPS_HOST
323 if not args.no_android:
324 deps += BUILD_DEPS_ANDROID + TEST_DEPS_ANDROID
Primiano Tucci4bdc4c42018-05-10 15:52:33 +0100325 if args.ui:
326 deps += UI_DEPS
Primiano Tuccid7750452017-09-29 14:38:51 +0100327 for rel_path, url, expected_sha1, platform in deps:
Lalit Maganti367fcd52018-02-05 16:06:13 +0000328 if (platform != 'all' and platform != sys.platform):
Primiano Tucciae2879e2017-09-27 11:02:09 +0900329 continue
Primiano Tucciae2879e2017-09-27 11:02:09 +0900330 local_path = os.path.join(ROOT_DIR, rel_path)
Primiano Tucci0825bc82017-09-28 18:50:23 +0100331 if url.endswith('.git'):
332 CheckoutGitRepo(local_path, url, expected_sha1)
333 continue
Primiano Tuccib60d4b02017-11-10 11:03:00 +0000334 is_zip = local_path.endswith('.zip') or local_path.endswith('.tgz')
Primiano Tucciae2879e2017-09-27 11:02:09 +0900335 zip_target_dir = local_path[:-4] if is_zip else None
336 zip_dir_stamp = os.path.join(zip_target_dir, '.stamp') if is_zip else None
337
338 if ((not is_zip and HashLocalFile(local_path) == expected_sha1) or
339 (is_zip and ReadFile(zip_dir_stamp) == expected_sha1)):
340 continue
341 MkdirRecursive(os.path.dirname(rel_path))
342 if HashLocalFile(local_path) != expected_sha1:
343 download_path = local_path + '.tmp'
344 logging.info('Downloading %s from %s', local_path, url)
345 urllib.urlretrieve(url, download_path)
346 os.chmod(download_path, 0o755)
347 if (HashLocalFile(download_path) != expected_sha1):
348 os.remove(download_path)
349 logging.fatal('SHA1 mismatch for %s', download_path)
350 return 1
351 os.rename(download_path, local_path)
352 assert(HashLocalFile(local_path) == expected_sha1)
353
354 if is_zip:
355 logging.info('Extracting %s into %s' % (local_path, zip_target_dir))
356 assert(os.path.commonprefix((ROOT_DIR, zip_target_dir)) == ROOT_DIR)
357 if os.path.exists(zip_target_dir):
358 logging.info('Deleting stale dir %s' % zip_target_dir)
359 shutil.rmtree(zip_target_dir)
Primiano Tucciae2879e2017-09-27 11:02:09 +0900360
Primiano Tuccib60d4b02017-11-10 11:03:00 +0000361 # Decompress the archive.
362 if local_path.endswith('.tgz'):
363 MkdirRecursive(zip_target_dir)
Primiano Tucci4bdc4c42018-05-10 15:52:33 +0100364 subprocess.check_call(['tar', '-xf', local_path], cwd=zip_target_dir)
Primiano Tuccib60d4b02017-11-10 11:03:00 +0000365 elif local_path.endswith('.zip'):
366 with zipfile.ZipFile(local_path, 'r') as zf:
367 for info in zf.infolist():
368 ExtractZipfilePreservePermissions(zf, info, zip_target_dir)
369
370 # If the zip contains one root folder, rebase one level up moving all
371 # its sub files and folders inside |target_dir|.
372 subdir = os.listdir(zip_target_dir)
373 if len(subdir) == 1:
374 subdir = os.path.join(zip_target_dir, subdir[0])
375 if os.path.isdir(subdir):
376 for subf in os.listdir(subdir):
377 shutil.move(os.path.join(subdir,subf), zip_target_dir)
378 os.rmdir(subdir)
379
380 # Create stamp and remove the archive.
381 with open(zip_dir_stamp, 'w') as stamp_file:
382 stamp_file.write(expected_sha1)
383 os.remove(local_path)
Primiano Tucciae2879e2017-09-27 11:02:09 +0900384
Deepanjan Royacf8c072018-07-13 11:37:04 -0400385 if args.ui:
386 # Needs to happen after nodejs is installed above.
387 InstallNodeModules()
Primiano Tucciae2879e2017-09-27 11:02:09 +0900388
389if __name__ == '__main__':
390 logging.basicConfig(level=logging.INFO)
391 sys.exit(Main())