guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

02/13: build-system/julia: Don't rely on file name to set module name.


From: guix-commits
Subject: 02/13: build-system/julia: Don't rely on file name to set module name.
Date: Sat, 30 Jan 2021 09:38:27 -0500 (EST)

civodul pushed a commit to branch master
in repository guix.

commit ba093a6d27557766b999b2f29ea6706bb8697db9
Author: nixo <nicolo@nixo.xyz>
AuthorDate: Thu Jan 28 16:13:33 2021 +0100

    build-system/julia: Don't rely on file name to set module name.
    
    * guix/build/julia-build-system.scm (project.toml->name): New procedure.
      (precompile, check, julia-build): Accept new key argument 
#:julia-package-name.
    * guix/build-system/julia.scm (julia-build): ... add it.
    * doc/guix.texi (julia-build-system): Update julia-package-name accordingly.
    
    Signed-off-by: Ludovic Court├Ęs <ludo@gnu.org>
---
 doc/guix.texi                     |  5 +++--
 guix/build-system/julia.scm       |  4 +++-
 guix/build/julia-build-system.scm | 35 ++++++++++++++++++++++++++++-------
 3 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 219617e..9b65be3 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -7618,8 +7618,9 @@ julia} packages, which essentially is similar to running 
@samp{julia -e
 @env{JULIA_LOAD_PATH} contains the paths to all Julia package inputs.
 Tests are run by calling @code{/test/runtests.jl}.
 
-Julia packages require the source @code{file-name} to be the real name of the
-package, correctly capitalized.
+The Julia package name is read from the file @file{Project.toml}.  This
+value can be overridden by passing the argument @code{#:julia-file-name}
+(which must be correctly capitalized).
 
 For packages requiring shared library dependencies, you may need to write the
 @file{/deps/deps.jl} file manually.  It's usually a line of @code{const
diff --git a/guix/build-system/julia.scm b/guix/build-system/julia.scm
index d3cb41c..63cb7cd 100644
--- a/guix/build-system/julia.scm
+++ b/guix/build-system/julia.scm
@@ -82,6 +82,7 @@
                       (search-paths '())
                       (system (%current-system))
                       (guile #f)
+                      (julia-package-name #f)
                       (imported-modules %julia-build-system-modules)
                       (modules '((guix build julia-build-system)
                                  (guix build utils))))
@@ -103,7 +104,8 @@
                     #:outputs %outputs
                     #:search-paths ',(map search-path-specification->sexp
                                           search-paths)
-                    #:inputs %build-inputs)))
+                    #:inputs %build-inputs
+                    #:julia-package-name ,julia-package-name)))
 
   (define guile-for-build
     (match guile
diff --git a/guix/build/julia-build-system.scm 
b/guix/build/julia-build-system.scm
index 61817e0..8f57045 100644
--- a/guix/build/julia-build-system.scm
+++ b/guix/build/julia-build-system.scm
@@ -21,6 +21,8 @@
   #:use-module ((guix build gnu-build-system) #:prefix gnu:)
   #:use-module (guix build utils)
   #:use-module (ice-9 match)
+  #:use-module (ice-9 regex)
+  #:use-module (ice-9 rdelim)
   #:export (%standard-phases
             julia-create-package-toml
             julia-build))
@@ -37,18 +39,34 @@
 ;; subpath where we store the package content
 (define %package-path "/share/julia/packages/")
 
-(define* (install #:key source inputs outputs #:allow-other-keys)
+(define (project.toml->name file)
+  "Look for Julia package name in the TOML file FILE (usually named
+Project.toml)."
+  (call-with-input-file file
+    (lambda (in)
+      (let loop ((line (read-line in 'concat)))
+        (if (eof-object? line)
+            #f
+            (let ((m (string-match "name\\s*=\\s*\"(.*)\"" line)))
+              (if m (match:substring m 1)
+                  (loop (read-line in 'concat)))))))))
+
+(define* (install #:key source inputs outputs julia-package-name
+                  #:allow-other-keys)
   (let* ((out (assoc-ref outputs "out"))
          (package-dir (string-append out %package-path
-                                     (strip-store-file-name source))))
+                                     (or
+                                      julia-package-name
+                                      (project.toml->name "Project.toml")))))
     (mkdir-p package-dir)
     (copy-recursively (getcwd) package-dir))
   #t)
 
-(define* (precompile #:key source inputs outputs #:allow-other-keys)
+(define* (precompile #:key source inputs outputs julia-package-name
+                     #:allow-other-keys)
   (let* ((out (assoc-ref outputs "out"))
          (builddir (string-append out "/share/julia/"))
-         (package (strip-store-file-name source)))
+         (package (or julia-package-name (project.toml->name "Project.toml"))))
     (mkdir-p builddir)
     ;; With a patch, SOURCE_DATE_EPOCH is honored
     (setenv "SOURCE_DATE_EPOCH" "1")
@@ -69,10 +87,11 @@
      (string-append "pushfirst!(DEPOT_PATH, pop!(DEPOT_PATH)); using " 
package)))
   #t)
 
-(define* (check #:key tests? source inputs outputs #:allow-other-keys)
+(define* (check #:key tests? source inputs outputs julia-package-name
+                #:allow-other-keys)
   (when tests?
     (let* ((out (assoc-ref outputs "out"))
-           (package (strip-store-file-name source))
+           (package (or julia-package-name (project.toml->name 
"Project.toml")))
            (builddir (string-append out "/share/julia/")))
       ;; With a patch, SOURCE_DATE_EPOCH is honored
       (setenv "SOURCE_DATE_EPOCH" "1")
@@ -127,9 +146,11 @@ version = \"" version "\"
     (delete 'patch-usr-bin-file)
     (delete 'build)))
 
-(define* (julia-build #:key inputs (phases %standard-phases)
+(define* (julia-build #:key inputs julia-package-name
+                      (phases %standard-phases)
                       #:allow-other-keys #:rest args)
   "Build the given Julia package, applying all of PHASES in order."
   (apply gnu:gnu-build
          #:inputs inputs #:phases phases
+         #:julia-package-name julia-package-name
          args))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]