From bb3f36ed4ca83f01eb422f9de9c404d53218b382 Mon Sep 17 00:00:00 2001 From: David Craven Date: Sat, 10 Dec 2016 18:43:39 +0100 Subject: import: utils: Add some utilities. * guix/import/utils.scm (maybe-inputs, maybe-native-inputs, package->definition): New variables. --- guix/import/utils.scm | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'guix/import') diff --git a/guix/import/utils.scm b/guix/import/utils.scm index 057c2d9c7d..f304da20e6 100644 --- a/guix/import/utils.scm +++ b/guix/import/utils.scm @@ -22,6 +22,7 @@ #:use-module (guix base32) #:use-module ((guix build download) #:prefix build:) #:use-module (guix hash) + #:use-module (guix http-client) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix utils) #:use-module (ice-9 match) @@ -36,6 +37,10 @@ url-fetch guix-hash-url + maybe-inputs + maybe-native-inputs + package->definition + spdx-string->license license->symbol @@ -205,3 +210,32 @@ into a proper sentence and by using two spaces between sentences." ;; Use double spacing between sentences (regexp-substitute/global #f "\\. \\b" cleaned 'pre ". " 'post))) + +(define (package-names->package-inputs names) + (map (lambda (input) + (list input (list 'unquote (string->symbol input)))) + names)) + +(define (maybe-inputs package-names) + "Given a list of PACKAGE-NAMES, tries to generate the 'inputs' field of a +package definition." + (match (package-names->package-inputs package-names) + (() + '()) + ((package-inputs ...) + `((inputs (,'quasiquote ,package-inputs)))))) + +(define (maybe-native-inputs package-names) + "Given a list of PACKAGE-NAMES, tries to generate the 'inputs' field of a +package definition." + (match (package-names->package-inputs package-names) + (() + '()) + ((package-inputs ...) + `((native-inputs (,'quasiquote ,package-inputs)))))) + +(define (package->definition guix-package) + (match guix-package + (('package ('name (? string? name)) _ ...) + `(define-public ,(string->symbol name) + ,guix-package)))) -- cgit v1.2.3 From 3e0c036584b41bcc08a8c8e040295716108bb0b2 Mon Sep 17 00:00:00 2001 From: David Craven Date: Thu, 22 Sep 2016 11:40:58 +0200 Subject: import: Add importer for rust crates. * guix/import/crate.scm: New file. * guix/scripts/import/crate.scm: New file. * guix/scripts/import.scm (importers): Add crate importer. * tests/crate.scm: New file. * doc/guix.texi: Add crate importer to table. * Makefile.am (MODULES, SCM_TESTS): Add files. --- Makefile.am | 5 +- doc/guix.texi | 5 ++ guix/import/crate.scm | 125 ++++++++++++++++++++++++++++++++++++++++++ guix/scripts/import.scm | 2 +- guix/scripts/import/crate.scm | 94 +++++++++++++++++++++++++++++++ guix/scripts/refresh.scm | 1 + tests/crate.scm | 102 ++++++++++++++++++++++++++++++++++ 7 files changed, 332 insertions(+), 2 deletions(-) create mode 100644 guix/import/crate.scm create mode 100644 guix/scripts/import/crate.scm create mode 100644 tests/crate.scm (limited to 'guix/import') diff --git a/Makefile.am b/Makefile.am index 5cb4261f4b..84ff6642a2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -122,6 +122,7 @@ MODULES = \ guix/import/snix.scm \ guix/import/cabal.scm \ guix/import/cran.scm \ + guix/import/crate.scm \ guix/import/hackage.scm \ guix/import/elpa.scm \ guix/scripts.scm \ @@ -141,6 +142,7 @@ MODULES = \ guix/scripts/lint.scm \ guix/scripts/challenge.scm \ guix/scripts/import/cran.scm \ + guix/scripts/import/crate.scm \ guix/scripts/import/gnu.scm \ guix/scripts/import/nix.scm \ guix/scripts/import/hackage.scm \ @@ -282,7 +284,8 @@ if HAVE_GUILE_JSON SCM_TESTS += \ tests/pypi.scm \ tests/cpan.scm \ - tests/gem.scm + tests/gem.scm \ + tests/crate.scm endif diff --git a/doc/guix.texi b/doc/guix.texi index f1c5963f76..5db20ecdfa 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -5267,6 +5267,11 @@ signatures,, emacs, The GNU Emacs Manual}). identifier. @end itemize @end table + +@item crate +@cindex crate +Import metadata from the crates.io Rust package repository +@uref{https://crates.io, crates.io}. @end table The structure of the @command{guix import} code is modular. It would be diff --git a/guix/import/crate.scm b/guix/import/crate.scm new file mode 100644 index 0000000000..e78e3ad9ca --- /dev/null +++ b/guix/import/crate.scm @@ -0,0 +1,125 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2016 David Craven +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (guix import crate) + #:use-module (guix base32) + #:use-module (guix build-system cargo) + #:use-module ((guix download) #:prefix download:) + #:use-module (guix hash) + #:use-module (guix http-client) + #:use-module (guix import json) + #:use-module (guix import utils) + #:use-module ((guix licenses) #:prefix license:) + #:use-module (guix monads) + #:use-module (guix packages) + #:use-module (guix upstream) + #:use-module (guix utils) + #:use-module (ice-9 match) + #:use-module (ice-9 pretty-print) ; recursive + #:use-module (json) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-2) + #:use-module (srfi srfi-26) + #:export (crate->guix-package + guix-package->crate-name)) + +(define (crate-fetch crate-name callback) + "Fetch the metadata for CRATE-NAME from crates.io and call the callback." + + (define (crates->inputs crates) + (sort (map (cut assoc-ref <> "crate_id") crates) string-cilicense string) + (map spdx-string->license (string-split string #\/))) + + (define (crate-kind-predicate kind) + (lambda (dep) (string=? (assoc-ref dep "kind") kind))) + + (and-let* ((crate-json (json-fetch (string-append crate-url crate-name))) + (crate (assoc-ref crate-json "crate")) + (name (assoc-ref crate "name")) + (version (assoc-ref crate "max_version")) + (home-page (assoc-ref crate "homepage")) + (synopsis (assoc-ref crate "description")) + (description (assoc-ref crate "description")) + (license (string->license (assoc-ref crate "license"))) + (path (string-append "/" version "/dependencies")) + (deps-json (json-fetch (string-append crate-url name path))) + (deps (assoc-ref deps-json "dependencies")) + (input-crates (filter (crate-kind-predicate "normal") deps)) + (native-input-crates + (filter (lambda (dep) + (not ((crate-kind-predicate "normal") dep))) deps)) + (inputs (crates->inputs input-crates)) + (native-inputs (crates->inputs native-input-crates))) + (callback #:name name #:version version + #:inputs inputs #:native-inputs native-inputs + #:home-page home-page #:synopsis synopsis + #:description description #:license license))) + +(define* (make-crate-sexp #:key name version inputs native-inputs + home-page synopsis description license + #:allow-other-keys) + "Return the `package' s-expression for a rust package with the given NAME, +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)) + (pkg `(package + (name ,guix-name) + (version ,version) + (source (origin + (method url-fetch) + (uri (crate-uri ,name version)) + (file-name (string-append name "-" version ".tar.gz")) + (sha256 + (base32 + ,(bytevector->nix-base32-string (port-sha256 port)))))) + (build-system cargo-build-system) + ,@(maybe-native-inputs native-inputs) + ,@(maybe-inputs inputs) + (home-page ,home-page) + (synopsis ,synopsis) + (description ,(beautify-description description)) + (license ,(match license + (() #f) + ((license) license) + (_ `(list ,@license))))))) + (close-port port) + pkg)) + +(define (crate->guix-package 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)) + +(define (guix-package->crate-name package) + "Return the crate name of PACKAGE." + (and-let* ((origin (package-source package)) + (uri (origin-uri origin)) + (crate-url? uri) + (len (string-length crate-url)) + (path (xsubstring uri len)) + (parts (string-split path #\/))) + (match parts + ((name _ ...) name)))) + +(define (crate-name->package-name name) + (string-append "rust-" (string-join (string-split name #\_) "-"))) + diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm index e54744feca..c671686043 100644 --- a/guix/scripts/import.scm +++ b/guix/scripts/import.scm @@ -73,7 +73,7 @@ rather than \\n." ;;; Entry point. ;;; -(define importers '("gnu" "nix" "pypi" "cpan" "hackage" "elpa" "gem" "cran")) +(define importers '("gnu" "nix" "pypi" "cpan" "hackage" "elpa" "gem" "cran" "crate")) (define (resolve-importer name) (let ((module (resolve-interface diff --git a/guix/scripts/import/crate.scm b/guix/scripts/import/crate.scm new file mode 100644 index 0000000000..4337a0b623 --- /dev/null +++ b/guix/scripts/import/crate.scm @@ -0,0 +1,94 @@ + +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2014 David Thompson +;;; Copyright © 2016 David Craven +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (guix scripts import crate) + #:use-module (guix ui) + #:use-module (guix utils) + #:use-module (guix scripts) + #:use-module (guix import crate) + #:use-module (guix scripts import) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-11) + #:use-module (srfi srfi-37) + #:use-module (ice-9 match) + #:use-module (ice-9 format) + #:export (guix-import-crate)) + + +;;; +;;; Command-line options. +;;; + +(define %default-options + '()) + +(define (show-help) + (display (_ "Usage: guix import crate PACKAGE-NAME +Import and convert the crate.io package for PACKAGE-NAME.\n")) + (display (_ " + -h, --help display this help and exit")) + (display (_ " + -V, --version display version information and exit")) + (newline) + (show-bug-report-information)) + +(define %options + ;; Specification of the command-line options. + (cons* (option '(#\h "help") #f #f + (lambda args + (show-help) + (exit 0))) + (option '(#\V "version") #f #f + (lambda args + (show-version-and-exit "guix import crate"))) + %standard-import-options)) + + +;;; +;;; Entry point. +;;; + +(define (guix-import-crate . args) + (define (parse-options) + ;; Return the alist of option values. + (args-fold* args %options + (lambda (opt name arg result) + (leave (_ "~A: unrecognized option~%") name)) + (lambda (arg result) + (alist-cons 'argument arg result)) + %default-options)) + + (let* ((opts (parse-options)) + (args (filter-map (match-lambda + (('argument . value) + value) + (_ #f)) + (reverse opts)))) + (match args + ((package-name) + (let ((sexp (crate->guix-package package-name))) + (unless sexp + (leave (_ "failed to download meta-data for package '~a'~%") + package-name)) + sexp)) + (() + (leave (_ "too few arguments~%"))) + ((many ...) + (leave (_ "too many arguments~%")))))) diff --git a/guix/scripts/refresh.scm b/guix/scripts/refresh.scm index f8fb3f80ca..72f51cbff8 100644 --- a/guix/scripts/refresh.scm +++ b/guix/scripts/refresh.scm @@ -39,6 +39,7 @@ %kernel.org-updater)) #:use-module (guix import elpa) #:use-module (guix import cran) + #:use-module (guix import crate) #:use-module (guix import hackage) #:use-module (guix gnupg) #:use-module (gnu packages) diff --git a/tests/crate.scm b/tests/crate.scm new file mode 100644 index 0000000000..18d5f72a8c --- /dev/null +++ b/tests/crate.scm @@ -0,0 +1,102 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2014 David Thompson +;;; Copyright © 2016 David Craven +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (test-crate) + #:use-module (guix import crate) + #:use-module (guix base32) + #:use-module (guix build-system cargo) + #:use-module (guix hash) + #:use-module (guix tests) + #:use-module (ice-9 iconv) + #:use-module (ice-9 match) + #:use-module (srfi srfi-64)) + +(define test-crate + "{ + \"crate\": { + \"max_version\": \"1.0.0\", + \"name\": \"foo\", + \"license\": \"MIT/Apache-2.0\", + \"description\": \"summary\", + \"homepage\": \"http://example.com\", + } +}") + +(define test-dependencies + "{ + \"dependencies\": [ + { + \"crate_id\": \"bar\", + \"kind\": \"normal\", + } + ] +}") + +(define test-source-hash + "") + +(test-begin "crate") + +(test-equal "guix-package->crate-name" + "rustc-serialize" + (guix-package->crate-name + (dummy-package + "rust-rustc-serialize" + (source (dummy-origin + (uri (crate-uri "rustc-serialize" "1.0"))))))) + +(test-assert "crate->guix-package" + ;; Replace network resources with sample data. + (mock ((guix http-client) http-fetch + (lambda (url) + (match url + ("https://crates.io/api/v1/crates/foo" + (open-input-string test-crate)) + ("https://crates.io/api/v1/crates/foo/1.0.0/download" + (set! test-source-hash + (bytevector->nix-base32-string + (sha256 (string->bytevector "empty file\n" "utf-8")))) + (open-input-string "empty file\n")) + ("https://crates.io/api/v1/crates/foo/1.0.0/dependencies" + (open-input-string test-dependencies)) + (_ (error "Unexpected URL: " url))))) + (match (crate->guix-package "foo") + (('package + ('name "rust-foo") + ('version "1.0.0") + ('source ('origin + ('method 'url-fetch) + ('uri ('crate-uri "foo" 'version)) + ('file-name ('string-append 'name "-" 'version ".tar.gz")) + ('sha256 + ('base32 + (? string? hash))))) + ('build-system 'cargo-build-system) + ('inputs + ('quasiquote + (("rust-bar" ('unquote 'rust-bar))))) + ('home-page "http://example.com") + ('synopsis "summary") + ('description "summary") + ('license ('list 'license:expat 'license:asl2.0))) + (string=? test-source-hash hash)) + (x + (pk 'fail x #f))))) + +(test-end "crate") -- cgit v1.2.3 From 8ac529878640de632356895fbcaeeed6c1cb335e Mon Sep 17 00:00:00 2001 From: David Craven Date: Thu, 22 Sep 2016 11:40:58 +0200 Subject: import: Add updater for rust crates. * guix/import/crate.scm (crate-package?, latest-release, %crate-updater): New variables. * guix/scripts/refresh.scm (%updaters): Add crate updater. * doc/guix.texi: Add crate updater to table. --- doc/guix.texi | 2 ++ guix/import/crate.scm | 36 +++++++++++++++++++++++++++++++++++- guix/scripts/refresh.scm | 3 ++- 3 files changed, 39 insertions(+), 2 deletions(-) (limited to 'guix/import') diff --git a/doc/guix.texi b/doc/guix.texi index 5db20ecdfa..a5424b4e01 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -5396,6 +5396,8 @@ the updater for @uref{https://rubygems.org, RubyGems} packages. the updater for @uref{https://github.com, GitHub} packages. @item hackage the updater for @uref{https://hackage.haskell.org, Hackage} packages. +@item crate +the updater for @uref{https://crates.io, Crates} packages. @end table For instance, the following command only checks for updates of Emacs diff --git a/guix/import/crate.scm b/guix/import/crate.scm index e78e3ad9ca..3a19fc70cf 100644 --- a/guix/import/crate.scm +++ b/guix/import/crate.scm @@ -36,7 +36,8 @@ #:use-module (srfi srfi-2) #:use-module (srfi srfi-26) #:export (crate->guix-package - guix-package->crate-name)) + guix-package->crate-name + %crate-updater)) (define (crate-fetch crate-name callback) "Fetch the metadata for CRATE-NAME from crates.io and call the callback." @@ -123,3 +124,36 @@ VERSION, INPUTS, NATIVE-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE." (define (crate-name->package-name name) (string-append "rust-" (string-join (string-split name #\_) "-"))) +;;; +;;; Updater +;;; + +(define (crate-package? package) + "Return true if PACKAGE is a Rust crate from crates.io." + (let ((source-url (and=> (package-source package) origin-uri)) + (fetch-method (and=> (package-source package) origin-method))) + (and (eq? fetch-method download:url-fetch) + (match source-url + ((? string?) + (crate-url? source-url)) + ((source-url ...) + (any crate-url? source-url)))))) + +(define (latest-release package) + "Return an for the latest release of PACKAGE." + (let* ((crate-name (guix-package->crate-name package)) + (callback (lambda* (#:key version #:allow-other-keys) version)) + (version (crate-fetch crate-name callback)) + (url (crate-uri crate-name version))) + (upstream-source + (package (package-name package)) + (version version) + (urls (list url))))) + +(define %crate-updater + (upstream-updater + (name 'crates) + (description "Updater for crates.io packages") + (pred crate-package?) + (latest latest-release))) + diff --git a/guix/scripts/refresh.scm b/guix/scripts/refresh.scm index 72f51cbff8..2a06405a14 100644 --- a/guix/scripts/refresh.scm +++ b/guix/scripts/refresh.scm @@ -210,7 +210,8 @@ unavailable optional dependencies such as Guile-JSON." ((guix import cpan) => %cpan-updater) ((guix import pypi) => %pypi-updater) ((guix import gem) => %gem-updater) - ((guix import github) => %github-updater))) + ((guix import github) => %github-updater) + ((guix import crate) => %crate-updater))) (define (lookup-updater-by-name name) "Return the updater called NAME." -- cgit v1.2.3 From 13f54d081b6922c65f7cb369ad24071e78ebba54 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Thu, 8 Dec 2016 14:35:20 +0100 Subject: import cran: Do not use "or later" licenses by default. * guix/import/cran.scm (string->license): Use exact license versions. --- guix/import/cran.scm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'guix/import') diff --git a/guix/import/cran.scm b/guix/import/cran.scm index 3fb2e213b0..13f5f82a45 100644 --- a/guix/import/cran.scm +++ b/guix/import/cran.scm @@ -55,11 +55,11 @@ ("GPL" (list 'gpl2+ 'gpl3+)) ("GPL (>= 2)" 'gpl2+) ("GPL (>= 3)" 'gpl3+) - ("GPL-2" 'gpl2+) - ("GPL-3" 'gpl3+) - ("LGPL-2" 'lgpl2.0+) - ("LGPL-2.1" 'lgpl2.1+) - ("LGPL-3" 'lgpl3+) + ("GPL-2" 'gpl2) + ("GPL-3" 'gpl3) + ("LGPL-2" 'lgpl2.0) + ("LGPL-2.1" 'lgpl2.1) + ("LGPL-3" 'lgpl3) ("LGPL (>= 2)" 'lgpl2.0+) ("LGPL (>= 3)" 'lgpl3+) ("MIT" 'x11) -- cgit v1.2.3 From 741d68c20d1910252f34441c3df65a6f35771673 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Thu, 8 Dec 2016 14:36:27 +0100 Subject: import cran: Translate MIT to the Expat license. * guix/import/cran.scm (string->license): Translate "MIT" license to Expat license. --- guix/import/cran.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'guix/import') diff --git a/guix/import/cran.scm b/guix/import/cran.scm index 13f5f82a45..549b11c392 100644 --- a/guix/import/cran.scm +++ b/guix/import/cran.scm @@ -62,8 +62,8 @@ ("LGPL-3" 'lgpl3) ("LGPL (>= 2)" 'lgpl2.0+) ("LGPL (>= 3)" 'lgpl3+) - ("MIT" 'x11) - ("MIT + file LICENSE" 'x11) + ("MIT" 'expat) + ("MIT + file LICENSE" 'expat) ((x) (string->license x)) ((lst ...) `(list ,@(map string->license lst))) (_ #f))) -- cgit v1.2.3 From 576eda6d02c65cbbbd611691abb5f5ee9511afc6 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Thu, 8 Dec 2016 14:37:32 +0100 Subject: import cran: Handle BSD licenses with LICENSE file. * guix/import/cran.scm (string->license): Add cases for BSD licenses with LICENSE file. --- guix/import/cran.scm | 2 ++ 1 file changed, 2 insertions(+) (limited to 'guix/import') diff --git a/guix/import/cran.scm b/guix/import/cran.scm index 549b11c392..d2add6f633 100644 --- a/guix/import/cran.scm +++ b/guix/import/cran.scm @@ -51,7 +51,9 @@ ("Artistic-2.0" 'artistic2.0) ("Apache License 2.0" 'asl2.0) ("BSD_2_clause" 'bsd-2) + ("BSD_2_clause + file LICENSE" 'bsd-2) ("BSD_3_clause" 'bsd-3) + ("BSD_3_clause + file LICENSE" 'bsd-3) ("GPL" (list 'gpl2+ 'gpl3+)) ("GPL (>= 2)" 'gpl2+) ("GPL (>= 3)" 'gpl3+) -- cgit v1.2.3 From 2e5f32ce1b2d552527b8eb9a85a100a92d6d252a Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Tue, 17 May 2016 15:06:44 +0200 Subject: import cran: Remove more invalid characters from package names. * guix/import/cran.scm (guix-name): Replace period and underscore with dash; always prepend package names with "r-". --- guix/import/cran.scm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'guix/import') diff --git a/guix/import/cran.scm b/guix/import/cran.scm index d2add6f633..ee34eade94 100644 --- a/guix/import/cran.scm +++ b/guix/import/cran.scm @@ -152,9 +152,11 @@ empty list when the FIELD cannot be found." "Return the `package' s-expression for an R package published on REPOSITORY from the alist META, which was derived from the R package's DESCRIPTION file." (define (guix-name name) - (if (string-prefix? "r-" name) - (string-downcase name) - (string-append "r-" (string-downcase name)))) + (string-append "r-" (string-map (match-lambda + (#\_ #\-) + (#\. #\-) + (chr (char-downcase chr))) + name))) (let* ((base-url (case repository ((cran) %cran-url) -- cgit v1.2.3 From bfa0c752bc19810f7b4908c3d0f4a1dd7832c1b6 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Wed, 6 Jul 2016 12:42:38 +0200 Subject: import cran: Move guix-name to top-level. * guix/import/cran.scm (guix-name): Move to top-level. --- guix/import/cran.scm | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'guix/import') diff --git a/guix/import/cran.scm b/guix/import/cran.scm index ee34eade94..c98ab88aec 100644 --- a/guix/import/cran.scm +++ b/guix/import/cran.scm @@ -148,16 +148,17 @@ empty list when the FIELD cannot be found." (string-any char-set:whitespace item))) (map string-trim-both items)))))) +(define (guix-name name) + "Return a Guix package name for a given R package name." + (string-append "r-" (string-map (match-lambda + (#\_ #\-) + (#\. #\-) + (chr (char-downcase chr))) + name))) + (define (description->package repository meta) "Return the `package' s-expression for an R package published on REPOSITORY from the alist META, which was derived from the R package's DESCRIPTION file." - (define (guix-name name) - (string-append "r-" (string-map (match-lambda - (#\_ #\-) - (#\. #\-) - (chr (char-downcase chr))) - name))) - (let* ((base-url (case repository ((cran) %cran-url) ((bioconductor) %bioconductor-url))) -- cgit v1.2.3 From ad68f7fa58daeff542d2fba19f65928c1af5799b Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Tue, 17 May 2016 15:17:54 +0200 Subject: import cran: description->package: Also return package dependencies. * guix/import/cran.scm (description->package): Return package dependencies in addition to generated package expression. --- guix/import/cran.scm | 58 ++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 27 deletions(-) (limited to 'guix/import') diff --git a/guix/import/cran.scm b/guix/import/cran.scm index c98ab88aec..313e26b03d 100644 --- a/guix/import/cran.scm +++ b/guix/import/cran.scm @@ -23,6 +23,7 @@ #:use-module ((ice-9 rdelim) #:select (read-string)) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) + #:use-module (ice-9 receive) #:use-module (guix http-client) #:use-module (guix hash) #:use-module (guix store) @@ -179,33 +180,36 @@ from the alist META, which was derived from the R package's DESCRIPTION file." (_ #f))) (tarball (with-store store (download-to-store store source-url))) (sysdepends (map string-downcase (listify meta "SystemRequirements"))) - (propagate (map guix-name (lset-union equal? - (listify meta "Imports") - (listify meta "LinkingTo") - (delete "R" - (listify meta "Depends")))))) - `(package - (name ,(guix-name name)) - (version ,version) - (source (origin - (method url-fetch) - (uri (,(procedure-name uri-helper) ,name version)) - (sha256 - (base32 - ,(bytevector->nix-base32-string (file-sha256 tarball)))))) - ,@(if (not (equal? (string-append "r-" name) - (guix-name name))) - `((properties ,`(,'quasiquote ((,'upstream-name . ,name))))) - '()) - (build-system r-build-system) - ,@(maybe-inputs sysdepends) - ,@(maybe-inputs propagate 'propagated-inputs) - (home-page ,(if (string-null? home-page) - (string-append base-url name) - home-page)) - (synopsis ,synopsis) - (description ,(beautify-description (assoc-ref meta "Description"))) - (license ,license)))) + (propagate (lset-union equal? + (listify meta "Imports") + (listify meta "LinkingTo") + (delete "R" + (listify meta "Depends"))))) + (values + `(package + (name ,(guix-name name)) + (version ,version) + (source (origin + (method url-fetch) + (uri (,(procedure-name uri-helper) ,name version)) + (sha256 + (base32 + ,(bytevector->nix-base32-string (file-sha256 tarball)))))) + ,@(if (not (equal? (string-append "r-" name) + (guix-name name))) + `((properties ,`(,'quasiquote ((,'upstream-name . ,name))))) + '()) + (build-system r-build-system) + ,@(maybe-inputs sysdepends) + ,@(maybe-inputs (map guix-name propagate) 'propagated-inputs) + (home-page ,(if (string-null? home-page) + (string-append base-url name) + home-page)) + (synopsis ,synopsis) + (description ,(beautify-description (or (assoc-ref meta "Description") + ""))) + (license ,license)) + propagate))) (define* (cran->guix-package package-name #:optional (repo 'cran)) "Fetch the metadata for PACKAGE-NAME from REPO and return the `package' -- cgit v1.2.3 From b26abe4f148ea04145cb1f62122eb560b64a0139 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Tue, 17 May 2016 15:22:30 +0200 Subject: import cran: Ignore default R packages. * guix/import/cran.scm (default-r-packages): New variable. (description->package): Drop default R packages from list of inputs. --- guix/import/cran.scm | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'guix/import') diff --git a/guix/import/cran.scm b/guix/import/cran.scm index 313e26b03d..09796e0159 100644 --- a/guix/import/cran.scm +++ b/guix/import/cran.scm @@ -149,6 +149,38 @@ empty list when the FIELD cannot be found." (string-any char-set:whitespace item))) (map string-trim-both items)))))) +(define default-r-packages + (list "KernSmooth" + "MASS" + "Matrix" + "base" + "boot" + "class" + "cluster" + "codetools" + "compiler" + "datasets" + "foreign" + "grDevices" + "graphics" + "grid" + "lattice" + "methods" + "mgcv" + "nlme" + "nnet" + "parallel" + "rpart" + "spatial" + "splines" + "stats" + "stats4" + "survival" + "tcltk" + "tools" + "translations" + "utils")) + (define (guix-name name) "Return a Guix package name for a given R package name." (string-append "r-" (string-map (match-lambda @@ -180,11 +212,13 @@ from the alist META, which was derived from the R package's DESCRIPTION file." (_ #f))) (tarball (with-store store (download-to-store store source-url))) (sysdepends (map string-downcase (listify meta "SystemRequirements"))) - (propagate (lset-union equal? - (listify meta "Imports") - (listify meta "LinkingTo") - (delete "R" - (listify meta "Depends"))))) + (propagate (filter (lambda (name) + (not (member name default-r-packages))) + (lset-union equal? + (listify meta "Imports") + (listify meta "LinkingTo") + (delete "R" + (listify meta "Depends")))))) (values `(package (name ,(guix-name name)) -- cgit v1.2.3 From 94e907b96252bda6bbf49552b89928f337aadcfd Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Tue, 17 May 2016 16:38:17 +0200 Subject: import cran: Add recursive importer. * guix/import/cran.scm (recursive-import): New variable. (cran->guix-package): Memoize the procedure. --- guix/import/cran.scm | 78 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 7 deletions(-) (limited to 'guix/import') diff --git a/guix/import/cran.scm b/guix/import/cran.scm index 09796e0159..123abfe7ea 100644 --- a/guix/import/cran.scm +++ b/guix/import/cran.scm @@ -23,7 +23,9 @@ #:use-module ((ice-9 rdelim) #:select (read-string)) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-41) #:use-module (ice-9 receive) + #:use-module (guix combinators) #:use-module (guix http-client) #:use-module (guix hash) #:use-module (guix store) @@ -33,8 +35,10 @@ #:use-module ((guix build-system r) #:select (cran-uri bioconductor-uri)) #:use-module (guix upstream) #:use-module (guix packages) + #:use-module (gnu packages) #:export (cran->guix-package bioconductor->guix-package + recursive-import %cran-updater %bioconductor-updater)) @@ -245,14 +249,74 @@ from the alist META, which was derived from the R package's DESCRIPTION file." (license ,license)) propagate))) -(define* (cran->guix-package package-name #:optional (repo 'cran)) - "Fetch the metadata for PACKAGE-NAME from REPO and return the `package' +(define cran->guix-package + (memoize + (lambda* (package-name #:optional (repo 'cran)) + "Fetch the metadata for PACKAGE-NAME from REPO and return the `package' s-expression corresponding to that package, or #f on failure." - (let* ((url (case repo - ((cran) %cran-url) - ((bioconductor) %bioconductor-svn-url))) - (module-meta (fetch-description url package-name))) - (and=> module-meta (cut description->package repo <>)))) + (let* ((url (case repo + ((cran) %cran-url) + ((bioconductor) %bioconductor-svn-url))) + (module-meta (fetch-description url package-name))) + (and=> module-meta (cut description->package repo <>)))))) + +(define* (recursive-import package-name #:optional (repo 'cran)) + "Generate a stream of package expressions for PACKAGE-NAME and all its +dependencies." + (receive (package . dependencies) + (cran->guix-package package-name repo) + (if (not package) + stream-null + + ;; Generate a lazy stream of package expressions for all unknown + ;; dependencies in the graph. + (let* ((make-state (lambda (queue done) + (cons queue done))) + (next (match-lambda + (((next . rest) . done) next))) + (imported (match-lambda + ((queue . done) done))) + (done? (match-lambda + ((queue . done) + (zero? (length queue))))) + (unknown? (lambda* (dependency #:optional (done '())) + (and (not (member dependency + done)) + (null? (find-packages-by-name + (guix-name dependency)))))) + (update (lambda (state new-queue) + (match state + (((head . tail) . done) + (make-state (lset-difference + equal? + (lset-union equal? new-queue tail) + done) + (cons head done))))))) + (stream-cons + package + (stream-unfold + ;; map: produce a stream element + (lambda (state) + (cran->guix-package (next state) repo)) + + ;; predicate + (compose not done?) + + ;; generator: update the queue + (lambda (state) + (receive (package . dependencies) + (cran->guix-package (next state) repo) + (if package + (update state (filter (cut unknown? <> + (cons (next state) + (imported state))) + (car dependencies))) + ;; TODO: Try the other archives before giving up + (update state (imported state))))) + + ;; initial state + (make-state (filter unknown? (car dependencies)) + (list package-name)))))))) ;;; -- cgit v1.2.3 From fdbc84b056683204c5832d3740d9b109f31f7cb9 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Sat, 17 Dec 2016 15:24:45 +0100 Subject: import cran: Handle HTTP errors. Fixes . * guix/import/cran.scm (fetch-description): Return #f in case of HTTP errors. --- guix/import/cran.scm | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'guix/import') diff --git a/guix/import/cran.scm b/guix/import/cran.scm index 123abfe7ea..463a25514e 100644 --- a/guix/import/cran.scm +++ b/guix/import/cran.scm @@ -23,8 +23,10 @@ #:use-module ((ice-9 rdelim) #:select (read-string)) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-34) #:use-module (srfi srfi-41) #:use-module (ice-9 receive) + #:use-module (web uri) #:use-module (guix combinators) #:use-module (guix http-client) #:use-module (guix hash) @@ -128,10 +130,18 @@ package definition." (define (fetch-description base-url name) "Return an alist of the contents of the DESCRIPTION file for the R package -NAME, or #f on failure. NAME is case-sensitive." +NAME, or #f in case of failure. NAME is case-sensitive." ;; This API always returns the latest release of the module. (let ((url (string-append base-url name "/DESCRIPTION"))) - (description->alist (read-string (http-fetch url))))) + (guard (c ((http-get-error? c) + (format (current-error-port) + "error: failed to retrieve package information \ +from ~s: ~a (~s)~%" + (uri->string (http-get-error-uri c)) + (http-get-error-code c) + (http-get-error-reason c)) + #f)) + (description->alist (read-string (http-fetch url)))))) (define (listify meta field) "Look up FIELD in the alist META. If FIELD contains a comma-separated -- cgit v1.2.3 From 4cb7786eff9b9188169ed2c2e5af53903962e7d1 Mon Sep 17 00:00:00 2001 From: Marius Bakke Date: Tue, 20 Dec 2016 12:44:45 +0100 Subject: import: pypi: Match new 'pypi-uri' domain in updater. * guix/import/pypi.scm (pypi-package?): Match pypi.io domain. --- guix/import/pypi.scm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'guix/import') diff --git a/guix/import/pypi.scm b/guix/import/pypi.scm index 9794ff9757..7cce0fc594 100644 --- a/guix/import/pypi.scm +++ b/guix/import/pypi.scm @@ -303,7 +303,8 @@ VERSION, SOURCE-URL, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE." "Return true if PACKAGE is a Python package from PyPI." (define (pypi-url? url) - (string-prefix? "https://pypi.python.org/" url)) + (or (string-prefix? "https://pypi.python.org/" url) + (string-prefix? "https://pypi.io/packages" url))) (let ((source-url (and=> (package-source package) origin-uri)) (fetch-method (and=> (package-source package) origin-method))) -- cgit v1.2.3 From 62bd24db39a86f80242f923eb4cc2f18f3b02c67 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Tue, 20 Dec 2016 19:08:22 +0100 Subject: import: github: Use 'json-fetch'. * guix/import/github.scm (json-fetch*): Remove. (latest-released-version): Adjust accordingly. --- guix/import/github.scm | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) (limited to 'guix/import') diff --git a/guix/import/github.scm b/guix/import/github.scm index 0843ddeefd..01452b12e3 100644 --- a/guix/import/github.scm +++ b/guix/import/github.scm @@ -23,23 +23,12 @@ #:use-module (guix utils) #:use-module ((guix download) #:prefix download:) #:use-module (guix import utils) + #:use-module (guix import json) #:use-module (guix packages) #:use-module (guix upstream) #:use-module (web uri) #:export (%github-updater)) -(define (json-fetch* url) - "Return a list/hash representation of the JSON resource URL, or #f on -failure." - (call-with-output-file "/dev/null" - (lambda (null) - (with-error-to-port null - (lambda () - (call-with-temporary-output-file - (lambda (temp port) - (and (url-fetch url temp) - (call-with-input-file temp json->scm))))))))) - (define (find-extension url) "Return the extension of the archive e.g. '.tar.gz' given a URL, or false if none is recognized" @@ -136,7 +125,7 @@ the package e.g. 'bedtools2'. Return #f if there is no releases" "https://api.github.com/repos/" (github-user-slash-repository url) "/releases")) - (json (json-fetch* + (json (json-fetch (if token (string-append api-url "?access_token=" token) api-url)))) -- cgit v1.2.3 From 36225d4feff2f5582c05239b49433627997d2f2a Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Wed, 14 Dec 2016 12:31:12 +1100 Subject: import: elpa: Fix call-with-downloaded-file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/import/elpa.scm (call-with-downloaded-file): Make function behaviour match documentation string. Signed-off-by: Ludovic Courtès --- guix/import/elpa.scm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'guix/import') diff --git a/guix/import/elpa.scm b/guix/import/elpa.scm index 320a09e8c6..ec232cd8a3 100644 --- a/guix/import/elpa.scm +++ b/guix/import/elpa.scm @@ -89,7 +89,13 @@ NAMES (strings)." "Fetch URL, store the content in a temporary file and call PROC with that file. Returns the value returned by PROC. On error call ERROR-THUNK and return its value or leave if it's false." - (proc (http-fetch/cached (string->uri url)))) + (catch #t + (lambda () + (proc (http-fetch/cached (string->uri url)))) + (lambda (key . args) + (if error-thunk + (error-thunk) + (leave (_ "~A: download failed~%") url))))) (define (is-elpa-package? name elpa-pkg-spec) "Return true if the string NAME corresponds to the name of the package -- cgit v1.2.3 From 681a555b837d766848baacbed5750e9d30314709 Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Wed, 14 Dec 2016 12:34:15 +1100 Subject: import: elpa: Import dependencies as propagated-inputs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/import/elpa.scm (elpa-package->sexp): Import dependencies as propagated-inputs. Signed-off-by: Ludovic Courtès --- guix/import/elpa.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guix/import') diff --git a/guix/import/elpa.scm b/guix/import/elpa.scm index ec232cd8a3..96cf5bbae6 100644 --- a/guix/import/elpa.scm +++ b/guix/import/elpa.scm @@ -228,7 +228,7 @@ type ''." (bytevector->nix-base32-string (file-sha256 tarball)) "failed to download package"))))) (build-system emacs-build-system) - ,@(maybe-inputs 'inputs dependencies) + ,@(maybe-inputs 'propagated-inputs dependencies) (home-page ,(elpa-package-home-page pkg)) (synopsis ,(elpa-package-synopsis pkg)) (description ,(elpa-package-description pkg)) -- cgit v1.2.3 From f53a5514e0e9535d2e7c668803e64b4aac17da2b Mon Sep 17 00:00:00 2001 From: David Craven Date: Sun, 1 Jan 2017 16:14:45 +0100 Subject: import: crate: Provide a default home-page value. * guix/import/crate.scm (make-crate-sexp): Provide a default home-page value. * tests/crate.scm (test-crate): Add repository field. Problem reported by ng0 . --- guix/import/crate.scm | 12 +++++++++--- tests/crate.scm | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'guix/import') diff --git a/guix/import/crate.scm b/guix/import/crate.scm index 3a19fc70cf..33cc6104c5 100644 --- a/guix/import/crate.scm +++ b/guix/import/crate.scm @@ -55,7 +55,8 @@ (crate (assoc-ref crate-json "crate")) (name (assoc-ref crate "name")) (version (assoc-ref crate "max_version")) - (home-page (assoc-ref crate "homepage")) + (homepage (assoc-ref crate "homepage")) + (repository (assoc-ref crate "repository")) (synopsis (assoc-ref crate "description")) (description (assoc-ref crate "description")) (license (string->license (assoc-ref crate "license"))) @@ -67,7 +68,10 @@ (filter (lambda (dep) (not ((crate-kind-predicate "normal") dep))) deps)) (inputs (crates->inputs input-crates)) - (native-inputs (crates->inputs native-input-crates))) + (native-inputs (crates->inputs native-input-crates)) + (home-page (match homepage + (() repository) + (_ homepage)))) (callback #:name name #:version version #:inputs inputs #:native-inputs native-inputs #:home-page home-page #:synopsis synopsis @@ -95,7 +99,9 @@ VERSION, INPUTS, NATIVE-INPUTS, HOME-PAGE, SYNOPSIS, DESCRIPTION, and LICENSE." (build-system cargo-build-system) ,@(maybe-native-inputs native-inputs) ,@(maybe-inputs inputs) - (home-page ,home-page) + (home-page ,(match home-page + (() "") + (_ home-page))) (synopsis ,synopsis) (description ,(beautify-description description)) (license ,(match license diff --git a/tests/crate.scm b/tests/crate.scm index 18d5f72a8c..6f6fc2bc29 100644 --- a/tests/crate.scm +++ b/tests/crate.scm @@ -35,6 +35,7 @@ \"license\": \"MIT/Apache-2.0\", \"description\": \"summary\", \"homepage\": \"http://example.com\", + \"repository\": \"http://example.com\", } }") -- cgit v1.2.3 From f1d136957d0d5634e60e5389a046a917169cdb9e Mon Sep 17 00:00:00 2001 From: David Craven Date: Thu, 29 Dec 2016 16:29:24 +0100 Subject: build-system: cargo: Handle Cargo.lock file not present. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * guix/build-system/cargo.scm (cargo-build): Add src output. (private-keywords): Add #:outputs. * guix/build/cargo-build-system.scm (configure): Use /share/rust-source when replacing inputs. (build, check): Don't do anything when there isn't a Cargo.lock file present. (install): Install sources to src output. When a Cargo.lock file is present use cargo install to install binaries to out. * guix/import/crate.scm (make-crate-sexp): Importer uses the src output for crate inputs by default. * guix/import/utils.scm (package-names->package-inputs, maybe-inputs, maybe-native-inputs): Take an optional output argument. * tests/crate.scm (crate->guix-package test): Update. Problem reported by Francisco Gómez García . --- guix/build-system/cargo.scm | 4 ++-- guix/build/cargo-build-system.scm | 20 ++++++++++++-------- guix/import/crate.scm | 4 ++-- guix/import/utils.scm | 14 ++++++++------ tests/crate.scm | 2 +- 5 files changed, 25 insertions(+), 19 deletions(-) (limited to 'guix/import') diff --git a/guix/build-system/cargo.scm b/guix/build-system/cargo.scm index 8d835dda1d..ffc0afda3b 100644 --- a/guix/build-system/cargo.scm +++ b/guix/build-system/cargo.scm @@ -109,7 +109,7 @@ to NAME and VERSION." #:inputs inputs #:system system #:modules imported-modules - #:outputs outputs + #:outputs (cons "src" outputs) #:guile-for-build guile-for-build)) (define* (lower name @@ -121,7 +121,7 @@ to NAME and VERSION." "Return a bag for NAME." (define private-keywords - '(#:source #:target #:cargo #:rustc #:inputs #:native-inputs)) + '(#:source #:target #:cargo #:rustc #:inputs #:native-inputs #:outputs)) (and (not target) ;; TODO: support cross-compilation (bag diff --git a/guix/build/cargo-build-system.scm b/guix/build/cargo-build-system.scm index 4fa29b4cd3..7d656a8d58 100644 --- a/guix/build/cargo-build-system.scm +++ b/guix/build/cargo-build-system.scm @@ -54,7 +54,7 @@ (when (and crate path) (match (string-split (basename path) #\-) ((_ ... version) - (format port "\"~a:~a\" = { path = \"~a/rustsrc\" }~%" + (format port "\"~a:~a\" = { path = \"~a/share/rust-source\" }~%" crate version path))))))) inputs) (close-port port)) @@ -63,19 +63,22 @@ (define* (build #:key (cargo-build-flags '("--release" "--frozen")) #:allow-other-keys) "Build a given Cargo package." - (zero? (apply system* `("cargo" "build" ,@cargo-build-flags)))) + (if (file-exists? "Cargo.lock") + (zero? (apply system* `("cargo" "build" ,@cargo-build-flags))) + #t)) (define* (check #:key tests? #:allow-other-keys) "Run tests for a given Cargo package." - (when tests? - (zero? (system* "cargo" "test")))) + (if (and tests? (file-exists? "Cargo.lock")) + (zero? (system* "cargo" "test")) + #t)) (define* (install #:key inputs outputs #:allow-other-keys) "Install a given Cargo package." (let* ((out (assoc-ref outputs "out")) (src (assoc-ref inputs "source")) - (bin (string-append out "/bin")) - (rsrc (string-append out "/rustsrc"))) + (rsrc (string-append (assoc-ref outputs "src") + "/share/rust-source"))) (mkdir-p rsrc) ;; Rust doesn't have a stable ABI yet. Because of this ;; Cargo doesn't have a search path for binaries yet. @@ -87,8 +90,9 @@ ;; When the package includes executables we install ;; it using cargo install. This fails when the crate ;; doesn't contain an executable. - (system* "cargo" "install" "--root" bin) - #t)) + (if (file-exists? "Cargo.lock") + (system* "cargo" "install" "--root" out) + (mkdir out)))) (define %standard-phases ;; 'configure' phase is not needed. diff --git a/guix/import/crate.scm b/guix/import/crate.scm index 33cc6104c5..233a20e983 100644 --- a/guix/import/crate.scm +++ b/guix/import/crate.scm @@ -97,8 +97,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) - ,@(maybe-inputs inputs) + ,@(maybe-native-inputs native-inputs "src") + ,@(maybe-inputs inputs "src") (home-page ,(match home-page (() "") (_ home-page))) diff --git a/guix/import/utils.scm b/guix/import/utils.scm index f304da20e6..be1980d08f 100644 --- a/guix/import/utils.scm +++ b/guix/import/utils.scm @@ -211,24 +211,26 @@ into a proper sentence and by using two spaces between sentences." (regexp-substitute/global #f "\\. \\b" cleaned 'pre ". " 'post))) -(define (package-names->package-inputs names) +(define* (package-names->package-inputs names #:optional (output #f)) (map (lambda (input) - (list input (list 'unquote (string->symbol input)))) + (cons* input (list 'unquote (string->symbol input)) + (or (and output (list output)) + '()))) names)) -(define (maybe-inputs package-names) +(define* (maybe-inputs package-names #:optional (output #f)) "Given a list of PACKAGE-NAMES, tries to generate the 'inputs' field of a package definition." - (match (package-names->package-inputs package-names) + (match (package-names->package-inputs package-names output) (() '()) ((package-inputs ...) `((inputs (,'quasiquote ,package-inputs)))))) -(define (maybe-native-inputs package-names) +(define* (maybe-native-inputs package-names #:optional (output #f)) "Given a list of PACKAGE-NAMES, tries to generate the 'inputs' field of a package definition." - (match (package-names->package-inputs package-names) + (match (package-names->package-inputs package-names output) (() '()) ((package-inputs ...) diff --git a/tests/crate.scm b/tests/crate.scm index 6f6fc2bc29..0bb344bb8a 100644 --- a/tests/crate.scm +++ b/tests/crate.scm @@ -91,7 +91,7 @@ ('build-system 'cargo-build-system) ('inputs ('quasiquote - (("rust-bar" ('unquote 'rust-bar))))) + (("rust-bar" ('unquote 'rust-bar) "src")))) ('home-page "http://example.com") ('synopsis "summary") ('description "summary") -- cgit v1.2.3