Subject: [bug#77131] [PATCH 08/51] gnu: Add makem-minimal.

From: Nicolas Graves <[email-masked]>
Date: Thu, 20 Mar 2025 11:08:16 +0100

* gnu/packages/emacs-build.scm (makem-minimal): New variable.
---
 gnu/local.mk                                 |  1 +
 gnu/packages/emacs-build.scm                 | 59 +++++++++++++++++
 gnu/packages/patches/makem-replace-git.patch | 66 ++++++++++++++++++++
 3 files changed, 126 insertions(+)
 create mode 100644 gnu/packages/patches/makem-replace-git.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index 417cbf080d..21d58b9bef 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1827,6 +1827,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/mailutils-variable-lookup.patch		\
   %D%/packages/patches/mandoc-support-zstd-compression.patch	\
   %D%/packages/patches/make-impure-dirs.patch			\
+  %D%/packages/patches/makem-replace-git.patch			\
   %D%/packages/patches/mariadb-rocksdb-atomic-linking.patch	\
   %D%/packages/patches/mathjax-disable-webpack.patch			\
   %D%/packages/patches/mathjax-no-a11y.patch			\
diff --git a/gnu/packages/emacs-build.scm b/gnu/packages/emacs-build.scm
index aa917cc0ac..bc7c9ca708 100644
--- a/gnu/packages/emacs-build.scm
+++ b/gnu/packages/emacs-build.scm
@@ -521,3 +521,62 @@ (define-public makel
       (description "This package provides a makefile to help checking Emacs
 packages.")
       (license license:gpl3+))))
+
+;; This is an alternative version patches for internal Guix tests.
+;; The user-facing version is in emacs-xyz.scm
+(define-public makem-minimal
+  (package
+    (name "makem")
+    (version "0.7.1")
+    (source
+     (origin
+       (method git-fetch)
+       (uri (git-reference
+             (url "https://github.com/alphapapa/makem.sh")
+             (commit (string-append "v" version))))
+       (file-name (git-file-name name version))
+       (sha256
+        (base32 "1xqwfxkxgpcm3k2m2shwkwrm4asl59ik8867c3k1iwfj8xzfp089"))
+       (modules '((guix build utils)))
+       (snippet #~(begin
+                    (delete-file-recursively "images")))))
+    (build-system emacs-build-system)
+    (arguments
+     (let ((patch (local-file
+                   (car (search-patches "makem-replace-git.patch")))))
+       (list
+        #:tests? #f
+        #:modules
+        '((guix build emacs-build-system)
+          (guix build utils)
+          (guix build emacs-utils)
+          (srfi srfi-26))
+        #:phases
+        #~(modify-phases %standard-phases
+            (add-after 'unpack 'patch-file
+              (lambda* (#:key inputs #:allow-other-keys)
+                (invoke (search-input-file inputs "bin/patch")
+                        "--force" "--no-backup-if-mismatch"
+                        "-p1" "--input" #$patch)))
+            (add-after 'install 'install-bin
+              (lambda _
+                (let ((bin (string-append #$output "/bin")))
+                  (mkdir-p bin)
+                  (install-file "makem.sh" bin))))
+            (add-after 'install-bin 'wrap-script
+              (lambda* (#:key inputs outputs #:allow-other-keys)
+                (wrap-program (string-append #$output "/bin/makem.sh")
+                  `("PATH" ":" prefix
+                    ,(map dirname
+                          (map (cut search-input-file inputs <>)
+                               (list "bin/find"
+                                     "bin/grep"
+                                     "bin/sed")))))))))))
+    (native-inputs (list patch))
+    (inputs
+     (list coreutils-minimal grep sed util-linux))  ; for getopt
+    (home-page "https://github.com/alphapapa/makem.sh")
+    (synopsis "Makefile-like script to help checking Emacs packages")
+    (description "This package provides a Makefile-like script and a transient
+menu for linting and testing Emacs packages.")
+    (license license:gpl3+)))
diff --git a/gnu/packages/patches/makem-replace-git.patch b/gnu/packages/patches/makem-replace-git.patch
new file mode 100644
index 0000000000..eced0618e3
--- /dev/null
+++ b/gnu/packages/patches/makem-replace-git.patch
@@ -0,0 +1,66 @@
+From 5396f4d6312b24eac79da2f70279df773443fd10 Mon Sep 17 00:00:00 2001
+From: Nicolas Graves <[email-masked]>
+Date: Wed, 19 Mar 2025 13:02:47 +0100
+Subject: [PATCH] Replace git.
+
+---
+ makem.sh | 34 +++++-----------------------------
+ 1 file changed, 5 insertions(+), 29 deletions(-)
+
+diff --git a/makem.sh b/makem.sh
+index fd81e0f..4ec9577 100755
+--- a/makem.sh
++++ b/makem.sh
+@@ -385,34 +385,13 @@ function byte-compile-file {
+ 
+ # ** Files
+ 
+-function submodules {
+-    # Echo a list of submodules's paths relative to the repo root.
+-    # TODO: Parse with bash regexp instead of cut.
+-    git submodule status | awk '{print $2}'
+-}
+-
+-function project-root {
+-    # Echo the root of the project (or superproject, if running from
+-    # within a submodule).
+-    root_dir=$(git rev-parse --show-superproject-working-tree)
+-    [[ $root_dir ]] || root_dir=$(git rev-parse --show-toplevel)
+-    [[ $root_dir ]] || error "Can't find repo root."
+-
+-    echo "$root_dir"
+-}
+-
+ function files-project {
+     # Echo a list of files in project; or with $1, files in it
+-    # matching that pattern with "git ls-files".  Excludes submodules.
+-    [[ $1 ]] && pattern="/$1" || pattern="."
+-
+-    local excludes
+-    for submodule in $(submodules)
+-    do
+-        excludes+=(":!:$submodule")
+-    done
+-
+-    git ls-files -- "$pattern" "${excludes[@]}"
++    # matching that pattern with "find".
++    if [[ $1 ]]
++    then find . -type f -name "$1" | sed 's|^\./||'
++    else find . -type f | sed 's|^\./||'
++    fi
+ }
+ 
+ function dirs-project {
+@@ -1223,9 +1202,6 @@ paths_temp+=("$package_initialize_file")
+ 
+ trap cleanup EXIT INT TERM
+ 
+-# Change to project root directory first.
+-cd "$(project-root)"
+-
+ # Discover project files.
+ files_project_feature=($(files-project-feature))
+ files_project_test=($(files-project-test))
+-- 
+2.48.1
+
-- 
2.48.1