diff --git a/Makefile.am b/Makefile.am index 49fe57a095..8e91e1e558 100644 --- a/Makefile.am +++ b/Makefile.am @@ -68,7 +68,6 @@ MODULES = \ guix/cpio.scm \ guix/deprecation.scm \ guix/docker.scm \ - guix/json.scm \ guix/records.scm \ guix/openpgp.scm \ guix/pki.scm \ diff --git a/doc/guix.texi b/doc/guix.texi index f224e356bc..4e9e5581c3 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -790,7 +790,8 @@ or later; @c FIXME: Specify a version number once a release has been made. @uref{https://gitlab.com/guile-git/guile-git, Guile-Git}, from August 2017 or later; -@item @uref{https://savannah.nongnu.org/projects/guile-json/, Guile-JSON} 3.x; +@item @uref{https://savannah.nongnu.org/projects/guile-json/, +Guile-JSON} 4.3.0 or later; @item @url{https://www.gnu.org/software/make/, GNU Make}. @end itemize diff --git a/guix/ci.scm b/guix/ci.scm index 02eb90e6c3..7a03befc7c 100644 --- a/guix/ci.scm +++ b/guix/ci.scm @@ -19,7 +19,6 @@ (define-module (guix ci) #:use-module (guix http-client) - #:use-module (guix json) #:use-module (json) #:use-module (srfi srfi-1) #:use-module (ice-9 match) diff --git a/guix/cve.scm b/guix/cve.scm index ae9cca2341..57b8459d01 100644 --- a/guix/cve.scm +++ b/guix/cve.scm @@ -19,7 +19,6 @@ (define-module (guix cve) #:use-module (guix utils) #:use-module (guix http-client) - #:use-module (guix json) #:use-module (guix i18n) #:use-module ((guix diagnostics) #:select (formatted-message)) #:use-module (json) diff --git a/guix/git-download.scm b/guix/git-download.scm index 90634a8c4c..8e575e3b5f 100644 --- a/guix/git-download.scm +++ b/guix/git-download.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès +;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019, 2020 Ludovic Courtès ;;; Copyright © 2017 Mathieu Lirzin ;;; Copyright © 2017 Christopher Baines ;;; Copyright © 2020 Jakub Kądziołka @@ -85,7 +85,7 @@ HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f." 'tar))))) (define guile-json - (module-ref (resolve-interface '(gnu packages guile)) 'guile-json-3)) + (module-ref (resolve-interface '(gnu packages guile)) 'guile-json-4)) (define guile-zlib (module-ref (resolve-interface '(gnu packages guile)) 'guile-zlib)) diff --git a/guix/import/cpan.scm b/guix/import/cpan.scm index 085467b871..fd940415a2 100644 --- a/guix/import/cpan.scm +++ b/guix/import/cpan.scm @@ -28,7 +28,6 @@ #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (json) - #:use-module (guix json) #:use-module (gcrypt hash) #:use-module (guix store) #:use-module (guix utils) diff --git a/guix/import/crate.scm b/guix/import/crate.scm index 796a7641e9..f87c89163c 100644 --- a/guix/import/crate.scm +++ b/guix/import/crate.scm @@ -24,7 +24,6 @@ #:use-module ((guix download) #:prefix download:) #:use-module (gcrypt hash) #:use-module (guix http-client) - #:use-module (guix json) #:use-module (guix import json) #:use-module (guix import utils) #:use-module ((guix licenses) #:prefix license:) diff --git a/guix/import/gem.scm b/guix/import/gem.scm index a2d99ddbca..3fe240f36a 100644 --- a/guix/import/gem.scm +++ b/guix/import/gem.scm @@ -22,7 +22,7 @@ (define-module (guix import gem) #:use-module (ice-9 match) #:use-module (srfi srfi-1) - #:use-module (guix json) + #:use-module (json) #:use-module ((guix download) #:prefix download:) #:use-module (guix import utils) #:use-module (guix import json) diff --git a/guix/import/pypi.scm b/guix/import/pypi.scm index a4a2489688..15116e349d 100644 --- a/guix/import/pypi.scm +++ b/guix/import/pypi.scm @@ -46,7 +46,7 @@ #:use-module (guix import utils) #:use-module ((guix download) #:prefix download:) #:use-module (guix import json) - #:use-module (guix json) + #:use-module (json) #:use-module (guix packages) #:use-module (guix upstream) #:use-module ((guix licenses) #:prefix license:) diff --git a/guix/json.scm b/guix/json.scm deleted file mode 100644 index 3e3a28b749..0000000000 --- a/guix/json.scm +++ /dev/null @@ -1,83 +0,0 @@ -;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2018, 2019, 2020 Ludovic Courtès -;;; -;;; 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 json) - #:use-module (json) - #:use-module (srfi srfi-9)) - -;;; Commentary: -;;; -;;; Helpers to map JSON objects to SRFI-9 records. Taken from (guix swh). -;;; This module is superseded by 'define-json-mapping' as found since version -;;; 4.2.0 of Guile-JSON and will be removed once migration is complete. -;;; -;;; Code: - -(define-syntax define-as-needed - (lambda (s) - "Define the given syntax rule unless (json) already provides it." - (syntax-case s () - ((_ (macro args ...) body ...) - (if (module-defined? (resolve-interface '(json)) - (syntax->datum #'macro)) - #'(eval-when (expand load eval) - ;; Re-export MACRO from (json). - (module-re-export! (current-module) '(macro))) - #'(begin - ;; Using Guile-JSON < 4.2.0, so provide our own MACRO. - (define-syntax-rule (macro args ...) - body ...) - (eval-when (expand load eval) - (module-export! (current-module) '(macro))))))))) - -(define-syntax-rule (define-json-reader json->record ctor spec ...) - "Define JSON->RECORD as a procedure that converts a JSON representation, -read from a port, string, or hash table, into a record created by CTOR and -following SPEC, a series of field specifications." - (define (json->record input) - (let ((table (cond ((port? input) - (json->scm input)) - ((string? input) - (json-string->scm input)) - ((or (null? input) (pair? input)) - input)))) - (let-syntax ((extract-field (syntax-rules () - ((_ table (field key json->value)) - (json->value (assoc-ref table key))) - ((_ table (field key)) - (assoc-ref table key)) - ((_ table (field)) - (assoc-ref table - (symbol->string 'field)))))) - (ctor (extract-field table spec) ...))))) - -;; For some reason we cannot just have colliding definitions of -;; 'define-json-mapping' (that leads to a build failure in users of this -;; module), hence the use of 'define-as-needed'. -(define-as-needed (define-json-mapping rtd ctor pred json->record - (field getter spec ...) ...) - "Define RTD as a record type with the given FIELDs and GETTERs, à la SRFI-9, -and define JSON->RECORD as a conversion from JSON to a record of this type." - (begin - (define-record-type rtd - (ctor field ...) - pred - (field getter) ...) - - (define-json-reader json->record ctor - (field spec ...) ...))) diff --git a/guix/self.scm b/guix/self.scm index 6a1640acdf..02ef982c7c 100644 --- a/guix/self.scm +++ b/guix/self.scm @@ -49,7 +49,7 @@ (module-ref (resolve-interface module) variable)))) (match-lambda ("guile" (ref '(gnu packages guile) 'guile-3.0/libgc-7)) - ("guile-json" (ref '(gnu packages guile) 'guile-json-3)) + ("guile-json" (ref '(gnu packages guile) 'guile-json-4)) ("guile-ssh" (ref '(gnu packages ssh) 'guile-ssh)) ("guile-git" (ref '(gnu packages guile) 'guile-git)) ("guile-sqlite3" (ref '(gnu packages guile) 'guile-sqlite3)) diff --git a/guix/swh.scm b/guix/swh.scm index a343ccfdd7..0b765cc743 100644 --- a/guix/swh.scm +++ b/guix/swh.scm @@ -22,7 +22,6 @@ #:use-module (guix build utils) #:use-module ((guix build syscalls) #:select (mkdtemp!)) #:use-module (web uri) - #:use-module (guix json) #:use-module (web client) #:use-module (web response) #:use-module (json) diff --git a/m4/guix.m4 b/m4/guix.m4 index 7256e792a5..2fcc65e039 100644 --- a/m4/guix.m4 +++ b/m4/guix.m4 @@ -161,14 +161,23 @@ dnl GUIX_CHECK_GUILE_JSON dnl dnl Check whether a recent-enough Guile-JSON is available. AC_DEFUN([GUIX_CHECK_GUILE_JSON], [ - dnl Check whether we're using Guile-JSON 3.x, which uses a JSON-to-Scheme - dnl mapping different from that of earlier versions. + dnl Check whether we're using Guile-JSON 4.3+, which provides + dnl 'define-json-mapping'. AC_CACHE_CHECK([whether Guile-JSON is available and recent enough], [guix_cv_have_recent_guile_json], [GUILE_CHECK([retval], - [(use-modules (json) (ice-9 match)) - (match (json-string->scm \"[[ { \\\"a\\\": 42 } ]]\") - (#((("a" . 42))) #t))]) + [(use-modules (json)) + + (define-json-mapping make-frob + frob? + json->frob + (a frob-a) + (b frob-b \"bee\")) + + (exit + (equal? (json->frob + (open-input-string \"{ \\\"a\\\": 1, \\\"bee\\\": 2 }\")) + (make-frob 1 2)))]) if test "$retval" = 0; then guix_cv_have_recent_guile_json="yes" else