import: crate: Stop importing dependencies from crates.io.

* guix/scripts/import/crate.scm (show-help, %options, guix-import-crate)
[--recursive, --recursive-dev-dependencies, --mark-missing]: Remove options.
* doc/guix.texi (Invoking guix import)[crate]: Adjust accordingly.
Mention packaging workflow.
* guix/import/crate.scm (make-crate-sexp): Don't use "rust-" prefix and semver
suffix for package name.
[#:cargo-inputs, #:cargo-development-inputs, #:build?]: Remove arguments.
(crate->guix-package)[#:include-dev-deps?, #:mark-missing?]: Remove arguments.
(<crate-dependency>): Remove data type.
(make-crate-dependency, crate-dependency?, json->crate-dependency)
(crate-version-dependencies, package-names->package-inputs)
(maybe-cargo-inputs, maybe-cargo-development-inputs, maybe-arguments)
(version->semver-prefix, find-package-version, crate-recursive-import): Remove
procedures.
* tests/crate.scm (test-foo-crate, test-bar-crate): Adjust for modified tests.
(test-foo-dependencies, test-bar-dependencies, test-root-crate)
(test-root-dependencies, test-intermediate-a-crate)
(test-intermediate-a-dependencies, test-intermediate-b-crate)
(test-intermediate-b-dependencies, test-intermediate-c-crate)
(test-intermediate-c-dependencies, test-leaf-alice-crate)
(test-leaf-alice-dependencies, test-leaf-bob-crate)
(test-leaf-bob-dependencies, rust-leaf-bob-3, rust-leaf-bob-3.0.2-yanked):
Remove variables.
("crate->guix-package yanked", "crate->guix-package only yanked available"): New
tests.
("crate->guix-package"): Adjust accordingly.
("crate->guix-package-marks-missing-packages", "crate-recursive-import")
("crate-recursive-import-honors-existing-packages")
("crate-import-only-yanked-available"): Remove tests.

Change-Id: Ib1d24511ed0ea1a2373f53de12e06afa7950a7d7
This commit is contained in:
Hilton Chain 2025-06-09 18:35:27 +08:00
parent efaa3e681e
commit 92d130e035
No known key found for this signature in database
GPG key ID: ACC66D09CA528292
4 changed files with 152 additions and 1332 deletions

View file

@ -49,18 +49,9 @@
(define (show-help)
(display (G_ "Usage: guix import crate PACKAGE-NAME
Import and convert the crates.io package for PACKAGE-NAME.\n"))
(display (G_ "
-r, --recursive import packages recursively"))
(display (G_ "
--recursive-dev-dependencies
include dev-dependencies recursively"))
(newline)
(display (G_ "
--allow-yanked allow importing yanked crates if no alternative
satisfying the version requirement is found"))
(display (G_ "
--mark-missing comment out the desired dependency if no
sufficient package exists for it"))
(newline)
(display (G_ "
-f, --lockfile=FILE import dependencies from FILE, a 'Cargo.lock' file"))
@ -81,18 +72,9 @@ Import and convert the crates.io package for PACKAGE-NAME.\n"))
(option '(#\V "version") #f #f
(lambda args
(show-version-and-exit "guix import crate")))
(option '(#\r "recursive") #f #f
(lambda (opt name arg result)
(alist-cons 'recursive #t result)))
(option '("recursive-dev-dependencies") #f #f
(lambda (opt name arg result)
(alist-cons 'recursive-dev-dependencies #t result)))
(option '("allow-yanked") #f #f
(lambda (opt name arg result)
(alist-cons 'allow-yanked #t result)))
(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)
(if (file-exists? arg)
@ -124,44 +106,35 @@ Import and convert the crates.io package for PACKAGE-NAME.\n"))
(define-values (name version)
(package-name->name+version spec))
(match (cond
(lockfile
(let ((source-expressions
_
(cargo-lock->expressions lockfile name)))
(when file-to-insert
(let* ((source-expressions
cargo-inputs-entry
(cargo-lock->expressions lockfile name))
(term (first cargo-inputs-entry))
(cargo-inputs
`(define-cargo-inputs lookup-cargo-inputs
,@(sort
(cons cargo-inputs-entry
(extract-cargo-inputs
file-to-insert #:exclude term))
(lambda (a b)
(string< (symbol->string (first a))
(symbol->string (first b)))))))
(_
(and=> (find-cargo-inputs-location file-to-insert)
delete-expression))
(port (open-file file-to-insert "a")))
(pretty-print-with-comments port cargo-inputs)
(newline port)
(close-port port)))
source-expressions))
((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))))
(match (if lockfile
(let ((source-expressions
_
(cargo-lock->expressions lockfile name)))
(when file-to-insert
(let* ((source-expressions
cargo-inputs-entry
(cargo-lock->expressions lockfile name))
(term (first cargo-inputs-entry))
(cargo-inputs
`(define-cargo-inputs lookup-cargo-inputs
,@(sort
(cons cargo-inputs-entry
(extract-cargo-inputs
file-to-insert #:exclude term))
(lambda (a b)
(string< (symbol->string (first a))
(symbol->string (first b)))))))
(_
(and=> (find-cargo-inputs-location file-to-insert)
delete-expression))
(port (open-file file-to-insert "a")))
(pretty-print-with-comments port cargo-inputs)
(newline port)
(close-port port)))
source-expressions)
(crate->guix-package
name #:version version
#:allow-yanked? (assoc-ref opts 'allow-yanked)))
((or #f '())
(leave (G_ "failed to download meta-data for package '~a'~%")
(if version