mirror of
https://codeberg.org/guix/guix.git
synced 2025-10-02 02:15:12 +00:00
* guix/import/utils.scm (find-version): New procedure. * guix/scripts/refresh.scm (<update-spec>) [partial?]: New field. (update-spec-partial?): New accessor. (update-spec): Add a PARTIAL? optional argument. (update-specification->update-spec) <update-spec>: Call with its new PARTIAL? optional argument when FALLBACK-VERSION is provided, i.e. when '--target-version' was used. (update-package): Remove the PACKAGE and VERSION positional arguments, and replace them with UPDATE-SPEC. Update doc. Call `package-update' with its new #:partial-version? argument. (check-for-package-update) <package-latest-release>: Pass the new #:partial-version? argument to it. (guix-refresh) <update-package>: Adjust call accordingly. (show-help): Udate doc. * guix/upstream.scm (package-latest-release): Add #:partial-version? argument, and apply it to the importer call. (package-update): Add #:partial-version?> argument. Update doc. Pass it to the `package-latest-release' call. * guix/gnu-maintenance.scm (rewrite-url): Add #:partial-version? argument. Update doc. Crawl URL for newer compatible versions when provided. (import-html-release): Add #:partial-version? argument, and pass it to the `rewrite-url' call. Use `find-version' to find the best version. (import-release, import-ftp-release, import-gnu-release) (import-release*): Add #:partial-version? argument and honor it. (import-html-updatable-release): Add #:partial-version? argument, and pass it to the `import-html-release' call. * guix/import/gnome.scm (import-gnome-release) <#:partial-version?>: Add new argument and honor it. * guix/import/texlive.scm (latest-texlive-tag): Rename to... (texlive-tags): ... this, and have it return all tags. (texlive->guix-package): Adjust accordingly. (latest-release): Add a #:partial-version? argument. Update doc. * guix/import/stackage.scm (latest-lts-release): New #:partial-version? argument. * guix/import/pypi.scm (import-release): New #:partial-version? argument; pass it to `pypi-package->upstream-source'. * guix/import/opam.scm (latest-release): New #:partial-version? argument. * guix/import/minetest.scm (latest-minetest-release): New #:partial-version? argument. (pypi-package->upstream-source): New #:partial-version? argument. Update doc. * guix/import/launchpad.scm (latest-released-version): Rename to... (release-versions): ... this, making it return all versions. (import-release) <#:partial-version?>: New argument. * guix/import/kde.scm (import-kde-release) <#:partial-version?>: New argument. Update doc. Refactor to honor argument. * guix/import/hexpm.scm (lookup-hexpm): Update doc. (hexpm-latest-release): Rename to... (hexpm-releases): ... this; return all release strings. (hexpm->guix-package): Adjust accordingly. (import-release): Add and honor a #:partial-version? argument. Update doc. * guix/import/hackage.scm (import-release): New #:partial-version? argument. * guix/import/cpan.scm (latest-release): New #:partial-version? argument. * guix/import/crate.scm (max-crate-version-of-semver): Improve doc. (import-release): Add a #:partial-version? argument and honor it. * guix/import/egg.scm (find-latest-version): Rename to... (get-versions): ... this, returning all versions. (egg-metadata): Adjust accordingly. (egg->guix-package): Likewise. (import-release): Add a new #:partial-version? argument and honor it. * guix/import/elpa.scm (latest-release): New #:partial-version? argument. * guix/import/gem.scm (get-versions): New procedure. (import-release): Add a new #:partial-version? argument and honor it. * guix/import/git.scm (version-mapping): Update doc; streamline a bit. (latest-tag): Rename to... (get-tags): ... this, dropping the #:version keyword and returning the complete tags alist. Update doc. (latest-git-tag-version): Rename to... (get-package-tags): ... this, returning the complete tags alist of the package. Update doc. (import-git-release): Add a new #:partial-version? argument and honor it. Update doc. * guix/import/github.scm (latest-released-version): Rename to... (get-package-tags): ... this, returning all tags. Update doc. (import-release): Add a new #:partial-version? argument and honor it. * guix/import/cran.scm (latest-cran-release) (latest-bioconductor-release): Add #:partial-version? argument. * guix/import/composer.scm (latest-version): Delete procedure. (composer-fetch): Add #:partial-version? keyword and honor it. Update doc. (import-release): Likewise. * guix/import/test.scm (import-release): Add #:partial-version? argument. * tests/guix-refresh.sh: Add test. * tests/gem.scm (test-foo-versions-json): New variable. (package-latest-release): Mock new URL. * tests/import-git.scm (latest-git-tag-version): New procedure. * tests/gnu-maintenance.scm (libuv-dist-html) (libuv-dist-1.46.0-html, libuv-dist-1.44.2-html) (libuv-html-data): New variables. (mock-http-fetch/cached): New procedure. ("rewrite-url, without to-version"): Rewrite using the above. ("rewrite-url, partial to-version"): New test. * doc/guix.texi <"Invoking guix refresh">: Update doc. Series-to: 75871@debbugs.gnu.org Change-Id: I092a58b57ac42e54a2fa55e7761e8c6993af8ad4
276 lines
12 KiB
Scheme
276 lines
12 KiB
Scheme
;;; GNU Guix --- Functional package management for GNU
|
|
;;; Copyright © 2019 Julien Lepiller <julien@lepiller.eu>
|
|
;;; Copyright © 2024 Maxim Cournoyer <maxim.cournoyer@gmail.com>
|
|
;;;
|
|
;;; 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 composer)
|
|
#:use-module (ice-9 match)
|
|
#:use-module (json)
|
|
#:use-module (guix base32)
|
|
#:use-module (guix build git)
|
|
#:use-module (guix build utils)
|
|
#:use-module (guix build-system)
|
|
#:use-module (guix build-system composer)
|
|
#:use-module ((guix diagnostics) #:select (warning))
|
|
#:use-module (guix hash)
|
|
#:use-module (guix i18n)
|
|
#:use-module (guix import json)
|
|
#:use-module (guix import utils)
|
|
#:use-module ((guix licenses) #:prefix license:)
|
|
#:use-module (guix memoization)
|
|
#:use-module (guix packages)
|
|
#:use-module (guix serialization)
|
|
#:use-module (guix upstream)
|
|
#:use-module (guix utils)
|
|
#:use-module (srfi srfi-1)
|
|
#:use-module (srfi srfi-2)
|
|
#:use-module (srfi srfi-11)
|
|
#:use-module (srfi srfi-26)
|
|
#:export (composer->guix-package
|
|
%composer-updater
|
|
composer-recursive-import
|
|
|
|
%composer-base-url))
|
|
|
|
(define %composer-base-url
|
|
(make-parameter "https://repo.packagist.org"))
|
|
|
|
(define (fix-version version)
|
|
"Return a fixed version from a version string. For instance, v10.1 -> 10.1"
|
|
(cond
|
|
((string-prefix? "version" version)
|
|
(if (char-set-contains? char-set:digit (string-ref version 7))
|
|
(substring version 7)
|
|
(substring version 8)))
|
|
((string-prefix? "v" version)
|
|
(substring version 1))
|
|
(else version)))
|
|
|
|
(define (json->require dict)
|
|
(if dict
|
|
(let loop ((result '()) (require dict))
|
|
(match require
|
|
(() result)
|
|
((((? (cut string-contains <> "/") name) . _)
|
|
require ...)
|
|
(loop (cons name result) require))
|
|
((_ require ...) (loop result require))
|
|
(_ result)))
|
|
'()))
|
|
|
|
(define-json-mapping <composer-source> make-composer-source composer-source?
|
|
json->composer-source
|
|
(type composer-source-type)
|
|
(url composer-source-url)
|
|
(reference composer-source-reference))
|
|
|
|
(define-json-mapping <composer-package> make-composer-package composer-package?
|
|
json->composer-package
|
|
(description composer-package-description)
|
|
(homepage composer-package-homepage)
|
|
(source composer-package-source "source" json->composer-source)
|
|
(name composer-package-name "name" php-package-name)
|
|
(version composer-package-version "version" fix-version)
|
|
(require composer-package-require "require" json->require)
|
|
(dev-require composer-package-dev-require "require-dev" json->require)
|
|
(license composer-package-license "license"
|
|
(lambda (vector)
|
|
(let ((l (map string->license (vector->list vector))))
|
|
(if (eq? (length l) 1)
|
|
(car l)
|
|
`(list ,@l))))))
|
|
|
|
(define (valid-version? v)
|
|
(let ((d (string-downcase v)))
|
|
(and (not (string-contains d "dev"))
|
|
(not (string-contains d "beta"))
|
|
(not (string-contains d "rc")))))
|
|
|
|
(define* (composer-fetch name #:key version partial-version?)
|
|
"Return a composer-package representation of the Composer metadata for the
|
|
package NAME with optional VERSION, or #f on failure. VERSION may be gien as
|
|
version prefix if PARTIAL-VERSION? is #t."
|
|
(and-let* ((url (string-append (%composer-base-url) "/p/" name ".json"))
|
|
(packages (and=> (json-fetch url)
|
|
(lambda (pkg)
|
|
(let ((pkgs (assoc-ref pkg "packages")))
|
|
(or (assoc-ref pkgs name) pkg)))))
|
|
(all-versions (map car packages))
|
|
(valid-versions (filter valid-version? all-versions))
|
|
(version (or (find-version valid-versions version partial-version?)
|
|
(and version
|
|
;; If the user-provided VERSION could not be
|
|
;; found, fallback to look through all
|
|
;; versions.
|
|
(find-version all-versions version
|
|
partial-version?)))))
|
|
(json->composer-package (assoc-ref packages version))))
|
|
|
|
(define (php-package-name name)
|
|
"Given the NAME of a package on Packagist, return a Guix-compliant name for
|
|
the package."
|
|
(let ((name (string-join (string-split name #\/) "-")))
|
|
(if (string-prefix? "php-" name)
|
|
(snake-case name)
|
|
(string-append "php-" (snake-case name)))))
|
|
|
|
(define (make-php-sexp composer-package)
|
|
"Return the `package' s-expression for a PHP package for the given
|
|
COMPOSER-PACKAGE."
|
|
(let* ((source (composer-package-source composer-package))
|
|
(dependencies (map php-package-name
|
|
(composer-package-require composer-package)))
|
|
(dev-dependencies (map php-package-name
|
|
(composer-package-dev-require composer-package)))
|
|
(git? (equal? (composer-source-type source) "git")))
|
|
((if git? call-with-temporary-directory call-with-temporary-output-file)
|
|
(lambda* (temp #:optional port)
|
|
(and (if git?
|
|
(begin
|
|
(mkdir-p temp)
|
|
(git-fetch (composer-source-url source)
|
|
(composer-source-reference source)
|
|
temp))
|
|
(url-fetch (composer-source-url source) temp))
|
|
`(package
|
|
(name ,(composer-package-name composer-package))
|
|
(version ,(composer-package-version composer-package))
|
|
(source
|
|
(origin
|
|
,@(if git?
|
|
`((method git-fetch)
|
|
(uri (git-reference
|
|
(url ,(if (string-suffix?
|
|
".git"
|
|
(composer-source-url source))
|
|
(string-drop-right
|
|
(composer-source-url source)
|
|
(string-length ".git"))
|
|
(composer-source-url source)))
|
|
(commit ,(composer-source-reference source))))
|
|
(file-name (git-file-name name version))
|
|
(sha256
|
|
(base32
|
|
,(bytevector->nix-base32-string
|
|
(file-hash* temp)))))
|
|
`((method url-fetch)
|
|
(uri ,(composer-source-url source))
|
|
(sha256 (base32 ,(guix-hash-url temp)))))))
|
|
(build-system composer-build-system)
|
|
,@(if (null? dependencies)
|
|
'()
|
|
`((inputs
|
|
(list ,@(map string->symbol dependencies)))))
|
|
,@(if (null? dev-dependencies)
|
|
'()
|
|
`((native-inputs
|
|
(list ,@(map string->symbol dev-dependencies)))))
|
|
(synopsis "")
|
|
(description ,(composer-package-description composer-package))
|
|
(home-page ,(composer-package-homepage composer-package))
|
|
(license ,(or (composer-package-license composer-package)
|
|
'unknown-license!))))))))
|
|
|
|
(define composer->guix-package
|
|
(memoize
|
|
(lambda* (package-name #:key (version #f) #:allow-other-keys)
|
|
"Fetch the metadata for PACKAGE-NAME from packagist.org, and return the
|
|
`package' s-expression corresponding to that package and its list of
|
|
dependencies, or #f and the empty list on failure."
|
|
(let ((package (composer-fetch package-name #:version version)))
|
|
(if package
|
|
(let* ((dependencies-names (composer-package-require package))
|
|
(dev-dependencies-names (composer-package-dev-require package)))
|
|
(values (make-php-sexp package)
|
|
(append dependencies-names dev-dependencies-names)))
|
|
(values #f '()))))))
|
|
|
|
(define (guix-name->composer-name name)
|
|
"Given a guix package name, return the name of the package in Packagist."
|
|
(if (string-prefix? "php-" name)
|
|
(let ((components (string-split (substring name 4) #\-)))
|
|
(match components
|
|
((namespace name ...)
|
|
(string-append namespace "/" (string-join name "-")))))
|
|
name))
|
|
|
|
(define (guix-package->composer-name package)
|
|
"Given a Composer PACKAGE built from Packagist, return the name of the
|
|
package in Packagist."
|
|
(or (assoc-ref (package-properties package) 'upstream-name)
|
|
(guix-name->composer-name (package-name package))))
|
|
|
|
(define (string->license str)
|
|
"Convert the string STR into a license object."
|
|
(or (spdx-string->license str)
|
|
(match str
|
|
("GNU LGPL" 'license:lgpl2.0)
|
|
("GPL" 'license:gpl3)
|
|
((or "BSD" "BSD License") 'license:bsd-3)
|
|
((or "MIT" "MIT license" "Expat license") 'license:expat)
|
|
("Public domain" 'license:public-domain)
|
|
((or "Apache License, Version 2.0" "Apache 2.0") 'license:asl2.0)
|
|
(_ 'unknown-license!))))
|
|
|
|
(define (php-package? package)
|
|
"Return true if PACKAGE is a PHP package from Packagist."
|
|
(and
|
|
(eq? (package-build-system package) composer-build-system)
|
|
(string-prefix? "php-" (package-name package))))
|
|
|
|
(define (dependency->input dependency type)
|
|
(upstream-input
|
|
(name dependency)
|
|
(downstream-name (php-package-name dependency))
|
|
(type type)))
|
|
|
|
(define* (import-release package #:key version partial-version?)
|
|
"Return an <upstream-source> for VERSION or the latest release of PACKAGE.
|
|
If PARTIAL-VERSION? is #t, the provided VERSION may be a partial version
|
|
prefix."
|
|
(let* ((php-name (guix-package->composer-name package))
|
|
(composer-package (composer-fetch php-name
|
|
#:version version
|
|
#:partial-version?
|
|
partial-version?)))
|
|
(if composer-package
|
|
(upstream-source
|
|
(package (composer-package-name composer-package))
|
|
(version (composer-package-version composer-package))
|
|
(urls (list (composer-source-url
|
|
(composer-package-source composer-package))))
|
|
(inputs (append
|
|
(map (cut dependency->input <> 'regular)
|
|
(composer-package-require composer-package))
|
|
(map (cut dependency->input <> 'native)
|
|
(composer-package-dev-require composer-package)))))
|
|
(begin
|
|
(warning (G_ "failed to parse ~a~%") php-name)
|
|
#f))))
|
|
|
|
(define %composer-updater
|
|
(upstream-updater
|
|
(name 'composer)
|
|
(description "Updater for Composer packages")
|
|
(pred php-package?)
|
|
(import import-release)))
|
|
|
|
(define* (composer-recursive-import package-name #:optional version)
|
|
(recursive-import package-name
|
|
#:version version
|
|
#:repo->guix-package composer->guix-package
|
|
#:guix-name php-package-name))
|