Make a wrong uncrustify version a fatal error

We know that using a different version of uncrustify produces different
results. So make that an error rather than a warning.

Also make the error output more helpful if uncrustify is not found.

Signed-off-by: Gilles Peskine <[email protected]>
This commit is contained in:
Gilles Peskine
2025-11-03 18:50:52 +01:00
parent 4579964747
commit 3bf133525f
+18 -14
View File
@@ -166,16 +166,18 @@ def get_submodule_hash(commit: str, submodule: str) -> str:
def get_uncrustify_version() -> str: def get_uncrustify_version() -> str:
""" """
Get the version string from Uncrustify Get the version string from Uncrustify.
Return an empty string if Uncrustify is not found.
""" """
result = subprocess.run([UNCRUSTIFY_EXE, "--version"], try:
stdout=subprocess.PIPE, stderr=subprocess.PIPE, output = subprocess.check_output([UNCRUSTIFY_EXE, "--version"],
check=False) stderr=subprocess.PIPE)
if result.returncode != 0: return str(output, "utf-8").strip()
print_err("Could not get Uncrustify version:", str(result.stderr, "utf-8")) except FileNotFoundError:
return "" sys.stderr.write('Fatal: command {} not found in PATH.\n'
else: .format(UNCRUSTIFY_EXE))
return str(result.stdout, "utf-8") return ''
def check_style_is_correct(src_file_list: List[str]) -> bool: def check_style_is_correct(src_file_list: List[str]) -> bool:
""" """
@@ -246,12 +248,14 @@ def main() -> int:
""" """
Main with command line arguments. Main with command line arguments.
""" """
uncrustify_version = get_uncrustify_version().strip() uncrustify_version = get_uncrustify_version()
if UNCRUSTIFY_SUPPORTED_VERSION not in uncrustify_version: if UNCRUSTIFY_SUPPORTED_VERSION not in uncrustify_version:
print("Warning: Using unsupported Uncrustify version '" + if uncrustify_version != '':
uncrustify_version + "'") sys.stderr.write('Fatal: wrong uncrustify version ({}).\n'
print("Note: The only supported version is " + .format(uncrustify_version))
UNCRUSTIFY_SUPPORTED_VERSION) sys.stderr.write('You need uncrustify {} for correct results.\n'
.format(UNCRUSTIFY_SUPPORTED_VERSION))
return 2
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('-f', '--fix', action='store_true', parser.add_argument('-f', '--fix', action='store_true',