unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ludovic Courtès" <ludo@gnu.org>
To: 65229@debbugs.gnu.org
Cc: "Ludovic Courtès" <ludovic.courtes@inria.fr>,
	"Christopher Baines" <guix@cbaines.net>,
	"Josselin Poiret" <dev@jpoiret.xyz>,
	"Ludovic Courtès" <ludo@gnu.org>,
	"Mathieu Othacehe" <othacehe@gnu.org>,
	"Ricardo Wurmus" <rekado@elephly.net>,
	"Simon Tournier" <zimon.toutoune@gmail.com>,
	"Tobias Geerinckx-Rice" <me@tobias.gr>
Subject: [bug#65229] [PATCH v2 1/2] ui: 'load*' accepts /dev/fd/N files pointing to a pipe.
Date: Thu, 17 Aug 2023 12:17:28 +0200	[thread overview]
Message-ID: <f4b74d9d76b29436c1a4ce84fa3897bd274d524d.1692267211.git.ludo@gnu.org> (raw)
In-Reply-To: <875y5eyrl0.fsf@gnu.org>

From: Ludovic Courtès <ludovic.courtes@inria.fr>

This allows users to write Bash commands like:

  guix time-machine -C <(echo %default-channels) -- ...

or:

  guix build -m <(echo '(specifications->manifest (list "guile"))')

Previously, on GNU/Linux, they would fail with:

  error: failed to load '/dev/fd/63': No such file or directory

* guix/ui.scm (try-canonicalize-path): New procedure.
(load*): Use it.
* tests/guix-build.sh: Test 'guix build -m' with a /dev/fd/N file.
---
 guix/ui.scm         | 16 +++++++++++++++-
 tests/guix-build.sh |  9 ++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/guix/ui.scm b/guix/ui.scm
index 47a118364a..6f2d4fe245 100644
--- a/guix/ui.scm
+++ b/guix/ui.scm
@@ -200,6 +200,20 @@ (define-syntax-rule (without-compiler-optimizations exp)
   (parameterize (((@ (system base compile) default-optimization-level) 1))
     exp))
 
+(define (try-canonicalize-path file)
+  "Like 'canonicalize-path', but return FILE as-is if 'canonicalize-path'
+throws.
+
+This is necessary for corner cases where 'canonicalize-path' fails.  One
+example is on Linux when a /dev/fd/N file denotes a pipe, represented as a
+symlink to a non-existent file like 'pipe:[1234]', as in this example:
+
+  sh -c 'stat $(readlink -f /dev/fd/1)' | cat"
+  (catch 'system-error
+    (lambda ()
+      (canonicalize-path file))
+    (const file)))
+
 (define* (load* file user-module
                 #:key (on-error 'nothing-special))
   "Load the user provided Scheme source code FILE."
@@ -230,7 +244,7 @@ (define* (load* file user-module
                ;; 'primitive-load', so that FILE is compiled, which then allows
                ;; us to provide better error reporting with source line numbers.
                (without-compiler-optimizations
-                (load (canonicalize-path file))))
+                (load (try-canonicalize-path file))))
              (const #f))))))
     (lambda _
       ;; XXX: Errors are reported from the pre-unwind handler below, but
diff --git a/tests/guix-build.sh b/tests/guix-build.sh
index 317c58ac42..4eab0e38b6 100644
--- a/tests/guix-build.sh
+++ b/tests/guix-build.sh
@@ -1,5 +1,5 @@
 # GNU Guix --- Functional package management for GNU
-# Copyright © 2012-2014, 2016-2022 Ludovic Courtès <ludo@gnu.org>
+# Copyright © 2012-2014, 2016-2023 Ludovic Courtès <ludo@gnu.org>
 # Copyright © 2020 Marius Bakke <mbakke@fastmail.com>
 # Copyright © 2021 Chris Marusich <cmmarusich@gmail.com>
 #
@@ -397,6 +397,13 @@ guix build -d -m "$module_dir/manifest.scm" \
 
 rm "$module_dir"/*.scm
 
+if [ -n "$BASH_VERSION" ]
+then
+    # Check whether we can load from a /dev/fd/N denoting a pipe, using this
+    # handy Bash-specific construct.
+    guix build -m <(echo '(specifications->manifest (list "guile"))') -n
+fi
+
 # Using 'GUIX_BUILD_OPTIONS'.
 GUIX_BUILD_OPTIONS="--dry-run --no-grafts"
 export GUIX_BUILD_OPTIONS

base-commit: 1bd44b425b79e9da160b33a9b19d01973b44772e
-- 
2.41.0





  parent reply	other threads:[~2023-08-17 10:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-11 15:31 [bug#65229] [PATCH 0/2] Add '-q' for 'pull' and 'time-machine'; support loading from pipes Ludovic Courtès
2023-08-11 15:34 ` [bug#65229] [PATCH 1/2] pull, time-machine: Add '-q' to ignore channel files Ludovic Courtès
2023-08-16 12:59   ` Simon Tournier
2023-08-16 13:43     ` Simon Tournier
2023-08-17  8:56     ` Ludovic Courtès
2023-08-17  9:59       ` Simon Tournier
2023-08-17 10:17       ` Ludovic Courtès [this message]
2023-08-17 10:17       ` [bug#65229] [PATCH v2 2/2] " Ludovic Courtès
2023-08-17 11:20         ` Simon Tournier
2023-08-17 17:10           ` bug#65229: [PATCH 0/2] Add '-q' for 'pull' and 'time-machine'; support loading from pipes Ludovic Courtès
2023-08-11 15:34 ` [bug#65229] [PATCH 2/2] ui: 'load*' accepts /dev/fd/N files pointing to a pipe Ludovic Courtès
2023-08-16 13:32   ` Simon Tournier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f4b74d9d76b29436c1a4ce84fa3897bd274d524d.1692267211.git.ludo@gnu.org \
    --to=ludo@gnu.org \
    --cc=65229@debbugs.gnu.org \
    --cc=dev@jpoiret.xyz \
    --cc=guix@cbaines.net \
    --cc=ludovic.courtes@inria.fr \
    --cc=me@tobias.gr \
    --cc=othacehe@gnu.org \
    --cc=rekado@elephly.net \
    --cc=zimon.toutoune@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).