aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ravanan/command-line-tool.scm31
-rw-r--r--ravanan/utils.scm31
2 files changed, 36 insertions, 26 deletions
diff --git a/ravanan/command-line-tool.scm b/ravanan/command-line-tool.scm
index da585d8..84744d3 100644
--- a/ravanan/command-line-tool.scm
+++ b/ravanan/command-line-tool.scm
@@ -40,6 +40,7 @@
#:use-module (ravanan job-state)
#:use-module (ravanan reader)
#:use-module (ravanan slurm-api)
+ #:use-module (ravanan utils)
#:use-module (ravanan work command-line-tool)
#:use-module (ravanan work monads)
#:use-module (ravanan work types)
@@ -552,31 +553,11 @@ maybe-monadic value."
(define (load-manifest manifest-file)
"Load Guix manifest from @var{manifest-file} and return it."
- ;; We load the manifest file into a dummy module of its own so that any
- ;; definitions from there don't leak into this module. We also ensure that
- ;; this dummy module is different for different manifest files so that
- ;; definitions from one manifest file don't leak into other manifest files.
- (let ((manifest-module
- (resolve-module (match (file-name-split (canonicalize-file-name manifest-file))
- (("" parts ...)
- (map string->symbol parts))))))
- ;; Import modules required for loading manifests.
- (for-each (lambda (module-name)
- (module-use! manifest-module (resolve-interface module-name)))
- '((guile)
- (gnu packages)
- (guix gexp)
- (guix profiles)))
- (save-module-excursion
- (lambda ()
- (set-current-module manifest-module)
- ;; Do not auto-compile manifest files.
- (set! %load-should-auto-compile #f)
- ;; Our use of load triggers a "Add #:declarative? #f to your
- ;; define-module invocation" warning during compilation. But, it is
- ;; probably safe to ignore this warning since we use load only within a
- ;; dummy module.
- (load (canonicalize-path manifest-file))))))
+ (load-script manifest-file
+ #:modules '((guile)
+ (gnu packages)
+ (guix gexp)
+ (guix profiles))))
(define (build-command-line-tool-script name manifest-file cwl inputs
scratch store batch-system
diff --git a/ravanan/utils.scm b/ravanan/utils.scm
index 471785a..c9294cd 100644
--- a/ravanan/utils.scm
+++ b/ravanan/utils.scm
@@ -19,8 +19,11 @@
(define-module (ravanan utils)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-26)
+ #:use-module (ice-9 filesystem)
+ #:use-module (ice-9 match)
#:export (string-trim-prefix
- call-with-temporary-file))
+ call-with-temporary-file
+ load-script))
(define (string-trim-prefix prefix str)
"Remove @var{prefix} from @var{str} if it exists. Else, return @var{str} as is."
@@ -37,3 +40,29 @@ non-locally."
(cut proc temporary-file-port)
(lambda ()
(delete-file (port-filename temporary-file-port))))))
+
+(define* (load-script script-file #:key (modules '()))
+ "Load script from @var{script-file} and return its value. Import @var{modules}
+before loading script."
+ ;; We load the script file into a dummy module of its own so that any
+ ;; definitions from there don't leak into this module. We also ensure that
+ ;; this dummy module is different for different script files so that
+ ;; definitions from one script file don't leak into other script files.
+ (let ((script-module
+ (resolve-module (match (file-name-split (canonicalize-file-name script-file))
+ (("" parts ...)
+ (map string->symbol parts))))))
+ ;; Import modules required for loading script.
+ (for-each (lambda (module-name)
+ (module-use! script-module (resolve-interface module-name)))
+ modules)
+ (save-module-excursion
+ (lambda ()
+ (set-current-module script-module)
+ ;; Do not auto-compile script file.
+ (set! %load-should-auto-compile #f)
+ ;; Our use of load triggers a "Add #:declarative? #f to your
+ ;; define-module invocation" warning during compilation. But, it is
+ ;; probably safe to ignore this warning since we use load only within a
+ ;; dummy module.
+ (load (canonicalize-path script-file))))))