Commit ad7901f9 authored by Ken Rockot's avatar Ken Rockot Committed by Commit Bot

Fix mojom backcompat presubmit with deleted files

The presubmit step for checking mojom backward-compatibility does not
work properly when a mojom file is deleted. This is due to incorrect use
of the presubmit input API, effectively not providing the checking tool
with any information about deleted files.

This fixes that.

Fixed: 1091407
Change-Id: I4cd3d7bb5ce07a7d75e8bac99319c75ca6d28118
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2231266Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#775248}
parent 75fd5c06
......@@ -5200,8 +5200,9 @@ def _CheckTranslationExpectations(input_api, output_api,
def _CheckStableMojomChanges(input_api, output_api):
"""Changes to [Stable] mojom types must preserve backward-compatibility."""
changed_mojoms = [f for f in input_api.AffectedSourceFiles(None)
if f.LocalPath().endswith('.mojom')]
changed_mojoms = input_api.AffectedFiles(
include_deletes=True,
file_filter=lambda f: f.LocalPath().endswith(('.mojom')))
delta = []
for mojom in changed_mojoms:
old_contents = ''.join(mojom.OldContents()) or None
......
......@@ -3524,6 +3524,17 @@ class MojomStabilityCheckTest(unittest.TestCase):
self.assertEqual(1, len(errors))
self.assertTrue('not backward-compatible' in errors[0].message)
def testDeletedFile(self):
"""Regression test for https://crbug.com/1091407."""
errors = self.runTestWithAffectedFiles([
MockAffectedFile('a.mojom', [], old_contents=['struct S {};'],
action='D'),
MockAffectedFile('b.mojom',
['struct S {}; struct T { S s; };'],
old_contents=['import "a.mojom"; struct T { S s; };'])
])
self.assertEqual([], errors)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment