linux-firmware.lore.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Adam Sampson <ats@offog.org>
To: linux-firmware@kernel.org
Cc: Adam Sampson <ats@offog.org>
Subject: [PATCH 1/2] check_whence: Check link targets are valid
Date: Thu, 16 Feb 2023 00:56:01 +0000	[thread overview]
Message-ID: <20230216005602.18838-1-ats@offog.org> (raw)

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


             reply	other threads:[~2023-02-16  0:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-16  0:56 Adam Sampson [this message]
2023-02-16  0:56 ` [PATCH 2/2] intel: Fix broken links Adam Sampson
2023-03-07 14:50   ` Josh Boyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230216005602.18838-1-ats@offog.org \
    --to=ats@offog.org \
    --cc=linux-firmware@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).