From debbugs-submit-bounces@debbugs.gnu.org Mon May 20 15:42:15 2019 Received: (at submit) by debbugs.gnu.org; 20 May 2019 19:42:15 +0000 Received: from localhost ([127.0.0.1]:37984 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hSoAo-0007ph-0E for submit@debbugs.gnu.org; Mon, 20 May 2019 15:42:14 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60258) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hSmwU-0007qb-Hh for submit@debbugs.gnu.org; Mon, 20 May 2019 14:23:23 -0400 Received: from lists.gnu.org ([209.51.188.17]:50627) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hSmwP-0000pW-3d for submit@debbugs.gnu.org; Mon, 20 May 2019 14:23:17 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hSmwN-0000qS-3s for guix-patches@gnu.org; Mon, 20 May 2019 14:23:16 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,FREEMAIL_FROM, T_FILL_THIS_FORM_SHORT,URIBL_BLOCKED autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hSmwL-0000mM-7A for guix-patches@gnu.org; Mon, 20 May 2019 14:23:14 -0400 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]:34158) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hSmwK-0000lP-VV for guix-patches@gnu.org; Mon, 20 May 2019 14:23:13 -0400 Received: by mail-wr1-x431.google.com with SMTP id f8so9301865wrt.1 for ; Mon, 20 May 2019 11:23:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=L7p2d27EXZ/TA7DC0aJovxavCt7lqWwjdvUwOrrtOtc=; b=YX6iHcItLq4a0mOa8WwzwlkOhDIK4++kaue+T+zGa8SdNGU6JQ2LI3BKxfG4Bu5dRR yPxpqfZQBbfzPRvHnTQHhal1WMV4r4WGEYPn/5Kx+OFoCH+QbbwyQIfDgC2jjVvi5IV+ T5nsB1Gzz3SaOxyTQDXMfKZiZLv5unbwyx/zT016Q5/QKb5PdThb1Y1BrRylbWTFkUld vTyORKHrMdO+C6M42ZjRCgnyRbmQ6UNNZ7p/o+hin7MBLnCU0lnpQtwdw2kaOBN6lrJk Q1twHXLU59vo7AickMOndv08j0JbuzfT+01zbKTCUpVO82znr8ZKiJEvmctrFA7oA2uu evBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=L7p2d27EXZ/TA7DC0aJovxavCt7lqWwjdvUwOrrtOtc=; b=tpacEncIk6YWI2F8DwF0Q3wXRMtZo0s50K4ycw/Rb2hOFggAYkeZq1dmb+YIzRzHnp Jvzv5miTOEkN5PMy/J0neiSPTQg1NujmCGvHTyFhWbfsOiEwhqecJlyJ0fI/hauhmfIM AVxuok8V1wGBk3tV7KculCi3GXB1cZ0G3jiR+tiM6+mPCknmEjKZu6iFsad2HA+MxjFR KdGskDhzBh7IaTsU5L+5IwpozBqcpO0mbMFXLbI439t21kxGJkd+tsyB4FYEzl2HASyc v+q7N3D2S11BVC2zauFoqDvxJe6zrWQ06dX3lhvZyB+9TW4wUAwum2dU0s9RwwiVir1L agPw== X-Gm-Message-State: APjAAAXJ0nxq0GpljjrY0cMzXCgyVq0a3CvJi64k43KYuGqAz5B+EWGo EDMdvOrQxBAxa/4nXroRfLv2dJmYDSg= X-Google-Smtp-Source: APXvYqxtn086unKcLww6qjLxwC45XIFRzUZxjEv37dghu7ZJNOFbTID44j8M7xSV9WhD9TysQNZnPA== X-Received: by 2002:a5d:4002:: with SMTP id n2mr11687521wrp.187.1558376590275; Mon, 20 May 2019 11:23:10 -0700 (PDT) Received: from localhost (owp026a.halls.manchester.ac.uk. [130.88.254.26]) by smtp.gmail.com with ESMTPSA id d16sm14739785wrs.68.2019.05.20.11.23.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 20 May 2019 11:23:09 -0700 (PDT) From: Karl Meakin X-Google-Original-From: Karl Meakin To: guix-patches@gnu.org Subject: [PATCH] import: crate: add recursive option Date: Mon, 20 May 2019 19:23:06 +0100 Message-Id: <20190520182306.11899-1-Karlwfmeakin@gmail.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::431 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Spam-Score: -1.3 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Mon, 20 May 2019 15:42:12 -0400 Cc: Karl Meakin X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) * guix/script/import/crate.scm: Add recursive option. * guix/import/crate.scm (crate-recursive-import): New variable. --- doc/guix.texi | 8 ++++++++ guix/import/crate.scm | 24 ++++++++++++++++-------- guix/scripts/import/crate.scm | 27 ++++++++++++++++++++++----- 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index ae9ad0739e..636bb7521d 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -8787,6 +8787,14 @@ in Guix. Import metadata from the crates.io Rust package repository @uref{https://crates.io, crates.io}. +@table @code +@item --recursive +@itemx -r +Traverse the dependency graph of the given upstream package recursively +and generate package expressions for all those packages that are not yet +in Guix. +@end table + @item opam @cindex OPAM @cindex OCaml diff --git a/guix/import/crate.scm b/guix/import/crate.scm index e0b400d054..d8554b0e7a 100644 --- a/guix/import/crate.scm +++ b/guix/import/crate.scm @@ -37,6 +37,7 @@ #:use-module (srfi srfi-26) #:export (crate->guix-package guix-package->crate-name + crate-recursive-import %crate-updater)) (define (crate-fetch crate-name callback) @@ -86,8 +87,8 @@ VERSION, INPUTS, NATIVE-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE." (let* ((port (http-fetch (crate-uri name version))) (guix-name (crate-name->package-name name)) - (inputs (map crate-name->package-name inputs)) - (native-inputs (map crate-name->package-name native-inputs)) + (input-packages (map crate-name->package-name inputs)) + (native-input-packages (map crate-name->package-name native-inputs)) (pkg `(package (name ,guix-name) (version ,version) @@ -99,8 +100,8 @@ VERSION, INPUTS, NATIVE-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE." (base32 ,(bytevector->nix-base32-string (port-sha256 port)))))) (build-system cargo-build-system) - ,@(maybe-native-inputs native-inputs "src") - ,@(maybe-inputs inputs "src") + ,@(maybe-native-inputs native-input-packages "src") + ,@(maybe-inputs input-packages "src") (home-page ,(match home-page (() "") (_ home-page))) @@ -111,12 +112,14 @@ VERSION, INPUTS, NATIVE-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE." ((license) license) (_ `(list ,@license))))))) (close-port port) - pkg)) + (values pkg inputs))) -(define (crate->guix-package crate-name) - "Fetch the metadata for CRATE-NAME from crates.io, and return the +(define crate->guix-package + (memoize + (lambda* (crate-name _) + "Fetch the metadata for CRATE-NAME from crates.io, and return the `package' s-expression corresponding to that package, or #f on failure." - (crate-fetch crate-name make-crate-sexp)) + (crate-fetch crate-name make-crate-sexp)))) (define (guix-package->crate-name package) "Return the crate name of PACKAGE." @@ -158,6 +161,11 @@ VERSION, INPUTS, NATIVE-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE." (version version) (urls (list url))))) +(define* (crate-recursive-import package-name) + (recursive-import package-name #f + #:repo->guix-package crate->guix-package + #:guix-name crate-name->package-name)) + (define %crate-updater (upstream-updater (name 'crates) diff --git a/guix/scripts/import/crate.scm b/guix/scripts/import/crate.scm index cab9a4397b..8fadcdd57c 100644 --- a/guix/scripts/import/crate.scm +++ b/guix/scripts/import/crate.scm @@ -27,6 +27,7 @@ #:use-module (srfi srfi-1) #:use-module (srfi srfi-11) #:use-module (srfi srfi-37) + #:use-module (srfi srfi-41) #:use-module (ice-9 match) #:use-module (ice-9 format) #:export (guix-import-crate)) @@ -45,6 +46,8 @@ Import and convert the crate.io package for PACKAGE-NAME.\n")) (display (G_ " -h, --help display this help and exit")) (display (G_ " + -r, --recursive import packages recursively")) + (display (G_ " -V, --version display version information and exit")) (newline) (show-bug-report-information)) @@ -58,6 +61,9 @@ Import and convert the crate.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))) %standard-import-options)) @@ -83,11 +89,22 @@ Import and convert the crate.io package for PACKAGE-NAME.\n")) (reverse opts)))) (match args ((package-name) - (let ((sexp (crate->guix-package package-name))) - (unless sexp - (leave (G_ "failed to download meta-data for package '~a'~%") - package-name)) - sexp)) + (if (assoc-ref opts 'recursive) + ;; Recursive import + (map (match-lambda + ((and ('package ('name name) . rest) pkg) + `(define-public ,(string->symbol name) + ,pkg)) + (_ #f)) + (reverse + (stream->list + (crate-recursive-import package-name)))) + ;; Single import + (let ((sexp (crate->guix-package package-name #f))) + (unless sexp + (leave (G_ "failed to download meta-data for package '~a'~%") + package-name)) + sexp))) (() (leave (G_ "too few arguments~%"))) ((many ...) -- 2.21.0