Don't fail on cog when gclient_args.gni is not found
This can happen when presubmits are run before gclient sync in a cog workspace. We should warn the user instead of failing and blocking the change. Bug: b/355285071 Change-Id: I201e89cec2494bd343d6371e4f0ea8b0704d9870 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5740154 Reviewed-by: Josip Sokcevic <sokcevic@chromium.org> Commit-Queue: Gavin Mak <gavinmak@google.com> Reviewed-by: Peter Wen <wnwen@chromium.org> Cr-Commit-Position: refs/heads/main@{#1333186}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
68da7f63cb
commit
23884403b9
30
PRESUBMIT.py
30
PRESUBMIT.py
@ -5105,7 +5105,35 @@ def CheckPydepsNeedsUpdating(input_api, output_api, checker_for_tests=None):
|
||||
if results:
|
||||
return results
|
||||
|
||||
is_android = _ParseGclientArgs().get('checkout_android', 'false') == 'true'
|
||||
try:
|
||||
parsed_args = _ParseGclientArgs()
|
||||
except FileNotFoundError:
|
||||
message = (
|
||||
'build/config/gclient_args.gni not found. Please make sure your '
|
||||
'workspace has been initialized with gclient sync.'
|
||||
)
|
||||
import sys
|
||||
original_sys_path = sys.path
|
||||
try:
|
||||
sys.path = sys.path + [
|
||||
input_api.os_path.join(input_api.PresubmitLocalPath(),
|
||||
'third_party', 'depot_tools')
|
||||
]
|
||||
import gclient_utils
|
||||
if gclient_utils.IsEnvCog():
|
||||
# Users will always hit this when they run presubmits before cog
|
||||
# workspace initialization finishes. The check shouldn't fail in
|
||||
# this case. This is an unavoidable workaround that's needed for
|
||||
# good presubmit UX for cog.
|
||||
results.append(output_api.PresubmitPromptWarning(message))
|
||||
else:
|
||||
results.append(output_api.PresubmitError(message))
|
||||
return results
|
||||
finally:
|
||||
# Restore sys.path to what it was before.
|
||||
sys.path = original_sys_path
|
||||
|
||||
is_android = parsed_args.get('checkout_android', 'false') == 'true'
|
||||
checker = checker_for_tests or PydepsChecker(input_api, _ALL_PYDEPS_FILES)
|
||||
affected_pydeps = set(checker.ComputeAffectedPydeps())
|
||||
affected_android_pydeps = affected_pydeps.intersection(
|
||||
|
Reference in New Issue
Block a user