Add a 'build-status' enumeration.

* src/cuirass/utils.scm (define-enumeration): New macro.
* src/cuirass/database.scm (build-status): New macro.
* src/cuirass/base.scm (build-packages)[hydra-build-status]: Remove.
Use the 'build-status' macro instead.
This commit is contained in:
Ludovic Courtès 2018-01-23 17:37:08 +01:00
parent 6822b4735f
commit b0f1a438ff
3 changed files with 23 additions and 13 deletions

View File

@ -290,15 +290,6 @@ and so on. "
(define (build-packages store db jobs)
"Build JOBS and return a list of Build results."
(define hydra-build-status
;; Build status as expected by hydra compatible API's.
'((succeeded . 0)
(failed . 1)
(failed-dependency . 2)
(failed-other . 3)
(cancelled . 4)))
(define (register job)
(let* ((name (assq-ref job #:job-name))
(drv (assq-ref job #:derivation))
@ -317,8 +308,8 @@ and so on. "
(#:log . ,log)
(#:status .
,(match (length outputs)
(0 (assq-ref hydra-build-status 'failed))
(_ (assq-ref hydra-build-status 'succeeded))))
(0 (build-status failed))
(_ (build-status succeeded))))
(#:outputs . ,outputs)
;;; XXX: For now, we do not know start/stop build time.
(#:timestamp . ,cur-time)

View File

@ -37,6 +37,7 @@
db-add-evaluation
db-add-derivation
db-get-derivation
build-status
db-add-build
db-get-build
db-get-builds
@ -197,6 +198,14 @@ string."
(define SQLITE_CONSTRAINT_PRIMARYKEY
(logior SQLITE_CONSTRAINT (ash 6 8)))
(define-enumeration build-status
;; Build status as expected by Hydra's API.
(succeeded 0)
(failed 1)
(failed-dependency 2)
(failed-other 3)
(cancelled 4))
(define (db-add-build db build)
"Store BUILD in database DB. BUILD eventual outputs are stored
in the OUTPUTS table."

View File

@ -1,5 +1,5 @@
;;; utils.scm -- helper procedures
;;; Copyright © 2012, 2013, 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2012, 2013, 2016, 2018 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2015 David Thompson <davet@gnu.org>
;;; Copyright © 2016 Mathieu Lirzin <mthl@gnu.org>
;;;
@ -24,7 +24,8 @@
#:use-module (json)
#:export (alist?
object->json-scm
object->json-string))
object->json-string
define-enumeration))
(define (alist? obj)
"Return #t if OBJ is an alist."
@ -47,3 +48,12 @@
(define* (object->json-string object #:key pretty)
"Return OBJECT as a JSON object."
(scm->json-string (object->json-scm object) #:pretty pretty))
(define-syntax-rule (define-enumeration name (symbol value) ...)
"Define an 'enum' type with the given SYMBOL/VALUE pairs. NAME is defined a
macro that accepts one of these symbols and expands to the corresponding
value."
(define-syntax name
(syntax-rules (symbol ...)
((_ symbol) value)
...)))