From patchwork Tue Mar 18 14:26:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hilton Chain X-Patchwork-Id: 40340 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 D51E227BBE9; Tue, 18 Mar 2025 14:30:58 +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 EAA8B27BBE2 for ; Tue, 18 Mar 2025 14:30:57 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tuXxv-0006cm-EK; Tue, 18 Mar 2025 10:30:47 -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 1tuXxQ-0006HX-MU for guix-patches@gnu.org; Tue, 18 Mar 2025 10:30:16 -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 1tuXxQ-0001w8-4H; Tue, 18 Mar 2025 10:30:16 -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=NMsWPuSK7R0bwF3Y+WIV3Ki4xiumhf538WeEtRM3dR4=; b=KYOZl6jpkrAtYwZZiMB/01sF5Ey2njnf7kMRQa3HYWwKOLG8LAmr0wdZ/cFxQo/K3bghTzgUDrq5IQnolE006kQQfZ6HkPyUwl9EeRs7yJUbJlTX3d9TAx/P3PJq83D/GitYNL9fNefx5J30a5KpT79GrVW2cv/nGC6sVE4kEkyyPH5X8eJh+aELd7ER4dB+ExVroKYlqPcg8FFh3CnNBNomEzmuNNcsdPMVEZg4ZZxWeNX+V4gpUZdnGBRSUCJBIad2PYVnTkW6PvuS4XK5HuJbhQ5R5Z8gvgW9jgAtCPdoCvi9JM20wRNLIrfjv239qMmwjPVJmsEcRmAVNu/0PQ==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tuXxL-0004tg-EB; Tue, 18 Mar 2025 10:30:11 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77093] [PATCH rust-team v2 16/17] import: crate: Add =?utf-8?b?4oCYLS1sb2NrZmlsZeKAmQ==?= option. Resent-From: Hilton Chain Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, divya@subvertising.org, efraim@flashner.co.il, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, maxim.cournoyer@gmail.com, zimon.toutoune@gmail.com, steve@futurile.net, me@tobias.gr, guix-patches@gnu.org Resent-Date: Tue, 18 Mar 2025 14:30:11 +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 , Efraim Flashner , Christopher Baines , Divya Ranjan Pattanaik , Efraim Flashner , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Maxim Cournoyer , Simon Tournier , Steve George , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Divya Ranjan Pattanaik , Efraim Flashner , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Maxim Cournoyer , Simon Tournier , Steve George , Tobias Geerinckx-Rice Received: via spool by 77093-submit@debbugs.gnu.org id=B77093.174230816918333 (code B ref 77093); Tue, 18 Mar 2025 14:30:11 +0000 Received: (at 77093) by debbugs.gnu.org; 18 Mar 2025 14:29:29 +0000 Received: from localhost ([127.0.0.1]:41740 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tuXwa-0004kq-1J for submit@debbugs.gnu.org; Tue, 18 Mar 2025 10:29:29 -0400 Received: from mx.boiledscript.com ([2a01:4f8:10b:392::42]:58320) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tuXvL-0004Y3-OA for 77093@debbugs.gnu.org; Tue, 18 Mar 2025 10:28:11 -0400 From: Hilton Chain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ultrarare.space; s=mail; t=1742308086; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tLsvHH8VgEZ9trUTlGPnGfx4OlFJVsZlzG2s3udRpug=; b=S7EPp0En2htH14PODV0zkTTVrbP8jeAZxviPL8WyrXGew/Ol1wpvgAO06I2sXkmODyGshs ojuVKPJPslqKL/tA2ZmijeboTKvwXBICSgrMnCQWplQOXSG6VTuTgZlnWk7SOQaFkJ5oj4 FmPB0/IQnn8ns9WsBeSEYwNrNWkSofGX/rU7Yt03q2ycr6wcCCn+UjY+09z9aymqpwtDWT gHAcQ/vSFt1M2T1vVMSu1eDCzR+00+ka4rKmhrzasDD1zarkZy++XzBK6lyOuPhAp68NJt PA32O4aJWlxx3gjkQPsvjSGYrwuvMgkj0pL5j4g0Z+mC2PlmtCnPfbOq+HtW5Q== Date: Tue, 18 Mar 2025 22:26:59 +0800 Message-ID: <2cdc1f3f422de5c16aa0b653d4a740867a4e2cee.1742306960.git.hako@ultrarare.space> In-Reply-To: References: MIME-Version: 1.0 X-MS-Reactions: disallow 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/scripts/import/crate.scm (%options): Add ‘--lockfile’ option. * guix/scripts/import/crate.scm (show-help): Add it. (guix-import-crate): Use it. * doc/guix.texi (Invoking guix import): Document it. * tests/crate.scm (temp-file): New variable. ("crate-lockfile-import"): New test. Change-Id: I291478e04adf9f2df0bf216425a5e8aeba0bedd9 --- doc/guix.texi | 14 ++++++ guix/scripts/import/crate.scm | 58 +++++++++++++++++++---- tests/crate.scm | 88 +++++++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 10 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 7fa986b4b9..218c2ba630 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -14703,6 +14703,20 @@ Invoking guix import If a crate dependency is not (yet) packaged, make the corresponding input in @code{#:cargo-inputs} or @code{#:cargo-development-inputs} into a comment. +@item --lockfile=@var{file} +@itemx -f @var{file} +When @option{--lockfile} is specified, the importer will ignore other options +and won't output package definitions, instead generating source definitions for +all dependencies in @var{file}, a @file{Cargo.lock} file. For example: + +@example +guix import crate --lockfile=/path/to/Cargo.lock my-package +@end example + +generates sources from @file{/path/to/Cargo.lock} and a list +@code{my-package-cargo-inputs} referencing these sources. The generated list is +intended for the package's @code{inputs}, replacing @code{#:cargo-inputs} and +@code{#:cargo-development-inputs}. @end table @item elm diff --git a/guix/scripts/import/crate.scm b/guix/scripts/import/crate.scm index 723cbb3665..3b536e135a 100644 --- a/guix/scripts/import/crate.scm +++ b/guix/scripts/import/crate.scm @@ -25,11 +25,13 @@ (define-module (guix scripts import crate) #:use-module (guix ui) #:use-module (guix utils) + #:use-module (guix read-print) #:use-module (guix scripts) #:use-module (guix import crate) #:use-module (guix scripts import) #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) + #:use-module (srfi srfi-26) #:use-module (srfi srfi-37) #:use-module (ice-9 match) #:use-module (ice-9 format) @@ -60,6 +62,9 @@ (define (show-help) sufficient package exists for it")) (newline) (display (G_ " + -f, --lockfile=FILE import dependencies from FILE, a 'Cargo.lock' file")) + (newline) + (display (G_ " -h, --help display this help and exit")) (display (G_ " -V, --version display version information and exit")) @@ -87,6 +92,9 @@ (define %options (option '("mark-missing") #f #f (lambda (opt name arg result) (alist-cons 'mark-missing #t result))) + (option '(#\f "lockfile") #f #t + (lambda (opt name arg result) + (alist-cons 'lockfile arg result))) %standard-import-options)) @@ -101,6 +109,8 @@ (define (guix-import-crate . args) #:build-options? #f)) (let* ((opts (parse-options)) + (lockfile (assoc-ref opts 'lockfile)) + (file-to-insert (assoc-ref opts 'file-to-insert)) (args (filter-map (match-lambda (('argument . value) value) @@ -111,16 +121,44 @@ (define (guix-import-crate . args) (define-values (name version) (package-name->name+version spec)) - (match (if (assoc-ref opts 'recursive) - (crate-recursive-import - name #:version version - #:recursive-dev-dependencies? - (assoc-ref opts 'recursive-dev-dependencies) - #:allow-yanked? (assoc-ref opts 'allow-yanked)) - (crate->guix-package - name #:version version #:include-dev-deps? #t - #:allow-yanked? (assoc-ref opts 'allow-yanked) - #:mark-missing? (assoc-ref opts 'mark-missing))) + (match (cond + ((and=> lockfile + (lambda (file) + (or (file-exists? file) + (leave (G_ "file '~a' does not exist~%") file)))) + (let-values (((crate-definitions input-list) + (cargo-lock->definitions lockfile name))) + (if file-to-insert + ;; Adjusted from ‘--insert’ option of guix-import. + (let ((term (second input-list))) + (begin + ;; Remove existing input list definition. + (and=> (find-definition-location file-to-insert term) + delete-expression) + ;; Insert input list alphabetically. + (or (and=> (find-definition-insertion-location + file-to-insert term) + (cut insert-expression <> input-list)) + (let ((port (open-file file-to-insert "a"))) + (newline port) + (pretty-print-with-comments port input-list) + (newline port) + (newline port) + (close-port port)))) + crate-definitions) + `(,@crate-definitions + ,input-list)))) + ((assoc-ref opts 'recursive) + (crate-recursive-import + name #:version version + #:recursive-dev-dependencies? + (assoc-ref opts 'recursive-dev-dependencies) + #:allow-yanked? (assoc-ref opts 'allow-yanked))) + (else + (crate->guix-package + name #:version version #:include-dev-deps? #t + #:allow-yanked? (assoc-ref opts 'allow-yanked) + #:mark-missing? (assoc-ref opts 'mark-missing)))) ((or #f '()) (leave (G_ "failed to download meta-data for package '~a'~%") (if version diff --git a/tests/crate.scm b/tests/crate.scm index d0dc779cd2..9b7066c3b1 100644 --- a/tests/crate.scm +++ b/tests/crate.scm @@ -34,6 +34,7 @@ (define-module (test-crate) #:use-module (gnu packages) #:use-module (ice-9 iconv) #:use-module (ice-9 match) + #:use-module (srfi srfi-11) #:use-module (srfi srfi-64)) @@ -476,6 +477,9 @@ (define rust-leaf-bob-3.0.2-yanked (description #f) (license #f))) +(define temp-file + (string-append "t-crate-" (number->string (getpid)))) + (test-begin "crate") @@ -1178,4 +1182,88 @@ (define rust-leaf-bob-3.0.2-yanked (x (pk 'fail (pretty-print-with-comments (current-output-port) x) #f))))) + +(test-assert "crate-lockfile-import" + (begin + (call-with-output-file temp-file + (lambda (port) + (display "\ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = \"adler2\" +version = \"2.0.0\" +source = \"registry+https://github.com/rust-lang/crates.io-index\" +checksum = \"512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627\" + +[[package]] +name = \"aho-corasick\" +version = \"1.1.3\" +source = \"registry+https://github.com/rust-lang/crates.io-index\" +checksum = \"8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916\" +dependencies = [ + \"memchr\", +] + +[[package]] +name = \"smithay\" +version = \"0.4.0\" +source = \"git+https://github.com/Smithay/smithay.git?rev=\ +0cd3345c59f7cb139521f267956a1a4e33248393#\ +0cd3345c59f7cb139521f267956a1a4e33248393\" +dependencies = [ + \"appendlist\", +] + +[[package]] +name = \"test\" +version = \"25.2.0\"\n" port))) + (mock + ((guix scripts download) guix-download + (lambda _ + (format #t "~a~%~a~%" + "/gnu/store/in056fyrz6nvy3jpxrxglgj30g0lwniv-smithay-0cd3345" + "191h87bpzg0l1ihfb4hmx00b86pfb5mwwc6s8i49al0vigc14l37"))) + (let-values + (((crates-definitions input-list) + (cargo-lock->definitions temp-file "test"))) + (and + (match crates-definitions + (((define 'rust-adler2-2.0.0 + (crate-source + "adler2" "2.0.0" + "09r6drylvgy8vv8k20lnbvwq8gp09h7smfn6h1rxsy15pgh629si")) + (define 'rust-aho-corasick-1.1.3 + (crate-source + "aho-corasick" "1.1.3" + "05mrpkvdgp5d20y2p989f187ry9diliijgwrs254fs9s1m1x6q4f")) + (define 'rust-smithay-0.4.0.0cd3345 + ($ + ";; TODO: Define standalone package if this is a workspace.\n" + #f) + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/Smithay/smithay.git") + (commit "0cd3345c59f7cb139521f267956a1a4e33248393"))) + (file-name (git-file-name "rust-smithay" "0.4.0.0cd3345")) + (sha256 + (base32 + "191h87bpzg0l1ihfb4hmx00b86pfb5mwwc6s8i49al0vigc14l37"))))) + #t) + (x + (pk 'fail (pretty-print-with-comments (current-output-port) x) #f))) + (match input-list + ((define-public 'test-cargo-inputs + (list rust-adler2-2.0.0 + rust-aho-corasick-1.1.3 + rust-smithay-0.4.0.0cd3345)) + #t) + (x + (pk 'fail x #f)))))))) + (test-end "crate") + +(false-if-exception (delete-file temp-file))