Revert of Don't require DEPS OWNERS when moving lines around in a DEPS file. (patchset #2 id:20001 of https://codereview.chromium.org/2759593003/ )
Reason for revert:
Broke DEPS auto rollers.
https://bugs.chromium.org/p/chromium/issues/detail?id=704405
Original issue's description:
> Don't require DEPS OWNERS when moving lines around in a DEPS file.
>
> As a bonus, less regex than before and also correctly handles the
> '!' prefix in DEPS files now.
>
> BUG=702851
>
> Review-Url: https://codereview.chromium.org/2759593003
> Cr-Commit-Position: refs/heads/master@{#458928}
> Committed: https://chromium.googlesource.com/chromium/src/+/63dd720c98271a15da8e483906dc92c3d0603e7d
[email protected],[email protected]
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=702851
Review-Url: https://codereview.chromium.org/2772693002
Cr-Commit-Position: refs/heads/master@{#459004}
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index beca2b5..16f00ad 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -1049,26 +1049,7 @@
return results
-def _ExtractAddRulesFromParsedDeps(parsed_deps):
- """Extract the rules that add dependencies from a parsed DEPS file.
-
- Args:
- parsed_deps: the locals dictionary from evaluating the DEPS file."""
- add_rules = set()
- add_rules.update([
- rule[1:] for rule in parsed_deps.get('include_rules', [])
- if rule.startswith('+') or rule.startswith('!')
- ])
- for specific_file, rules in parsed_deps.get('specific_include_rules',
- {}).iteritems():
- add_rules.update([
- rule[1:] for rule in rules
- if rule.startswith('+') or rule.startswith('!')
- ])
- return add_rules
-
-
-def _CalculateAddedDeps(os_path, old_contents, new_contents):
+def _FilesToCheckForIncomingDeps(re, changed_lines):
"""Helper method for _CheckAddedDepsHaveTargetApprovals. Returns
a set of DEPS entries that we should look up.
@@ -1079,27 +1060,22 @@
# We ignore deps entries on auto-generated directories.
AUTO_GENERATED_DIRS = ['grit', 'jni']
- global_scope = {}
- local_scope = {}
- exec old_contents in global_scope, local_scope
- old_deps = _ExtractAddRulesFromParsedDeps(local_scope)
-
- global_scope = {}
- local_scope = {}
- exec new_contents in global_scope, local_scope
- new_deps = _ExtractAddRulesFromParsedDeps(local_scope)
-
- added_deps = new_deps.difference(old_deps)
-
+ # This pattern grabs the path without basename in the first
+ # parentheses, and the basename (if present) in the second. It
+ # relies on the simple heuristic that if there is a basename it will
+ # be a header file ending in ".h".
+ pattern = re.compile(
+ r"""['"]\+([^'"]+?)(/[a-zA-Z0-9_]+\.h)?['"].*""")
results = set()
- for added_dep in added_deps:
- if added_dep.split('/')[0] in AUTO_GENERATED_DIRS:
- continue
- # Assume that a rule that ends in .h is a rule for a specific file.
- if added_dep.endswith('.h'):
- results.add(added_dep)
- else:
- results.add(os_path.join(added_dep, 'DEPS'))
+ for changed_line in changed_lines:
+ m = pattern.match(changed_line)
+ if m:
+ path = m.group(1)
+ if path.split('/')[0] not in AUTO_GENERATED_DIRS:
+ if m.group(2):
+ results.add('%s%s' % (path, m.group(2)))
+ else:
+ results.add('%s/DEPS' % path)
return results
@@ -1109,7 +1085,7 @@
target file or directory, to avoid layering violations from being
introduced. This check verifies that this happens.
"""
- virtual_depended_on_files = set()
+ changed_lines = set()
file_filter = lambda f: not input_api.re.match(
r"^third_party[\\\/]WebKit[\\\/].*", f.LocalPath())
@@ -1117,11 +1093,14 @@
file_filter=file_filter):
filename = input_api.os_path.basename(f.LocalPath())
if filename == 'DEPS':
- virtual_depended_on_files.update(_CalculateAddedDeps(
- input_api.os_path,
- '\n'.join(f.OldContents()),
- '\n'.join(f.NewContents())))
+ changed_lines |= set(line.strip()
+ for line_num, line
+ in f.ChangedContents())
+ if not changed_lines:
+ return []
+ virtual_depended_on_files = _FilesToCheckForIncomingDeps(input_api.re,
+ changed_lines)
if not virtual_depended_on_files:
return []