Subject: [PATCH v2] gnu: linux-libre-documentation: Fix compilation.

From: Tomas Volf <[email-masked]>
Date: Tue, 20 Feb 2024 19:26:15 +0100

When compiling [email-masked], the compilation fails with
following error message:

    Exception occurred:
      File "/tmp/guix-build-linux-libre-documentation-6.6.16.drv-0/linux-6.6.16/Documentation/sphinx/kernel_feat.py", line 112, in run
        nodeList = self.nestedParse(out_lines, fname)
    UnboundLocalError: local variable 'fname' referenced before assignment

This is already fixed upstream[0], so this commit backports the change.

0: https://lore.kernel.org/all/[email-masked]/t/

* gnu/packages/patches/linux-libre-documentation-fix-kernel_feat.py.patch: Add
patch.
* gnu/local.mk (dist_patch_DATA): Register it.
* gnu/packages/linux.scm (linux-libre-documentation): Use it.

Change-Id: Ic96f14aa25df09f38e029ca70d2647cbf37c2365
---
v2: Commit the patch instead of fetching it.

 gnu/local.mk                                  |  1 +
 gnu/packages/linux.scm                        |  5 ++
 ...bre-documentation-fix-kernel_feat.py.patch | 52 +++++++++++++++++++
 3 files changed, 58 insertions(+)
 create mode 100644 gnu/packages/patches/linux-libre-documentation-fix-kernel_feat.py.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index ab690795a7..a75577386c 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1629,6 +1629,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/linphone-desktop-without-sdk.patch	\
   %D%/packages/patches/linux-libre-infodocs-target.patch	\
   %D%/packages/patches/linux-libre-support-for-Pinebook-Pro.patch \
+  %D%/packages/patches/linux-libre-documentation-fix-kernel_feat.py.patch \
   %D%/packages/patches/linux-pam-no-setfsuid.patch		\
   %D%/packages/patches/linux-pam-unix_chkpwd.patch		\
   %D%/packages/patches/linuxdcpp-openssl-1.1.patch		\
diff --git a/gnu/packages/linux.scm b/gnu/packages/linux.scm
index b8b119e474..c23f07b1d5 100644
--- a/gnu/packages/linux.scm
+++ b/gnu/packages/linux.scm
@@ -2003,6 +2003,11 @@ (define-public linux-libre-documentation
   (package
     (inherit linux-libre)
     (name "linux-libre-documentation")
+    (source
+     (origin
+       (inherit linux-libre-source)
+       (patches
+        (search-patches "linux-libre-documentation-fix-kernel_feat.py.patch"))))
     (arguments
      (list
       #:tests? #f
diff --git a/gnu/packages/patches/linux-libre-documentation-fix-kernel_feat.py.patch b/gnu/packages/patches/linux-libre-documentation-fix-kernel_feat.py.patch
new file mode 100644
index 0000000000..9d535395be
--- /dev/null
+++ b/gnu/packages/patches/linux-libre-documentation-fix-kernel_feat.py.patch
@@ -0,0 +1,52 @@
+From c23de7ceae59e4ca5894c3ecf4f785c50c0fa428 Mon Sep 17 00:00:00 2001
+From: Vegard Nossum <[email-masked]>
+Date: Mon, 5 Feb 2024 18:51:26 +0100
+Subject: docs: kernel_feat.py: fix build error for missing files
+
+If the directory passed to the '.. kernel-feat::' directive does not
+exist or the get_feat.pl script does not find any files to extract
+features from, Sphinx will report the following error:
+
+    Sphinx parallel build error:
+    UnboundLocalError: local variable 'fname' referenced before assignment
+    make[2]: *** [Documentation/Makefile:102: htmldocs] Error 2
+
+This is due to how I changed the script in c48a7c44a1d0 ("docs:
+kernel_feat.py: fix potential command injection"). Before that, the
+filename passed along to self.nestedParse() in this case was weirdly
+just the whole get_feat.pl invocation.
+
+We can fix it by doing what kernel_abi.py does -- just pass
+self.arguments[0] as 'fname'.
+
+Fixes: c48a7c44a1d0 ("docs: kernel_feat.py: fix potential command injection")
+Cc: Justin Forbes <[email-masked]>
+Cc: Salvatore Bonaccorso <[email-masked]>
+Cc: Jani Nikula <[email-masked]>
+Cc: Mauro Carvalho Chehab <[email-masked]>
+Cc: [email-masked]
+Signed-off-by: Vegard Nossum <[email-masked]>
+Link: https://lore.kernel.org/r/[email-masked]
+Signed-off-by: Jonathan Corbet <[email-masked]>
+---
+ Documentation/sphinx/kernel_feat.py | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+(limited to 'Documentation/sphinx/kernel_feat.py')
+
+diff --git a/Documentation/sphinx/kernel_feat.py b/Documentation/sphinx/kernel_feat.py
+index b9df61eb450138..03ace5f01b5c02 100644
+--- a/Documentation/sphinx/kernel_feat.py
++++ b/Documentation/sphinx/kernel_feat.py
+@@ -109,7 +109,7 @@ class KernelFeat(Directive):
+             else:
+                 out_lines += line + "\n"
+
+-        nodeList = self.nestedParse(out_lines, fname)
++        nodeList = self.nestedParse(out_lines, self.arguments[0])
+         return nodeList
+
+     def nestedParse(self, lines, fname):
+--
+cgit 1.2.3-korg
+

base-commit: e9a6c7094822bc859d0694eeaf8f434317219367
--
2.41.0