Subject: [bug#60145] [PATCH 2/2] gnu: Add patman.

From: Maxim Cournoyer <[email-masked]>
Date: Fri, 16 Dec 2022 23:35:49 -0500

* gnu/packages/bootloaders.scm (patman): New variable.
* gnu/packages/patches/u-boot-patman-fix-help.patch: New patch.
* gnu/local.mk (dist_patch_DATA): Register it.
---

 gnu/local.mk                                  |  1 +
 gnu/packages/bootloaders.scm                  | 34 +++++++++++++++-
 .../patches/u-boot-patman-fix-help.patch      | 40 +++++++++++++++++++
 3 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 gnu/packages/patches/u-boot-patman-fix-help.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 8ae21641d7..456d955616 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1924,6 +1924,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/twinkle-bcg729.patch			\
   %D%/packages/patches/u-boot-allow-disabling-openssl.patch	\
   %D%/packages/patches/u-boot-infodocs-target.patch		\
+  %D%/packages/patches/u-boot-patman-fix-help.patch		\
   %D%/packages/patches/u-boot-nintendo-nes-serial.patch		\
   %D%/packages/patches/u-boot-rockchip-inno-usb.patch		\
   %D%/packages/patches/u-boot-sifive-prevent-reloc-initrd-fdt.patch	\
diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index f52b2130ac..335b5a56d8 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -69,7 +69,10 @@ (define-module (gnu packages bootloaders)
   #:use-module (gnu packages valgrind)
   #:use-module (gnu packages virtualization)
   #:use-module (gnu packages xorg)
+  #:use-module (gnu packages python-web)
+  #:use-module (gnu packages python-xyz)
   #:use-module (guix build-system gnu)
+  #:use-module (guix build-system pyproject)
   #:use-module (guix build-system trivial)
   #:use-module (guix download)
   #:use-module (guix gexp)
@@ -640,7 +643,8 @@ (define u-boot
                      %u-boot-allow-disabling-openssl-patch
                      %u-boot-sifive-prevent-relocating-initrd-fdt
                      %u-boot-rk3399-enable-emmc-phy-patch
-                     (search-patch "u-boot-infodocs-target.patch")))
+                     (search-patch "u-boot-infodocs-target.patch")
+                     (search-patch "u-boot-patman-fix-help.patch")))
               (method url-fetch)
               (uri (string-append
                     "https://ftp.denx.de/pub/u-boot/"
@@ -822,6 +826,34 @@ (define-public u-boot-tools
                   "  This package provides board-independent tools "
                   "of U-Boot."))))
 
+;;; This is packaged separately, as it can be used in other contexts than for
+;;; U-Boot development.
+(define-public patman
+  (package
+    (inherit u-boot)
+    (name "patman")
+    (build-system pyproject-build-system)
+    (arguments
+     ;; The test suite strongly relies on the git metadata being available (23
+     ;; failed, 14 passed).
+     (list
+      #:tests? #f
+      #:phases
+      #~(modify-phases %standard-phases
+          (add-after 'unpack 'chdir
+            (lambda _
+              (chdir "tools/patman"))))))
+    (inputs (list python-pygit2 python-requests))
+    (synopsis "Patch automation tool")
+    (description "Patman is a patch automation script which:
+@itemize
+@item Creates patches directly from your branch
+@item Cleans them up by removing unwanted tags
+@item Inserts a cover letter with change lists
+@item Runs the patches through automated checks
+@item Optionally emails them out to selected people.
+@end itemize")))
+
 (define*-public (make-u-boot-package board triplet
                                      #:key
                                      defconfig
diff --git a/gnu/packages/patches/u-boot-patman-fix-help.patch b/gnu/packages/patches/u-boot-patman-fix-help.patch
new file mode 100644
index 0000000000..15b1aa3b55
--- /dev/null
+++ b/gnu/packages/patches/u-boot-patman-fix-help.patch
@@ -0,0 +1,40 @@
+Submitted upstream on Dec 16th, 2022.
+
+diff --git a/tools/patman/main.py b/tools/patman/main.py
+index 5a7756a221..bf300c6e64 100755
+--- a/tools/patman/main.py
++++ b/tools/patman/main.py
+@@ -7,6 +7,7 @@
+ """See README for more information"""
+ 
+ from argparse import ArgumentParser
++import importlib.resources
+ import os
+ import re
+ import shutil
+@@ -163,11 +164,8 @@ elif args.cmd == 'send':
+         fd.close()
+ 
+     elif args.full_help:
+-        tools.print_full_help(
+-            os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])),
+-                         'README.rst')
+-        )
+-
++        with importlib.resources.path('patman', 'README.rst') as readme:
++            tools.print_full_help(str(readme))
+     else:
+         # If we are not processing tags, no need to warning about bad ones
+         if not args.process_tags:
+diff --git a/tools/patman/setup.py b/tools/patman/setup.py
+index 43fdc00ce6..ce9bb4aa63 100644
+--- a/tools/patman/setup.py
++++ b/tools/patman/setup.py
+@@ -7,6 +7,6 @@ setup(name='patman',
+       scripts=['patman'],
+       packages=['patman'],
+       package_dir={'patman': ''},
+-      package_data={'patman': ['README']},
++      package_data={'patman': ['README.rst']},
+       classifiers=['Environment :: Console',
+                    'Topic :: Software Development'])
-- 
2.38.1