mojom: handle relative imports in check script
crrev.com/c/3367595 and crrev.com/c/3141536 revealed mojom import statements in src/platform2/media_perception/mojom inconsistent with imports elsewhere in src/platform2. Attempts to make these consistent also failed the check-mojoms presbumit check. This adjusts the mojom compatibility checker to handle partially- specified paths in mojom import statements, when they are not resolved directly from --src-root, by speculatively prepending path components to the import path. In the case no mojom is found, we are back where we started. TEST=repo upload crrev.com/c/3367595 succeeded with presubmit checks Bug: None Change-Id: Iaedd486931f08008319549f144a4ad65baba9f6b Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3387100 Reviewed-by: Ken Rockot <rockot@google.com> Commit-Queue: Richard Yeh <rcy@google.com> Cr-Commit-Position: refs/heads/main@{#961052}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
aa42d177a8
commit
d30db55832
mojo/public/tools/mojom
@@ -75,6 +75,17 @@ def _ValidateDelta(root, delta):
|
|||||||
raise ParseError('encountered exception {0} while parsing {1}'.format(
|
raise ParseError('encountered exception {0} while parsing {1}'.format(
|
||||||
e, mojom))
|
e, mojom))
|
||||||
for imp in ast.import_list:
|
for imp in ast.import_list:
|
||||||
|
if (not file_overrides.get(imp.import_filename)
|
||||||
|
and not os.path.exists(os.path.join(root, imp.import_filename))):
|
||||||
|
# Speculatively construct a path prefix to locate the import_filename
|
||||||
|
mojom_path = os.path.dirname(os.path.normpath(mojom)).split(os.sep)
|
||||||
|
test_prefix = ''
|
||||||
|
for path_component in mojom_path:
|
||||||
|
test_prefix = os.path.join(test_prefix, path_component)
|
||||||
|
test_import_filename = os.path.join(test_prefix, imp.import_filename)
|
||||||
|
if os.path.exists(os.path.join(root, test_import_filename)):
|
||||||
|
imp.import_filename = test_import_filename
|
||||||
|
break
|
||||||
parseMojom(imp.import_filename, file_overrides, override_modules)
|
parseMojom(imp.import_filename, file_overrides, override_modules)
|
||||||
|
|
||||||
# Now that the transitive set of dependencies has been imported and parsed
|
# Now that the transitive set of dependencies has been imported and parsed
|
||||||
|
@@ -258,3 +258,66 @@ class CheckStableMojomCompatibilityTest(unittest.TestCase):
|
|||||||
[Stable] struct T { foo.S s; int32 x; };
|
[Stable] struct T { foo.S s; int32 x; };
|
||||||
""")
|
""")
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def testWithPartialImport(self):
|
||||||
|
"""The compatibility checking tool correctly parses imports with partial
|
||||||
|
paths."""
|
||||||
|
self.assertBackwardCompatible([
|
||||||
|
UnchangedFile('foo/foo.mojom', 'module foo; [Stable] struct S {};'),
|
||||||
|
Change('foo/bar.mojom',
|
||||||
|
old="""\
|
||||||
|
module bar;
|
||||||
|
import "foo/foo.mojom";
|
||||||
|
[Stable] struct T { foo.S s; };
|
||||||
|
""",
|
||||||
|
new="""\
|
||||||
|
module bar;
|
||||||
|
import "foo.mojom";
|
||||||
|
[Stable] struct T { foo.S s; };
|
||||||
|
""")
|
||||||
|
])
|
||||||
|
|
||||||
|
self.assertBackwardCompatible([
|
||||||
|
UnchangedFile('foo/foo.mojom', 'module foo; [Stable] struct S {};'),
|
||||||
|
Change('foo/bar.mojom',
|
||||||
|
old="""\
|
||||||
|
module bar;
|
||||||
|
import "foo.mojom";
|
||||||
|
[Stable] struct T { foo.S s; };
|
||||||
|
""",
|
||||||
|
new="""\
|
||||||
|
module bar;
|
||||||
|
import "foo/foo.mojom";
|
||||||
|
[Stable] struct T { foo.S s; };
|
||||||
|
""")
|
||||||
|
])
|
||||||
|
|
||||||
|
self.assertNotBackwardCompatible([
|
||||||
|
UnchangedFile('foo/foo.mojom', 'module foo; [Stable] struct S {};'),
|
||||||
|
Change('bar/bar.mojom',
|
||||||
|
old="""\
|
||||||
|
module bar;
|
||||||
|
import "foo/foo.mojom";
|
||||||
|
[Stable] struct T { foo.S s; };
|
||||||
|
""",
|
||||||
|
new="""\
|
||||||
|
module bar;
|
||||||
|
import "foo.mojom";
|
||||||
|
[Stable] struct T { foo.S s; };
|
||||||
|
""")
|
||||||
|
])
|
||||||
|
|
||||||
|
self.assertNotBackwardCompatible([
|
||||||
|
UnchangedFile('foo/foo.mojom', 'module foo; [Stable] struct S {};'),
|
||||||
|
Change('bar/bar.mojom',
|
||||||
|
old="""\
|
||||||
|
module bar;
|
||||||
|
import "foo.mojom";
|
||||||
|
[Stable] struct T { foo.S s; };
|
||||||
|
""",
|
||||||
|
new="""\
|
||||||
|
module bar;
|
||||||
|
import "foo/foo.mojom";
|
||||||
|
[Stable] struct T { foo.S s; };
|
||||||
|
""")
|
||||||
|
])
|
||||||
|
Reference in New Issue
Block a user