From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:1008:1e59::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms1.migadu.com with LMTPS id 4FJ8FKVHXWaZEgAAA41jLg (envelope-from ) for ; Mon, 03 Jun 2024 06:33:41 +0200 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id eFY7D6VHXWZRsgAA62LTzQ (envelope-from ) for ; Mon, 03 Jun 2024 06:33:41 +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=MDeLS9DB; dmarc=none; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1717389221; 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=RL+BgNxFkKVki17qWWKWxXMBrPsVYqBtkc3Yqb/FMng=; b=s1xtsz8O8kaYgRYMdEar7rnFjgn/HkCpzu/ym7O2XPDjkY+hFk31mYnB9CQx12rp1HBfPZ 2qBJSkkoqqNa+r6VrZLWJtFilNZydSHV58cov/cSc47TIUVvsZTS6xCFRQXr0+us3O7tce AeMi1hIECTRw8Kqm4l1mnCn1eVekVw1S8VCsX2v5GmeGywXPtk2aZXCac6FTb3VTZIMW4n KhggovlrHiySs/Zo+ypcAjJLoyMVLEuVS6EVrA+TsmZWi27lBZyon92HO/mHqqi0SRKNUv GkrNWdhwhj/GPaTbm/c9XsHy8kRc8wzgU7ffsTvdUMsQzsBQ5Jyui1n1Q0g0/A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1717389221; a=rsa-sha256; cv=none; b=Wlwaynn/j2FncYXZxH12unj/KC3VPFIX61f9+Q7Q/TCE49qTPsJZNjgOmw0iVdDf4EtPI9 8vUvTIRnqxPYgcvJIwvLPdG1ZUpqKSTA56UKdxqq3NGqHYLhy+IMtWpO1JnUxAT4jMxyWl jt2WQzcNX/8xcx7grhGEHSV1V87Io9jmgJWKYHueB+ONxX2Lx/nMZQYVx9PyWq4IMjOluC w2XTpgBpYhLCP1VrKGYdiuCJI9SCW6zUcObq/8iPpTVtREw37/jAOlL3mhfA8pQ9Ry9fpD ctNLl/wunHfRTwms5Nv+eI1cabdZqYAg6uf4ar1VuMG9nOygiEP4w/XL2CL32g== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=freakingpenguin.com header.s=x header.b=MDeLS9DB; dmarc=none; 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" 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 CB57A67A9D for ; Mon, 03 Jun 2024 06:33:40 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sDy6q-0004Vh-Un; Sun, 02 Jun 2024 23:11:44 -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 1sDy6p-0004S9-3A for guix-patches@gnu.org; Sun, 02 Jun 2024 23:11:43 -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 1sDrTj-0005FH-GZ; Sun, 02 Jun 2024 16:06:55 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sDrTq-0002CO-G5; Sun, 02 Jun 2024 16:07:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70829] [PATCH v4] guix: gexp: Add assume-source-relative-file-name References: In-Reply-To: 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, matt@excalamus.com, maxim.cournoyer@gmail.com, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Sun, 02 Jun 2024 20:07: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 , Matthew Trzcinski , Maxim Cournoyer , 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 , Matthew Trzcinski , Maxim Cournoyer , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 70829-submit@debbugs.gnu.org id=B70829.17173587968369 (code B ref 70829); Sun, 02 Jun 2024 20:07:02 +0000 Received: (at 70829) by debbugs.gnu.org; 2 Jun 2024 20:06:36 +0000 Received: from localhost ([127.0.0.1]:36090 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sDrTP-0002Au-W7 for submit@debbugs.gnu.org; Sun, 02 Jun 2024 16:06:36 -0400 Received: from mail-108-mta127.mxroute.com ([136.175.108.127]:40317) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sDrTM-0002Aj-QX for 70829@debbugs.gnu.org; Sun, 02 Jun 2024 16:06:34 -0400 Received: from filter006.mxroute.com ([136.175.111.3] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta127.mxroute.com (ZoneMTA) with ESMTPSA id 18fda7cec1a000e2b6.001 for <70829@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Sun, 02 Jun 2024 19:46:11 +0000 X-Zone-Loop: 43f7dfd5ee862162ddf361359f6fb27405b976dc572f X-Originating-IP: [136.175.111.3] 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=RL+BgNxFkKVki17qWWKWxXMBrPsVYqBtkc3Yqb/FMng=; b=MDeLS9DBuJEhsH8rFcynZXmCaD 9rV/ZWCVKhoKeDEjgSlW9p8PqsMu3wxKtqwd0k1Jjy6pAVi8T+/rkcebr5FC2k4ctMxaDnrUENRrb ksx+Od5w3kTyRNTcb0Yqt1X0lFIg5/pDqIj2jTopAmG+zJNhZtYIyv1NInvgs7e/hg6/HreltES82 p0eL+XxDHA+DSjiGc8Y9sS45dvoRnbeqlHuiKIMKAUnbjTS5Or3sQu4loVroictLJHsO56kdCDG9b Tf3OUoMZnOlFn01qTYpGEV1Lq7M/Yxuv2Cq2pWcr51NsxEBfaTyn8IjvcyDfgFh1362CvnWS2PBnh h2BUtPmg==; From: Richard Sent Date: Sun, 2 Jun 2024 15:44:27 -0400 Message-ID: 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-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Spam-Score: -0.34 X-Spam-Score: -0.34 X-Migadu-Queue-Id: CB57A67A9D X-Migadu-Scanner: mx11.migadu.com X-TUID: MdHAiL3Fyaw5 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. --- Hi all, Since #70830 wound up being merged, I'm resubmitting this patch rebased on master and without the documentation for assume-valid-file-name. 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 8cc01b2e65..d291da4b98 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -12204,6 +12204,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))) base-commit: 2e53fa5346bf52f6d6d26e035bc905ebd410dabb -- 2.45.1