mirror of
https://github.com/wentasah/ros2nix.git
synced 2025-06-09 15:52:23 +03:00
Don't fail with --compare when a .nix file is missing on disk
The switch --compare is typically used during CI, to check whether all automatically generated files are up to date. When some files are missing (e.g. a ROS package was added but its Nix expression was not generated), ros2nix would fail with "FileNotFoundError" and would not return exit code 2 as it should. This commit fixes that. Missing files are reported with an error message and execution continues. Exit code 2 is correctly reported.
This commit is contained in:
parent
c42d7ecaa1
commit
a850550783
1 changed files with 9 additions and 3 deletions
|
@ -75,9 +75,16 @@ def file_writer(path: str, compare: bool):
|
|||
yield f
|
||||
finally:
|
||||
if compare:
|
||||
ondisk = open(path, "r", encoding="utf-8").read()
|
||||
global compare_failed
|
||||
ondisk = None
|
||||
try:
|
||||
ondisk = open(path, "r", encoding="utf-8").read()
|
||||
except Exception as e:
|
||||
compare_failed = True
|
||||
err(f'Cannot read {path}: {e}')
|
||||
|
||||
current = f.getvalue()
|
||||
if current != ondisk:
|
||||
if ondisk is not None and current != ondisk:
|
||||
err(f"{path} is not up-to-date")
|
||||
for line in difflib.unified_diff(
|
||||
ondisk.splitlines(),
|
||||
|
@ -86,7 +93,6 @@ def file_writer(path: str, compare: bool):
|
|||
tofile="up-to-date",
|
||||
):
|
||||
print(line)
|
||||
global compare_failed
|
||||
compare_failed = True
|
||||
f.close()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue