From patchwork Mon Dec 6 22:17:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 35001 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 4AB2827BBEA; Mon, 6 Dec 2021 22:18:20 +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=-3.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2,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 4B1E327BBE9 for ; Mon, 6 Dec 2021 22:18:19 +0000 (GMT) Received: from localhost ([::1]:40488 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1muMJO-000160-88 for patchwork@mira.cbaines.net; Mon, 06 Dec 2021 17:18:18 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1muMJ8-00015W-M3 for guix-patches@gnu.org; Mon, 06 Dec 2021 17:18:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:52293) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1muMJ8-0000Lz-EP for guix-patches@gnu.org; Mon, 06 Dec 2021 17:18:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1muMJ8-0002Sg-A5 for guix-patches@gnu.org; Mon, 06 Dec 2021 17:18:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#51845] Using =?utf-8?b?4oCYbmF0aXZlLWlucHV0c+KAmQ==?= and =?utf-8?b?4oCYaW5wdXRz4oCZ?= for Cargo packages? Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 06 Dec 2021 22:18:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 51845 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Efraim Flashner Cc: 51845@debbugs.gnu.org Received: via spool by 51845-submit@debbugs.gnu.org id=B51845.16388290799453 (code B ref 51845); Mon, 06 Dec 2021 22:18:02 +0000 Received: (at 51845) by debbugs.gnu.org; 6 Dec 2021 22:17:59 +0000 Received: from localhost ([127.0.0.1]:35606 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1muMJ4-0002SO-Gg for submit@debbugs.gnu.org; Mon, 06 Dec 2021 17:17:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:32788) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1muMJ2-0002SB-J2 for 51845@debbugs.gnu.org; Mon, 06 Dec 2021 17:17:57 -0500 Received: from [2001:470:142:3::e] (port=44776 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1muMIw-0000JG-V7; Mon, 06 Dec 2021 17:17:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=HhhhaG5Goz4aMi3kzCmJjnHE+uW2dfpTW4U1eWKVxMs=; b=EVmLApYGfpB8oCt/No1y 0VXl43mkdj6jNP2+MvTqliWOqPBG1Im5QPzjQtWBvRuE5pUwF8D8viMunYxaC0wrCW1ZgixzNNqPS Kq5JjRYhakUgeguBnfcL2VfCG2Tx2NIUDuku1yCsXqjHlpiCFAyBmxX9fbM/6hL4wL7sEx15bWKZV saJ2487phCZM5XYorKZET58h43JBUiIH4PEgv+KhQyROQVsG7B3DoxU6EbYdEzJ0z7eKMjpa/VrVw f2WMZIwVDfYLXOAcy8DCgCqy887WrR421aZCISljsgQcXtzOgxz6XxZViHyI7/IOiD5B+sk99zHMP 2VKlcs9YQ9+NgA==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:59669 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1muMIw-0000B0-Af; Mon, 06 Dec 2021 17:17:50 -0500 From: Ludovic =?utf-8?q?Court=C3=A8s?= References: <87zgpend04.fsf@gnu.org> <87wnkhlmfb.fsf@gnu.org> <405F2D9A-C0E6-42EC-9F81-F52F305B723C@flashner.co.il> Date: Mon, 06 Dec 2021 23:17:47 +0100 In-Reply-To: <405F2D9A-C0E6-42EC-9F81-F52F305B723C@flashner.co.il> (Efraim Flashner's message of "Mon, 06 Dec 2021 17:02:45 +0000") Message-ID: <878rwxl6no.fsf_-_@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) 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" X-getmail-retrieved-from-mailbox: Patches Efraim Flashner skribis: > On December 6, 2021 4:37:12 PM UTC, "Ludovic Courtès" wrote: [...] >>Thinking out loud… would it work to change: >> >> (arguments '(#:cargo-inputs X #:cargo-development-inputs Y)) >> >>to: >> >> (native-inputs (map package-source Y)) >> (inputs (map package-source X)) >> >>? [...] > Then we lose the transitive package sources, which is how we ended up where we are today. True. With the minimal changes to (guix build-system cargo) below, one can use either the current style or pass “development inputs” as ‘native-inputs’ and other dependencies as ‘inputs’. Source transitivity is preserved but you can write packages the normal way. I modified some of the dependencies of librsvg to use native-inputs/inputs and you can see when applying this part of the patch that the librsvg derivation is unchanged. Good thing is that ‘guix graph’ and ‘guix refresh -l’ work for these packages. Is this a direction we want to take? If so, we can have ‘guix style’ automate transformations. Thanks, Ludo’. diff --git a/gnu/packages/crates-io.scm b/gnu/packages/crates-io.scm index b8c4c7bd39..d7214e2d4f 100644 --- a/gnu/packages/crates-io.scm +++ b/gnu/packages/crates-io.scm @@ -5728,18 +5728,26 @@ (define-public rust-bitflags-1.3 (file-name (string-append name "-" version ".tar.gz")) (sha256 (base32 "12ki6w8gn1ldq7yz9y680llwk5gmrhrzszaa17g1sbrw2r2qvwxy")))) - (arguments - `(#:tests? #f ; Tests require rust-1.46 or newer. - #:cargo-inputs - (("rust-compiler-builtins" ,rust-compiler-builtins-0.1) - ("rust-rustc-std-workspace-core" ,rust-rustc-std-workspace-core-1)) - #:cargo-development-inputs - (("rust-rustversion" ,rust-rustversion-1) - ("rust-serde" ,rust-serde-1) - ("rust-serde-derive" ,rust-serde-derive-1) - ("rust-serde-json" ,rust-serde-json-1) - ("rust-trybuild" ,rust-trybuild-1) - ("rust-walkdir" ,rust-walkdir-2)))))) + (arguments `(#:tests? #f ; Tests require rust-1.46 or newer. + )) + (native-inputs `(("rust-rustversion" ,rust-rustversion-1) ( + "rust-serde" , + rust-serde-1) + ( + "rust-serde-derive" , + rust-serde-derive-1) + ( + "rust-serde-json" , + rust-serde-json-1) + ( + "rust-trybuild" , + rust-trybuild-1) + ( + "rust-walkdir" , + rust-walkdir-2))) + (inputs `(("rust-compiler-builtins" ,rust-compiler-builtins-0.1) ( + "rust-rustc-std-workspace-core" , + rust-rustc-std-workspace-core-1))))) (define-public rust-bitflags-0.9 (package @@ -8391,12 +8399,9 @@ (define-public rust-cast-0.2 (base32 "1c5z7zryj0zwnhdgs6rw5dfvnlwc1vm19jzrlgx5055alnwk952b")))) (build-system cargo-build-system) - (arguments - `(#:skip-build? #t - #:cargo-inputs - (("rust-rustc-version" ,rust-rustc-version-0.2)) - #:cargo-development-inputs - (("rust-quickcheck" ,rust-quickcheck-0.9)))) + (arguments `(#:skip-build? #t)) + (native-inputs `(("rust-quickcheck" ,rust-quickcheck-0.9))) + (inputs `(("rust-rustc-version" ,rust-rustc-version-0.2))) (home-page "https://github.com/japaric/cast.rs") (synopsis "Ergonomic, checked cast functions for primitive types") @@ -12459,19 +12464,34 @@ (define-public rust-cssparser-0.28 (sha256 (base32 "1h924c5g2rwlmgk8hllciyky3ih3z9vf04xz3xsp3cv1jyd5kf0x")))) (build-system cargo-build-system) - (arguments - `(#:skip-build? #t - #:cargo-inputs - (("rust-cssparser-macros" ,rust-cssparser-macros-0.6) - ("rust-dtoa-short" ,rust-dtoa-short-0.3) - ("rust-itoa" ,rust-itoa-0.4) - ("rust-matches" ,rust-matches-0.1) - ("rust-phf" ,rust-phf-0.8) - ("rust-proc-macro2" ,rust-proc-macro2-1) - ("rust-quote" ,rust-quote-1) - ("rust-serde" ,rust-serde-1) - ("rust-smallvec" ,rust-smallvec-1) - ("rust-syn" ,rust-syn-1)))) + (arguments `(#:skip-build? #t)) + (inputs `(("rust-cssparser-macros" ,rust-cssparser-macros-0.6) ( + "rust-dtoa-short" , + rust-dtoa-short-0.3) + ( + "rust-itoa" , + rust-itoa-0.4) + ( + "rust-matches" , + rust-matches-0.1) + ( + "rust-phf" , + rust-phf-0.8) + ( + "rust-proc-macro2" , + rust-proc-macro2-1) + ( + "rust-quote" , + rust-quote-1) + ( + "rust-serde" , + rust-serde-1) + ( + "rust-smallvec" , + rust-smallvec-1) + ( + "rust-syn" , + rust-syn-1))) (home-page "https://github.com/servo/rust-cssparser") (synopsis "Rust implementation of CSS Syntax Level 3") (description @@ -13601,13 +13621,13 @@ (define-public rust-data-url-0.1 (base32 "176wa1n8h71iwyaxhar4sqwrgrvb5sxk26az0fy88vnxrsffjgyk")))) (build-system cargo-build-system) - (arguments - `(#:cargo-inputs - (("rust-matches" ,rust-matches-0.1)) - #:cargo-development-inputs - (("rust-rustc-test" ,rust-rustc-test-0.3) - ("rust-serde" ,rust-serde-1) - ("rust-serde-json" ,rust-serde-json-1)))) + (native-inputs `(("rust-rustc-test" ,rust-rustc-test-0.3) ( + "rust-serde" , + rust-serde-1) + ( + "rust-serde-json" , + rust-serde-json-1))) + (inputs `(("rust-matches" ,rust-matches-0.1))) (home-page "https://github.com/servo/rust-url") (synopsis "Processing of data: URL according to WHATWG's Fetch Standard") (description @@ -16336,21 +16356,21 @@ (define-public rust-encoding-0.2 (base32 "1v1ndmkarh9z3n5hk53da4z56hgk9wa5kcsm7cnx345raqw983bb")))) (build-system cargo-build-system) - (arguments - `(#:skip-build? #t - #:cargo-inputs - (("rust-encoding-index-japanese" - ,rust-encoding-index-japanese-1.20141219) - ("rust-encoding-index-korean" - ,rust-encoding-index-korean-1.20141219) - ("rust-encoding-index-simpchinese" - ,rust-encoding-index-simpchinese-1.20141219) - ("rust-encoding-index-singlebyte" - ,rust-encoding-index-singlebyte-1.20141219) - ("rust-encoding-index-tradchinese" - ,rust-encoding-index-tradchinese-1.20141219)) - #:cargo-development-inputs - (("rust-getopts" ,rust-getopts-0.2)))) + (arguments `(#:skip-build? #t)) + (native-inputs `(("rust-getopts" ,rust-getopts-0.2))) + (inputs `(("rust-encoding-index-japanese" , + rust-encoding-index-japanese-1.20141219) ( + "rust-encoding-index-korean" , + rust-encoding-index-korean-1.20141219) + ( + "rust-encoding-index-simpchinese" , + rust-encoding-index-simpchinese-1.20141219) + ( + "rust-encoding-index-singlebyte" , + rust-encoding-index-singlebyte-1.20141219) + ( + "rust-encoding-index-tradchinese" , + rust-encoding-index-tradchinese-1.20141219))) (home-page "https://github.com/lifthrasiir/rust-encoding") (synopsis "Character encoding support for Rust") @@ -18388,8 +18408,7 @@ (define-public rust-float-cmp-0.8 (base32 "1i56hnzjn5pmrcm47fwkmfxiihk7wz5vvcgpb0kpfhzkqi57y9p1")))) (build-system cargo-build-system) - (arguments - `(#:cargo-inputs (("rust-num-traits" ,rust-num-traits-0.2)))) + (inputs `(("rust-num-traits" ,rust-num-traits-0.2))) (home-page "https://github.com/mikedilger/float-cmp") (synopsis "Floating point approximate comparison traits") (description @@ -26818,11 +26837,8 @@ (define-public rust-libm-0.2 (base32 "0akh56sh51adhagmk9l84dyrlz60gv8ri05xhr13i1b18czkpmy7")))) (build-system cargo-build-system) - (arguments - `(#:cargo-inputs - (("rust-rand" ,rust-rand-0.6)) - #:cargo-development-inputs - (("rust-no-panic" ,rust-no-panic-0.1)))) + (native-inputs `(("rust-no-panic" ,rust-no-panic-0.1))) + (inputs `(("rust-rand" ,rust-rand-0.6))) (home-page "https://github.com/rust-lang/libm") (synopsis "Libm in pure Rust") (description "This package provides an implementation of libm in pure Rust.") diff --git a/guix/build-system/cargo.scm b/guix/build-system/cargo.scm index 60c35eed07..b2d97beb2f 100644 --- a/guix/build-system/cargo.scm +++ b/guix/build-system/cargo.scm @@ -125,17 +125,21 @@ (define builder #:target #f #:guile-for-build guile)) +(define (cargo-input? input) + (match input + ((label (? package? p)) + (eq? cargo-build-system (package-build-system p))) + (_ #f))) + (define (package-cargo-inputs p) - (apply - (lambda* (#:key (cargo-inputs '()) #:allow-other-keys) - cargo-inputs) - (package-arguments p))) + (match (member #:cargo-inputs (package-arguments p)) + (#f (filter cargo-input? (package-inputs p))) + ((_ inputs . _) inputs))) (define (package-cargo-development-inputs p) - (apply - (lambda* (#:key (cargo-development-inputs '()) #:allow-other-keys) - cargo-development-inputs) - (package-arguments p))) + (match (member #:cargo-development-inputs (package-arguments p)) + (#f (filter cargo-input? (package-native-inputs p))) + ((_ inputs . _) inputs))) (define (crate-closure inputs) "Return the closure of INPUTS when considering the 'cargo-inputs' and @@ -235,8 +239,8 @@ (define (expand-crate-sources cargo-inputs cargo-development-inputs) (define* (lower name #:key source inputs native-inputs outputs system target (rust (default-rust)) - (cargo-inputs '()) - (cargo-development-inputs '()) + (cargo-inputs (filter cargo-input? inputs)) + (cargo-development-inputs (filter cargo-input? native-inputs)) #:allow-other-keys #:rest arguments) "Return a bag for NAME." @@ -260,7 +264,9 @@ (define private-keywords (build-inputs `(("cargo" ,rust "cargo") ("rustc" ,rust) ,@(expand-crate-sources cargo-inputs cargo-development-inputs) - ,@native-inputs)) + ,@(if (eq? native-inputs cargo-development-inputs) + '() + native-inputs))) (outputs outputs) (build cargo-build) (arguments (strip-keyword-arguments private-keywords arguments))))) diff --git a/guix/packages.scm b/guix/packages.scm index b3c5a00011..275cc3675c 100644 --- a/guix/packages.scm +++ b/guix/packages.scm @@ -660,7 +660,8 @@ (define (deprecated-package old-name p) (name old-name) (properties `((superseded . ,p))))) -(define (package-field-location package field) +(define* (package-field-location package field + #:key (value-location? #t)) "Return the source code location of the definition of FIELD for PACKAGE, or #f if it could not be determined." (match (package-location package) @@ -678,7 +679,10 @@ (define (package-field-location package field) (let ((field (assoc field inits))) (match field ((_ value) - (let ((loc (and=> (source-properties value) + (let ((loc (and=> (source-properties + (if value-location? + value + field)) source-properties->location))) (and loc ;; Preserve the original file name, which may be a diff --git a/guix/scripts/style.scm b/guix/scripts/style.scm index 86a46f693c..dccc20d880 100644 --- a/guix/scripts/style.scm +++ b/guix/scripts/style.scm @@ -29,6 +29,7 @@ (define-module (guix scripts style) #:autoload (gnu packages) (specification->package fold-packages) + #:autoload (guix build-system cargo) (cargo-build-system) #:use-module (guix scripts) #:use-module ((guix scripts build) #:select (%standard-build-options)) #:use-module (guix combinators) @@ -212,6 +213,21 @@ (define (object->string* obj indent) (pretty-print-with-comments port obj #:indent indent)))) +(define (object-list->string lst indent) + (call-with-output-string + (lambda (port) + (let loop ((lst lst)) + (match lst + ((obj) + (pretty-print-with-comments port obj + #:indent indent)) + ((obj rest ...) + (pretty-print-with-comments port obj + #:indent indent) + (newline port) + (display (make-string indent #\space) port) + (loop rest))))))) + ;;; ;;; Simplifying input expressions. @@ -441,6 +457,49 @@ (define matches? (list package-inputs package-native-inputs package-propagated-inputs))) + +;;; +;;; Crates, Cargo, Rust, and all that. +;;; + +(define* (rewrite-cargo-inputs package + #:key (policy 'silent) + (edit-expression edit-expression)) + (when (eq? (package-build-system package) cargo-build-system) + (match (package-field-location package 'arguments + #:value-location? #f) + (#f #f) + (location + (let* ((indent (location-column location))) + (edit-expression + (pk 'loc (location->source-properties location)) + (lambda (str) + (define arguments + (call-with-input-string (pk 'str str) read-with-comments)) + + (match arguments + (('arguments ('quasiquote lst)) + (let ((inputs (match (member #:cargo-inputs lst) + (#f '()) + ((_ inputs . _) inputs))) + (native (match (member #:cargo-development-inputs lst) + (#f '()) + ((_ inputs . _) inputs))) + (rest (strip-keyword-arguments + '(#:cargo-inputs #:cargo-development-inputs) + lst))) + (object-list->string + `(,@(if (null? rest) + '() + `((arguments ,(list 'quasiquote rest)))) + ,@(if (null? native) + '() + `((native-inputs ,(list 'quasiquote native)))) + ,@(if (null? inputs) + '() + `((inputs ,(list 'quasiquote inputs))))) + indent))))))))))) + (define (package-location