Make CToolchain comparator ignore differences in CToolchain.Tool.tool_path and CToolcain.ToolPath.path when one is "" and the other "NOT_USED"
Starlark constructors for tool_path and tool do not allow empty strings for the path field. Therefore the migrator replaces the "" with "NOT_USED". We should ignore this difference when comparing the CToolchains.
#5380
PiperOrigin-RevId: 232827179
diff --git a/tools/migration/ctoolchain_comparator_lib.py b/tools/migration/ctoolchain_comparator_lib.py
index 0adefd3..eb47305 100644
--- a/tools/migration/ctoolchain_comparator_lib.py
+++ b/tools/migration/ctoolchain_comparator_lib.py
@@ -52,6 +52,11 @@
def _check_tool_equivalence(before, after):
+ """Compares two "CToolchain.Tool"s."""
+ if before.tool_path == "NOT_USED":
+ before.tool_path = ""
+ if after.tool_path == "NOT_USED":
+ after.tool_path = ""
if before.tool_path != after.tool_path:
return False
if set(before.execution_requirement) != set(after.execution_requirement):
@@ -297,9 +302,11 @@
tool_to_path_before = {}
tool_to_path_after = {}
for tool_path in tool_paths_before:
- tool_to_path_before[tool_path.name] = tool_path.path
+ tool_to_path_before[tool_path.name] = (
+ tool_path.path if tool_path.path != "NOT_USED" else "")
for tool_path in tool_paths_after:
- tool_to_path_after[tool_path.name] = tool_path.path
+ tool_to_path_after[tool_path.name] = (
+ tool_path.path if tool_path.path != "NOT_USED" else "")
tool_names_before = set(tool_to_path_before.keys())
tool_names_after = set(tool_to_path_after.keys())
diff --git a/tools/migration/ctoolchain_comparator_lib_test.py b/tools/migration/ctoolchain_comparator_lib_test.py
index 06645b0..c81ff47 100644
--- a/tools/migration/ctoolchain_comparator_lib_test.py
+++ b/tools/migration/ctoolchain_comparator_lib_test.py
@@ -1665,6 +1665,45 @@
self.assertIn("* Action config 'config' differs before and after",
mock_stdout.getvalue())
+ def test_unused_tool_path(self):
+ first = make_toolchain("""
+ tool_path {
+ name: "empty"
+ path: ""
+ }
+ """)
+ second = make_toolchain("""
+ tool_path {
+ name: "empty"
+ path: "NOT_USED"
+ }
+ """)
+ mock_stdout = StringIO()
+ with mock.patch("sys.stdout", mock_stdout):
+ compare_ctoolchains(first, second)
+ self.assertIn("No difference", mock_stdout.getvalue())
+
+ def test_unused_tool_path_in_tool(self):
+ first = make_toolchain("""
+ action_config {
+ config_name: 'config'
+ tool {
+ tool_path: ''
+ }
+ }
+ """)
+ second = make_toolchain("""
+ action_config {
+ config_name: 'config'
+ tool {
+ tool_path: 'NOT_USED'
+ }
+ }
+ """)
+ mock_stdout = StringIO()
+ with mock.patch("sys.stdout", mock_stdout):
+ compare_ctoolchains(first, second)
+ self.assertIn("No difference", mock_stdout.getvalue())
if __name__ == "__main__":
unittest.main()