load pre-compile configs from config files

When create a pre-compiled gem in MinGW MSYS shell passing Ruby or OpenCV's paths,
the paths are converted to be invalid by MSYS shell.

E.g.
  When we run the following command
    $ rake gem:precompile RUBIES=C:/ruby19/bin/ruby.exe,C:/ruby20/bin/ruby.exe
  The following paths are expected
    ENV['RUBIES'] = "C:/ruby19/bin/ruby.exe,C:/ruby20/bin/ruby.exe"
  But we get the following
    ENV['RUBIES'] = "C;C:\\MinGW\\msys\\1.0\\ruby19\\bin\\ruby.exe,C;C:\\MinGW\\msys\\1.0\\ruby20\\bin\\ruby.exe"

This fix is for avoiding the problem.
This commit is contained in:
ser1zw 2013-05-05 02:23:19 +09:00
parent ba32cc36ba
commit 6850627473
2 changed files with 14 additions and 16 deletions

View File

@ -47,36 +47,27 @@ task 'gem:precompile' => ['gem'] do
installer = Gem::Installer.new(gemfile)
installer.unpack(target_dir)
rubies = ENV['RUBIES'] ? ENV['RUBIES'].split(',') : [Gem.ruby]
args = ENV['EXT_OPTS'] ? ENV['EXT_OPTS'].split(',') : []
gemspec = installer.spec
extension = gemspec.extensions[0]
gemspec.extensions.clear
gemspec.platform = ENV['PLATFORM'] || Gem::Platform::CURRENT
config = ENV['CONFIG'] ? YAML.load_file(ENV['CONFIG']) : {}
rubies = config['rubies'] || [Gem.ruby]
args = config['extopts'] || []
gemspec.platform = config['platform'] || Gem::Platform::CURRENT
multi = rubies.size > 1
rubies.each { |ruby|
results = []
# Convert MinGW's drive letters to Windows' ones
# e.g. /c/ruby/bin/ruby.exe => c:/ruby/bin/ruby.exe
ruby.gsub!(/^\/([a-zA-Z])\//, '\1:/')
lib_dir = 'lib'
if multi
major, minor, _ = `#{ruby} -e "print RUBY_VERSION"`.chomp.split('.')
lib_dir = File.join(lib_dir, [major, minor].join('.'))
end
target_platform = `#{ruby} -e "print RUBY_PLATFORM"`
# Convert MinGW's drive letters to Windows' ones
# e.g. --with-opencv-dir=/c/path/to/opencv => --with-opencv-dir=c:/path/to/opencv
args.map! { |a| a.gsub(/=\/([a-zA-Z])\//, '=\1:/') } if target_platform =~ /mingw/
make_cmd = (target_platform =~ /mswin/) ? 'nmake' : 'make'
make_cmd = (`#{ruby} -e "print RUBY_PLATFORM"` =~ /mswin/) ? 'nmake' : 'make'
Dir.chdir(target_dir) {
cmd = [ruby, extension, *args].join(' ')
results = []
Gem::Ext::ExtConfBuilder.run(cmd, results)
Gem::Ext::ExtConfBuilder.make('', results)

7
config.yml Normal file
View File

@ -0,0 +1,7 @@
platform: mingw32
rubies:
- C:/ruby-1.9.3-p392-mingw32/bin/ruby.exe
- C:/ruby-2.0.0-p0-mingw32/bin/ruby.exe
extopts:
- --with-opencv-include=C:/opencv-2.4.5/build/include
- --with-opencv-lib=C:/opencv-2.4.5/build/x86/mingw/lib