unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [PATCH 1/3] gnu: Add ruby.
@ 2014-09-28 15:22 David Thompson
  2014-09-28 15:22 ` [PATCH 2/3] build: Add ruby build system David Thompson
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: David Thompson @ 2014-09-28 15:22 UTC (permalink / raw)
  To: guix-devel; +Cc: Pjotr Prins

From: Pjotr Prins <pjotr.public01@thebird.nl>

* gnu/packages/ruby.scm: New file.
* gnu-system.am (GNU_SYSTEM_MODULES): Add it.
* guix/licenses.scm (ruby): New variable.
---
 gnu-system.am         |  1 +
 gnu/packages/ruby.scm | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++
 guix/licenses.scm     |  6 ++++
 3 files changed, 97 insertions(+)
 create mode 100644 gnu/packages/ruby.scm

diff --git a/gnu-system.am b/gnu-system.am
index e774f50..126f4e3 100644
--- a/gnu-system.am
+++ b/gnu-system.am
@@ -214,6 +214,7 @@ GNU_SYSTEM_MODULES =				\
   gnu/packages/readline.scm			\
   gnu/packages/rrdtool.scm			\
   gnu/packages/rsync.scm			\
+  gnu/packages/ruby.scm				\
   gnu/packages/rush.scm				\
   gnu/packages/samba.scm			\
   gnu/packages/scheme.scm			\
diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
new file mode 100644
index 0000000..cded7e9
--- /dev/null
+++ b/gnu/packages/ruby.scm
@@ -0,0 +1,90 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2014 Pjotr Prins <pjotr.guix@thebird.nl>
+;;; Copyright © 2014 Ludovic Courtès <ludo@gnu.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu packages ruby)
+  #:use-module ((guix licenses) #:prefix license:)
+  #:use-module (gnu packages)
+  #:use-module (gnu packages compression)
+  #:use-module (gnu packages readline)
+  #:use-module (gnu packages openssl)
+  #:use-module (gnu packages autotools)
+  #:use-module (gnu packages libffi)
+  #:use-module (gnu packages gdbm)
+  #:use-module (guix packages)
+  #:use-module (guix download)
+  #:use-module (guix utils)
+  #:use-module (guix build-system gnu))
+
+(define-public ruby
+  (package
+    (name "ruby")
+    (version "2.1.3")
+    (source
+     (origin
+       (method url-fetch)
+       (uri (string-append "http://cache.ruby-lang.org/pub/ruby/2.1/ruby-"
+                           version ".tar.gz"))
+       (sha256
+        (base32
+         "00bz6jcbxgnllplk4b9lnyc3w8yd3pz5rn11rmca1s8cn6vvw608"))))
+    (build-system gnu-build-system)
+    (arguments
+     `(#:test-target "test"
+       #:parallel-tests? #f
+       #:phases
+       (alist-cons-after
+        ;; Minor patch:
+        ;; https://bugs.ruby-lang.org/projects/ruby-trunk/repository/revisions/45225/diff/
+        'unpack 'patch-readline
+        (lambda _
+          (substitute* '("ext/readline/readline.c")
+            (("Function ") "rl_hook_func_t ")))
+        (alist-cons-before
+         'configure 'replace-bin-sh
+         (lambda _
+           (substitute* '("Makefile.in"
+                          "ext/pty/pty.c"
+                          "io.c"
+                          "lib/mkmf.rb"
+                          "process.c"
+                          "test/rubygems/test_gem_ext_configure_builder.rb"
+                          "test/rdoc/test_rdoc_parser.rb"
+                          "test/ruby/test_rubyoptions.rb"
+                          "test/ruby/test_process.rb"
+                          "test/ruby/test_system.rb"
+                          "tool/rbinstall.rb")
+             (("/bin/sh") (which "sh"))))
+         %standard-phases))))
+    (inputs
+     `(("readline" ,readline)
+       ("autoconf" ,autoconf)
+       ("openssl" ,openssl)
+       ("libffi" ,libffi)
+       ("gdbm" ,gdbm)
+       ("zlib" ,zlib)))
+    (native-search-paths
+     (list (search-path-specification
+            (variable "GEM_PATH")
+            (directories '("lib/ruby/gems/2.1.3")))))
+    (synopsis "Ruby programming language interpreter")
+    (description "Ruby is a dynamic object-oriented programming language with
+a focus on simplicity and productivity.")
+    (home-page "https://ruby-lang.org")
+    (license license:ruby)))
+
diff --git a/guix/licenses.scm b/guix/licenses.scm
index 23e4458..65ef06c 100644
--- a/guix/licenses.scm
+++ b/guix/licenses.scm
@@ -42,6 +42,7 @@
             openldap2.8 openssl
             psfl public-domain
             qpl
+            ruby
             vim
             x11 x11-style
             zlib
@@ -255,6 +256,11 @@ which may be a file:// URI pointing the package's tree."
            "http://directory.fsf.org/wiki/License:QPLv1.0"
            "http://www.gnu.org/licenses/license-list.html#QPL"))
 
+(define ruby
+  (license "Ruby License"
+           "http://directory.fsf.org/wiki/License:Ruby"
+           "https://www.ruby-lang.org/en/about/license.txt"))
+
 (define vim
   (license "Vim"
            "http://directory.fsf.org/wiki/License:Vim7.2"
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 2/3] build: Add ruby build system.
  2014-09-28 15:22 [PATCH 1/3] gnu: Add ruby David Thompson
@ 2014-09-28 15:22 ` David Thompson
  2014-09-28 15:41   ` David Thompson
  2014-09-28 15:50   ` Ludovic Courtès
  2014-09-28 15:22 ` [PATCH 3/3] gnu: Add ruby-i18n David Thompson
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 13+ messages in thread
From: David Thompson @ 2014-09-28 15:22 UTC (permalink / raw)
  To: guix-devel

* guix/build-system/ruby.scm: New file.
* guix/build/ruby-build-system: New file.
* Makefile.am (MODULES): Add new files.
---
 Makefile.am                      |   2 +
 guix/build-system/ruby.scm       | 108 +++++++++++++++++++++++++++++++++++++++
 guix/build/ruby-build-system.scm |  70 +++++++++++++++++++++++++
 3 files changed, 180 insertions(+)
 create mode 100644 guix/build-system/ruby.scm
 create mode 100644 guix/build/ruby-build-system.scm

diff --git a/Makefile.am b/Makefile.am
index 1f2c4db..3c22a77 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -50,6 +50,7 @@ MODULES =					\
   guix/build-system/gnu.scm			\
   guix/build-system/perl.scm			\
   guix/build-system/python.scm			\
+  guix/build-system/ruby.scm			\
   guix/build-system/trivial.scm			\
   guix/ftp-client.scm				\
   guix/http-client.scm				\
@@ -64,6 +65,7 @@ MODULES =					\
   guix/build/gnu-dist.scm			\
   guix/build/perl-build-system.scm		\
   guix/build/python-build-system.scm		\
+  guix/build/ruby-build-system.scm		\
   guix/build/store-copy.scm			\
   guix/build/utils.scm				\
   guix/build/union.scm				\
diff --git a/guix/build-system/ruby.scm b/guix/build-system/ruby.scm
new file mode 100644
index 0000000..f20967a
--- /dev/null
+++ b/guix/build-system/ruby.scm
@@ -0,0 +1,108 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2014 David Thompson <davet@gnu.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix build-system ruby)
+  #:use-module (guix store)
+  #:use-module (guix utils)
+  #:use-module (guix packages)
+  #:use-module (guix derivations)
+  #:use-module (guix build-system)
+  #:use-module (guix build-system gnu)
+  #:use-module (gnu packages version-control)
+  #:use-module (ice-9 match)
+  #:use-module (srfi srfi-26)
+  #:export (ruby-build
+            ruby-build-system))
+
+(define (default-ruby)
+  "Return the default Ruby package."
+  ;; Lazily resolve the binding to avoid a circular dependency.
+  (let ((ruby (resolve-interface '(gnu packages ruby))))
+    (module-ref ruby 'ruby)))
+
+(define* (ruby-build store name source inputs
+                     #:key
+                     (ruby (default-ruby))
+                     (test-target "test")
+                     (tests? #t)
+                     (phases '(@ (guix build ruby-build-system)
+                                 %standard-phases))
+                     (outputs '("out"))
+                     (search-paths '())
+                     (system (%current-system))
+                     (guile #f)
+                     (imported-modules '((guix build ruby-build-system)
+                                         (guix build gnu-build-system)
+                                         (guix build utils)))
+                     (modules '((guix build ruby-build-system)
+                                (guix build utils))))
+  "Build SOURCE using RUBY and INPUTS."
+  (define ruby-search-paths
+    (append (package-native-search-paths ruby)
+            (standard-search-paths)))
+
+  (define builder
+    `(begin
+       (use-modules ,@modules)
+       (ruby-build #:name ,name
+                   #:source ,(if (derivation? source)
+                                 (derivation->output-path source)
+                                 source)
+                   #:system ,system
+                   #:test-target ,test-target
+                   #:tests? ,tests?
+                   #:phases ,phases
+                   #:outputs %outputs
+                   #:search-paths ',(map search-path-specification->sexp
+                                         (append ruby-search-paths
+                                                 search-paths))
+                   #:inputs %build-inputs)))
+
+  (define guile-for-build
+    (match guile
+      ((? package?)
+       (package-derivation store guile system))
+      ((and (? string?) (? derivation-path?))
+       guile)
+      (#f
+       (let* ((distro (resolve-interface '(gnu packages commencement)))
+              (guile  (module-ref distro 'guile-final)))
+         (package-derivation store guile system)))))
+
+  (let ((ruby (package-derivation store ruby system))
+        (git (package-derivation store git system)))
+    (build-expression->derivation store name builder
+                                  #:inputs
+                                  `(,@(if source
+                                          `(("source" ,source))
+                                          '())
+                                    ("ruby" ,ruby)
+                                    ,@inputs
+                                    ;; Keep the standard inputs of
+                                    ;; 'gnu-build-system'.
+                                    ,@(standard-inputs system))
+                                  #:system system
+                                  #:modules imported-modules
+                                  #:outputs outputs
+                                  #:guile-for-build guile-for-build)))
+
+(define ruby-build-system
+  (build-system
+   (name 'ruby)
+   (description "The standard Ruby build system")
+   (build ruby-build)))
diff --git a/guix/build/ruby-build-system.scm b/guix/build/ruby-build-system.scm
new file mode 100644
index 0000000..214d4f7
--- /dev/null
+++ b/guix/build/ruby-build-system.scm
@@ -0,0 +1,70 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2014 David Thompson <davet@gnu.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(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 match)
+  #:use-module (ice-9 regex)
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-26)
+  #:export (%standard-phases
+            ruby-build))
+
+;; Commentary:
+;;
+;; Builder-side code of the standard Ruby package build procedure.
+;;
+;; Code:
+
+(define build
+  (lambda _
+    (system "ls -la")
+    (let ((gemspec (car (find-files "." "\\.gemspec$"))))
+      (zero? (system* "gem" "build" gemspec)))))
+
+(define* (check #:key tests? test-target #:allow-other-keys)
+  (if tests?
+      (zero? (system* "rake" test-target))
+      #t))
+
+(define* (install #:key source inputs outputs #:allow-other-keys)
+  (let* ((ruby-version
+          (match:substring (string-match "ruby-(.*)$"
+                                         (assoc-ref inputs "ruby"))
+                           1))
+         (gem-home (string-append (assoc-ref outputs "out")
+                                  "/lib/ruby/gems/"
+                                  ruby-version)))
+    (setenv "GEM_HOME" gem-home)
+    (mkdir-p gem-home)
+    (let ((gem (car (find-files "." "\\.gem$"))))
+      (zero? (system* "gem" "install" "--local" gem)))))
+
+(define %standard-phases
+  (alist-replace
+   'build build
+   (alist-replace
+    'install install
+    (alist-replace
+     'check check
+     (alist-delete 'configure gnu:%standard-phases)))))
+
+(define* (ruby-build #:key inputs (phases %standard-phases)
+                     #:allow-other-keys #:rest args)
+  (apply gnu:gnu-build #:inputs inputs #:phases phases args))
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 3/3] gnu: Add ruby-i18n.
  2014-09-28 15:22 [PATCH 1/3] gnu: Add ruby David Thompson
  2014-09-28 15:22 ` [PATCH 2/3] build: Add ruby build system David Thompson
@ 2014-09-28 15:22 ` David Thompson
  2014-09-28 15:50   ` Ludovic Courtès
  2014-10-01 19:28   ` Ludovic Courtès
  2014-09-28 15:46 ` [PATCH 1/3] gnu: Add ruby Ludovic Courtès
  2014-09-28 19:24 ` David Thompson
  3 siblings, 2 replies; 13+ messages in thread
From: David Thompson @ 2014-09-28 15:22 UTC (permalink / raw)
  To: guix-devel

* gnu/packages/ruby.scm (ruby-i18n): New variable.
---
 gnu/packages/ruby.scm | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/ruby.scm b/gnu/packages/ruby.scm
index cded7e9..ac751f5 100644
--- a/gnu/packages/ruby.scm
+++ b/gnu/packages/ruby.scm
@@ -29,7 +29,8 @@
   #:use-module (guix packages)
   #:use-module (guix download)
   #:use-module (guix utils)
-  #:use-module (guix build-system gnu))
+  #:use-module (guix build-system gnu)
+  #:use-module (guix build-system ruby))
 
 (define-public ruby
   (package
@@ -88,3 +89,26 @@ a focus on simplicity and productivity.")
     (home-page "https://ruby-lang.org")
     (license license:ruby)))
 
+(define-public ruby-i18n
+  (package
+    (name "ruby-i18n")
+    (version "0.6.11")
+    (source (origin
+              (method url-fetch)
+              (uri (string-append "https://github.com/svenfuchs/i18n/archive/v"
+                                  version ".tar.gz"))
+              (sha256
+               (base32
+                "1fdhnhh1p5g8vibv44d770z8nq208zrms3m2nswdvr54072y1m6k"))))
+    (build-system ruby-build-system)
+    (arguments
+     '(#:tests? #f)) ; requires bundler
+    (synopsis "Internationalization library for Ruby")
+    (description "Ruby i18n is an internationalization and localization
+solution for Ruby programs.  It features translation and localization,
+interpolation of values to translations, pluralization, customizable
+transliteration to ASCII, flexible defaults, bulk lookup, lambdas as
+translation data, custom key/scope separator, custom exception handlers, and
+an extensible architecture with a swappable backend.")
+    (home-page "http://github.com/svenfuchs/i18n")
+    (license license:expat)))
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] build: Add ruby build system.
  2014-09-28 15:22 ` [PATCH 2/3] build: Add ruby build system David Thompson
@ 2014-09-28 15:41   ` David Thompson
  2014-09-28 15:50   ` Ludovic Courtès
  1 sibling, 0 replies; 13+ messages in thread
From: David Thompson @ 2014-09-28 15:41 UTC (permalink / raw)
  To: guix-devel

David Thompson <dthompson2@worcester.edu> writes:

> +(define build
> +  (lambda _
> +    (system "ls -la")

Oops!  Left a little debugging expression in.  Removed.

> +    (let ((gemspec (car (find-files "." "\\.gemspec$"))))
> +      (zero? (system* "gem" "build" gemspec)))))

-- 
David Thompson
Web Developer - Free Software Foundation - http://fsf.org
GPG Key: 0FF1D807
Support the FSF: https://fsf.org/donate

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/3] gnu: Add ruby.
  2014-09-28 15:22 [PATCH 1/3] gnu: Add ruby David Thompson
  2014-09-28 15:22 ` [PATCH 2/3] build: Add ruby build system David Thompson
  2014-09-28 15:22 ` [PATCH 3/3] gnu: Add ruby-i18n David Thompson
@ 2014-09-28 15:46 ` Ludovic Courtès
  2014-09-28 19:24 ` David Thompson
  3 siblings, 0 replies; 13+ messages in thread
From: Ludovic Courtès @ 2014-09-28 15:46 UTC (permalink / raw)
  To: David Thompson; +Cc: guix-devel, Pjotr Prins

David Thompson <dthompson2@worcester.edu> skribis:

> From: Pjotr Prins <pjotr.public01@thebird.nl>
>
> * gnu/packages/ruby.scm: New file.
> * gnu-system.am (GNU_SYSTEM_MODULES): Add it.
> * guix/licenses.scm (ruby): New variable.

LGTM, thanks to both of you!

Please add Co-authored-by: you if applicable.

Ludo’.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] build: Add ruby build system.
  2014-09-28 15:22 ` [PATCH 2/3] build: Add ruby build system David Thompson
  2014-09-28 15:41   ` David Thompson
@ 2014-09-28 15:50   ` Ludovic Courtès
  2014-09-28 16:25     ` David Thompson
  1 sibling, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2014-09-28 15:50 UTC (permalink / raw)
  To: David Thompson; +Cc: guix-devel

David Thompson <dthompson2@worcester.edu> skribis:

> * guix/build-system/ruby.scm: New file.
> * guix/build/ruby-build-system: New file.
> * Makefile.am (MODULES): Add new files.

Nice!  Some comments:

> +(define build
> +  (lambda _
> +    (system "ls -la")

Debugging leftover?

> +    (let ((gemspec (car (find-files "." "\\.gemspec$"))))
> +      (zero? (system* "gem" "build" gemspec)))))

Rather (match (find-files ...) ...).

> +(define* (install #:key source inputs outputs #:allow-other-keys)
> +  (let* ((ruby-version
> +          (match:substring (string-match "ruby-(.*)$"
> +                                         (assoc-ref inputs "ruby"))
> +                           1))
> +         (gem-home (string-append (assoc-ref outputs "out")
> +                                  "/lib/ruby/gems/"
> +                                  ruby-version)))
> +    (setenv "GEM_HOME" gem-home)
> +    (mkdir-p gem-home)
> +    (let ((gem (car (find-files "." "\\.gem$"))))
> +      (zero? (system* "gem" "install" "--local" gem)))))

Ditto.  Might be worth defining ‘first-gem-file’ for that.

Could you also add a few lines in guix.texi under “Build Systems”?

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/3] gnu: Add ruby-i18n.
  2014-09-28 15:22 ` [PATCH 3/3] gnu: Add ruby-i18n David Thompson
@ 2014-09-28 15:50   ` Ludovic Courtès
  2014-10-01 19:28   ` Ludovic Courtès
  1 sibling, 0 replies; 13+ messages in thread
From: Ludovic Courtès @ 2014-09-28 15:50 UTC (permalink / raw)
  To: David Thompson; +Cc: guix-devel

David Thompson <dthompson2@worcester.edu> skribis:

> * gnu/packages/ruby.scm (ruby-i18n): New variable.

OK!

Ludo'.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] build: Add ruby build system.
  2014-09-28 15:50   ` Ludovic Courtès
@ 2014-09-28 16:25     ` David Thompson
  2014-09-28 18:59       ` Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: David Thompson @ 2014-09-28 16:25 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1417 bytes --]

Ludovic Courtès <ludo@gnu.org> writes:

> David Thompson <dthompson2@worcester.edu> skribis:
>
>> * guix/build-system/ruby.scm: New file.
>> * guix/build/ruby-build-system: New file.
>> * Makefile.am (MODULES): Add new files.
>
> Nice!  Some comments:
>
>> +(define build
>> +  (lambda _
>> +    (system "ls -la")
>
> Debugging leftover?
>

Yup. :)

>> +    (let ((gemspec (car (find-files "." "\\.gemspec$"))))
>> +      (zero? (system* "gem" "build" gemspec)))))
>
> Rather (match (find-files ...) ...).
>
>> +(define* (install #:key source inputs outputs #:allow-other-keys)
>> +  (let* ((ruby-version
>> +          (match:substring (string-match "ruby-(.*)$"
>> +                                         (assoc-ref inputs "ruby"))
>> +                           1))
>> +         (gem-home (string-append (assoc-ref outputs "out")
>> +                                  "/lib/ruby/gems/"
>> +                                  ruby-version)))
>> +    (setenv "GEM_HOME" gem-home)
>> +    (mkdir-p gem-home)
>> +    (let ((gem (car (find-files "." "\\.gem$"))))
>> +      (zero? (system* "gem" "install" "--local" gem)))))
>
> Ditto.  Might be worth defining ‘first-gem-file’ for that.
>

Wrote a 'first-matching-file' procedure.

> Could you also add a few lines in guix.texi under “Build Systems”?
>

Done.

Updated patch attached.  Thanks for the review.


[-- Attachment #2: 0002-build-Add-ruby-build-system.patch --]
[-- Type: text/x-diff, Size: 9953 bytes --]

From c75bb477d28b057a0f78d520968daec5fdf881fa Mon Sep 17 00:00:00 2001
From: David Thompson <dthompson2@worcester.edu>
Date: Sun, 28 Sep 2014 11:14:53 -0400
Subject: [PATCH 2/3] build: Add ruby build system.

* guix/build-system/ruby.scm: New file.
* guix/build/ruby-build-system: New file.
* Makefile.am (MODULES): Add new files.
---
 Makefile.am                      |   2 +
 doc/guix.texi                    |   8 +++
 guix/build-system/ruby.scm       | 108 +++++++++++++++++++++++++++++++++++++++
 guix/build/ruby-build-system.scm |  75 +++++++++++++++++++++++++++
 4 files changed, 193 insertions(+)
 create mode 100644 guix/build-system/ruby.scm
 create mode 100644 guix/build/ruby-build-system.scm

diff --git a/Makefile.am b/Makefile.am
index 1f2c4db..3c22a77 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -50,6 +50,7 @@ MODULES =					\
   guix/build-system/gnu.scm			\
   guix/build-system/perl.scm			\
   guix/build-system/python.scm			\
+  guix/build-system/ruby.scm			\
   guix/build-system/trivial.scm			\
   guix/ftp-client.scm				\
   guix/http-client.scm				\
@@ -64,6 +65,7 @@ MODULES =					\
   guix/build/gnu-dist.scm			\
   guix/build/perl-build-system.scm		\
   guix/build/python-build-system.scm		\
+  guix/build/ruby-build-system.scm		\
   guix/build/store-copy.scm			\
   guix/build/utils.scm				\
   guix/build/union.scm				\
diff --git a/doc/guix.texi b/doc/guix.texi
index f73ce52..f5c3829 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -1648,6 +1648,14 @@ the @code{#:make-maker-flags} parameter.
 Which Perl package is used can be specified with @code{#:perl}.
 @end defvr
 
+@defvr {Scheme Variable} ruby-build-system
+This variable is exported by @code{(guix build-system ruby)}.  It
+implements the RubyGems build procedure used by Ruby packages, which
+involves running @code{gem build} followed by @code{gem install}.
+
+Which Ruby package is used can be specified with the @code{#:ruby}
+parameter.
+@end defvr
 
 Lastly, for packages that do not need anything as sophisticated, a
 ``trivial'' build system is provided.  It is trivial in the sense that
diff --git a/guix/build-system/ruby.scm b/guix/build-system/ruby.scm
new file mode 100644
index 0000000..f20967a
--- /dev/null
+++ b/guix/build-system/ruby.scm
@@ -0,0 +1,108 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2014 David Thompson <davet@gnu.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (guix build-system ruby)
+  #:use-module (guix store)
+  #:use-module (guix utils)
+  #:use-module (guix packages)
+  #:use-module (guix derivations)
+  #:use-module (guix build-system)
+  #:use-module (guix build-system gnu)
+  #:use-module (gnu packages version-control)
+  #:use-module (ice-9 match)
+  #:use-module (srfi srfi-26)
+  #:export (ruby-build
+            ruby-build-system))
+
+(define (default-ruby)
+  "Return the default Ruby package."
+  ;; Lazily resolve the binding to avoid a circular dependency.
+  (let ((ruby (resolve-interface '(gnu packages ruby))))
+    (module-ref ruby 'ruby)))
+
+(define* (ruby-build store name source inputs
+                     #:key
+                     (ruby (default-ruby))
+                     (test-target "test")
+                     (tests? #t)
+                     (phases '(@ (guix build ruby-build-system)
+                                 %standard-phases))
+                     (outputs '("out"))
+                     (search-paths '())
+                     (system (%current-system))
+                     (guile #f)
+                     (imported-modules '((guix build ruby-build-system)
+                                         (guix build gnu-build-system)
+                                         (guix build utils)))
+                     (modules '((guix build ruby-build-system)
+                                (guix build utils))))
+  "Build SOURCE using RUBY and INPUTS."
+  (define ruby-search-paths
+    (append (package-native-search-paths ruby)
+            (standard-search-paths)))
+
+  (define builder
+    `(begin
+       (use-modules ,@modules)
+       (ruby-build #:name ,name
+                   #:source ,(if (derivation? source)
+                                 (derivation->output-path source)
+                                 source)
+                   #:system ,system
+                   #:test-target ,test-target
+                   #:tests? ,tests?
+                   #:phases ,phases
+                   #:outputs %outputs
+                   #:search-paths ',(map search-path-specification->sexp
+                                         (append ruby-search-paths
+                                                 search-paths))
+                   #:inputs %build-inputs)))
+
+  (define guile-for-build
+    (match guile
+      ((? package?)
+       (package-derivation store guile system))
+      ((and (? string?) (? derivation-path?))
+       guile)
+      (#f
+       (let* ((distro (resolve-interface '(gnu packages commencement)))
+              (guile  (module-ref distro 'guile-final)))
+         (package-derivation store guile system)))))
+
+  (let ((ruby (package-derivation store ruby system))
+        (git (package-derivation store git system)))
+    (build-expression->derivation store name builder
+                                  #:inputs
+                                  `(,@(if source
+                                          `(("source" ,source))
+                                          '())
+                                    ("ruby" ,ruby)
+                                    ,@inputs
+                                    ;; Keep the standard inputs of
+                                    ;; 'gnu-build-system'.
+                                    ,@(standard-inputs system))
+                                  #:system system
+                                  #:modules imported-modules
+                                  #:outputs outputs
+                                  #:guile-for-build guile-for-build)))
+
+(define ruby-build-system
+  (build-system
+   (name 'ruby)
+   (description "The standard Ruby build system")
+   (build ruby-build)))
diff --git a/guix/build/ruby-build-system.scm b/guix/build/ruby-build-system.scm
new file mode 100644
index 0000000..2b3ba7c
--- /dev/null
+++ b/guix/build/ruby-build-system.scm
@@ -0,0 +1,75 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2014 David Thompson <davet@gnu.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(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 match)
+  #:use-module (ice-9 regex)
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-26)
+  #:export (%standard-phases
+            ruby-build))
+
+;; Commentary:
+;;
+;; Builder-side code of the standard Ruby package build procedure.
+;;
+;; Code:
+
+(define (first-matching-file pattern)
+  "Return the first file name that matches PATTERN in the current working
+directory."
+  (match (find-files "." pattern)
+    ((file-name . _) file-name)
+    (() (error "No files matching pattern: " pattern))))
+
+(define build
+  (lambda _
+    (zero? (system* "gem" "build" (first-matching-file "\\.gemspec$")))))
+
+(define* (check #:key tests? test-target #:allow-other-keys)
+  (if tests?
+      (zero? (system* "rake" test-target))
+      #t))
+
+(define* (install #:key source inputs outputs #:allow-other-keys)
+  (let* ((ruby-version
+          (match:substring (string-match "ruby-(.*)$"
+                                         (assoc-ref inputs "ruby"))
+                           1))
+         (gem-home (string-append (assoc-ref outputs "out")
+                                  "/lib/ruby/gems/"
+                                  ruby-version)))
+    (setenv "GEM_HOME" gem-home)
+    (mkdir-p gem-home)
+    (zero? (system* "gem" "install" "--local"
+                    (first-matching-file "\\.gem$")))))
+
+(define %standard-phases
+  (alist-replace
+   'build build
+   (alist-replace
+    'install install
+    (alist-replace
+     'check check
+     (alist-delete 'configure gnu:%standard-phases)))))
+
+(define* (ruby-build #:key inputs (phases %standard-phases)
+                     #:allow-other-keys #:rest args)
+  (apply gnu:gnu-build #:inputs inputs #:phases phases args))
-- 
2.1.0


[-- Attachment #3: Type: text/plain, Size: 136 bytes --]


-- 
David Thompson
Web Developer - Free Software Foundation - http://fsf.org
GPG Key: 0FF1D807
Support the FSF: https://fsf.org/donate

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/3] build: Add ruby build system.
  2014-09-28 16:25     ` David Thompson
@ 2014-09-28 18:59       ` Ludovic Courtès
  0 siblings, 0 replies; 13+ messages in thread
From: Ludovic Courtès @ 2014-09-28 18:59 UTC (permalink / raw)
  To: David Thompson; +Cc: guix-devel

David Thompson <dthompson2@worcester.edu> skribis:

> From c75bb477d28b057a0f78d520968daec5fdf881fa Mon Sep 17 00:00:00 2001
> From: David Thompson <dthompson2@worcester.edu>
> Date: Sun, 28 Sep 2014 11:14:53 -0400
> Subject: [PATCH 2/3] build: Add ruby build system.
>
> * guix/build-system/ruby.scm: New file.
> * guix/build/ruby-build-system: New file.
> * Makefile.am (MODULES): Add new files.

Perfect, please push!

Ludo’.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 1/3] gnu: Add ruby.
  2014-09-28 15:22 [PATCH 1/3] gnu: Add ruby David Thompson
                   ` (2 preceding siblings ...)
  2014-09-28 15:46 ` [PATCH 1/3] gnu: Add ruby Ludovic Courtès
@ 2014-09-28 19:24 ` David Thompson
  3 siblings, 0 replies; 13+ messages in thread
From: David Thompson @ 2014-09-28 19:24 UTC (permalink / raw)
  To: guix-devel; +Cc: Pjotr Prins

All 3 patches have been pushed!  :D

-- 
David Thompson
Web Developer - Free Software Foundation - http://fsf.org
GPG Key: 0FF1D807
Support the FSF: https://fsf.org/donate

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/3] gnu: Add ruby-i18n.
  2014-09-28 15:22 ` [PATCH 3/3] gnu: Add ruby-i18n David Thompson
  2014-09-28 15:50   ` Ludovic Courtès
@ 2014-10-01 19:28   ` Ludovic Courtès
  2014-10-01 19:49     ` Thompson, David
  1 sibling, 1 reply; 13+ messages in thread
From: Ludovic Courtès @ 2014-10-01 19:28 UTC (permalink / raw)
  To: David Thompson; +Cc: guix-devel

Hello,

I just noticed this:

  $ guix gc --references /gnu/store/whj6j9f34adpzwhfj3qf00fcq9zsb3hp-ruby-i18n-0.6.11
  [nothing here]

Apparently the .gem is +/- a gzip archive, which makes it opaque to the
GC, hence the above result.

Is it something we should worry about, or is it fine because .gem files
in general don’t won’t hold any reference to something else?

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/3] gnu: Add ruby-i18n.
  2014-10-01 19:28   ` Ludovic Courtès
@ 2014-10-01 19:49     ` Thompson, David
  2014-10-02  8:35       ` Ludovic Courtès
  0 siblings, 1 reply; 13+ messages in thread
From: Thompson, David @ 2014-10-01 19:49 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: guix-devel

On Wed, Oct 1, 2014 at 3:28 PM, Ludovic Courtès <ludo@gnu.org> wrote:
> Hello,
>
> I just noticed this:
>
>   $ guix gc --references /gnu/store/whj6j9f34adpzwhfj3qf00fcq9zsb3hp-ruby-i18n-0.6.11
>   [nothing here]
>
> Apparently the .gem is +/- a gzip archive, which makes it opaque to the
> GC, hence the above result.
>
> Is it something we should worry about, or is it fine because .gem files
> in general don’t won’t hold any reference to something else?
>

There should be many other files there, too, right?  The Ruby source
should be there in plain text.  In the case of the i18n gem, it
doesn't depend on any external librararies, so there's no references
to be found since it doesn't directly refer to the Ruby interpreter
that built the gem (should it?).  Now, when a gem has other
dependencies, my suspicion is that there also won't be any references,
which is definitely something to worry about.  I guess the Ruby build
system needs to be adjusted to do something similar to the shebang
substitution, but for gem paths.  That might be really tough to do
reliably, though.

Sorry that I don't have a better answer right now.  I guess I should
take a look at how Nix handles this.

Thanks for letting me know.

- Dave

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 3/3] gnu: Add ruby-i18n.
  2014-10-01 19:49     ` Thompson, David
@ 2014-10-02  8:35       ` Ludovic Courtès
  0 siblings, 0 replies; 13+ messages in thread
From: Ludovic Courtès @ 2014-10-02  8:35 UTC (permalink / raw)
  To: Thompson, David; +Cc: guix-devel

"Thompson, David" <dthompson2@worcester.edu> skribis:

> On Wed, Oct 1, 2014 at 3:28 PM, Ludovic Courtès <ludo@gnu.org> wrote:
>> Hello,
>>
>> I just noticed this:
>>
>>   $ guix gc --references /gnu/store/whj6j9f34adpzwhfj3qf00fcq9zsb3hp-ruby-i18n-0.6.11
>>   [nothing here]
>>
>> Apparently the .gem is +/- a gzip archive, which makes it opaque to the
>> GC, hence the above result.
>>
>> Is it something we should worry about, or is it fine because .gem files
>> in general don’t won’t hold any reference to something else?
>>
>
> There should be many other files there, too, right?

Yes, notably all the .rb files.

> The Ruby source should be there in plain text.  In the case of the
> i18n gem, it doesn't depend on any external librararies, so there's no
> references to be found since it doesn't directly refer to the Ruby
> interpreter that built the gem (should it?).

This is fine.

> Now, when a gem has other dependencies, my suspicion is that there
> also won't be any references, which is definitely something to worry
> about.

Actually it depends.  I hadn’t noticed, but since all the .rb source
files are there, uncompressed, that means that if a reference is
embedded in the source, it *will* be scanned correctly by the GC.

So maybe there’s no real problem, after all.

Thanks,
Ludo’.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-10-02  8:35 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-28 15:22 [PATCH 1/3] gnu: Add ruby David Thompson
2014-09-28 15:22 ` [PATCH 2/3] build: Add ruby build system David Thompson
2014-09-28 15:41   ` David Thompson
2014-09-28 15:50   ` Ludovic Courtès
2014-09-28 16:25     ` David Thompson
2014-09-28 18:59       ` Ludovic Courtès
2014-09-28 15:22 ` [PATCH 3/3] gnu: Add ruby-i18n David Thompson
2014-09-28 15:50   ` Ludovic Courtès
2014-10-01 19:28   ` Ludovic Courtès
2014-10-01 19:49     ` Thompson, David
2014-10-02  8:35       ` Ludovic Courtès
2014-09-28 15:46 ` [PATCH 1/3] gnu: Add ruby Ludovic Courtès
2014-09-28 19:24 ` David Thompson

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).