2014-09-27 16:16:23 +02:00
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2020-03-12 11:13:33 +01:00
|
|
|
;;; Copyright © 2012, 2013, 2018, 2019, 2020 Ludovic Courtès <ludo@gnu.org>
|
2016-09-22 11:33:46 +02:00
|
|
|
;;; Copyright © 2016 Jelle Licht <jlicht@fsfe.org>
|
2016-09-22 11:35:13 +02:00
|
|
|
;;; Copyright © 2016 David Craven <david@craven.ch>
|
2020-04-15 00:41:03 +02:00
|
|
|
;;; Copyright © 2017, 2019, 2020 Ricardo Wurmus <rekado@elephly.net>
|
2018-06-08 12:46:43 +02:00
|
|
|
;;; Copyright © 2018 Oleg Pykhalov <go.wigust@gmail.com>
|
2019-05-27 22:07:31 +02:00
|
|
|
;;; Copyright © 2019 Robert Vollmert <rob@vllmrt.net>
|
2020-10-15 18:32:59 +02:00
|
|
|
;;; Copyright © 2020 Helio Machado <0x2b3bfa0+guix@googlemail.com>
|
2020-02-04 13:18:18 +01:00
|
|
|
;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
|
2021-03-05 15:21:14 +01:00
|
|
|
;;; Copyright © 2021 Maxim Cournoyer <maxim.cournoyer@gmail.com>
|
2021-08-06 20:05:16 +02:00
|
|
|
;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
|
2021-12-17 14:10:30 +01:00
|
|
|
;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
|
2022-01-26 09:27:12 +01:00
|
|
|
;;; Copyright © 2022 Alice Brenon <alice.brenon@ens-lyon.fr>
|
2022-05-23 00:28:04 +02:00
|
|
|
;;; Copyright © 2022 Kyle Meyer <kyle@kyleam.com>
|
2014-09-27 16:16:23 +02:00
|
|
|
;;;
|
|
|
|
;;; 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
(define-module (guix import utils)
|
2015-08-17 03:09:19 +02:00
|
|
|
#:use-module (guix base32)
|
2016-09-22 11:25:31 +02:00
|
|
|
#:use-module ((guix build download) #:prefix build:)
|
2020-05-19 15:55:08 +02:00
|
|
|
#:use-module ((gcrypt hash) #:hide (sha256))
|
2016-12-10 18:43:39 +01:00
|
|
|
#:use-module (guix http-client)
|
2016-08-05 19:15:56 +02:00
|
|
|
#:use-module ((guix licenses) #:prefix license:)
|
2015-01-08 21:38:54 +01:00
|
|
|
#:use-module (guix utils)
|
2017-08-27 17:38:47 +02:00
|
|
|
#:use-module (guix packages)
|
|
|
|
#:use-module (guix discovery)
|
|
|
|
#:use-module (guix build-system)
|
|
|
|
#:use-module (guix gexp)
|
2022-01-26 09:27:12 +01:00
|
|
|
#:use-module ((guix i18n) #:select (G_))
|
2017-08-27 17:38:47 +02:00
|
|
|
#:use-module (guix store)
|
|
|
|
#:use-module (guix download)
|
2019-12-10 20:13:04 +01:00
|
|
|
#:use-module (guix sets)
|
2022-01-26 09:27:12 +01:00
|
|
|
#:use-module ((guix ui) #:select (fill-paragraph))
|
2017-08-27 17:38:47 +02:00
|
|
|
#:use-module (gnu packages)
|
2016-09-22 11:25:31 +02:00
|
|
|
#:use-module (ice-9 match)
|
2017-11-06 16:53:39 +01:00
|
|
|
#:use-module (ice-9 rdelim)
|
|
|
|
#:use-module (ice-9 receive)
|
2016-09-22 11:25:31 +02:00
|
|
|
#:use-module (ice-9 regex)
|
|
|
|
#:use-module (srfi srfi-1)
|
2019-12-10 20:13:04 +01:00
|
|
|
#:use-module (srfi srfi-9)
|
2017-08-27 17:38:47 +02:00
|
|
|
#:use-module (srfi srfi-11)
|
2018-06-08 12:46:43 +02:00
|
|
|
#:use-module (srfi srfi-26)
|
2020-02-04 13:18:18 +01:00
|
|
|
#:use-module (srfi srfi-71)
|
2015-01-08 21:38:54 +01:00
|
|
|
#:export (factorize-uri
|
|
|
|
|
|
|
|
flatten
|
|
|
|
|
2015-08-17 03:09:19 +02:00
|
|
|
url-fetch
|
|
|
|
guix-hash-url
|
|
|
|
|
2019-05-17 09:26:07 +02:00
|
|
|
package-names->package-inputs
|
2016-12-10 18:43:39 +01:00
|
|
|
maybe-inputs
|
|
|
|
maybe-native-inputs
|
2021-03-05 15:21:14 +01:00
|
|
|
maybe-propagated-inputs
|
2016-12-10 18:43:39 +01:00
|
|
|
package->definition
|
|
|
|
|
2016-09-22 11:33:46 +02:00
|
|
|
spdx-string->license
|
2015-08-17 03:09:19 +02:00
|
|
|
license->symbol
|
|
|
|
|
2016-01-05 15:09:19 +01:00
|
|
|
snake-case
|
2017-08-27 17:38:47 +02:00
|
|
|
beautify-description
|
|
|
|
|
2017-11-06 16:53:39 +01:00
|
|
|
alist->package
|
|
|
|
|
|
|
|
read-lines
|
2018-06-08 12:46:43 +02:00
|
|
|
chunk-lines
|
|
|
|
|
|
|
|
guix-name
|
|
|
|
|
|
|
|
recursive-import))
|
2014-09-27 16:16:23 +02:00
|
|
|
|
|
|
|
(define (factorize-uri uri version)
|
|
|
|
"Factorize URI, a package tarball URI as a string, such that any occurrences
|
|
|
|
of the string VERSION is replaced by the symbol 'version."
|
|
|
|
(let ((version-rx (make-regexp (regexp-quote version))))
|
|
|
|
(match (regexp-exec version-rx uri)
|
|
|
|
(#f
|
|
|
|
uri)
|
|
|
|
(_
|
|
|
|
(let ((indices (fold-matches version-rx uri
|
|
|
|
'((0))
|
|
|
|
(lambda (m result)
|
|
|
|
(match result
|
|
|
|
(((start) rest ...)
|
|
|
|
`((,(match:end m))
|
|
|
|
(,start . ,(match:start m))
|
|
|
|
,@rest)))))))
|
|
|
|
(fold (lambda (index result)
|
|
|
|
(match index
|
|
|
|
((start)
|
|
|
|
(cons (substring uri start)
|
|
|
|
result))
|
|
|
|
((start . end)
|
|
|
|
(cons* (substring uri start end)
|
|
|
|
'version
|
|
|
|
result))))
|
|
|
|
'()
|
|
|
|
indices))))))
|
2015-01-08 21:38:54 +01:00
|
|
|
|
|
|
|
(define (flatten lst)
|
|
|
|
"Return a list that recursively concatenates all sub-lists of LST."
|
|
|
|
(fold-right
|
|
|
|
(match-lambda*
|
|
|
|
(((sub-list ...) memo)
|
|
|
|
(append (flatten sub-list) memo))
|
|
|
|
((elem memo)
|
|
|
|
(cons elem memo)))
|
|
|
|
'() lst))
|
|
|
|
|
|
|
|
(define (url-fetch url file-name)
|
|
|
|
"Save the contents of URL to FILE-NAME. Return #f on failure."
|
|
|
|
(parameterize ((current-output-port (current-error-port)))
|
|
|
|
(build:url-fetch url file-name)))
|
2015-08-17 03:09:19 +02:00
|
|
|
|
|
|
|
(define (guix-hash-url filename)
|
|
|
|
"Return the hash of FILENAME in nix-base32 format."
|
|
|
|
(bytevector->nix-base32-string (file-sha256 filename)))
|
|
|
|
|
2016-09-22 11:33:46 +02:00
|
|
|
(define (spdx-string->license str)
|
|
|
|
"Convert STR, a SPDX formatted license identifier, to a license object.
|
|
|
|
Return #f if STR does not match any known identifiers."
|
|
|
|
;; https://spdx.org/licenses/
|
2022-04-27 07:39:27 +02:00
|
|
|
;; The gfl1.0, nmap, repoze
|
2016-09-22 11:33:46 +02:00
|
|
|
;; licenses doesn't have SPDX identifiers
|
2020-10-15 18:32:59 +02:00
|
|
|
;;
|
|
|
|
;; Please update guix/licenses.scm when modifying
|
|
|
|
;; this list to avoid mismatches.
|
2015-08-17 03:09:19 +02:00
|
|
|
(match str
|
2021-08-10 17:07:19 +02:00
|
|
|
;; "GPL-N+" has been deprecated in favour of "GPL-N-or-later".
|
|
|
|
;; "GPL-N" has been deprecated in favour of "GPL-N-only"
|
|
|
|
;; or "GPL-N-or-later" as appropriate. Likewise for LGPL
|
|
|
|
;; and AGPL
|
2020-10-15 18:32:59 +02:00
|
|
|
("AGPL-1.0" 'license:agpl1)
|
2022-04-27 07:39:27 +02:00
|
|
|
("AGPL-1.0-only" 'license:agpl1)
|
2020-10-15 18:32:59 +02:00
|
|
|
("AGPL-3.0" 'license:agpl3)
|
2021-08-10 17:07:19 +02:00
|
|
|
("AGPL-3.0-only" 'license:agpl3)
|
|
|
|
("AGPL-3.0-or-later" 'license:agpl3+)
|
2016-09-22 11:33:46 +02:00
|
|
|
("Apache-1.1" 'license:asl1.1)
|
|
|
|
("Apache-2.0" 'license:asl2.0)
|
2022-04-27 07:39:27 +02:00
|
|
|
("APSL-2.0" 'license:apsl2)
|
2016-09-22 11:33:46 +02:00
|
|
|
("BSL-1.0" 'license:boost1.0)
|
2021-02-26 00:57:15 +01:00
|
|
|
("0BSD" 'license:bsd-0)
|
2022-04-27 07:39:27 +02:00
|
|
|
("BSD-2-Clause" 'license:bsd-2)
|
|
|
|
("BSD-2-Clause-FreeBSD" 'license:bsd-2) ;flagged as deprecated on spdx
|
2016-09-22 11:33:46 +02:00
|
|
|
("BSD-3-Clause" 'license:bsd-3)
|
|
|
|
("BSD-4-Clause" 'license:bsd-4)
|
|
|
|
("CC0-1.0" 'license:cc0)
|
|
|
|
("CC-BY-2.0" 'license:cc-by2.0)
|
|
|
|
("CC-BY-3.0" 'license:cc-by3.0)
|
2021-11-02 11:57:29 +01:00
|
|
|
("CC-BY-4.0" 'license:cc-by4.0)
|
2016-09-22 11:33:46 +02:00
|
|
|
("CC-BY-SA-2.0" 'license:cc-by-sa2.0)
|
|
|
|
("CC-BY-SA-3.0" 'license:cc-by-sa3.0)
|
|
|
|
("CC-BY-SA-4.0" 'license:cc-by-sa4.0)
|
|
|
|
("CDDL-1.0" 'license:cddl1.0)
|
2022-04-27 07:39:27 +02:00
|
|
|
("CDDL-1.1" 'license:cddl1.1)
|
|
|
|
("CECILL-2.1" 'license:cecill)
|
|
|
|
("CECILL-B" 'license:cecill-b)
|
2016-09-22 11:33:46 +02:00
|
|
|
("CECILL-C" 'license:cecill-c)
|
|
|
|
("Artistic-2.0" 'license:artistic2.0)
|
|
|
|
("ClArtistic" 'license:clarified-artistic)
|
2022-04-27 07:39:27 +02:00
|
|
|
("copyleft-next-0.3.0" 'license:copyleft-next)
|
2016-09-22 11:33:46 +02:00
|
|
|
("CPL-1.0" 'license:cpl1.0)
|
|
|
|
("EPL-1.0" 'license:epl1.0)
|
2022-04-27 07:39:27 +02:00
|
|
|
("EPL-2.0" 'license:epl2.0)
|
|
|
|
("EUPL-1.2" 'license:eupl1.2)
|
2016-09-22 11:33:46 +02:00
|
|
|
("MIT" 'license:expat)
|
2022-05-23 00:28:04 +02:00
|
|
|
("MIT-0" 'license:expat-0)
|
2016-09-22 11:33:46 +02:00
|
|
|
("FTL" 'license:freetype)
|
2022-04-27 07:39:27 +02:00
|
|
|
("FreeBSD-DOC" 'license:freebsd-doc)
|
2021-11-02 11:57:29 +01:00
|
|
|
("Freetype" 'license:freetype)
|
2022-04-27 07:39:27 +02:00
|
|
|
("FSFAP" 'license:fsf-free)
|
|
|
|
("FSFUL" 'license:fsf-free)
|
2016-09-22 11:33:46 +02:00
|
|
|
("GFDL-1.1" 'license:fdl1.1+)
|
2022-04-27 07:39:27 +02:00
|
|
|
("GFDL-1.1-or-later" 'license:fdl1.1+)
|
2016-09-22 11:33:46 +02:00
|
|
|
("GFDL-1.2" 'license:fdl1.2+)
|
2022-04-27 07:39:27 +02:00
|
|
|
("GFDL-1.2-or-later" 'license:fdl1.2+)
|
2016-09-22 11:33:46 +02:00
|
|
|
("GFDL-1.3" 'license:fdl1.3+)
|
2022-04-27 07:39:27 +02:00
|
|
|
("GFDL-1.3-or-later" 'license:fdl1.3+)
|
2016-09-22 11:33:46 +02:00
|
|
|
("Giftware" 'license:giftware)
|
|
|
|
("GPL-1.0" 'license:gpl1)
|
2021-08-10 17:07:19 +02:00
|
|
|
("GPL-1.0-only" 'license:gpl1)
|
2016-09-22 11:33:46 +02:00
|
|
|
("GPL-1.0+" 'license:gpl1+)
|
2021-08-10 17:07:19 +02:00
|
|
|
("GPL-1.0-or-later" 'license:gpl1+)
|
2016-09-22 11:33:46 +02:00
|
|
|
("GPL-2.0" 'license:gpl2)
|
2021-08-10 17:07:19 +02:00
|
|
|
("GPL-2.0-only" 'license:gpl2)
|
2016-09-22 11:33:46 +02:00
|
|
|
("GPL-2.0+" 'license:gpl2+)
|
2021-08-10 17:07:19 +02:00
|
|
|
("GPL-2.0-or-later" 'license:gpl2+)
|
2016-09-22 11:33:46 +02:00
|
|
|
("GPL-3.0" 'license:gpl3)
|
2021-08-10 17:07:19 +02:00
|
|
|
("GPL-3.0-only" 'license:gpl3)
|
2016-09-22 11:33:46 +02:00
|
|
|
("GPL-3.0+" 'license:gpl3+)
|
2021-08-10 17:07:19 +02:00
|
|
|
("GPL-3.0-or-later" 'license:gpl3+)
|
2021-11-02 11:57:29 +01:00
|
|
|
("HPND" 'license:hpnd)
|
2016-09-22 11:33:46 +02:00
|
|
|
("ISC" 'license:isc)
|
|
|
|
("IJG" 'license:ijg)
|
|
|
|
("Imlib2" 'license:imlib2)
|
|
|
|
("IPA" 'license:ipa)
|
|
|
|
("IPL-1.0" 'license:ibmpl1.0)
|
2021-03-28 10:40:20 +02:00
|
|
|
("LAL-1.3" 'license:lal1.3)
|
2016-09-22 11:33:46 +02:00
|
|
|
("LGPL-2.0" 'license:lgpl2.0)
|
2021-08-10 17:07:19 +02:00
|
|
|
("LGPL-2.0-only" 'license:lgpl2.0)
|
2016-09-22 11:33:46 +02:00
|
|
|
("LGPL-2.0+" 'license:lgpl2.0+)
|
2021-08-10 17:07:19 +02:00
|
|
|
("LGPL-2.0-or-later" 'license:lgpl2.0+)
|
2016-09-22 11:33:46 +02:00
|
|
|
("LGPL-2.1" 'license:lgpl2.1)
|
2021-08-10 17:07:19 +02:00
|
|
|
("LGPL-2.1-only" 'license:lgpl2.1)
|
2016-09-22 11:33:46 +02:00
|
|
|
("LGPL-2.1+" 'license:lgpl2.1+)
|
2021-08-10 17:07:19 +02:00
|
|
|
("LGPL-2.1-or-later" 'license:lgpl2.1+)
|
2020-10-15 18:32:59 +02:00
|
|
|
("LGPL-3.0" 'license:lgpl3)
|
2021-08-10 17:07:19 +02:00
|
|
|
("LGPL-3.0-only" 'license:lgpl3)
|
2020-10-15 18:32:59 +02:00
|
|
|
("LGPL-3.0+" 'license:lgpl3+)
|
2021-08-10 17:07:19 +02:00
|
|
|
("LGPL-3.0-or-later" 'license:lgpl3+)
|
2022-04-27 07:39:27 +02:00
|
|
|
("LPPL-1.0" 'license:lppl)
|
|
|
|
("LPPL-1.1" 'license:lppl)
|
|
|
|
("LPPL-1.2" 'license:lppl1.2)
|
|
|
|
("LPPL-1.3a" 'license:lppl1.3a)
|
|
|
|
("LPPL-1.3c" 'license:lppl1.3c)
|
|
|
|
("MirOS" 'license:miros)
|
2016-09-22 11:33:46 +02:00
|
|
|
("MPL-1.0" 'license:mpl1.0)
|
|
|
|
("MPL-1.1" 'license:mpl1.1)
|
|
|
|
("MPL-2.0" 'license:mpl2.0)
|
|
|
|
("MS-PL" 'license:ms-pl)
|
|
|
|
("NCSA" 'license:ncsa)
|
2022-04-27 07:39:27 +02:00
|
|
|
("OGL-UK-1.0" 'license:ogl-psi1.0)
|
2016-09-22 11:33:46 +02:00
|
|
|
("OpenSSL" 'license:openssl)
|
|
|
|
("OLDAP-2.8" 'license:openldap2.8)
|
2022-04-27 07:39:27 +02:00
|
|
|
("OPL-1.0" 'license:opl1.0+)
|
2020-10-15 18:32:59 +02:00
|
|
|
("CUA-OPL-1.0" 'license:cua-opl1.0)
|
2022-04-27 07:39:27 +02:00
|
|
|
("PSF-2.0" 'license:psfl)
|
|
|
|
("OSL-2.1" 'license:osl2.1)
|
2016-09-22 11:33:46 +02:00
|
|
|
("QPL-1.0" 'license:qpl)
|
|
|
|
("Ruby" 'license:ruby)
|
|
|
|
("SGI-B-2.0" 'license:sgifreeb2.0)
|
|
|
|
("OFL-1.1" 'license:silofl1.1)
|
|
|
|
("Sleepycat" 'license:sleepycat)
|
|
|
|
("TCL" 'license:tcl/tk)
|
|
|
|
("Unlicense" 'license:unlicense)
|
|
|
|
("Vim" 'license:vim)
|
2022-04-27 07:39:27 +02:00
|
|
|
("W3C" 'license:w3c)
|
|
|
|
("WTFPL" 'license:wtfpl2)
|
|
|
|
("wxWindow" 'license:wxwindows3.1+) ;flagged as deprecated on spdx
|
2016-09-22 11:33:46 +02:00
|
|
|
("X11" 'license:x11)
|
|
|
|
("ZPL-2.1" 'license:zpl2.1)
|
|
|
|
("Zlib" 'license:zlib)
|
2015-08-17 03:09:19 +02:00
|
|
|
(_ #f)))
|
|
|
|
|
|
|
|
(define (license->symbol license)
|
|
|
|
"Convert license to a symbol representing the variable the object is bound
|
|
|
|
to in the (guix licenses) module, or #f if there is no such known license."
|
2016-09-22 11:35:13 +02:00
|
|
|
(define licenses
|
|
|
|
(module-map (lambda (sym var) `(,(variable-ref var) . ,sym))
|
|
|
|
(resolve-interface '(guix licenses) #:prefix 'license:)))
|
|
|
|
(assoc-ref licenses license))
|
2015-08-17 03:09:19 +02:00
|
|
|
|
|
|
|
(define (snake-case str)
|
|
|
|
"Return a downcased version of the string STR where underscores are replaced
|
|
|
|
with dashes."
|
|
|
|
(string-join (string-split (string-downcase str) #\_) "-"))
|
2016-01-05 15:09:19 +01:00
|
|
|
|
2021-12-17 14:10:30 +01:00
|
|
|
(define* (beautify-description description #:optional (length 80))
|
|
|
|
"Improve the package DESCRIPTION by turning a beginning sentence fragment into
|
|
|
|
a proper sentence and by using two spaces between sentences, and wrap lines at
|
|
|
|
LENGTH characters."
|
2019-09-14 00:36:51 +02:00
|
|
|
(let ((cleaned (cond
|
2022-01-26 09:27:12 +01:00
|
|
|
((not (string? description))
|
|
|
|
(G_ "This package lacks a description. Run \
|
|
|
|
\"info '(guix) Synopses and Descriptions'\" for more information."))
|
2019-09-14 00:36:51 +02:00
|
|
|
((string-prefix? "A " description)
|
|
|
|
(string-append "This package provides a"
|
|
|
|
(substring description 1)))
|
|
|
|
((string-prefix? "Provides " description)
|
|
|
|
(string-append "This package provides"
|
|
|
|
(substring description
|
|
|
|
(string-length "Provides"))))
|
|
|
|
((string-prefix? "Functions " description)
|
|
|
|
(string-append "This package provides functions"
|
|
|
|
(substring description
|
|
|
|
(string-length "Functions"))))
|
|
|
|
(else description))))
|
2016-01-05 15:09:19 +01:00
|
|
|
;; Use double spacing between sentences
|
2021-12-17 14:10:30 +01:00
|
|
|
(fill-paragraph (regexp-substitute/global #f "\\. \\b"
|
|
|
|
cleaned 'pre ". " 'post)
|
|
|
|
length)))
|
2016-12-10 18:43:39 +01:00
|
|
|
|
2016-12-29 16:29:24 +01:00
|
|
|
(define* (package-names->package-inputs names #:optional (output #f))
|
2020-02-04 09:50:48 +01:00
|
|
|
"Given a list of PACKAGE-NAMES or (PACKAGE-NAME VERSION) pairs, and an
|
|
|
|
optional OUTPUT, tries to generate a quoted list of inputs, as suitable to
|
|
|
|
use in an 'inputs' field of a package definition."
|
|
|
|
(define (make-input input version)
|
|
|
|
(cons* input (list 'unquote (string->symbol
|
|
|
|
(if version
|
|
|
|
(string-append input "-" version)
|
|
|
|
input)))
|
|
|
|
(or (and output (list output))
|
|
|
|
'())))
|
|
|
|
|
|
|
|
(map (match-lambda
|
|
|
|
((input version) (make-input input version))
|
|
|
|
(input (make-input input #f)))
|
2016-12-10 18:43:39 +01:00
|
|
|
names))
|
|
|
|
|
2021-03-05 15:21:14 +01:00
|
|
|
(define* (maybe-inputs package-names #:optional (output #f)
|
|
|
|
#:key (type #f))
|
2016-12-10 18:43:39 +01:00
|
|
|
"Given a list of PACKAGE-NAMES, tries to generate the 'inputs' field of a
|
2021-03-05 15:21:14 +01:00
|
|
|
package definition. TYPE can be used to specify the type of the inputs;
|
|
|
|
either the 'native or 'propagated symbols are accepted. Left unspecified, the
|
|
|
|
snippet generated is for regular inputs."
|
|
|
|
(let ((field-name (match type
|
|
|
|
('native 'native-inputs)
|
|
|
|
('propagated 'propagated-inputs)
|
|
|
|
(_ 'inputs))))
|
|
|
|
(match (package-names->package-inputs package-names output)
|
|
|
|
(()
|
|
|
|
'())
|
|
|
|
((package-inputs ...)
|
|
|
|
`((,field-name (,'quasiquote ,package-inputs)))))))
|
2016-12-10 18:43:39 +01:00
|
|
|
|
2016-12-29 16:29:24 +01:00
|
|
|
(define* (maybe-native-inputs package-names #:optional (output #f))
|
2021-03-05 15:21:14 +01:00
|
|
|
"Same as MAYBE-INPUTS, but for native inputs."
|
|
|
|
(maybe-inputs package-names output #:type 'native))
|
|
|
|
|
|
|
|
(define* (maybe-propagated-inputs package-names #:optional (output #f))
|
|
|
|
"Same as MAYBE-INPUTS, but for propagated inputs."
|
|
|
|
(maybe-inputs package-names output #:type 'propagated))
|
2016-12-10 18:43:39 +01:00
|
|
|
|
2020-11-14 21:31:33 +01:00
|
|
|
(define* (package->definition guix-package #:optional append-version?/string)
|
2021-03-21 05:16:22 +01:00
|
|
|
"If APPEND-VERSION?/STRING is #t, append the package's major+minor version.
|
|
|
|
If it is the symbol 'full, append the package's complete version. If
|
|
|
|
APPEND-VERSION?/string is a string, append this string."
|
2016-12-10 18:43:39 +01:00
|
|
|
(match guix-package
|
2020-02-04 13:18:18 +01:00
|
|
|
((or
|
|
|
|
('package ('name name) ('version version) . rest)
|
|
|
|
('let _ ('package ('name name) ('version version) . rest)))
|
|
|
|
|
2020-11-14 19:47:32 +01:00
|
|
|
`(define-public ,(string->symbol
|
2020-11-14 21:31:33 +01:00
|
|
|
(cond
|
|
|
|
((string? append-version?/string)
|
|
|
|
(string-append name "-" append-version?/string))
|
2020-12-09 19:49:00 +01:00
|
|
|
((eq? append-version?/string #t)
|
2020-11-14 21:31:33 +01:00
|
|
|
(string-append name "-" (version-major+minor version)))
|
2021-03-21 05:16:22 +01:00
|
|
|
((eq? 'full append-version?/string)
|
|
|
|
(string-append name "-" version))
|
2020-12-09 19:49:00 +01:00
|
|
|
(else name)))
|
2016-12-10 18:43:39 +01:00
|
|
|
,guix-package))))
|
2017-08-27 17:38:47 +02:00
|
|
|
|
|
|
|
(define (build-system-modules)
|
|
|
|
(all-modules (map (lambda (entry)
|
|
|
|
`(,entry . "guix/build-system"))
|
|
|
|
%load-path)))
|
|
|
|
|
|
|
|
(define (lookup-build-system-by-name name)
|
|
|
|
"Return a <build-system> value for the symbol NAME, representing the name of
|
|
|
|
the build system."
|
|
|
|
(fold-module-public-variables (lambda (obj result)
|
|
|
|
(if (and (build-system? obj)
|
|
|
|
(eq? name (build-system-name obj)))
|
|
|
|
obj result))
|
|
|
|
#f
|
|
|
|
(build-system-modules)))
|
|
|
|
|
|
|
|
(define (specs->package-lists specs)
|
|
|
|
"Convert each string in the SPECS list to a list of a package label and a
|
|
|
|
package value."
|
|
|
|
(map (lambda (spec)
|
|
|
|
(let-values (((pkg out) (specification->package+output spec)))
|
|
|
|
(match out
|
2019-06-07 22:55:50 +02:00
|
|
|
("out" (list (package-name pkg) pkg))
|
2017-08-27 17:38:47 +02:00
|
|
|
(_ (list (package-name pkg) pkg out)))))
|
|
|
|
specs))
|
|
|
|
|
|
|
|
(define (source-spec->object source)
|
|
|
|
"Generate an <origin> object from a SOURCE specification. The SOURCE can
|
|
|
|
either be a simple URL string, #F, or an alist containing entries for each of
|
|
|
|
the expected fields of an <origin> object."
|
|
|
|
(match source
|
|
|
|
((? string? source-url)
|
|
|
|
(let ((tarball (with-store store (download-to-store store source-url))))
|
|
|
|
(origin
|
|
|
|
(method url-fetch)
|
|
|
|
(uri source-url)
|
|
|
|
(sha256 (base32 (guix-hash-url tarball))))))
|
|
|
|
(#f #f)
|
|
|
|
(orig (let ((sha (match (assoc-ref orig "sha256")
|
|
|
|
((("base32" . value))
|
|
|
|
(base32 value))
|
|
|
|
(_ #f))))
|
|
|
|
(origin
|
|
|
|
(method (match (assoc-ref orig "method")
|
|
|
|
("url-fetch" (@ (guix download) url-fetch))
|
|
|
|
("git-fetch" (@ (guix git-download) git-fetch))
|
|
|
|
("svn-fetch" (@ (guix svn-download) svn-fetch))
|
|
|
|
("hg-fetch" (@ (guix hg-download) hg-fetch))
|
|
|
|
(_ #f)))
|
|
|
|
(uri (assoc-ref orig "uri"))
|
|
|
|
(sha256 sha))))))
|
|
|
|
|
2020-04-15 00:41:03 +02:00
|
|
|
(define* (alist->package meta #:optional (known-inputs '()))
|
|
|
|
"Return a package value generated from the alist META. If the list of
|
|
|
|
strings KNOWN-INPUTS is provided, do not treat the mentioned inputs as
|
|
|
|
specifications to look up and replace them with plain symbols instead."
|
|
|
|
(define (process-inputs which)
|
|
|
|
(let-values (((regular known)
|
|
|
|
(lset-diff+intersection
|
|
|
|
string=?
|
|
|
|
(vector->list (or (assoc-ref meta which) #()))
|
|
|
|
known-inputs)))
|
|
|
|
(append (specs->package-lists regular)
|
|
|
|
(map string->symbol known))))
|
2020-04-16 21:44:21 +02:00
|
|
|
(define (process-arguments arguments)
|
|
|
|
(append-map (match-lambda
|
|
|
|
((key . value)
|
|
|
|
(list (symbol->keyword (string->symbol key)) value)))
|
|
|
|
arguments))
|
2017-08-27 17:38:47 +02:00
|
|
|
(package
|
|
|
|
(name (assoc-ref meta "name"))
|
|
|
|
(version (assoc-ref meta "version"))
|
|
|
|
(source (source-spec->object (assoc-ref meta "source")))
|
|
|
|
(build-system
|
|
|
|
(lookup-build-system-by-name
|
|
|
|
(string->symbol (assoc-ref meta "build-system"))))
|
2020-04-16 21:44:21 +02:00
|
|
|
(arguments
|
|
|
|
(or (and=> (assoc-ref meta "arguments")
|
|
|
|
process-arguments)
|
|
|
|
'()))
|
2020-04-15 00:41:03 +02:00
|
|
|
(native-inputs (process-inputs "native-inputs"))
|
|
|
|
(inputs (process-inputs "inputs"))
|
|
|
|
(propagated-inputs (process-inputs "propagated-inputs"))
|
2017-08-27 17:38:47 +02:00
|
|
|
(home-page
|
|
|
|
(assoc-ref meta "home-page"))
|
|
|
|
(synopsis
|
|
|
|
(assoc-ref meta "synopsis"))
|
|
|
|
(description
|
|
|
|
(assoc-ref meta "description"))
|
|
|
|
(license
|
2018-02-16 11:06:31 +01:00
|
|
|
(match (assoc-ref meta "license")
|
|
|
|
(#f #f)
|
|
|
|
(l
|
2020-12-27 12:05:24 +01:00
|
|
|
(or (false-if-exception
|
|
|
|
(module-ref (resolve-interface '(guix licenses))
|
|
|
|
(string->symbol l)))
|
|
|
|
(false-if-exception
|
|
|
|
(module-ref (resolve-interface '(guix licenses) #:prefix 'license:)
|
|
|
|
(spdx-string->license l)))
|
2018-02-16 11:06:31 +01:00
|
|
|
(license:fsdg-compatible l)))))))
|
2017-11-06 16:53:39 +01:00
|
|
|
|
|
|
|
(define* (read-lines #:optional (port (current-input-port)))
|
|
|
|
"Read lines from PORT and return them as a list."
|
|
|
|
(let loop ((line (read-line port))
|
|
|
|
(lines '()))
|
|
|
|
(if (eof-object? line)
|
|
|
|
(reverse lines)
|
|
|
|
(loop (read-line port)
|
|
|
|
(cons line lines)))))
|
|
|
|
|
|
|
|
(define* (chunk-lines lines #:optional (pred string-null?))
|
|
|
|
"Return a list of chunks, each of which is a list of lines. The chunks are
|
|
|
|
separated by PRED."
|
|
|
|
(let loop ((rest lines)
|
|
|
|
(parts '()))
|
|
|
|
(receive (before after)
|
|
|
|
(break pred rest)
|
|
|
|
(let ((res (cons before parts)))
|
|
|
|
(if (null? after)
|
|
|
|
(reverse res)
|
|
|
|
(loop (cdr after) res))))))
|
2018-06-08 12:46:43 +02:00
|
|
|
|
|
|
|
(define (guix-name prefix name)
|
|
|
|
"Return a Guix package name for a given package name."
|
|
|
|
(string-append prefix (string-map (match-lambda
|
|
|
|
(#\_ #\-)
|
|
|
|
(#\. #\-)
|
|
|
|
(chr (char-downcase chr)))
|
|
|
|
name)))
|
|
|
|
|
2019-12-10 20:13:04 +01:00
|
|
|
(define (topological-sort nodes
|
|
|
|
node-dependencies
|
|
|
|
node-name)
|
|
|
|
"Perform a breadth-first traversal of the graph rooted at NODES, a list of
|
|
|
|
nodes, and return the list of nodes sorted in topological order. Call
|
|
|
|
NODE-DEPENDENCIES to obtain the dependencies of a node, and NODE-NAME to
|
|
|
|
obtain a node's uniquely identifying \"key\"."
|
|
|
|
(let loop ((nodes nodes)
|
|
|
|
(result '())
|
|
|
|
(visited (set)))
|
|
|
|
(match nodes
|
|
|
|
(()
|
|
|
|
result)
|
|
|
|
((head . tail)
|
|
|
|
(if (set-contains? visited (node-name head))
|
|
|
|
(loop tail result visited)
|
|
|
|
(let ((dependencies (node-dependencies head)))
|
|
|
|
(loop (append dependencies tail)
|
|
|
|
(cons head result)
|
|
|
|
(set-insert (node-name head) visited))))))))
|
|
|
|
|
2020-02-04 13:18:18 +01:00
|
|
|
(define* (recursive-import package-name
|
|
|
|
#:key repo->guix-package guix-name version repo
|
2018-06-08 12:46:43 +02:00
|
|
|
#:allow-other-keys)
|
2019-12-12 22:18:37 +01:00
|
|
|
"Return a list of package expressions for PACKAGE-NAME and all its
|
2019-12-10 20:13:04 +01:00
|
|
|
dependencies, sorted in topological order. For each package,
|
2020-02-04 13:18:18 +01:00
|
|
|
call (REPO->GUIX-PACKAGE NAME :KEYS version repo), which should return a
|
2021-03-22 04:53:21 +01:00
|
|
|
package expression and a list of dependencies; call (GUIX-NAME PACKAGE-NAME)
|
|
|
|
to obtain the Guix package name corresponding to the upstream name."
|
2019-12-10 20:13:04 +01:00
|
|
|
(define-record-type <node>
|
2020-02-04 13:18:18 +01:00
|
|
|
(make-node name version package dependencies)
|
2019-12-10 20:13:04 +01:00
|
|
|
node?
|
|
|
|
(name node-name)
|
2020-02-04 13:18:18 +01:00
|
|
|
(version node-version)
|
2019-12-10 20:13:04 +01:00
|
|
|
(package node-package)
|
|
|
|
(dependencies node-dependencies))
|
|
|
|
|
2020-02-04 13:18:18 +01:00
|
|
|
(define (exists? name version)
|
|
|
|
(not (null? (find-packages-by-name (guix-name name) version))))
|
2019-12-10 20:13:04 +01:00
|
|
|
|
2020-02-04 13:18:18 +01:00
|
|
|
(define (lookup-node name version)
|
|
|
|
(let* ((package dependencies (repo->guix-package name
|
|
|
|
#:version version
|
|
|
|
#:repo repo))
|
2020-12-31 15:52:13 +01:00
|
|
|
(normalized-deps (map (match-lambda
|
2020-02-04 13:18:18 +01:00
|
|
|
((name version) (list name version))
|
|
|
|
(name (list name #f))) dependencies)))
|
2020-12-31 15:52:13 +01:00
|
|
|
(make-node name version package normalized-deps)))
|
2019-12-10 20:13:04 +01:00
|
|
|
|
2021-08-06 20:05:16 +02:00
|
|
|
(filter-map
|
|
|
|
node-package
|
|
|
|
(topological-sort (list (lookup-node package-name version))
|
|
|
|
(lambda (node)
|
|
|
|
(map (lambda (name-version)
|
|
|
|
(apply lookup-node name-version))
|
|
|
|
(remove (lambda (name-version)
|
|
|
|
(apply exists? name-version))
|
|
|
|
(node-dependencies node))))
|
|
|
|
(lambda (node)
|
|
|
|
(string-append
|
|
|
|
(node-name node)
|
|
|
|
(or (node-version node) ""))))))
|