From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alex Kost Subject: Re: [PATCH] ui: 'package->recutils' serializes the source field. Date: Sat, 06 Aug 2016 15:35:29 +0300 Message-ID: <87y44af52m.fsf@gmail.com> References: <20160805145804.26753-1-david@craven.ch> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:32946) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bW0pG-0003Y3-4u for guix-devel@gnu.org; Sat, 06 Aug 2016 08:35:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bW0pB-0000Lp-0v for guix-devel@gnu.org; Sat, 06 Aug 2016 08:35:37 -0400 Received: from mail-lf0-x242.google.com ([2a00:1450:4010:c07::242]:36539) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bW0pA-0000LV-KX for guix-devel@gnu.org; Sat, 06 Aug 2016 08:35:32 -0400 Received: by mail-lf0-x242.google.com with SMTP id 33so18006071lfw.3 for ; Sat, 06 Aug 2016 05:35:32 -0700 (PDT) In-Reply-To: <20160805145804.26753-1-david@craven.ch> (David Craven's message of "Fri, 5 Aug 2016 16:58:04 +0200") 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: David Craven Cc: guix-devel@gnu.org David Craven (2016-08-05 17:58 +0300) wrote: > * guix/ui.scm (package->recutils): Format origin. > --- > guix/ui.scm | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > > diff --git a/guix/ui.scm b/guix/ui.scm > index 4d1b65c..e232548 100644 > --- a/guix/ui.scm > +++ b/guix/ui.scm > @@ -26,6 +26,7 @@ > (define-module (guix ui) > #:use-module (guix utils) > #:use-module (guix store) > + #:use-module (guix base32) > #:use-module (guix config) > #:use-module (guix packages) > #:use-module (guix profiles) > @@ -33,6 +34,7 @@ > #:use-module (guix combinators) > #:use-module (guix build-system) > #:use-module (guix serialization) > + #:use-module (guix git-download) > #:use-module ((guix build utils) #:select (mkdir-p)) > #:use-module ((guix licenses) #:select (license? license-name)) > #:use-module ((guix build syscalls) #:select (terminal-columns)) > @@ -878,6 +880,22 @@ WIDTH columns." > ;; Note: Don't i18n field names so that people can post-process it. > (format port "name: ~a~%" (package-name p)) > (format port "version: ~a~%" (package-version p)) > + > + (let ((uri (origin-uri (package-source p)))) This will fail for some packages (for example, for 'gcc-toolchain') because the source value can be #f, and (origin-uri #f) errors. > + (cond > + ((git-reference? uri) > + (begin 'begin' is not needed here. > + (format port "source-git-url: ~a~%" > + (git-reference-url uri)) > + (format port "source-git-commit: ~a~%" > + (git-reference-commit uri)) > + (format port "source-git-recursive: ~a~%" > + (git-reference-recursive? uri)))) > + (#t I think using 'else' here would be more Schemey than '#t'. > + (format port "source-uri: ~a~%" uri)))) > + > + (format port "source-hash: ~a~%" (bytevector->base32-string > + (origin-sha256 (package-source p)))) > (format port "outputs: ~a~%" (string-join (package-outputs p))) > (format port "systems: ~a~%" > (string-join (package-transitive-supported-systems p))) After all I would write it like this: (let ((source (package-source p))) (when (origin? source) (let ((uri (origin-uri source))) (cond ((git-reference? uri) (format port "source-git-url: ~a~%" (git-reference-url uri)) (format port "source-git-commit: ~a~%" (git-reference-commit uri)) (format port "source-git-recursive: ~a~%" (git-reference-recursive? uri))) (else (format port "source-uri: ~a~%" uri)))) (format port "source-hash: ~a~%" (bytevector->base32-string (origin-sha256 source))))) However, I'm not sure whether all these source things are needed to be in the output, I would wait for other opinions. (I agree with you though and I would like to add the same info for Emacs interface :-)) Also note that packages may have multiple sources. For example, for 'sudo' package, the output will be: source-uri: (https://www.sudo.ws/sudo/dist/sudo-1.8.17p1.tar.gz ftp://ftp.sudo.ws/pub/sudo/OLD/sudo-1.8.17p1.tar.gz) I'm not sure if this is a desired formatting, WDYT? -- Alex