0

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/+/2231266
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#775248}
This commit is contained in:
Ken Rockot
2020-06-04 20:17:09 +00:00
committed by Commit Bot
parent 75fd5c0631
commit ad7901f94a
2 changed files with 14 additions and 2 deletions

@ -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()