Skip to contentSkip to conversation

Range of copy-firmware/check_whence fixes

PATCH Superseded Emil Velikov 1 participant 18 messages Sep 22, 2024 Kbuild

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Range of copy-firmware/check_whence fixes

Hello all,

With the latest python 3.12 check_whence.py started throwing some warnings. The more I looked around, the more loose ends and bugs reared their (ugly) heads.

In this series:
- check_whence.py: sort the filenames, use consistent variable names
- check_whence.py: fix links-to-links and band them
- editorconfig: add the config and fix the yaml+sh indentation
- copy-firmware.sh: factor out dedup fix broken ad-hoc symlink handling
- copy-firmware.sh: remove the hacky argument injection
- copy-firmware.sh: warn if the destination folder is NOT empty
- copy-firmware.sh: call ./check_whence.py and remove the dead code
- Dockerfile: remove unused packages... based on local testing

I've tried to keep the rant to a minimum, thus some commit messages may seem sparse. Let me know and I would happily add a few extra words.

As always, input is highly appreciated. Thanks o/

---
Emil Velikov (16):
check_whence.py: use consistent naming check_whence.py: ban link-to-a-link
check_whence.py: LC_ALL=C sort -u the filelist check_whence.py: annotate replacement strings as raw
editorconfig: add initial config file
Style update yaml files
Flesh out deduplicate-firmware.sh script
Revert "copy-firmware: Support additional compressor options" copy-firmware.sh: fixup indentation, consistently use test copy-firmware.sh: add err() helper
copy-firmware.sh: warn if the destination folder is not empty copy-firmware.sh: call ./check_whence.py before parsing the file copy-firmware.sh: remove no longer reachable test -f copy-firmware.sh: remove no longer reachable test -L copy-firmware.sh: rename variables in symlink hanlding
Dockerfile: remove unused packages

 .editorconfig           |  21 +++++++++
 .gitlab-ci.yml          |   2 +-
 .pre-commit-config.yaml |  38 ++++++++---------
 Dockerfile              |   5 +--
 Makefile                |   7 ++-
 WHENCE                  |  14 +++---
 check_whence.py         |  42 +++++++++++-------
 copy-firmware.sh        | 110 +++++++++++++-----------------------------------
 deduplicate-firmware.sh |  50 ++++++++++++++++++++++
 9 files changed, 157 insertions(+), 132 deletions(-)

---
base-commit: 6c88d9b8253b8ec6df701a551a56438ea2e5bacf
change-id: 20240922-misc-fixes-8a13acc71a93

Best regards,

Signature · 1 line
Emil Velikov <[email protected]>
#1 lore raw

PATCH 1/16 check_whence.py: use consistent naming

Namely: file(name) and sym(link) ... which were swapped in a few places. One of which by yours truly :facepalm:

---
 check_whence.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
check_whence.py +4 -4
index fd74a56a5c5a1fbbc989588626ba1d9bc072d602..c270ee6020083044645353235a94eee0b2497960 100755
@@ -99,7 +99,7 @@ def main():
         sys.stderr.write("E: %s listed in WHENCE as File, but is directory\n" % name)
         ret = 1
 
-    for name in set(fw for fw in whence_files if whence_files.count(fw) > 1):
+    for name in set(name for name in whence_files if whence_files.count(name) > 1):
         sys.stderr.write("E: %s listed in WHENCE twice\n" % name)
         ret = 1
 
@@ -107,7 +107,7 @@ def main():
         sys.stderr.write("E: %s listed in WHENCE twice\n" % name)
         ret = 1
 
-    for name in set(link for link in whence_files if os.path.islink(link)):
+    for name in set(file for file in whence_files if os.path.islink(file)):
         sys.stderr.write("E: %s listed in WHENCE as File, but is a symlink\n" % name)
         ret = 1
 
@@ -131,10 +131,10 @@ def main():
                 break
             valid_targets.add(dirname)
 
-    for name, target in sorted(links_list):
+    for link, 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)
+                "E: target %s of link %s in WHENCE" " does not exist\n" % (target, link)
             )
             ret = 1
 
Signature · 1 line
2.46.1
#2 lore raw

PATCH 2/16 check_whence.py: ban link-to-a-link

In reply to Emil Velikov

Using link-to-a-link is a bad idea since it reduces legibility and any changes to the rook link also change the leaf. Where the latter may be undesired.

We have a couple of instances in-tree, so fix them up and ban

---
 WHENCE          | 14 +++++++-------
 check_whence.py | 12 ++++++++++--
 2 files changed, 17 insertions(+), 9 deletions(-)
WHENCE +7 -7
index 3897121a115e185cc36e782b33ef66e43d87d557..6af1a97e2672922f2a3a1fcf0306b158eae1b6f7 100644
@@ -3686,7 +3686,7 @@ File: ath10k/WCN3990/hw1.0/qcm2290/wlanmdsp.mbn
 Version: WLAN.HL.3.3.7.c2-00931-QCAHLSWMTPLZ-1
 Link: ath10k/WCN3990/hw1.0/qrb4210/wlanmdsp.mbn -> ../qcm2290/wlanmdsp.mbn
 Link: qcom/qcm2290/wlanmdsp.mbn -> ../../ath10k/WCN3990/hw1.0/qcm2290/wlanmdsp.mbn
-Link: qcom/qrb4210/wlanmdsp.mbn -> ../../ath10k/WCN3990/hw1.0/qrb4210/wlanmdsp.mbn
+Link: qcom/qrb4210/wlanmdsp.mbn -> ../../ath10k/WCN3990/hw1.0/qcm2290/wlanmdsp.mbn
 File: ath10k/WCN3990/hw1.0/qcm2290/firmware-5.bin
 Link: ath10k/WCN3990/hw1.0/qrb4210/firmware-5.bin -> ../qcm2290/firmware-5.bin
 
@@ -5214,11 +5214,11 @@ Link: nvidia/gp104/acr/bl.bin -> ../../gp102/acr/bl.bin
 Link: nvidia/gp104/acr/ucode_load.bin -> ../../gp102/acr/ucode_load.bin
 Link: nvidia/gp104/acr/ucode_unload.bin -> ../../gp102/acr/ucode_unload.bin
 Link: nvidia/gp104/acr/unload_bl.bin -> ../../gp102/acr/unload_bl.bin
-Link: nvidia/gp104/gr/fecs_bl.bin -> ../../gp102/gr/fecs_bl.bin
+Link: nvidia/gp104/gr/fecs_bl.bin -> ../../gm200/gr/fecs_bl.bin
 File: nvidia/gp104/gr/fecs_data.bin
 File: nvidia/gp104/gr/fecs_inst.bin
 File: nvidia/gp104/gr/fecs_sig.bin
-Link: nvidia/gp104/gr/gpccs_bl.bin -> ../../gp102/gr/gpccs_bl.bin
+Link: nvidia/gp104/gr/gpccs_bl.bin -> ../../gm200/gr/gpccs_bl.bin
 File: nvidia/gp104/gr/gpccs_data.bin
 File: nvidia/gp104/gr/gpccs_inst.bin
 File: nvidia/gp104/gr/gpccs_sig.bin
@@ -5237,11 +5237,11 @@ Link: nvidia/gp106/acr/bl.bin -> ../../gp102/acr/bl.bin
 Link: nvidia/gp106/acr/ucode_load.bin -> ../../gp102/acr/ucode_load.bin
 Link: nvidia/gp106/acr/ucode_unload.bin -> ../../gp102/acr/ucode_unload.bin
 Link: nvidia/gp106/acr/unload_bl.bin -> ../../gp102/acr/unload_bl.bin
-Link: nvidia/gp106/gr/fecs_bl.bin -> ../../gp102/gr/fecs_bl.bin
+Link: nvidia/gp106/gr/fecs_bl.bin -> ../../gm200/gr/fecs_bl.bin
 File: nvidia/gp106/gr/fecs_data.bin
 Link: nvidia/gp106/gr/fecs_inst.bin -> ../../gp102/gr/fecs_inst.bin
 File: nvidia/gp106/gr/fecs_sig.bin
-Link: nvidia/gp106/gr/gpccs_bl.bin -> ../../gp102/gr/gpccs_bl.bin
+Link: nvidia/gp106/gr/gpccs_bl.bin -> ../../gm200/gr/gpccs_bl.bin
 File: nvidia/gp106/gr/gpccs_data.bin
 Link: nvidia/gp106/gr/gpccs_inst.bin -> ../../gp102/gr/gpccs_inst.bin
 File: nvidia/gp106/gr/gpccs_sig.bin
@@ -5924,10 +5924,10 @@ File: netronome/flower/nic_AMDA0096.nffw
 File: netronome/flower/nic_AMDA0097.nffw
 File: netronome/flower/nic_AMDA0058.nffw
 Link: netronome/flower/nic_AMDA0081.nffw -> nic_AMDA0097.nffw
-Link: netronome/flower/nic_AMDA0081-0001_1x40.nffw -> nic_AMDA0081.nffw
+Link: netronome/flower/nic_AMDA0081-0001_1x40.nffw -> nic_AMDA0097.nffw
 Link: netronome/flower/nic_AMDA0097-0001_2x40.nffw -> nic_AMDA0097.nffw
 Link: netronome/flower/nic_AMDA0099-0001_2x10.nffw -> nic_AMDA0099.nffw
-Link: netronome/flower/nic_AMDA0081-0001_4x10.nffw -> nic_AMDA0081.nffw
+Link: netronome/flower/nic_AMDA0081-0001_4x10.nffw -> nic_AMDA0097.nffw
 Link: netronome/flower/nic_AMDA0097-0001_4x10_1x40.nffw -> nic_AMDA0097.nffw
 Link: netronome/flower/nic_AMDA0099-0001_2x25.nffw -> nic_AMDA0099.nffw
 Link: netronome/flower/nic_AMDA0096-0001_2x10.nffw -> nic_AMDA0096.nffw
check_whence.py +10 -2
index c270ee6020083044645353235a94eee0b2497960..d7742f1ed951acab6efc89916c7f6621ba56881b 100755
@@ -115,12 +115,20 @@ def main():
         sys.stderr.write("E: %s listed in WHENCE as Link, is in tree\n" % name)
         ret = 1
 
+    invalid_targets = set(link[0] for link in links_list)
+    for link, target in sorted(links_list):
+        if target in invalid_targets:
+            sys.stderr.write(
+                "E: target %s of link %s is also a link\n" % (target, link)
+            )
+            ret = 1
+
     for name in sorted(list(known_files - git_files)):
         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
+    # A link can point to a file...
+    valid_targets = set(git_files)
 
     # ... or to a directory
     for target in set(valid_targets):
Signature · 1 line
2.46.1
#3 lore raw

PATCH 3/16 check_whence.py: LC_ALL=C sort -u the filelist

In reply to Emil Velikov

Sort the file list, to provide some sanity and make it easier to manage.

---
 check_whence.py | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
check_whence.py +7 -7
index d7742f1ed951acab6efc89916c7f6621ba56881b..dbbb68f7ab51b8db52c1d2334a6d4d20962bbef8 100755
@@ -73,23 +73,23 @@ def main():
     whence_links = list(zip(*links_list))[0]
     known_files = set(name for name in whence_list if not name.endswith("/")) | set(
         [
-            ".gitignore",
             ".codespell.cfg",
+            ".gitignore",
             ".gitlab-ci.yml",
             ".pre-commit-config.yaml",
-            "build_packages.py",
-            "check_whence.py",
-            "configure",
+            "Dockerfile",
             "Makefile",
             "README.md",
-            "copy-firmware.sh",
             "WHENCE",
-            "Dockerfile",
+            "build_packages.py",
+            "check_whence.py",
+            "configure",
+            "contrib/process_linux_firmware.py",
             "contrib/templates/debian.changelog",
             "contrib/templates/debian.control",
             "contrib/templates/debian.copyright",
             "contrib/templates/rpm.spec",
-            "contrib/process_linux_firmware.py",
+            "copy-firmware.sh",
         ]
     )
     known_prefixes = set(name for name in whence_list if name.endswith("/"))
Signature · 1 line
2.46.1
#4 lore raw

PATCH 4/16 check_whence.py: annotate replacement strings as raw

In reply to Emil Velikov

Otherwise python 3.12 throws warnings like below:

.../check_whence.py:40: SyntaxWarning: invalid escape sequence '\ '
yield match.group(1).replace("\ ", " ").replace('"', "")

---
 check_whence.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
check_whence.py +3 -3
index dbbb68f7ab51b8db52c1d2334a6d4d20962bbef8..64dc133551a68aeb24dbf7f02f617ea3913477b2 100755
@@ -37,7 +37,7 @@ def list_whence_files():
         for line in whence:
             match = re.match(r"(?:RawFile|File):\s*(.*)", line)
             if match:
-                yield match.group(1).replace("\ ", " ").replace('"', "")
+                yield match.group(1).replace(r"\ ", " ").replace('"', "")
                 continue
 
 
@@ -48,8 +48,8 @@ def list_links_list():
             if match:
                 linkname, target = match.group(1).split("->")
 
-                linkname = linkname.strip().replace("\ ", " ").replace('"', "")
-                target = target.strip().replace("\ ", " ").replace('"', "")
+                linkname = linkname.strip().replace(r"\ ", " ").replace('"', "")
+                target = target.strip().replace(r"\ ", " ").replace('"', "")
 
                 # Link target is relative to the link
                 target = os.path.join(os.path.dirname(linkname), target)
Signature · 1 line
2.46.1
#5 lore raw

PATCH 5/16 editorconfig: add initial config file

In reply to Emil Velikov

It's a simple format supported by practically every supported platform or program out there.

Add an initial configuration file, so we don't get notable style variations like the ones we have in-tree.

---
 .editorconfig   | 21 +++++++++++++++++++++
 check_whence.py |  1 +
 2 files changed, 22 insertions(+)
.editorconfig new file +21 -0
new file mode 100644
index 0000000000000000000000000000000000000000..2da3ba9694341dd4f1f5db9c3ad946ac96c5bdac
@@ -0,0 +1,21 @@
+# To use this config on you editor, follow the instructions at:
+# http://editorconfig.org
+
+root = true
+
+[*]
+charset = utf-8
+insert_final_newline = true
+tab_width = 8
+max_line_length = 80
+
+[Makefile]
+indent_style = tab
+
+[*.{sh,py}]
+indent_style = space
+indent_size = 4
+
+[*.{yml,yaml}]
+indent_style = space
+indent_size = 2
check_whence.py +1 -0
index 64dc133551a68aeb24dbf7f02f617ea3913477b2..afe97a76cf5ed609117d07387a19c2092fa00c6c 100755
@@ -74,6 +74,7 @@ def main():
     known_files = set(name for name in whence_list if not name.endswith("/")) | set(
         [
             ".codespell.cfg",
+            ".editorconfig",
             ".gitignore",
             ".gitlab-ci.yml",
             ".pre-commit-config.yaml",
Signature · 1 line
2.46.1
#6 lore raw

PATCH 6/16 Style update yaml files

In reply to Emil Velikov
---
 .gitlab-ci.yml          |  2 +-
 .pre-commit-config.yaml | 38 +++++++++++++++++++-------------------
 2 files changed, 20 insertions(+), 20 deletions(-)
.gitlab-ci.yml +1 -1
index ae96f7d859fc34ebc74c93a93993f623e05d78a2..e05ef3bb81c8f15049a3b068daac9fff35184d17 100644
@@ -11,7 +11,7 @@ check-commits:
   stage: test
   image: registry.gitlab.com/kernel-firmware/linux-firmware
   rules:
-   - if: $CI_MERGE_REQUEST_ID
+    - if: $CI_MERGE_REQUEST_ID
   script:
     - ci-fairy check-commits --signed-off-by --textwidth=0
 
.pre-commit-config.yaml +19 -19
index 7a49d063250e755b531059fe24b5a571d311005f..370a2970616bda3a340ebe523cd2ee2bb57759c1 100644
@@ -1,30 +1,30 @@
 default_stages: [commit]
 repos:
--   repo: https://github.com/pre-commit/pre-commit-hooks
+  - repo: https://github.com/pre-commit/pre-commit-hooks
     rev: v4.0.1
     hooks:
-    -   id: check-executables-have-shebangs
-    -   id: forbid-new-submodules
-    -   id: check-yaml
-    -   id: check-symlinks
-    -   id: destroyed-symlinks
--   repo: https://github.com/shellcheck-py/shellcheck-py
+      - id: check-executables-have-shebangs
+      - id: forbid-new-submodules
+      - id: check-yaml
+      - id: check-symlinks
+      - id: destroyed-symlinks
+  - repo: https://github.com/shellcheck-py/shellcheck-py
     rev: v0.9.0.5
     hooks:
-    -   id: shellcheck
--   repo: https://github.com/ambv/black
+      - id: shellcheck
+  - repo: https://github.com/ambv/black
     rev: 22.6.0
     hooks:
-    - id: black
--   repo: https://github.com/igorshubovych/markdownlint-cli
+      - id: black
+  - repo: https://github.com/igorshubovych/markdownlint-cli
     rev: v0.33.0
     hooks:
-    - id: markdownlint
-      args: ['--fix']
--   repo: local
+      - id: markdownlint
+        args: ['--fix']
+  - repo: local
     hooks:
-    - id: check-whence
-      name: Check whence
-      files: 'WHENCE'
-      language: script
-      entry: ./check_whence.py
+      - id: check-whence
+        name: Check whence
+        files: 'WHENCE'
+        language: script
+        entry: ./check_whence.py
Signature · 1 line
2.46.1
#7 lore raw

PATCH 7/16 Flesh out deduplicate-firmware.sh script

In reply to Emil Velikov

Flesh out the deduplication logic in separate script. The copy-firmware.sh is already complex enough and de-duplication isn't really copying ;-)

In the process we migrate from the open-coded (and seemingly buggy) ln --relative logic, which was masked around with moving the de-duplication around.

We also get a few added bonuses:
- the COPYOPTS shell injection is gone - the variable was never used
- people can dedup as separate step if they need to

---
 Makefile                |  7 +++----
 check_whence.py         |  1 +
 copy-firmware.sh        | 23 -----------------------
 deduplicate-firmware.sh | 50 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 54 insertions(+), 27 deletions(-)
Makefile +3 -4
index ac43c97fbd0a35b610c4d21c2bf8e8cf21864c9a..a52831fe4e7b69e355d77e0833cde3b451d5800e 100644
@@ -26,13 +26,12 @@ deb:
 rpm:
 	./build_packages.py --rpm
 
-install:
-	install -d $(DESTDIR)$(FIRMWAREDIR)
-	./copy-firmware.sh $(COPYOPTS) $(DESTDIR)$(FIRMWAREDIR)
+install: install-nodedup
+	./deduplicate-firmware.sh $(DESTDIR)$(FIRMWAREDIR)
 
 install-nodedup:
 	install -d $(DESTDIR)$(FIRMWAREDIR)
-	./copy-firmware.sh --ignore-duplicates $(DESTDIR)$(FIRMWAREDIR)
+	./copy-firmware.sh $(DESTDIR)$(FIRMWAREDIR)
 
 install-xz:
 	install -d $(DESTDIR)$(FIRMWAREDIR)
check_whence.py +1 -0
index afe97a76cf5ed609117d07387a19c2092fa00c6c..b84c1f0f2c310e71eccc17270f7d37e8cd48f2ae 100755
@@ -91,6 +91,7 @@ def main():
             "contrib/templates/debian.copyright",
             "contrib/templates/rpm.spec",
             "copy-firmware.sh",
+            "deduplicate-firmware.sh",
         ]
     )
     known_prefixes = set(name for name in whence_list if name.endswith("/"))
copy-firmware.sh +0 -23
index 6c557f234dd2b90e68ba26429ad3e788f2201c4f..344f478db74a7080b34c264645d6bcd9a80384a8 100755
@@ -9,7 +9,6 @@ prune=no
 # shellcheck disable=SC2209
 compress=cat
 compext=
-skip_dedup=0
 
 while test $# -gt 0; do
     case $1 in
@@ -45,11 +44,6 @@ while test $# -gt 0; do
             shift
             ;;
 
-        --ignore-duplicates)
-            skip_dedup=1
-            shift
-            ;;
-
         -*)
             if test "$compress" = "cat"; then
                 echo "ERROR: unknown command-line option: $1"
@@ -75,13 +69,6 @@ if [ -z "$destdir" ]; then
 	exit 1
 fi
 
-if ! command -v rdfind >/dev/null; then
-	if [ "$skip_dedup" != 1 ]; then
-    		echo "ERROR: rdfind is not installed.  Pass --ignore-duplicates to skip deduplication"
-		exit 1
-	fi
-fi
-
 # shellcheck disable=SC2162 # file/folder name can include escaped symbols
 grep -E '^(RawFile|File):' WHENCE | sed -E -e 's/^(RawFile|File): */\1 /;s/"//g' | while read k f; do
     test -f "$f" || continue
@@ -95,16 +82,6 @@ grep -E '^(RawFile|File):' WHENCE | sed -E -e 's/^(RawFile|File): */\1 /;s/"//g'
     fi
 done
 
-if [ "$skip_dedup" != 1 ] ; then
-	$verbose "Finding duplicate files"
-	rdfind -makesymlinks true -makeresultsfile false "$destdir" >/dev/null
-	find "$destdir" -type l | while read -r l; do
-		target="$(realpath "$l")"
-		$verbose "Correcting path for $l"
-		ln -fs "$(realpath --relative-to="$(dirname "$(realpath -s "$l")")" "$target")" "$l"
-	done
-fi
-
 # shellcheck disable=SC2162 # file/folder name can include escaped symbols
 grep -E '^Link:' WHENCE | sed -e 's/^Link: *//g;s/-> //g' | while read f d; do
     if test -L "$f$compext"; then
deduplicate-firmware.sh new file +50 -0

50 lines not on this page · raw message

Signature · 1 line
2.46.1
#8 lore raw

PATCH 8/16 Revert "copy-firmware: Support additional compressor options"

In reply to Emil Velikov

This reverts commit 2bad80e7edd3c0f84718545d9338c8edfed16513.

The commit effectively added accidental command injection, while it was aiming to control the compression flags.

In practise you'd want to use ZSTD_CLEVEL and ZSTD_NBTHREADS for zstd as documented in man(1)zstd it allows for up-to level 19, which is fined since the kernel does not support higher levels.

Arch, Alpine and likely other distributions have been using this since day one.

The other compressors like xz have equivalent environment variables.

Cc Juerg Haefliger <[email protected]>
---
 copy-firmware.sh | 8 --------
 1 file changed, 8 deletions(-)
copy-firmware.sh +0 -8
index 344f478db74a7080b34c264645d6bcd9a80384a8..21ed20d5886fe71588b923914265f992cf5c29b0 100755
@@ -44,14 +44,6 @@ while test $# -gt 0; do
             shift
             ;;
 
-        -*)
-            if test "$compress" = "cat"; then
-                echo "ERROR: unknown command-line option: $1"
-                exit 1
-            fi
-            compress="$compress $1"
-            shift
-            ;;
         *)
             if test "x$destdir" != "x"; then
                 echo "ERROR: unknown command-line options: $*"
Signature · 1 line
2.46.1
#9 lore raw

PATCH 9/16 copy-firmware.sh: fixup indentation, consistently use test

In reply to Emil Velikov
---
 copy-firmware.sh | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
copy-firmware.sh +6 -6
index 21ed20d5886fe71588b923914265f992cf5c29b0..e46bb9926f86a813bc76f1da1604c1b7a4980848 100755
@@ -56,9 +56,9 @@ while test $# -gt 0; do
     esac
 done
 
-if [ -z "$destdir" ]; then
-	echo "ERROR: destination directory was not specified"
-	exit 1
+if test -z "$destdir"; then
+    echo "ERROR: destination directory was not specified"
+    exit 1
 fi
 
 # shellcheck disable=SC2162 # file/folder name can include escaped symbols
@@ -114,9 +114,9 @@ done
 
 # Verify no broken symlinks
 if test "$(find "$destdir" -xtype l | wc -l)" -ne 0 ; then
-        echo "ERROR: Broken symlinks found:"
-        find "$destdir" -xtype l
-        exit 1
+    echo "ERROR: Broken symlinks found:"
+    find "$destdir" -xtype l
+    exit 1
 fi
 
 exit 0
Signature · 1 line
2.46.1
#10 lore raw

PATCH 10/16 copy-firmware.sh: add err() helper

In reply to Emil Velikov
---
 copy-firmware.sh | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)
copy-firmware.sh +10 -11
index e46bb9926f86a813bc76f1da1604c1b7a4980848..f59d8403ab3f4c6928f6976069c134dfb98b1246 100755
@@ -10,6 +10,11 @@ prune=no
 compress=cat
 compext=
 
+err() {
+    echo "ERROR: $*"
+    exit 1
+}
+
 while test $# -gt 0; do
     case $1 in
         -v | --verbose)
@@ -25,8 +30,7 @@ while test $# -gt 0; do
 
         --xz)
             if test "$compext" = ".zst"; then
-                echo "ERROR: cannot mix XZ and ZSTD compression"
-                exit 1
+                err "cannot mix XZ and ZSTD compression"
             fi
             compress="xz --compress --quiet --stdout --check=crc32"
             compext=".xz"
@@ -35,8 +39,7 @@ while test $# -gt 0; do
 
         --zstd)
             if test "$compext" = ".xz"; then
-                echo "ERROR: cannot mix XZ and ZSTD compression"
-                exit 1
+                err "cannot mix XZ and ZSTD compression"
             fi
             # shellcheck disable=SC2209
             compress="zstd --compress --quiet --stdout"
@@ -46,8 +49,7 @@ while test $# -gt 0; do
 
         *)
             if test "x$destdir" != "x"; then
-                echo "ERROR: unknown command-line options: $*"
-                exit 1
+                err "unknown command-line options: $*"
             fi
 
             destdir="$1"
@@ -57,8 +59,7 @@ while test $# -gt 0; do
 done
 
 if test -z "$destdir"; then
-    echo "ERROR: destination directory was not specified"
-    exit 1
+    err "destination directory was not specified"
 fi
 
 # shellcheck disable=SC2162 # file/folder name can include escaped symbols
@@ -114,9 +115,7 @@ done
 
 # Verify no broken symlinks
 if test "$(find "$destdir" -xtype l | wc -l)" -ne 0 ; then
-    echo "ERROR: Broken symlinks found:"
-    find "$destdir" -xtype l
-    exit 1
+    err "Broken symlinks found:\n$(find "$destdir" -xtype l)"
 fi
 
 exit 0
Signature · 1 line
2.46.1
#11 lore raw

PATCH 11/16 copy-firmware.sh: warn if the destination folder is not empty

In reply to Emil Velikov

If the user provides their existing /usr/lib/firmware/ there is a high chance we'll overwrite existing files. That may or may not be what they wanted.

Throw a warning about it.

---
 copy-firmware.sh | 8 ++++++++
 1 file changed, 8 insertions(+)
copy-firmware.sh +8 -0
index f59d8403ab3f4c6928f6976069c134dfb98b1246..dc959cbad3be3e79a1174afd0ff68b8d6c0567a5 100755
@@ -15,6 +15,10 @@ err() {
     exit 1
 }
 
+warn() {
+    echo "WARNING: $*"
+}
+
 while test $# -gt 0; do
     case $1 in
         -v | --verbose)
@@ -62,6 +66,10 @@ if test -z "$destdir"; then
     err "destination directory was not specified"
 fi
 
+if test -d "$destdir"; then
+    find "$destdir" -type d -empty >/dev/null && warn "destination folder is not empty."
+fi
+
 # shellcheck disable=SC2162 # file/folder name can include escaped symbols
 grep -E '^(RawFile|File):' WHENCE | sed -E -e 's/^(RawFile|File): */\1 /;s/"//g' | while read k f; do
     test -f "$f" || continue
Signature · 1 line
2.46.1
#12 lore raw

PATCH 12/16 copy-firmware.sh: call ./check_whence.py before parsing the file

In reply to Emil Velikov

This will prevent accidental changes (eg. you're hacking locally) to wreaking chaos, as copy-firmware.sh expect a specific format.

---
 copy-firmware.sh | 3 +++
 1 file changed, 3 insertions(+)
copy-firmware.sh +3 -0
index dc959cbad3be3e79a1174afd0ff68b8d6c0567a5..ff3124d9d055f1f72351f472609d0158bd91dfb7 100755
@@ -70,6 +70,9 @@ if test -d "$destdir"; then
     find "$destdir" -type d -empty >/dev/null && warn "destination folder is not empty."
 fi
 
+$verbose "Checking that WHENCE file is formatted properly"
+./check_whence.py
+
 # shellcheck disable=SC2162 # file/folder name can include escaped symbols
 grep -E '^(RawFile|File):' WHENCE | sed -E -e 's/^(RawFile|File): */\1 /;s/"//g' | while read k f; do
     test -f "$f" || continue
Signature · 1 line
2.46.1
#13 lore raw

PATCH 13/16 copy-firmware.sh: remove no longer reachable test -f

In reply to Emil Velikov

With previous commit we call check_whence.py, which ensures that all files listed are available. Drop the now dead code test -f.

---
 copy-firmware.sh | 1 -
 1 file changed, 1 deletion(-)
copy-firmware.sh +0 -1
index ff3124d9d055f1f72351f472609d0158bd91dfb7..d1d526f43d2c71a5f1456ed6c09ed94a73a1229e 100755
@@ -75,7 +75,6 @@ $verbose "Checking that WHENCE file is formatted properly"
 
 # shellcheck disable=SC2162 # file/folder name can include escaped symbols
 grep -E '^(RawFile|File):' WHENCE | sed -E -e 's/^(RawFile|File): */\1 /;s/"//g' | while read k f; do
-    test -f "$f" || continue
     install -d "$destdir/$(dirname "$f")"
     $verbose "copying/compressing file $f$compext"
     if test "$compress" != "cat" && test "$k" = "RawFile"; then
Signature · 1 line
2.46.1
#14 lore raw

PATCH 14/16 copy-firmware.sh: remove no longer reachable test -L

In reply to Emil Velikov

The check_whence.py script ensures that links defined in WHENCE are not in-tree. Since we're calling the script, we no longer need the convoluted path and associated --prune tag.

---
 copy-firmware.sh | 46 ++++++++--------------------------------------
 1 file changed, 8 insertions(+), 38 deletions(-)
copy-firmware.sh +8 -38
index d1d526f43d2c71a5f1456ed6c09ed94a73a1229e..8de3774153d783d6a79443aa789f03da5f04b2c7 100755
@@ -5,7 +5,6 @@
 #
 
 verbose=:
-prune=no
 # shellcheck disable=SC2209
 compress=cat
 compext=
@@ -27,11 +26,6 @@ while test $# -gt 0; do
             shift
             ;;
 
-        -P | --prune)
-            prune=yes
-            shift
-            ;;
-
         --xz)
             if test "$compext" = ".zst"; then
                 err "cannot mix XZ and ZSTD compression"
@@ -87,39 +81,15 @@ done
 
 # shellcheck disable=SC2162 # file/folder name can include escaped symbols
 grep -E '^Link:' WHENCE | sed -e 's/^Link: *//g;s/-> //g' | while read f d; do
-    if test -L "$f$compext"; then
-        test -f "$destdir/$f$compext" && continue
-        $verbose "copying link $f$compext"
-        install -d "$destdir/$(dirname "$f")"
-        cp -d "$f$compext" "$destdir/$f$compext"
-
-        if test "x$d" != "x"; then
-            target="$(readlink "$f")"
-
-            if test "x$target" != "x$d"; then
-                $verbose "WARNING: inconsistent symlink target: $target != $d"
-            else
-                if test "x$prune" != "xyes"; then
-                    $verbose "WARNING: unneeded symlink detected: $f"
-                else
-                    $verbose "WARNING: pruning unneeded symlink $f"
-                    rm -f "$f$compext"
-                fi
-            fi
-        else
-            $verbose "WARNING: missing target for symlink $f"
-        fi
+    directory="$destdir/$(dirname "$f")"
+    install -d "$directory"
+    target="$(cd "$directory" && realpath -m -s "$d")"
+    if test -e "$target"; then
+        $verbose "creating link $f -> $d"
+        ln -s "$d" "$destdir/$f"
     else
-        directory="$destdir/$(dirname "$f")"
-        install -d "$directory"
-        target="$(cd "$directory" && realpath -m -s "$d")"
-        if test -e "$target"; then
-            $verbose "creating link $f -> $d"
-            ln -s "$d" "$destdir/$f"
-        else
-            $verbose "creating link $f$compext -> $d$compext"
-            ln -s "$d$compext" "$destdir/$f$compext"
-        fi
+        $verbose "creating link $f$compext -> $d$compext"
+        ln -s "$d$compext" "$destdir/$f$compext"
     fi
 done
 
Signature · 1 line
2.46.1
#15 lore raw

PATCH 15/16 copy-firmware.sh: rename variables in symlink hanlding

In reply to Emil Velikov

Currently we use f(ile) and d(irectory), over the more common ones t(arget) and l(ink). Rename things appropriately.

---
 copy-firmware.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
copy-firmware.sh +7 -7
index 8de3774153d783d6a79443aa789f03da5f04b2c7..7713328a15dcce5f6136ee8e3c0bad045ae9101f 100755
@@ -80,16 +80,16 @@ grep -E '^(RawFile|File):' WHENCE | sed -E -e 's/^(RawFile|File): */\1 /;s/"//g'
 done
 
 # shellcheck disable=SC2162 # file/folder name can include escaped symbols
-grep -E '^Link:' WHENCE | sed -e 's/^Link: *//g;s/-> //g' | while read f d; do
-    directory="$destdir/$(dirname "$f")"
+grep -E '^Link:' WHENCE | sed -e 's/^Link: *//g;s/-> //g' | while read l t; do
+    directory="$destdir/$(dirname "$l")"
     install -d "$directory"
-    target="$(cd "$directory" && realpath -m -s "$d")"
+    target="$(cd "$directory" && realpath -m -s "$t")"
     if test -e "$target"; then
-        $verbose "creating link $f -> $d"
-        ln -s "$d" "$destdir/$f"
+        $verbose "creating link $l -> $t"
+        ln -s "$t" "$destdir/$l"
     else
-        $verbose "creating link $f$compext -> $d$compext"
-        ln -s "$d$compext" "$destdir/$f$compext"
+        $verbose "creating link $l$compext -> $t$compext"
+        ln -s "$t$compext" "$destdir/$l$compext"
     fi
 done
 
Signature · 1 line
2.46.1
#16 lore raw

PATCH 16/16 Dockerfile: remove unused packages

In reply to Emil Velikov

We're not compiling anything so gcc, the various *dev package and npm are not needed.

Aside: we should probably document what this file is, how to use and most importantly make sure the registry gets updated as we push new one.

---
 Dockerfile | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
Dockerfile +1 -4
index 9350dc71fc1d2473771a6b0a6a40f9a6e7434ddf..ea86f6cadcd3cc0ab415eda6fa238d8e1f18daf4 100644
@@ -1,10 +1,7 @@
 # Leverage FDO CI fairy, but add pre-commit to it
 FROM quay.io/freedesktop.org/ci-templates:ci-fairy-sha256-eb20531b68e57da06f4e631402fd494869b1529e2c4ad05cfe24ef3fb8038815
-RUN apk add python3-dev
-RUN apk add gcc
-RUN apk add musl-dev
+RUN apk add python3
 RUN apk add git
-RUN apk add npm
 RUN apk add rdfind
 RUN apk add shellcheck
 RUN pip install pre-commit --ignore-installed distlib
Signature · 1 line
2.46.1
#17 lore raw
In reply to Emil Velikov
Quoted 17 lines · On Sun, 22 Sept 2024 at 21:17, Emil Velikov via B4 Relay…

Hello all,

With the latest python 3.12 check_whence.py started throwing some warnings. The more I looked around, the more loose ends and bugs reared their (ugly) heads.

In this series:
- check_whence.py: sort the filenames, use consistent variable names
- check_whence.py: fix links-to-links and band them
- editorconfig: add the config and fix the yaml+sh indentation
- copy-firmware.sh: factor out dedup fix broken ad-hoc symlink handling
- copy-firmware.sh: remove the hacky argument injection
- copy-firmware.sh: warn if the destination folder is NOT empty
- copy-firmware.sh: call ./check_whence.py and remove the dead code
- Dockerfile: remove unused packages... based on local testing

Quoted 5 lines

I've tried to keep the rant to a minimum, thus some commit messages may seem sparse. Let me know and I would happily add a few extra words.

As always, input is highly appreciated. Thanks o/

Please ignore the series for now... Seems like I've done quite a bad job at actually testing it

Pardon for the noise o/
Emil