diff options
author | Mat Sadler <mat@sourcetagsandcodes.com> | 2023-01-22 22:46:22 -0800 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2023-01-30 17:39:47 +0000 |
commit | b4defea362278a38a4f7c86a86c5c44fff173e8b (patch) | |
tree | 659ea08fcc52d625f29792dbaf5205213f4b6456 /lib/rubygems | |
parent | ca951f671920b64c8275ffccdc680848f60cbede (diff) |
[rubygems/rubygems] install rust extensions into expected directory nesting
https://github.com/rubygems/rubygems/commit/85ea86d348
Diffstat (limited to 'lib/rubygems')
-rw-r--r-- | lib/rubygems/ext/cargo_builder.rb | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/lib/rubygems/ext/cargo_builder.rb b/lib/rubygems/ext/cargo_builder.rb index 7c1d4a72cd..2a9e72fdfe 100644 --- a/lib/rubygems/ext/cargo_builder.rb +++ b/lib/rubygems/ext/cargo_builder.rb @@ -14,7 +14,7 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder @profile = :release end - def build(_extension, dest_path, results, args = [], lib_dir = nil, cargo_dir = Dir.pwd) + def build(extension, dest_path, results, args = [], lib_dir = nil, cargo_dir = Dir.pwd) require "tempfile" require "fileutils" @@ -43,16 +43,19 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder dlext_path = File.join(File.dirname(dylib_path), dlext_name) FileUtils.cp(dylib_path, dlext_path) + nesting = extension_nesting(extension) + # TODO: remove in RubyGems 4 if Gem.install_extension_in_lib && lib_dir - FileUtils.mkdir_p lib_dir - p [dlext_path, lib_dir] - FileUtils.cp_r dlext_path, lib_dir, remove_destination: true + nested_lib_dir = File.join(lib_dir, nesting) + FileUtils.mkdir_p nested_lib_dir + FileUtils.cp_r dlext_path, nested_lib_dir, remove_destination: true end # move to final destination - FileUtils.mkdir_p dest_path - FileUtils.cp_r dlext_path, dest_path, remove_destination: true + nested_dest_path = File.join(dest_path, nesting) + FileUtils.mkdir_p nested_dest_path + FileUtils.cp_r dlext_path, nested_dest_path, remove_destination: true ensure # clean up intermediary build artifacts FileUtils.rm_rf tmp_dest if tmp_dest @@ -94,6 +97,23 @@ class Gem::Ext::CargoBuilder < Gem::Ext::Builder ENV.fetch("CARGO", "cargo") end + # returns the directory nesting of the extension, ignoring the first part, so + # "ext/foo/bar/Cargo.toml" becomes "foo/bar" + def extension_nesting(extension) + parts = extension.to_s.split(Regexp.union([File::SEPARATOR, File::ALT_SEPARATOR].compact)) + + parts = parts.each_with_object([]) do |segment, final| + next if segment == "." + if segment == ".." + raise Gem::InstallError, "extension outside of gem root" if final.empty? + next final.pop + end + final << segment + end + + File.join(parts[1...-1]) + end + def rb_config_env result = {} RbConfig::CONFIG.each {|k, v| result["RBCONFIG_#{k}"] = v } |