[PATCH 0/2]: Update guile-bash

  • Done
  • quality assurance status badge
Details
2 participants
  • david larsson
  • Ricardo Wurmus
Owner
unassigned
Submitted by
david larsson
Severity
normal

Debbugs page

david larsson wrote 3 years ago
(address . guix-patches@gnu.org)
cb85c24cfbbe08819ec2ce5381259059@selfhosted.xyz
Hi,

The following 2 patches update the guile-bash source url and home-page,
and adds a patch for it that does 2 things:
- fixes a bug, see below
- enables reading newline- or null-separated arguments via stdin to
guile-bash-defined bash functions.

The bug is that guile-bash can't read string args with whitespaces in
it. Example:
------------------------
~$ enable -f ~/.guix-profile/lib/bash/libguile-bash.so scm
~$ scm /tmp/printargs
~$ printargs "apa bepa" cepa
In procedure printargs: scm-function called from Bash with args (apa
bepa cepa) failed to match signature (file1 file2)
~$ cat /tmp/printargs
(use-modules
(gnu bash))
(define-bash-function (printargs file1 file2)
(display file1)
(display "\n")
(display file2)
(display "\n"))
-------------------------

After this patch, you can read args "as normal", or via stdin that are
either newline- or null-separated:
-------------------------
~$ printargs "apa bepa" cepa
apa bepa
cepa
~$ echo "$apa"
aba
aca
~$ printf '%s\0' "$apa" bepa | printargs -z
aba
aca
bepa
~$ echo "$apa" | printargs
aba
aca
-------------------------

Best regards,
David
david larsson wrote 3 years ago
Re: [bug#51791] [PATCH 1/2]: Update guile-bash
(address . 51791@debbugs.gnu.org)(name . Guix-patches)(address . guix-patches-bounces+david.larsson=selfhosted.xyz@gnu.org)
d57cb1227c8b359403eb0c780f96e416@selfhosted.xyz
On 2021-11-12 14:56, david larsson wrote:
Toggle quote (46 lines)
> Hi,
>
> The following 2 patches update the guile-bash source url and
> home-page, and adds a patch for it that does 2 things:
> - fixes a bug, see below
> - enables reading newline- or null-separated arguments via stdin to
> guile-bash-defined bash functions.
>
> The bug is that guile-bash can't read string args with whitespaces in
> it. Example:
> ------------------------
> ~$ enable -f ~/.guix-profile/lib/bash/libguile-bash.so scm
> ~$ scm /tmp/printargs
> ~$ printargs "apa bepa" cepa
> In procedure printargs: scm-function called from Bash with args (apa
> bepa cepa) failed to match signature (file1 file2)
> ~$ cat /tmp/printargs
> (use-modules
> (gnu bash))
> (define-bash-function (printargs file1 file2)
> (display file1)
> (display "\n")
> (display file2)
> (display "\n"))
> -------------------------
>
> After this patch, you can read args "as normal", or via stdin that are
> either newline- or null-separated:
> -------------------------
> ~$ printargs "apa bepa" cepa
> apa bepa
> cepa
> ~$ echo "$apa"
> aba
> aca
> ~$ printf '%s\0' "$apa" bepa | printargs -z
> aba
> aca
> bepa
> ~$ echo "$apa" | printargs
> aba
> aca
> -------------------------
>
> Best regards,
> David
From 413c8f08b0056fe6d08ee7dc08a9279f60c960c7 Mon Sep 17 00:00:00 2001
From: David Larsson <david.larsson@selfhosted.xyz>
Date: Fri, 12 Nov 2021 13:16:58 +0100
Subject: [PATCH 1/2] gnu: guile-bash: Update source url

* gnu/packages/guile-xyz (guile-bash)[homepage]: update to
the new repository.
---
gnu/packages/guile-xyz.scm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Toggle diff (15 lines)
diff --git a/gnu/packages/guile-xyz.scm b/gnu/packages/guile-xyz.scm
index 56d6d2565d..1d35c41796 100644
--- a/gnu/packages/guile-xyz.scm
+++ b/gnu/packages/guile-xyz.scm
@@ -413,7 +413,7 @@ dictionary and suggesting spelling corrections.")
(name "guile2.0-bash")
(version (string-append "0.1.6-" revision "." (string-take commit 7)))
(home-page
- "https://anonscm.debian.org/cgit/users/kaction-guest/retired/dev.guile-bash.git")
+ "https://git.sr.ht/~kaction/guile-bash")
(source (origin
(method git-fetch)
(uri (git-reference
--
2.31.0
david larsson wrote 3 years ago
(address . 51791@debbugs.gnu.org)(name . Guix-patches)(address . guix-patches-bounces+david.larsson=selfhosted.xyz@gnu.org)
bbb463a262deb7d59525297e337c6253@selfhosted.xyz
On 2021-11-12 14:56, david larsson wrote:
Toggle quote (46 lines)
> Hi,
>
> The following 2 patches update the guile-bash source url and
> home-page, and adds a patch for it that does 2 things:
> - fixes a bug, see below
> - enables reading newline- or null-separated arguments via stdin to
> guile-bash-defined bash functions.
>
> The bug is that guile-bash can't read string args with whitespaces in
> it. Example:
> ------------------------
> ~$ enable -f ~/.guix-profile/lib/bash/libguile-bash.so scm
> ~$ scm /tmp/printargs
> ~$ printargs "apa bepa" cepa
> In procedure printargs: scm-function called from Bash with args (apa
> bepa cepa) failed to match signature (file1 file2)
> ~$ cat /tmp/printargs
> (use-modules
> (gnu bash))
> (define-bash-function (printargs file1 file2)
> (display file1)
> (display "\n")
> (display file2)
> (display "\n"))
> -------------------------
>
> After this patch, you can read args "as normal", or via stdin that are
> either newline- or null-separated:
> -------------------------
> ~$ printargs "apa bepa" cepa
> apa bepa
> cepa
> ~$ echo "$apa"
> aba
> aca
> ~$ printf '%s\0' "$apa" bepa | printargs -z
> aba
> aca
> bepa
> ~$ echo "$apa" | printargs
> aba
> aca
> -------------------------
>
> Best regards,
> David
From 10cc67f7c25991ec2aca2044a9e18e90001d7a1a Mon Sep 17 00:00:00 2001
From: David Larsson <david.larsson@selfhosted.xyz>
Date: Fri, 12 Nov 2021 13:42:41 +0100
Subject: [PATCH 2/2] gnu: guile-bash: Add patch that fixes reading args.

This patch allows guile-bash defined bash-functions
to read newline- or null-separated arguments from stdin,
making it usable in bash pipelines. It also fixes a bug
with arguments containing whitespace not being properly
passed to the corresponding guile function.

* gnu/packages/guile-xyz (guile-bash)[patches]: add patch.
* gnu/packages/patches/guile-bash-args-from-stdin.patch: new file.
---
gnu/packages/guile-xyz.scm | 1 +
.../patches/guile-bash-args-from-stdin.patch | 42 +++++++++++++++++++
2 files changed, 43 insertions(+)
create mode 100644 gnu/packages/patches/guile-bash-args-from-stdin.patch

Toggle diff (62 lines)
diff --git a/gnu/packages/guile-xyz.scm b/gnu/packages/guile-xyz.scm
index 1d35c41796..511d766a6f 100644
--- a/gnu/packages/guile-xyz.scm
+++ b/gnu/packages/guile-xyz.scm
@@ -419,6 +419,7 @@ dictionary and suggesting spelling corrections.")
(uri (git-reference
(commit commit)
(url home-page)))
+ (patches (search-patches "guile-bash-args-from-stdin.patch"))
(sha256
(base32
"097vny990wp2qpjij6a5a5gwc6fxzg5wk56inhy18iki5v6pif1p"))
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 <david.larsson@selfhosted.xyz>
+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.31.0
david larsson wrote 3 years ago
Re: [bug#51791] [PATCH 2/2]: Update guile-bash
(address . 51791@debbugs.gnu.org)(name . Guix-patches)(address . guix-patches-bounces+david.larsson=selfhosted.xyz@gnu.org)
8d6b871864d52beebcdbe83cae97769c@selfhosted.xyz
On 2021-11-12 14:56, david larsson wrote:
Toggle quote (46 lines)
> Hi,
>
> The following 2 patches update the guile-bash source url and
> home-page, and adds a patch for it that does 2 things:
> - fixes a bug, see below
> - enables reading newline- or null-separated arguments via stdin to
> guile-bash-defined bash functions.
>
> The bug is that guile-bash can't read string args with whitespaces in
> it. Example:
> ------------------------
> ~$ enable -f ~/.guix-profile/lib/bash/libguile-bash.so scm
> ~$ scm /tmp/printargs
> ~$ printargs "apa bepa" cepa
> In procedure printargs: scm-function called from Bash with args (apa
> bepa cepa) failed to match signature (file1 file2)
> ~$ cat /tmp/printargs
> (use-modules
> (gnu bash))
> (define-bash-function (printargs file1 file2)
> (display file1)
> (display "\n")
> (display file2)
> (display "\n"))
> -------------------------
>
> After this patch, you can read args "as normal", or via stdin that are
> either newline- or null-separated:
> -------------------------
> ~$ printargs "apa bepa" cepa
> apa bepa
> cepa
> ~$ echo "$apa"
> aba
> aca
> ~$ printf '%s\0' "$apa" bepa | printargs -z
> aba
> aca
> bepa
> ~$ echo "$apa" | printargs
> aba
> aca
> -------------------------
>
> Best regards,
> David
From 10cc67f7c25991ec2aca2044a9e18e90001d7a1a Mon Sep 17 00:00:00 2001
From: David Larsson <david.larsson@selfhosted.xyz>
Date: Fri, 12 Nov 2021 13:42:41 +0100
Subject: [PATCH 2/2] gnu: guile-bash: Add patch that fixes reading args.

This patch allows guile-bash defined bash-functions
to read newline- or null-separated arguments from stdin,
making it usable in bash pipelines. It also fixes a bug
with arguments containing whitespace not being properly
passed to the corresponding guile function.

* gnu/packages/guile-xyz (guile-bash)[patches]: add patch.
* gnu/packages/patches/guile-bash-args-from-stdin.patch: new file.
---
gnu/packages/guile-xyz.scm | 1 +
.../patches/guile-bash-args-from-stdin.patch | 42 +++++++++++++++++++
2 files changed, 43 insertions(+)
create mode 100644 gnu/packages/patches/guile-bash-args-from-stdin.patch

Toggle diff (62 lines)
diff --git a/gnu/packages/guile-xyz.scm b/gnu/packages/guile-xyz.scm
index 1d35c41796..511d766a6f 100644
--- a/gnu/packages/guile-xyz.scm
+++ b/gnu/packages/guile-xyz.scm
@@ -419,6 +419,7 @@ dictionary and suggesting spelling corrections.")
(uri (git-reference
(commit commit)
(url home-page)))
+ (patches (search-patches "guile-bash-args-from-stdin.patch"))
(sha256
(base32
"097vny990wp2qpjij6a5a5gwc6fxzg5wk56inhy18iki5v6pif1p"))
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 <david.larsson@selfhosted.xyz>
+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.31.0
david larsson wrote 3 years ago
Re: [bug#51791] [PATCH 2/2 v2]: Update guile-bash
(address . 51791@debbugs.gnu.org)(name . Guix-patches)(address . guix-patches-bounces+david.larsson=selfhosted.xyz@gnu.org)
650e73fe887c2524947b7c06d9dc9994@selfhosted.xyz
Forgot to update gnu/local.mk with the patch file for guile-bash so
fixing that with this new patch.
From b5e120040b47e590aa276a2802aac53139a72196 Mon Sep 17 00:00:00 2001
From: David Larsson <david.larsson@selfhosted.xyz>
Date: Fri, 12 Nov 2021 13:42:41 +0100
Subject: [PATCH 2/2] gnu: guile-bash: Add patch that fixes reading args.

This patch allows guile-bash defined bash-functions
to read newline- or null-separated arguments from stdin,
making it usable in bash pipelines. It also fixes a bug
with arguments containing whitespace not being properly
passed to the corresponding guile function.

* gnu/packages/guile-xyz (guile-bash)[patches]: add patch.
* gnu/packages/patches/guile-bash-args-from-stdin.patch: new file.
* gnu/local.mk: add patch file.
---
gnu/local.mk | 1 +
gnu/packages/guile-xyz.scm | 1 +
.../patches/guile-bash-args-from-stdin.patch | 42 +++++++++++++++++++
3 files changed, 44 insertions(+)
create mode 100644 gnu/packages/patches/guile-bash-args-from-stdin.patch

Toggle diff (74 lines)
diff --git a/gnu/local.mk b/gnu/local.mk
index 05258ac054..fdc562b710 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1242,6 +1242,7 @@ dist_patch_DATA = \
%D%/packages/patches/guile-3.0-relocatable.patch \
%D%/packages/patches/guile-linux-syscalls.patch \
%D%/packages/patches/guile-3.0-linux-syscalls.patch \
+ %D%/packages/patches/guile-bash-args-from-stdin.patch \
%D%/packages/patches/guile-fibers-destroy-peer-schedulers.patch \
%D%/packages/patches/guile-gdbm-ffi-support-gdbm-1.14.patch \
%D%/packages/patches/guile-present-coding.patch \
diff --git a/gnu/packages/guile-xyz.scm b/gnu/packages/guile-xyz.scm
index 1d35c41796..511d766a6f 100644
--- a/gnu/packages/guile-xyz.scm
+++ b/gnu/packages/guile-xyz.scm
@@ -419,6 +419,7 @@ dictionary and suggesting spelling corrections.")
(uri (git-reference
(commit commit)
(url home-page)))
+ (patches (search-patches "guile-bash-args-from-stdin.patch"))
(sha256
(base32
"097vny990wp2qpjij6a5a5gwc6fxzg5wk56inhy18iki5v6pif1p"))
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 <david.larsson@selfhosted.xyz>
+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.31.0
Ricardo Wurmus wrote 3 years ago
[PATCH 0/2]: Update guile-bash
(address . 51791@debbugs.gnu.org)(address . david.larsson@selfhosted.xyz)
871r2wu6x7.fsf@elephly.net
Hi David,

thank you for the update! What is the upstream status of this
patch? Has it been sent to upstream? Is upstream development
continuing? (That’s what the new home-page implies.)

--
Ricardo
david larsson wrote 3 years ago
(name . Ricardo Wurmus)(address . rekado@elephly.net)(address . 51791@debbugs.gnu.org)
16a9bbc19db48fb2698d75f30ae6a647@selfhosted.xyz
On 2021-12-01 08:20, Ricardo Wurmus wrote:
Toggle quote (6 lines)
> Hi David,
>
> thank you for the update! What is the upstream status of this patch?
> Has it been sent to upstream? Is upstream development continuing?
> (That’s what the new home-page implies.)

I have sent a patch a couple weeks ago via sr.ht (my fork is here:
response so far.

The latest patch is from 6 years ago so development has probably not
restarted.

I still think it would be good to change the upstream to sr.ht because
it very much looks like it's the original author's repository (username
is kaction) and it has all the change history - versus as it is now
where I think software heritage is used when building it from source (or
maybe a cached version on the build farms).

Best regards,
David
david larsson wrote 3 years ago
Re: [bug#51791] [PATCH 0/2]: Update guile-bash
(address . 51791@debbugs.gnu.org)(name . Guix-patches)(address . guix-patches-bounces+david.larsson=selfhosted.xyz@gnu.org)
53c6bec8033b6f2f720db9886d7ed8e2@selfhosted.xyz
If anyone wants to install a guile-bash that can read arguments with
whitespace, and newlines, you can install it like this:

wget -O /tmp/patch.temp http://paste.debian.net/plain/1223545; guix
package --with-patch=guile-bash=/tmp/patch.temp -i guile-bash


Then prepare it like this for example:

------------------------------------------
$ export GUILE_AUTO_COMPILE=0
$ enable -f ~/.guix-profile/lib/bash/libguile-bash.so scm
$ cat <<'EOF'>/tmp/printargs.scm
(use-modules
(gnu bash))
(define-bash-function (printargs file1 file2)
(display file1)
(display "\n")
(display file2)
(display "\n"))
EOF
$ scm /tmp/printargs.scm
-------------------------

And then use the guile function from bash like this:

-------------------------
~$ printargs "apa bepa" cepa
apa bepa
cepa
~$ echo "$apa"
aba
aca
~$ printf '%s\0' "$apa" bepa | printargs -z
aba
aca
bepa
~$ echo "$apa" | printargs
aba
aca
-------------------------


Closing this bug now.
david larsson wrote 3 years ago
done
(address . 51791-done@debbugs.gnu.org)
e65d8120df6330d962d8e491b0f2edaf@selfhosted.xyz
done
Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 51791@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 51791
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help