From patchwork Fri Aug 11 15:34:19 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: 52746 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 2587227BBE9; Fri, 11 Aug 2023 16:35:17 +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 4168127BBE2 for ; Fri, 11 Aug 2023 16:35:16 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qUUAM-0006MQ-3U; Fri, 11 Aug 2023 11:35:06 -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 1qUUAK-0006MA-3M for guix-patches@gnu.org; Fri, 11 Aug 2023 11:35:04 -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 1qUUAJ-00031W-Qh; Fri, 11 Aug 2023 11:35:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qUUAI-0002qr-Ac; Fri, 11 Aug 2023 11:35:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#65229] [PATCH 2/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: mail@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: Fri, 11 Aug 2023 15:35: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: maurice.bremond@inria.fr, 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.169176809210937 (code B ref 65229); Fri, 11 Aug 2023 15:35:02 +0000 Received: (at 65229) by debbugs.gnu.org; 11 Aug 2023 15:34:52 +0000 Received: from localhost ([127.0.0.1]:47803 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUUA8-0002qK-5p for submit@debbugs.gnu.org; Fri, 11 Aug 2023 11:34:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54552) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUUA4-0002pr-DZ for 65229@debbugs.gnu.org; Fri, 11 Aug 2023 11:34:49 -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 1qUU9z-0002oU-6y; Fri, 11 Aug 2023 11:34: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=4+nfJAjFTaMoKMhiD+s5D9q7E4G2OJtv2W3ZoJCLMqw=; b=mGKDNRB5Axm9/93TJXiK q8WhVjGVmaKt5T02oq0sPAei1rOOvUx5TeQsztOwwWTTJEy9+xSPqX+4wZo0dCFSx3GmYglL2+Sgj CC0tvALkm0/fyXVL0fPb99zymnEj/O5yJXjrD0iDk22bfJS5t51S0bG0Vv6OmXS6RXzyeiSEKFjxP VRm1kov3X+3V6z3Lm5IKk2IGSxA/YKUpl/pwFY9IviLgwrVl7AXY8AS0zx5ZS4qbSy3dkfHRhM22l iwQW25veJOcvZIkAOwngAy/BHpcmzoNDLhckud587vbTVZcUKtcGRwQT7ULFgXTLcEDJ/8QIPP/0D Rf3Y9qG2VLVGRA==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Fri, 11 Aug 2023 17:34:19 +0200 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: 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(-) 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