summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2017-10-10 07:41:19 +0100
committerChristopher Baines <mail@cbaines.net>2018-01-14 22:16:20 +0000
commit2c2ec3d04a36914390c7617bb9971fd840b40646 (patch)
treec43b0916327f9b65dadeb59e5758bac4796337c0
parentd9df4bf055f2bef8c2c428db34c5fa056bdeba73 (diff)
downloadguix-2c2ec3d04a36914390c7617bb9971fd840b40646.tar.gz
ruby-build-system: Add a new wrap phase.
Wrap files in bin/ and sbin/ with the location of the gem itself and the
location of any other gems in use (GEM_PATH). This ensures that the bin files
will run with the right environment when executed.

It does however mean that native-inputs will also get wrapped up in any
binaries, which is not good, as it increases the size of the closure, and
risks this code being used at runtime.

* guix/build/ruby-build-system.scm (wrap): New procedure.
  (%standard-phases): Add the wrap phase.
-rw-r--r--guix/build/ruby-build-system.scm29
1 files changed, 28 insertions, 1 deletions
diff --git a/guix/build/ruby-build-system.scm b/guix/build/ruby-build-system.scm
index a28c47db9d..d78986da10 100644
--- a/guix/build/ruby-build-system.scm
+++ b/guix/build/ruby-build-system.scm
@@ -21,6 +21,7 @@
 (define-module (guix build ruby-build-system)
   #:use-module ((guix build gnu-build-system) #:prefix gnu:)
   #:use-module (guix build utils)
+  #:use-module (ice-9 ftw)
   #:use-module (ice-9 match)
   #:use-module (ice-9 popen)
   #:use-module (ice-9 regex)
@@ -276,6 +277,31 @@ extended with definitions for VARS."
         (chmod prog-tmp #o755)
         (rename-file prog-tmp prog))))
 
+(define* (wrap #:key inputs outputs #:allow-other-keys)
+  (define (list-of-files dir)
+    (map (cut string-append dir "/" <>)
+         (or (scandir dir (lambda (f)
+                            (let ((s (stat (string-append dir "/" f))))
+                              (eq? 'regular (stat:type s)))))
+             '())))
+
+  (define bindirs
+    (append-map (match-lambda
+                 ((_ . dir)
+                  (list (string-append dir "/bin")
+                        (string-append dir "/sbin"))))
+                outputs))
+
+  (let* ((out  (assoc-ref outputs "out"))
+         (var `("GEM_PATH" prefix
+                (,(string-append out "/lib/ruby/vendor_ruby")
+                 ,(getenv "GEM_PATH")))))
+    (for-each (lambda (dir)
+                (let ((files (list-of-files dir)))
+                  (for-each (cut wrap-ruby-program <> var)
+                            files)))
+              bindirs)))
+
 (define (log-file-deletion file)
   (display (string-append "deleting '" file "' for reproducibility\n")))
 
@@ -287,7 +313,8 @@ extended with definitions for VARS."
     (add-after 'extract-gemspec 'replace-git-ls-files replace-git-ls-files)
     (replace 'build build)
     (replace 'check check)
-    (replace 'install install)))
+    (replace 'install install)
+    (add-after 'install 'wrap wrap)))
 
 (define* (ruby-build #:key inputs (phases %standard-phases)
                      #:allow-other-keys #:rest args)