From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id 4HfqEt3FO2b6AQEAqHPOHw:P1 (envelope-from ) for ; Wed, 08 May 2024 20:35:09 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id 4HfqEt3FO2b6AQEAqHPOHw (envelope-from ) for ; Wed, 08 May 2024 20:35:09 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=freakingpenguin.com header.s=x header.b="Z/CWiVUa"; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1715193309; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=7k94FEsj0CXh+Ie+kUgRyejF/HnqZnGu1HS2+wB8DFs=; b=fVAQ2UNTO8otu6Jt6kdQIjQ/ZfHlyEQhMXFB0d54sKdvvdCxGiDMf9dJIfHlP4EBLutxxy T4VACG2jsOLt7AvIGnRZUaHikEW6GnY26U1pgnj2dStII2mIrOnGQZoAYt/d4CqAY/LqPr tnskU0lvkSy9YrszAzUVcj5BPrPmFbpiy+Pm8uPbxxzOSDcwo9wVynjtqHQk3xXeuZxUYj uPIvvPVpeaPqDM/Jy0UgHwcLPwKhpm9MjpR464uPn5iQxIuC40lXe2ozLPc8/nPL0cHJUc Y7jgfgc+3rw0x6PFHEGFxMCBhpa6NFUCLXsnGuqjMO4Ap0Mug1r5ABzsMW+dxQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=freakingpenguin.com header.s=x header.b="Z/CWiVUa"; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=none ARC-Seal: i=1; s=key1; d=yhetil.org; t=1715193309; a=rsa-sha256; cv=none; b=n/FdSLqktus78+poJOwt8IjbVW44S6cjEK3bRZY0pUvF6m/6gmKw4StkaaXcv6LdVtUI2j bQ0zJTWcXJsMeeSBgAuZ0qlnqR4ENQKrPFc1k9LbeB4STJN61jNkVCOkxVuDHAxeUbxPVG a1wOqI7xK1yMCRCToYlOd+Sqdex+3T/m95GAwj3zW6Q1Bhv0eZnDpT7oancgC6MTPGONOc 3d/Vfsx0SvgO8bZ4c35iKwSvrD/Q+W+E2cXzMAhtKbwPTKjTeTAYEG4m3pyYUumb65Myjh d9vCkbWyPSxvGbWSrWGRRX6Zc14Bvo0PisZUav9v0yLULR47C9tSotDBTo4CUA== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id DD034791E6 for ; Wed, 8 May 2024 20:35:08 +0200 (CEST) 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 Content-Transfer-Encoding: 8bit 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+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Spam-Score: -3.39 X-Migadu-Queue-Id: DD034791E6 X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -3.39 X-TUID: t/gUh2ulPf86 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))) -- 2.41.0