examples: random: Create jobs with dependencies.

* examples/random-manifest.scm (random-computed-file): Add ‘dependency’
parameter and honor it.
<top level>: Replace ‘unfold’ call with a loop; pass ‘dependency’
argument to ‘random-computed-file’.
This commit is contained in:
Ludovic Courtès 2023-09-03 16:05:31 +02:00
parent 951ce6c0c0
commit 042efcdf7c
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
1 changed files with 34 additions and 16 deletions

View File

@ -38,7 +38,8 @@
(seed->random-state %seed))
(define* (random-computed-file #:optional (suffix "")
multiple-outputs?)
multiple-outputs?
dependency)
(let ((nonce (random 1e6 %state)))
(computed-file (string-append "random" suffix)
#~(let ((delay #$(random 60 %state))
@ -47,6 +48,14 @@
(setvbuf (current-error-port) 'line)
(set-port-encoding! (current-output-port) "UTF-8")
;; Optionally introduce a dependency.
(let ((dependency
'#$(and dependency
#~(ungexp (manifest-entry-item dependency)
(manifest-entry-output dependency)))))
(when dependency
(format #t "dependency on ~a~%" dependency)))
(display "Starting build!\n")
(display "Here's a UTF-8-encoded lambda: λ.\n")
(sleep (pk 'sleeping delay))
@ -63,20 +72,29 @@
(when (zero? (random 7 %state))
(error "Evaluation is failing!"))
;; Synthesize a manifest that covers various cases: succeeding/failing jobs,
;; jobs with/without dependencies, etc.
(manifest
(unfold (cut > <> 15)
(lambda (i)
(let* ((multiple-outputs? (zero? (modulo i 5)))
(suffix (string-append
(if multiple-outputs?
"multiple-outputs"
"")
(number->string i))))
(make-job (string-append "entropy-" suffix)
(random-computed-file suffix
multiple-outputs?)
(let loop ((i 0)
(lst '()))
(if (>= i 20)
(reverse lst)
(let* ((multiple-outputs? (zero? (modulo i 5)))
(dependency (and (= 0 (modulo i 3))
(> i 0)
(list-ref lst
(random (length lst) %state))))
(suffix (string-append
(if multiple-outputs?
"first"
"out"))))
1+
0))
"multiple-outputs"
"")
(number->string i))))
(loop (+ i 1)
(cons (make-job (string-append "entropy-" suffix)
(random-computed-file suffix
multiple-outputs?
dependency)
(if multiple-outputs?
"first"
"out"))
lst))))))