>From 69bfdff9a8772bbe9254c9cd3a97966e059060af Mon Sep 17 00:00:00 2001 From: nixo Date: Mon, 24 Feb 2020 15:28:45 +0100 Subject: [PATCH 03/16] gnu: julia-build-system: Enable tests, fix precompilation. --- guix/build-system/julia.scm | 2 +- guix/build/julia-build-system.scm | 71 +++++++++++++++---------------- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/guix/build-system/julia.scm b/guix/build-system/julia.scm index 488fe9bb1d..d3cb41c054 100644 --- a/guix/build-system/julia.scm +++ b/guix/build-system/julia.scm @@ -75,7 +75,7 @@ (define* (julia-build store name inputs #:key source - (tests? #f) + (tests? #t) (phases '(@ (guix build julia-build-system) %standard-phases)) (outputs '("out")) diff --git a/guix/build/julia-build-system.scm b/guix/build/julia-build-system.scm index ff6fcf5fe3..2916775c9d 100644 --- a/guix/build/julia-build-system.scm +++ b/guix/build/julia-build-system.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2019 Nicolò Balzarotti +;;; Copyright © 2019, 2020 Nicolò Balzarotti ;;; ;;; This file is part of GNU Guix. ;;; @@ -37,54 +37,53 @@ ;; subpath where we store the package content (define %package-path "/share/julia/packages/") -(define (generate-load-path inputs outputs) - (string-append - (string-join (map (match-lambda - ((_ . path) - (string-append path %package-path))) - ;; Restrict to inputs beginning with "julia-". - (filter (match-lambda - ((name . _) - (string-prefix? "julia-" name))) - inputs)) - ":") - (string-append ":" (assoc-ref outputs "out") %package-path) - ;; stdlib is always required to find Julia's standard libraries. - ;; usually there are other two paths in this variable: - ;; "@" and "@v#.#" - ":@stdlib")) - (define* (install #:key source inputs outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (package-dir (string-append out %package-path - (string-append - (strip-store-file-name source))))) - (setenv "JULIA_LOAD_PATH" (generate-load-path inputs outputs)) + (strip-store-file-name source)))) (mkdir-p package-dir) - (copy-recursively source package-dir)) + (copy-recursively (getcwd) package-dir)) #t) -;; TODO: Precompilation is working, but I don't know how to tell -;; julia to use use it. If (on rantime) we set HOME to -;; store path, julia tries to write files there (failing) (define* (precompile #:key source inputs outputs #:allow-other-keys) (let* ((out (assoc-ref outputs "out")) (builddir (string-append out "/share/julia/")) (package (strip-store-file-name source))) (mkdir-p builddir) (setenv "JULIA_DEPOT_PATH" builddir) - (setenv "JULIA_LOAD_PATH" (generate-load-path inputs outputs)) - ;; Actual precompilation - (invoke-julia (string-append "using " package))) + ;; add new package dir to the load path + (setenv "JULIA_LOAD_PATH" + (string-append builddir "packages/" + (if (getenv "JULIA_LOAD_PATH") + (string-append ":" (getenv "JULIA_LOAD_PATH")) + ""))) + ;; Actual precompilation. + (invoke-julia + ;; when using julia as a user, julia writes precompile cache to the first + ;; entry of the DEPOT_PATH list (by default, the home dir). We want to + ;; write it to the store, so let's push the store path as the first + ;; element of DEPOT_PATH. Once the cache file exists, this hack is not + ;; needed anymore (like in the check phase). If the user install new + ;; pacakges, those will be installed and precompiled in the home dir + (string-append "pushfirst!(DEPOT_PATH, pop!(DEPOT_PATH)); using " package))) #t) -(define* (check #:key source inputs outputs #:allow-other-keys) - (let* ((out (assoc-ref outputs "out")) - (package (strip-store-file-name source)) - (builddir (string-append out "/share/julia/"))) - (setenv "JULIA_DEPOT_PATH" builddir) - (setenv "JULIA_LOAD_PATH" (generate-load-path inputs outputs)) - (invoke-julia (string-append "using Pkg;Pkg.test(\"" package "\")"))) +(define* (check #:key tests? source outputs #:allow-other-keys) + (if tests? + (let* ((out (assoc-ref outputs "out")) + (package (strip-store-file-name source)) + (builddir (string-append out "/share/julia/"))) + (setenv "HOME" "/tmp") + (setenv "JULIA_DEPOT_PATH" builddir) + (setenv "JULIA_LOAD_PATH" + (string-append builddir "packages/" ":" + (or (getenv "JULIA_LOAD_PATH") + ""))) + ;; tests assume they are run from the test directory + (with-directory-excursion + (string-append builddir "packages/" package "/test/") + (invoke "julia" "runtests.jl"))) + (format #t "test suite not run~%")) #t) (define (julia-create-package-toml outputs source @@ -119,7 +118,7 @@ version = \"" version "\" (delete 'check) ; tests must be run after installation (replace 'install install) (add-after 'install 'precompile precompile) - ;; (add-after 'install 'check check) + (add-after 'precompile 'check check) ;; TODO: In the future we could add a "system-image-generation" phase ;; where we use PackageCompiler.jl to speed up package loading times (delete 'configure) -- 2.25.0