From 6c8d2a9ce540ae481fefd3028aa91753c7ed796c Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Tue, 29 Aug 2023 01:48:19 +0000 Subject: [PATCH] Revert "Check if DEPS git is not in git submodules" This reverts commit e6f40ea0341552c3e78fb107fe9f37b87d95f321. Reason for revert: infra and angle have git dependencies with no gitlink. Original change's description: > Check if DEPS git is not in git submodules > > If a new git dependency is added to DEPS file, presubmit check should > fail if there's no corresponding git submodule entry if git_dependencies > is set to SYNC. > > R=jojwang@google.com > > Bug: 1476115 > Change-Id: I0fdebb036c129c2f97524b86ee4d70c07e5b0091 > Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4818792 > Commit-Queue: Josip Sokcevic > Reviewed-by: Joanna Wang Bug: 1476115 Change-Id: Id990407f1738ac1e3d3950e0a85e9e39f8f1b624 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4820455 Auto-Submit: Josip Sokcevic Commit-Queue: Rubber Stamper Bot-Commit: Rubber Stamper --- presubmit_canned_checks.py | 62 ++++++++++++++------------------------ 1 file changed, 22 insertions(+), 40 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 060379eab..2ffcfb2ee 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -1712,24 +1712,6 @@ def CheckForCommitObjects(input_api, output_api): Returns: A presubmit error if a commit object is not expected. """ - # 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! - return [] - - with open(deps_file) as f: - deps_content = f.read() - deps = _ParseDeps(deps_content) - # set default - if 'deps' not in deps: - deps['deps'] = {} - if 'git_dependencies' not in deps: - deps['git_dependencies'] = 'DEPS' - - if deps['git_dependencies'] == 'SUBMODULES': - # git submodule is source of truth, so no further action needed. - return [] def parse_tree_entry(ent): """Splits a tree entry into components @@ -1762,7 +1744,17 @@ def CheckForCommitObjects(input_api, output_api): if len(commit_tree_entries) == 0: return [] - if deps['git_dependencies'] == 'DEPS': + # This gets 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! + return [] + + with open(deps_file) as f: + deps_content = f.read() + deps = _ParseDeps(deps_content) + + if not 'git_dependencies' in deps or deps['git_dependencies'] == 'DEPS': commit_tree_entries = [x[3] for x in commit_tree_entries] return [ output_api.PresubmitError( @@ -1774,30 +1766,19 @@ def CheckForCommitObjects(input_api, output_api): 'again:\n', commit_tree_entries) ] - assert deps['git_dependencies'] == 'SYNC', 'unexpected git_dependencies.' + if deps['git_dependencies'] == 'SUBMODULES': + # git submodule is source of truth, so no further action needed. + return [] - # Create mapping HASH -> PATH - git_submodules = {} - for commit_tree_entry in commit_tree_entries: - git_submodules[commit_tree_entry[2]] = commit_tree_entry[3] + assert deps['git_dependencies'] == 'SYNC', 'unexpected git_dependencies.' mismatch_entries = [] deps_msg = "" - for dep_path, dep in deps['deps'].items(): - if 'dep_type' in dep and dep['dep_type'] != 'git': - continue - - url = dep if isinstance(dep, str) else dep['url'] - commit_hash = url.split('@')[-1] - if commit_hash in git_submodules: - git_submodules.pop(commit_hash) - else: - mismatch_entries.append(dep_path) - deps_msg += f"\n [DEPS] {dep_path} -> {commit_hash}" - - for commit_hash, path in git_submodules.items(): - mismatch_entries.append(path) - deps_msg += f"\n [gitlink] {path} -> {commit_hash}" + for commit_tree_entry in commit_tree_entries: + # Search for commit hashes in DEPS file - they must be present + if commit_tree_entry[2] not in deps_content: + mismatch_entries.append(commit_tree_entry[3]) + deps_msg += f"\n {commit_tree_entry[3]} -> {commit_tree_entry[2]}" if mismatch_entries: return [ @@ -1808,7 +1789,8 @@ def CheckForCommitObjects(input_api, output_api): 'the following command in the root of this repository:\n' ' gclient gitmodules' '\n\n' - 'The following entries diverged: ' + deps_msg) + 'If git submodule changes are correct, update the following DEPS ' + 'entries to: ' + deps_msg) ] return []