| Store | Cart

Re: Cross-platform gems / conditional loading of gems

From: D. Deryl Downey <m...@daviddwdowney.com>
Fri, 4 Jan 2013 12:08:06 +0900
In my config/database.yml I have the following:

development:
   adapter: <%= "jdbc" if defined?(JRUBY_PLATFORM) %>sqlite3
   database: db/dtf_development.sqlite3
   pool: 5
   timeout: 5000


In my spec/spec_helper I have the following (Need to change the YAML 
engine used under JRuby):

# Set the YAML engine for JRuby
if RUBY_PLATFORM == "java"
   ::YAML::ENGINE.yamler = 'psych'
end

When working with gems (as in writing them) use this in your gemspec for 
specifying a specific sqlite3 based on the platform:

   gem.add_dependency "sqlite3" if RUBY_PLATFORM == "ruby"

   gem.add_dependency "jdbc-sqlite3" if RUBY_PLATFORM == "java"
   #gem.add_dependency "activerecord-jdbcsqlite3-adapter" if 
RUBY_PLATFORM == "java"
   gem.add_dependency "jruby-openssl" if RUBY_PLATFORM == "java"


In these instances, I am adapting to change for use with JRuby. Modify 
as you need for the Windows platform.


> Intransition <mailto:tran...@gmail.com>> January 3, 2013 9:04 PM> Try something like:>>     if RUBY_PLATFORM =~ /(win|ming)/>       ...>     else>       ...>     end>>> Alex Allmont <mailto:Alex...@naturalmotion.com>> January 3, 2013 6:59 AM>> Hi all,>> We use ruby as part of our development team tools for Windows and Mac > machines.  This is maintained internally in an SVN repository where > the platform-specific files are interleaved, i.e. the bin/ directory > contains both a Windows ruby.exe and a Mac ruby executable.  This > repository is packaged into installers so we can deploy to our dev > team ensuring that everyone has the correct ruby version and gems.>> New gems are installed on an administrator's machine and SVN added to > the gems folder (and the corresponding gemspec is added to the > specifications folder).  Most of these are platform agnostic but we > have a few that are Windows-only, e.g. qtbindings.>> This was working fine until trying to get sqlite3 running on both PC > and Mac.  The PC version was installed first > (gems/sqlite3-1.3.6-x86-mingw32) and this worked fine.  The mingw32 > version is PC only so I installed sqlite3 on an OSX machine which > added the new gem to gems\sqlite3-1.3.6.>> This new gem conflicts with the PC version, e.g. attempting to require > via IRB on the Mac:>> irb(main):001:0> require 'sqlite3'>> LoadError: cannot load such file -- sqlite3/sqlite3_native>>                 from > /Users/aallmont/nm/buildtools/ruby/1.9.3/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in > `require'>>                 from > /Users/aallmont/nm/buildtools/ruby/1.9.3/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in > `require'>> This error goes away if I remove the gems/sqlite3-1.3.6-x86-mingw32 > folder on the Mac.  There is a similar error on the PC which goes away > if I remove the gems/sqlite3-1.3.6-x86 folder, i.e. they are mutually > exclusive.>> I would like to only load gems/sqlite3-1.3.6-x86 when running on the > Mac and only load gems/sqlite3-1.3.6-x86-mingw32 when running on the > PC.  Is this possible?>> Many thanks,>> Alex>

-- 
D. Deryl Downey

"The bug which you would fright me with I seek" - William Shakespeare - The Winter's Tale, Act III, Scene II - A court of Justice.




Recent Messages in this Thread
Alex Allmont Jan 03, 2013 11:59 am
Intransition Jan 04, 2013 02:04 am
D. Deryl Downey Jan 04, 2013 03:08 am
Messages in this thread