Skip to content

Commit 6850627

Browse files
committed
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.
1 parent ba32cc3 commit 6850627

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

Rakefile

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,36 +47,27 @@ task 'gem:precompile' => ['gem'] do
4747
installer = Gem::Installer.new(gemfile)
4848
installer.unpack(target_dir)
4949

50-
rubies = ENV['RUBIES'] ? ENV['RUBIES'].split(',') : [Gem.ruby]
51-
args = ENV['EXT_OPTS'] ? ENV['EXT_OPTS'].split(',') : []
52-
5350
gemspec = installer.spec
5451
extension = gemspec.extensions[0]
5552
gemspec.extensions.clear
56-
gemspec.platform = ENV['PLATFORM'] || Gem::Platform::CURRENT
53+
54+
config = ENV['CONFIG'] ? YAML.load_file(ENV['CONFIG']) : {}
55+
rubies = config['rubies'] || [Gem.ruby]
56+
args = config['extopts'] || []
57+
gemspec.platform = config['platform'] || Gem::Platform::CURRENT
5758

5859
multi = rubies.size > 1
5960
rubies.each { |ruby|
60-
results = []
61-
62-
# Convert MinGW's drive letters to Windows' ones
63-
# e.g. /c/ruby/bin/ruby.exe => c:/ruby/bin/ruby.exe
64-
ruby.gsub!(/^\/([a-zA-Z])\//, '\1:/')
65-
6661
lib_dir = 'lib'
6762
if multi
6863
major, minor, _ = `#{ruby} -e "print RUBY_VERSION"`.chomp.split('.')
6964
lib_dir = File.join(lib_dir, [major, minor].join('.'))
7065
end
7166

72-
target_platform = `#{ruby} -e "print RUBY_PLATFORM"`
73-
# Convert MinGW's drive letters to Windows' ones
74-
# e.g. --with-opencv-dir=/c/path/to/opencv => --with-opencv-dir=c:/path/to/opencv
75-
args.map! { |a| a.gsub(/=\/([a-zA-Z])\//, '=\1:/') } if target_platform =~ /mingw/
76-
77-
make_cmd = (target_platform =~ /mswin/) ? 'nmake' : 'make'
67+
make_cmd = (`#{ruby} -e "print RUBY_PLATFORM"` =~ /mswin/) ? 'nmake' : 'make'
7868
Dir.chdir(target_dir) {
7969
cmd = [ruby, extension, *args].join(' ')
70+
results = []
8071
Gem::Ext::ExtConfBuilder.run(cmd, results)
8172
Gem::Ext::ExtConfBuilder.make('', results)
8273

config.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
platform: mingw32
2+
rubies:
3+
- C:/ruby-1.9.3-p392-mingw32/bin/ruby.exe
4+
- C:/ruby-2.0.0-p0-mingw32/bin/ruby.exe
5+
extopts:
6+
- --with-opencv-include=C:/opencv-2.4.5/build/include
7+
- --with-opencv-lib=C:/opencv-2.4.5/build/x86/mingw/lib

0 commit comments

Comments
 (0)