From patchwork Tue Mar 18 07:24:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hilton Chain X-Patchwork-Id: 40320 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 29CC427BBEA; Tue, 18 Mar 2025 07:28:37 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,FROM_SUSPICIOUS_NTLD,MAILING_LIST_MULTI, PDS_OTHER_BAD_TLD,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE,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 92E7827BBE2 for ; Tue, 18 Mar 2025 07:28:36 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tuRNK-0008EI-HG; Tue, 18 Mar 2025 03:28:35 -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 1tuRML-0007er-BQ for guix-patches@gnu.org; Tue, 18 Mar 2025 03:27:37 -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 1tuRM4-0001Uh-3F; Tue, 18 Mar 2025 03:27:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=M8h4BLqf5Sizq/UMmmhN+z7UiKyrXITYFZKJnhlvF90=; b=jSieWWlGR7P8EcB5Cp/gKQGUmJB2lVZgAWNenL9FQgmMbTQEGilddMec6aLtro31s+11PcoDo59HED+AbvUrVyovbLAFVYPDsD82kArgkFBTt1CgUXEUp/A1/ATJUNMn3V3Igxj61FnuPRZT+YzMErVz7QQtVw0MHx5QYzVRjmPHW1KbViYZczbapgTXMZoP+TwTKxwYq6UM1N8TvsAQhGzrVitcvWrB2WbVQIVdY1gv3R7iSIivJTtgXueOmGDjFpJb1xMr1Cki/OyNX9bsnzOkM1teXRLONyE3IhVpsMFnUVAWF9mQmVNAq5KYVBpVzruTvSJX/6a0PkrkJzQb0Q==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tuRLz-0004pm-3H; Tue, 18 Mar 2025 03:27:11 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77093] [PATCH rust-team 11/18] scripts: import: Support expressions defined by 'define. Resent-From: Hilton Chain Original-Sender: "Debbugs-submit" Resent-CC: hako@ultrarare.space, guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Tue, 18 Mar 2025 07:27:10 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 77093 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 77093@debbugs.gnu.org Cc: Hilton Chain , Hilton Chain , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Hilton Chain , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 77093-submit@debbugs.gnu.org id=B77093.174228281018301 (code B ref 77093); Tue, 18 Mar 2025 07:27:10 +0000 Received: (at 77093) by debbugs.gnu.org; 18 Mar 2025 07:26:50 +0000 Received: from localhost ([127.0.0.1]:35929 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tuRLc-0004kp-HZ for submit@debbugs.gnu.org; Tue, 18 Mar 2025 03:26:50 -0400 Received: from mx.boiledscript.com ([2a01:4f8:10b:392::42]:49398) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tuRL0-0004fO-Cl for 77093@debbugs.gnu.org; Tue, 18 Mar 2025 03:26:10 -0400 From: Hilton Chain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ultrarare.space; s=mail; t=1742282769; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+/srC+Epo38ycQfk6D22nsIOCLinapf8wmQlHm5t+vg=; b=UmtSNoWHFTnrTp24la7RmU9XCpsJiYfTB13simxF3whRInNcCy063jnijP9R53SaFlQ43h BX5Y3xW1xFSt1wPTDQkkMHxWMawC79D1KhYfZymv5v+ui0ilAGkgJkudwU0V29Ftg8aqAI 0+FiTBO8ZmTtVxiWR5tI1DZ4dB2yzr2WiUm8RQQyyex0Lvz/Wwhavvlyi05Z7SbBJGvCBI OJ1oYW+iajrJTZfbCZj4Jv2KMZdqXv3MQu/nimPSszdq2wHxlt9GwJqao8b1+bsmc7qNgE yufa+KHuCrO5hbxq1hwqr4e20EaoyOgcdQaW2BuxtgN2yTRkWT6WCkABj+MXyg== Date: Tue, 18 Mar 2025 15:24:24 +0800 Message-ID: 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 * guix/utils.scm (find-definition-location): New procedure. (find-definition-insertion-location): Define with it. * guix/scripts/import.scm (import-as-definitions, guix-import): Support expressions defined by 'define. Change-Id: I03118e1a3372028b4f0530964aba871b4a1a4d25 --- guix/scripts/import.scm | 20 +++++++++++++++----- guix/utils.scm | 27 +++++++++++++++++++-------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm index 58a84d0db7..aaa3d26673 100644 --- a/guix/scripts/import.scm +++ b/guix/scripts/import.scm @@ -30,6 +30,7 @@ (define-module (guix scripts import) #:use-module (guix read-print) #:use-module (guix utils) #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) #:use-module (ice-9 format) #:use-module (ice-9 match) #:export (%standard-import-options @@ -83,7 +84,8 @@ (define (import-as-definitions importer args proc) ((and expr (or ('package _ ...) ('let _ ...))) (proc (package->definition expr))) - ((and expr ('define-public _ ...)) + ((and expr (or ('define-public _ ...) + ('define _ ...))) (proc expr)) ((expressions ...) (for-each (lambda (expr) @@ -91,7 +93,8 @@ (define (import-as-definitions importer args proc) ((and expr (or ('package _ ...) ('let _ ...))) (proc (package->definition expr))) - ((and expr ('define-public _ ...)) + ((and expr (or ('define-public _ ...) + ('define _ ...))) (proc expr)))) expressions)) (x @@ -117,13 +120,20 @@ (define-command (guix-import . args) (show-version-and-exit "guix import")) ((or ("-i" file importer args ...) ("--insert" file importer args ...)) - (let ((find-and-insert + (let* ((definer? + (cut member + <> + `(,@(if (member importer '("crate")) + '(define) + '()) + define-public))) + (find-and-insert (lambda (expr) (match expr - (('define-public term _ ...) + (((? definer? definer) term _ ...) (let ((source-properties (find-definition-insertion-location - file term))) + file term #:definer definer))) (if source-properties (insert-expression source-properties expr) (let ((port (open-file file "a"))) diff --git a/guix/utils.scm b/guix/utils.scm index c7c23d9d5b..77ec6d992a 100644 --- a/guix/utils.scm +++ b/guix/utils.scm @@ -154,6 +154,7 @@ (define-module (guix utils) edit-expression delete-expression insert-expression + find-definition-location find-definition-insertion-location filtered-port @@ -520,24 +521,34 @@ (define (insert-expression source-properties expr) (string-append expr "\n\n" str)))) (edit-expression source-properties insert))) -(define (find-definition-insertion-location file term) - "Search in FILE for a top-level public definition whose defined term -alphabetically succeeds TERM. Return the location if found, or #f -otherwise." - (let ((search-term (symbol->string term))) +(define* (find-definition-location file term + #:key (definer 'define-public) + (pred string=)) + "Search in FILE for a top-level definition defined by DEFINER with defined +term comparing to TERM through PRED. Return the location if PRED returns #t, +or #f otherwise." + (let ((search-term (symbol->string term)) + (definer? (cut eq? definer <>))) (call-with-input-file file (lambda (port) (do ((syntax (read-syntax port) (read-syntax port))) ((match (syntax->datum syntax) - (('define-public current-term _ ...) - (string> (symbol->string current-term) - search-term)) + (((? definer?) current-term _ ...) + (pred (symbol->string current-term) + search-term)) ((? eof-object?) #t) (_ #f)) (and (not (eof-object? syntax)) (syntax-source syntax)))))))) +(define* (find-definition-insertion-location file term + #:key (definer 'define-public)) + "Search in FILE for a top-level definition defined by DEFINER with defined +term alphabetically succeeds TERM. Return the location if found, or #f +otherwise." + (find-definition-location file term #:definer definer #:pred string>)) + ;;; ;;; Keyword arguments.