Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 1 | #!/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 | |
| 16 | import argparse |
| 17 | import hashlib |
| 18 | import logging |
| 19 | import os |
| 20 | import shutil |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 21 | import subprocess |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 22 | import sys |
Sami Kyostila | c7ddac7 | 2019-06-05 21:43:40 +0100 | [diff] [blame] | 23 | import tempfile |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 24 | import zipfile |
| 25 | |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 26 | from collections import namedtuple |
Matthew Clarkson | 40e4819 | 2019-10-28 12:35:01 +0000 | [diff] [blame] | 27 | from platform import system |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 28 | |
Primiano Tucci | b60d4b0 | 2017-11-10 11:03:00 +0000 | [diff] [blame] | 29 | # The format for the deps below is the following: |
| 30 | # (target_folder, source_url, sha1, target_platform) |
| 31 | # |source_url| can be either a git repo or a http url. |
| 32 | # If a git repo, |sha1| is the committish that will be checked out. |
| 33 | # If a http url, |sha1| is the shasum of the original file. |
| 34 | # If the url is a .zip or .tgz file it will be automatically deflated under |
| 35 | # |target_folder|, taking care of stripping the root folder if it's a single |
| 36 | # root (to avoid ending up with buildtools/protobuf/protobuf-1.2.3/... and have |
| 37 | # instead just buildtools/protobuf). |
Matthew Clarkson | 40e4819 | 2019-10-28 12:35:01 +0000 | [diff] [blame] | 38 | # |target_platform| is either 'darwin', 'linux' or 'all' and applies the dep |
| 39 | # only on the given platform |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 40 | Dependency = namedtuple( |
| 41 | 'Dependency', ['target_folder', 'source_url', 'sha1', 'target_platform']) |
Primiano Tucci | b60d4b0 | 2017-11-10 11:03:00 +0000 | [diff] [blame] | 42 | |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 43 | # Dependencies required to build code on the host or when targeting desktop OS. |
| 44 | BUILD_DEPS_HOST = [ |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 45 | # GN |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 46 | Dependency('buildtools/mac/gn', |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 47 | 'https://storage.googleapis.com/perfetto/gn-mac-1695-83dad00a', |
| 48 | '4c0d45772aea4146699772165e8112fa76ceb295', 'darwin'), |
| 49 | Dependency( |
| 50 | 'buildtools/linux64/gn', |
| 51 | 'https://storage.googleapis.com/perfetto/gn-linux64-1695-83dad00a', |
| 52 | 'fcabfc379bccaa65b4e2fc791594ba124dafc7d0', 'linux'), |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 53 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 54 | # clang-format |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 55 | Dependency( |
| 56 | 'buildtools/mac/clang-format', |
| 57 | 'https://storage.googleapis.com/chromium-clang-format/025ca7c75f37ef4a40f3a67d81ddd11d7d0cdb9b', |
| 58 | '025ca7c75f37ef4a40f3a67d81ddd11d7d0cdb9b', 'darwin'), |
| 59 | Dependency( |
| 60 | 'buildtools/linux64/clang-format', |
| 61 | 'https://storage.googleapis.com/chromium-clang-format/942fc8b1789144b8071d3fc03ff0fcbe1cf81ac8', |
| 62 | '942fc8b1789144b8071d3fc03ff0fcbe1cf81ac8', 'linux'), |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 63 | # Keep the SHA1 in sync with |clang_format_rev| in chromium //buildtools/DEPS. |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 64 | Dependency( |
| 65 | 'buildtools/clang_format/script', |
| 66 | 'https://chromium.googlesource.com/chromium/llvm-project/cfe/tools/clang-format.git', |
| 67 | '96636aa0e9f047f17447f2d45a094d0b59ed7917', 'all'), |
Primiano Tucci | 104bd6d | 2017-10-12 00:10:24 +0200 | [diff] [blame] | 68 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 69 | # Ninja |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 70 | Dependency( |
| 71 | 'buildtools/mac/ninja', |
| 72 | 'https://storage.googleapis.com/perfetto/ninja-mac-c15b0698da038b2bd2e8970c14c75fadc06b1add', |
| 73 | 'c15b0698da038b2bd2e8970c14c75fadc06b1add', 'darwin'), |
| 74 | Dependency( |
| 75 | 'buildtools/linux64/ninja', |
| 76 | 'https://storage.googleapis.com/perfetto/ninja-linux64-c866952bda50c29a669222477309287119bbb7e8', |
| 77 | 'c866952bda50c29a669222477309287119bbb7e8', 'linux'), |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 78 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 79 | # Keep in sync with Android's //external/googletest/README.version. |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 80 | Dependency( |
| 81 | 'buildtools/googletest.zip', |
| 82 | 'https://github.com/google/googletest/archive/3f05f651ae3621db58468153e32016bc1397800b.zip', |
| 83 | '86384688f7c533ad325a505efc917e0cdf39a0ce', 'all'), |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 84 | |
Primiano Tucci | f550b25 | 2019-12-03 11:06:02 +0000 | [diff] [blame] | 85 | # Keep in sync with Chromium's //third_party/protobuf. |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 86 | Dependency( |
| 87 | 'buildtools/protobuf.zip', |
| 88 | 'https://github.com/protocolbuffers/protobuf/releases/download/v3.9.0/protobuf-cpp-3.9.0.zip', |
| 89 | 'c975536dffe9d9a3d362928aef4fb9f199012b98', 'all'), |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 90 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 91 | # libc++, libc++abi and libunwind for Linux where we need to rebuild the C++ |
| 92 | # lib from sources. Keep the SHA1s in sync with Chrome's src/buildtools/DEPS. |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 93 | Dependency( |
| 94 | 'buildtools/libcxx', |
| 95 | 'https://chromium.googlesource.com/chromium/llvm-project/libcxx.git', |
| 96 | '78d6a7767ed57b50122a161b91f59f19c9bd0d19', 'all'), |
| 97 | Dependency( |
| 98 | 'buildtools/libcxxabi', |
| 99 | 'https://chromium.googlesource.com/chromium/llvm-project/libcxxabi.git', |
| 100 | '0d529660e32d77d9111912d73f2c74fc5fa2a858', 'all'), |
| 101 | Dependency( |
| 102 | 'buildtools/libunwind', |
| 103 | 'https://chromium.googlesource.com/external/llvm.org/libunwind.git', |
| 104 | '69d9b84cca8354117b9fe9705a4430d789ee599b', 'all'), |
Hector Dearman | 88a1011 | 2017-10-12 11:07:10 +0100 | [diff] [blame] | 105 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 106 | # Keep the revision in sync with Chrome's PACKAGE_VERSION in |
| 107 | # tools/clang/scripts/update.py. |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 108 | Dependency( |
| 109 | 'buildtools/clang.tgz', |
| 110 | 'https://commondatastorage.googleapis.com/chromium-browser-clang/Linux_x64/clang-n332890-c2443155-2.tgz', |
| 111 | 'd6501ffdb5dbb0ffe8a4b873cc092a9929e661ec', 'linux'), |
Primiano Tucci | a65497e | 2018-09-26 19:53:58 +0100 | [diff] [blame] | 112 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 113 | # Keep in sync with chromium DEPS. |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 114 | Dependency( |
| 115 | 'buildtools/libfuzzer', |
| 116 | 'https://chromium.googlesource.com/chromium/llvm-project/compiler-rt/lib/fuzzer.git', |
| 117 | 'debe7d2d1982e540fbd6bd78604bf001753f9e74', 'linux'), |
Primiano Tucci | b60d4b0 | 2017-11-10 11:03:00 +0000 | [diff] [blame] | 118 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 119 | # Benchmarking tool. |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 120 | Dependency('buildtools/benchmark.zip', |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 121 | 'https://github.com/google/benchmark/archive/v1.5.0.zip', |
| 122 | 'a9c9bd8a28db82f5ba02998197cfcc4db5a67507', 'all'), |
Primiano Tucci | 38faa6f | 2018-04-01 20:12:08 +0200 | [diff] [blame] | 123 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 124 | # Libbacktrace, for stacktraces in Linux/Android debug builds. |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 125 | Dependency( |
| 126 | 'buildtools/libbacktrace.zip', |
| 127 | 'https://github.com/ianlancetaylor/libbacktrace/archive/177940370e4a6b2509e92a0aaa9749184e64af43.zip', |
| 128 | 'b723fe9d671d1ab54df1297f6afbf2893a41c3ea', 'all'), |
Lalit Maganti | 6fe26e6 | 2018-05-23 12:14:38 +0100 | [diff] [blame] | 129 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 130 | # Sqlite for the trace processing library. |
| 131 | # This is the amalgamated source whose compiled output is meant to be faster. |
| 132 | # We still pull the full source for the extensions (not amalgamated). |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 133 | Dependency( |
| 134 | 'buildtools/sqlite.zip', |
| 135 | 'https://storage.googleapis.com/perfetto/sqlite-amalgamation-3320300.zip', |
| 136 | '0c805bea134712a903290a26b2a61c3a8a3bd8cc', 'all'), |
| 137 | Dependency( |
| 138 | 'buildtools/sqlite_src.zip', |
| 139 | 'https://storage.googleapis.com/perfetto/sqlite-src-3320300.zip', |
| 140 | 'd46f60e0fb2b1a959ae59bfa881fc95a510c4d21', 'all'), |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 141 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 142 | # JsonCpp for legacy json import. Used only by the trace processor in |
| 143 | # standalone builds. |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 144 | Dependency( |
| 145 | 'buildtools/jsoncpp.zip', |
| 146 | 'https://github.com/open-source-parsers/jsoncpp/archive/1.9.3.zip', |
| 147 | 'ec1cf26bf4e60822dbb31576e1a83ce1b9fbc36a', 'all'), |
Florian Mayer | 475bd7e | 2018-08-07 20:04:03 +0100 | [diff] [blame] | 148 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 149 | # These dependencies are for libunwindstack, which is used by src/profiling. |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 150 | Dependency('buildtools/android-core', |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 151 | 'https://android.googlesource.com/platform/system/core.git', |
| 152 | '8bf4e29e44098e3232ff646331675fb113064162', 'all'), |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 153 | Dependency('buildtools/lzma', |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 154 | 'https://android.googlesource.com/platform/external/lzma.git', |
| 155 | '7851dce6f4ca17f5caa1c93a4e0a45686b1d56c3', 'all'), |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 156 | Dependency('buildtools/zlib', |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 157 | 'https://android.googlesource.com/platform/external/zlib.git', |
| 158 | 'dfa0646a03b4e1707469e04dc931b09774968fe6', 'all'), |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 159 | Dependency('buildtools/bionic', |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 160 | 'https://android.googlesource.com/platform/bionic.git', |
| 161 | 'a60488109cda997dfd83832731c8527feaa2825e', 'all'), |
Florian Mayer | 475bd7e | 2018-08-07 20:04:03 +0100 | [diff] [blame] | 162 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 163 | # Example traces for regression tests. |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 164 | Dependency( |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 165 | 'buildtools/test_data.zip', |
Florian Mayer | 192c15f | 2020-07-31 10:44:27 +0100 | [diff] [blame^] | 166 | 'https://storage.googleapis.com/perfetto/test-data-20200730-163541.zip', |
| 167 | '21531fb582e98c8c459f3e7a90bce5b6dedd1035', |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 168 | 'all', |
| 169 | ), |
Hector Dearman | 7f71d0e | 2018-08-09 11:26:10 +0100 | [diff] [blame] | 170 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 171 | # Linenoise, used only by trace_processor in standalone builds. |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 172 | Dependency('buildtools/linenoise', |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 173 | 'https://fuchsia.googlesource.com/third_party/linenoise.git', |
| 174 | 'c894b9e59f02203dbe4e2be657572cf88c4230c3', 'all'), |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 175 | ] |
| 176 | |
| 177 | # Dependencies required to build Android code. |
| 178 | # URLs and SHA1s taken from: |
| 179 | # - https://dl.google.com/android/repository/repository-11.xml |
| 180 | # - https://dl.google.com/android/repository/sys-img/android/sys-img.xml |
| 181 | BUILD_DEPS_ANDROID = [ |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 182 | # Android NDK |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 183 | Dependency( |
| 184 | 'buildtools/ndk.zip', |
| 185 | 'https://dl.google.com/android/repository/android-ndk-r17b-darwin-x86_64.zip', |
| 186 | 'f990aafaffec0b583d2c5420bfa622e52ac14248', 'darwin'), |
| 187 | Dependency( |
| 188 | 'buildtools/ndk.zip', |
| 189 | 'https://dl.google.com/android/repository/android-ndk-r17b-linux-x86_64.zip', |
| 190 | 'dd5762ee7ef4995ad04fe0c45a608c344d99ca9f', 'linux'), |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 191 | ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 192 | |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 193 | # Dependencies required to run Android tests. |
| 194 | TEST_DEPS_ANDROID = [ |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 195 | # Android emulator images. |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 196 | Dependency('buildtools/aosp-arm.zip', |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 197 | 'https://storage.googleapis.com/perfetto/aosp-02022018-arm.zip', |
| 198 | 'a480d5e7d3ca888b0a58fe15ce76b1791537429a', 'all'), |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 199 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 200 | # platform-tools.zip contains adb binaries. |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 201 | Dependency( |
| 202 | 'buildtools/android_sdk/platform-tools.zip', |
| 203 | 'https://dl.google.com/android/repository/platform-tools_r26.0.0-darwin.zip', |
| 204 | 'e75b6137dc444f777eb02f44a6d9819b3aabff82', 'darwin'), |
| 205 | Dependency( |
| 206 | 'buildtools/android_sdk/platform-tools.zip', |
| 207 | 'https://dl.google.com/android/repository/platform-tools_r26.0.0-linux.zip', |
| 208 | '00de8a6631405b617c10f68cd11ff2e1cd528e23', 'linux'), |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 209 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 210 | # Android emulator binaries. |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 211 | Dependency( |
| 212 | 'buildtools/emulator', |
| 213 | 'https://android.googlesource.com/platform/prebuilts/android-emulator.git', |
| 214 | '4b260028dc27bc92c39bee9129cb2ba839970956', 'all'), |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 215 | ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 216 | |
Primiano Tucci | 1c752c1 | 2018-10-23 09:27:19 +0100 | [diff] [blame] | 217 | # This variable is updated by tools/roll-catapult-trace-viewer. |
Isabelle Taylor | 4a69bd8 | 2020-06-08 09:24:58 +0100 | [diff] [blame] | 218 | CATAPULT_SHA1 = '5f77256e1b24851a05e8580438b532e2480dd7fd' |
Primiano Tucci | 1c752c1 | 2018-10-23 09:27:19 +0100 | [diff] [blame] | 219 | |
Primiano Tucci | 32ea103 | 2020-01-07 13:53:23 +0000 | [diff] [blame] | 220 | TYPEFACES_SHA1 = '4fb455de506f8a2859dc5264b8448c2559b08ab8' |
Hector Dearman | 6177b75 | 2019-01-24 10:17:32 +0000 | [diff] [blame] | 221 | |
Primiano Tucci | 4bdc4c4 | 2018-05-10 15:52:33 +0100 | [diff] [blame] | 222 | UI_DEPS = [ |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 223 | Dependency( |
| 224 | 'buildtools/nodejs.tgz', |
| 225 | 'https://storage.googleapis.com/perfetto/node-v12.18.3-darwin-x64.tar.gz', |
| 226 | '8a7a901b7c1447235bfe8575a1c8a78eb14afbcf', 'darwin'), |
| 227 | Dependency( |
| 228 | 'buildtools/nodejs.tgz', |
| 229 | 'https://storage.googleapis.com/perfetto/node-v12.18.3-linux-x64.tar.gz', |
| 230 | 'c02138c2f9a813f88e81d31c4f9e5652dd7a9684', 'linux'), |
| 231 | Dependency( |
| 232 | 'buildtools/emsdk/emscripten.tgz', |
| 233 | 'https://storage.googleapis.com/perfetto/emscripten-1.37.40.tar.gz', |
| 234 | '588c28221321ebbdfc8e3a6f47ea6106f589669b', 'all'), |
| 235 | Dependency( |
| 236 | 'buildtools/emsdk/llvm.tgz', |
| 237 | 'https://storage.googleapis.com/perfetto/emscripten-llvm-e1.37.40-darwin.tar.gz', |
| 238 | '7a894ef0a52821c62f6abaac552dc4ce5d424607', 'darwin'), |
| 239 | Dependency( |
| 240 | 'buildtools/emsdk/llvm.tgz', |
| 241 | 'https://storage.googleapis.com/perfetto/emscripten-llvm-e1.37.40-static-linux.tar.gz', |
| 242 | '478501b9b7a14884e546c84efe209a90052cbb07', 'linux'), |
| 243 | Dependency( |
| 244 | 'buildtools/d8.tgz', |
| 245 | 'https://storage.googleapis.com/perfetto/d8-linux-5.7.492.65.tar.gz', |
| 246 | '95e82ad7faf0a6f74d950c2aa65e3858b7bdb6c6', 'linux'), |
| 247 | Dependency( |
| 248 | 'buildtools/d8.tgz', |
| 249 | 'https://storage.googleapis.com/perfetto/d8-darwin-6.6.346.32.tar.gz', |
| 250 | '1abd630619bb1977ab62095570a113d782a1545d', 'darwin'), |
| 251 | Dependency( |
| 252 | 'buildtools/catapult_trace_viewer.tgz', |
| 253 | 'https://storage.googleapis.com/perfetto/catapult_trace_viewer-%s.tar.gz' |
| 254 | % CATAPULT_SHA1, CATAPULT_SHA1, 'all'), |
| 255 | Dependency( |
| 256 | 'buildtools/typefaces.tgz', |
| 257 | 'https://storage.googleapis.com/perfetto/typefaces-%s.tar.gz' % |
| 258 | TYPEFACES_SHA1, TYPEFACES_SHA1, 'all') |
Primiano Tucci | 4bdc4c4 | 2018-05-10 15:52:33 +0100 | [diff] [blame] | 259 | ] |
| 260 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 261 | ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
Primiano Tucci | 69132a1 | 2020-02-07 22:33:06 +0000 | [diff] [blame] | 262 | UI_DIR = os.path.join(ROOT_DIR, 'ui') |
| 263 | NODE_MODULES_STATUS_FILE = os.path.join(UI_DIR, 'node_modules', '.last_install') |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 264 | |
| 265 | |
Primiano Tucci | 585b7e8 | 2020-05-14 11:19:10 +0100 | [diff] [blame] | 266 | def DownloadURL(url, out_file): |
Primiano Tucci | 9ff392c | 2020-05-15 22:35:38 +0100 | [diff] [blame] | 267 | subprocess.check_call(['curl', '-L', '-#', '-o', out_file, url]) |
Primiano Tucci | 585b7e8 | 2020-05-14 11:19:10 +0100 | [diff] [blame] | 268 | |
| 269 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 270 | def ReadFile(path): |
| 271 | if not os.path.exists(path): |
| 272 | return None |
| 273 | with open(path) as f: |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 274 | return f.read().strip() |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 275 | |
| 276 | |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 277 | def MkdirRecursive(path): |
| 278 | # Works with both relative and absolute paths |
| 279 | cwd = '/' if path.startswith('/') else ROOT_DIR |
| 280 | for part in path.split('/'): |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 281 | cwd = os.path.join(cwd, part) |
| 282 | if not os.path.exists(cwd): |
| 283 | os.makedirs(cwd) |
| 284 | else: |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 285 | assert (os.path.isdir(cwd)) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 286 | |
| 287 | |
| 288 | def HashLocalFile(path): |
| 289 | if not os.path.exists(path): |
| 290 | return None |
| 291 | with open(path, 'rb') as f: |
| 292 | return hashlib.sha1(f.read()).hexdigest() |
| 293 | |
| 294 | |
| 295 | def ExtractZipfilePreservePermissions(zf, info, path): |
| 296 | zf.extract(info.filename, path=path) |
| 297 | target_path = os.path.join(path, info.filename) |
| 298 | min_acls = 0o755 if info.filename.endswith('/') else 0o644 |
Matthew Clarkson | 9a5dfa5 | 2019-10-03 09:54:04 +0100 | [diff] [blame] | 299 | os.chmod(target_path, (info.external_attr >> 16) | min_acls) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 300 | |
| 301 | |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 302 | def IsGitRepoCheckoutOutAtRevision(path, revision): |
| 303 | return ReadFile(os.path.join(path, '.git', 'HEAD')) == revision |
| 304 | |
| 305 | |
Primiano Tucci | 69132a1 | 2020-02-07 22:33:06 +0000 | [diff] [blame] | 306 | def CheckoutGitRepo(path, git_url, revision, check_only): |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 307 | if IsGitRepoCheckoutOutAtRevision(path, revision): |
Eric Seckler | 676421f | 2019-02-12 14:43:31 +0000 | [diff] [blame] | 308 | return False |
Primiano Tucci | 69132a1 | 2020-02-07 22:33:06 +0000 | [diff] [blame] | 309 | if check_only: |
| 310 | return True |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 311 | if os.path.exists(path): |
| 312 | shutil.rmtree(path) |
| 313 | MkdirRecursive(path) |
| 314 | logging.info('Fetching %s @ %s into %s', git_url, revision, path) |
Lalit Maganti | 367fcd5 | 2018-02-05 16:06:13 +0000 | [diff] [blame] | 315 | subprocess.check_call(['git', 'init', path], cwd=path) |
| 316 | subprocess.check_call( |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 317 | ['git', 'fetch', '--quiet', '--depth', '1', git_url, revision], cwd=path) |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 318 | subprocess.check_call(['git', 'checkout', revision, '--quiet'], cwd=path) |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 319 | assert (IsGitRepoCheckoutOutAtRevision(path, revision)) |
Eric Seckler | 676421f | 2019-02-12 14:43:31 +0000 | [diff] [blame] | 320 | return True |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 321 | |
Sami Kyostila | c7ddac7 | 2019-06-05 21:43:40 +0100 | [diff] [blame] | 322 | |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 323 | def InstallNodeModules(force_clean=False): |
| 324 | if force_clean: |
| 325 | node_modules = os.path.join(UI_DIR, 'node_modules') |
| 326 | logging.info('Clearing %s', node_modules) |
| 327 | subprocess.check_call(['git', 'clean', '-qxffd', node_modules], |
| 328 | cwd=ROOT_DIR) |
Primiano Tucci | 69132a1 | 2020-02-07 22:33:06 +0000 | [diff] [blame] | 329 | logging.info("Running npm install in {0}".format(UI_DIR)) |
| 330 | subprocess.check_call([os.path.join(UI_DIR, 'npm'), 'install', '--no-save'], |
| 331 | cwd=UI_DIR) |
| 332 | with open(NODE_MODULES_STATUS_FILE, 'w') as f: |
| 333 | f.write(HashLocalFile(os.path.join(UI_DIR, 'package-lock.json'))) |
| 334 | |
| 335 | |
| 336 | def CheckNodeModules(): |
| 337 | """Returns True if the modules are up-to-date. |
| 338 | |
| 339 | There doesn't seem to be an easy way to check node modules versions. Instead |
| 340 | just check if package-lock.json changed since the last `npm install` call. |
| 341 | """ |
| 342 | if not os.path.exists(NODE_MODULES_STATUS_FILE): |
| 343 | return False |
| 344 | with open(NODE_MODULES_STATUS_FILE, 'r') as f: |
| 345 | actual = f.read() |
| 346 | expected = HashLocalFile(os.path.join(UI_DIR, 'package-lock.json')) |
| 347 | return expected == actual |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 348 | |
Sami Kyostila | c7ddac7 | 2019-06-05 21:43:40 +0100 | [diff] [blame] | 349 | |
| 350 | def CheckHashes(): |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 351 | for deps in [BUILD_DEPS_HOST, BUILD_DEPS_ANDROID, TEST_DEPS_ANDROID, UI_DEPS]: |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 352 | for dep in deps: |
| 353 | if dep.source_url.endswith('.git'): |
Sami Kyostila | c7ddac7 | 2019-06-05 21:43:40 +0100 | [diff] [blame] | 354 | continue |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 355 | logging.info('Downloading %s from %s', dep.target_platform, |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 356 | dep.source_url) |
Sami Kyostila | c7ddac7 | 2019-06-05 21:43:40 +0100 | [diff] [blame] | 357 | with tempfile.NamedTemporaryFile(delete=False) as f: |
| 358 | f.close() |
Primiano Tucci | 585b7e8 | 2020-05-14 11:19:10 +0100 | [diff] [blame] | 359 | DownloadURL(url, f.name) |
Sami Kyostila | c7ddac7 | 2019-06-05 21:43:40 +0100 | [diff] [blame] | 360 | actual_sha1 = HashLocalFile(f.name) |
| 361 | os.unlink(f.name) |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 362 | if (actual_sha1 != dep.sha1): |
Sami Kyostila | c7ddac7 | 2019-06-05 21:43:40 +0100 | [diff] [blame] | 363 | logging.fatal('SHA1 mismatch for {} expected {} was {}'.format( |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 364 | dep.source_url, dep.sha1, actual_sha1)) |
Sami Kyostila | c7ddac7 | 2019-06-05 21:43:40 +0100 | [diff] [blame] | 365 | |
| 366 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 367 | def Main(): |
| 368 | parser = argparse.ArgumentParser() |
Primiano Tucci | 69132a1 | 2020-02-07 22:33:06 +0000 | [diff] [blame] | 369 | parser.add_argument('--android', action='store_true') |
Primiano Tucci | 4bdc4c4 | 2018-05-10 15:52:33 +0100 | [diff] [blame] | 370 | parser.add_argument('--ui', action='store_true') |
Primiano Tucci | 69132a1 | 2020-02-07 22:33:06 +0000 | [diff] [blame] | 371 | parser.add_argument('--check-only') |
| 372 | parser.add_argument('--verify', help='Check all URLs', action='store_true') |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 373 | args = parser.parse_args() |
Primiano Tucci | 69132a1 | 2020-02-07 22:33:06 +0000 | [diff] [blame] | 374 | if args.verify: |
Sami Kyostila | c7ddac7 | 2019-06-05 21:43:40 +0100 | [diff] [blame] | 375 | CheckHashes() |
| 376 | return 0 |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 377 | deps = BUILD_DEPS_HOST |
Primiano Tucci | 69132a1 | 2020-02-07 22:33:06 +0000 | [diff] [blame] | 378 | if args.android: |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 379 | deps += BUILD_DEPS_ANDROID + TEST_DEPS_ANDROID |
Primiano Tucci | 4bdc4c4 | 2018-05-10 15:52:33 +0100 | [diff] [blame] | 380 | if args.ui: |
| 381 | deps += UI_DEPS |
Eric Seckler | 6e828f3 | 2019-01-02 11:10:56 +0000 | [diff] [blame] | 382 | deps_updated = False |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 383 | nodejs_updated = False |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 384 | |
| 385 | for dep in deps: |
| 386 | if (dep.target_platform != 'all' and |
| 387 | dep.target_platform != system().lower()): |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 388 | continue |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 389 | local_path = os.path.join(ROOT_DIR, dep.target_folder) |
| 390 | if dep.source_url.endswith('.git'): |
| 391 | deps_updated |= CheckoutGitRepo(local_path, dep.source_url, dep.sha1, |
Primiano Tucci | 69132a1 | 2020-02-07 22:33:06 +0000 | [diff] [blame] | 392 | args.check_only) |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 393 | continue |
Primiano Tucci | b60d4b0 | 2017-11-10 11:03:00 +0000 | [diff] [blame] | 394 | is_zip = local_path.endswith('.zip') or local_path.endswith('.tgz') |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 395 | zip_target_dir = local_path[:-4] if is_zip else None |
| 396 | zip_dir_stamp = os.path.join(zip_target_dir, '.stamp') if is_zip else None |
| 397 | |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 398 | if ((not is_zip and HashLocalFile(local_path) == dep.sha1) or |
| 399 | (is_zip and ReadFile(zip_dir_stamp) == dep.sha1)): |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 400 | continue |
Eric Seckler | 6e828f3 | 2019-01-02 11:10:56 +0000 | [diff] [blame] | 401 | deps_updated = True |
Primiano Tucci | 69132a1 | 2020-02-07 22:33:06 +0000 | [diff] [blame] | 402 | if args.check_only: |
| 403 | continue |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 404 | MkdirRecursive(os.path.dirname(dep.target_folder)) |
| 405 | if HashLocalFile(local_path) != dep.sha1: |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 406 | download_path = local_path + '.tmp' |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 407 | logging.info('Downloading %s from %s', local_path, dep.source_url) |
| 408 | DownloadURL(dep.source_url, download_path) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 409 | os.chmod(download_path, 0o755) |
Hector Dearman | d9628d3 | 2018-10-17 14:38:26 +0100 | [diff] [blame] | 410 | actual_sha1 = HashLocalFile(download_path) |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 411 | if (actual_sha1 != dep.sha1): |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 412 | os.remove(download_path) |
Hector Dearman | d9628d3 | 2018-10-17 14:38:26 +0100 | [diff] [blame] | 413 | logging.fatal('SHA1 mismatch for {} expected {} was {}'.format( |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 414 | download_path, dep.sha1, actual_sha1)) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 415 | return 1 |
| 416 | os.rename(download_path, local_path) |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 417 | if 'nodejs' in dep.target_folder: |
| 418 | nodejs_updated = True |
| 419 | |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 420 | assert (HashLocalFile(local_path) == dep.sha1) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 421 | |
| 422 | if is_zip: |
| 423 | logging.info('Extracting %s into %s' % (local_path, zip_target_dir)) |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 424 | assert (os.path.commonprefix((ROOT_DIR, zip_target_dir)) == ROOT_DIR) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 425 | if os.path.exists(zip_target_dir): |
| 426 | logging.info('Deleting stale dir %s' % zip_target_dir) |
| 427 | shutil.rmtree(zip_target_dir) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 428 | |
Primiano Tucci | b60d4b0 | 2017-11-10 11:03:00 +0000 | [diff] [blame] | 429 | # Decompress the archive. |
| 430 | if local_path.endswith('.tgz'): |
| 431 | MkdirRecursive(zip_target_dir) |
Primiano Tucci | 4bdc4c4 | 2018-05-10 15:52:33 +0100 | [diff] [blame] | 432 | subprocess.check_call(['tar', '-xf', local_path], cwd=zip_target_dir) |
Primiano Tucci | b60d4b0 | 2017-11-10 11:03:00 +0000 | [diff] [blame] | 433 | elif local_path.endswith('.zip'): |
| 434 | with zipfile.ZipFile(local_path, 'r') as zf: |
| 435 | for info in zf.infolist(): |
| 436 | ExtractZipfilePreservePermissions(zf, info, zip_target_dir) |
| 437 | |
| 438 | # If the zip contains one root folder, rebase one level up moving all |
| 439 | # its sub files and folders inside |target_dir|. |
| 440 | subdir = os.listdir(zip_target_dir) |
| 441 | if len(subdir) == 1: |
| 442 | subdir = os.path.join(zip_target_dir, subdir[0]) |
| 443 | if os.path.isdir(subdir): |
| 444 | for subf in os.listdir(subdir): |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 445 | shutil.move(os.path.join(subdir, subf), zip_target_dir) |
Primiano Tucci | b60d4b0 | 2017-11-10 11:03:00 +0000 | [diff] [blame] | 446 | os.rmdir(subdir) |
| 447 | |
| 448 | # Create stamp and remove the archive. |
| 449 | with open(zip_dir_stamp, 'w') as stamp_file: |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 450 | stamp_file.write(dep.sha1) |
Primiano Tucci | b60d4b0 | 2017-11-10 11:03:00 +0000 | [diff] [blame] | 451 | os.remove(local_path) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 452 | |
Deepanjan Roy | acf8c07 | 2018-07-13 11:37:04 -0400 | [diff] [blame] | 453 | if args.ui: |
| 454 | # Needs to happen after nodejs is installed above. |
Primiano Tucci | 69132a1 | 2020-02-07 22:33:06 +0000 | [diff] [blame] | 455 | if args.check_only: |
| 456 | deps_updated = not CheckNodeModules() |
| 457 | else: |
Primiano Tucci | 43f111a | 2020-07-27 20:37:52 +0200 | [diff] [blame] | 458 | InstallNodeModules(force_clean=nodejs_updated) |
Primiano Tucci | 69132a1 | 2020-02-07 22:33:06 +0000 | [diff] [blame] | 459 | |
| 460 | if args.check_only: |
| 461 | if not deps_updated: |
| 462 | with open(args.check_only, 'w') as f: |
| 463 | f.write('OK') # The content is irrelevant, just keep GN happy. |
| 464 | return 0 |
Jordan Bayles | 8c6a4bc | 2020-07-16 20:20:48 -0700 | [diff] [blame] | 465 | argz = ' '.join([x for x in sys.argv[1:] if '--check-only' not in x]) |
Primiano Tucci | 69132a1 | 2020-02-07 22:33:06 +0000 | [diff] [blame] | 466 | sys.stderr.write('\033[91mBuild deps are stale. ' + |
| 467 | 'Please run tools/install-build-deps %s\033[0m' % argz) |
| 468 | return 1 |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 469 | |
Eric Seckler | 6e828f3 | 2019-01-02 11:10:56 +0000 | [diff] [blame] | 470 | if deps_updated: |
| 471 | # Stale binary files may be compiled against old sysroot headers that aren't |
| 472 | # tracked by gn. |
Matthew Clarkson | 9a5dfa5 | 2019-10-03 09:54:04 +0100 | [diff] [blame] | 473 | logging.warning('Remember to run "gn clean <output_directory>" ' + |
| 474 | 'to avoid stale binary files.') |
Eric Seckler | 6e828f3 | 2019-01-02 11:10:56 +0000 | [diff] [blame] | 475 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 476 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 477 | if __name__ == '__main__': |
| 478 | logging.basicConfig(level=logging.INFO) |
| 479 | sys.exit(Main()) |