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 sFXGLqfIO2bfEQAAqHPOHw:P1 (envelope-from ) for ; Wed, 08 May 2024 20:47:03 +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 sFXGLqfIO2bfEQAAqHPOHw (envelope-from ) for ; Wed, 08 May 2024 20:47:03 +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=K0FFA6cd; 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=1715194023; 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=CiYlEJ/H4QYHk7HWgrcW2Etoh/nXnyCS7YNDqJKXOlw=; b=jdLuCD9e45m4FZenDNjSSH7mvs4i1BDsGCJzvVhNvWsz+XHFp3G4UthbE93qKyloozV8ZJ 4QF+2NSD857tjWF9JCW35ombUrjXbIuq5DlOgEYq5mJfQNGq7RoWzwq68X79kKorosV71Y GqJWzI+pxDzF/ZAkrvpW7zMk1n9fAwRNSdTlue9iX7seW37TM068L6QGHdyCmdRlPKhVV3 hmYYF/G5p7wVwbZxvqeVSoPclyQ38vYLdkMcQ+67/hxSeamENZSSnNv0H9+n3brO/GWSOb 4MCmLbHzcLl5CY7wmnIcCybjmbjLT1VTz/efw34tjrf5CjLIzqLHl0UtLYMRdA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none ("invalid DKIM record") header.d=freakingpenguin.com header.s=x header.b=K0FFA6cd; 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=1715194023; a=rsa-sha256; cv=none; b=Va1wXqG9hI1z64Rgb65fvZKKoKb7xX+2Vpf2gQJBmuVkftVtcWjMgiYwEEkB2qTG8Sz6gP YZx0k8zHygZtAmIOaiA1tfu0cYMgB2ivy/tZ0B7TpW4gidgpA5KDUu5CN9d7hBfbcor7IZ 8mASXzqCS1M+WHBU6nomR95PbowCpQ7KWkkC7/fY4jU78rkYQNAGdtigRzrJa3wPFsl+ZR jsKDkFnHUqreO1rsW/RnDRAgmNT4/KIFw14sYmSYRUjWq+O5/8A37BHUrrghhh3fuLYdAM Rsp+vwyY1fuIENBEUg6avqzyIbxYylB5JjegNs5mB9vDeow+zWsWFbbdIObtAg== 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 8482C79B4C for ; Wed, 8 May 2024 20:47:03 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s4mJQ-0004tz-O6; Wed, 08 May 2024 14:46: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 1s4mJN-0004tL-GU for guix-patches@gnu.org; Wed, 08 May 2024 14:46:41 -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 1s4mJM-0000m2-OI; Wed, 08 May 2024 14:46:40 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1s4mJi-0001eG-FX; Wed, 08 May 2024 14:47:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#70829] [PATCH v3 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:47: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.17151940026320 (code B ref 70829); Wed, 08 May 2024 18:47:02 +0000 Received: (at 70829) by debbugs.gnu.org; 8 May 2024 18:46:42 +0000 Received: from localhost ([127.0.0.1]:50277 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s4mJN-0001ds-Sc for submit@debbugs.gnu.org; Wed, 08 May 2024 14:46:42 -0400 Received: from mail-108-mta138.mxroute.com ([136.175.108.138]:41131) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1s4mJL-0001dm-R1 for 70829@debbugs.gnu.org; Wed, 08 May 2024 14:46:40 -0400 Received: from filter006.mxroute.com ([136.175.111.2] filter006.mxroute.com) (Authenticated sender: mN4UYu2MZsgR) by mail-108-mta138.mxroute.com (ZoneMTA) with ESMTPSA id 18f598702d40008ca2.001 for <70829@debbugs.gnu.org> (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Wed, 08 May 2024 18:46:11 +0000 X-Zone-Loop: bd6359acbfbc1befa9e89aeeb0241c2d128fedf4853d 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=CiYlEJ/H4QYHk7HWgrcW2Etoh/nXnyCS7YNDqJKXOlw=; b=K0FFA6cd7DXFw/I8oUkivu1GcE pM0s43Toqh1ACFinGIAwd05CaYT9nKoEaU1+mqcHwrMHGSCfHJCQOFmPWRowue/Mn112XGx0MZE1B ta6mD9yyATdDx43pROoM1oyQS6pNQO8qq7EGlrZWzAdVkGigMA5OQ8d4nPf+GvB2MH/TbZroSOcY7 hGu7au7zNxIX0E6aWAhCnEH/RPLIydxLTMRTvLI9fu0WytxxhNwCK7fRAoKGTUPLl5bt9cPOrO1Xb pui/Tj/+9n69gWd4yvc1vzl/FRj+ID47U7m2WTOvj+a8Vmll+3b6BmSOUAAsuIWT/H76HzobF8kmS rM8qLSzQ==; From: Richard Sent Date: Wed, 8 May 2024 14:45:07 -0400 Message-ID: <35b31773ca90745dbba436e3436d7813704a86aa.1715193907.git.richard@freakingpenguin.com> In-Reply-To: <23ca145e6087ea18559fdd71d0c92db572abc8a3.1715193907.git.richard@freakingpenguin.com> References: <23ca145e6087ea18559fdd71d0c92db572abc8a3.1715193907.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: 8482C79B4C X-Migadu-Scanner: mx10.migadu.com X-Migadu-Spam-Score: -3.39 X-TUID: MHA3OcmlHHYN 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. Change-Id: Ibc24239ad201797c151b01e0b4fec43b07b4a02f --- Typo in the previous commit message. Sorry for the noise! 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