From 0bc7c4832e4f2d453e4826c9a2e1197e11bd6ec7 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Fri, 16 Aug 2024 21:19:29 +0000 Subject: [PATCH] [PRESUBMIT] Read DEPS file from Git in CheckForCommitObjects CheckForCommitObjects is not working correctly if there is a PanProjectChecks in non-root PRESUBMIT.py together with a DEPS file in the same directory. Instead, PRESUBMIT needs to check the root DEPS file. In order to get commit objects (gitlink), we need to run Git ops. This patch relies on Git to provide the root DEPS file. R=gavinmak@google.com Fixed: 359944302 Change-Id: I7934a24c1ea8e6b6daa2f936ad4209ad9cdad5ce Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5784174 Commit-Queue: Josip Sokcevic Reviewed-by: Gavin Mak Auto-Submit: Josip Sokcevic Commit-Queue: Gavin Mak --- presubmit_canned_checks.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 6dd4c3c29..03608d185 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -1970,14 +1970,14 @@ def CheckForCommitObjects(input_api, output_api): ] # Get DEPS file. - deps_file = input_api.os_path.join(input_api.PresubmitLocalPath(), 'DEPS') - if not input_api.os_path.isfile(deps_file): - # No DEPS file, carry on! + try: + deps_content = input_api.subprocess.check_output( + ['git', 'show', 'HEAD:DEPS'], cwd=input_api.PresubmitLocalPath()) + deps = _ParseDeps(deps_content) + except Exception: + # No DEPS file, so skip this check. return [] - with open(deps_file) as f: - deps_content = f.read() - deps = _ParseDeps(deps_content) # set default if 'deps' not in deps: deps['deps'] = {}