Skip to content

Commit

Permalink
Auto merge of #1683 - coderanger:nativeuser, r=segiddins
Browse files Browse the repository at this point in the history
Set loaded_from before using extension_dir to ensure it is correct for --user or other alternate install path modes

Fixes #1680

Not 100% sure the best way to write a test for this.

I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).
  • Loading branch information
homu committed Aug 11, 2016
2 parents a313546 + adb2f5c commit 4320056
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/rubygems/installer.rb
Expand Up @@ -282,18 +282,23 @@ def install

run_pre_install_hooks

# Set loaded_from to ensure extension_dir is correct
if @options[:install_as_default] then
spec.loaded_from = default_spec_file
else
spec.loaded_from = spec_file
end

# Completely remove any previous gem files
FileUtils.rm_rf gem_dir
FileUtils.rm_rf spec.extension_dir

FileUtils.mkdir_p gem_dir

if @options[:install_as_default]
spec.loaded_from = default_spec_file
if @options[:install_as_default] then
extract_bin
write_default_spec
else
spec.loaded_from = spec_file
extract_files

build_extensions
Expand Down
29 changes: 29 additions & 0 deletions test/rubygems/test_gem_installer.rb
Expand Up @@ -1141,6 +1141,35 @@ def test_install_extension_dir_is_removed_on_reinstall
refute_path_exists should_be_removed
end

def test_install_user_extension_dir
@spec.extensions << "extconf.rb"
write_file File.join(@tempdir, "extconf.rb") do |io|
io.write <<-RUBY
require "mkmf"
create_makefile("#{@spec.name}")
RUBY
end

@spec.files += %w[extconf.rb]

# Create the non-user ext dir
expected_extension_dir = @spec.extension_dir.dup
FileUtils.mkdir_p expected_extension_dir

use_ui @ui do
path = Gem::Package.build @spec

installer = Gem::Installer.at path, :user_install => true
installer.install
end

expected_makefile = File.join Gem.user_dir, 'gems', @spec.full_name, 'Makefile'

assert_path_exists expected_makefile
assert_path_exists expected_extension_dir
refute_path_exists File.join expected_extension_dir, 'gem_make.out'
end

# ruby core repository needs to `depend` file for extension build.
# but 1.9.2 and earlier mkmf.rb does not create TOUCH file like depend.
if RUBY_VERSION < '1.9.3'
Expand Down

0 comments on commit 4320056

Please sign in to comment.