react-native-vision-camera-spoof-detector 1.0.22 → 1.0.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. package/README.md +442 -442
  2. package/android/.gradle/9.2.0/checksums/checksums.lock +0 -0
  3. package/android/.gradle/9.2.0/fileHashes/fileHashes.bin +0 -0
  4. package/android/.gradle/9.2.0/fileHashes/fileHashes.lock +0 -0
  5. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  6. package/android/.gradle/buildOutputCleanup/cache.properties +2 -2
  7. package/android/build/reports/problems/problems-report.html +659 -0
  8. package/android/build.gradle +12 -4
  9. package/android/src/main/cpp/CMakeLists.txt +101 -94
  10. package/android/src/main/cpp/libyuv/.clang-format +6 -6
  11. package/android/src/main/cpp/libyuv/.gn +40 -40
  12. package/android/src/main/cpp/libyuv/.vpython3 +410 -410
  13. package/android/src/main/cpp/libyuv/AUTHORS +7 -7
  14. package/android/src/main/cpp/libyuv/Android.bp +202 -202
  15. package/android/src/main/cpp/libyuv/Android.mk +106 -106
  16. package/android/src/main/cpp/libyuv/BUILD.gn +490 -490
  17. package/android/src/main/cpp/libyuv/CM_linux_packages.cmake +70 -70
  18. package/android/src/main/cpp/libyuv/CMakeLists.txt +259 -252
  19. package/android/src/main/cpp/libyuv/DEPS +935 -935
  20. package/android/src/main/cpp/libyuv/DIR_METADATA +3 -3
  21. package/android/src/main/cpp/libyuv/LICENSE +29 -29
  22. package/android/src/main/cpp/libyuv/OWNERS +11 -11
  23. package/android/src/main/cpp/libyuv/PATENTS +23 -23
  24. package/android/src/main/cpp/libyuv/PRESUBMIT.py +65 -65
  25. package/android/src/main/cpp/libyuv/README.chromium +11 -11
  26. package/android/src/main/cpp/libyuv/README.md +19 -19
  27. package/android/src/main/cpp/libyuv/build_overrides/build.gni +60 -60
  28. package/android/src/main/cpp/libyuv/build_overrides/gtest.gni +19 -19
  29. package/android/src/main/cpp/libyuv/build_overrides/partition_alloc.gni +17 -17
  30. package/android/src/main/cpp/libyuv/codereview.settings +5 -5
  31. package/android/src/main/cpp/libyuv/docs/deprecated_builds.md +409 -409
  32. package/android/src/main/cpp/libyuv/docs/environment_variables.md +64 -64
  33. package/android/src/main/cpp/libyuv/docs/feature_detection.md +108 -108
  34. package/android/src/main/cpp/libyuv/docs/filtering.md +196 -196
  35. package/android/src/main/cpp/libyuv/docs/formats.md +208 -208
  36. package/android/src/main/cpp/libyuv/docs/getting_started.md +296 -296
  37. package/android/src/main/cpp/libyuv/docs/rotation.md +107 -107
  38. package/android/src/main/cpp/libyuv/download_vs_toolchain.py +29 -29
  39. package/android/src/main/cpp/libyuv/include/libyuv/basic_types.h +68 -68
  40. package/android/src/main/cpp/libyuv/include/libyuv/compare.h +111 -111
  41. package/android/src/main/cpp/libyuv/include/libyuv/compare_row.h +112 -112
  42. package/android/src/main/cpp/libyuv/include/libyuv/convert.h +1117 -1117
  43. package/android/src/main/cpp/libyuv/include/libyuv/convert_argb.h +2335 -2335
  44. package/android/src/main/cpp/libyuv/include/libyuv/convert_from.h +203 -203
  45. package/android/src/main/cpp/libyuv/include/libyuv/convert_from_argb.h +394 -394
  46. package/android/src/main/cpp/libyuv/include/libyuv/cpu_id.h +147 -147
  47. package/android/src/main/cpp/libyuv/include/libyuv/cpu_support.h +99 -99
  48. package/android/src/main/cpp/libyuv/include/libyuv/loongson_intrinsics.h +1949 -1949
  49. package/android/src/main/cpp/libyuv/include/libyuv/mjpeg_decoder.h +195 -195
  50. package/android/src/main/cpp/libyuv/include/libyuv/planar_functions.h +1131 -1131
  51. package/android/src/main/cpp/libyuv/include/libyuv/rotate.h +296 -296
  52. package/android/src/main/cpp/libyuv/include/libyuv/rotate_argb.h +37 -37
  53. package/android/src/main/cpp/libyuv/include/libyuv/rotate_row.h +265 -265
  54. package/android/src/main/cpp/libyuv/include/libyuv/row.h +6738 -6738
  55. package/android/src/main/cpp/libyuv/include/libyuv/row_sve.h +2154 -2154
  56. package/android/src/main/cpp/libyuv/include/libyuv/scale.h +336 -336
  57. package/android/src/main/cpp/libyuv/include/libyuv/scale_argb.h +76 -76
  58. package/android/src/main/cpp/libyuv/include/libyuv/scale_rgb.h +42 -42
  59. package/android/src/main/cpp/libyuv/include/libyuv/scale_row.h +1726 -1726
  60. package/android/src/main/cpp/libyuv/include/libyuv/scale_uv.h +51 -51
  61. package/android/src/main/cpp/libyuv/include/libyuv/version.h +16 -16
  62. package/android/src/main/cpp/libyuv/include/libyuv/video_common.h +222 -222
  63. package/android/src/main/cpp/libyuv/include/libyuv.h +33 -33
  64. package/android/src/main/cpp/libyuv/infra/config/OWNERS +3 -3
  65. package/android/src/main/cpp/libyuv/infra/config/PRESUBMIT.py +17 -17
  66. package/android/src/main/cpp/libyuv/infra/config/README.md +2 -2
  67. package/android/src/main/cpp/libyuv/infra/config/codereview.settings +6 -6
  68. package/android/src/main/cpp/libyuv/infra/config/commit-queue.cfg +144 -144
  69. package/android/src/main/cpp/libyuv/infra/config/cr-buildbucket.cfg +1185 -1185
  70. package/android/src/main/cpp/libyuv/infra/config/luci-logdog.cfg +9 -9
  71. package/android/src/main/cpp/libyuv/infra/config/luci-milo.cfg +246 -246
  72. package/android/src/main/cpp/libyuv/infra/config/luci-scheduler.cfg +385 -385
  73. package/android/src/main/cpp/libyuv/infra/config/main.star +402 -402
  74. package/android/src/main/cpp/libyuv/infra/config/project.cfg +16 -16
  75. package/android/src/main/cpp/libyuv/infra/config/realms.cfg +111 -111
  76. package/android/src/main/cpp/libyuv/libyuv.gni +34 -34
  77. package/android/src/main/cpp/libyuv/libyuv.gyp +149 -149
  78. package/android/src/main/cpp/libyuv/libyuv.gypi +87 -87
  79. package/android/src/main/cpp/libyuv/linux.mk +96 -96
  80. package/android/src/main/cpp/libyuv/public.mk +13 -13
  81. package/android/src/main/cpp/libyuv/pylintrc +49 -49
  82. package/android/src/main/cpp/libyuv/riscv_script/prepare_toolchain_qemu.sh +74 -74
  83. package/android/src/main/cpp/libyuv/riscv_script/riscv-clang.cmake +56 -56
  84. package/android/src/main/cpp/libyuv/riscv_script/run_qemu.sh +15 -15
  85. package/android/src/main/cpp/libyuv/source/compare.cc +435 -435
  86. package/android/src/main/cpp/libyuv/source/compare_common.cc +74 -74
  87. package/android/src/main/cpp/libyuv/source/compare_gcc.cc +362 -362
  88. package/android/src/main/cpp/libyuv/source/compare_neon.cc +96 -96
  89. package/android/src/main/cpp/libyuv/source/compare_neon64.cc +223 -223
  90. package/android/src/main/cpp/libyuv/source/compare_win.cc +241 -241
  91. package/android/src/main/cpp/libyuv/source/convert.cc +4746 -4746
  92. package/android/src/main/cpp/libyuv/source/convert_argb.cc +9179 -9179
  93. package/android/src/main/cpp/libyuv/source/convert_from.cc +866 -866
  94. package/android/src/main/cpp/libyuv/source/convert_from_argb.cc +3671 -3671
  95. package/android/src/main/cpp/libyuv/source/convert_jpeg.cc +602 -602
  96. package/android/src/main/cpp/libyuv/source/convert_to_argb.cc +391 -391
  97. package/android/src/main/cpp/libyuv/source/convert_to_i420.cc +288 -288
  98. package/android/src/main/cpp/libyuv/source/cpu_id.cc +496 -496
  99. package/android/src/main/cpp/libyuv/source/mjpeg_decoder.cc +580 -580
  100. package/android/src/main/cpp/libyuv/source/mjpeg_validate.cc +71 -71
  101. package/android/src/main/cpp/libyuv/source/planar_functions.cc +5663 -5663
  102. package/android/src/main/cpp/libyuv/source/rotate.cc +1241 -1241
  103. package/android/src/main/cpp/libyuv/source/rotate_any.cc +76 -76
  104. package/android/src/main/cpp/libyuv/source/rotate_argb.cc +259 -259
  105. package/android/src/main/cpp/libyuv/source/rotate_common.cc +208 -208
  106. package/android/src/main/cpp/libyuv/source/rotate_gcc.cc +505 -505
  107. package/android/src/main/cpp/libyuv/source/rotate_lsx.cc +233 -233
  108. package/android/src/main/cpp/libyuv/source/rotate_neon.cc +219 -219
  109. package/android/src/main/cpp/libyuv/source/rotate_neon64.cc +273 -273
  110. package/android/src/main/cpp/libyuv/source/rotate_sme.cc +174 -174
  111. package/android/src/main/cpp/libyuv/source/rotate_win.cc +253 -253
  112. package/android/src/main/cpp/libyuv/source/row_any.cc +2519 -2519
  113. package/android/src/main/cpp/libyuv/source/row_common.cc +4461 -4461
  114. package/android/src/main/cpp/libyuv/source/row_gcc.cc +9570 -9570
  115. package/android/src/main/cpp/libyuv/source/row_lasx.cc +2343 -2343
  116. package/android/src/main/cpp/libyuv/source/row_lsx.cc +3030 -3030
  117. package/android/src/main/cpp/libyuv/source/row_neon.cc +4026 -4026
  118. package/android/src/main/cpp/libyuv/source/row_neon64.cc +5617 -5617
  119. package/android/src/main/cpp/libyuv/source/row_rvv.cc +2599 -2599
  120. package/android/src/main/cpp/libyuv/source/row_sme.cc +1183 -1183
  121. package/android/src/main/cpp/libyuv/source/row_sve.cc +1088 -1088
  122. package/android/src/main/cpp/libyuv/source/row_win.cc +6453 -6453
  123. package/android/src/main/cpp/libyuv/source/scale.cc +2710 -2710
  124. package/android/src/main/cpp/libyuv/source/scale_any.cc +991 -991
  125. package/android/src/main/cpp/libyuv/source/scale_argb.cc +1158 -1158
  126. package/android/src/main/cpp/libyuv/source/scale_common.cc +1977 -1977
  127. package/android/src/main/cpp/libyuv/source/scale_gcc.cc +2947 -2947
  128. package/android/src/main/cpp/libyuv/source/scale_lsx.cc +739 -739
  129. package/android/src/main/cpp/libyuv/source/scale_neon.cc +1449 -1449
  130. package/android/src/main/cpp/libyuv/source/scale_neon64.cc +1552 -1552
  131. package/android/src/main/cpp/libyuv/source/scale_rgb.cc +82 -82
  132. package/android/src/main/cpp/libyuv/source/scale_rvv.cc +1971 -1971
  133. package/android/src/main/cpp/libyuv/source/scale_sme.cc +555 -555
  134. package/android/src/main/cpp/libyuv/source/scale_uv.cc +1159 -1159
  135. package/android/src/main/cpp/libyuv/source/scale_win.cc +1392 -1392
  136. package/android/src/main/cpp/libyuv/source/test.sh +35 -35
  137. package/android/src/main/cpp/libyuv/source/video_common.cc +62 -62
  138. package/android/src/main/cpp/libyuv/tools_libyuv/OWNERS +4 -4
  139. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/roll_deps.py +931 -931
  140. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/roll_deps_test.py +164 -164
  141. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS +21 -21
  142. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.new +13 -13
  143. package/android/src/main/cpp/libyuv/tools_libyuv/autoroller/unittests/testdata/DEPS.chromium.old +13 -13
  144. package/android/src/main/cpp/libyuv/tools_libyuv/get_landmines.py +38 -38
  145. package/android/src/main/cpp/libyuv/tools_libyuv/msan/OWNERS +3 -3
  146. package/android/src/main/cpp/libyuv/tools_libyuv/msan/blacklist.txt +9 -9
  147. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/OWNERS +3 -3
  148. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/blacklist.txt +15 -15
  149. package/android/src/main/cpp/libyuv/tools_libyuv/ubsan/vptr_blacklist.txt +25 -25
  150. package/android/src/main/cpp/libyuv/unit_test/basictypes_test.cc +43 -43
  151. package/android/src/main/cpp/libyuv/unit_test/color_test.cc +848 -848
  152. package/android/src/main/cpp/libyuv/unit_test/compare_test.cc +739 -739
  153. package/android/src/main/cpp/libyuv/unit_test/convert_argb_test.cc +2867 -2867
  154. package/android/src/main/cpp/libyuv/unit_test/convert_test.cc +2133 -2133
  155. package/android/src/main/cpp/libyuv/unit_test/cpu_test.cc +427 -427
  156. package/android/src/main/cpp/libyuv/unit_test/cpu_thread_test.cc +63 -63
  157. package/android/src/main/cpp/libyuv/unit_test/math_test.cc +160 -160
  158. package/android/src/main/cpp/libyuv/unit_test/planar_test.cc +4731 -4731
  159. package/android/src/main/cpp/libyuv/unit_test/rotate_argb_test.cc +334 -334
  160. package/android/src/main/cpp/libyuv/unit_test/rotate_test.cc +962 -962
  161. package/android/src/main/cpp/libyuv/unit_test/scale_argb_test.cc +590 -590
  162. package/android/src/main/cpp/libyuv/unit_test/scale_plane_test.cc +465 -465
  163. package/android/src/main/cpp/libyuv/unit_test/scale_rgb_test.cc +280 -280
  164. package/android/src/main/cpp/libyuv/unit_test/scale_test.cc +1135 -1135
  165. package/android/src/main/cpp/libyuv/unit_test/scale_uv_test.cc +249 -249
  166. package/android/src/main/cpp/libyuv/unit_test/testdata/arm_v7.txt +12 -12
  167. package/android/src/main/cpp/libyuv/unit_test/testdata/mips.txt +7 -7
  168. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson2k.txt +5 -5
  169. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson3.txt +10 -10
  170. package/android/src/main/cpp/libyuv/unit_test/testdata/mips_loongson_mmi.txt +7 -7
  171. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64.txt +3 -3
  172. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv.txt +3 -3
  173. package/android/src/main/cpp/libyuv/unit_test/testdata/riscv64_rvv_zvfh.txt +3 -3
  174. package/android/src/main/cpp/libyuv/unit_test/testdata/tegra3.txt +23 -23
  175. package/android/src/main/cpp/libyuv/unit_test/unit_test.cc +581 -581
  176. package/android/src/main/cpp/libyuv/unit_test/unit_test.h +232 -232
  177. package/android/src/main/cpp/libyuv/unit_test/video_common_test.cc +112 -112
  178. package/android/src/main/cpp/libyuv/util/Makefile +9 -9
  179. package/android/src/main/cpp/libyuv/util/color.cc +120 -120
  180. package/android/src/main/cpp/libyuv/util/compare.cc +67 -67
  181. package/android/src/main/cpp/libyuv/util/cpuid.c +211 -211
  182. package/android/src/main/cpp/libyuv/util/i444tonv12_eg.cc +27 -27
  183. package/android/src/main/cpp/libyuv/util/psnr.cc +291 -291
  184. package/android/src/main/cpp/libyuv/util/psnr.h +47 -47
  185. package/android/src/main/cpp/libyuv/util/psnr_main.cc +620 -620
  186. package/android/src/main/cpp/libyuv/util/ssim.cc +364 -364
  187. package/android/src/main/cpp/libyuv/util/ssim.h +38 -38
  188. package/android/src/main/cpp/libyuv/util/yuvconstants.c +114 -114
  189. package/android/src/main/cpp/libyuv/util/yuvconvert.cc +367 -367
  190. package/android/src/main/cpp/libyuv/winarm.mk +47 -47
  191. package/index.js +17 -1
  192. package/ios/FaceAntiSpoofFrameProcessor.swift +283 -0
  193. package/ios/FaceAntiSpoofJSI.h +12 -0
  194. package/ios/FaceAntiSpoofJSI.mm +92 -0
  195. package/ios/FaceAntiSpoofManager.swift +63 -0
  196. package/ios/FaceAntiSpoofModule.m +191 -0
  197. package/ios/FaceAntiSpoofPluginRegister.m +42 -0
  198. package/ios/models/FaceAntiSpoofing.tflite +0 -0
  199. package/ios/models/model_spec.json +16 -0
  200. package/package.json +87 -86
  201. package/.gitignore +0 -27
  202. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  203. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  204. package/android/.gradle/8.9/gc.properties +0 -0
  205. /package/android/.gradle/{8.9 → 9.2.0}/fileChanges/last-build.bin +0 -0
  206. /package/android/.gradle/{8.9/dependencies-accessors → 9.2.0}/gc.properties +0 -0
@@ -1,931 +1,931 @@
1
- #!/usr/bin/env vpython3
2
-
3
- # Copyright (c) 2017 The LibYUV project authors. All Rights Reserved.
4
- #
5
- # Use of this source code is governed by a BSD-style license
6
- # that can be found in the LICENSE file in the root of the source
7
- # tree. An additional intellectual property rights grant can be found
8
- # in the file PATENTS. All contributing project authors may
9
- # be found in the AUTHORS file in the root of the source tree.
10
- """Script to automatically roll dependencies in the LibYUV DEPS file."""
11
-
12
-
13
- import argparse
14
- import base64
15
- import collections
16
- import logging
17
- import os
18
- import re
19
- import subprocess
20
- import sys
21
- import urllib.request
22
-
23
- def FindRootPath():
24
- """Returns the absolute path to the highest level repo root.
25
-
26
- If this repo is checked out as a submodule of the chromium/src
27
- superproject, this returns the superproect root. Otherwise, it returns the
28
- webrtc/src repo root.
29
- """
30
- root_dir = os.path.dirname(os.path.abspath(__file__))
31
- while os.path.basename(root_dir) not in ('src', 'chromium'):
32
- par_dir = os.path.normpath(os.path.join(root_dir, os.pardir))
33
- if par_dir == root_dir:
34
- raise RuntimeError('Could not find the repo root.')
35
- root_dir = par_dir
36
- return root_dir
37
-
38
-
39
- # Skip these dependencies (list without solution name prefix).
40
- DONT_AUTOROLL_THESE = [
41
- 'third_party/fuchsia-gn-sdk',
42
- 'src/third_party/gflags/src',
43
- 'src/third_party/mockito/src',
44
- ]
45
-
46
- # These dependencies are missing in chromium/src/DEPS, either unused or already
47
- # in-tree. For instance, src/base is a part of the Chromium source git repo,
48
- # but we pull it through a subtree mirror, so therefore it isn't listed in
49
- # Chromium's deps but it is in ours.
50
- LIBYUV_ONLY_DEPS = [
51
- 'src/build',
52
- 'src/buildtools',
53
- 'src/ios',
54
- 'src/testing',
55
- 'src/third_party',
56
- 'src/third_party/android_support_test_runner',
57
- 'src/third_party/errorprone/lib',
58
- 'src/third_party/findbugs',
59
- 'src/third_party/gson',
60
- 'src/third_party/gtest-parallel',
61
- 'src/third_party/guava',
62
- 'src/third_party/intellij',
63
- 'src/third_party/jsr-305/src',
64
- 'src/third_party/ow2_asm',
65
- 'src/third_party/proguard',
66
- 'src/third_party/ub-uiautomator/lib',
67
- 'src/tools',
68
- 'src/tools/clang/dsymutil',
69
- ]
70
-
71
- LIBYUV_URL = 'https://chromium.googlesource.com/libyuv/libyuv'
72
- CHROMIUM_SRC_URL = 'https://chromium.googlesource.com/chromium/src'
73
- CHROMIUM_COMMIT_TEMPLATE = CHROMIUM_SRC_URL + '/+/%s'
74
- CHROMIUM_LOG_TEMPLATE = CHROMIUM_SRC_URL + '/+log/%s'
75
- CHROMIUM_FILE_TEMPLATE = CHROMIUM_SRC_URL + '/+/%s/%s'
76
-
77
- COMMIT_POSITION_RE = re.compile('^Cr-Commit-Position: .*#([0-9]+).*$')
78
- CLANG_REVISION_RE = re.compile(r'^CLANG_REVISION = \'([-0-9a-z]+)\'$')
79
- ROLL_BRANCH_NAME = 'roll_chromium_revision'
80
-
81
- SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
82
- CHECKOUT_ROOT_DIR = FindRootPath()
83
- GCLIENT_ROOT_DIR = os.path.realpath(os.path.join(CHECKOUT_ROOT_DIR, os.pardir))
84
-
85
- # Copied from tools/android/roll/android_deps/.../BuildConfigGenerator.groovy.
86
- ANDROID_DEPS_START = r'=== ANDROID_DEPS Generated Code Start ==='
87
- ANDROID_DEPS_END = r'=== ANDROID_DEPS Generated Code End ==='
88
- # Location of automically gathered android deps.
89
- ANDROID_DEPS_PATH = 'src/third_party/android_deps/'
90
-
91
- sys.path.append(os.path.join(CHECKOUT_ROOT_DIR, 'build'))
92
- import find_depot_tools # pylint: disable=wrong-import-position
93
-
94
- find_depot_tools.add_depot_tools_to_path()
95
-
96
- CLANG_UPDATE_SCRIPT_URL_PATH = 'tools/clang/scripts/update.py'
97
- CLANG_UPDATE_SCRIPT_LOCAL_PATH = os.path.join(
98
- CHECKOUT_ROOT_DIR, 'tools', 'clang', 'scripts', 'update.py'
99
- )
100
-
101
- DepsEntry = collections.namedtuple('DepsEntry', 'path url revision')
102
- ChangedDep = collections.namedtuple(
103
- 'ChangedDep', 'path url current_rev new_rev'
104
- )
105
- CipdDepsEntry = collections.namedtuple('CipdDepsEntry', 'path packages')
106
- GcsDepsEntry = collections.namedtuple('GcsDepsEntry', 'path bucket objects')
107
- VersionEntry = collections.namedtuple('VersionEntry', 'version')
108
- ChangedCipdPackage = collections.namedtuple(
109
- 'ChangedCipdPackage', 'path package current_version new_version'
110
- )
111
- ChangedVersionEntry = collections.namedtuple(
112
- 'ChangedVersionEntry', 'path current_version new_version'
113
- )
114
-
115
- ChromiumRevisionUpdate = collections.namedtuple(
116
- 'ChromiumRevisionUpdate', 'current_chromium_rev new_chromium_rev '
117
- )
118
-
119
-
120
- class RollError(Exception):
121
- pass
122
-
123
-
124
- def StrExpansion():
125
- return lambda str_value: str_value
126
-
127
-
128
- def VarLookup(local_scope):
129
- return lambda var_name: local_scope['vars'][var_name]
130
-
131
-
132
- def ParseDepsDict(deps_content):
133
- local_scope = {}
134
- global_scope = {
135
- 'Str': StrExpansion(),
136
- 'Var': VarLookup(local_scope),
137
- 'deps_os': {},
138
- }
139
- exec(deps_content, global_scope, local_scope)
140
- return local_scope
141
-
142
-
143
- def ParseLocalDepsFile(filename):
144
- with open(filename, 'rb') as f:
145
- deps_content = f.read().decode('utf-8')
146
- return ParseDepsDict(deps_content)
147
-
148
-
149
- def ParseCommitPosition(commit_message):
150
- for line in reversed(commit_message.splitlines()):
151
- m = COMMIT_POSITION_RE.match(line.strip())
152
- if m:
153
- return int(m.group(1))
154
- logging.error(
155
- 'Failed to parse commit position id from:\n%s\n', commit_message
156
- )
157
- sys.exit(-1)
158
-
159
-
160
- def _RunCommand(
161
- command,
162
- working_dir=None,
163
- ignore_exit_code=False,
164
- extra_env=None,
165
- input_data=None,
166
- ):
167
- """Runs a command and returns the output from that command.
168
-
169
- If the command fails (exit code != 0), the function will exit the process.
170
-
171
- Returns:
172
- A tuple containing the stdout and stderr outputs as strings.
173
- """
174
- working_dir = working_dir or CHECKOUT_ROOT_DIR
175
- logging.debug('CMD: %s CWD: %s', ' '.join(command), working_dir)
176
- env = os.environ.copy()
177
- if extra_env:
178
- assert all(isinstance(value, str) for value in extra_env.values())
179
- logging.debug('extra env: %s', extra_env)
180
- env.update(extra_env)
181
- p = subprocess.Popen(
182
- command,
183
- stdin=subprocess.PIPE,
184
- stdout=subprocess.PIPE,
185
- stderr=subprocess.PIPE,
186
- env=env,
187
- cwd=working_dir,
188
- universal_newlines=True,
189
- )
190
- std_output, err_output = p.communicate(input_data)
191
- p.stdout.close()
192
- p.stderr.close()
193
- if not ignore_exit_code and p.returncode != 0:
194
- logging.error(
195
- 'Command failed: %s\nstdout:\n%s\nstderr:\n%s\n',
196
- ' '.join(command),
197
- std_output,
198
- err_output,
199
- )
200
- sys.exit(p.returncode)
201
- return std_output, err_output
202
-
203
-
204
- def _GetBranches():
205
- """Returns a tuple of active,branches.
206
-
207
- The 'active' is the name of the currently active branch and 'branches' is a
208
- list of all branches.
209
- """
210
- lines = _RunCommand(['git', 'branch'])[0].split('\n')
211
- branches = []
212
- active = ''
213
- for line in lines:
214
- if '*' in line:
215
- # The assumption is that the first char will always be the '*'.
216
- active = line[1:].strip()
217
- branches.append(active)
218
- else:
219
- branch = line.strip()
220
- if branch:
221
- branches.append(branch)
222
- return active, branches
223
-
224
-
225
- def _ReadGitilesContent(url):
226
- # Download and decode BASE64 content until
227
- # https://code.google.com/p/gitiles/issues/detail?id=7 is fixed.
228
- base64_content = ReadUrlContent(url + '?format=TEXT')
229
- return base64.b64decode(base64_content[0]).decode('utf-8')
230
-
231
-
232
- def ReadRemoteCrFile(path_below_src, revision):
233
- """Reads a remote Chromium file of a specific revision.
234
-
235
- Args:
236
- path_below_src: A path to the target file relative to src dir.
237
- revision: Revision to read.
238
-
239
- Returns:
240
- A string with file content.
241
- """
242
- return _ReadGitilesContent(
243
- CHROMIUM_FILE_TEMPLATE % (revision, path_below_src)
244
- )
245
-
246
-
247
- def ReadRemoteCrCommit(revision):
248
- """Reads a remote Chromium commit message. Returns a string."""
249
- return _ReadGitilesContent(CHROMIUM_COMMIT_TEMPLATE % revision)
250
-
251
-
252
- def ReadUrlContent(url):
253
- """Connect to a remote host and read the contents.
254
-
255
- Args:
256
- url: URL to connect to.
257
-
258
- Returns:
259
- A list of lines.
260
- """
261
- conn = urllib.request.urlopen(url)
262
- try:
263
- return conn.readlines()
264
- except IOError as e:
265
- logging.exception('Error connecting to %s. Error: %s', url, e)
266
- raise
267
- finally:
268
- conn.close()
269
-
270
-
271
- def GetMatchingDepsEntries(depsentry_dict, dir_path):
272
- """Gets all deps entries matching the provided path.
273
-
274
- This list may contain more than one DepsEntry object.
275
- Example: dir_path='src/testing' would give results containing both
276
- 'src/testing/gtest' and 'src/testing/gmock' deps entries for Chromium's
277
- DEPS.
278
- Example 2: dir_path='src/build' should return 'src/build' but not
279
- 'src/buildtools'.
280
-
281
- Returns:
282
- A list of DepsEntry objects.
283
- """
284
- result = []
285
- for path, depsentry in depsentry_dict.items():
286
- if path == dir_path:
287
- result.append(depsentry)
288
- else:
289
- parts = path.split('/')
290
- if all(
291
- part == parts[i] for i, part in enumerate(dir_path.split('/'))
292
- ):
293
- result.append(depsentry)
294
- return result
295
-
296
-
297
- def BuildDepsentryDict(deps_dict):
298
- """Builds a dict of paths to DepsEntry objects from a raw deps dict."""
299
- result = {}
300
-
301
- def AddDepsEntries(deps_subdict):
302
- for path, dep in deps_subdict.items():
303
- if path in result:
304
- continue
305
- if not isinstance(dep, dict):
306
- dep = {'url': dep}
307
- if dep.get('dep_type') == 'cipd':
308
- result[path] = CipdDepsEntry(path, dep['packages'])
309
- elif dep.get('dep_type') == 'gcs':
310
- result[path] = GcsDepsEntry(path, dep['bucket'],
311
- dep['objects'])
312
- else:
313
- if '@' not in dep['url']:
314
- url, revision = dep['url'], 'HEAD'
315
- else:
316
- url, revision = dep['url'].split('@')
317
- result[path] = DepsEntry(path, url, revision)
318
-
319
- def AddVersionEntry(vars_subdict):
320
- for key, value in vars_subdict.items():
321
- if key in result:
322
- continue
323
- if not key.endswith('_version'):
324
- continue
325
- key = re.sub('_version$', '', key)
326
- result[key] = VersionEntry(value)
327
-
328
- AddDepsEntries(deps_dict['deps'])
329
- for deps_os in ['win', 'mac', 'unix', 'android', 'ios', 'unix']:
330
- AddDepsEntries(deps_dict.get('deps_os', {}).get(deps_os, {}))
331
- AddVersionEntry(deps_dict.get('vars', {}))
332
- return result
333
-
334
-
335
- def _FindChangedCipdPackages(path, old_pkgs, new_pkgs):
336
- old_pkgs_names = {p['package'] for p in old_pkgs}
337
- new_pkgs_names = {p['package'] for p in new_pkgs}
338
- pkgs_equal = old_pkgs_names == new_pkgs_names
339
- added_pkgs = [p for p in new_pkgs_names if p not in old_pkgs_names]
340
- removed_pkgs = [p for p in old_pkgs_names if p not in new_pkgs_names]
341
-
342
- assert pkgs_equal, (
343
- 'Old: %s\n New: %s.\nYou need to do a manual roll '
344
- 'and remove/add entries in DEPS so the old and new '
345
- 'list match.\nMost likely, you should add "%s" and '
346
- 'remove "%s"' % (old_pkgs, new_pkgs, added_pkgs, removed_pkgs)
347
- )
348
-
349
- for old_pkg in old_pkgs:
350
- for new_pkg in new_pkgs:
351
- old_version = old_pkg['version']
352
- new_version = new_pkg['version']
353
- if (
354
- old_pkg['package'] == new_pkg['package']
355
- and old_version != new_version
356
- ):
357
- logging.debug('Roll dependency %s to %s', path, new_version)
358
- yield ChangedCipdPackage(
359
- path, old_pkg['package'], old_version, new_version
360
- )
361
-
362
-
363
- def _FindChangedVars(name, old_version, new_version):
364
- if old_version != new_version:
365
- logging.debug('Roll dependency %s to %s', name, new_version)
366
- yield ChangedVersionEntry(name, old_version, new_version)
367
-
368
-
369
- def _FindNewDeps(old, new):
370
- """Gather dependencies only in `new` and return corresponding paths."""
371
- old_entries = set(BuildDepsentryDict(old))
372
- new_entries = set(BuildDepsentryDict(new))
373
- return [
374
- path
375
- for path in new_entries - old_entries
376
- if path not in DONT_AUTOROLL_THESE
377
- ]
378
-
379
-
380
- def FindAddedDeps(libyuv_deps, new_cr_deps):
381
- """Calculate new deps entries of interest.
382
-
383
- Ideally, that would mean: only appearing in chromium DEPS
384
- but transitively used in LibYUV.
385
-
386
- Since it's hard to compute, we restrict ourselves to a well defined subset:
387
- deps sitting in `ANDROID_DEPS_PATH`.
388
- Otherwise, assumes that's a Chromium-only dependency.
389
-
390
- Args:
391
- libyuv_deps: dict of deps as defined in the LibYUV DEPS file.
392
- new_cr_deps: dict of deps as defined in the chromium DEPS file.
393
-
394
- Caveat: Doesn't detect a new package in existing dep.
395
-
396
- Returns:
397
- A tuple consisting of:
398
- A list of paths added dependencies sitting in `ANDROID_DEPS_PATH`.
399
- A list of paths for other added dependencies.
400
- """
401
- all_added_deps = _FindNewDeps(libyuv_deps, new_cr_deps)
402
- generated_android_deps = [
403
- path for path in all_added_deps if path.startswith(ANDROID_DEPS_PATH)
404
- ]
405
- other_deps = [
406
- path for path in all_added_deps if path not in generated_android_deps
407
- ]
408
- return generated_android_deps, other_deps
409
-
410
-
411
- def FindRemovedDeps(libyuv_deps, new_cr_deps):
412
- """Calculate obsolete deps entries.
413
-
414
- Ideally, that would mean: no more appearing in chromium DEPS
415
- and not used in LibYUV.
416
-
417
- Since it's hard to compute:
418
- 1/ We restrict ourselves to a well defined subset:
419
- deps sitting in `ANDROID_DEPS_PATH`.
420
- 2/ We rely on existing behavior of CalculateChangeDeps.
421
- I.e. Assumes non-CIPD dependencies are LibYUV-only, don't remove them.
422
-
423
- Args:
424
- libyuv_deps: dict of deps as defined in the LibYUV DEPS file.
425
- new_cr_deps: dict of deps as defined in the chromium DEPS file.
426
-
427
- Caveat: Doesn't detect a deleted package in existing dep.
428
-
429
- Returns:
430
- A tuple consisting of:
431
- A list of paths of dependencies removed from `ANDROID_DEPS_PATH`.
432
- A list of paths of unexpected disappearing dependencies.
433
- """
434
- all_removed_deps = _FindNewDeps(new_cr_deps, libyuv_deps)
435
- generated_android_deps = sorted([
436
- path for path in all_removed_deps if path.startswith(ANDROID_DEPS_PATH)
437
- ])
438
- # Webrtc-only dependencies are handled in CalculateChangedDeps.
439
- other_deps = sorted([
440
- path
441
- for path in all_removed_deps
442
- if path not in generated_android_deps and path not in LIBYUV_ONLY_DEPS
443
- ])
444
- return generated_android_deps, other_deps
445
-
446
-
447
- def CalculateChangedDeps(libyuv_deps, new_cr_deps):
448
- """Calculate changed deps entries based on entries defined in the LibYUV
449
-
450
- DEPS
451
-
452
- file:
453
- - If a shared dependency with the Chromium DEPS file: roll it to the same
454
- revision as Chromium (i.e. entry in the new_cr_deps dict)
455
- - If it's a Chromium sub-directory, roll it to the HEAD revision (notice
456
- this means it may be ahead of the chromium_revision, but generally these
457
- should be close).
458
- - If it's another DEPS entry (not shared with Chromium), roll it to HEAD
459
- unless it's configured to be skipped.
460
-
461
- Returns:
462
- A list of ChangedDep objects representing the changed deps.
463
- """
464
- result = []
465
- libyuv_entries = BuildDepsentryDict(libyuv_deps)
466
- new_cr_entries = BuildDepsentryDict(new_cr_deps)
467
- for path, libyuv_deps_entry in libyuv_entries.items():
468
- if path in DONT_AUTOROLL_THESE:
469
- continue
470
- cr_deps_entry = new_cr_entries.get(path)
471
- if cr_deps_entry:
472
- assert type(cr_deps_entry) is type(libyuv_deps_entry)
473
-
474
- if isinstance(cr_deps_entry, CipdDepsEntry):
475
- result.extend(
476
- _FindChangedCipdPackages(path, libyuv_deps_entry.packages,
477
- cr_deps_entry.packages))
478
- continue
479
-
480
- if isinstance(cr_deps_entry, GcsDepsEntry):
481
- result.extend(
482
- _FindChangedVars(
483
- path, ','.join(x['object_name']
484
- for x in libyuv_deps_entry.objects),
485
- ','.join(x['object_name']
486
- for x in cr_deps_entry.objects)))
487
- continue
488
-
489
- if isinstance(cr_deps_entry, VersionEntry):
490
- result.extend(
491
- _FindChangedVars(
492
- path, libyuv_deps_entry.version, cr_deps_entry.version
493
- )
494
- )
495
- continue
496
-
497
- # Use the revision from Chromium's DEPS file.
498
- new_rev = cr_deps_entry.revision
499
- assert libyuv_deps_entry.url == cr_deps_entry.url, (
500
- 'LibYUV DEPS entry %s has a different URL %s than Chromium %s.'
501
- % (
502
- path,
503
- libyuv_deps_entry.url,
504
- cr_deps_entry.url,
505
- )
506
- )
507
- else:
508
- if isinstance(libyuv_deps_entry, DepsEntry):
509
- # Use the HEAD of the deps repo.
510
- stdout, _ = _RunCommand(
511
- ['git', 'ls-remote', libyuv_deps_entry.url, 'HEAD']
512
- )
513
- new_rev = stdout.strip().split('\t')[0]
514
- else:
515
- # The dependency has been removed from chromium.
516
- # This is handled by FindRemovedDeps.
517
- continue
518
-
519
- # Check if an update is necessary.
520
- if libyuv_deps_entry.revision != new_rev:
521
- logging.debug('Roll dependency %s to %s', path, new_rev)
522
- result.append(
523
- ChangedDep(
524
- path,
525
- libyuv_deps_entry.url,
526
- libyuv_deps_entry.revision,
527
- new_rev,
528
- )
529
- )
530
- return sorted(result)
531
-
532
-
533
- def CalculateChangedClang(new_cr_rev):
534
-
535
- def GetClangRev(lines):
536
- for line in lines:
537
- match = CLANG_REVISION_RE.match(line)
538
- if match:
539
- return match.group(1)
540
- raise RollError('Could not parse Clang revision!')
541
-
542
- with open(CLANG_UPDATE_SCRIPT_LOCAL_PATH, 'r') as f:
543
- current_lines = f.readlines()
544
- current_rev = GetClangRev(current_lines)
545
-
546
- new_clang_update_py = ReadRemoteCrFile(
547
- CLANG_UPDATE_SCRIPT_URL_PATH, new_cr_rev
548
- ).splitlines()
549
- new_rev = GetClangRev(new_clang_update_py)
550
- return ChangedDep(
551
- CLANG_UPDATE_SCRIPT_LOCAL_PATH, None, current_rev, new_rev
552
- )
553
-
554
-
555
- def GenerateCommitMessage(
556
- rev_update,
557
- current_commit_pos,
558
- new_commit_pos,
559
- changed_deps_list,
560
- added_deps_paths=None,
561
- removed_deps_paths=None,
562
- clang_change=None,
563
- ):
564
- current_cr_rev = rev_update.current_chromium_rev[0:10]
565
- new_cr_rev = rev_update.new_chromium_rev[0:10]
566
- rev_interval = '%s..%s' % (current_cr_rev, new_cr_rev)
567
- git_number_interval = '%s:%s' % (current_commit_pos, new_commit_pos)
568
-
569
- commit_msg = [
570
- 'Roll chromium_revision %s (%s)\n'
571
- % (rev_interval, git_number_interval),
572
- 'Change log: %s' % (CHROMIUM_LOG_TEMPLATE % rev_interval),
573
- 'Full diff: %s\n' % (CHROMIUM_COMMIT_TEMPLATE % rev_interval),
574
- ]
575
-
576
- def Section(adjective, deps):
577
- noun = 'dependency' if len(deps) == 1 else 'dependencies'
578
- commit_msg.append('%s %s' % (adjective, noun))
579
-
580
- if changed_deps_list:
581
- Section('Changed', changed_deps_list)
582
-
583
- for c in changed_deps_list:
584
- if isinstance(c, ChangedCipdPackage):
585
- commit_msg.append(
586
- '* %s: %s..%s' % (c.path, c.current_version, c.new_version)
587
- )
588
- elif isinstance(c, ChangedVersionEntry):
589
- commit_msg.append(
590
- '* %s_vesion: %s..%s'
591
- % (c.path, c.current_version, c.new_version)
592
- )
593
- else:
594
- commit_msg.append(
595
- '* %s: %s/+log/%s..%s'
596
- % (c.path, c.url, c.current_rev[0:10], c.new_rev[0:10])
597
- )
598
-
599
- if added_deps_paths:
600
- Section('Added', added_deps_paths)
601
- commit_msg.extend('* %s' % p for p in added_deps_paths)
602
-
603
- if removed_deps_paths:
604
- Section('Removed', removed_deps_paths)
605
- commit_msg.extend('* %s' % p for p in removed_deps_paths)
606
-
607
- if any([changed_deps_list, added_deps_paths, removed_deps_paths]):
608
- change_url = CHROMIUM_FILE_TEMPLATE % (rev_interval, 'DEPS')
609
- commit_msg.append('DEPS diff: %s\n' % change_url)
610
- else:
611
- commit_msg.append('No dependencies changed.')
612
-
613
- if clang_change and clang_change.current_rev != clang_change.new_rev:
614
- commit_msg.append(
615
- 'Clang version changed %s:%s'
616
- % (clang_change.current_rev, clang_change.new_rev)
617
- )
618
- change_url = CHROMIUM_FILE_TEMPLATE % (
619
- rev_interval,
620
- CLANG_UPDATE_SCRIPT_URL_PATH,
621
- )
622
- commit_msg.append('Details: %s\n' % change_url)
623
- else:
624
- commit_msg.append('No update to Clang.\n')
625
-
626
- commit_msg.append('BUG=None')
627
- return '\n'.join(commit_msg)
628
-
629
-
630
- def UpdateDepsFile(deps_filename, rev_update, changed_deps, new_cr_content):
631
- """Update the DEPS file with the new revision."""
632
-
633
- with open(deps_filename, 'rb') as deps_file:
634
- deps_content = deps_file.read().decode('utf-8')
635
-
636
- # Update the chromium_revision variable.
637
- deps_content = deps_content.replace(
638
- rev_update.current_chromium_rev, rev_update.new_chromium_rev
639
- )
640
-
641
- # Add and remove dependencies. For now: only generated android deps.
642
- # Since gclient cannot add or remove deps, we on the fact that
643
- # these android deps are located in one place we can copy/paste.
644
- deps_re = re.compile(
645
- ANDROID_DEPS_START + '.*' + ANDROID_DEPS_END, re.DOTALL
646
- )
647
- new_deps = deps_re.search(new_cr_content)
648
- old_deps = deps_re.search(deps_content)
649
- if not new_deps or not old_deps:
650
- faulty = 'Chromium' if not new_deps else 'LibYUV'
651
- raise RollError(
652
- 'Was expecting to find "%s" and "%s"\nin %s DEPS'
653
- % (ANDROID_DEPS_START, ANDROID_DEPS_END, faulty)
654
- )
655
- deps_content = deps_re.sub(new_deps.group(0), deps_content)
656
-
657
- for dep in changed_deps:
658
- if isinstance(dep, ChangedVersionEntry):
659
- deps_content = deps_content.replace(
660
- dep.current_version, dep.new_version
661
- )
662
-
663
- with open(deps_filename, 'wb') as deps_file:
664
- deps_file.write(deps_content.encode('utf-8'))
665
-
666
- # Update each individual DEPS entry.
667
- for dep in changed_deps:
668
- # ChangedVersionEntry types are already been processed.
669
- if isinstance(dep, ChangedVersionEntry):
670
- continue
671
- local_dep_dir = os.path.join(GCLIENT_ROOT_DIR, dep.path)
672
- if not os.path.isdir(local_dep_dir):
673
- raise RollError(
674
- 'Cannot find local directory %s. Either run\n'
675
- 'gclient sync --deps=all\n'
676
- 'or make sure the .gclient file for your solution contains '
677
- 'all platforms in the target_os list, i.e.\n'
678
- 'target_os = ["android", "unix", "mac", "ios", "win"];\n'
679
- 'Then run "gclient sync" again.' % local_dep_dir
680
- )
681
- if isinstance(dep, ChangedCipdPackage):
682
- package = dep.package.format() # Eliminate double curly brackets
683
- update = '%s:%s@%s' % (dep.path, package, dep.new_version)
684
- else:
685
- update = '%s@%s' % (dep.path, dep.new_rev)
686
- _RunCommand(
687
- ['gclient', 'setdep', '--revision', update],
688
- working_dir=CHECKOUT_ROOT_DIR,
689
- )
690
-
691
-
692
- def _IsTreeClean():
693
- stdout, _ = _RunCommand(['git', 'status', '--porcelain'])
694
- if len(stdout) == 0:
695
- return True
696
-
697
- logging.error('Dirty/unversioned files:\n%s', stdout)
698
- return False
699
-
700
-
701
- def _EnsureUpdatedMainBranch(dry_run):
702
- current_branch = _RunCommand(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])[
703
- 0
704
- ].splitlines()[0]
705
- if current_branch != 'main':
706
- logging.error('Please checkout the main branch and re-run this script.') # pylint: disable=line-too-long
707
- if not dry_run:
708
- sys.exit(-1)
709
-
710
- logging.info('Updating main branch...')
711
- _RunCommand(['git', 'pull'])
712
-
713
-
714
- def _CreateRollBranch(dry_run):
715
- logging.info('Creating roll branch: %s', ROLL_BRANCH_NAME)
716
- if not dry_run:
717
- _RunCommand(['git', 'checkout', '-b', ROLL_BRANCH_NAME])
718
-
719
-
720
- def _RemovePreviousRollBranch(dry_run):
721
- active_branch, branches = _GetBranches()
722
- if active_branch == ROLL_BRANCH_NAME:
723
- active_branch = 'main'
724
- if ROLL_BRANCH_NAME in branches:
725
- logging.info('Removing previous roll branch (%s)', ROLL_BRANCH_NAME)
726
- if not dry_run:
727
- _RunCommand(['git', 'checkout', active_branch])
728
- _RunCommand(['git', 'branch', '-D', ROLL_BRANCH_NAME])
729
-
730
-
731
- def _LocalCommit(commit_msg, dry_run):
732
- logging.info('Committing changes locally.')
733
- if not dry_run:
734
- _RunCommand(['git', 'add', '--update', '.'])
735
- _RunCommand(['git', 'commit', '-m', commit_msg])
736
-
737
-
738
- def ChooseCQMode(skip_cq, cq_over, current_commit_pos, new_commit_pos):
739
- if skip_cq:
740
- return 0
741
- if (new_commit_pos - current_commit_pos) < cq_over:
742
- return 1
743
- return 2
744
-
745
-
746
- def _GetCcRecipients(changed_deps_list):
747
- """Returns a list of emails to notify based on the changed deps list."""
748
- cc_recipients = []
749
- for _ in changed_deps_list:
750
- pass
751
- return cc_recipients
752
-
753
-
754
- def _UploadCL(commit_queue_mode, add_cc=None):
755
- """Upload the committed changes as a changelist to Gerrit.
756
-
757
- commit_queue_mode:
758
- - 2: Submit to commit queue.
759
- - 1: Run trybots but do not submit to CQ.
760
- - 0: Skip CQ, upload only.
761
-
762
- add_cc: A list of email addresses to add as CC recipients.
763
- """
764
- cc_recipients = []
765
- if add_cc:
766
- cc_recipients.extend(add_cc)
767
- cmd = ['git', 'cl', 'upload', '--force', '--bypass-hooks']
768
- if commit_queue_mode >= 2:
769
- logging.info('Sending the CL to the CQ...')
770
- cmd.extend(['-o', 'label=Bot-Commit+1'])
771
- cmd.extend(['-o', 'label=Commit-Queue+2'])
772
- cmd.extend(['--send-mail', '--cc', ','.join(cc_recipients)])
773
- elif commit_queue_mode >= 1:
774
- logging.info('Starting CQ dry run...')
775
- cmd.extend(['-o', 'label=Commit-Queue+1'])
776
- extra_env = {
777
- 'EDITOR': 'true',
778
- 'SKIP_GCE_AUTH_FOR_GIT': '1',
779
- }
780
- stdout, stderr = _RunCommand(cmd, extra_env=extra_env)
781
- logging.debug(
782
- 'Output from "git cl upload":\nstdout:\n%s\n\nstderr:\n%s',
783
- stdout,
784
- stderr,
785
- )
786
-
787
-
788
- def GetRollRevisionRanges(opts, libyuv_deps):
789
- current_cr_rev = libyuv_deps['vars']['chromium_revision']
790
- new_cr_rev = opts.revision
791
- if not new_cr_rev:
792
- stdout, _ = _RunCommand(['git', 'ls-remote', CHROMIUM_SRC_URL, 'HEAD'])
793
- head_rev = stdout.strip().split('\t')[0]
794
- logging.info('No revision specified. Using HEAD: %s', head_rev)
795
- new_cr_rev = head_rev
796
-
797
- return ChromiumRevisionUpdate(current_cr_rev, new_cr_rev)
798
-
799
-
800
- def main():
801
- p = argparse.ArgumentParser()
802
- p.add_argument(
803
- '--clean',
804
- action='store_true',
805
- default=False,
806
- help='Removes any previous local roll branch.',
807
- )
808
- p.add_argument(
809
- '-r',
810
- '--revision',
811
- help=(
812
- 'Chromium Git revision to roll to. Defaults to the '
813
- 'Chromium HEAD revision if omitted.'
814
- ),
815
- )
816
- p.add_argument(
817
- '--dry-run',
818
- action='store_true',
819
- default=False,
820
- help=(
821
- "Calculate changes and modify DEPS, but don't create "
822
- 'any local branch, commit, upload CL or send any '
823
- 'tryjobs.'
824
- ),
825
- )
826
- p.add_argument(
827
- '-i',
828
- '--ignore-unclean-workdir',
829
- action='store_true',
830
- default=False,
831
- help=(
832
- 'Ignore if the current branch is not main or if there '
833
- 'are uncommitted changes (default: %(default)s).'
834
- ),
835
- )
836
- grp = p.add_mutually_exclusive_group()
837
- grp.add_argument(
838
- '--skip-cq',
839
- action='store_true',
840
- default=False,
841
- help='Skip sending the CL to the CQ (default: %(default)s)',
842
- )
843
- grp.add_argument(
844
- '--cq-over',
845
- type=int,
846
- default=1,
847
- help=(
848
- 'Commit queue dry run if the revision difference '
849
- 'is below this number (default: %(default)s)'
850
- ),
851
- )
852
- p.add_argument(
853
- '-v',
854
- '--verbose',
855
- action='store_true',
856
- default=False,
857
- help='Be extra verbose in printing of log messages.',
858
- )
859
- opts = p.parse_args()
860
-
861
- if opts.verbose:
862
- logging.basicConfig(level=logging.DEBUG)
863
- else:
864
- logging.basicConfig(level=logging.INFO)
865
-
866
- if not opts.ignore_unclean_workdir and not _IsTreeClean():
867
- logging.error('Please clean your local checkout first.')
868
- return 1
869
-
870
- if opts.clean:
871
- _RemovePreviousRollBranch(opts.dry_run)
872
-
873
- if not opts.ignore_unclean_workdir:
874
- _EnsureUpdatedMainBranch(opts.dry_run)
875
-
876
- deps_filename = os.path.join(CHECKOUT_ROOT_DIR, 'DEPS')
877
- libyuv_deps = ParseLocalDepsFile(deps_filename)
878
-
879
- rev_update = GetRollRevisionRanges(opts, libyuv_deps)
880
-
881
- current_commit_pos = ParseCommitPosition(
882
- ReadRemoteCrCommit(rev_update.current_chromium_rev)
883
- )
884
- new_commit_pos = ParseCommitPosition(
885
- ReadRemoteCrCommit(rev_update.new_chromium_rev)
886
- )
887
-
888
- new_cr_content = ReadRemoteCrFile('DEPS', rev_update.new_chromium_rev)
889
- new_cr_deps = ParseDepsDict(new_cr_content)
890
- changed_deps = CalculateChangedDeps(libyuv_deps, new_cr_deps)
891
- # Discard other deps, assumed to be chromium-only dependencies.
892
- new_generated_android_deps, _ = FindAddedDeps(libyuv_deps, new_cr_deps)
893
- removed_generated_android_deps, other_deps = FindRemovedDeps(
894
- libyuv_deps, new_cr_deps
895
- )
896
- if other_deps:
897
- raise RollError(
898
- 'LibYUV DEPS entries are missing from Chromium: %s.\n'
899
- 'Remove them or add them to either '
900
- 'LIBYUV_ONLY_DEPS or DONT_AUTOROLL_THESE.' % other_deps
901
- )
902
- clang_change = CalculateChangedClang(rev_update.new_chromium_rev)
903
- commit_msg = GenerateCommitMessage(
904
- rev_update,
905
- current_commit_pos,
906
- new_commit_pos,
907
- changed_deps,
908
- added_deps_paths=new_generated_android_deps,
909
- removed_deps_paths=removed_generated_android_deps,
910
- clang_change=clang_change,
911
- )
912
- logging.debug('Commit message:\n%s', commit_msg)
913
-
914
- _CreateRollBranch(opts.dry_run)
915
- if not opts.dry_run:
916
- UpdateDepsFile(deps_filename, rev_update, changed_deps, new_cr_content)
917
- if _IsTreeClean():
918
- logging.info('No DEPS changes detected, skipping CL creation.')
919
- else:
920
- _LocalCommit(commit_msg, opts.dry_run)
921
- commit_queue_mode = ChooseCQMode(
922
- opts.skip_cq, opts.cq_over, current_commit_pos, new_commit_pos
923
- )
924
- logging.info('Uploading CL...')
925
- if not opts.dry_run:
926
- _UploadCL(commit_queue_mode, _GetCcRecipients(changed_deps))
927
- return 0
928
-
929
-
930
- if __name__ == '__main__':
931
- sys.exit(main())
1
+ #!/usr/bin/env vpython3
2
+
3
+ # Copyright (c) 2017 The LibYUV project authors. All Rights Reserved.
4
+ #
5
+ # Use of this source code is governed by a BSD-style license
6
+ # that can be found in the LICENSE file in the root of the source
7
+ # tree. An additional intellectual property rights grant can be found
8
+ # in the file PATENTS. All contributing project authors may
9
+ # be found in the AUTHORS file in the root of the source tree.
10
+ """Script to automatically roll dependencies in the LibYUV DEPS file."""
11
+
12
+
13
+ import argparse
14
+ import base64
15
+ import collections
16
+ import logging
17
+ import os
18
+ import re
19
+ import subprocess
20
+ import sys
21
+ import urllib.request
22
+
23
+ def FindRootPath():
24
+ """Returns the absolute path to the highest level repo root.
25
+
26
+ If this repo is checked out as a submodule of the chromium/src
27
+ superproject, this returns the superproect root. Otherwise, it returns the
28
+ webrtc/src repo root.
29
+ """
30
+ root_dir = os.path.dirname(os.path.abspath(__file__))
31
+ while os.path.basename(root_dir) not in ('src', 'chromium'):
32
+ par_dir = os.path.normpath(os.path.join(root_dir, os.pardir))
33
+ if par_dir == root_dir:
34
+ raise RuntimeError('Could not find the repo root.')
35
+ root_dir = par_dir
36
+ return root_dir
37
+
38
+
39
+ # Skip these dependencies (list without solution name prefix).
40
+ DONT_AUTOROLL_THESE = [
41
+ 'third_party/fuchsia-gn-sdk',
42
+ 'src/third_party/gflags/src',
43
+ 'src/third_party/mockito/src',
44
+ ]
45
+
46
+ # These dependencies are missing in chromium/src/DEPS, either unused or already
47
+ # in-tree. For instance, src/base is a part of the Chromium source git repo,
48
+ # but we pull it through a subtree mirror, so therefore it isn't listed in
49
+ # Chromium's deps but it is in ours.
50
+ LIBYUV_ONLY_DEPS = [
51
+ 'src/build',
52
+ 'src/buildtools',
53
+ 'src/ios',
54
+ 'src/testing',
55
+ 'src/third_party',
56
+ 'src/third_party/android_support_test_runner',
57
+ 'src/third_party/errorprone/lib',
58
+ 'src/third_party/findbugs',
59
+ 'src/third_party/gson',
60
+ 'src/third_party/gtest-parallel',
61
+ 'src/third_party/guava',
62
+ 'src/third_party/intellij',
63
+ 'src/third_party/jsr-305/src',
64
+ 'src/third_party/ow2_asm',
65
+ 'src/third_party/proguard',
66
+ 'src/third_party/ub-uiautomator/lib',
67
+ 'src/tools',
68
+ 'src/tools/clang/dsymutil',
69
+ ]
70
+
71
+ LIBYUV_URL = 'https://chromium.googlesource.com/libyuv/libyuv'
72
+ CHROMIUM_SRC_URL = 'https://chromium.googlesource.com/chromium/src'
73
+ CHROMIUM_COMMIT_TEMPLATE = CHROMIUM_SRC_URL + '/+/%s'
74
+ CHROMIUM_LOG_TEMPLATE = CHROMIUM_SRC_URL + '/+log/%s'
75
+ CHROMIUM_FILE_TEMPLATE = CHROMIUM_SRC_URL + '/+/%s/%s'
76
+
77
+ COMMIT_POSITION_RE = re.compile('^Cr-Commit-Position: .*#([0-9]+).*$')
78
+ CLANG_REVISION_RE = re.compile(r'^CLANG_REVISION = \'([-0-9a-z]+)\'$')
79
+ ROLL_BRANCH_NAME = 'roll_chromium_revision'
80
+
81
+ SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
82
+ CHECKOUT_ROOT_DIR = FindRootPath()
83
+ GCLIENT_ROOT_DIR = os.path.realpath(os.path.join(CHECKOUT_ROOT_DIR, os.pardir))
84
+
85
+ # Copied from tools/android/roll/android_deps/.../BuildConfigGenerator.groovy.
86
+ ANDROID_DEPS_START = r'=== ANDROID_DEPS Generated Code Start ==='
87
+ ANDROID_DEPS_END = r'=== ANDROID_DEPS Generated Code End ==='
88
+ # Location of automically gathered android deps.
89
+ ANDROID_DEPS_PATH = 'src/third_party/android_deps/'
90
+
91
+ sys.path.append(os.path.join(CHECKOUT_ROOT_DIR, 'build'))
92
+ import find_depot_tools # pylint: disable=wrong-import-position
93
+
94
+ find_depot_tools.add_depot_tools_to_path()
95
+
96
+ CLANG_UPDATE_SCRIPT_URL_PATH = 'tools/clang/scripts/update.py'
97
+ CLANG_UPDATE_SCRIPT_LOCAL_PATH = os.path.join(
98
+ CHECKOUT_ROOT_DIR, 'tools', 'clang', 'scripts', 'update.py'
99
+ )
100
+
101
+ DepsEntry = collections.namedtuple('DepsEntry', 'path url revision')
102
+ ChangedDep = collections.namedtuple(
103
+ 'ChangedDep', 'path url current_rev new_rev'
104
+ )
105
+ CipdDepsEntry = collections.namedtuple('CipdDepsEntry', 'path packages')
106
+ GcsDepsEntry = collections.namedtuple('GcsDepsEntry', 'path bucket objects')
107
+ VersionEntry = collections.namedtuple('VersionEntry', 'version')
108
+ ChangedCipdPackage = collections.namedtuple(
109
+ 'ChangedCipdPackage', 'path package current_version new_version'
110
+ )
111
+ ChangedVersionEntry = collections.namedtuple(
112
+ 'ChangedVersionEntry', 'path current_version new_version'
113
+ )
114
+
115
+ ChromiumRevisionUpdate = collections.namedtuple(
116
+ 'ChromiumRevisionUpdate', 'current_chromium_rev new_chromium_rev '
117
+ )
118
+
119
+
120
+ class RollError(Exception):
121
+ pass
122
+
123
+
124
+ def StrExpansion():
125
+ return lambda str_value: str_value
126
+
127
+
128
+ def VarLookup(local_scope):
129
+ return lambda var_name: local_scope['vars'][var_name]
130
+
131
+
132
+ def ParseDepsDict(deps_content):
133
+ local_scope = {}
134
+ global_scope = {
135
+ 'Str': StrExpansion(),
136
+ 'Var': VarLookup(local_scope),
137
+ 'deps_os': {},
138
+ }
139
+ exec(deps_content, global_scope, local_scope)
140
+ return local_scope
141
+
142
+
143
+ def ParseLocalDepsFile(filename):
144
+ with open(filename, 'rb') as f:
145
+ deps_content = f.read().decode('utf-8')
146
+ return ParseDepsDict(deps_content)
147
+
148
+
149
+ def ParseCommitPosition(commit_message):
150
+ for line in reversed(commit_message.splitlines()):
151
+ m = COMMIT_POSITION_RE.match(line.strip())
152
+ if m:
153
+ return int(m.group(1))
154
+ logging.error(
155
+ 'Failed to parse commit position id from:\n%s\n', commit_message
156
+ )
157
+ sys.exit(-1)
158
+
159
+
160
+ def _RunCommand(
161
+ command,
162
+ working_dir=None,
163
+ ignore_exit_code=False,
164
+ extra_env=None,
165
+ input_data=None,
166
+ ):
167
+ """Runs a command and returns the output from that command.
168
+
169
+ If the command fails (exit code != 0), the function will exit the process.
170
+
171
+ Returns:
172
+ A tuple containing the stdout and stderr outputs as strings.
173
+ """
174
+ working_dir = working_dir or CHECKOUT_ROOT_DIR
175
+ logging.debug('CMD: %s CWD: %s', ' '.join(command), working_dir)
176
+ env = os.environ.copy()
177
+ if extra_env:
178
+ assert all(isinstance(value, str) for value in extra_env.values())
179
+ logging.debug('extra env: %s', extra_env)
180
+ env.update(extra_env)
181
+ p = subprocess.Popen(
182
+ command,
183
+ stdin=subprocess.PIPE,
184
+ stdout=subprocess.PIPE,
185
+ stderr=subprocess.PIPE,
186
+ env=env,
187
+ cwd=working_dir,
188
+ universal_newlines=True,
189
+ )
190
+ std_output, err_output = p.communicate(input_data)
191
+ p.stdout.close()
192
+ p.stderr.close()
193
+ if not ignore_exit_code and p.returncode != 0:
194
+ logging.error(
195
+ 'Command failed: %s\nstdout:\n%s\nstderr:\n%s\n',
196
+ ' '.join(command),
197
+ std_output,
198
+ err_output,
199
+ )
200
+ sys.exit(p.returncode)
201
+ return std_output, err_output
202
+
203
+
204
+ def _GetBranches():
205
+ """Returns a tuple of active,branches.
206
+
207
+ The 'active' is the name of the currently active branch and 'branches' is a
208
+ list of all branches.
209
+ """
210
+ lines = _RunCommand(['git', 'branch'])[0].split('\n')
211
+ branches = []
212
+ active = ''
213
+ for line in lines:
214
+ if '*' in line:
215
+ # The assumption is that the first char will always be the '*'.
216
+ active = line[1:].strip()
217
+ branches.append(active)
218
+ else:
219
+ branch = line.strip()
220
+ if branch:
221
+ branches.append(branch)
222
+ return active, branches
223
+
224
+
225
+ def _ReadGitilesContent(url):
226
+ # Download and decode BASE64 content until
227
+ # https://code.google.com/p/gitiles/issues/detail?id=7 is fixed.
228
+ base64_content = ReadUrlContent(url + '?format=TEXT')
229
+ return base64.b64decode(base64_content[0]).decode('utf-8')
230
+
231
+
232
+ def ReadRemoteCrFile(path_below_src, revision):
233
+ """Reads a remote Chromium file of a specific revision.
234
+
235
+ Args:
236
+ path_below_src: A path to the target file relative to src dir.
237
+ revision: Revision to read.
238
+
239
+ Returns:
240
+ A string with file content.
241
+ """
242
+ return _ReadGitilesContent(
243
+ CHROMIUM_FILE_TEMPLATE % (revision, path_below_src)
244
+ )
245
+
246
+
247
+ def ReadRemoteCrCommit(revision):
248
+ """Reads a remote Chromium commit message. Returns a string."""
249
+ return _ReadGitilesContent(CHROMIUM_COMMIT_TEMPLATE % revision)
250
+
251
+
252
+ def ReadUrlContent(url):
253
+ """Connect to a remote host and read the contents.
254
+
255
+ Args:
256
+ url: URL to connect to.
257
+
258
+ Returns:
259
+ A list of lines.
260
+ """
261
+ conn = urllib.request.urlopen(url)
262
+ try:
263
+ return conn.readlines()
264
+ except IOError as e:
265
+ logging.exception('Error connecting to %s. Error: %s', url, e)
266
+ raise
267
+ finally:
268
+ conn.close()
269
+
270
+
271
+ def GetMatchingDepsEntries(depsentry_dict, dir_path):
272
+ """Gets all deps entries matching the provided path.
273
+
274
+ This list may contain more than one DepsEntry object.
275
+ Example: dir_path='src/testing' would give results containing both
276
+ 'src/testing/gtest' and 'src/testing/gmock' deps entries for Chromium's
277
+ DEPS.
278
+ Example 2: dir_path='src/build' should return 'src/build' but not
279
+ 'src/buildtools'.
280
+
281
+ Returns:
282
+ A list of DepsEntry objects.
283
+ """
284
+ result = []
285
+ for path, depsentry in depsentry_dict.items():
286
+ if path == dir_path:
287
+ result.append(depsentry)
288
+ else:
289
+ parts = path.split('/')
290
+ if all(
291
+ part == parts[i] for i, part in enumerate(dir_path.split('/'))
292
+ ):
293
+ result.append(depsentry)
294
+ return result
295
+
296
+
297
+ def BuildDepsentryDict(deps_dict):
298
+ """Builds a dict of paths to DepsEntry objects from a raw deps dict."""
299
+ result = {}
300
+
301
+ def AddDepsEntries(deps_subdict):
302
+ for path, dep in deps_subdict.items():
303
+ if path in result:
304
+ continue
305
+ if not isinstance(dep, dict):
306
+ dep = {'url': dep}
307
+ if dep.get('dep_type') == 'cipd':
308
+ result[path] = CipdDepsEntry(path, dep['packages'])
309
+ elif dep.get('dep_type') == 'gcs':
310
+ result[path] = GcsDepsEntry(path, dep['bucket'],
311
+ dep['objects'])
312
+ else:
313
+ if '@' not in dep['url']:
314
+ url, revision = dep['url'], 'HEAD'
315
+ else:
316
+ url, revision = dep['url'].split('@')
317
+ result[path] = DepsEntry(path, url, revision)
318
+
319
+ def AddVersionEntry(vars_subdict):
320
+ for key, value in vars_subdict.items():
321
+ if key in result:
322
+ continue
323
+ if not key.endswith('_version'):
324
+ continue
325
+ key = re.sub('_version$', '', key)
326
+ result[key] = VersionEntry(value)
327
+
328
+ AddDepsEntries(deps_dict['deps'])
329
+ for deps_os in ['win', 'mac', 'unix', 'android', 'ios', 'unix']:
330
+ AddDepsEntries(deps_dict.get('deps_os', {}).get(deps_os, {}))
331
+ AddVersionEntry(deps_dict.get('vars', {}))
332
+ return result
333
+
334
+
335
+ def _FindChangedCipdPackages(path, old_pkgs, new_pkgs):
336
+ old_pkgs_names = {p['package'] for p in old_pkgs}
337
+ new_pkgs_names = {p['package'] for p in new_pkgs}
338
+ pkgs_equal = old_pkgs_names == new_pkgs_names
339
+ added_pkgs = [p for p in new_pkgs_names if p not in old_pkgs_names]
340
+ removed_pkgs = [p for p in old_pkgs_names if p not in new_pkgs_names]
341
+
342
+ assert pkgs_equal, (
343
+ 'Old: %s\n New: %s.\nYou need to do a manual roll '
344
+ 'and remove/add entries in DEPS so the old and new '
345
+ 'list match.\nMost likely, you should add "%s" and '
346
+ 'remove "%s"' % (old_pkgs, new_pkgs, added_pkgs, removed_pkgs)
347
+ )
348
+
349
+ for old_pkg in old_pkgs:
350
+ for new_pkg in new_pkgs:
351
+ old_version = old_pkg['version']
352
+ new_version = new_pkg['version']
353
+ if (
354
+ old_pkg['package'] == new_pkg['package']
355
+ and old_version != new_version
356
+ ):
357
+ logging.debug('Roll dependency %s to %s', path, new_version)
358
+ yield ChangedCipdPackage(
359
+ path, old_pkg['package'], old_version, new_version
360
+ )
361
+
362
+
363
+ def _FindChangedVars(name, old_version, new_version):
364
+ if old_version != new_version:
365
+ logging.debug('Roll dependency %s to %s', name, new_version)
366
+ yield ChangedVersionEntry(name, old_version, new_version)
367
+
368
+
369
+ def _FindNewDeps(old, new):
370
+ """Gather dependencies only in `new` and return corresponding paths."""
371
+ old_entries = set(BuildDepsentryDict(old))
372
+ new_entries = set(BuildDepsentryDict(new))
373
+ return [
374
+ path
375
+ for path in new_entries - old_entries
376
+ if path not in DONT_AUTOROLL_THESE
377
+ ]
378
+
379
+
380
+ def FindAddedDeps(libyuv_deps, new_cr_deps):
381
+ """Calculate new deps entries of interest.
382
+
383
+ Ideally, that would mean: only appearing in chromium DEPS
384
+ but transitively used in LibYUV.
385
+
386
+ Since it's hard to compute, we restrict ourselves to a well defined subset:
387
+ deps sitting in `ANDROID_DEPS_PATH`.
388
+ Otherwise, assumes that's a Chromium-only dependency.
389
+
390
+ Args:
391
+ libyuv_deps: dict of deps as defined in the LibYUV DEPS file.
392
+ new_cr_deps: dict of deps as defined in the chromium DEPS file.
393
+
394
+ Caveat: Doesn't detect a new package in existing dep.
395
+
396
+ Returns:
397
+ A tuple consisting of:
398
+ A list of paths added dependencies sitting in `ANDROID_DEPS_PATH`.
399
+ A list of paths for other added dependencies.
400
+ """
401
+ all_added_deps = _FindNewDeps(libyuv_deps, new_cr_deps)
402
+ generated_android_deps = [
403
+ path for path in all_added_deps if path.startswith(ANDROID_DEPS_PATH)
404
+ ]
405
+ other_deps = [
406
+ path for path in all_added_deps if path not in generated_android_deps
407
+ ]
408
+ return generated_android_deps, other_deps
409
+
410
+
411
+ def FindRemovedDeps(libyuv_deps, new_cr_deps):
412
+ """Calculate obsolete deps entries.
413
+
414
+ Ideally, that would mean: no more appearing in chromium DEPS
415
+ and not used in LibYUV.
416
+
417
+ Since it's hard to compute:
418
+ 1/ We restrict ourselves to a well defined subset:
419
+ deps sitting in `ANDROID_DEPS_PATH`.
420
+ 2/ We rely on existing behavior of CalculateChangeDeps.
421
+ I.e. Assumes non-CIPD dependencies are LibYUV-only, don't remove them.
422
+
423
+ Args:
424
+ libyuv_deps: dict of deps as defined in the LibYUV DEPS file.
425
+ new_cr_deps: dict of deps as defined in the chromium DEPS file.
426
+
427
+ Caveat: Doesn't detect a deleted package in existing dep.
428
+
429
+ Returns:
430
+ A tuple consisting of:
431
+ A list of paths of dependencies removed from `ANDROID_DEPS_PATH`.
432
+ A list of paths of unexpected disappearing dependencies.
433
+ """
434
+ all_removed_deps = _FindNewDeps(new_cr_deps, libyuv_deps)
435
+ generated_android_deps = sorted([
436
+ path for path in all_removed_deps if path.startswith(ANDROID_DEPS_PATH)
437
+ ])
438
+ # Webrtc-only dependencies are handled in CalculateChangedDeps.
439
+ other_deps = sorted([
440
+ path
441
+ for path in all_removed_deps
442
+ if path not in generated_android_deps and path not in LIBYUV_ONLY_DEPS
443
+ ])
444
+ return generated_android_deps, other_deps
445
+
446
+
447
+ def CalculateChangedDeps(libyuv_deps, new_cr_deps):
448
+ """Calculate changed deps entries based on entries defined in the LibYUV
449
+
450
+ DEPS
451
+
452
+ file:
453
+ - If a shared dependency with the Chromium DEPS file: roll it to the same
454
+ revision as Chromium (i.e. entry in the new_cr_deps dict)
455
+ - If it's a Chromium sub-directory, roll it to the HEAD revision (notice
456
+ this means it may be ahead of the chromium_revision, but generally these
457
+ should be close).
458
+ - If it's another DEPS entry (not shared with Chromium), roll it to HEAD
459
+ unless it's configured to be skipped.
460
+
461
+ Returns:
462
+ A list of ChangedDep objects representing the changed deps.
463
+ """
464
+ result = []
465
+ libyuv_entries = BuildDepsentryDict(libyuv_deps)
466
+ new_cr_entries = BuildDepsentryDict(new_cr_deps)
467
+ for path, libyuv_deps_entry in libyuv_entries.items():
468
+ if path in DONT_AUTOROLL_THESE:
469
+ continue
470
+ cr_deps_entry = new_cr_entries.get(path)
471
+ if cr_deps_entry:
472
+ assert type(cr_deps_entry) is type(libyuv_deps_entry)
473
+
474
+ if isinstance(cr_deps_entry, CipdDepsEntry):
475
+ result.extend(
476
+ _FindChangedCipdPackages(path, libyuv_deps_entry.packages,
477
+ cr_deps_entry.packages))
478
+ continue
479
+
480
+ if isinstance(cr_deps_entry, GcsDepsEntry):
481
+ result.extend(
482
+ _FindChangedVars(
483
+ path, ','.join(x['object_name']
484
+ for x in libyuv_deps_entry.objects),
485
+ ','.join(x['object_name']
486
+ for x in cr_deps_entry.objects)))
487
+ continue
488
+
489
+ if isinstance(cr_deps_entry, VersionEntry):
490
+ result.extend(
491
+ _FindChangedVars(
492
+ path, libyuv_deps_entry.version, cr_deps_entry.version
493
+ )
494
+ )
495
+ continue
496
+
497
+ # Use the revision from Chromium's DEPS file.
498
+ new_rev = cr_deps_entry.revision
499
+ assert libyuv_deps_entry.url == cr_deps_entry.url, (
500
+ 'LibYUV DEPS entry %s has a different URL %s than Chromium %s.'
501
+ % (
502
+ path,
503
+ libyuv_deps_entry.url,
504
+ cr_deps_entry.url,
505
+ )
506
+ )
507
+ else:
508
+ if isinstance(libyuv_deps_entry, DepsEntry):
509
+ # Use the HEAD of the deps repo.
510
+ stdout, _ = _RunCommand(
511
+ ['git', 'ls-remote', libyuv_deps_entry.url, 'HEAD']
512
+ )
513
+ new_rev = stdout.strip().split('\t')[0]
514
+ else:
515
+ # The dependency has been removed from chromium.
516
+ # This is handled by FindRemovedDeps.
517
+ continue
518
+
519
+ # Check if an update is necessary.
520
+ if libyuv_deps_entry.revision != new_rev:
521
+ logging.debug('Roll dependency %s to %s', path, new_rev)
522
+ result.append(
523
+ ChangedDep(
524
+ path,
525
+ libyuv_deps_entry.url,
526
+ libyuv_deps_entry.revision,
527
+ new_rev,
528
+ )
529
+ )
530
+ return sorted(result)
531
+
532
+
533
+ def CalculateChangedClang(new_cr_rev):
534
+
535
+ def GetClangRev(lines):
536
+ for line in lines:
537
+ match = CLANG_REVISION_RE.match(line)
538
+ if match:
539
+ return match.group(1)
540
+ raise RollError('Could not parse Clang revision!')
541
+
542
+ with open(CLANG_UPDATE_SCRIPT_LOCAL_PATH, 'r') as f:
543
+ current_lines = f.readlines()
544
+ current_rev = GetClangRev(current_lines)
545
+
546
+ new_clang_update_py = ReadRemoteCrFile(
547
+ CLANG_UPDATE_SCRIPT_URL_PATH, new_cr_rev
548
+ ).splitlines()
549
+ new_rev = GetClangRev(new_clang_update_py)
550
+ return ChangedDep(
551
+ CLANG_UPDATE_SCRIPT_LOCAL_PATH, None, current_rev, new_rev
552
+ )
553
+
554
+
555
+ def GenerateCommitMessage(
556
+ rev_update,
557
+ current_commit_pos,
558
+ new_commit_pos,
559
+ changed_deps_list,
560
+ added_deps_paths=None,
561
+ removed_deps_paths=None,
562
+ clang_change=None,
563
+ ):
564
+ current_cr_rev = rev_update.current_chromium_rev[0:10]
565
+ new_cr_rev = rev_update.new_chromium_rev[0:10]
566
+ rev_interval = '%s..%s' % (current_cr_rev, new_cr_rev)
567
+ git_number_interval = '%s:%s' % (current_commit_pos, new_commit_pos)
568
+
569
+ commit_msg = [
570
+ 'Roll chromium_revision %s (%s)\n'
571
+ % (rev_interval, git_number_interval),
572
+ 'Change log: %s' % (CHROMIUM_LOG_TEMPLATE % rev_interval),
573
+ 'Full diff: %s\n' % (CHROMIUM_COMMIT_TEMPLATE % rev_interval),
574
+ ]
575
+
576
+ def Section(adjective, deps):
577
+ noun = 'dependency' if len(deps) == 1 else 'dependencies'
578
+ commit_msg.append('%s %s' % (adjective, noun))
579
+
580
+ if changed_deps_list:
581
+ Section('Changed', changed_deps_list)
582
+
583
+ for c in changed_deps_list:
584
+ if isinstance(c, ChangedCipdPackage):
585
+ commit_msg.append(
586
+ '* %s: %s..%s' % (c.path, c.current_version, c.new_version)
587
+ )
588
+ elif isinstance(c, ChangedVersionEntry):
589
+ commit_msg.append(
590
+ '* %s_vesion: %s..%s'
591
+ % (c.path, c.current_version, c.new_version)
592
+ )
593
+ else:
594
+ commit_msg.append(
595
+ '* %s: %s/+log/%s..%s'
596
+ % (c.path, c.url, c.current_rev[0:10], c.new_rev[0:10])
597
+ )
598
+
599
+ if added_deps_paths:
600
+ Section('Added', added_deps_paths)
601
+ commit_msg.extend('* %s' % p for p in added_deps_paths)
602
+
603
+ if removed_deps_paths:
604
+ Section('Removed', removed_deps_paths)
605
+ commit_msg.extend('* %s' % p for p in removed_deps_paths)
606
+
607
+ if any([changed_deps_list, added_deps_paths, removed_deps_paths]):
608
+ change_url = CHROMIUM_FILE_TEMPLATE % (rev_interval, 'DEPS')
609
+ commit_msg.append('DEPS diff: %s\n' % change_url)
610
+ else:
611
+ commit_msg.append('No dependencies changed.')
612
+
613
+ if clang_change and clang_change.current_rev != clang_change.new_rev:
614
+ commit_msg.append(
615
+ 'Clang version changed %s:%s'
616
+ % (clang_change.current_rev, clang_change.new_rev)
617
+ )
618
+ change_url = CHROMIUM_FILE_TEMPLATE % (
619
+ rev_interval,
620
+ CLANG_UPDATE_SCRIPT_URL_PATH,
621
+ )
622
+ commit_msg.append('Details: %s\n' % change_url)
623
+ else:
624
+ commit_msg.append('No update to Clang.\n')
625
+
626
+ commit_msg.append('BUG=None')
627
+ return '\n'.join(commit_msg)
628
+
629
+
630
+ def UpdateDepsFile(deps_filename, rev_update, changed_deps, new_cr_content):
631
+ """Update the DEPS file with the new revision."""
632
+
633
+ with open(deps_filename, 'rb') as deps_file:
634
+ deps_content = deps_file.read().decode('utf-8')
635
+
636
+ # Update the chromium_revision variable.
637
+ deps_content = deps_content.replace(
638
+ rev_update.current_chromium_rev, rev_update.new_chromium_rev
639
+ )
640
+
641
+ # Add and remove dependencies. For now: only generated android deps.
642
+ # Since gclient cannot add or remove deps, we on the fact that
643
+ # these android deps are located in one place we can copy/paste.
644
+ deps_re = re.compile(
645
+ ANDROID_DEPS_START + '.*' + ANDROID_DEPS_END, re.DOTALL
646
+ )
647
+ new_deps = deps_re.search(new_cr_content)
648
+ old_deps = deps_re.search(deps_content)
649
+ if not new_deps or not old_deps:
650
+ faulty = 'Chromium' if not new_deps else 'LibYUV'
651
+ raise RollError(
652
+ 'Was expecting to find "%s" and "%s"\nin %s DEPS'
653
+ % (ANDROID_DEPS_START, ANDROID_DEPS_END, faulty)
654
+ )
655
+ deps_content = deps_re.sub(new_deps.group(0), deps_content)
656
+
657
+ for dep in changed_deps:
658
+ if isinstance(dep, ChangedVersionEntry):
659
+ deps_content = deps_content.replace(
660
+ dep.current_version, dep.new_version
661
+ )
662
+
663
+ with open(deps_filename, 'wb') as deps_file:
664
+ deps_file.write(deps_content.encode('utf-8'))
665
+
666
+ # Update each individual DEPS entry.
667
+ for dep in changed_deps:
668
+ # ChangedVersionEntry types are already been processed.
669
+ if isinstance(dep, ChangedVersionEntry):
670
+ continue
671
+ local_dep_dir = os.path.join(GCLIENT_ROOT_DIR, dep.path)
672
+ if not os.path.isdir(local_dep_dir):
673
+ raise RollError(
674
+ 'Cannot find local directory %s. Either run\n'
675
+ 'gclient sync --deps=all\n'
676
+ 'or make sure the .gclient file for your solution contains '
677
+ 'all platforms in the target_os list, i.e.\n'
678
+ 'target_os = ["android", "unix", "mac", "ios", "win"];\n'
679
+ 'Then run "gclient sync" again.' % local_dep_dir
680
+ )
681
+ if isinstance(dep, ChangedCipdPackage):
682
+ package = dep.package.format() # Eliminate double curly brackets
683
+ update = '%s:%s@%s' % (dep.path, package, dep.new_version)
684
+ else:
685
+ update = '%s@%s' % (dep.path, dep.new_rev)
686
+ _RunCommand(
687
+ ['gclient', 'setdep', '--revision', update],
688
+ working_dir=CHECKOUT_ROOT_DIR,
689
+ )
690
+
691
+
692
+ def _IsTreeClean():
693
+ stdout, _ = _RunCommand(['git', 'status', '--porcelain'])
694
+ if len(stdout) == 0:
695
+ return True
696
+
697
+ logging.error('Dirty/unversioned files:\n%s', stdout)
698
+ return False
699
+
700
+
701
+ def _EnsureUpdatedMainBranch(dry_run):
702
+ current_branch = _RunCommand(['git', 'rev-parse', '--abbrev-ref', 'HEAD'])[
703
+ 0
704
+ ].splitlines()[0]
705
+ if current_branch != 'main':
706
+ logging.error('Please checkout the main branch and re-run this script.') # pylint: disable=line-too-long
707
+ if not dry_run:
708
+ sys.exit(-1)
709
+
710
+ logging.info('Updating main branch...')
711
+ _RunCommand(['git', 'pull'])
712
+
713
+
714
+ def _CreateRollBranch(dry_run):
715
+ logging.info('Creating roll branch: %s', ROLL_BRANCH_NAME)
716
+ if not dry_run:
717
+ _RunCommand(['git', 'checkout', '-b', ROLL_BRANCH_NAME])
718
+
719
+
720
+ def _RemovePreviousRollBranch(dry_run):
721
+ active_branch, branches = _GetBranches()
722
+ if active_branch == ROLL_BRANCH_NAME:
723
+ active_branch = 'main'
724
+ if ROLL_BRANCH_NAME in branches:
725
+ logging.info('Removing previous roll branch (%s)', ROLL_BRANCH_NAME)
726
+ if not dry_run:
727
+ _RunCommand(['git', 'checkout', active_branch])
728
+ _RunCommand(['git', 'branch', '-D', ROLL_BRANCH_NAME])
729
+
730
+
731
+ def _LocalCommit(commit_msg, dry_run):
732
+ logging.info('Committing changes locally.')
733
+ if not dry_run:
734
+ _RunCommand(['git', 'add', '--update', '.'])
735
+ _RunCommand(['git', 'commit', '-m', commit_msg])
736
+
737
+
738
+ def ChooseCQMode(skip_cq, cq_over, current_commit_pos, new_commit_pos):
739
+ if skip_cq:
740
+ return 0
741
+ if (new_commit_pos - current_commit_pos) < cq_over:
742
+ return 1
743
+ return 2
744
+
745
+
746
+ def _GetCcRecipients(changed_deps_list):
747
+ """Returns a list of emails to notify based on the changed deps list."""
748
+ cc_recipients = []
749
+ for _ in changed_deps_list:
750
+ pass
751
+ return cc_recipients
752
+
753
+
754
+ def _UploadCL(commit_queue_mode, add_cc=None):
755
+ """Upload the committed changes as a changelist to Gerrit.
756
+
757
+ commit_queue_mode:
758
+ - 2: Submit to commit queue.
759
+ - 1: Run trybots but do not submit to CQ.
760
+ - 0: Skip CQ, upload only.
761
+
762
+ add_cc: A list of email addresses to add as CC recipients.
763
+ """
764
+ cc_recipients = []
765
+ if add_cc:
766
+ cc_recipients.extend(add_cc)
767
+ cmd = ['git', 'cl', 'upload', '--force', '--bypass-hooks']
768
+ if commit_queue_mode >= 2:
769
+ logging.info('Sending the CL to the CQ...')
770
+ cmd.extend(['-o', 'label=Bot-Commit+1'])
771
+ cmd.extend(['-o', 'label=Commit-Queue+2'])
772
+ cmd.extend(['--send-mail', '--cc', ','.join(cc_recipients)])
773
+ elif commit_queue_mode >= 1:
774
+ logging.info('Starting CQ dry run...')
775
+ cmd.extend(['-o', 'label=Commit-Queue+1'])
776
+ extra_env = {
777
+ 'EDITOR': 'true',
778
+ 'SKIP_GCE_AUTH_FOR_GIT': '1',
779
+ }
780
+ stdout, stderr = _RunCommand(cmd, extra_env=extra_env)
781
+ logging.debug(
782
+ 'Output from "git cl upload":\nstdout:\n%s\n\nstderr:\n%s',
783
+ stdout,
784
+ stderr,
785
+ )
786
+
787
+
788
+ def GetRollRevisionRanges(opts, libyuv_deps):
789
+ current_cr_rev = libyuv_deps['vars']['chromium_revision']
790
+ new_cr_rev = opts.revision
791
+ if not new_cr_rev:
792
+ stdout, _ = _RunCommand(['git', 'ls-remote', CHROMIUM_SRC_URL, 'HEAD'])
793
+ head_rev = stdout.strip().split('\t')[0]
794
+ logging.info('No revision specified. Using HEAD: %s', head_rev)
795
+ new_cr_rev = head_rev
796
+
797
+ return ChromiumRevisionUpdate(current_cr_rev, new_cr_rev)
798
+
799
+
800
+ def main():
801
+ p = argparse.ArgumentParser()
802
+ p.add_argument(
803
+ '--clean',
804
+ action='store_true',
805
+ default=False,
806
+ help='Removes any previous local roll branch.',
807
+ )
808
+ p.add_argument(
809
+ '-r',
810
+ '--revision',
811
+ help=(
812
+ 'Chromium Git revision to roll to. Defaults to the '
813
+ 'Chromium HEAD revision if omitted.'
814
+ ),
815
+ )
816
+ p.add_argument(
817
+ '--dry-run',
818
+ action='store_true',
819
+ default=False,
820
+ help=(
821
+ "Calculate changes and modify DEPS, but don't create "
822
+ 'any local branch, commit, upload CL or send any '
823
+ 'tryjobs.'
824
+ ),
825
+ )
826
+ p.add_argument(
827
+ '-i',
828
+ '--ignore-unclean-workdir',
829
+ action='store_true',
830
+ default=False,
831
+ help=(
832
+ 'Ignore if the current branch is not main or if there '
833
+ 'are uncommitted changes (default: %(default)s).'
834
+ ),
835
+ )
836
+ grp = p.add_mutually_exclusive_group()
837
+ grp.add_argument(
838
+ '--skip-cq',
839
+ action='store_true',
840
+ default=False,
841
+ help='Skip sending the CL to the CQ (default: %(default)s)',
842
+ )
843
+ grp.add_argument(
844
+ '--cq-over',
845
+ type=int,
846
+ default=1,
847
+ help=(
848
+ 'Commit queue dry run if the revision difference '
849
+ 'is below this number (default: %(default)s)'
850
+ ),
851
+ )
852
+ p.add_argument(
853
+ '-v',
854
+ '--verbose',
855
+ action='store_true',
856
+ default=False,
857
+ help='Be extra verbose in printing of log messages.',
858
+ )
859
+ opts = p.parse_args()
860
+
861
+ if opts.verbose:
862
+ logging.basicConfig(level=logging.DEBUG)
863
+ else:
864
+ logging.basicConfig(level=logging.INFO)
865
+
866
+ if not opts.ignore_unclean_workdir and not _IsTreeClean():
867
+ logging.error('Please clean your local checkout first.')
868
+ return 1
869
+
870
+ if opts.clean:
871
+ _RemovePreviousRollBranch(opts.dry_run)
872
+
873
+ if not opts.ignore_unclean_workdir:
874
+ _EnsureUpdatedMainBranch(opts.dry_run)
875
+
876
+ deps_filename = os.path.join(CHECKOUT_ROOT_DIR, 'DEPS')
877
+ libyuv_deps = ParseLocalDepsFile(deps_filename)
878
+
879
+ rev_update = GetRollRevisionRanges(opts, libyuv_deps)
880
+
881
+ current_commit_pos = ParseCommitPosition(
882
+ ReadRemoteCrCommit(rev_update.current_chromium_rev)
883
+ )
884
+ new_commit_pos = ParseCommitPosition(
885
+ ReadRemoteCrCommit(rev_update.new_chromium_rev)
886
+ )
887
+
888
+ new_cr_content = ReadRemoteCrFile('DEPS', rev_update.new_chromium_rev)
889
+ new_cr_deps = ParseDepsDict(new_cr_content)
890
+ changed_deps = CalculateChangedDeps(libyuv_deps, new_cr_deps)
891
+ # Discard other deps, assumed to be chromium-only dependencies.
892
+ new_generated_android_deps, _ = FindAddedDeps(libyuv_deps, new_cr_deps)
893
+ removed_generated_android_deps, other_deps = FindRemovedDeps(
894
+ libyuv_deps, new_cr_deps
895
+ )
896
+ if other_deps:
897
+ raise RollError(
898
+ 'LibYUV DEPS entries are missing from Chromium: %s.\n'
899
+ 'Remove them or add them to either '
900
+ 'LIBYUV_ONLY_DEPS or DONT_AUTOROLL_THESE.' % other_deps
901
+ )
902
+ clang_change = CalculateChangedClang(rev_update.new_chromium_rev)
903
+ commit_msg = GenerateCommitMessage(
904
+ rev_update,
905
+ current_commit_pos,
906
+ new_commit_pos,
907
+ changed_deps,
908
+ added_deps_paths=new_generated_android_deps,
909
+ removed_deps_paths=removed_generated_android_deps,
910
+ clang_change=clang_change,
911
+ )
912
+ logging.debug('Commit message:\n%s', commit_msg)
913
+
914
+ _CreateRollBranch(opts.dry_run)
915
+ if not opts.dry_run:
916
+ UpdateDepsFile(deps_filename, rev_update, changed_deps, new_cr_content)
917
+ if _IsTreeClean():
918
+ logging.info('No DEPS changes detected, skipping CL creation.')
919
+ else:
920
+ _LocalCommit(commit_msg, opts.dry_run)
921
+ commit_queue_mode = ChooseCQMode(
922
+ opts.skip_cq, opts.cq_over, current_commit_pos, new_commit_pos
923
+ )
924
+ logging.info('Uploading CL...')
925
+ if not opts.dry_run:
926
+ _UploadCL(commit_queue_mode, _GetCcRecipients(changed_deps))
927
+ return 0
928
+
929
+
930
+ if __name__ == '__main__':
931
+ sys.exit(main())