Skip to content

Commit aaa7949

Browse files
authored
Handle absolute paths in required_paths
1 parent cc2f5ce commit aaa7949

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ruby/private/bundle/create_bundle_build_file.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
Dir.glob("lib/#{RbConfig::CONFIG['RUBY_INSTALL_NAME']}/#{ruby_version}/specifications/#{gem_name}-#{gem_version}*.gemspec").first
8585
end
8686

87+
HERE = File.absolute_path '.'
88+
8789
require 'bundler'
8890
require 'json'
8991
require 'stringio'
@@ -271,7 +273,15 @@ def register_gem(spec, template_out, bundle_lib_paths, bundle_binaries)
271273
# Usually, registering the directory paths listed in the `require_paths` of gemspecs is sufficient, but
272274
# some gems also require additional paths to be included in the load paths.
273275
require_paths += include_array(spec.name)
274-
gem_lib_paths = require_paths.map { |require_path| File.join(gem_path, require_path) }
276+
gem_lib_paths = require_paths.map do |require_path|
277+
# Gems with native extensions (like ffi) will sometimes have elements of
278+
# require_paths that are absolute rather than gem-path relative paths.
279+
# It is incorrect to prepend those paths with the gem_path and Bazel will
280+
# only allow relative paths as inputs to its glob() function.
281+
pathname = Pathname.new(require_path)
282+
pathname.absolute? ? pathname.relative_path_from(HERE).to_s : File.join(gem_path, require_path)
283+
end
284+
275285
bundle_lib_paths.push(*gem_lib_paths)
276286

277287
# paths to search for executables

0 commit comments

Comments
 (0)