-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
mkrf_conf_bingem.rb
149 lines (127 loc) · 5.08 KB
/
mkrf_conf_bingem.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#--------------------------------------------------------------------
# mkrf_conf_bingem.rb - Rakefile generator binary gem installation
#
# Author: Martin Corino
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the R2CORBA LICENSE which is
# included with this program.
#
# Copyright (c) Remedy IT Expertise BV
#--------------------------------------------------------------------
# generate Rakefile with appropriate default task (all actual task in rakelib)
File.open('Rakefile', 'w') do |f|
f.puts <<EOF__
#--------------------------------------------------------------------
# Rakefile - build file for srcgem installation
#
# Author: Martin Corino
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the R2CORBA LICENSE which is
# included with this program.
#
# Copyright (c) Remedy IT Expertise BV
#--------------------------------------------------------------------
if defined?(JRUBY_VERSION)
task :default => 'r2corba:build'
else
task :default => 'r2corba:gem:binbuild'
end
EOF__
end
if defined?(JRUBY_VERSION)
unless system("ruby -S rake -- configure --jacorb-home=#{File.expand_path('ext')}")
$stderr.puts 'Failed to configure R2CORBA'
exit(1)
end
else
require 'rbconfig'
if defined? ::RbConfig
RB_CONFIG = ::RbConfig::CONFIG
else
RB_CONFIG = ::Config::CONFIG
end unless defined? RB_CONFIG
# check if we have a full bin gem here, or one without extension binaries
if Dir["ext/*.#{RB_CONFIG['DLEXT']}"].empty?
RB_VER_MAJOR, RB_VER_MINOR, RB_VER_REL = RUBY_VERSION.split('.').collect {|n| n.to_i}
require File.join(File.dirname(__FILE__), 'lib', 'corba', 'common', 'version.rb')
require 'rubygems'
require 'rubygems/command.rb'
require 'rubygems/dependency_installer.rb'
require 'rubygems/uninstaller'
require 'fileutils'
## ==========================================================================================##
# determin rubygems version
gem_ver_major, gem_ver_minor, gem_ver_release = Gem::VERSION.split('.').collect {|s| s.to_i }
# in case of rubygems 2.3.0 - 2.4.5
if gem_ver_major == 2 && (gem_ver_minor == 3 || (gem_ver_minor == 4 && gem_ver_release <= 5))
# patch the Gem::Resolver::InstallerSet class
require 'rubygems/resolver/installer_set'
class ::Gem::Resolver::InstallerSet
def add_always_install dependency
request = Gem::Resolver::DependencyRequest.new dependency, nil
found = find_all request
found.delete_if { |s|
s.version.prerelease? and not s.local?
} unless dependency.prerelease?
found = found.select do |s|
Gem::Source::SpecificFile === s.source or
Gem::Platform::RUBY == s.platform or
# *** MCO patch *** use correct platform comparison -> s.platform === String
Gem::Platform.local =~ s.platform
end
if found.empty? then
exc = Gem::UnsatisfiableDependencyError.new request
exc.errors = errors
raise exc
end
newest = found.max_by do |s|
[s.version, s.platform == Gem::Platform::RUBY ? -1 : 1]
end
@always_install << newest.spec
end
end
end
## ==========================================================================================##
begin
Gem::Command.build_args = ARGV
rescue NoMethodError
end
unless ENV['R2CORBA_GEM_SOURCE'].to_s.empty?
# make sure the RubyGems configuration has been loaded as this potentially overwrites
# Gem.sources
Gem.configuration
# add custom source
Gem.sources << ENV['R2CORBA_GEM_SOURCE']
puts "Gem sources: #{Gem.sources.to_a}"
end
inst = Gem::DependencyInstaller.new
begin
# install corresponding gem with extension binaries
puts "Installing extension binaries gem: r2corba_ext#{RB_VER_MAJOR}#{RB_VER_MINOR}-#{R2CORBA::R2CORBA_VERSION}."
spec = inst.install("r2corba_ext#{RB_VER_MAJOR}#{RB_VER_MINOR}", R2CORBA::R2CORBA_VERSION.dup).last
begin
# move extension binaries from extension binaries gem location to our own
srcdir = File.join(spec.gem_dir, 'ext')
puts "Moving extension binaries from #{srcdir}"
Dir[File.join(srcdir, '*')].each do |extpath|
FileUtils.mv(extpath, 'ext', :force => true)
end
ensure
# uninstall extension binaries gem
puts "Uninstalling extension binaries gem: r2corba_ext#{RB_VER_MAJOR}#{RB_VER_MINOR}-#{R2CORBA::R2CORBA_VERSION}."
Gem::Uninstaller.new("r2corba_ext#{RB_VER_MAJOR}#{RB_VER_MINOR}", :version => R2CORBA::R2CORBA_VERSION.dup).uninstall
end
rescue
puts "Failed to install binary r2corba_ext#{RB_VER_MAJOR}#{RB_VER_MINOR} v. #{R2CORBA::R2CORBA_VERSION} gem for #{RUBY_PLATFORM}."
puts "#{$!}\n#{$!.backtrace.join('\n')}"
exit(1)
end
end
puts 'Running rake -- configure --without-tao'
unless system('rake -- configure --without-tao')
puts 'Failed to configure R2CORBA.'
exit(1)
end
end