From patchwork Thu Aug 17 10:17:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 52955 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id ED49C27BBE9; Thu, 17 Aug 2023 11:18:27 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id E06C927BBE2 for ; Thu, 17 Aug 2023 11:18:26 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qWa4u-00069d-LG; Thu, 17 Aug 2023 06:18:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWa4s-00068j-N4 for guix-patches@gnu.org; Thu, 17 Aug 2023 06:18:06 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qWa4r-0003Sv-KS; Thu, 17 Aug 2023 06:18:05 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qWa4o-0001Ce-6f; Thu, 17 Aug 2023 06:18:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65229] [PATCH v2 1/2] ui: 'load*' accepts /dev/fd/N files pointing to a pipe. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Thu, 17 Aug 2023 10:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65229 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 65229@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 65229-submit@debbugs.gnu.org id=B65229.16922674774607 (code B ref 65229); Thu, 17 Aug 2023 10:18:02 +0000 Received: (at 65229) by debbugs.gnu.org; 17 Aug 2023 10:17:57 +0000 Received: from localhost ([127.0.0.1]:42813 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qWa4j-0001CE-3d for submit@debbugs.gnu.org; Thu, 17 Aug 2023 06:17:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40762) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qWa4b-0001Bk-Oi for 65229@debbugs.gnu.org; Thu, 17 Aug 2023 06:17:51 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qWa4V-0003Hj-Lw; Thu, 17 Aug 2023 06:17:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=Mnxw26De5vdZVXKFi5nZ2Y/yB10IKQ3L9iKRyr0hvjc=; b=Y7Uk123DxmujXGeiYXws 1JpDz9dYSh2F5DCqOhprbNqCrcUMCKAUbVVWTLwsSjWKfnMDk+E4zSH7QvgqoQtdXL7ex5Rm49T3k skyXf+snA8nfDZ2R7rMNvRhg0loMsd5u5XWOcHE4oYSn61qvRfV8NcMDDOiOOhmkyl/HuCo7NW/QQ oa3ig4tv0oGaDQwVK0O9VDxp6LtTX7kZZThANSXpKqwk6RBh01tmfW85P+kAidGkYHw8AxTSaferZ kgnSTrcNMixlpn/6ImBuSjHgp9fkQvk0h/cwzU+fE223o5za1E05hlJOCxVc4j2Q/Zj7mh2fM3DoW 9sI7ncPhf/f+aQ==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Thu, 17 Aug 2023 12:17:28 +0200 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: <875y5eyrl0.fsf@gnu.org> References: <875y5eyrl0.fsf@gnu.org> MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches From: Ludovic Courtès 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(-) base-commit: 1bd44b425b79e9da160b33a9b19d01973b44772e 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 +# Copyright © 2012-2014, 2016-2023 Ludovic Courtès # Copyright © 2020 Marius Bakke # Copyright © 2021 Chris Marusich # @@ -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