From 7d47eb5495a0e5991dfc77171aaa799004431f35 Mon Sep 17 00:00:00 2001 From: Robert Iannucci Date: Wed, 6 Dec 2017 12:18:18 -0800 Subject: [PATCH] [PRESUBMIT] Add cipd package checks for all known manifests. This also improves the cipd manifest canned check to produce unique names in order to debug PRESUBMIT's more easily. Adds onto https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/708354 R=maruel@chromium.org, tandrii@chromium.org, vadimsh@chromium.org Bug: Change-Id: I9f086996998608092a4d23f5c98fbac34117a9e4 Reviewed-on: https://chromium-review.googlesource.com/811445 Reviewed-by: Vadim Shtayura Commit-Queue: Robbie Iannucci --- PRESUBMIT.py | 38 ++++++++++++++++++++++++ bootstrap/win/manifest.txt | 2 ++ bootstrap/win/manifest_bleeding_edge.txt | 2 ++ presubmit_canned_checks.py | 9 +++++- 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 392d1e30bb..13a2428fe3 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -12,6 +12,16 @@ import fnmatch import os +ENSURE_FILE_TEMPLATE = r''' +$VerifiedPlatform linux-386 linux-amd64 linux-arm64 linux-armv6l linux-mips64 +$VerifiedPlatform linux-ppc64 linux-ppc64le linux-s390x +$VerifiedPlatform mac-amd64 +$VerifiedPlatform windows-386 windows-amd64 + +%s %s +''' + + def DepotToolsPylint(input_api, output_api): """Gather all the pylint logic into one place to make it self-contained.""" white_list = [ @@ -59,6 +69,34 @@ def CommonChecks(input_api, output_api, tests_to_black_list): tests.extend(unit_tests) else: print('Warning: not running unit tests on Windows') + + # Validate CIPD manifests. + root = input_api.os_path.normpath( + input_api.os_path.abspath(input_api.PresubmitLocalPath())) + rel_file = lambda rel: input_api.os_path.join(root, rel) + cipd_manifests = set(rel_file(input_api.os_path.join(*x)) for x in ( + ('cipd_manifest.txt',), + ('bootstrap', 'win', 'manifest.txt'), + ('bootstrap', 'win', 'manifest_bleeding_edge.txt'), + + # Also generate a file for the cipd client itself. + ('cipd_client_version',), + )) + affected_manifests = input_api.AffectedFiles( + include_deletes=False, + file_filter=lambda x: + input_api.os_path.normpath(x.AbsoluteLocalPath()) in cipd_manifests) + for path in affected_manifests: + path = path.AbsoluteLocalPath() + if path.endswith('.txt'): + tests.append(input_api.canned_checks.CheckCIPDManifest( + input_api, output_api, path=path)) + else: + pkg = 'infra/tools/cipd/${platform}' + ver = input_api.ReadFile(path) + tests.append(input_api.canned_checks.CheckCIPDManifest( + input_api, output_api, content=ENSURE_FILE_TEMPLATE % (pkg, ver))) + results.extend(input_api.RunTests(tests)) return results diff --git a/bootstrap/win/manifest.txt b/bootstrap/win/manifest.txt index 3213a77bef..6ca9359f03 100644 --- a/bootstrap/win/manifest.txt +++ b/bootstrap/win/manifest.txt @@ -11,6 +11,8 @@ # string "cpython" and ends with the CIPD tag "version:VERSION". It uses this # to extract VERSION. +$VerifiedPlatform windows-386 windows-amd64 + @Subdir python infra/python/cpython/windows-386 version:2.7.6 diff --git a/bootstrap/win/manifest_bleeding_edge.txt b/bootstrap/win/manifest_bleeding_edge.txt index 364dfe4edb..8f2758e348 100644 --- a/bootstrap/win/manifest_bleeding_edge.txt +++ b/bootstrap/win/manifest_bleeding_edge.txt @@ -11,6 +11,8 @@ # string "cpython" and ends with the CIPD tag "version:VERSION". It uses this # to extract VERSION. +$VerifiedPlatform windows-386 windows-amd64 + @Subdir python infra/python/cpython/${platform} version:2.7.13.chromium7 diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index ef6b7c083b..0b2db367fa 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -1165,15 +1165,22 @@ def CheckCIPDManifest(input_api, output_api, path=None, content=None): if path: assert content is None, 'Cannot provide both "path" and "content".' cmd += ['-ensure-file', path] + name = 'Check CIPD manifest %r' % path elif content: assert path is None, 'Cannot provide both "path" and "content".' cmd += ['-ensure-file=-'] kwargs['stdin'] = content + # quick and dirty parser to extract checked packages. + packages = [ + l.split()[0] for l in (ll.strip() for ll in content.splitlines()) + if ' ' in l and not l.startswith('$') + ] + name = 'Check CIPD packages from string: %r' % (packages,) else: raise Exception('Exactly one of "path" or "content" must be provided.') return input_api.Command( - 'Check CIPD manifest', + name, cmd, kwargs, output_api.PresubmitError)