You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@deltacloud.apache.org by lu...@redhat.com on 2010/10/22 00:42:00 UTC

Only build one gem for JRuby and MRI

I don't like the fact that currently we're building two gems: one for
JRuby, and another one for MRI.

The only reason we're doing this is that we like to run under thin [1],
which is not available for JRuby. Rather than hardcode the webserver to use
in the gem dependency, I feel it's enough to do this later in an RPM spec
and through documentation. That's the route most other Ruby webapps go.

With these patches, we'll only build one gem, which does not depend on thin
(or rerun) and therefore will work under JRuby. Furthermore, we'll make the
decision whether to use WebRick or thin solely based on whether thin is
available or not.

David

[1] It's more than a preference: blob streaming only works with thin, but
    that's just details ;)


Re: Only build one gem for JRuby and MRI

Posted by Benjamin Browning <bb...@redhat.com>.
On Oct 22, 2010, at 9:13 AM, Benjamin Browning wrote:
>  I've had success running the FFI version on recent Linux distros (Fedora 13, Ubuntu 10.04), but not on Mac or Windows.

I just tried the latest Nokogiri stable release (1.4.3+), and they've fixed the issue that prevented it from running on Macs easily. I don't have a Windows machine to test, but at this point I'd be comfortable dropping the higher JRuby version requirement and let's just document that if someone has problems under JRuby to try installing Nokogiri 1.5.0.beta2.

Ben


Re: Only build one gem for JRuby and MRI

Posted by Benjamin Browning <bb...@redhat.com>.
David,

On Oct 21, 2010, at 6:42 PM, lutter@redhat.com wrote:

> I don't like the fact that currently we're building two gems: one for
> JRuby, and another one for MRI.
> 
> The only reason we're doing this is that we like to run under thin [1],
> which is not available for JRuby. Rather than hardcode the webserver to use
> in the gem dependency, I feel it's enough to do this later in an RPM spec
> and through documentation. That's the route most other Ruby webapps go.

Makes sense and will make the JRuby experience easier. Thanks!

> 
> With these patches, we'll only build one gem...

The client still builds two gems because of Nokogiri versions. There has been a java-specific Nokogiri gem for quite a while but until the latest beta it relied on FFI. I've had success running the FFI version on recent Linux distros (Fedora 13, Ubuntu 10.04), but not on Mac or Windows. The version currently specific in the client gemspec for java is 1.5.0.beta2, which is the first version to introduce a pure-java implementation that doesn't need libxml2 and libxslt and thus runs on anything without external libraries.

Maybe we can converge these also? I'd be comfortable leaving the gemspec nokogiri requirement at version '>= 1.4.1' if you let me add a wrapper around the nokogiri require giving instructions for installing the pure-java version if on JRuby and nokogiri fails to load.

Ben

[PATCH 1/2] * server/bin/deltacloudd: fall back to WebRick if thin isn't there

Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>

Rather than use WebRick only on the Java platform, check whether thin is
there, und decide whether to start thin or WebRick depending on whether
thin is there.
---
 server/bin/deltacloudd |   32 +++++++++++++++++---------------
 1 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/server/bin/deltacloudd b/server/bin/deltacloudd
index 9d91e1a..ed7883b 100755
--- a/server/bin/deltacloudd
+++ b/server/bin/deltacloudd
@@ -3,6 +3,18 @@
 require 'rubygems'
 require 'optparse'
 
+# See if we can require +name+ and return +true+ if the library is there,
+# +false+ otherwise. Note that, as a side effect, the library will be
+# loaded
+def library_present?(name)
+  begin
+    require name
+    true
+  rescue LoadError
+    false
+  end
+end
+
 options = {
   :env => 'development'
 }
@@ -47,9 +59,11 @@ puts "Starting Deltacloud API :: #{ENV["API_DRIVER"]} :: http://#{ENV["API_HOST"
 puts
 
 dirname="#{File.dirname(__FILE__)}/.."
-platform = RUBY_PLATFORM[/java/] || 'ruby'
 
-if platform == 'java'
+have_thin = library_present?('thin')
+have_rerun = library_present?('rerun')
+
+unless have_thin
   require 'rack'
 
   # We can't chdir with webrick so add our root directory
@@ -78,8 +92,6 @@ if platform == 'java'
                              :Port => port,
                              :AccessLog => [])
 else
-  require 'thin'
-
   argv_opts = ARGV.clone
   argv_opts << ['start'] unless Thin::Runner.commands.include?(options[0])
   argv_opts << ['--address', ENV["API_HOST"] ]
@@ -91,17 +103,7 @@ else
 
   argv_opts.flatten!
 
-  if options[:env] == "development"
-    use_rerun = false
-    begin
-      require "rerun"
-      use_rerun = true
-    rescue
-      # Do nothing
-    end
-  end
-
-  if use_rerun
+  if have_rerun && options[:env] == "development"
     argv_opts.unshift "thin"
     command = argv_opts.join(" ")
     topdir = File::expand_path(File::join(File::dirname(__FILE__), ".."))
-- 
1.7.2.3


Re: [PATCH 2/2] Gem building: do not depend on thin/rerun

Posted by Michal Fojtik <mf...@redhat.com>.
On 21/10/10 15:42 -0700, lutter@redhat.com wrote:
>From: David Lutterkort <lu...@redhat.com>
>
>Having thin/rerun should be developer conveniences resp. recommendations
>for deployment. No need to hardcode this as gem dependencies.
>
>  * server/Rakefile: only build one gem, which will work under MRI and
>    JRuby
>  * server/deltacloud-core.gemspec: remove dependencies on thin and rerun
>  * tests/mock/99_rake.feature: only expect one gem file
>---
> server/Rakefile                |   12 +++---------
> server/deltacloud-core.gemspec |    8 --------
> tests/mock/99_rake.feature     |    2 +-
> 3 files changed, 4 insertions(+), 18 deletions(-)
>
>diff --git a/server/Rakefile b/server/Rakefile
>index eb0b767..e562cb5 100644
>--- a/server/Rakefile
>+++ b/server/Rakefile
>@@ -43,15 +43,9 @@ begin
> rescue LoadError
> end
> 
>-@specs = ['ruby', 'java'].inject({}) do |hash, spec_platform|
>-  $platform = spec_platform
>-  hash.update(spec_platform => Gem::Specification.load('deltacloud-core.gemspec'))
>-end
>-
>-@specs.values.each do |spec|
>-  Rake::GemPackageTask.new(spec) do |pkg|
>-    pkg.need_tar = true
>-  end
>+spec = Gem::Specification.load('deltacloud-core.gemspec')
>+Rake::GemPackageTask.new(spec) do |pkg|
>+  pkg.need_tar = true
> end
> 
> desc "Install API"
>diff --git a/server/deltacloud-core.gemspec b/server/deltacloud-core.gemspec
>index 5fc7c19..f6fc542 100644
>--- a/server/deltacloud-core.gemspec
>+++ b/server/deltacloud-core.gemspec
>@@ -58,19 +58,11 @@ Gem::Specification.new do |s|
>   s.extra_rdoc_files = Dir["COPYING"]
>   s.required_ruby_version = '>= 1.8.1'
> 
>-  # Rakefile needs to create spec for both platforms (ruby and java), using the
>-  # $platform global variable. In all other cases, we figure it out from
>-  # RUBY_PLATFORM.
>-  s.platform = $platform || RUBY_PLATFORM[/java/] || 'ruby'
>-
>   s.add_dependency('rake', '>= 0.8.7')
>-  s.add_dependency('eventmachine', '>= 0.12.10') if s.platform.to_s == 'ruby'
>   s.add_dependency('haml', '>= 2.2.17')
>   s.add_dependency('sinatra', '>= 0.9.4')
>   s.add_dependency('rack', '>= 1.0.0')
>   s.add_dependency('rack-accept', '~> 0.4.3')
>-  s.add_dependency('thin', '>= 1.2.5') if s.platform.to_s == 'ruby'
>-  s.add_dependency('rerun', '>= 0.5.2') if s.platform.to_s == 'ruby'
>   s.add_dependency('json', '>= 1.1.9')
>   s.add_development_dependency('compass', '>= 0.8.17')
>   s.add_development_dependency('nokogiri', '>= 1.4.1')
>diff --git a/tests/mock/99_rake.feature b/tests/mock/99_rake.feature
>index 5d70b8a..d6b424a 100644
>--- a/tests/mock/99_rake.feature
>+++ b/tests/mock/99_rake.feature
>@@ -3,5 +3,5 @@ Feature: Running rake tasks
>   Scenario: I want to build Deltacloud API gem
>     Given I have a clean /pkg directory
>     When I run a 'package' task
>-    Then I should see a 2 gem file inside pkg directory
>+    Then I should see a 1 gem file inside pkg directory
>     And I should see a 1 tgz file inside pkg directory
>-- 
>1.7.2.3

ACK.

   -- MIchal

-- 
--------------------------------------------------------
Michal Fojtik, mfojtik@redhat.com
Deltacloud API: http://deltacloud.org
--------------------------------------------------------

[PATCH 2/2] Gem building: do not depend on thin/rerun

Posted by lu...@redhat.com.
From: David Lutterkort <lu...@redhat.com>

Having thin/rerun should be developer conveniences resp. recommendations
for deployment. No need to hardcode this as gem dependencies.

  * server/Rakefile: only build one gem, which will work under MRI and
    JRuby
  * server/deltacloud-core.gemspec: remove dependencies on thin and rerun
  * tests/mock/99_rake.feature: only expect one gem file
---
 server/Rakefile                |   12 +++---------
 server/deltacloud-core.gemspec |    8 --------
 tests/mock/99_rake.feature     |    2 +-
 3 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/server/Rakefile b/server/Rakefile
index eb0b767..e562cb5 100644
--- a/server/Rakefile
+++ b/server/Rakefile
@@ -43,15 +43,9 @@ begin
 rescue LoadError
 end
 
-@specs = ['ruby', 'java'].inject({}) do |hash, spec_platform|
-  $platform = spec_platform
-  hash.update(spec_platform => Gem::Specification.load('deltacloud-core.gemspec'))
-end
-
-@specs.values.each do |spec|
-  Rake::GemPackageTask.new(spec) do |pkg|
-    pkg.need_tar = true
-  end
+spec = Gem::Specification.load('deltacloud-core.gemspec')
+Rake::GemPackageTask.new(spec) do |pkg|
+  pkg.need_tar = true
 end
 
 desc "Install API"
diff --git a/server/deltacloud-core.gemspec b/server/deltacloud-core.gemspec
index 5fc7c19..f6fc542 100644
--- a/server/deltacloud-core.gemspec
+++ b/server/deltacloud-core.gemspec
@@ -58,19 +58,11 @@ Gem::Specification.new do |s|
   s.extra_rdoc_files = Dir["COPYING"]
   s.required_ruby_version = '>= 1.8.1'
 
-  # Rakefile needs to create spec for both platforms (ruby and java), using the
-  # $platform global variable. In all other cases, we figure it out from
-  # RUBY_PLATFORM.
-  s.platform = $platform || RUBY_PLATFORM[/java/] || 'ruby'
-
   s.add_dependency('rake', '>= 0.8.7')
-  s.add_dependency('eventmachine', '>= 0.12.10') if s.platform.to_s == 'ruby'
   s.add_dependency('haml', '>= 2.2.17')
   s.add_dependency('sinatra', '>= 0.9.4')
   s.add_dependency('rack', '>= 1.0.0')
   s.add_dependency('rack-accept', '~> 0.4.3')
-  s.add_dependency('thin', '>= 1.2.5') if s.platform.to_s == 'ruby'
-  s.add_dependency('rerun', '>= 0.5.2') if s.platform.to_s == 'ruby'
   s.add_dependency('json', '>= 1.1.9')
   s.add_development_dependency('compass', '>= 0.8.17')
   s.add_development_dependency('nokogiri', '>= 1.4.1')
diff --git a/tests/mock/99_rake.feature b/tests/mock/99_rake.feature
index 5d70b8a..d6b424a 100644
--- a/tests/mock/99_rake.feature
+++ b/tests/mock/99_rake.feature
@@ -3,5 +3,5 @@ Feature: Running rake tasks
   Scenario: I want to build Deltacloud API gem
     Given I have a clean /pkg directory
     When I run a 'package' task
-    Then I should see a 2 gem file inside pkg directory
+    Then I should see a 1 gem file inside pkg directory
     And I should see a 1 tgz file inside pkg directory
-- 
1.7.2.3