Skip to content

Commit ad2850b

Browse files
ClareCatkigster
authored andcommitted
Add force_gem_pristine attr to rb_binary (#11)
* Add gem pristine functionality to unblock gems * Run buildifier, move ruby attrs
1 parent 08847a2 commit ad2850b

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

ruby/private/binary.bzl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ def ruby_binary_macro(ctx, main, srcs):
5454

5555
gem_path = _get_gem_path(deps.incpaths.to_list())
5656

57+
gems_to_pristine = ctx.attr.force_gem_pristine
58+
5759
rubyopt = reversed(deps.rubyopt.to_list())
5860

5961
ctx.actions.expand_template(
@@ -65,6 +67,8 @@ def ruby_binary_macro(ctx, main, srcs):
6567
"{main}": repr(_to_manifest_path(ctx, main)),
6668
"{interpreter}": _to_manifest_path(ctx, interpreter),
6769
"{gem_path}": gem_path,
70+
"{should_gem_pristine}": str(len(gems_to_pristine) > 0).lower(),
71+
"{gems_to_pristine}": " ".join(gems_to_pristine),
6872
},
6973
)
7074

ruby/private/binary_wrapper.tpl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,13 @@ def find_ruby_binary
9191
)
9292
end
9393

94+
def find_gem_binary
95+
File.join(
96+
RbConfig::CONFIG['bindir'],
97+
'gem',
98+
)
99+
end
100+
94101
def main(args)
95102
custom_loadpaths = {loadpaths}
96103
runfiles = find_runfiles
@@ -104,6 +111,7 @@ def main(args)
104111
ENV[runfiles_envkey] = runfiles_envvalue if runfiles_envkey
105112

106113
ENV["GEM_PATH"] = File.join(runfiles, "{gem_path}") if "{gem_path}"
114+
ENV["GEM_HOME"] = File.join(runfiles, "{gem_path}") if "{gem_path}"
107115

108116
ruby_program = find_ruby_binary
109117

@@ -119,6 +127,17 @@ def main(args)
119127
end
120128
end
121129
end
130+
131+
# This is a jank hack because some of our gems are having issues with how
132+
# they are being installed. Most gems are fine, but this fixes the ones that
133+
# aren't. Put it here instead of in the library because we want to fix the
134+
# underlying issue and then tear this out.
135+
if {should_gem_pristine} then
136+
gem_program = find_gem_binary
137+
puts "Running pristine on {gems_to_pristine}"
138+
system(gem_program + " pristine {gems_to_pristine}")
139+
end
140+
122141
exec(ruby_program, *rubyopt, main, *args)
123142
# TODO(yugui) Support windows
124143
end

ruby/private/bundle/create_bundle_build_file.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@
3333
name = "{name}",
3434
srcs = glob(
3535
include = [
36+
<<<<<<< HEAD
3637
".bundle/config",
3738
"{gem_lib_files}",
3839
"lib/ruby/{ruby_version}/specifications/{name}-{version}.gemspec",
3940
{gem_binaries}
41+
=======
42+
"lib/ruby/{ruby_version}/gems/{name}-{version}*/**",
43+
"lib/ruby/{ruby_version}/specifications/{name}-{version}*.gemspec",
44+
"lib/ruby/{ruby_version}/cache/{name}-{version}*.gem",
45+
"bin/*"
46+
>>>>>>> eeab881... Add force_gem_pristine attr to rb_binary (#11)
4047
],
4148
exclude = {exclude},
4249
),

ruby/private/constants.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ RUBY_ATTRS = {
3030
"main": attr.label(
3131
allow_single_file = True,
3232
),
33+
"force_gem_pristine": attr.string_list(
34+
doc = "Jank hack. Run gem pristine on some gems that don't handle symlinks well",
35+
),
3336
"_wrapper_template": attr.label(
3437
allow_single_file = True,
3538
default = "binary_wrapper.tpl",

0 commit comments

Comments
 (0)