Make ctoolchain_comparator.py throw exit(1) when CToolchains differ
While here, Also fix _read_crosstool_or_ctoolchain_proto to actually return the CToolchain found in the CROSSTOOL file, and add some missing \n.
RELNOTES: None.
PiperOrigin-RevId: 229926500
diff --git a/tools/migration/ctoolchain_comparator.py b/tools/migration/ctoolchain_comparator.py
index 13bf258..5c730ce 100644
--- a/tools/migration/ctoolchain_comparator.py
+++ b/tools/migration/ctoolchain_comparator.py
@@ -80,6 +80,7 @@
print(("Cannnot find a CToolchain with an identifier '%s' in CROSSTOOL"
"file") % toolchain_identifier)
return None
+ return toolchain
except text_format.ParseError as crosstool_error:
try:
text_format.Merge(text, c_toolchain)
@@ -112,7 +113,9 @@
if not toolchain_before or not toolchain_after:
return
- compare_ctoolchains(toolchain_before, toolchain_after)
+ found_difference = compare_ctoolchains(toolchain_before, toolchain_after)
+ if found_difference:
+ exit(1)
if __name__ == "__main__":
diff --git a/tools/migration/ctoolchain_comparator_lib.py b/tools/migration/ctoolchain_comparator_lib.py
index c870545..0adefd3 100644
--- a/tools/migration/ctoolchain_comparator_lib.py
+++ b/tools/migration/ctoolchain_comparator_lib.py
@@ -212,7 +212,7 @@
if not found_difference:
print(diff_string) # pylint: disable=superfluous-parens
found_difference = True
- print(("Features not in right order:\t"
+ print(("Features not in right order:\n"
"* List of features before change:\t%s"
"* List of features before change:\t%s") %
(_array_to_string(names_before), _array_to_string(names_after)))
@@ -271,7 +271,7 @@
if not found_difference:
print(diff_string) # pylint: disable=superfluous-parens
found_difference = True
- print(("Action configs not in right order:\t"
+ print(("Action configs not in right order:\n"
"* List of action configs before change:\t%s"
"* List of action_configs before change:\t%s") %
(_array_to_string(names_before), _array_to_string(names_after)))
@@ -513,3 +513,4 @@
toolchain_after.artifact_name_pattern) or found_difference
if not found_difference:
print("No difference") # pylint: disable=superfluous-parens
+ return found_difference