diff options
author | Arun Isaac | 2024-10-04 13:59:53 +0100 |
---|---|---|
committer | Arun Isaac | 2024-10-04 14:48:08 +0100 |
commit | 1f5a362bfba9b611311d32903fdcd39b14f6f7c3 (patch) | |
tree | f0f4c0b2abc2a9434e870e63cb9d7d1325f617da | |
parent | 6b63921275a7834f6231f92185a2cc23d77c13ba (diff) | |
download | ravanan-1f5a362bfba9b611311d32903fdcd39b14f6f7c3.tar.gz ravanan-1f5a362bfba9b611311d32903fdcd39b14f6f7c3.tar.lz ravanan-1f5a362bfba9b611311d32903fdcd39b14f6f7c3.zip |
command-line-tool: Move canonicalize-json to (ravanan work utils).
* ravanan/command-line-tool.scm (canonicalize-json): Move to (ravanan
work utils). Move comment about G-expressions to
build-command-line-tool-script.
* ravanan/work/utils.scm (ravanan): Import (ravanan work vectors).
-rw-r--r-- | ravanan/command-line-tool.scm | 25 | ||||
-rw-r--r-- | ravanan/work/utils.scm | 21 |
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 |