guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Ludovic Courtès
Date: Sun, 3 Sep 2023 11:44:15 -0400 (EDT)

branch: master
commit 042efcdf7cdbc9b56f0aede6953a4c97652dcb2e
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Sun Sep 3 16:05:31 2023 +0200

    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’.
---
 examples/random-manifest.scm | 50 ++++++++++++++++++++++++++++++--------------
 1 file changed, 34 insertions(+), 16 deletions(-)

diff --git a/examples/random-manifest.scm b/examples/random-manifest.scm
index b8df5f0..ed96e90 100644
--- a/examples/random-manifest.scm
+++ b/examples/random-manifest.scm
@@ -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))))))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]