Subject: [bug#51512] [PATCH v6 2/3]: gnu: Add guile-bash-for-bash-coding-utils

From: david larsson <[email-masked]>
Date: Tue, 23 May 2023 06:55:22 +0200

From 7f2df5fd5b6ec44170b44ac74cae554405d939b6 Mon Sep 17 00:00:00 2001
 From: David Larsson <[email-masked]>
Date: Tue, 23 May 2023 05:38:36 +0200
Subject: [PATCH 2/3] gnu: Add guile-bash-for-bash-coding-utils

* gnu/packages/bash.scm (guile-bash-for-bash-coding-utils): New 
variable.
---
  gnu/local.mk                                  |  1 +
  gnu/packages/bash.scm                         | 34 +++++++++++++++
  .../patches/guile-bash-args-from-stdin.patch  | 42 +++++++++++++++++++
  3 files changed, 77 insertions(+)
  create mode 100644 
gnu/packages/patches/guile-bash-args-from-stdin.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index c10fb01bb3..1db38d093c 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1302,6 +1302,7 @@ dist_patch_DATA =						\
    %D%/packages/patches/guile-1.8-cpp-4.5.patch			\
    %D%/packages/patches/guile-2.2-skip-oom-test.patch            \
    %D%/packages/patches/guile-2.2-skip-so-test.patch             \
+  %D%/packages/patches/guile-bash-args-from-stdin.patch		\
    %D%/packages/patches/guile-default-utf8.patch			\
    %D%/packages/patches/guile-2.2-default-utf8.patch		\
    %D%/packages/patches/guile-relocatable.patch			\
diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index 1650fdeb72..64d6e8d65e 100644
--- a/gnu/packages/bash.scm
+++ b/gnu/packages/bash.scm
@@ -40,6 +40,7 @@ (define-module (gnu packages bash)
    #:use-module (gnu packages pkg-config)
    #:use-module (gnu packages python)
    #:use-module (gnu packages guile)
+  #:use-module (gnu packages guile-xyz)
    #:use-module (gnu packages version-control)
    #:use-module (gnu packages less)
    #:use-module (guix packages)
@@ -540,3 +541,36 @@ (define-public pydaemon
  back as strings.  Can be used over either of a unix or tcp socket.")
        (home-page "https://gitlab.com/methuselah-0/pydaemon")
        (license license:gpl3))))
+
+(define-public guile-bash-for-bash-coding-utils
+  (let ((commit "1eabc563ca5692b3e08d84f1f0e6fd2283284469")
+        (revision "0"))
+    (package
+      (inherit guile2.0-bash)
+      (version (string-append "0.1.6-" revision "." (string-take commit 
7)))
+      (name "guile-bash-for-bash-coding-utils")
+      (home-page (package-home-page guile2.0-bash))
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (commit commit)
+                      (url home-page)))
+                (sha256
+                 (base32
+                  
"097vny990wp2qpjij6a5a5gwc6fxzg5wk56inhy18iki5v6pif1p"))
+                (file-name (string-append name "-" version 
"-checkout"))
+                (patches (search-patches 
"guile-bash-args-from-stdin.patch"))))
+      (arguments (substitute-keyword-arguments (package-arguments 
guile2.0-bash)
+                   ((#:tests? _ #f) #f)
+                   ((#:phases phases #~%standard-phases)
+                    #~(modify-phases #$phases
+                        (add-after 'install 'install-guile
+                          (lambda* (#:key inputs outputs 
#:allow-other-keys)
+                            (copy-recursively
+                             (string-append (assoc-ref outputs "out")
+                                            (assoc-ref inputs "guile") 
"/share")
+                             (string-append (assoc-ref outputs "out") 
"/share"))
+                            #t))))))
+      (inputs (modify-inputs (package-inputs guile2.0-bash)
+                (replace "guile" guile-3.0-latest)))
+      (propagated-inputs (list bash)))))
diff --git a/gnu/packages/patches/guile-bash-args-from-stdin.patch 
b/gnu/packages/patches/guile-bash-args-from-stdin.patch
new file mode 100644
index 0000000000..ad42616c70
--- /dev/null
+++ b/gnu/packages/patches/guile-bash-args-from-stdin.patch
@@ -0,0 +1,42 @@
+From a124921666a16cb4e93f59a653f98b99c78eb2ca Mon Sep 17 00:00:00 2001
+From: David Larsson <[email-masked]>
+Date: Thu, 11 Nov 2021 14:07:04 +0100
+Subject: [PATCH] Enable reading arguments from bash via stdin
+
+* lisp/gnu/bash.scm(define-bash-function): read from stdin
+to SCM_ARGS array when it is open, and separate args by null
+instead of newline if -z option is passed as $1.
+---
+ lisp/gnu/bash.scm | 16 ++++++++++++----
+ 1 file changed, 12 insertions(+), 4 deletions(-)
+
+diff --git a/lisp/gnu/bash.scm b/lisp/gnu/bash.scm
+index 199ebc0..e9dcea5 100644
+--- a/lisp/gnu/bash.scm
++++ b/lisp/gnu/bash.scm
+@@ -326,10 +326,18 @@
+       (hashq-set! *funcs* symbol thunk)
+       (unsafe-format/eval
+        "function ~a {
+-            SCM_ARGS=($@)    ;
+-            local retval=$~a ;
+-            unset SCM_ARGS   ;
+-            return $retval   ;
++            local -a Input SCM_ARGS                                    
       ;
++            [[ ! -t 0 ]] && mapfile -d '' Input                        
       ;
++            if [[ -n \"${Input[@]}\" ]]; then
++                if [[ \"$1\" == -z ]]; then
++                    local -a SCM_ARGS=\"(${Input[*]@Q})\"              
       ;
++                else
++                    mapfile -t SCM_ARGS < <(printf '%s' 
\"${Input[@]}\"); fi ;
++            else
++                SCM_ARGS=(\"$@\"); fi                                  
       ;
++            local retval=$~a                                           
       ;
++            unset SCM_ARGS                                             
       ;
++            return $retval                                             
       ;
+        }"
+        symbol special-varname))))
+
+--
+2.31.0
+
--
2.39.1

From 7f2df5fd5b6ec44170b44ac74cae554405d939b6 Mon Sep 17 00:00:00 2001
From: David Larsson <[email-masked]>
Date: Tue, 23 May 2023 05:38:36 +0200
Subject: [PATCH 2/3] gnu: Add guile-bash-for-bash-coding-utils

* gnu/packages/bash.scm (guile-bash-for-bash-coding-utils): New variable.
---
 gnu/local.mk                                  |  1 +
 gnu/packages/bash.scm                         | 34 +++++++++++++++
 .../patches/guile-bash-args-from-stdin.patch  | 42 +++++++++++++++++++
 3 files changed, 77 insertions(+)
 create mode 100644 gnu/packages/patches/guile-bash-args-from-stdin.patch

diff --git a/gnu/local.mk b/gnu/local.mk
index c10fb01bb3..1db38d093c 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1302,6 +1302,7 @@ dist_patch_DATA =						\
   %D%/packages/patches/guile-1.8-cpp-4.5.patch			\
   %D%/packages/patches/guile-2.2-skip-oom-test.patch            \
   %D%/packages/patches/guile-2.2-skip-so-test.patch             \
+  %D%/packages/patches/guile-bash-args-from-stdin.patch		\
   %D%/packages/patches/guile-default-utf8.patch			\
   %D%/packages/patches/guile-2.2-default-utf8.patch		\
   %D%/packages/patches/guile-relocatable.patch			\
diff --git a/gnu/packages/bash.scm b/gnu/packages/bash.scm
index 1650fdeb72..64d6e8d65e 100644
--- a/gnu/packages/bash.scm
+++ b/gnu/packages/bash.scm
@@ -40,6 +40,7 @@ (define-module (gnu packages bash)
   #:use-module (gnu packages pkg-config)
   #:use-module (gnu packages python)
   #:use-module (gnu packages guile)
+  #:use-module (gnu packages guile-xyz)
   #:use-module (gnu packages version-control)
   #:use-module (gnu packages less)
   #:use-module (guix packages)
@@ -540,3 +541,36 @@ (define-public pydaemon
 back as strings.  Can be used over either of a unix or tcp socket.")
       (home-page "https://gitlab.com/methuselah-0/pydaemon")
       (license license:gpl3))))
+
+(define-public guile-bash-for-bash-coding-utils
+  (let ((commit "1eabc563ca5692b3e08d84f1f0e6fd2283284469")
+        (revision "0"))
+    (package
+      (inherit guile2.0-bash)
+      (version (string-append "0.1.6-" revision "." (string-take commit 7)))
+      (name "guile-bash-for-bash-coding-utils")
+      (home-page (package-home-page guile2.0-bash))
+      (source (origin
+                (method git-fetch)
+                (uri (git-reference
+                      (commit commit)
+                      (url home-page)))
+                (sha256
+                 (base32
+                  "097vny990wp2qpjij6a5a5gwc6fxzg5wk56inhy18iki5v6pif1p"))
+                (file-name (string-append name "-" version "-checkout"))
+                (patches (search-patches "guile-bash-args-from-stdin.patch"))))
+      (arguments (substitute-keyword-arguments (package-arguments guile2.0-bash)
+                   ((#:tests? _ #f) #f)
+                   ((#:phases phases #~%standard-phases)
+                    #~(modify-phases #$phases
+                        (add-after 'install 'install-guile
+                          (lambda* (#:key inputs outputs #:allow-other-keys)
+                            (copy-recursively
+                             (string-append (assoc-ref outputs "out")
+                                            (assoc-ref inputs "guile") "/share")
+                             (string-append (assoc-ref outputs "out") "/share"))
+                            #t))))))
+      (inputs (modify-inputs (package-inputs guile2.0-bash)
+                (replace "guile" guile-3.0-latest)))
+      (propagated-inputs (list bash)))))
diff --git a/gnu/packages/patches/guile-bash-args-from-stdin.patch b/gnu/packages/patches/guile-bash-args-from-stdin.patch
new file mode 100644
index 0000000000..ad42616c70
--- /dev/null
+++ b/gnu/packages/patches/guile-bash-args-from-stdin.patch
@@ -0,0 +1,42 @@
+From a124921666a16cb4e93f59a653f98b99c78eb2ca Mon Sep 17 00:00:00 2001
+From: David Larsson <[email-masked]>
+Date: Thu, 11 Nov 2021 14:07:04 +0100
+Subject: [PATCH] Enable reading arguments from bash via stdin
+
+* lisp/gnu/bash.scm(define-bash-function): read from stdin
+to SCM_ARGS array when it is open, and separate args by null
+instead of newline if -z option is passed as $1.
+---
+ lisp/gnu/bash.scm | 16 ++++++++++++----
+ 1 file changed, 12 insertions(+), 4 deletions(-)
+
+diff --git a/lisp/gnu/bash.scm b/lisp/gnu/bash.scm
+index 199ebc0..e9dcea5 100644
+--- a/lisp/gnu/bash.scm
++++ b/lisp/gnu/bash.scm
+@@ -326,10 +326,18 @@
+       (hashq-set! *funcs* symbol thunk)
+       (unsafe-format/eval
+        "function ~a {
+-            SCM_ARGS=($@)    ;
+-            local retval=$~a ;
+-            unset SCM_ARGS   ;
+-            return $retval   ;
++            local -a Input SCM_ARGS                                          ;
++            [[ ! -t 0 ]] && mapfile -d '' Input                              ;
++            if [[ -n \"${Input[@]}\" ]]; then
++                if [[ \"$1\" == -z ]]; then
++                    local -a SCM_ARGS=\"(${Input[*]@Q})\"                    ;
++                else
++                    mapfile -t SCM_ARGS < <(printf '%s' \"${Input[@]}\"); fi ;
++            else
++                SCM_ARGS=(\"$@\"); fi                                        ;
++            local retval=$~a                                                 ;
++            unset SCM_ARGS                                                   ;
++            return $retval                                                   ;
+        }"
+        symbol special-varname))))
+ 
+-- 
+2.31.0
+
-- 
2.39.1