From patchwork Thu Nov 2 15:16:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 55842 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 5439B27BBEE; Thu, 2 Nov 2023 15:19:41 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 923F627BBE2 for ; Thu, 2 Nov 2023 15:19:36 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qyZSm-0008WA-Qc; Thu, 02 Nov 2023 11:18:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qyZSl-0008Vh-Br for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:27 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qyZSl-0003pU-41 for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:27 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qyZTK-0006bU-2w for guix-patches@gnu.org; Thu, 02 Nov 2023 11:19:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#42338] [PATCH v5 1/9] guix: import: Add composer importer. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 02 Nov 2023 15:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42338 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 42338@debbugs.gnu.org Cc: ngraves@ngraves.fr Received: via spool by 42338-submit@debbugs.gnu.org id=B42338.169893829425215 (code B ref 42338); Thu, 02 Nov 2023 15:19:02 +0000 Received: (at 42338) by debbugs.gnu.org; 2 Nov 2023 15:18:14 +0000 Received: from localhost ([127.0.0.1]:55769 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSW-0006Ya-UQ for submit@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:14 -0400 Received: from 6.mo560.mail-out.ovh.net ([87.98.165.38]:57765) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZST-0006Y8-TO for 42338@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:11 -0400 Received: from director9.ghost.mail-out.ovh.net (unknown [10.108.1.219]) by mo560.mail-out.ovh.net (Postfix) with ESMTP id 8D4C8256E9 for <42338@debbugs.gnu.org>; Thu, 2 Nov 2023 15:17:33 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-wwgj2 (unknown [10.110.115.9]) by director9.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 421A91FE55; Thu, 2 Nov 2023 15:17:33 +0000 (UTC) Received: from ngraves.fr ([37.59.142.107]) by ghost-submission-6684bf9d7b-wwgj2 with ESMTPSA id hprzBI29Q2XpKAAA3NU5ow (envelope-from ); Thu, 02 Nov 2023 15:17:33 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-107S0016ec37c43-80dc-4918-9d05-69331be9ba87, 1761E107A7246F2314AE904A186E6A889A3776EC) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 87.88.157.103 Date: Thu, 2 Nov 2023 16:16:48 +0100 Message-ID: <20231102151725.31362-2-ngraves@ngraves.fr> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231102151725.31362-1-ngraves@ngraves.fr> References: <20231102151725.31362-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13658573248153772770 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedruddtiedgjeegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfgggtgfesthekredtredtjeenucfhrhhomheppfhitgholhgrshcuifhrrghvvghsuceonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqeenucggtffrrghtthgvrhhnpeduheefjefggfffhfdtjedvudetleevveejveevtdetfeeiheejgfejhedtieekueenucffohhmrghinhepghgvthgtohhmphhoshgvrhdrohhrghdpghhnuhdrohhrghdpphgrtghkrghgihhsthdrohhrghdpvgigrghmphhlvgdrtghomhenucfkphepuddvjedrtddrtddruddpkeejrdekkedrudehjedruddtfedpfeejrdehledrudegvddruddtjeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqpdhnsggprhgtphhtthhopedupdhrtghpthhtohepgedvfeefkeesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheeitddpmhhouggvpehsmhhtphhouhht X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/import/composer.scm: New file. * guix/scripts/import/composer.scm: New file. * guix/tests/composer.scm: New file. * Makefile.am: Add them. * guix/scripts/import.scm: Add composer importer. * doc/guix.texi (Invoking guix import): Mention it. --- Makefile.am | 3 + doc/guix.texi | 20 +++ guix/import/composer.scm | 270 +++++++++++++++++++++++++++++++ guix/scripts/import.scm | 2 +- guix/scripts/import/composer.scm | 107 ++++++++++++ tests/composer.scm | 92 +++++++++++ 6 files changed, 493 insertions(+), 1 deletion(-) create mode 100644 guix/import/composer.scm create mode 100644 guix/scripts/import/composer.scm create mode 100644 tests/composer.scm diff --git a/Makefile.am b/Makefile.am index 310a231259..3fec98f064 100644 --- a/Makefile.am +++ b/Makefile.am @@ -274,6 +274,7 @@ MODULES = \ guix/search-paths.scm \ guix/packages.scm \ guix/import/cabal.scm \ + guix/import/composer.scm \ guix/import/cpan.scm \ guix/import/cran.scm \ guix/import/crate.scm \ @@ -332,6 +333,7 @@ MODULES = \ guix/scripts/home/import.scm \ guix/scripts/lint.scm \ guix/scripts/challenge.scm \ + guix/scripts/import/composer.scm \ guix/scripts/import/crate.scm \ guix/scripts/import/cpan.scm \ guix/scripts/import/cran.scm \ @@ -504,6 +506,7 @@ SCM_TESTS = \ tests/challenge.scm \ tests/channels.scm \ tests/combinators.scm \ + tests/composer.scm \ tests/containers.scm \ tests/cpan.scm \ tests/cpio.scm \ diff --git a/doc/guix.texi b/doc/guix.texi index 8c5697589f..0e64654715 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -14539,6 +14539,26 @@ guix import hexpm cf@@0.3.0 Additional options include: +@table @code +@item --recursive +@itemx -r +Traverse the dependency graph of the given upstream package recursively +and generate package expressions for all those packages that are not yet +in Guix. +@end table + +@item composer +@cindex Composer +@cindex PHP +Import metadat from the @uref{https://getcomposer.org/, Composer} package +archive used by the PHP community, as in this example: + +@example +guix import composer phpunit/phpunit +@end example + +Additional options include: + @table @code @item --recursive @itemx -r diff --git a/guix/import/composer.scm b/guix/import/composer.scm new file mode 100644 index 0000000000..c152f402bb --- /dev/null +++ b/guix/import/composer.scm @@ -0,0 +1,270 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2019 Julien Lepiller +;;; +;;; 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 composer) + #:use-module (ice-9 match) + #:use-module (json) + #:use-module (gcrypt hash) + #:use-module (guix base32) + #:use-module (guix build git) + #:use-module (guix build utils) + #:use-module (guix build-system) + #:use-module (guix import json) + #:use-module (guix import utils) + #:use-module ((guix licenses) #:prefix license:) + #: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-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")) + +;; XXX adapted from (guix scripts hash) +(define (file-hash file select? recursive?) + ;; Compute the hash of FILE. + (if recursive? + (let-values (((port get-hash) (open-sha256-port))) + (write-file file port #:select? select?) + (force-output port) + (get-hash)) + (call-with-input-file file port-sha256))) + +;; XXX taken from (guix scripts hash) +(define (vcs-file? file stat) + (case (stat:type stat) + ((directory) + (member (basename file) '(".bzr" ".git" ".hg" ".svn" "CVS"))) + ((regular) + ;; Git sub-modules have a '.git' file that is a regular text file. + (string=? (basename file) ".git")) + (else + #f))) + +(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 (latest-version versions) + (fold (lambda (a b) (if (version>? (fix-version a) (fix-version b)) a b)) + (car versions) versions)) + +(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)))) + '())) + +(define-json-mapping make-composer-source composer-source? + json->composer-source + (type composer-source-type) + (url composer-source-url) + (reference composer-source-reference)) + +(define-json-mapping 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) + (map string->license (vector->list vector))))) + +(define* (composer-fetch name #:optional version) + "Return an alist representation of the Composer metadata for the package NAME, +or #f on failure." + (let ((package (json-fetch + (string-append (%composer-base-url) "/p/" name ".json")))) + (if package + (let* ((packages (assoc-ref package "packages")) + (package (or (assoc-ref packages name) package)) + (versions (filter + (lambda (version) + (and (not (string-contains version "dev")) + (not (string-contains version "beta")))) + (map car package))) + (version (or (if (null? version) #f version) + (latest-version versions)))) + (assoc-ref package version)) + #f))) + +(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 ,(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 (negate vcs-file?) #t))))) + `((method url-fetch) + (uri ,(composer-source-url source)) + (sha256 (base32 ,(guix-hash-url temp))))))) + (build-system composer-build-system) + ,@(if (null? dependencies) + '() + `((inputs + (,'quasiquote + ,(map (lambda (name) + `(,name + (,'unquote + ,(string->symbol name)))) + dependencies))))) + ,@(if (null? dev-dependencies) + '() + `((native-inputs + (,'quasiquote + ,(map (lambda (name) + `(,name + (,'unquote + ,(string->symbol name)))) + dev-dependencies))))) + (synopsis "") + (description ,(composer-package-description composer-package)) + (home-page ,(composer-package-homepage composer-package)) + (license ,(match (composer-package-license composer-package) + (() #f) + ((license) license) + (_ license))))))))) + +(define* (composer->guix-package package-name #:optional version) + "Fetch the metadata for PACKAGE-NAME from packagist.org, and return the +`package' s-expression corresponding to that package, or #f on failure." + (let ((package (composer-fetch package-name version))) + (and package + (let* ((package (json->composer-package package)) + (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)))))) + +(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." + (let ((upstream-name (assoc-ref + (package-properties package) + 'upstream-name)) + (name (package-name package))) + (if upstream-name + upstream-name + (guix-name->composer-name name)))) + +(define (string->license str) + "Convert the string STR into a license object." + (match str + ("GNU LGPL" 'license:lgpl2.0) + ("GPL" 'license:gpl3) + ((or "BSD" "BSD License" "BSD-3-Clause") '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) + (_ #f))) + +(define (php-package? package) + "Return true if PACKAGE is a PHP package from Packagist." + (and + (eq? (build-system-name (package-build-system package)) 'composer) + (string-prefix? "php-" (package-name package)))) + +(define (latest-release package) + "Return an for the latest release of PACKAGE." + (let* ((php-name (guix-package->composer-name package)) + (metadata (composer-fetch php-name)) + (package (json->composer-package metadata)) + (version (composer-package-version package)) + (url (composer-source-url (composer-package-source package)))) + (upstream-source + (package (package-name package)) + (version version) + (urls (list url))))) + +(define %composer-updater + (upstream-updater + (name 'composer) + (description "Updater for Composer packages") + (pred php-package?) + (import latest-release))) + +(define* (composer-recursive-import package-name #:optional version) + (recursive-import package-name '() + #:repo->guix-package composer->guix-package + #:guix-name php-package-name)) diff --git a/guix/scripts/import.scm b/guix/scripts/import.scm index 4ddd8d46a1..8c58dd35e2 100644 --- a/guix/scripts/import.scm +++ b/guix/scripts/import.scm @@ -47,7 +47,7 @@ (define %standard-import-options '()) (define importers '("gnu" "pypi" "cpan" "hackage" "stackage" "egg" "elpa" "gem" "go" "cran" "crate" "texlive" "json" "opam" - "minetest" "elm" "hexpm")) + "minetest" "elm" "hexpm" "composer")) (define (resolve-importer name) (let ((module (resolve-interface diff --git a/guix/scripts/import/composer.scm b/guix/scripts/import/composer.scm new file mode 100644 index 0000000000..412bae6318 --- /dev/null +++ b/guix/scripts/import/composer.scm @@ -0,0 +1,107 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2015 David Thompson +;;; Copyright © 2018 Oleg Pykhalov +;;; +;;; 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 composer) + #:use-module (guix ui) + #:use-module (guix utils) + #:use-module (guix scripts) + #:use-module (guix import composer) + #:use-module (guix scripts import) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-11) + #:use-module (srfi srfi-37) + #:use-module (srfi srfi-41) + #:use-module (ice-9 match) + #:use-module (ice-9 format) + #:export (guix-import-composer)) + + +;;; +;;; Command-line options. +;;; + +(define %default-options + '()) + +(define (show-help) + (display (G_ "Usage: guix import composer PACKAGE-NAME +Import and convert the Composer package for PACKAGE-NAME.\n")) + (display (G_ " + -h, --help display this help and exit")) + (display (G_ " + -V, --version display version information and exit")) + (display (G_ " + -r, --recursive generate package expressions for all Composer packages\ + that are not yet in Guix")) + (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 composer"))) + (option '(#\r "recursive") #f #f + (lambda (opt name arg result) + (alist-cons 'recursive #t result))) + %standard-import-options)) + + +;;; +;;; Entry point. +;;; + +(define (guix-import-composer . args) + (define (parse-options) + ;; Return the alist of option values. + (args-fold* args %options + (lambda (opt name arg result) + (leave (G_ "~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) + (if (assoc-ref opts 'recursive) + (map (match-lambda + ((and ('package ('name name) . rest) pkg) + `(define-public ,(string->symbol name) + ,pkg)) + (_ #f)) + (composer-recursive-import package-name)) + (let ((sexp (composer->guix-package package-name))) + (unless sexp + (leave (G_ "failed to download meta-data for package '~a'~%") + package-name)) + sexp))) + (() + (leave (G_ "too few arguments~%"))) + ((many ...) + (leave (G_ "too many arguments~%")))))) diff --git a/tests/composer.scm b/tests/composer.scm new file mode 100644 index 0000000000..cefaf9f434 --- /dev/null +++ b/tests/composer.scm @@ -0,0 +1,92 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2020 Julien Lepiller +;;; +;;; 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-composer) + #:use-module (guix import composer) + #:use-module (guix base32) + #:use-module (gcrypt hash) + #:use-module (guix tests http) + #:use-module (guix grafts) + #:use-module (srfi srfi-64) + #:use-module (web client) + #:use-module (ice-9 match)) + +;; Globally disable grafts because they can trigger early builds. +(%graft? #f) + +(define test-json + "{ + \"packages\": { + \"foo/bar\": { + \"0.1\": { + \"name\": \"foo/bar\", + \"description\": \"description\", + \"keywords\": [\"testing\"], + \"homepage\": \"http://example.com\", + \"version\": \"0.1\", + \"license\": [\"BSD-3-Clause\"], + \"source\": { + \"type\": \"url\", + \"url\": \"http://example.com/Bar-0.1.tar.gz\" + }, + \"require\": {}, + \"require-dev\": {\"phpunit/phpunit\": \"1.0.0\"} + } + } + } +}") + +(define test-source + "foobar") + +;; Avoid collisions with other tests. +(%http-server-port 10450) + +(test-begin "composer") + +(test-assert "composer->guix-package" + ;; Replace network resources with sample data. + (with-http-server `((200 ,test-json) + (200 ,test-source)) + (parameterize ((%composer-base-url (%local-url)) + (current-http-proxy (%local-url))) + (match (composer->guix-package "foo/bar") + (('package + ('name "php-foo-bar") + ('version "0.1") + ('source ('origin + ('method 'url-fetch) + ('uri "http://example.com/Bar-0.1.tar.gz") + ('sha256 + ('base32 + (? string? hash))))) + ('build-system 'composer-build-system) + ('native-inputs + ('quasiquote + (("php-phpunit-phpunit" ('unquote 'php-phpunit-phpunit))))) + ('synopsis "") + ('description "description") + ('home-page "http://example.com") + ('license 'license:bsd-3)) + (string=? (bytevector->nix-base32-string + (call-with-input-string test-source port-sha256)) + hash)) + (x + (pk 'fail x #f)))))) + +(test-end "composer") From patchwork Thu Nov 2 15:16:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 55843 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id EF54A27BBE2; Thu, 2 Nov 2023 15:19:45 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 8415527BBEA for ; Thu, 2 Nov 2023 15:19:37 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qyZSn-00005G-UX; Thu, 02 Nov 2023 11:18:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qyZSl-0008Vr-SA for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:27 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qyZSl-0003pa-KK for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:27 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qyZTK-0006bd-JG for guix-patches@gnu.org; Thu, 02 Nov 2023 11:19:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#42338] [PATCH v5 2/9] gnu: Add composer-classloader. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 02 Nov 2023 15:19:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42338 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 42338@debbugs.gnu.org Cc: ngraves@ngraves.fr Received: via spool by 42338-submit@debbugs.gnu.org id=B42338.169893829425222 (code B ref 42338); Thu, 02 Nov 2023 15:19:02 +0000 Received: (at 42338) by debbugs.gnu.org; 2 Nov 2023 15:18:14 +0000 Received: from localhost ([127.0.0.1]:55771 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSY-0006Ye-4K for submit@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:14 -0400 Received: from 20.mo561.mail-out.ovh.net ([178.33.47.94]:40581) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSV-0006YF-0G for 42338@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:12 -0400 Received: from director8.ghost.mail-out.ovh.net (unknown [10.108.16.142]) by mo561.mail-out.ovh.net (Postfix) with ESMTP id C9EA627D59 for <42338@debbugs.gnu.org>; Thu, 2 Nov 2023 15:17:34 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-9zq47 (unknown [10.108.1.13]) by director8.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 62A621FE99; Thu, 2 Nov 2023 15:17:34 +0000 (UTC) Received: from ngraves.fr ([37.59.142.105]) by ghost-submission-6684bf9d7b-9zq47 with ESMTPSA id XckMEY69Q2XD7CwAE7nfSw (envelope-from ); Thu, 02 Nov 2023 15:17:34 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-105G0062b0fbf16-11c9-443d-bdb1-9cb4921880ae, 1761E107A7246F2314AE904A186E6A889A3776EC) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 87.88.157.103 Date: Thu, 2 Nov 2023 16:16:49 +0100 Message-ID: <20231102151725.31362-3-ngraves@ngraves.fr> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231102151725.31362-1-ngraves@ngraves.fr> References: <20231102151725.31362-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13658854724022493922 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedruddtiedgjeehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfgggtgfesthekredtredtjeenucfhrhhomheppfhitgholhgrshcuifhrrghvvghsuceonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqeenucggtffrrghtthgvrhhnpeeugeeukeelheehteeuueeileffveetgffghfffueffhfejvedvgeelleetueduheenucffohhmrghinhepghhnuhdrohhrghdpghhithhhuhgsrdgtohhmpdhgvghttghomhhpohhsvghrrdhorhhgnecukfhppeduvdejrddtrddtrddupdekjedrkeekrdduheejrddutdefpdefjedrheelrddugedvrddutdehnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpeeonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqedpnhgspghrtghpthhtohepuddprhgtphhtthhopeegvdeffeekseguvggssghughhsrdhgnhhurdhorhhgpdfovfetjfhoshhtpehmohehiedupdhmohguvgepshhmthhpohhuth X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/packages/php-xyz.scm: New file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add it. --- gnu/local.mk | 1 + gnu/packages/php-xyz.scm | 60 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 gnu/packages/php-xyz.scm diff --git a/gnu/local.mk b/gnu/local.mk index 83b5268c7e..f1d16f873c 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -502,6 +502,7 @@ GNU_SYSTEM_MODULES = \ %D%/packages/photo.scm \ %D%/packages/phabricator.scm \ %D%/packages/php.scm \ + %D%/packages/php-xyz.scm \ %D%/packages/piet.scm \ %D%/packages/pikchr.scm \ %D%/packages/pkg-config.scm \ diff --git a/gnu/packages/php-xyz.scm b/gnu/packages/php-xyz.scm new file mode 100644 index 0000000000..ac90ee3c25 --- /dev/null +++ b/gnu/packages/php-xyz.scm @@ -0,0 +1,60 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2019 Julien Lepiller +;;; +;;; 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 (gnu packages php-xyz) + #:use-module (gnu packages) + #:use-module (gnu packages php) + #:use-module (guix packages) + #:use-module (guix download) + #:use-module (guix git-download) + #:use-module (guix build-system composer) + #:use-module (guix build-system gnu) + #:use-module (guix utils) + #:use-module ((guix licenses) #:prefix license:)) + +(define-public composer-classloader + (package + (name "composer-classloader") + (version "1.9.0") + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/composer/composer") + (commit version))) + (file-name (git-file-name name version)) + (sha256 + (base32 "0127zmmg3yx84ljngfs86q7kjhyypybkf4d1ihfrfnzgynzxfxdf")))) + (build-system gnu-build-system) + (arguments + `(#:phases + (modify-phases %standard-phases + (delete 'configure) + (delete 'build) + (delete 'check) + (replace 'install + (lambda* (#:key outputs #:allow-other-keys) + (let* ((out (assoc-ref outputs "out"))) + (install-file "src/Composer/Autoload/ClassLoader.php" + (string-append out "/share/web/composer/")))))))) + (home-page "https://getcomposer.org") + (synopsis "PHP class loader extracted from the composer package") + (description "This package contains the class loader class used by Composer to +build its autoloading feature. This package is used by the composer-build-system +to build its own store-aware autoloading feature.") + (license license:expat))) From patchwork Thu Nov 2 15:16:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 55844 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id EFBC227BBE2; Thu, 2 Nov 2023 15:19:46 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id D011027BBEC for ; Thu, 2 Nov 2023 15:19:40 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qyZSq-00006W-Dd; Thu, 02 Nov 2023 11:18:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qyZSm-0008Vz-9J for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:28 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qyZSm-0003pg-1x for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:28 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qyZTL-0006bk-1k for guix-patches@gnu.org; Thu, 02 Nov 2023 11:19:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#42338] [PATCH v5 3/9] guix: Add composer-build-system. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 02 Nov 2023 15:19:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42338 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 42338@debbugs.gnu.org Cc: ngraves@ngraves.fr Received: via spool by 42338-submit@debbugs.gnu.org id=B42338.169893830025262 (code B ref 42338); Thu, 02 Nov 2023 15:19:03 +0000 Received: (at 42338) by debbugs.gnu.org; 2 Nov 2023 15:18:20 +0000 Received: from localhost ([127.0.0.1]:55776 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSc-0006ZE-K8 for submit@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:20 -0400 Received: from 20.mo584.mail-out.ovh.net ([46.105.33.73]:57807) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSY-0006Yc-Mo for 42338@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:17 -0400 Received: from director4.ghost.mail-out.ovh.net (unknown [10.108.20.237]) by mo584.mail-out.ovh.net (Postfix) with ESMTP id 690F6285F5 for <42338@debbugs.gnu.org>; Thu, 2 Nov 2023 15:17:38 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-w9xmf (unknown [10.110.208.100]) by director4.ghost.mail-out.ovh.net (Postfix) with ESMTPS id E6BAC1FE62; Thu, 2 Nov 2023 15:17:37 +0000 (UTC) Received: from ngraves.fr ([37.59.142.110]) by ghost-submission-6684bf9d7b-w9xmf with ESMTPSA id dCRiM5G9Q2VUGQEAkDpEYg (envelope-from ); Thu, 02 Nov 2023 15:17:37 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-110S004142ef62d-54e7-431e-8685-21e24224c375, 1761E107A7246F2314AE904A186E6A889A3776EC) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 87.88.157.103 Date: Thu, 2 Nov 2023 16:16:50 +0100 Message-ID: <20231102151725.31362-4-ngraves@ngraves.fr> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231102151725.31362-1-ngraves@ngraves.fr> References: <20231102151725.31362-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13659980621468132066 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedruddtiedgjeehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfgggtgfesthekredtredtjeenucfhrhhomheppfhitgholhgrshcuifhrrghvvghsuceonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqeenucggtffrrghtthgvrhhnpefhgfehieffffdvjedujeelkeefuefhueehvdetieehiefhteffueejjeeuteffjeenucffohhmrghinhepghgvthgtohhmphhoshgvrhdrohhrghdpughunhgvrdgsuhhilhgupdhgihhthhhusgdrtghomhdpghhnuhdrohhrghdpvgigrghmphhlvgdrtghomhenucfkphepuddvjedrtddrtddruddpkeejrdekkedrudehjedruddtfedpfeejrdehledrudegvddruddutdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqpdhnsggprhgtphhtthhopedupdhrtghpthhtohepgedvfeefkeesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheekgedpmhhouggvpehsmhhtphhouhht X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/build-system/composer.scm: New file. * guix/build/composer-build-system.scm: New file. * gnu/packages/aux-files/findclass.php: New file. * Makefile.am: Add them. * doc/guix.texi (Build Systems): Document it. --- Makefile.am | 3 + doc/guix.texi | 16 +- gnu/packages/aux-files/findclass.php | 125 ++++++++++++++ guix/build-system/composer.scm | 162 ++++++++++++++++++ guix/build/composer-build-system.scm | 247 +++++++++++++++++++++++++++ tests/composer.scm | 36 ++-- 6 files changed, 568 insertions(+), 21 deletions(-) create mode 100644 gnu/packages/aux-files/findclass.php create mode 100644 guix/build-system/composer.scm create mode 100644 guix/build/composer-build-system.scm diff --git a/Makefile.am b/Makefile.am index 3fec98f064..47d1cb19ed 100644 --- a/Makefile.am +++ b/Makefile.am @@ -149,6 +149,7 @@ MODULES = \ guix/build-system/chicken.scm \ guix/build-system/clojure.scm \ guix/build-system/cmake.scm \ + guix/build-system/composer.scm \ guix/build-system/dub.scm \ guix/build-system/dune.scm \ guix/build-system/elm.scm \ @@ -206,6 +207,7 @@ MODULES = \ guix/build/cargo-utils.scm \ guix/build/chicken-build-system.scm \ guix/build/cmake-build-system.scm \ + guix/build/composer-build-system.scm \ guix/build/dub-build-system.scm \ guix/build/dune-build-system.scm \ guix/build/elm-build-system.scm \ @@ -411,6 +413,7 @@ dist_noinst_DATA = \ AUX_FILES = \ gnu/packages/aux-files/chromium/master-preferences.json \ gnu/packages/aux-files/emacs/guix-emacs.el \ + gnu/packages/aux-files/findclass.php \ gnu/packages/aux-files/guix.vim \ gnu/packages/aux-files/linux-libre/6.5-arm.conf \ gnu/packages/aux-files/linux-libre/6.5-arm64.conf \ diff --git a/doc/guix.texi b/doc/guix.texi index 0e64654715..6a1c0aeaa5 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -9554,6 +9554,20 @@ debugging information''), which roughly means that code is compiled with @code{-O2 -g}, as is the case for Autoconf-based packages by default. @end defvar +@defvar {Scheme Variable} composer-build-system +This variable is exported by @code{(guix build-system composer)}. It +implements the build procedure for packages using +@url{https://getcomposer.org/, Composer}, the PHP package manager. + +It automatically adds the @code{php} package to the set of inputs. Which +package is used can be specified with the @code{#:php} parameter. + +The @code{#:test-target} parameter is used to control which script is run +for the tests. By default, the @code{test} script is run if it exists. If +the script does not exist, the build system will run @code{phpunit} from the +source directory, assuming there is a @file{phpunit.xml} file. +@end defvar + @defvar dune-build-system This variable is exported by @code{(guix build-system dune)}. It supports builds of packages using @uref{https://dune.build/, Dune}, a build @@ -14550,7 +14564,7 @@ in Guix. @item composer @cindex Composer @cindex PHP -Import metadat from the @uref{https://getcomposer.org/, Composer} package +Import metadata from the @uref{https://getcomposer.org/, Composer} package archive used by the PHP community, as in this example: @example diff --git a/gnu/packages/aux-files/findclass.php b/gnu/packages/aux-files/findclass.php new file mode 100644 index 0000000000..d0b250c8e1 --- /dev/null +++ b/gnu/packages/aux-files/findclass.php @@ -0,0 +1,125 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * This file is copied from the Symfony package. + * + * (c) Fabien Potencier + * + * To the extent to wich it makes sense, as the author of the extract: + * Copyright © 2020 Julien Lepiller + */ + +/** + * Extract the classes in the given file + * + * @param string $path The file to check + * @throws \RuntimeException + * @return array The found classes + */ +function findClasses($path) +{ + $extraTypes = PHP_VERSION_ID < 50400 ? '' : '|trait'; + if (defined('HHVM_VERSION') && version_compare(HHVM_VERSION, '3.3', '>=')) { + $extraTypes .= '|enum'; + } + // Use @ here instead of Silencer to actively suppress 'unhelpful' output + // @link https://github.com/composer/composer/pull/4886 + $contents = @php_strip_whitespace($path); + if (!$contents) { + if (!file_exists($path)) { + $message = 'File at "%s" does not exist, check your classmap definitions'; + } elseif (!is_readable($path)) { + $message = 'File at "%s" is not readable, check its permissions'; + } elseif ('' === trim(file_get_contents($path))) { + // The input file was really empty and thus contains no classes + return array(); + } else { + $message = 'File at "%s" could not be parsed as PHP, it may be binary or corrupted'; + } + $error = error_get_last(); + if (isset($error['message'])) { + $message .= PHP_EOL . 'The following message may be helpful:' . PHP_EOL . $error['message']; + } + throw new \RuntimeException(sprintf($message, $path)); + } + // return early if there is no chance of matching anything in this file + if (!preg_match('{\b(?:class|interface'.$extraTypes.')\s}i', $contents)) { + return array(); + } + // strip heredocs/nowdocs + $contents = preg_replace('{<<<[ \t]*([\'"]?)(\w+)\\1(?:\r\n|\n|\r)(?:.*?)(?:\r\n|\n|\r)(?:\s*)\\2(?=\s+|[;,.)])}s', 'null', $contents); + // strip strings + $contents = preg_replace('{"[^"\\\\]*+(\\\\.[^"\\\\]*+)*+"|\'[^\'\\\\]*+(\\\\.[^\'\\\\]*+)*+\'}s', 'null', $contents); + // strip leading non-php code if needed + if (substr($contents, 0, 2) !== '(?:[^<]++|<(?!\?))*+<\?}s', '?>'); + if (false !== $pos && false === strpos(substr($contents, $pos), '])(?Pclass|interface'.$extraTypes.') \s++ (?P[a-zA-Z_\x7f-\xff:][a-zA-Z0-9_\x7f-\xff:\-]*+) + | \b(?])(?Pnamespace) (?P\s++[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+(?:\s*+\\\\\s*+[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*+)*+)? \s*+ [\{;] + ) + }ix', $contents, $matches); + $classes = array(); + $namespace = ''; + for ($i = 0, $len = count($matches['type']); $i < $len; $i++) { + if (!empty($matches['ns'][$i])) { + $namespace = str_replace(array(' ', "\t", "\r", "\n"), '', $matches['nsname'][$i]) . '\\'; + } else { + $name = $matches['name'][$i]; + // skip anon classes extending/implementing + if ($name === 'extends' || $name === 'implements') { + continue; + } + if ($name[0] === ':') { + // This is an XHP class, https://github.com/facebook/xhp + $name = 'xhp'.substr(str_replace(array('-', ':'), array('_', '__'), $name), 1); + } elseif ($matches['type'][$i] === 'enum') { + // In Hack, something like: + // enum Foo: int { HERP = '123'; } + // The regex above captures the colon, which isn't part of + // the class name. + $name = rtrim($name, ':'); + } + $classes[] = ltrim($namespace . $name, '\\'); + } + } + return $classes; +} + +$options = getopt('i:f:', []); +$file = $options["f"]; +$input = $options["i"]; + +$classes = findClasses($file); +foreach($classes as $class) { + echo '$classmap[\''.$class.'\'] = \''.$input.'/'.$file.'\';'; + echo "\n"; +} diff --git a/guix/build-system/composer.scm b/guix/build-system/composer.scm new file mode 100644 index 0000000000..8bf99ff9c5 --- /dev/null +++ b/guix/build-system/composer.scm @@ -0,0 +1,162 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2019 Julien Lepiller +;;; +;;; 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 build-system composer) + #:use-module (guix store) + #:use-module (guix utils) + #:use-module (guix derivations) + #:use-module (guix search-paths) + #:use-module (guix build-system) + #:use-module (guix build-system gnu) + #:use-module (guix gexp) + #:use-module (guix packages) + #:use-module (gnu packages) + #:use-module (ice-9 match) + #:use-module (srfi srfi-1) + #:export (%composer-build-system-modules + lower + composer-build + composer-build-system)) + +;; Commentary: +;; +;; Standard build procedure for PHP packages using Composer. This is implemented +;; as an extension of `gnu-build-system'. +;; +;; Code: + +(define (default-php) + "Return the default PHP package." + + ;; Do not use `@' to avoid introducing circular dependencies. + (let ((module (resolve-interface '(gnu packages php)))) + (module-ref module 'php))) + +(define (default-findclass) + "Return the default findclass script." + (search-auxiliary-file "findclass.php")) + +(define (default-composer-classloader) + "Return the default composer-classloader package." + + ;; Do not use `@' to avoid introducing circular dependencies. + (let ((module (resolve-interface '(gnu packages php-xyz)))) + (module-ref module 'composer-classloader))) + +(define %composer-build-system-modules + ;; Build-side modules imported by default. + `((guix build composer-build-system) + (guix build union) + (json) + (json builder) + (json parser) + (json record) + ,@%gnu-build-system-modules)) + +(define* (lower name + #:key source inputs native-inputs outputs system target + (php (default-php)) + (composer-classloader (default-composer-classloader)) + (findclass (default-findclass)) + #:allow-other-keys + #:rest arguments) + "Return a bag for NAME." + (define private-keywords + '(#:target #:php #:composer-classloader #:findclass #:inputs #:native-inputs)) + + (and (not target) ;XXX: no cross-compilation + (bag + (name name) + (system system) + (host-inputs `(,@(if source + `(("source" ,source)) + '()) + ,@inputs + + ;; Keep the standard inputs of 'gnu-build-system'. + ,@(standard-packages))) + (build-inputs `(("php" ,php) + ("findclass.php" ,findclass) + ("composer-classloader" ,composer-classloader) + ,@native-inputs)) + (outputs outputs) + (build composer-build) + (arguments (strip-keyword-arguments private-keywords arguments))))) + +(define* (composer-build name inputs + #:key + guile source + (outputs '("out")) + (configure-flags ''()) + (search-paths '()) + (out-of-source? #t) + (composer-file "composer.json") + (tests? #t) + (test-target "test") + (install-target "install") + (validate-runpath? #t) + (patch-shebangs? #t) + (strip-binaries? #t) + (strip-flags #~'("--strip-debug")) + (strip-directories #~'("lib" "lib64" "libexec" + "bin" "sbin")) + (phases '(@ (guix build composer-build-system) + %standard-phases)) + (system (%current-system)) + (imported-modules %composer-build-system-modules) + (modules '((guix build composer-build-system) + (guix build utils)))) + "Build SOURCE using PHP, and with INPUTS. This assumes that SOURCE provides +a 'composer.json' file as its build system." + (define builder + (with-imported-modules imported-modules + #~(begin + (use-modules #$@(sexp->gexp modules)) + + #$(with-build-variables inputs outputs + #~(composer-build + #:source #$source + #:system #$system + #:outputs %outputs + #:inputs %build-inputs + #:search-paths '#$(map search-path-specification->sexp + search-paths) + #:phases #$phases + #:out-of-source? #$out-of-source? + #:composer-file #$composer-file + #:tests? #$tests? + #:test-target #$test-target + #:install-target #$install-target + #:validate-runpath? #$validate-runpath? + #:patch-shebangs? #$patch-shebangs? + #:strip-binaries? #$strip-binaries? + #:strip-flags #$strip-flags + #:strip-directories #$strip-directories))))) + + (gexp->derivation name builder + #:system system + #:target #f + #:graft? #f + #:guile-for-build guile)) + +(define composer-build-system + (build-system + (name 'composer) + (description "The standard Composer build system") + (lower lower))) + +;;; composer.scm ends here diff --git a/guix/build/composer-build-system.scm b/guix/build/composer-build-system.scm new file mode 100644 index 0000000000..bcbae27021 --- /dev/null +++ b/guix/build/composer-build-system.scm @@ -0,0 +1,247 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2019 Julien Lepiller +;;; Copyright © 2023 Nicolas Graves +;;; +;;; 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 build composer-build-system) + #:use-module ((guix build gnu-build-system) #:prefix gnu:) + #:use-module (guix build utils) + #:use-module (ice-9 match) + #:use-module (json) + #:use-module (srfi srfi-26) + #:export (%standard-phases + composer-build)) + +;; Commentary: +;; +;; Builder-side code of the standard composer build procedure. +;; +;; Code: + +(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 (if-specified-to-list fn) + (match-lambda + ((? unspecified?) '()) + (arg (fn arg)) + (_ '()))) + +(define-json-mapping make-composer-autoload + composer-autoload? + json->composer-autoload + (psr-4 composer-autoload-psr-4 "psr-4" (if-specified-to-list identity)) + (classmap composer-autoload-classmap "classmap" + (if-specified-to-list vector->list))) + +(define-json-mapping make-composer-package composer-package? + json->composer-package + (name composer-package-name) + (autoload composer-package-autoload "autoload" + (if-specified-to-list json->composer-autoload)) + (autoload-dev composer-package-autoload-dev "autoload-dev" + (if-specified-to-list json->composer-autoload)) + (require composer-package-require "require" json->require) + (dev-require composer-package-dev-require "require-dev" json->require) + (scripts composer-package-scripts "scripts" + (if-specified-to-list identity)) + (binaries composer-package-binaries "bin" + (if-specified-to-list vector->list))) + +(define* (read-package-data #:key (filename "composer.json")) + (call-with-input-file filename + (lambda (port) + (json->composer-package (json->scm port))))) + +(define* (check #:key composer-file inputs outputs tests? test-target #:allow-other-keys) + "Test the given package." + (when tests? + (mkdir-p "vendor") + (create-autoload (string-append (getcwd) "/vendor") composer-file + (append inputs outputs) #:dev-dependencies? #t) + (let* ((package-data (read-package-data #:filename composer-file)) + (scripts (composer-package-scripts package-data)) + (test-script (assoc-ref scripts test-target)) + (dependencies (composer-package-require package-data)) + (dependencies-dev (composer-package-dev-require package-data)) + (name (composer-package-name package-data))) + (for-each + (match-lambda + ((_ . input) + (let ((bin (find-php-bin input))) + (when bin + (copy-recursively bin "vendor/bin"))))) + inputs) + (match test-script + ((? string? command) + (unless (zero? (system command)) + (throw 'failed-command command))) + (('@ (? string? command) ...) + (for-each + (lambda (c) + (unless (zero? (system c)) + (throw 'failed-command c))) + command)) + (#f (invoke "vendor/bin/phpunit")))))) + +(define (find-php-bin input) + (let* ((web-dir (string-append input "/share/web")) + (vendors (if (file-exists? web-dir) + (find-files web-dir "^vendor$" #:directories? #t) + #f))) + (match vendors + ((vendor) + (let ((bin (string-append vendor "/bin"))) + (and (file-exists? bin) bin))) + (_ #f)))) + +(define (find-php-dep inputs dependency) + (let loop ((inputs inputs)) + (match inputs + (() (throw 'unsatisfied-dependency "Unsatisfied dependency: required " + dependency)) + (((_ . input) inputs ...) + (let ((autoload (string-append input "/share/web/" dependency + "/vendor/autoload_conf.php"))) + (if (file-exists? autoload) + autoload + (loop inputs)))) + ((input inputs ...) + (let ((autoload (string-append input "/share/web/" dependency + "/vendor/autoload_conf.php"))) + (if (file-exists? autoload) + autoload + (loop inputs))))))) + +(define* (create-autoload vendor composer-file inputs #:key dev-dependencies?) + "creates an autoload.php file that sets up the class locations for this package, +so it can be autoloaded by PHP when the package classes are required." + (with-output-to-file (string-append vendor "/autoload.php") + (lambda _ + (display (string-append + " $path) { + $loader->set($namespace, $path); +} +foreach ($psr4map as $namespace => $path) { + $loader->setPsr4($namespace, $path); +} +$loader->addClassMap($classmap); +$loader->register(); +")))) + ;; Now, create autoload_conf.php that contains the actual data, as a set + ;; of arrays + (let* ((package-data (read-package-data #:filename composer-file)) + (autoload (composer-package-autoload package-data)) + (autoload-dev (composer-package-autoload-dev package-data)) + (dependencies (composer-package-require package-data)) + (dependencies-dev (composer-package-dev-require package-data))) + (with-output-to-file (string-append vendor "/autoload_conf.php") + (lambda _ + (format #t " +;;; Copyright © 2023 Nicolas Graves ;;; ;;; This file is part of GNU Guix. ;;; @@ -54,9 +55,6 @@ (define test-json (define test-source "foobar") -;; Avoid collisions with other tests. -(%http-server-port 10450) - (test-begin "composer") (test-assert "composer->guix-package" @@ -66,23 +64,21 @@ (define test-source (parameterize ((%composer-base-url (%local-url)) (current-http-proxy (%local-url))) (match (composer->guix-package "foo/bar") - (('package - ('name "php-foo-bar") - ('version "0.1") - ('source ('origin - ('method 'url-fetch) - ('uri "http://example.com/Bar-0.1.tar.gz") - ('sha256 - ('base32 - (? string? hash))))) - ('build-system 'composer-build-system) - ('native-inputs - ('quasiquote - (("php-phpunit-phpunit" ('unquote 'php-phpunit-phpunit))))) - ('synopsis "") - ('description "description") - ('home-page "http://example.com") - ('license 'license:bsd-3)) + (`(package + (name "php-foo-bar") + (version "0.1") + (source (origin + (method url-fetch) + (uri "http://example.com/Bar-0.1.tar.gz") + (sha256 + (base32 + ,(? string? hash))))) + (build-system composer-build-system) + (native-inputs (list php-phpunit-phpunit)) + (synopsis "") + (description "description") + (home-page "http://example.com") + (license license:bsd-3)) (string=? (bytevector->nix-base32-string (call-with-input-string test-source port-sha256)) hash)) From patchwork Thu Nov 2 15:16:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 55840 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 9DB9A27BBE2; Thu, 2 Nov 2023 15:18:48 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 7379327BBEA for ; Thu, 2 Nov 2023 15:18:47 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qyZSp-00006E-6T; Thu, 02 Nov 2023 11:18:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qyZSn-00004r-4d for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:29 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qyZSm-0003ps-S7 for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:28 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qyZTL-0006bz-RT for guix-patches@gnu.org; Thu, 02 Nov 2023 11:19:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#42338] [PATCH v5 4/9] guix: import: composer: Use memoization. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 02 Nov 2023 15:19:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42338 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 42338@debbugs.gnu.org Cc: ngraves@ngraves.fr Received: via spool by 42338-submit@debbugs.gnu.org id=B42338.169893830125280 (code B ref 42338); Thu, 02 Nov 2023 15:19:03 +0000 Received: (at 42338) by debbugs.gnu.org; 2 Nov 2023 15:18:21 +0000 Received: from localhost ([127.0.0.1]:55783 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSe-0006ZZ-QG for submit@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:21 -0400 Received: from 3.mo560.mail-out.ovh.net ([46.105.58.226]:58487) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSZ-0006Yr-W6 for 42338@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:17 -0400 Received: from director9.ghost.mail-out.ovh.net (unknown [10.108.1.219]) by mo560.mail-out.ovh.net (Postfix) with ESMTP id CDC4226DC5 for <42338@debbugs.gnu.org>; Thu, 2 Nov 2023 15:17:39 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-4qhnc (unknown [10.110.103.155]) by director9.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 70B6F1FE2D; Thu, 2 Nov 2023 15:17:39 +0000 (UTC) Received: from ngraves.fr ([37.59.142.107]) by ghost-submission-6684bf9d7b-4qhnc with ESMTPSA id po6fDJO9Q2UHFAEAIaFYXg (envelope-from ); Thu, 02 Nov 2023 15:17:39 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-107S0011e7a6a1a-d072-4966-a8a2-91deed8b9b29, 1761E107A7246F2314AE904A186E6A889A3776EC) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 87.88.157.103 Date: Thu, 2 Nov 2023 16:16:51 +0100 Message-ID: <20231102151725.31362-5-ngraves@ngraves.fr> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231102151725.31362-1-ngraves@ngraves.fr> References: <20231102151725.31362-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13660262095901156066 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedruddtiedgjeehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefpihgtohhlrghsucfirhgrvhgvshcuoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqnecuggftrfgrthhtvghrnhepgffgfeevhfegueetgeektdeiueejieelteffudeugfefffelffegveeffeetffdtnecuffhomhgrihhnpehprggtkhgrghhishhtrdhorhhgnecukfhppeduvdejrddtrddtrddupdekjedrkeekrdduheejrddutdefpdefjedrheelrddugedvrddutdejnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpeeonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqedpnhgspghrtghpthhtohepuddprhgtphhtthhopeegvdeffeekseguvggssghughhsrdhgnhhurdhorhhgpdfovfetjfhoshhtpehmohehiedtpdhmohguvgepshhmthhpohhuth X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches --- guix/import/composer.scm | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/guix/import/composer.scm b/guix/import/composer.scm index c152f402bb..177dc63092 100644 --- a/guix/import/composer.scm +++ b/guix/import/composer.scm @@ -27,6 +27,7 @@ (define-module (guix import composer) #: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) @@ -197,16 +198,18 @@ (define (make-php-sexp composer-package) ((license) license) (_ license))))))))) -(define* (composer->guix-package package-name #:optional version) - "Fetch the metadata for PACKAGE-NAME from packagist.org, and return the +(define composer->guix-package + (memoize + (lambda* (package-name #:key version #:allow-other-keys) + "Fetch the metadata for PACKAGE-NAME from packagist.org, and return the `package' s-expression corresponding to that package, or #f on failure." - (let ((package (composer-fetch package-name version))) - (and package - (let* ((package (json->composer-package package)) - (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)))))) + (let ((package (composer-fetch package-name version))) + (and package + (let* ((package (json->composer-package package)) + (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)))))))) (define (guix-name->composer-name name) "Given a guix package name, return the name of the package in Packagist." @@ -265,6 +268,7 @@ (define %composer-updater (import latest-release))) (define* (composer-recursive-import package-name #:optional version) - (recursive-import package-name '() + (recursive-import package-name + #:version version #:repo->guix-package composer->guix-package #:guix-name php-package-name)) From patchwork Thu Nov 2 15:16:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 55838 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 508D827BBE9; Thu, 2 Nov 2023 15:18:43 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id A053227BBE2 for ; Thu, 2 Nov 2023 15:18:41 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qyZSp-00006C-5t; Thu, 02 Nov 2023 11:18:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qyZSm-0008WB-Ql for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:28 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qyZSm-0003pl-GZ for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:28 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qyZTL-0006br-FQ for guix-patches@gnu.org; Thu, 02 Nov 2023 11:19:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#42338] [PATCH v5 5/9] guix: import: composer: Fix json->require. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 02 Nov 2023 15:19:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42338 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 42338@debbugs.gnu.org Cc: ngraves@ngraves.fr Received: via spool by 42338-submit@debbugs.gnu.org id=B42338.169893830025272 (code B ref 42338); Thu, 02 Nov 2023 15:19:03 +0000 Received: (at 42338) by debbugs.gnu.org; 2 Nov 2023 15:18:20 +0000 Received: from localhost ([127.0.0.1]:55780 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSe-0006ZQ-8h for submit@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:20 -0400 Received: from 3.mo582.mail-out.ovh.net ([178.33.253.26]:48231) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSa-0006Yt-JE for 42338@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:17 -0400 Received: from director10.ghost.mail-out.ovh.net (unknown [10.109.156.215]) by mo582.mail-out.ovh.net (Postfix) with ESMTP id CD4EC22DCE for <42338@debbugs.gnu.org>; Thu, 2 Nov 2023 15:17:40 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-cfcvv (unknown [10.110.171.34]) by director10.ghost.mail-out.ovh.net (Postfix) with ESMTPS id 85E051FE9C; Thu, 2 Nov 2023 15:17:40 +0000 (UTC) Received: from ngraves.fr ([37.59.142.106]) by ghost-submission-6684bf9d7b-cfcvv with ESMTPSA id R4GJHJS9Q2WFEQEA0wFIyQ (envelope-from ); Thu, 02 Nov 2023 15:17:40 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-106R006a2988ee5-162b-46ba-8cf6-7d026d76c949, 1761E107A7246F2314AE904A186E6A889A3776EC) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 87.88.157.103 Date: Thu, 2 Nov 2023 16:16:52 +0100 Message-ID: <20231102151725.31362-6-ngraves@ngraves.fr> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231102151725.31362-1-ngraves@ngraves.fr> References: <20231102151725.31362-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13660543571319317218 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedruddtiedgjeegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefpihgtohhlrghsucfirhgrvhgvshcuoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqnecuggftrfgrthhtvghrnhepleffjeetueethfefkeffffefvddukeejkefgleduiedthfekvefhiedvhfffgeegnecukfhppeduvdejrddtrddtrddupdekjedrkeekrdduheejrddutdefpdefjedrheelrddugedvrddutdeinecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpeeonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqedpnhgspghrtghpthhtohepuddprhgtphhtthhopeegvdeffeekseguvggssghughhsrdhgnhhurdhorhhgpdfovfetjfhoshhtpehmohehkedvpdhmohguvgepshhmthhpohhuth X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches --- guix/import/composer.scm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/guix/import/composer.scm b/guix/import/composer.scm index 177dc63092..3acbbecf82 100644 --- a/guix/import/composer.scm +++ b/guix/import/composer.scm @@ -88,7 +88,8 @@ (define (json->require dict) ((((? (cut string-contains <> "/") name) . _) require ...) (loop (cons name result) require)) - ((_ require ...) (loop result require)))) + ((_ require ...) (loop result require)) + (_ result))) '())) (define-json-mapping make-composer-source composer-source? From patchwork Thu Nov 2 15:16:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 55845 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id EBD7C27BBE9; Thu, 2 Nov 2023 15:19:51 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id D7CE327BBE2 for ; Thu, 2 Nov 2023 15:19:50 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qyZSx-0000AO-4k; Thu, 02 Nov 2023 11:18:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qyZSo-00005e-2o for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:30 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qyZSn-0003q6-Mj for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:29 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qyZTM-0006cE-Lk for guix-patches@gnu.org; Thu, 02 Nov 2023 11:19:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#42338] [PATCH v5 6/9] guix: import: composer: More robust string->license. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 02 Nov 2023 15:19:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42338 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 42338@debbugs.gnu.org Cc: ngraves@ngraves.fr Received: via spool by 42338-submit@debbugs.gnu.org id=B42338.169893830525313 (code B ref 42338); Thu, 02 Nov 2023 15:19:04 +0000 Received: (at 42338) by debbugs.gnu.org; 2 Nov 2023 15:18:25 +0000 Received: from localhost ([127.0.0.1]:55788 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSi-0006aC-J4 for submit@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:24 -0400 Received: from 1.mo575.mail-out.ovh.net ([46.105.41.146]:34115) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSd-0006Z1-4t for 42338@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:21 -0400 Received: from director6.ghost.mail-out.ovh.net (unknown [10.108.16.216]) by mo575.mail-out.ovh.net (Postfix) with ESMTP id 4A15928F5A for <42338@debbugs.gnu.org>; Thu, 2 Nov 2023 15:17:42 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-m2wzr (unknown [10.110.171.34]) by director6.ghost.mail-out.ovh.net (Postfix) with ESMTPS id DD9D91FEA9; Thu, 2 Nov 2023 15:17:41 +0000 (UTC) Received: from ngraves.fr ([37.59.142.99]) by ghost-submission-6684bf9d7b-m2wzr with ESMTPSA id ydjfJ5W9Q2UW9QAAgBOxzA (envelope-from ); Thu, 02 Nov 2023 15:17:41 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-99G003faf7ff7b-72cf-49aa-a267-83035e8d9a5b, 1761E107A7246F2314AE904A186E6A889A3776EC) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 87.88.157.103 Date: Thu, 2 Nov 2023 16:16:53 +0100 Message-ID: <20231102151725.31362-7-ngraves@ngraves.fr> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231102151725.31362-1-ngraves@ngraves.fr> References: <20231102151725.31362-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13661106521551069922 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedruddtiedgjeehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefpihgtohhlrghsucfirhgrvhgvshcuoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqnecuggftrfgrthhtvghrnhepleffjeetueethfefkeffffefvddukeejkefgleduiedthfekvefhiedvhfffgeegnecukfhppeduvdejrddtrddtrddupdekjedrkeekrdduheejrddutdefpdefjedrheelrddugedvrdelleenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqpdhnsggprhgtphhtthhopedupdhrtghpthhtohepgedvfeefkeesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheejhedpmhhouggvpehsmhhtphhouhht X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/import/composer.scm (string->license): Use spdx-string->license. Fall back to unknown-license!. --- guix/import/composer.scm | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/guix/import/composer.scm b/guix/import/composer.scm index 3acbbecf82..49f16caedf 100644 --- a/guix/import/composer.scm +++ b/guix/import/composer.scm @@ -109,7 +109,10 @@ (define-json-mapping make-composer-package composer-package? (dev-require composer-package-dev-require "require-dev" json->require) (license composer-package-license "license" (lambda (vector) - (map string->license (vector->list vector))))) + (let ((l (map string->license (vector->list vector)))) + (if (eq? (length l) 1) + (car l) + `(list ,@l)))))) (define* (composer-fetch name #:optional version) "Return an alist representation of the Composer metadata for the package NAME, @@ -194,10 +197,8 @@ (define (make-php-sexp composer-package) (synopsis "") (description ,(composer-package-description composer-package)) (home-page ,(composer-package-homepage composer-package)) - (license ,(match (composer-package-license composer-package) - (() #f) - ((license) license) - (_ license))))))))) + (license ,(or (composer-package-license composer-package) + 'unknown-license!)))))))) (define composer->guix-package (memoize @@ -234,14 +235,15 @@ (define (guix-package->composer-name package) (define (string->license str) "Convert the string STR into a license object." - (match str - ("GNU LGPL" 'license:lgpl2.0) - ("GPL" 'license:gpl3) - ((or "BSD" "BSD License" "BSD-3-Clause") '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) - (_ #f))) + (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." From patchwork Thu Nov 2 15:16:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 55837 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 9082327BBE9; Thu, 2 Nov 2023 15:18:37 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 3710427BBE2 for ; Thu, 2 Nov 2023 15:18:36 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qyZSp-00006O-AF; Thu, 02 Nov 2023 11:18:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qyZSn-000059-Lh for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:29 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qyZSn-0003py-7E for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:29 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qyZTM-0006c6-6m for guix-patches@gnu.org; Thu, 02 Nov 2023 11:19:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#42338] [PATCH v5 7/9] guix: import: composer: Modern inputs formatting. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 02 Nov 2023 15:19:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42338 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 42338@debbugs.gnu.org Cc: ngraves@ngraves.fr Received: via spool by 42338-submit@debbugs.gnu.org id=B42338.169893830125289 (code B ref 42338); Thu, 02 Nov 2023 15:19:04 +0000 Received: (at 42338) by debbugs.gnu.org; 2 Nov 2023 15:18:21 +0000 Received: from localhost ([127.0.0.1]:55785 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSf-0006Zh-7d for submit@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:21 -0400 Received: from 12.mo582.mail-out.ovh.net ([178.32.125.228]:33887) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSd-0006ZD-8F for 42338@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:20 -0400 Received: from director4.ghost.mail-out.ovh.net (unknown [10.109.138.16]) by mo582.mail-out.ovh.net (Postfix) with ESMTP id 2A19F229AF for <42338@debbugs.gnu.org>; Thu, 2 Nov 2023 15:17:43 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-w9xmf (unknown [10.110.171.120]) by director4.ghost.mail-out.ovh.net (Postfix) with ESMTPS id E0AB81FD68; Thu, 2 Nov 2023 15:17:42 +0000 (UTC) Received: from ngraves.fr ([37.59.142.97]) by ghost-submission-6684bf9d7b-w9xmf with ESMTPSA id 563qM5a9Q2VgGQEAkDpEYg (envelope-from ); Thu, 02 Nov 2023 15:17:42 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-97G00207eb3580-2e67-4d3f-b4f9-4660a3fd04b9, 1761E107A7246F2314AE904A186E6A889A3776EC) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 87.88.157.103 Date: Thu, 2 Nov 2023 16:16:54 +0100 Message-ID: <20231102151725.31362-8-ngraves@ngraves.fr> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231102151725.31362-1-ngraves@ngraves.fr> References: <20231102151725.31362-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13661387996363678434 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedruddtiedgjeegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefpihgtohhlrghsucfirhgrvhgvshcuoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqnecuggftrfgrthhtvghrnhepleffjeetueethfefkeffffefvddukeejkefgleduiedthfekvefhiedvhfffgeegnecukfhppeduvdejrddtrddtrddupdekjedrkeekrdduheejrddutdefpdefjedrheelrddugedvrdeljeenucevlhhushhtvghrufhiiigvpedvnecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqpdhnsggprhgtphhtthhopedupdhrtghpthhtohepgedvfeefkeesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheekvddpmhhouggvpehsmhhtphhouhht X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/import/composer.scm (make-php-sexp): Update inputs formatting. --- guix/import/composer.scm | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/guix/import/composer.scm b/guix/import/composer.scm index 49f16caedf..89c8ea9113 100644 --- a/guix/import/composer.scm +++ b/guix/import/composer.scm @@ -179,21 +179,11 @@ (define (make-php-sexp composer-package) ,@(if (null? dependencies) '() `((inputs - (,'quasiquote - ,(map (lambda (name) - `(,name - (,'unquote - ,(string->symbol name)))) - dependencies))))) + (list ,@(map string->symbol dependencies))))) ,@(if (null? dev-dependencies) '() `((native-inputs - (,'quasiquote - ,(map (lambda (name) - `(,name - (,'unquote - ,(string->symbol name)))) - dev-dependencies))))) + (list ,@(map string->symbol dev-dependencies))))) (synopsis "") (description ,(composer-package-description composer-package)) (home-page ,(composer-package-homepage composer-package)) From patchwork Thu Nov 2 15:16:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 55841 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 9FDC327BBE9; Thu, 2 Nov 2023 15:18:53 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id DFC4027BBE2 for ; Thu, 2 Nov 2023 15:18:50 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qyZSs-000073-D8; Thu, 02 Nov 2023 11:18:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qyZSo-00005v-Kj for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:30 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qyZSo-0003qC-2w for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:30 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qyZTN-0006cL-1a for guix-patches@gnu.org; Thu, 02 Nov 2023 11:19:05 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#42338] [PATCH v5 8/9] guix: import: composer: Full rewrite composer-fetch. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 02 Nov 2023 15:19:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42338 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 42338@debbugs.gnu.org Cc: ngraves@ngraves.fr Received: via spool by 42338-submit@debbugs.gnu.org id=B42338.169893830525320 (code B ref 42338); Thu, 02 Nov 2023 15:19:04 +0000 Received: (at 42338) by debbugs.gnu.org; 2 Nov 2023 15:18:25 +0000 Received: from localhost ([127.0.0.1]:55790 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSi-0006aE-Tt for submit@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:25 -0400 Received: from 7.mo575.mail-out.ovh.net ([46.105.63.230]:35809) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSe-0006ZG-6W for 42338@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:21 -0400 Received: from director8.ghost.mail-out.ovh.net (unknown [10.109.143.79]) by mo575.mail-out.ovh.net (Postfix) with ESMTP id 21FDA28F49 for <42338@debbugs.gnu.org>; Thu, 2 Nov 2023 15:17:44 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-vt5f5 (unknown [10.110.103.93]) by director8.ghost.mail-out.ovh.net (Postfix) with ESMTPS id B5C3A1FEB4; Thu, 2 Nov 2023 15:17:43 +0000 (UTC) Received: from ngraves.fr ([37.59.142.99]) by ghost-submission-6684bf9d7b-vt5f5 with ESMTPSA id x1lWKZe9Q2Vq5gAA5SnFsg (envelope-from ); Thu, 02 Nov 2023 15:17:43 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-99G003d815ace5-ccaf-45bc-aa7d-6b6576e44ec2, 1761E107A7246F2314AE904A186E6A889A3776EC) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 87.88.157.103 Date: Thu, 2 Nov 2023 16:16:55 +0100 Message-ID: <20231102151725.31362-9-ngraves@ngraves.fr> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231102151725.31362-1-ngraves@ngraves.fr> References: <20231102151725.31362-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13661669471634907874 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedruddtiedgjeehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefpihgtohhlrghsucfirhgrvhgvshcuoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqnecuggftrfgrthhtvghrnhepgffgfeevhfegueetgeektdeiueejieelteffudeugfefffelffegveeffeetffdtnecuffhomhgrihhnpehprggtkhgrghhishhtrdhorhhgnecukfhppeduvdejrddtrddtrddupdekjedrkeekrdduheejrddutdefpdefjedrheelrddugedvrdelleenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpeduvdejrddtrddtrddupdhmrghilhhfrhhomhepoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqpdhnsggprhgtphhtthhopedupdhrtghpthhtohepgedvfeefkeesuggvsggsuhhgshdrghhnuhdrohhrghdpoffvtefjohhsthepmhhoheejhedpmhhouggvpehsmhhtphhouhht X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Change-Id: I1c01c242cefe0bc4cfc9bd9a5717d10a61dd575e --- guix/import/composer.scm | 154 +++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 77 deletions(-) diff --git a/guix/import/composer.scm b/guix/import/composer.scm index 89c8ea9113..2cc8861bdd 100644 --- a/guix/import/composer.scm +++ b/guix/import/composer.scm @@ -19,7 +19,7 @@ (define-module (guix import composer) #:use-module (ice-9 match) #:use-module (json) - #:use-module (gcrypt hash) + #:use-module (guix hash) #:use-module (guix base32) #:use-module (guix build git) #:use-module (guix build utils) @@ -44,27 +44,6 @@ (define-module (guix import composer) (define %composer-base-url (make-parameter "https://repo.packagist.org")) -;; XXX adapted from (guix scripts hash) -(define (file-hash file select? recursive?) - ;; Compute the hash of FILE. - (if recursive? - (let-values (((port get-hash) (open-sha256-port))) - (write-file file port #:select? select?) - (force-output port) - (get-hash)) - (call-with-input-file file port-sha256))) - -;; XXX taken from (guix scripts hash) -(define (vcs-file? file stat) - (case (stat:type stat) - ((directory) - (member (basename file) '(".bzr" ".git" ".hg" ".svn" "CVS"))) - ((regular) - ;; Git sub-modules have a '.git' file that is a regular text file. - (string=? (basename file) ".git")) - (else - #f))) - (define (fix-version version) "Return a fixed version from a version string. For instance, v10.1 -> 10.1" (cond @@ -114,22 +93,36 @@ (define-json-mapping make-composer-package composer-package? (car l) `(list ,@l)))))) -(define* (composer-fetch name #:optional version) - "Return an alist representation of the Composer metadata for the package NAME, -or #f on failure." - (let ((package (json-fetch - (string-append (%composer-base-url) "/p/" name ".json")))) - (if package - (let* ((packages (assoc-ref package "packages")) - (package (or (assoc-ref packages name) package)) - (versions (filter - (lambda (version) - (and (not (string-contains version "dev")) - (not (string-contains version "beta")))) - (map car package))) - (version (or (if (null? version) #f version) - (latest-version versions)))) - (assoc-ref package version)) +(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 #f)) + "Return a composer-package representation of the Composer metadata for the +package NAME with optional VERSION, or #f on failure." + (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)))))) + (if packages + (json->composer-package + (if version + (assoc-ref packages version) + (cdr + (reduce + (lambda (new cur-max) + (match new + (((? valid-version? version) . tail) + (if (version>? (fix-version version) + (fix-version (car cur-max))) + (cons* version tail) + cur-max)) + (_ cur-max))) + (cons* "0.0.0" #f) + packages)))) #f))) (define (php-package-name name) @@ -158,47 +151,55 @@ (define (make-php-sexp composer-package) (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 ,(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 (negate vcs-file?) #t))))) - `((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-public ,(string->symbol + (composer-package-name composer-package)) + (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 #:allow-other-keys) + (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, or #f on failure." - (let ((package (composer-fetch package-name version))) + (let ((package (composer-fetch package-name #:version version))) (and package - (let* ((package (json->composer-package package)) - (dependencies-names (composer-package-require 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)))))))) @@ -238,14 +239,13 @@ (define (string->license str) (define (php-package? package) "Return true if PACKAGE is a PHP package from Packagist." (and - (eq? (build-system-name (package-build-system package)) 'composer) - (string-prefix? "php-" (package-name package)))) + (eq? (package-build-system package) composer-build-system) + (string-prefix? "php-" (package-name package)))) (define (latest-release package) "Return an for the latest release of PACKAGE." (let* ((php-name (guix-package->composer-name package)) - (metadata (composer-fetch php-name)) - (package (json->composer-package metadata)) + (package (composer-fetch php-name)) (version (composer-package-version package)) (url (composer-source-url (composer-package-source package)))) (upstream-source From patchwork Thu Nov 2 15:16:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 55839 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 4A5CD27BBE9; Thu, 2 Nov 2023 15:18:48 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,MAILING_LIST_MULTI, SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 2EA0927BBE2 for ; Thu, 2 Nov 2023 15:18:46 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qyZSs-00007n-VA; Thu, 02 Nov 2023 11:18:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qyZSo-000067-QD for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:30 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qyZSo-0003qF-Ge for guix-patches@gnu.org; Thu, 02 Nov 2023 11:18:30 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qyZTN-0006cS-Eo for guix-patches@gnu.org; Thu, 02 Nov 2023 11:19:05 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#42338] [PATCH v5 9/9] gnu: composer-build-system: Full check phase rewrite. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 02 Nov 2023 15:19:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 42338 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 42338@debbugs.gnu.org Cc: ngraves@ngraves.fr Received: via spool by 42338-submit@debbugs.gnu.org id=B42338.169893830625327 (code B ref 42338); Thu, 02 Nov 2023 15:19:05 +0000 Received: (at 42338) by debbugs.gnu.org; 2 Nov 2023 15:18:26 +0000 Received: from localhost ([127.0.0.1]:55792 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSj-0006aL-Hu for submit@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:26 -0400 Received: from 8.mo550.mail-out.ovh.net ([178.33.110.239]:40205) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qyZSf-0006ZX-C2 for 42338@debbugs.gnu.org; Thu, 02 Nov 2023 11:18:22 -0400 Received: from director2.ghost.mail-out.ovh.net (unknown [10.108.4.253]) by mo550.mail-out.ovh.net (Postfix) with ESMTP id 4A914290F0 for <42338@debbugs.gnu.org>; Thu, 2 Nov 2023 15:17:45 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-qvpd6 (unknown [10.110.171.251]) by director2.ghost.mail-out.ovh.net (Postfix) with ESMTPS id C56111FE79; Thu, 2 Nov 2023 15:17:44 +0000 (UTC) Received: from ngraves.fr ([37.59.142.110]) by ghost-submission-6684bf9d7b-qvpd6 with ESMTPSA id uc23LJi9Q2V3MgEAyqyfIw (envelope-from ); Thu, 02 Nov 2023 15:17:44 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-110S004da97deae-e500-47b6-835b-a6d0b8d515a5, 1761E107A7246F2314AE904A186E6A889A3776EC) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 87.88.157.103 Date: Thu, 2 Nov 2023 16:16:56 +0100 Message-ID: <20231102151725.31362-10-ngraves@ngraves.fr> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231102151725.31362-1-ngraves@ngraves.fr> References: <20231102151725.31362-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 13661950945032987362 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedruddtiedgjeehucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefpihgtohhlrghsucfirhgrvhgvshcuoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqnecuggftrfgrthhtvghrnhepleffjeetueethfefkeffffefvddukeejkefgleduiedthfekvefhiedvhfffgeegnecukfhppeduvdejrddtrddtrddupdekjedrkeekrdduheejrddutdefpdefjedrheelrddugedvrdduuddtnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpeeonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqedpnhgspghrtghpthhtohepuddprhgtphhtthhopeegvdeffeekseguvggssghughhsrdhgnhhurdhorhhgpdfovfetjfhoshhtpehmohehhedtpdhmohguvgepshhmthhpohhuthdpughkihhmpehprghssh X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches Change-Id: I824b27b925cd718ee83ef6b2ee4a8a1e69455de6 --- guix/build-system/composer.scm | 2 + guix/build/composer-build-system.scm | 239 ++++++++++++++++----------- 2 files changed, 148 insertions(+), 93 deletions(-) diff --git a/guix/build-system/composer.scm b/guix/build-system/composer.scm index 8bf99ff9c5..7d2ad2b398 100644 --- a/guix/build-system/composer.scm +++ b/guix/build-system/composer.scm @@ -107,6 +107,7 @@ (define* (composer-build name inputs (composer-file "composer.json") (tests? #t) (test-target "test") + (test-flags ''()) (install-target "install") (validate-runpath? #t) (patch-shebangs? #t) @@ -140,6 +141,7 @@ (define builder #:composer-file #$composer-file #:tests? #$tests? #:test-target #$test-target + #:test-flags #$test-flags #:install-target #$install-target #:validate-runpath? #$validate-runpath? #:patch-shebangs? #$patch-shebangs? diff --git a/guix/build/composer-build-system.scm b/guix/build/composer-build-system.scm index bcbae27021..6f05801ad1 100644 --- a/guix/build/composer-build-system.scm +++ b/guix/build/composer-build-system.scm @@ -53,9 +53,22 @@ (define (if-specified-to-list fn) (define-json-mapping make-composer-autoload composer-autoload? json->composer-autoload - (psr-4 composer-autoload-psr-4 "psr-4" (if-specified-to-list identity)) + (psr-4 composer-autoload-psr-4 "psr-4" + (match-lambda + ((? unspecified?) '()) + ((? (lambda (al) + (and (list? al) (pair? (car al)) (vector? (cdar al)))) al) + (append-map + (lambda (vect-el) + (list (cons (caar al) vect-el))) + (vector->list (cdar al)))) + ((? list? l) l) + (_ '()))) + (psr-0 composer-autoload-psr-0 "psr-0" (if-specified-to-list identity)) (classmap composer-autoload-classmap "classmap" - (if-specified-to-list vector->list))) + (if-specified-to-list vector->list)) + (files composer-autoload-files "files" + (if-specified-to-list vector->list))) (define-json-mapping make-composer-package composer-package? json->composer-package @@ -76,65 +89,57 @@ (define* (read-package-data #:key (filename "composer.json")) (lambda (port) (json->composer-package (json->scm port))))) -(define* (check #:key composer-file inputs outputs tests? test-target #:allow-other-keys) - "Test the given package." +(define* (create-test-autoload #:key composer-file inputs outputs tests? + #:allow-other-keys) + "Create the autoload.php file for tests. This is a standalone phase so that +the autoload.php file can be edited before the check phase." (when tests? (mkdir-p "vendor") (create-autoload (string-append (getcwd) "/vendor") composer-file - (append inputs outputs) #:dev-dependencies? #t) - (let* ((package-data (read-package-data #:filename composer-file)) - (scripts (composer-package-scripts package-data)) - (test-script (assoc-ref scripts test-target)) - (dependencies (composer-package-require package-data)) - (dependencies-dev (composer-package-dev-require package-data)) - (name (composer-package-name package-data))) - (for-each - (match-lambda - ((_ . input) - (let ((bin (find-php-bin input))) - (when bin - (copy-recursively bin "vendor/bin"))))) - inputs) - (match test-script - ((? string? command) - (unless (zero? (system command)) - (throw 'failed-command command))) - (('@ (? string? command) ...) - (for-each - (lambda (c) - (unless (zero? (system c)) - (throw 'failed-command c))) - command)) - (#f (invoke "vendor/bin/phpunit")))))) + inputs #:dev-dependencies? #t))) -(define (find-php-bin input) - (let* ((web-dir (string-append input "/share/web")) - (vendors (if (file-exists? web-dir) - (find-files web-dir "^vendor$" #:directories? #t) - #f))) - (match vendors - ((vendor) - (let ((bin (string-append vendor "/bin"))) - (and (file-exists? bin) bin))) - (_ #f)))) +(define (find-bin script inputs) + (search-input-file inputs + (string-append + "bin/" + (string-drop script (string-length "vendor/bin/"))))) -(define (find-php-dep inputs dependency) - (let loop ((inputs inputs)) - (match inputs - (() (throw 'unsatisfied-dependency "Unsatisfied dependency: required " - dependency)) - (((_ . input) inputs ...) - (let ((autoload (string-append input "/share/web/" dependency - "/vendor/autoload_conf.php"))) - (if (file-exists? autoload) - autoload - (loop inputs)))) - ((input inputs ...) - (let ((autoload (string-append input "/share/web/" dependency - "/vendor/autoload_conf.php"))) - (if (file-exists? autoload) - autoload - (loop inputs))))))) +(define* (check #:key composer-file inputs + tests? test-target test-flags #:allow-other-keys) + "Test the given package. +Please note that none of the PHP packages at the time of the rewrite of the +build-system did use the test-script field. This means that the @code{match +test-script} part is not tested on a real example and relies on the original +implementation." + (if tests? + (let* ((package-data (read-package-data #:filename composer-file)) + (scripts (composer-package-scripts package-data)) + (test-script (assoc-ref scripts test-target))) + (match test-script + ((? string? bin) + (let ((command (find-bin bin inputs))) + (unless (zero? (apply system command test-flags)) + (throw 'failed-command command)))) + (('@ (? string? bins) ...) + (for-each + (lambda (c) + (let ((command (find-bin bin inputs))) + (unless (zero? (apply system command test-flags)) + (throw 'failed-command command)))) + bins)) + (_ (if (file-exists? "phpunit.xml.dist") + (apply invoke + (with-exception-handler + (lambda (exn) + (if (search-error? exn) + (error "\ +Missing php-phpunit-phpunit native input.~%") + (raise exn))) + (lambda () + (search-input-file (or inputs '()) "bin/phpunit"))) + test-flags)) + (format #t "No test suite found.~%")))) + (format #t "Test suite not run.~%"))) (define* (create-autoload vendor composer-file inputs #:key dev-dependencies?) "creates an autoload.php file that sets up the class locations for this package, @@ -144,15 +149,14 @@ (define* (create-autoload vendor composer-file inputs #:key dev-dependencies?) (display (string-append " $path) { - $loader->set($namespace, $path); -} -foreach ($psr4map as $namespace => $path) { - $loader->setPsr4($namespace, $path); +foreach ($psr4map as $namespace => $paths) { + foreach ($paths as $path) { + $loader->addPsr4($namespace, $path); + } } $loader->addClassMap($classmap); $loader->register(); @@ -170,37 +174,85 @@ (define* (create-autoload vendor composer-file inputs #:key dev-dependencies?) (format #t "// autoload_conf.php @generated by Guix~%") (force-output) (for-each - (lambda (psr4) - (match psr4 - ((key . value) - (format #t "$psr4map['~a'] = '~a/../~a';~%" - (string-join (string-split key #\\) "\\\\") - vendor value)))) + (match-lambda + ((key . value) + (let ((vals (if (list? value) + (reverse value) + (list value)))) + (apply + format + #t + (string-append + "$psr4map['~a'][] = [" + (string-join + (make-list (length vals) "'~a/../~a'") ",") + "];~%") + (cons* (string-join (string-split key #\\) "\\\\") + (append-map (lambda (v) (list vendor v)) vals))))) + (_ (format #t ""))) + (merge-duplicates (append - (composer-autoload-psr-4 autoload) - (if dev-dependencies? - (composer-autoload-psr-4 autoload-dev) - '()))) + (composer-autoload-psr-4 autoload) + (if (and dev-dependencies? (not (null? autoload-dev))) + (composer-autoload-psr-4 autoload-dev) + '())) + '())) (for-each - (lambda (classmap) - (for-each - (lambda (file) - (invoke "php" (assoc-ref inputs "findclass.php") - "-i" (string-append vendor "/..") "-f" file)) - (find-files classmap ".(php|hh|inc)$"))) - (append - (composer-autoload-classmap autoload) - (if dev-dependencies? - (composer-autoload-classmap autoload-dev) - '()))) + (lambda (psr0) + (match psr0 + ((key . value) + (format #t "$psr4map['~a'][] = ['~a/../~a/~a'];~%" + (string-join (string-split key #\\) "\\\\") + vendor + value + (string-join (string-split key #\\) "/"))) + (_ (format #t "")))) + (append + (composer-autoload-psr-0 autoload) + (if (and dev-dependencies? (not (null? autoload-dev))) + (composer-autoload-psr-0 autoload-dev) + '()))) (for-each - (lambda (dep) - (format #t "require_once '~a';~%" (find-php-dep inputs dep))) - (append - dependencies - (if dev-dependencies? - dependencies-dev - '()))))))) + (lambda (classmap) + (for-each + (lambda (file) + (invoke "php" (assoc-ref inputs "findclass.php") + "-i" (string-append vendor "/..") "-f" file)) + (find-files classmap ".(php|hh|inc)$"))) + (append + (composer-autoload-classmap autoload) + (if (and dev-dependencies? (not (null? autoload-dev))) + (composer-autoload-classmap autoload-dev) + '()))) + (for-each + (lambda (file) + (format #t "require_once '~a/../~a';~%" vendor file)) + (append + (composer-autoload-files autoload) + (if (and dev-dependencies? (not (null? autoload-dev))) + (composer-autoload-files autoload-dev) + '()))) + (for-each + (lambda (dep) + (format + #t "require_once '~a';~%" + (search-input-file + inputs + (string-append "/share/web/" dep "/vendor/autoload_conf.php")))) + dependencies) + ;; Also add native-inputs that are not necessarily given in the + ;; composer.json. This allows to simply add a package in tests by + ;; adding it in native-inputs, without the need to patch composer.json. + (for-each + (match-lambda + ((name . loc) + (match (find-files loc "autoload_conf\\.php$") + (() #t) + (((? string? conf) . ()) + (format #t "require_once '~a';~%" conf)) + (_ #t))) + (_ #t)) + (or inputs '())))))) (define* (install #:key inputs outputs composer-file #:allow-other-keys) "Install the given package." @@ -237,7 +289,8 @@ (define %standard-phases (delete 'build) (delete 'check) (replace 'install install) - (add-after 'install 'check check))) + (add-after 'install 'check check) + (add-after 'install 'create-test-autoload create-test-autoload))) (define* (composer-build #:key inputs (phases %standard-phases) #:allow-other-keys #:rest args)