0

Reland "Add presubmit error when adding new download from google storage hook"

This is a reland of commit 729bfb6635

What's changed: Previously it was picking up affected files from paths
that end in DEPS, such as chrome/test/DEPS, because it was extracting
the basename. Changed it to look at the full path so it should only
analyze changes from src/DEPS.

Original change's description:
> Add presubmit error when adding new download from google storage hook
>
> If a user adds a new hook using the download_from_google_storage
> script, presubmit will error and tell the user to add it as a first
> class dep instead.
>
> Bug: b/324418194
> Change-Id: Id074b36d341f9ebadbb5301b36203f3b8122174e
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5447679
> Reviewed-by: Joanna Wang <jojwang@chromium.org>
> Commit-Queue: Stephanie Kim <kimstephanie@google.com>
> Reviewed-by: Dirk Pranke <dpranke@google.com>
> Cr-Commit-Position: refs/heads/main@{#1289381}

Bug: b/324418194
Change-Id: Ifbdd55c0db2b8d306f5edce7dc973c2a5ef46ed1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5472455
Commit-Queue: Stephanie Kim <kimstephanie@google.com>
Reviewed-by: Joanna Wang <jojwang@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@google.com>
Cr-Commit-Position: refs/heads/main@{#1291938}
This commit is contained in:
Stephanie Kim
2024-04-24 16:54:02 +00:00
committed by Chromium LUCI CQ
parent 002b973256
commit ec4f55a476

@ -3273,6 +3273,37 @@ def _CalculateAddedDeps(os_path, old_contents, new_contents):
results.add(os_path.join(added_dep, 'DEPS'))
return results
def CheckForNewDEPSDownloadFromGoogleStorageHooks(input_api, output_api):
"""Checks that there are no new download_from_google_storage hooks"""
for f in input_api.AffectedFiles(include_deletes=False):
if f.LocalPath() == 'DEPS':
old_hooks = _ParseDeps('\n'.join(f.OldContents()))['hooks']
new_hooks = _ParseDeps('\n'.join(f.NewContents()))['hooks']
old_name_to_hook = {hook['name']: hook for hook in old_hooks}
new_name_to_hook = {hook['name']: hook for hook in new_hooks}
added_hook_names = set(new_name_to_hook.keys()) - set(
old_name_to_hook.keys())
if not added_hook_names:
return []
new_download_from_google_storage_hooks = []
for new_hook in added_hook_names:
hook = new_name_to_hook[new_hook]
action_cmd = hook['action']
if any('download_from_google_storage' in arg
for arg in action_cmd):
new_download_from_google_storage_hooks.append(new_hook)
if new_download_from_google_storage_hooks:
return [
output_api.PresubmitError(
'Please do not add new download_from_google_storage '
'hooks. Instead, add a `gcs` dep_type entry to `deps`. '
'See https://chromium.googlesource.com/chromium/src.git'
'/+/refs/heads/main/docs/gcs_dependencies.md for more '
'info. Added hooks:',
items=new_download_from_google_storage_hooks)
]
return []
def CheckAddedDepsHaveTargetApprovals(input_api, output_api):
"""When a dependency prefixed with + is added to a DEPS file, we