Subject: [bug#76208] [PATCH 2/3] gnu: Add gnulib-2022-02-12.

From: Denis 'GNUtoo' Carikli <[email-masked]>
Date: Tue, 11 Feb 2025 18:14:54 +0100

* gnu/packages/build-tools.scm (gnulib-2022-02-12): New variable.
* gnu/packages/patches/gnulib-2022-02-12-bootstrap.patch: New patch.
* gnu/local.mk (dist_patch_DATA): Register patch.

GRUB 2.12 depends on gnulib 9f48fb992a3d7e96610c4ce8be969cff2d61a01b
("filevercmp: fix several unexpected results"), as stated in the
bootstrap.conf in the GRUB source code.

Signed-off-by: Denis 'GNUtoo' Carikli <[email-masked]>
Change-Id: I5c2c19aadfd0e6bf5303e10fbc602daa7dd0d0ff
---
 gnu/local.mk                                  |   1 +
 gnu/packages/build-tools.scm                  | 109 ++++++++++++++++++
 .../patches/gnulib-2022-02-12-bootstrap.patch |  78 +++++++++++++
 3 files changed, 188 insertions(+)
 create mode 100644 gnu/packages/patches/gnulib-2022-02-12-bootstrap.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 9e192f1e4f1..3b54cd60177 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1497,6 +1497,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/gnome-session-support-elogind.patch	\
   %D%/packages/patches/gnome-tweaks-search-paths.patch		\
   %D%/packages/patches/gnulib-bootstrap.patch			\
+  %D%/packages/patches/gnulib-2022-02-12-bootstrap.patch	\
   %D%/packages/patches/gnumach-version.patch			\
   %D%/packages/patches/gnupg-default-pinentry.patch		\
   %D%/packages/patches/gnupg-1-build-with-gcc10.patch		\
diff --git a/gnu/packages/build-tools.scm b/gnu/packages/build-tools.scm
index 20fd7bafd8e..839018cd661 100644
--- a/gnu/packages/build-tools.scm
+++ b/gnu/packages/build-tools.scm
@@ -16,6 +16,7 @@
 ;;; Copyright © 2021, 2023, 2024 Maxim Cournoyer <[email-masked]>
 ;;; Copyright © 2022, 2023 Juliana Sims <[email-masked]>
 ;;; Copyright © 2024 Evgeny Pisemsky <[email-masked]>
+;;; Copyright © 2025 Denis 'GNUtoo' Carikli <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -988,6 +989,114 @@ (define-public gnulib
    #:commit "ac4b301ae15223c98b51cd5a0eda2e2cf57c817b"
    #:hash (base32 "0f4w56fc97clg13mmdghx84dh9xqmaqr3j672ppfh3h66gmmmvzs")))
 
+(define-public gnulib-2022-02-12
+  (let ((gnulib-2022-02-12-checkout
+         (gnulib-checkout
+          #:version "2022-02-12"
+          ;; from bootstrap.conf in GRUB source code
+          #:commit "9f48fb992a3d7e96610c4ce8be969cff2d61a01b"
+          #:hash
+          (base32 "1njf4y5sfysrshf6l4gjbn5k7k1lm698wrpc4fjw9acdlkmwadlv"))))
+    (package
+      (inherit gnulib-2022-02-12-checkout)
+      (source
+       (origin
+         (inherit (package-source gnulib-2022-02-12-checkout))
+         ;; The Guix path only affect the gnulib tools and not its
+         ;; unmodified source code.
+         (patches (search-patches "gnulib-2022-02-12-bootstrap.patch"))))
+      (arguments
+       (substitute-keyword-arguments
+           (package-arguments gnulib-2022-02-12-checkout)
+         ((#:install-plan base-plan)
+          #~'(("./gnulib-tool"    "bin/")
+              ("./gnulib-tool.py" "bin/")
+              ("." "src/gnulib" #:exclude-regexp ("\\.git.*"))))
+         ((#:phases phases #~%standard-phases)
+          #~(modify-phases
+                #$phases
+              ;; The regenerate-unicode stage from gnulib-checkout in (gnu
+              ;; packages build-tools) passes an extra BidiMirroring.txt
+              ;; and this makes gen-uni-tables fails and print its help:
+              ;;     Usage: ./gen-uni-tables UnicodeData.txt PropList.txt
+              ;;     DerivedCoreProperties.txt emoji-data.txt
+              ;;     ArabicShaping.txt Scripts.txt Blocks.txt
+              ;;     PropList-3.0.1.txt EastAsianWidth.txt LineBreak.txt
+              ;;     WordBreakProperty.txt GraphemeBreakProperty.txt
+              ;;     CompositionExclusions.txt SpecialCasing.txt
+              ;;     CaseFolding.txt version
+              (delete 'regenerate-unicode)
+              (add-before
+                  'check 'regenerate-unicode-without-bidi-mirroring
+                (lambda* (#:key inputs #:allow-other-keys)
+                  (define (find-ucd-file name)
+                    (search-input-file
+                     inputs (string-append "share/ucd/" name)))
+                  (define (find-ucd-files . names)
+                    (map find-ucd-file names))
+                  (with-directory-excursion
+                      "lib"
+                    ;; See the compile-command buffer-local variable in
+                    ;; lib/gen-uni-tables.c
+                    (invoke "gcc" "-O" "-Wall" "gen-uni-tables.c"
+                            "-Iunictype" "-o" "gen-uni-tables")
+                    (apply invoke
+                           "./gen-uni-tables"
+                           (append
+                            (find-ucd-files
+                             "UnicodeData.txt"
+                             "PropList.txt"
+                             "DerivedCoreProperties.txt"
+                             "emoji/emoji-data.txt"
+                             "ArabicShaping.txt"
+                             "Scripts.txt"
+                             "Blocks.txt")
+                            (list #$(this-package-native-input "PropList.txt"))
+                            (find-ucd-files
+                             "EastAsianWidth.txt"
+                             "LineBreak.txt"
+                             "auxiliary/WordBreakProperty.txt"
+                             "auxiliary/GraphemeBreakProperty.txt"
+                             "CompositionExclusions.txt"
+                             "SpecialCasing.txt"
+                             "CaseFolding.txt")
+                            (list
+                             #$(package-version
+                                (this-package-native-input "ucd")))))
+                    (invoke "clisp" "-C" "uniname/gen-uninames.lisp"
+                            (find-ucd-file "UnicodeData.txt")
+                            "uniname/uninames.h"
+                            (find-ucd-file "NameAliases.txt"))
+                    (for-each
+                     (match-lambda
+                       ((ucd-file . directory)
+                        (copy-file (find-ucd-file ucd-file)
+                                   (string-append "../tests/" directory "/"
+                                                  (basename ucd-file)))))
+                     '(("NameAliases.txt" . "uniname")
+                       ("UnicodeData.txt" . "uniname")
+                       ("NormalizationTest.txt" . "uninorm")
+                       ("auxiliary/GraphemeBreakTest.txt" . "unigbrk")
+                       ("auxiliary/WordBreakTest.txt" . "uniwbrk")))
+                    (delete-file "gen-uni-tables"))))))))
+      (native-inputs
+       (list
+        bash-minimal
+        clisp
+        git
+        perl
+        python
+        ucd-14.0.0 ;; Unicode data:
+        (origin
+          (method url-fetch)
+          (uri (string-append
+                "https://www.unicode.org/Public/"
+                "3.0-Update1/PropList-3.0.1.txt"))
+          (file-name "PropList.txt")
+          (sha256
+           (base32
+            "0k6wyijyzdl5g3nibcwfm898kfydx1pqaz28v7fdvnzdvd5fz7lh"))))))))
+
 (define-public pdpmake
   (package
     (name "pdpmake")
diff --git a/gnu/packages/patches/gnulib-2022-02-12-bootstrap.patch b/gnu/packages/patches/gnulib-2022-02-12-bootstrap.patch
new file mode 100644
index 00000000000..f9efc061be4
--- /dev/null
+++ b/gnu/packages/patches/gnulib-2022-02-12-bootstrap.patch
@@ -0,0 +1,78 @@
+From b1bd3c4201d7b7936980538e85ad026f9954adcf Mon Sep 17 00:00:00 2001
+From: Maxim Cournoyer <[email-masked]>
+Date: Thu, 30 May 2024 14:48:04 -0400
+Subject: [PATCH] bootstrap: Use gnulib-tool from PATH if available.
+
+Some distributions such as GNU Guix include in their package for
+gnulib a 'gnulib-tool' command under their $bindir
+prefix (e.g. '/bin') for users to use, along the unmodified full
+sources.  The idea is that any wrapping or distribution modifications
+for the *execution* of the script at run time is done on these
+commands, while the rest of the source should be in their
+pristine (unmodified) version.  Adjust the 'gnulib-tool' discovery
+mechanism to support such installation layout.
+
+* build-aux/bootstrap (autogen) <gnulib_tool>: Prefer to use from
+PATH, else from $GNULIB_SRCDIR/../../bin/gnulib-tool, else from
+$GNULIB_SRCDIR/gnulib-tool.
+* gnulib-tool.sh (func_gnulib_dir): Honor GNULIB_SRCDIR to locate
+gnulib's main directory.
+
+GNUtoo: Backport on top of the commit
+        9f48fb992a3d7e96610c4ce8be969cff2d61a01b
+        ("filevercmp: fix several unexpected results").
+Signed-off-by: Denis 'GNUtoo' Carikli <[email-masked]>
+---
+ build-aux/bootstrap | 12 ++++++++++--
+ gnulib-tool         |  6 +++++-
+ 2 files changed, 15 insertions(+), 3 deletions(-)
+
+diff --git a/build-aux/bootstrap b/build-aux/bootstrap
+index dc2238f4ad..93778a7020 100755
+--- a/build-aux/bootstrap
++++ b/build-aux/bootstrap
+@@ -1,6 +1,6 @@
+ #! /bin/sh
+ # Print a version string.
+-scriptversion=2022-01-26.05; # UTC
++scriptversion=2022-02-12.00; # UTC
+ 
+ # Bootstrap this package from checked-out sources.
+ 
+@@ -838,7 +838,15 @@ if $use_gnulib; then
+     }
+   fi
+ 
+-  gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
++  gnulib_tool=$(command -v gnulib-tool)
++  if test -x "$gnulib_tool"; then
++    :                         # done
++  elif test -x $GNULIB_SRCDIR/../../bin/gnulib-tool; then
++    gnulib_tool=$GNULIB_SRCDIR/../../bin/gnulib-tool
++  else
++    gnulib_tool=$GNULIB_SRCDIR/gnulib-tool
++  fi
++
+   <$gnulib_tool || exit $?
+ fi
+ 
+diff --git a/gnulib-tool b/gnulib-tool
+index 99854415ba..728430579b 100755
+--- a/gnulib-tool
++++ b/gnulib-tool
+@@ -486,7 +486,11 @@ func_gnulib_dir ()
+       * ) self_abspathname=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`/"$linkval" ;;
+     esac
+   done
+-  gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
++  if test -n "$GNULIB_SRCDIR"; then
++    gnulib_dir=$GNULIB_SRCDIR
++  else
++    gnulib_dir=`echo "$self_abspathname" | sed -e 's,/[^/]*$,,'`
++  fi
+ }
+ 
+ # func_tmpdir
+-- 
+2.46.0
+
-- 
2.46.0