utils/check-package: handle missing files

When running check-package before completing commits for a change, if
any files are setup for removal, check-package will throw
FileNotFoundError exceptions instead of generating a warning state. For
example:

 $ utils/docker-run make check-package
 Traceback (most recent call last):
   ...
 FileNotFoundError: [Errno 2] No such file or directory: 'package/.../0001-some-removed-patch.patch'
 make: *** [Makefile:1264: check-package] Error 1

This commit will now catch FileNotFoundError and populate a warning
message:

 $ utils/docker-run make check-package
 package/.../0001-some-removed-patch.patch: missing; unstaged file removal?
 package/.../0002-another-removed-patch.patch: missing; unstaged file removal?
 427843 lines processed
 3 warnings generated
 make: *** [Makefile:1264: check-package] Error 1

Signed-off-by: James Knight <git@jdknight.me>
Reviewed-by: Romain Naour <romain.naour@smile.fr>
Signed-off-by: Julien Olivain <ju.o@free.fr>
(cherry picked from commit c41a06bbd9)
Signed-off-by: Thomas Perale <thomas.perale@mind.be>
This commit is contained in:
James Knight
2025-07-01 14:56:42 -04:00
committed by Thomas Perale
parent 1bcb3d53b3
commit 074e005e42

View File

@@ -257,18 +257,23 @@ def check_file_using_lib(fname):
nwarnings += warn nwarnings += warn
lastline = "" lastline = ""
with open(fname, "r", errors="surrogateescape") as f: try:
for lineno, text in enumerate(f): with open(fname, "r", errors="surrogateescape") as f:
nlines += 1 for lineno, text in enumerate(f):
for name, cf in objects: nlines += 1
if cf.disable.search(lastline): for name, cf in objects:
continue if cf.disable.search(lastline):
line_sts = cf.check_line(lineno + 1, text) continue
warn, fail = print_warnings(line_sts, name in xfail) line_sts = cf.check_line(lineno + 1, text)
if fail > 0: warn, fail = print_warnings(line_sts, name in xfail)
failed.add(name) if fail > 0:
nwarnings += warn failed.add(name)
lastline = text nwarnings += warn
lastline = text
except FileNotFoundError:
print(f"{fname}: missing; unstaged file removal?")
nwarnings += 1
return nwarnings, nlines
for name, cf in objects: for name, cf in objects:
warn, fail = print_warnings(cf.after(), name in xfail) warn, fail = print_warnings(cf.after(), name in xfail)