summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ravanan/command-line-tool.scm25
-rw-r--r--ravanan/work/utils.scm21
2 files changed, 24 insertions, 22 deletions
diff --git a/ravanan/command-line-tool.scm b/ravanan/command-line-tool.scm
index 83ccfa2..4c1fa43 100644
--- a/ravanan/command-line-tool.scm
+++ b/ravanan/command-line-tool.scm
@@ -586,28 +586,6 @@ The returned G-expression will reference an @code{inputs-directory} variable."
                 (list id (copy-input-files input))))
              inputs)))
 
-(define (canonicalize-json tree)
-  "Canonicalize JSON @var{tree} by recursively sorting objects in lexicographic
-order of keys."
-  ;; We need to canonicalize JSON trees before inserting them into
-  ;; G-expressions. If we don't, we would have degenerate G-expressions that
-  ;; produce exactly the same result.
-  (cond
-   ;; Sort objects by lexicographic order of keys, and recurse.
-   ((list? tree)
-    (sort (map (match-lambda
-                 ((key . value)
-                  (cons key (canonicalize-json value))))
-               tree)
-          (match-lambda*
-            (((key1 . _) (key2 . _))
-             (string< key1 key2)))))
-   ;; Do not rearrange arrays. Just recurse.
-   ((vector? tree)
-    (vector-map canonicalize-json tree))
-   ;; Atoms
-   (else tree)))
-
 (define (find-requirement requirements class)
   "Find requirement of @var{class} among @var{requirements} and return a
 maybe-monadic value."
@@ -977,6 +955,9 @@ directory of the workflow."
 
               (call-with-temporary-directory
                (lambda (inputs-directory)
+                 ;; We need to canonicalize JSON trees before inserting them
+                 ;; into G-expressions. If we don't, we would have degenerate
+                 ;; G-expressions that produce exactly the same result.
                  (let ((inputs #$(copy-input-files-gexp (canonicalize-json inputs)))
                        (runtime `(("cores" . ,#$(cores batch-system)))))
 
diff --git a/ravanan/work/utils.scm b/ravanan/work/utils.scm
index 15349b2..62b02ef 100644
--- a/ravanan/work/utils.scm
+++ b/ravanan/work/utils.scm
@@ -23,11 +23,13 @@
   #:use-module (ice-9 filesystem)
   #:use-module (ice-9 match)
   #:use-module (ice-9 popen)
+  #:use-module (ravanan work vectors)
   #:export (list->dotted-list
             alist=?
             assoc-ref*
             assoc-set
             json-ref
+            canonicalize-json
             call-with-temporary-directory
             call-with-input-pipe))
 
@@ -72,6 +74,25 @@ mutated."
             other-keys))
     (() scm)))
 
+(define (canonicalize-json tree)
+  "Canonicalize JSON @var{tree} by recursively sorting objects in lexicographic
+order of keys."
+  (cond
+   ;; Sort objects by lexicographic order of keys, and recurse.
+   ((list? tree)
+    (sort (map (match-lambda
+                 ((key . value)
+                  (cons key (canonicalize-json value))))
+               tree)
+          (match-lambda*
+            (((key1 . _) (key2 . _))
+             (string< key1 key2)))))
+   ;; Do not rearrange arrays. Just recurse.
+   ((vector? tree)
+    (vector-map canonicalize-json tree))
+   ;; Atoms
+   (else tree)))
+
 (define* (call-with-temporary-directory proc
                                         #:optional (parent-directory (getcwd)))
   "Call @var{proc} with a new temporary directory in