linux-firmware.lore.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] check_whence: Check link targets are valid
@ 2023-02-16  0:56 Adam Sampson
  2023-02-16  0:56 ` [PATCH 2/2] intel: Fix broken links Adam Sampson
  0 siblings, 1 reply; 3+ messages in thread
From: Adam Sampson @ 2023-02-16  0:56 UTC (permalink / raw)
  To: linux-firmware; +Cc: Adam Sampson

This should catch a couple of common errors: reversing the two
arguments, and not making the second argument relative to the first.

Signed-off-by: Adam Sampson <ats@offog.org>
---
 check_whence.py | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/check_whence.py b/check_whence.py
index 8805e99..654ff59 100755
--- a/check_whence.py
+++ b/check_whence.py
@@ -28,6 +28,24 @@ def list_whence():
                         yield match.group(2)
                         continue
 
+def list_whence_links():
+    with open('WHENCE', encoding='utf-8') as whence:
+        for line in whence:
+            fields = line.rstrip()
+            match = re.match(r'Link:\s*(.*)', line)
+            if match:
+                linkname, target = match.group(1).split("->")
+
+                linkname = linkname.strip().replace('\\ ', ' ')
+                target = target.strip().replace('\\ ', ' ')
+
+                # Link target is relative to the link
+                target = os.path.join(os.path.dirname(linkname), target)
+                target = os.path.normpath(target)
+
+                yield (linkname, target)
+                continue
+
 def list_git():
     with os.popen('git ls-files') as git_files:
         for line in git_files:
@@ -36,6 +54,7 @@ def list_git():
 def main():
     ret = 0
     whence_list = list(list_whence())
+    links_list = list(list_whence_links())
     known_files = set(name for name in whence_list if not name.endswith('/')) | \
                   set(['check_whence.py', 'configure', 'Makefile',
                        'README', 'copy-firmware.sh', 'WHENCE'])
@@ -46,6 +65,24 @@ def main():
         sys.stderr.write('E: %s listed in WHENCE does not exist\n' % name)
         ret = 1
 
+    # A link can point to another link, or to a file...
+    valid_targets = set(link[0] for link in links_list) | git_files
+
+    # ... or to a directory
+    for target in set(valid_targets):
+        dirname = target
+        while True:
+            dirname = os.path.dirname(dirname)
+            if dirname == '':
+                break
+            valid_targets.add(dirname)
+
+    for name, target in sorted(links_list):
+        if target not in valid_targets:
+            sys.stderr.write('E: target %s of link %s in WHENCE'
+                             ' does not exist\n' % (target, name))
+            ret = 1
+
     for name in sorted(list(git_files - known_files)):
         # Ignore subdirectory changelogs and GPG detached signatures
         if (name.endswith('/ChangeLog') or
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-03-07 14:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-16  0:56 [PATCH 1/2] check_whence: Check link targets are valid Adam Sampson
2023-02-16  0:56 ` [PATCH 2/2] intel: Fix broken links Adam Sampson
2023-03-07 14:50   ` Josh Boyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).