From c6f4fa5f577e4752d845fa3ce17c68fcd2079904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Sat, 17 Aug 2019 18:48:34 +0200 Subject: Switch to Guile-JSON 3.x. Guile-JSON 3.x is incompatible with Guile-JSON 1.x, which we relied on until now: it maps JSON dictionaries to alists (instead of hash tables), and JSON arrays to vectors (instead of lists). This commit is about adjusting all the existing code to this new mapping. * src/cuirass/http.scm (evaluation->json-object): New procedure. (handle-builds-request): Pass the result through 'list->vector'. (handle-builds-search-request): Likewise. (url-handler): Likewise for /jobsets, /specifications, /api/evaluations, and /build. For /api/evaluations, use 'evaluation->json-object'. * src/cuirass/utils.scm (object->json-scm): Add 'vector?' case. * tests/http.scm (hash-table-keys, hash-table=?): Remove. (evaluations-query-result): Use vectors for JSON arrays. ("object->json-string"): Expects alists instead of hash tables. ("/build/1"): Use 'lset=' instead of 'hash-table=?'. ("/api/latestbuilds?nr=1&jobset=guix"): Likewise, and expect alists instead of hash tables. ("/api/latestbuilds?nr=1&jobset=gnu"): Likewise. ("/api/evaluations?nr=1"): Likewise. * README: Mention Guile-JSON 3.x. --- src/cuirass/http.scm | 23 ++++++++++++++++++----- src/cuirass/utils.scm | 4 +++- 2 files changed, 21 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/cuirass/http.scm b/src/cuirass/http.scm index b69b6ce..a26b1c6 100644 --- a/src/cuirass/http.scm +++ b/src/cuirass/http.scm @@ -105,6 +105,14 @@ (#:releasename . #nil) (#:buildinputs_builds . #nil))) +(define (evaluation->json-object evaluation) + "Turn EVALUATION into a representation suitable for 'json->scm'." + ;; XXX: Since #:checkouts is a list of alists, we must turn it into a vector + ;; so that 'json->scm' converts it to a JSON array. + `(,@(alist-delete #:checkouts evaluation eq?) + (#:checkouts . ,(list->vector + (assq-ref evaluation #:checkouts))))) + (define (handle-build-request build-id) "Retrieve build identified by BUILD-ID over the database and convert it to hydra format. Return #f is not build was found." @@ -116,14 +124,14 @@ hydra format. Return #f is not build was found." Hydra format." (let ((builds (with-time-logging "builds request" (db-get-builds filters)))) - (map build->hydra-build builds))) + (list->vector (map build->hydra-build builds)))) (define (handle-builds-search-request filters) "Retrieve all builds matched by FILTERS in the database and convert them to Hydra format." (let ((builds (with-time-logging "builds search request" (db-get-builds-by-search filters)))) - (map build->hydra-build builds))) + (list->vector (map build->hydra-build builds)))) (define (request-parameters request) "Parse the REQUEST query parameters and return them under the form @@ -233,7 +241,8 @@ Hydra format." (request-path-components request) 'method-not-allowed) (((or "jobsets" "specifications") . rest) - (respond-json (object->json-string (db-get-specifications)))) + (respond-json (object->json-string + (list->vector (db-get-specifications))))) (("build" build-id) (let ((hydra-build (handle-build-request (string->number build-id)))) (if hydra-build @@ -274,7 +283,10 @@ Hydra format." ;; 'nr parameter is mandatory to limit query size. (nr (assq-ref params 'nr))) (if nr - (respond-json (object->json-string (db-get-evaluations nr))) + (respond-json (object->json-string + (list->vector + (map evaluation->json-object + (db-get-evaluations nr))))) (respond-json-with-error 500 "Parameter not defined!")))) (("api" "latestbuilds") (let* ((params (request-parameters request)) @@ -304,7 +316,8 @@ Hydra format." ('() (respond-html (html-page "Cuirass" - (specifications-table (db-get-specifications)) + (specifications-table + (list->vector (db-get-specifications))) '()))) (("jobset" name) diff --git a/src/cuirass/utils.scm b/src/cuirass/utils.scm index 48e797c..fe74b69 100644 --- a/src/cuirass/utils.scm +++ b/src/cuirass/utils.scm @@ -1,5 +1,5 @@ ;;; utils.scm -- helper procedures -;;; Copyright © 2012, 2013, 2016, 2018 Ludovic Courtès +;;; Copyright © 2012, 2013, 2016, 2018, 2019 Ludovic Courtès ;;; Copyright © 2015 David Thompson ;;; Copyright © 2016 Mathieu Lirzin ;;; Copyright © 2018 Clément Lassieur @@ -57,6 +57,8 @@ ((null? obj) obj) ((symbol? obj) (symbol->string obj)) ((keyword? obj) (object->json-scm (keyword->symbol obj))) + ((vector? obj) (list->vector + (map object->json-scm (vector->list obj)))) ((alist? obj) (map object->json-scm obj)) ((pair? obj) (cons (object->json-scm (car obj)) (object->json-scm (cdr obj)))) -- cgit v1.2.3