From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Craven Subject: [PATCH 10/12] RECURSIVE IMPORTER wip Date: Sun, 11 Dec 2016 18:25:35 +0100 Message-ID: <20161211172537.23315-11-david@craven.ch> References: <20161211172537.23315-1-david@craven.ch> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:46403) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cG7tK-00006p-6O for guix-devel@gnu.org; Sun, 11 Dec 2016 12:26:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cG7tH-0001Fl-5M for guix-devel@gnu.org; Sun, 11 Dec 2016 12:26:26 -0500 Received: from so254-10.mailgun.net ([198.61.254.10]:29391) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cG7tH-000177-0z for guix-devel@gnu.org; Sun, 11 Dec 2016 12:26:23 -0500 In-Reply-To: <20161211172537.23315-1-david@craven.ch> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: guix-devel@gnu.org --- guix/import/crate.scm | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/guix/import/crate.scm b/guix/import/crate.scm index 45d5bf846..632c35f0a 100644 --- a/guix/import/crate.scm +++ b/guix/import/crate.scm @@ -156,3 +156,64 @@ VERSION, INPUTS, NATIVE-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE." (pred crate-package?) (latest latest-release))) +;;; +;;; Recursive importer +;;; + +(define-public (recursive-import crate-name) + (define (crate-inputs crate-name) + (crate-fetch + crate-name + (lambda* (#:key inputs native-inputs #:allow-other-keys) + (append inputs native-inputs)))) + + (define (crate->input-list crate-name crate-list) + (let ((crates (cons crate-name crate-list)) + (inputs (crate-inputs crate-name))) + (for-each + (lambda (crate) + (when (not (member crate crates)) + (format #t "Needs ~s crate.~%" crate) + (set! crates (crate->input-list crate crates)))) + inputs) + crates)) + + (define (recursive-crate-inputs crate-name) + (crate->input-list crate-name '())) + + (and-let* ((crates (recursive-crate-inputs crate-name)) + (crates-sorted (sort crates stringguix-package crates-sorted)) + (definitions (map package->definition packages))) + (for-each + (lambda (expr) + (pretty-print expr (newline-rewriting-port + (current-output-port)))) + definitions))) + + +(define (newline-rewriting-port output) + "Return an output port that rewrites strings containing the \\n escape +to an actual newline. This works around the behavior of `pretty-print' +and `write', which output these as \\n instead of actual newlines, +whereas we want the `description' field to contain actual newlines +rather than \\n." + (define (write-string str) + (let loop ((chars (string->list str))) + (match chars + (() + #t) + ((#\\ #\n rest ...) + (newline output) + (loop rest)) + ((chr rest ...) + (write-char chr output) + (loop rest))))) + + (make-soft-port (vector (cut write-char <>) + write-string + (lambda _ #t) ; flush + #f + (lambda _ #t) ; close + #f) + "w")) -- 2.11.0