From 6dc002169ecc2d002983ab459c5e7f2bc870e8a3 Mon Sep 17 00:00:00 2001 From: Eric Boren Date: Wed, 24 Jul 2019 15:15:43 -0400 Subject: [PATCH] [infra] Fix DEPS to use full commit hashes Branches and tags may change out from under us or disappear entirely. Also add a presubmit check to prevent regressing. Change-Id: I73878907d9a72f7de7b50989919c3a7bc385abf9 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/229490 Reviewed-by: Ben Wagner aka dogben Commit-Queue: Eric Boren --- DEPS | 10 +++---- PRESUBMIT.py | 19 ++++++++++++ infra/bots/check_deps.py | 64 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 infra/bots/check_deps.py diff --git a/DEPS b/DEPS index 62562874d8..49da415206 100644 --- a/DEPS +++ b/DEPS @@ -9,17 +9,17 @@ deps = { "common" : "https://skia.googlesource.com/common.git@9737551d7a52c3db3262db5856e6bcd62c462b92", "third_party/externals/angle2" : "https://chromium.googlesource.com/angle/angle.git@557e3853da56b9ff72be8ad8ce3643f5cdeb1d4d", "third_party/externals/dawn" : "https://dawn.googlesource.com/dawn.git@472bd1ec29d8d4e03404bf4b4e0233e4fc6031ce", - "third_party/externals/dng_sdk" : "https://android.googlesource.com/platform/external/dng_sdk.git@c8d0c9b", + "third_party/externals/dng_sdk" : "https://android.googlesource.com/platform/external/dng_sdk.git@c8d0c9b1d16bfda56f15165d39e0ffa360a11123", "third_party/externals/egl-registry" : "https://skia.googlesource.com/external/github.com/KhronosGroup/EGL-Registry@a0bca08de07c7d7651047bedc0b653cfaaa4f2ae", - "third_party/externals/expat" : "https://android.googlesource.com/platform/external/expat.git@android-6.0.1_r55", + "third_party/externals/expat" : "https://android.googlesource.com/platform/external/expat.git@e5aa0a2cb0a5f759ef31c0819dc67d9b14246a4a", "third_party/externals/freetype" : "https://skia.googlesource.com/third_party/freetype2.git@05439f5cc69eaa3deaf3db52a7999af09a2c293a", "third_party/externals/harfbuzz" : "https://chromium.googlesource.com/external/github.com/harfbuzz/harfbuzz.git@1bada656a86e9cb27d4a6b9fcc50748f0bd9c1d9", "third_party/externals/icu" : "https://chromium.googlesource.com/chromium/deps/icu.git@407b39301e71006b68bd38e770f35d32398a7b14", "third_party/externals/imgui" : "https://skia.googlesource.com/external/github.com/ocornut/imgui.git@d38d7c6628bebd02692cfdd6fa76b4d992a35b75", - "third_party/externals/libjpeg-turbo" : "https://skia.googlesource.com/external/github.com/libjpeg-turbo/libjpeg-turbo.git@2.0.0", + "third_party/externals/libjpeg-turbo" : "https://skia.googlesource.com/external/github.com/libjpeg-turbo/libjpeg-turbo.git@574f3a772c96dc9db2c98ef24706feb3f6dbda9a", "third_party/externals/libpng" : "https://skia.googlesource.com/third_party/libpng.git@386707c6d19b974ca2e3db7f5c61873813c6fe44", - "third_party/externals/libwebp" : "https://chromium.googlesource.com/webm/libwebp.git@v1.0.3-rc1", - "third_party/externals/lua" : "https://skia.googlesource.com/external/github.com/lua/lua.git@v5.3.4", + "third_party/externals/libwebp" : "https://chromium.googlesource.com/webm/libwebp.git@0fe1a89dbf1930fc2554dbe76adad5d962054ead", + "third_party/externals/lua" : "https://skia.googlesource.com/external/github.com/lua/lua.git@e354c6355e7f48e087678ec49e340ca0696725b1", "third_party/externals/microhttpd" : "https://android.googlesource.com/platform/external/libmicrohttpd@748945ec6f1c67b7efc934ab0808e1d32f2fb98d", "third_party/externals/opencl-lib" : "https://skia.googlesource.com/external/github.com/GPUOpen-Tools/common-lib-amd-APPSDK-3.0@4e6d30e406d2e5a65e1d65e404fe6df5f772a32b", "third_party/externals/opencl-registry" : "https://skia.googlesource.com/external/github.com/KhronosGroup/OpenCL-Registry@932ed55c85f887041291cef8019e54280c033c35", diff --git a/PRESUBMIT.py b/PRESUBMIT.py index bd88c0a3a0..2513c9cbec 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -226,6 +226,24 @@ class _WarningsAsErrors(): self.output_api.PresubmitPromptWarning = self.old_warning +def _CheckDEPSValid(input_api, output_api): + """Ensure that DEPS contains valid entries.""" + results = [] + script = os.path.join('infra', 'bots', 'check_deps.py') + relevant_files = ('DEPS', script) + for f in input_api.AffectedFiles(): + if f.LocalPath() in relevant_files: + break + else: + return results + cmd = ['python', script] + try: + subprocess.check_output(cmd, stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as e: + results.append(output_api.PresubmitError(e.output)) + return results + + def _CommonChecks(input_api, output_api): """Presubmit checks common to upload and commit.""" results = [] @@ -251,6 +269,7 @@ def _CommonChecks(input_api, output_api): source_file_filter=sources)) results.extend(_ToolFlags(input_api, output_api)) results.extend(_CheckCompileIsolate(input_api, output_api)) + results.extend(_CheckDEPSValid(input_api, output_api)) return results diff --git a/infra/bots/check_deps.py b/infra/bots/check_deps.py new file mode 100644 index 0000000000..6f3106643d --- /dev/null +++ b/infra/bots/check_deps.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python +# +# Copyright 2019 Google LLC +# +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + + +"""Check the DEPS file for correctness.""" + + +import os +import re +import subprocess +import sys + +import utils + + +INFRA_BOTS_DIR = os.path.dirname(os.path.realpath(__file__)) +SKIA_DIR = os.path.abspath(os.path.join(INFRA_BOTS_DIR, os.pardir, os.pardir)) + + +def main(): + """Load the DEPS file and verify that all entries are valid.""" + # Find gclient.py and run that instead of simply "gclient", which calls into + # update_depot_tools. + gclient = subprocess.check_output([utils.WHICH, utils.GCLIENT]) + gclient_py = os.path.join(os.path.dirname(gclient), 'gclient.py') + python = sys.executable or 'python' + + # Obtain the DEPS mapping. + output = subprocess.check_output( + [python, gclient_py, 'revinfo'], cwd=SKIA_DIR) + + # Check each entry. + errs = [] + for e in output.rstrip().splitlines(): + split = e.split(': ') + if len(split) != 2: + errs.append( + 'Failed to parse `gclient revinfo` output; invalid format: %s' % e) + if split[0] == 'skia': + continue + split = split[1].split('@') + if len(split) != 2: + errs.append( + 'Failed to parse `gclient revinfo` output; invalid format: %s' % e) + repo = split[0] + rev = split[1] + if not 'googlesource.com' in repo: + errs.append( + 'DEPS must be hosted on googlesource.com; %s is not allowed.' % repo) + if not re.match(r'^[a-z0-9]{40}$', rev): + errs.append('%s: "%s" does not look like a commit hash.' % (repo, rev)) + if errs: + print >> sys.stderr, 'Found problems in DEPS:' + for err in errs: + print >> sys.stderr, err + sys.exit(1) + + +if __name__ == '__main__': + main()