From patchwork Wed May 8 18:32:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sent X-Patchwork-Id: 27191 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 AEF6227BBEA; Wed, 8 May 2024 19:35:16 +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=ham 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 217D727BBE2 for ; Wed, 8 May 2024 19: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 1s4m7s-0001v4-FC; Wed, 08 May 2024 14:34:50 -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 1s4m7h-0001tA-1a for guix-patches@gnu.org; Wed, 08 May 2024 14:34:40 -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 1s4m7g-0005hg-Cf; Wed, 08 May 2024 14:34:36 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s4m85-0007DT-Kn; Wed, 08 May 2024 14:35:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70829] [PATCH v2 1/2] doc: Document assume-valid-file-name in local-file References: In-Reply-To: Resent-From: Richard Sent Original-Sender: "Debbugs-submit" Resent-CC: pelzflorian@pelzflorian.de, ludo@gnu.org, guix-patches@gnu.org Resent-Date: Wed, 08 May 2024 18:35:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70829 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 70829@debbugs.gnu.org Cc: Richard Sent , Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= X-Debbugs-Original-Xcc: Florian Pelz , Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 70829-submit@debbugs.gnu.org id=B70829.171519329327717 (code B ref 70829); Wed, 08 May 2024 18:35:01 +0000 Received: (at 70829) by debbugs.gnu.org; 8 May 2024 18:34:53 +0000 Received: from localhost ([127.0.0.1]:50200 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s4m7w-0007Cz-Jg for submit@debbugs.gnu.org; Wed, 08 May 2024 14:34:52 -0400 Received: from mail-108-mta133.mxroute.com ([136.175.108.133]:44309) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s4m7u-0007Ct-7y for 70829@debbugs.gnu.org; Wed, 08 May 2024 14:34:51 -0400 Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta133.mxroute.com (ZoneMTA) with ESMTPSA id 18f597c2efd0008ca2.001 for <70829@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 08 May 2024 18:34:21 +0000 X-Zone-Loop: 2f01149c2e27682e8851b09fc15998b3fa99407a80c4 X-Originating-IP: [136.175.111.2] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:MIME-Version: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=5EpOFjh9Kf5sg43uVarK9Xk/XGf8vhABgrttwJpMsW0=; b=T/7slP/5obo2b9l1zK3p6qzyPp L+b7l1cG7kSm8o9M6xTlINCEpddp726zwTF2ZUqXTtWTA22E7YMf35zT9pYlZsZAiWdve2U7MtM64 gOfWbWaEkwBzzJWl7vz5x9jIfqjQgJs6plffru2ozx6mzn58VSCPBA+LhMRT0hK4K8cQMPkggU19D IEFIRvVYZemEPFaHSRcw5RvzApEE+Ho2PD+TV7/yg+/8k3vwYvEsmBYQ5l6RErLFZYDxuA7lO4JBL 5TQQ0oKPJgN3U7t6256PvmHv3rTpcC0whUj02wVlfB8UmwBVxV66bHgHPODKOag8HDl5O4vCug2yG 2/MS0Now==; From: Richard Sent Date: Wed, 8 May 2024 14:32:46 -0400 Message-ID: <23ca145e6087ea18559fdd71d0c92db572abc8a3.1715193167.git.richard@freakingpenguin.com> MIME-Version: 1.0 X-Authenticated-Id: richard@freakingpenguin.com 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 doc/guix.texi (G-Expressions): Document the use of assume-valid-file-name with local-file. --- Missed a commit that my original revision depended on. I initially submitted that previous commit to https://qa.guix.gnu.org/issue/70830, but since both commits change the same guix.texi section on similar subject matter, I'm resubmitting as a series. doc/guix.texi | 12 ++++++++++++ 1 file changed, 12 insertions(+) base-commit: 7b7f299bb493e485c5534b8c554e51d4f3a8c026 diff --git a/doc/guix.texi b/doc/guix.texi index 1c1e0164e7..221db5c022 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -12154,6 +12154,18 @@ G-Expressions absolute file name and @var{stat} is the result of @code{lstat}; exclude entries for which @var{select?} does not return true. +@var{file} can be wrapped in the @code{assume-valid-file-name} syntactic +keyword. When this is done, there will not be a warning when +@code{local-file} is used with a non-literal path. The path is still +looked up relative to the current working directory at run time. +Wrapping is done like this: + +@lisp +(define alice-key-file-path "alice.pub") +;; ... +(local-file (assume-valid-file-name alice-key-file-path)) +@end lisp + This is the declarative counterpart of the @code{interned-file} monadic procedure (@pxref{The Store Monad, @code{interned-file}}). @end deffn From patchwork Wed May 8 18:32:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sent X-Patchwork-Id: 27190 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 17AFD27BBE9; Wed, 8 May 2024 19:35:10 +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 BF6F227BBE2 for ; Wed, 8 May 2024 19:35:08 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4m7u-0001wN-Eu; Wed, 08 May 2024 14:34:50 -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 1s4m7k-0001tk-Lo for guix-patches@gnu.org; Wed, 08 May 2024 14:34:42 -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 1s4m7k-0005jR-DC; Wed, 08 May 2024 14:34:40 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s4m86-0007Db-45; Wed, 08 May 2024 14:35:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70829] [PATCH v2 2/2] guix: gexp: Add assume-source-relative-file-name Resent-From: Richard Sent Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, pelzflorian@pelzflorian.de, 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: Wed, 08 May 2024 18:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 70829 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 70829@debbugs.gnu.org Cc: Richard Sent , Christopher Baines , Florian Pelz , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Florian Pelz , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 70829-submit@debbugs.gnu.org id=B70829.171519329827730 (code B ref 70829); Wed, 08 May 2024 18:35:02 +0000 Received: (at 70829) by debbugs.gnu.org; 8 May 2024 18:34:58 +0000 Received: from localhost ([127.0.0.1]:50203 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s4m82-0007DC-02 for submit@debbugs.gnu.org; Wed, 08 May 2024 14:34:58 -0400 Received: from mail-108-mta163.mxroute.com ([136.175.108.163]:36859) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s4m7z-0007D6-Bm for 70829@debbugs.gnu.org; Wed, 08 May 2024 14:34:56 -0400 Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta163.mxroute.com (ZoneMTA) with ESMTPSA id 18f597c3b120008ca2.001 for <70829@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 08 May 2024 18:34:24 +0000 X-Zone-Loop: f171d798167e38549921c283ece4aeda0178129c29ff X-Originating-IP: [136.175.111.2] DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=freakingpenguin.com; s=x; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7k94FEsj0CXh+Ie+kUgRyejF/HnqZnGu1HS2+wB8DFs=; b=Z/CWiVUaFrMr0zzZqQPEoqS94O d6auQWNle6/uhAdjIfZgn2QJUCj7Y2lRzLp3l4iOqGc+3A86BdFRBxJgTyQPcClgAyYE+xnjPCU1p BwDxQPdTxogBba/q9pc+2Jp2tKqw8NEoUlAPPndGPub40cVT7ZSjmjvzq4hwqhhb86gDKV7cHsl0W FUP6vteR5BAXLzyyN0u9P/WkgyPhKaii5Zwa8CSy8ZgCOh8L7v6TudZ8zQ0ZJ53ImBLgIl5udZMnd cUYPTFsEgbGXprLJRwQK0Pj8CpjeVcIFLF+EXgsTvAqfFl/eR/Q2l/0ntO6oBkGC7hFkRfXtnOKcP tixJB63A==; From: Richard Sent Date: Wed, 8 May 2024 14:32:47 -0400 Message-ID: <822a1c5009d33b5e994fac9e21f087cbb3255972.1715193167.git.richard@freakingpenguin.com> In-Reply-To: <23ca145e6087ea18559fdd71d0c92db572abc8a3.1715193167.git.richard@freakingpenguin.com> References: <23ca145e6087ea18559fdd71d0c92db572abc8a3.1715193167.git.richard@freakingpenguin.com> MIME-Version: 1.0 X-Authenticated-Id: richard@freakingpenguin.com 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 guix/gexp.scm (assume-source-relative-file-name): Create syntax rule (local-file): Use assume-source-relative-file-name to look up a non-literal file relative to the current source directory. doc/guix.texi (G-expressions): Document it. tests: gexp.scm: Test it. --- doc/guix.texi | 5 +++++ guix/gexp.scm | 15 ++++++++++++++- tests/gexp.scm | 6 ++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/doc/guix.texi b/doc/guix.texi index 221db5c022..1fc7be7cd8 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -12166,6 +12166,11 @@ G-Expressions (local-file (assume-valid-file-name alice-key-file-path)) @end lisp +@var{file} can be wrapped in the @code{assume-source-relative-file-name} +syntactic keyword. When this is done, the file name will be looked up +relative to the source file where it appears even when it is not a +string literal. + This is the declarative counterpart of the @code{interned-file} monadic procedure (@pxref{The Store Monad, @code{interned-file}}). @end deffn diff --git a/guix/gexp.scm b/guix/gexp.scm index 74b4c49f90..871e59cfdc 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm @@ -52,6 +52,7 @@ (define-module (guix gexp) gexp-input-native? assume-valid-file-name + assume-source-relative-file-name local-file local-file? local-file-file @@ -485,6 +486,12 @@ (define-syntax-rule (assume-valid-file-name file) warn about it." file) +(define-syntax-rule (assume-source-relative-file-name file) + "This is a syntactic keyword to tell 'local-file' that it can assume that +the given file is relative to the source directory, even if it's not a string +literal." + file) + (define-syntax local-file (lambda (s) "Return an object representing local file FILE to add to the store; this @@ -503,13 +510,19 @@ (define-syntax local-file This is the declarative counterpart of the 'interned-file' monadic procedure. It is implemented as a macro to capture the current source directory where it appears." - (syntax-case s (assume-valid-file-name) + (syntax-case s (assume-valid-file-name assume-source-relative-file-name) ((_ file rest ...) (string? (syntax->datum #'file)) ;; FILE is a literal, so resolve it relative to the source directory. #'(%local-file file (delay (absolute-file-name file (current-source-directory))) rest ...)) + ((_ (assume-source-relative-file-name file) rest ...) + ;; FILE is not a literal, but the user requested we look it up + ;; relative to the current source directory. + #'(%local-file file + (delay (absolute-file-name file (current-source-directory))) + rest ...)) ((_ (assume-valid-file-name file) rest ...) ;; FILE is not a literal, so resolve it relative to the current ;; directory. Since the user declared FILE is valid, do not pass diff --git a/tests/gexp.scm b/tests/gexp.scm index 905009caee..8774097bd0 100644 --- a/tests/gexp.scm +++ b/tests/gexp.scm @@ -244,6 +244,12 @@ (define %extension-package (let ((file (local-file (string-copy "../base32.scm")))) (local-file-absolute-file-name file))))) +(test-equal "local-file, non-literal source relative file name" + (current-filename) + (let ((file (local-file (assume-source-relative-file-name + (string-append "gexp" ".scm"))))) + (local-file-absolute-file-name file))) + (test-assert "local-file, relative file name, within gexp" (let* ((file (search-path %load-path "guix/base32.scm")) (interned (add-to-store %store "base32.scm" #f "sha256" file)))