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 | |
Matthew Clarkson | 9a5dfa5 | 2019-10-03 09:54:04 +0100 | [diff] [blame] | 29 | from compat import urlretrieve |
| 30 | |
Primiano Tucci | b60d4b0 | 2017-11-10 11:03:00 +0000 | [diff] [blame] | 31 | # 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). |
Matthew Clarkson | 40e4819 | 2019-10-28 12:35:01 +0000 | [diff] [blame] | 40 | # |target_platform| is either 'darwin', 'linux' or 'all' and applies the dep |
| 41 | # only on the given 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 |
| 46 | ('buildtools/mac/gn', |
| 47 | 'https://storage.googleapis.com/perfetto/gn-mac-b5b65ca39d93a7cde9fa713be31b114755252f28', |
| 48 | 'b5b65ca39d93a7cde9fa713be31b114755252f28', 'darwin'), |
| 49 | ('buildtools/linux64/gn', |
| 50 | 'https://storage.googleapis.com/perfetto/gn-linux64-1370d9c5358868b7b66292821b6fe61950826870', |
Matthew Clarkson | 40e4819 | 2019-10-28 12:35:01 +0000 | [diff] [blame] | 51 | '1370d9c5358868b7b66292821b6fe61950826870', 'linux'), |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 52 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 53 | # clang-format |
| 54 | ('buildtools/mac/clang-format', |
| 55 | 'https://storage.googleapis.com/chromium-clang-format/025ca7c75f37ef4a40f3a67d81ddd11d7d0cdb9b', |
| 56 | '025ca7c75f37ef4a40f3a67d81ddd11d7d0cdb9b', 'darwin'), |
| 57 | ('buildtools/linux64/clang-format', |
| 58 | 'https://storage.googleapis.com/chromium-clang-format/942fc8b1789144b8071d3fc03ff0fcbe1cf81ac8', |
Matthew Clarkson | 40e4819 | 2019-10-28 12:35:01 +0000 | [diff] [blame] | 59 | '942fc8b1789144b8071d3fc03ff0fcbe1cf81ac8', 'linux'), |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 60 | # Keep the SHA1 in sync with |clang_format_rev| in chromium //buildtools/DEPS. |
| 61 | ('buildtools/clang_format/script', |
| 62 | 'https://chromium.googlesource.com/chromium/llvm-project/cfe/tools/clang-format.git', |
| 63 | '96636aa0e9f047f17447f2d45a094d0b59ed7917', 'all'), |
Primiano Tucci | 104bd6d | 2017-10-12 00:10:24 +0200 | [diff] [blame] | 64 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 65 | # Ninja |
| 66 | ('buildtools/mac/ninja', |
| 67 | 'https://storage.googleapis.com/perfetto/ninja-mac-c15b0698da038b2bd2e8970c14c75fadc06b1add', |
| 68 | 'c15b0698da038b2bd2e8970c14c75fadc06b1add', 'darwin'), |
| 69 | ('buildtools/linux64/ninja', |
| 70 | 'https://storage.googleapis.com/perfetto/ninja-linux64-c866952bda50c29a669222477309287119bbb7e8', |
Matthew Clarkson | 40e4819 | 2019-10-28 12:35:01 +0000 | [diff] [blame] | 71 | 'c866952bda50c29a669222477309287119bbb7e8', 'linux'), |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 72 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 73 | # Keep in sync with Android's //external/googletest/README.version. |
| 74 | ('buildtools/googletest.zip', |
Ryan Savitski | b08b9cb | 2019-11-01 17:36:19 +0000 | [diff] [blame] | 75 | 'https://github.com/google/googletest/archive/3f05f651ae3621db58468153e32016bc1397800b.zip', |
| 76 | '86384688f7c533ad325a505efc917e0cdf39a0ce', 'all'), |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 77 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 78 | # Keep in sync with Android's //external/protobuf/README.version. |
| 79 | ('buildtools/protobuf.zip', |
| 80 | 'https://github.com/google/protobuf/releases/download/v3.0.0-beta-3/protobuf-cpp-3.0.0-beta-3.zip', |
| 81 | '3caec60aa9d8eefc8c3c3201b6b8ca19935edb89', 'all'), |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 82 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 83 | # libc++, libc++abi and libunwind for Linux where we need to rebuild the C++ |
| 84 | # lib from sources. Keep the SHA1s in sync with Chrome's src/buildtools/DEPS. |
| 85 | ('buildtools/libcxx', |
| 86 | 'https://chromium.googlesource.com/chromium/llvm-project/libcxx.git', |
| 87 | '5938e0582bac570a41edb3d6a2217c299adc1bc6', 'all'), |
| 88 | ('buildtools/libcxxabi', |
| 89 | 'https://chromium.googlesource.com/chromium/llvm-project/libcxxabi.git', |
| 90 | '0d529660e32d77d9111912d73f2c74fc5fa2a858', 'all'), |
| 91 | ('buildtools/libunwind', |
| 92 | 'https://chromium.googlesource.com/external/llvm.org/libunwind.git', |
| 93 | '69d9b84cca8354117b9fe9705a4430d789ee599b', 'all'), |
Hector Dearman | 88a1011 | 2017-10-12 11:07:10 +0100 | [diff] [blame] | 94 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 95 | # Keep the revision in sync with Chrome's PACKAGE_VERSION in |
| 96 | # tools/clang/scripts/update.py. |
| 97 | ('buildtools/clang.tgz', |
| 98 | 'https://commondatastorage.googleapis.com/chromium-browser-clang/Linux_x64/clang-365097-f7e52fbd-8.tgz', |
Matthew Clarkson | 40e4819 | 2019-10-28 12:35:01 +0000 | [diff] [blame] | 99 | 'fe1b1e5bd7381ae655661cb9658487389561568d', 'linux'), |
Primiano Tucci | a65497e | 2018-09-26 19:53:58 +0100 | [diff] [blame] | 100 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 101 | # Keep in sync with chromium DEPS. |
| 102 | ('buildtools/libfuzzer', |
| 103 | 'https://chromium.googlesource.com/chromium/llvm-project/compiler-rt/lib/fuzzer.git', |
Matthew Clarkson | 40e4819 | 2019-10-28 12:35:01 +0000 | [diff] [blame] | 104 | 'b9f51dc8c98065df0c8da13c051046f5bab833db', 'linux'), |
Primiano Tucci | b60d4b0 | 2017-11-10 11:03:00 +0000 | [diff] [blame] | 105 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 106 | # Benchmarking tool. |
| 107 | ('buildtools/benchmark.zip', |
| 108 | 'https://github.com/google/benchmark/archive/v1.3.0.zip', |
| 109 | 'f387e0df37d54bfd5be239e8d0d3ea2e2c3e34f4', 'all'), |
Primiano Tucci | 38faa6f | 2018-04-01 20:12:08 +0200 | [diff] [blame] | 110 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 111 | # Libbacktrace, for stacktraces in Linux/Android debug builds. |
| 112 | ('buildtools/libbacktrace.zip', |
| 113 | 'https://github.com/ianlancetaylor/libbacktrace/archive/177940370e4a6b2509e92a0aaa9749184e64af43.zip', |
| 114 | 'b723fe9d671d1ab54df1297f6afbf2893a41c3ea', 'all'), |
Lalit Maganti | 6fe26e6 | 2018-05-23 12:14:38 +0100 | [diff] [blame] | 115 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 116 | # Sqlite for the trace processing library. |
| 117 | # This is the amalgamated source whose compiled output is meant to be faster. |
| 118 | # We still pull the full source for the extensions (not amalgamated). |
| 119 | ('buildtools/sqlite.zip', |
| 120 | 'https://storage.googleapis.com/perfetto/sqlite-amalgamation-3250300.zip', |
| 121 | 'b78c2cb0d2c9182686c582312479f96a82bf5380', 'all'), |
| 122 | ('buildtools/sqlite_src.zip', |
| 123 | 'https://storage.googleapis.com/perfetto/sqlite-src-3250300.zip', |
| 124 | 'd1af2883bb800852946f9bf8ab6055e7698e18ee', 'all'), |
Primiano Tucci | 0d72a31 | 2018-08-07 14:42:45 +0100 | [diff] [blame] | 125 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 126 | # JsonCpp for legacy json import. Used only by the trace processor in |
| 127 | # standalone builds. |
| 128 | ('buildtools/jsoncpp.zip', |
| 129 | 'https://github.com/open-source-parsers/jsoncpp/archive/1.0.0.zip', |
| 130 | '3219e26f2e249bb46b7d688478208c7ec138fea4', 'all'), |
Florian Mayer | 475bd7e | 2018-08-07 20:04:03 +0100 | [diff] [blame] | 131 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 132 | # These dependencies are for libunwindstack, which is used by src/profiling. |
| 133 | ('buildtools/android-core', |
| 134 | 'https://android.googlesource.com/platform/system/core.git', |
| 135 | '3f407fcc37b401c91784700c0a691ba8b1f7ef15', 'all'), |
| 136 | ('buildtools/lzma', |
| 137 | 'https://android.googlesource.com/platform/external/lzma.git', |
| 138 | '7851dce6f4ca17f5caa1c93a4e0a45686b1d56c3', 'all'), |
| 139 | ('buildtools/zlib', |
| 140 | 'https://android.googlesource.com/platform/external/zlib.git', |
| 141 | 'dfa0646a03b4e1707469e04dc931b09774968fe6', 'all'), |
| 142 | ('buildtools/bionic', |
| 143 | 'https://android.googlesource.com/platform/bionic.git', |
| 144 | 'a60488109cda997dfd83832731c8527feaa2825e', 'all'), |
Florian Mayer | 475bd7e | 2018-08-07 20:04:03 +0100 | [diff] [blame] | 145 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 146 | # Example traces for regression tests. |
| 147 | ( |
| 148 | 'buildtools/test_data.zip', |
Ryan Savitski | c53ec7e | 2019-11-07 17:04:50 +0000 | [diff] [blame^] | 149 | 'https://storage.googleapis.com/perfetto/test-data-20191107-164334.zip', |
| 150 | '499f11fbc2b04ef7742662a26b85ef03141e24bd', |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 151 | 'all', |
| 152 | ), |
Hector Dearman | 7f71d0e | 2018-08-09 11:26:10 +0100 | [diff] [blame] | 153 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 154 | # Linenoise, used only by trace_processor in standalone builds. |
| 155 | ('buildtools/linenoise', |
| 156 | 'https://fuchsia.googlesource.com/third_party/linenoise.git', |
| 157 | 'c894b9e59f02203dbe4e2be657572cf88c4230c3', 'all'), |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 158 | ] |
| 159 | |
| 160 | # Dependencies required to build Android code. |
| 161 | # URLs and SHA1s taken from: |
| 162 | # - https://dl.google.com/android/repository/repository-11.xml |
| 163 | # - https://dl.google.com/android/repository/sys-img/android/sys-img.xml |
| 164 | BUILD_DEPS_ANDROID = [ |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 165 | # Android NDK |
| 166 | ('buildtools/ndk.zip', |
| 167 | 'https://dl.google.com/android/repository/android-ndk-r17b-darwin-x86_64.zip', |
| 168 | 'f990aafaffec0b583d2c5420bfa622e52ac14248', 'darwin'), |
| 169 | ('buildtools/ndk.zip', |
| 170 | 'https://dl.google.com/android/repository/android-ndk-r17b-linux-x86_64.zip', |
Matthew Clarkson | 40e4819 | 2019-10-28 12:35:01 +0000 | [diff] [blame] | 171 | 'dd5762ee7ef4995ad04fe0c45a608c344d99ca9f', 'linux'), |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 172 | ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 173 | |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 174 | # Dependencies required to run Android tests. |
| 175 | TEST_DEPS_ANDROID = [ |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 176 | # Android emulator images. |
| 177 | ('buildtools/aosp-arm.zip', |
| 178 | 'https://storage.googleapis.com/perfetto/aosp-02022018-arm.zip', |
| 179 | 'a480d5e7d3ca888b0a58fe15ce76b1791537429a', 'all'), |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 180 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 181 | # platform-tools.zip contains adb binaries. |
| 182 | ('buildtools/android_sdk/platform-tools.zip', |
| 183 | 'https://dl.google.com/android/repository/platform-tools_r26.0.0-darwin.zip', |
| 184 | 'e75b6137dc444f777eb02f44a6d9819b3aabff82', 'darwin'), |
| 185 | ('buildtools/android_sdk/platform-tools.zip', |
| 186 | 'https://dl.google.com/android/repository/platform-tools_r26.0.0-linux.zip', |
Matthew Clarkson | 40e4819 | 2019-10-28 12:35:01 +0000 | [diff] [blame] | 187 | '00de8a6631405b617c10f68cd11ff2e1cd528e23', 'linux'), |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 188 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 189 | # Android emulator binaries. |
| 190 | ('buildtools/emulator', |
| 191 | 'https://android.googlesource.com/platform/prebuilts/android-emulator.git', |
| 192 | '4b260028dc27bc92c39bee9129cb2ba839970956', 'all'), |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 193 | ] |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 194 | |
Primiano Tucci | 1c752c1 | 2018-10-23 09:27:19 +0100 | [diff] [blame] | 195 | # This variable is updated by tools/roll-catapult-trace-viewer. |
| 196 | CATAPULT_SHA1 = 'ff5d8fd7244680b4d4456c25d5fdc04c76f9ef66' |
| 197 | |
Hector Dearman | 6177b75 | 2019-01-24 10:17:32 +0000 | [diff] [blame] | 198 | TYPEFACES_SHA1 = '756b0a015b8f99f5718f7fdf967d052c1ec55ab3' |
| 199 | |
Primiano Tucci | 4bdc4c4 | 2018-05-10 15:52:33 +0100 | [diff] [blame] | 200 | UI_DEPS = [ |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 201 | ('buildtools/nodejs.tgz', |
| 202 | 'https://storage.googleapis.com/perfetto/node-v10.3.0-darwin-x64.tar.gz', |
| 203 | '6d9a122785f38c256add3b25f74adf125497861a', 'darwin'), |
| 204 | ('buildtools/nodejs.tgz', |
| 205 | 'https://storage.googleapis.com/perfetto/node-v10.3.0-linux-x64.tar.xz', |
Matthew Clarkson | 40e4819 | 2019-10-28 12:35:01 +0000 | [diff] [blame] | 206 | '118f6ea19f75089b3f12ac2ddfce357bff872b5e', 'linux'), |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 207 | ('buildtools/emsdk/emscripten.tgz', |
| 208 | 'https://storage.googleapis.com/perfetto/emscripten-1.37.40.tar.gz', |
| 209 | '588c28221321ebbdfc8e3a6f47ea6106f589669b', 'all'), |
| 210 | ('buildtools/emsdk/llvm.tgz', |
| 211 | 'https://storage.googleapis.com/perfetto/emscripten-llvm-e1.37.40-darwin.tar.gz', |
| 212 | '7a894ef0a52821c62f6abaac552dc4ce5d424607', 'darwin'), |
| 213 | ('buildtools/emsdk/llvm.tgz', |
| 214 | 'https://storage.googleapis.com/perfetto/emscripten-llvm-e1.37.40-static-linux.tar.gz', |
Matthew Clarkson | 40e4819 | 2019-10-28 12:35:01 +0000 | [diff] [blame] | 215 | '478501b9b7a14884e546c84efe209a90052cbb07', 'linux'), |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 216 | ('buildtools/d8.tgz', |
Matthew Clarkson | 40e4819 | 2019-10-28 12:35:01 +0000 | [diff] [blame] | 217 | 'https://storage.googleapis.com/perfetto/d8-linux-5.7.492.65.tar.gz', |
| 218 | '95e82ad7faf0a6f74d950c2aa65e3858b7bdb6c6', 'linux'), |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 219 | ('buildtools/d8.tgz', |
| 220 | 'https://storage.googleapis.com/perfetto/d8-darwin-6.6.346.32.tar.gz', |
| 221 | '1abd630619bb1977ab62095570a113d782a1545d', 'darwin'), |
| 222 | ('buildtools/catapult_trace_viewer.tgz', |
| 223 | 'https://storage.googleapis.com/perfetto/catapult_trace_viewer-%s.tar.gz' % |
| 224 | CATAPULT_SHA1, CATAPULT_SHA1, 'all'), |
| 225 | ('buildtools/typefaces.tgz', |
| 226 | 'https://storage.googleapis.com/perfetto/typefaces-%s.tar.gz' % |
| 227 | TYPEFACES_SHA1, TYPEFACES_SHA1, 'all') |
Primiano Tucci | 4bdc4c4 | 2018-05-10 15:52:33 +0100 | [diff] [blame] | 228 | ] |
| 229 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 230 | ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 231 | |
| 232 | |
| 233 | def ReadFile(path): |
| 234 | if not os.path.exists(path): |
| 235 | return None |
| 236 | with open(path) as f: |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 237 | return f.read().strip() |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 238 | |
| 239 | |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 240 | def MkdirRecursive(path): |
| 241 | # Works with both relative and absolute paths |
| 242 | cwd = '/' if path.startswith('/') else ROOT_DIR |
| 243 | for part in path.split('/'): |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 244 | cwd = os.path.join(cwd, part) |
| 245 | if not os.path.exists(cwd): |
| 246 | os.makedirs(cwd) |
| 247 | else: |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 248 | assert (os.path.isdir(cwd)) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 249 | |
| 250 | |
| 251 | def HashLocalFile(path): |
| 252 | if not os.path.exists(path): |
| 253 | return None |
| 254 | with open(path, 'rb') as f: |
| 255 | return hashlib.sha1(f.read()).hexdigest() |
| 256 | |
| 257 | |
| 258 | def ExtractZipfilePreservePermissions(zf, info, path): |
| 259 | zf.extract(info.filename, path=path) |
| 260 | target_path = os.path.join(path, info.filename) |
| 261 | min_acls = 0o755 if info.filename.endswith('/') else 0o644 |
Matthew Clarkson | 9a5dfa5 | 2019-10-03 09:54:04 +0100 | [diff] [blame] | 262 | os.chmod(target_path, (info.external_attr >> 16) | min_acls) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 263 | |
| 264 | |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 265 | def IsGitRepoCheckoutOutAtRevision(path, revision): |
| 266 | return ReadFile(os.path.join(path, '.git', 'HEAD')) == revision |
| 267 | |
| 268 | |
| 269 | def CheckoutGitRepo(path, git_url, revision): |
| 270 | if IsGitRepoCheckoutOutAtRevision(path, revision): |
Eric Seckler | 676421f | 2019-02-12 14:43:31 +0000 | [diff] [blame] | 271 | return False |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 272 | if os.path.exists(path): |
| 273 | shutil.rmtree(path) |
| 274 | MkdirRecursive(path) |
| 275 | logging.info('Fetching %s @ %s into %s', git_url, revision, path) |
Lalit Maganti | 367fcd5 | 2018-02-05 16:06:13 +0000 | [diff] [blame] | 276 | subprocess.check_call(['git', 'init', path], cwd=path) |
| 277 | subprocess.check_call( |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 278 | ['git', 'fetch', '--quiet', '--depth', '1', git_url, revision], cwd=path) |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 279 | subprocess.check_call(['git', 'checkout', revision, '--quiet'], cwd=path) |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 280 | assert (IsGitRepoCheckoutOutAtRevision(path, revision)) |
Eric Seckler | 676421f | 2019-02-12 14:43:31 +0000 | [diff] [blame] | 281 | return True |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 282 | |
Sami Kyostila | c7ddac7 | 2019-06-05 21:43:40 +0100 | [diff] [blame] | 283 | |
Deepanjan Roy | acf8c07 | 2018-07-13 11:37:04 -0400 | [diff] [blame] | 284 | def InstallNodeModules(): |
| 285 | ui_dir = os.path.join(ROOT_DIR, 'ui') |
| 286 | logging.info("Running npm install in {0}".format(ui_dir)) |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 287 | subprocess.check_call([os.path.join(ui_dir, 'npm'), 'install', '--no-save'], |
| 288 | cwd=os.path.join(ROOT_DIR, 'ui')) |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 289 | |
Sami Kyostila | c7ddac7 | 2019-06-05 21:43:40 +0100 | [diff] [blame] | 290 | |
| 291 | def CheckHashes(): |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 292 | for deps in [BUILD_DEPS_HOST, BUILD_DEPS_ANDROID, TEST_DEPS_ANDROID, UI_DEPS]: |
Sami Kyostila | c7ddac7 | 2019-06-05 21:43:40 +0100 | [diff] [blame] | 293 | for rel_path, url, expected_sha1, platform in deps: |
| 294 | if url.endswith('.git'): |
| 295 | continue |
| 296 | logging.info('Downloading %s from %s', rel_path, url) |
| 297 | with tempfile.NamedTemporaryFile(delete=False) as f: |
| 298 | f.close() |
Matthew Clarkson | 9a5dfa5 | 2019-10-03 09:54:04 +0100 | [diff] [blame] | 299 | urlretrieve(url, f.name) |
Sami Kyostila | c7ddac7 | 2019-06-05 21:43:40 +0100 | [diff] [blame] | 300 | actual_sha1 = HashLocalFile(f.name) |
| 301 | os.unlink(f.name) |
| 302 | if (actual_sha1 != expected_sha1): |
| 303 | logging.fatal('SHA1 mismatch for {} expected {} was {}'.format( |
| 304 | url, expected_sha1, actual_sha1)) |
| 305 | |
| 306 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 307 | def Main(): |
| 308 | parser = argparse.ArgumentParser() |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 309 | parser.add_argument('--no-android', action='store_true') |
Primiano Tucci | 4bdc4c4 | 2018-05-10 15:52:33 +0100 | [diff] [blame] | 310 | parser.add_argument('--ui', action='store_true') |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 311 | parser.add_argument( |
| 312 | '--check-hashes', help='Check hashes for all URLs', action='store_true') |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 313 | args = parser.parse_args() |
Sami Kyostila | c7ddac7 | 2019-06-05 21:43:40 +0100 | [diff] [blame] | 314 | if args.check_hashes: |
| 315 | CheckHashes() |
| 316 | return 0 |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 317 | deps = BUILD_DEPS_HOST |
| 318 | if not args.no_android: |
| 319 | deps += BUILD_DEPS_ANDROID + TEST_DEPS_ANDROID |
Primiano Tucci | 4bdc4c4 | 2018-05-10 15:52:33 +0100 | [diff] [blame] | 320 | if args.ui: |
| 321 | deps += UI_DEPS |
Eric Seckler | 6e828f3 | 2019-01-02 11:10:56 +0000 | [diff] [blame] | 322 | deps_updated = False |
Primiano Tucci | d775045 | 2017-09-29 14:38:51 +0100 | [diff] [blame] | 323 | for rel_path, url, expected_sha1, platform in deps: |
Matthew Clarkson | 40e4819 | 2019-10-28 12:35:01 +0000 | [diff] [blame] | 324 | if (platform != 'all' and platform != system().lower()): |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 325 | continue |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 326 | local_path = os.path.join(ROOT_DIR, rel_path) |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 327 | if url.endswith('.git'): |
Eric Seckler | 676421f | 2019-02-12 14:43:31 +0000 | [diff] [blame] | 328 | deps_updated |= CheckoutGitRepo(local_path, url, expected_sha1) |
Primiano Tucci | 0825bc8 | 2017-09-28 18:50:23 +0100 | [diff] [blame] | 329 | continue |
Primiano Tucci | b60d4b0 | 2017-11-10 11:03:00 +0000 | [diff] [blame] | 330 | is_zip = local_path.endswith('.zip') or local_path.endswith('.tgz') |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 331 | zip_target_dir = local_path[:-4] if is_zip else None |
| 332 | zip_dir_stamp = os.path.join(zip_target_dir, '.stamp') if is_zip else None |
| 333 | |
| 334 | if ((not is_zip and HashLocalFile(local_path) == expected_sha1) or |
| 335 | (is_zip and ReadFile(zip_dir_stamp) == expected_sha1)): |
| 336 | continue |
Eric Seckler | 6e828f3 | 2019-01-02 11:10:56 +0000 | [diff] [blame] | 337 | deps_updated = True |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 338 | MkdirRecursive(os.path.dirname(rel_path)) |
| 339 | if HashLocalFile(local_path) != expected_sha1: |
| 340 | download_path = local_path + '.tmp' |
| 341 | logging.info('Downloading %s from %s', local_path, url) |
Matthew Clarkson | 9a5dfa5 | 2019-10-03 09:54:04 +0100 | [diff] [blame] | 342 | urlretrieve(url, download_path) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 343 | os.chmod(download_path, 0o755) |
Hector Dearman | d9628d3 | 2018-10-17 14:38:26 +0100 | [diff] [blame] | 344 | actual_sha1 = HashLocalFile(download_path) |
| 345 | if (actual_sha1 != expected_sha1): |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 346 | os.remove(download_path) |
Hector Dearman | d9628d3 | 2018-10-17 14:38:26 +0100 | [diff] [blame] | 347 | logging.fatal('SHA1 mismatch for {} expected {} was {}'.format( |
| 348 | download_path, expected_sha1, actual_sha1)) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 349 | return 1 |
| 350 | os.rename(download_path, local_path) |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 351 | assert (HashLocalFile(local_path) == expected_sha1) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 352 | |
| 353 | if is_zip: |
| 354 | logging.info('Extracting %s into %s' % (local_path, zip_target_dir)) |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 355 | assert (os.path.commonprefix((ROOT_DIR, zip_target_dir)) == ROOT_DIR) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 356 | if os.path.exists(zip_target_dir): |
| 357 | logging.info('Deleting stale dir %s' % zip_target_dir) |
| 358 | shutil.rmtree(zip_target_dir) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 359 | |
Primiano Tucci | b60d4b0 | 2017-11-10 11:03:00 +0000 | [diff] [blame] | 360 | # Decompress the archive. |
| 361 | if local_path.endswith('.tgz'): |
| 362 | MkdirRecursive(zip_target_dir) |
Primiano Tucci | 4bdc4c4 | 2018-05-10 15:52:33 +0100 | [diff] [blame] | 363 | subprocess.check_call(['tar', '-xf', local_path], cwd=zip_target_dir) |
Primiano Tucci | b60d4b0 | 2017-11-10 11:03:00 +0000 | [diff] [blame] | 364 | elif local_path.endswith('.zip'): |
| 365 | with zipfile.ZipFile(local_path, 'r') as zf: |
| 366 | for info in zf.infolist(): |
| 367 | ExtractZipfilePreservePermissions(zf, info, zip_target_dir) |
| 368 | |
| 369 | # If the zip contains one root folder, rebase one level up moving all |
| 370 | # its sub files and folders inside |target_dir|. |
| 371 | subdir = os.listdir(zip_target_dir) |
| 372 | if len(subdir) == 1: |
| 373 | subdir = os.path.join(zip_target_dir, subdir[0]) |
| 374 | if os.path.isdir(subdir): |
| 375 | for subf in os.listdir(subdir): |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 376 | shutil.move(os.path.join(subdir, subf), zip_target_dir) |
Primiano Tucci | b60d4b0 | 2017-11-10 11:03:00 +0000 | [diff] [blame] | 377 | os.rmdir(subdir) |
| 378 | |
| 379 | # Create stamp and remove the archive. |
| 380 | with open(zip_dir_stamp, 'w') as stamp_file: |
| 381 | stamp_file.write(expected_sha1) |
| 382 | os.remove(local_path) |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 383 | |
Deepanjan Roy | acf8c07 | 2018-07-13 11:37:04 -0400 | [diff] [blame] | 384 | if args.ui: |
| 385 | # Needs to happen after nodejs is installed above. |
| 386 | InstallNodeModules() |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 387 | |
Eric Seckler | 6e828f3 | 2019-01-02 11:10:56 +0000 | [diff] [blame] | 388 | if deps_updated: |
| 389 | # Stale binary files may be compiled against old sysroot headers that aren't |
| 390 | # tracked by gn. |
Matthew Clarkson | 9a5dfa5 | 2019-10-03 09:54:04 +0100 | [diff] [blame] | 391 | logging.warning('Remember to run "gn clean <output_directory>" ' + |
| 392 | 'to avoid stale binary files.') |
Eric Seckler | 6e828f3 | 2019-01-02 11:10:56 +0000 | [diff] [blame] | 393 | |
Matthew Clarkson | 63028d6 | 2019-10-10 15:48:23 +0100 | [diff] [blame] | 394 | |
Primiano Tucci | ae2879e | 2017-09-27 11:02:09 +0900 | [diff] [blame] | 395 | if __name__ == '__main__': |
| 396 | logging.basicConfig(level=logging.INFO) |
| 397 | sys.exit(Main()) |