-
Notifications
You must be signed in to change notification settings - Fork 145
/
pl-ruby-patch.rb
56 lines (50 loc) · 2.16 KB
/
pl-ruby-patch.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
# This component patches the pl-ruby package on cross compiled
# platforms. Ruby gem components should require this.
#
# We have to do this when installing gems with native extensions in
# order to trick rubygems into thinking we have a different ruby
# version and target architecture
#
# This component should also be present in the puppet-runtime project
component "pl-ruby-patch" do |pkg, settings, platform|
if platform.is_cross_compiled?
if platform.is_macos?
pkg.build_requires 'gnu-sed'
pkg.environment "PATH", "/usr/local/opt/gnu-sed/libexec/gnubin:$(PATH)"
end
ruby_api_version = settings[:ruby_version].gsub(/\.\d*$/, '.0')
ruby_version_y = settings[:ruby_version].gsub(/(\d+)\.(\d+)\.(\d+)/, '\1.\2')
base_ruby = if platform.name =~ /osx/
"/usr/local/opt/ruby@#{ruby_version_y}/lib/ruby/#{ruby_api_version}"
else
"/opt/pl-build-tools/lib/ruby/2.1.0"
end
target_triple = if platform.architecture =~ /ppc64el|ppc64le/
"powerpc64le-linux"
elsif platform.name == 'solaris-11-sparc'
"sparc-solaris-2.11"
elsif platform.is_macos?
"aarch64-darwin"
else
"#{platform.architecture}-linux"
end
pkg.build do
[
%(#{platform[:sed]} -i 's/Gem::Platform.local.to_s/"#{target_triple}"/' #{base_ruby}/rubygems/basic_specification.rb),
%(#{platform[:sed]} -i 's/Gem.extension_api_version/"#{ruby_api_version}"/' #{base_ruby}/rubygems/basic_specification.rb)
]
end
# make rubygems use our target rbconfig when installing gems
case File.basename(base_ruby)
when '2.0.0', '2.1.0'
sed_command = %(s|Gem.ruby|&, '-r/opt/puppetlabs/puppet/share/doc/rbconfig-#{settings[:ruby_version]}-orig.rb'|)
else
sed_command = %(s|Gem.ruby.shellsplit|& << '-r/opt/puppetlabs/puppet/share/doc/rbconfig-#{settings[:ruby_version]}-orig.rb'|)
end
pkg.build do
[
%(#{platform[:sed]} -i "#{sed_command}" #{base_ruby}/rubygems/ext/ext_conf_builder.rb)
]
end
end
end