123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- (define-module (guix build r-build-system)
- #:use-module ((guix build gnu-build-system) #:prefix gnu:)
- #:use-module (guix build utils)
- #:use-module (ice-9 match)
- #:use-module (ice-9 ftw)
- #:use-module (ice-9 popen)
- #:use-module (srfi srfi-1)
- #:use-module (srfi srfi-26)
- #:use-module (srfi srfi-35)
- #:export (%standard-phases
- r-build))
- (define (invoke-r command params)
- (apply invoke "R" "CMD" command params))
- (define (pipe-to-r command params)
- (let ((port (apply open-pipe* OPEN_WRITE "R" params)))
- (display command port)
- (let ((code (status:exit-val (close-pipe port))))
- (unless (zero? code)
- (raise (condition ((@@ (guix build utils) &invoke-error)
- (program "R")
- (arguments (cons command params))
- (exit-status (status:exit-val code))
- (term-signal (status:term-sig code))
- (stop-signal (status:stop-sig code)))))))))
- (define (generate-site-path inputs)
- (string-join (map (match-lambda
- ((_ . path)
- (string-append path "/site-library")))
-
- (filter (match-lambda
- ((name . _)
- (string-prefix? "r-" name)))
- inputs))
- ":"))
- (define* (check #:key test-target inputs outputs tests? #:allow-other-keys)
- "Run the test suite of a given R package."
- (let* ((libdir (string-append (assoc-ref outputs "out") "/site-library/"))
-
-
-
-
-
-
-
-
- (pkg-name (car (scandir libdir (negate (cut member <> '("." ".."))))))
- (testdir (string-append libdir pkg-name "/" test-target))
- (site-path (string-append libdir ":" (generate-site-path inputs))))
- (when (and tests? (file-exists? testdir))
- (setenv "R_LIBS_SITE" site-path)
- (pipe-to-r (string-append "tools::testInstalledPackage(\"" pkg-name "\", "
- "lib.loc = \"" libdir "\")")
- '("--no-save" "--slave")))
- #t))
- (define* (install #:key outputs inputs (configure-flags '())
- #:allow-other-keys)
- "Install a given R package."
- (let* ((out (assoc-ref outputs "out"))
- (site-library (string-append out "/site-library/"))
- (params (append configure-flags
- (list "--install-tests"
- (string-append "--library=" site-library)
- "--built-timestamp=1970-01-01"
- ".")))
- (site-path (string-append site-library ":"
- (generate-site-path inputs))))
-
-
- (setenv "R_LIBS_SITE" site-path)
-
-
- (setenv "CONFIG_SHELL" (which "bash"))
- (mkdir-p site-library)
- (invoke-r "INSTALL" params)))
- (define %standard-phases
- (modify-phases gnu:%standard-phases
- (delete 'bootstrap)
- (delete 'configure)
- (delete 'build)
- (delete 'check)
- (replace 'install install)
- (add-after 'install 'check check)))
- (define* (r-build #:key inputs (phases %standard-phases)
- #:allow-other-keys #:rest args)
- "Build the given R package, applying all of PHASES in order."
- (apply gnu:gnu-build #:inputs inputs #:phases phases args))
|