From patchwork Sun Mar 23 07:28:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Hilton Chain X-Patchwork-Id: 40716 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 5E82A27BBEA; Sun, 23 Mar 2025 07:31:33 +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 A846C27BBE2 for ; Sun, 23 Mar 2025 07:31:32 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1twFn5-0001cJ-57; Sun, 23 Mar 2025 03:30:39 -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 1twFmx-0001XA-2X for guix-patches@gnu.org; Sun, 23 Mar 2025 03:30:36 -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 1twFmw-00007L-FC; Sun, 23 Mar 2025 03:30: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=NCZbRfIjbdQsYRHffQ3JwLPvp0oN3GvJjdKWqctYL4Q=; b=jQFAe0qzHcw9VRxffBNuS5ZNea6JeWeO5umbi7pPp86lbVjY4SOncfbbbGKSsBkhBTcuuNVJhJppRZd0kw+J3KAZzdd07jNHpW+Mus1ZAnYSutsAXlVtuW1eP8crcqPYpcc9OWNWfiUsyAR4amHFZPWnN5TGyRAl04UQvC7+JSlO22dCJ24INRj2nO2RxEcL++GkipSljqTnBCPV42CEKDs3RcGD6z0dv3DU3ENnMLOL8zr9rduOrQgrxBfIBr3vl4P21T4zqzzrpn+iRUMVx2b/w/ObEJIMGiACew5HZp6MyTKTsevxehNwuDZSZyrrmGrsWQ9ZijQ0kGlegJrQ9w==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1twFmu-0004Sg-Sg; Sun, 23 Mar 2025 03:30:28 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77093] [PATCH rust-team v3 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: Sun, 23 Mar 2025 07:30:28 +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 , 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.174271501116701 (code B ref 77093); Sun, 23 Mar 2025 07:30:28 +0000 Received: (at 77093) by debbugs.gnu.org; 23 Mar 2025 07:30:11 +0000 Received: from localhost ([127.0.0.1]:47368 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1twFma-0004Jn-Da for submit@debbugs.gnu.org; Sun, 23 Mar 2025 03:30:11 -0400 Received: from mx.boiledscript.com ([88.99.243.112]:40062) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1twFmI-0004EA-2l for 77093@debbugs.gnu.org; Sun, 23 Mar 2025 03:29:50 -0400 From: Hilton Chain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ultrarare.space; s=mail; t=1742714989; 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=sLJzYPGfO+QkRVtxgTvXJbYwUKaAeoBjRxGqIariPi0=; b=R6IyhD+OlTa8VCB2/0Pzzddok9Rt6Z7FtSSrY9zHAMtfhWdoVmxpm8QIdK9ibN/AnSSc2m NikQtlly/ro2mtdvRe3719bSSGGW1NqIF8UTz0XMaNcVIJjuGVSUELTRCZLbMHbtFNtTT+ NHuUjg5QgVH9mchnaRYyi6CNiHoTJI9CuT8tWSS5rCy3L+WSdUMbn7g7zgUosgBP9PbfVP niWFsIbe/UujIHy8fYLzsKlLJR6BwSyHyBPF7j7DSZBJgUUnSxHQwHqsEKceGs2TMruVZ6 38X1pswhScvVMc3FSp3Blyk/X2rw6y4DWTVVurGTkTNrjeZIUp6T+e2ngbW9/g== Date: Sun, 23 Mar 2025 15:28:38 +0800 Message-ID: <81adafb3ac10a3b522c2e1949a91351f34216a9e.1742713356.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))