Skip to content

Commit

Permalink
Fix standalone install of default gems
Browse files Browse the repository at this point in the history
Rubygems source replacement was broken.
  • Loading branch information
deivid-rodriguez committed Jul 28, 2021
1 parent 2b8dcab commit 3549c12
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
1 change: 1 addition & 0 deletions bundler/lib/bundler/lockfile_parser.rb
Expand Up @@ -195,6 +195,7 @@ def parse_spec(line)
platform = platform ? Gem::Platform.new(platform) : Gem::Platform::RUBY
@current_spec = LazySpecification.new(name, version, platform)
@current_spec.source = @current_source
@current_source.add_dependency_names(name)

@specs[@current_spec.identifier] = @current_spec
elsif spaces.size == 6
Expand Down
13 changes: 11 additions & 2 deletions bundler/lib/bundler/source_list.rb
Expand Up @@ -121,7 +121,8 @@ def lock_rubygems_sources
def replace_sources!(replacement_sources)
return false if replacement_sources.empty?

@path_sources, @git_sources, @plugin_sources = map_sources(replacement_sources)
@rubygems_sources, @path_sources, @git_sources, @plugin_sources = map_sources(replacement_sources)
@global_rubygems_source = global_replacement_source(replacement_sources)

different_sources?(lock_sources, replacement_sources)
end
Expand Down Expand Up @@ -156,13 +157,21 @@ def dup_with_replaced_sources(replacement_sources)
end

def map_sources(replacement_sources)
[path_sources, git_sources, plugin_sources].map do |sources|
[@rubygems_sources, @path_sources, @git_sources, @plugin_sources].map do |sources|
sources.map do |source|
replacement_sources.find {|s| s == source } || source
end
end
end

def global_replacement_source(replacement_sources)
replacement_source = replacement_sources.find {|s| s == global_rubygems_source }
return global_rubygems_source unless replacement_source

replacement_source.local!
replacement_source
end

def different_sources?(lock_sources, replacement_sources)
!equal_sources?(lock_sources, replacement_sources) && !equivalent_sources?(lock_sources, replacement_sources)
end
Expand Down
39 changes: 39 additions & 0 deletions bundler/spec/install/gems/standalone_spec.rb
Expand Up @@ -108,6 +108,45 @@
include_examples "common functionality"
end

describe "with default gems and a lockfile", :ruby_repo do
before do
skip "does not work on rubygems versions where `--install_dir` doesn't respect --default" unless Gem::Installer.for_spec(loaded_gemspec, :install_dir => "/foo").default_spec_file == "/foo/specifications/default/bundler-#{Bundler::VERSION}.gemspec" # Since rubygems 3.2.0.rc.2
skip "does not work on old rubies because the realworld gems that need to be installed don't support them" if RUBY_VERSION < "2.7.0"

realworld_system_gems "fiddle --version 1.0.6", "tsort --version 0.1.0"

necessary_system_gems = ["optparse --version 0.1.1", "psych --version 3.3.2", "yaml --version 0.1.1", "logger --version 1.4.3", "etc --version 1.2.0"]
necessary_system_gems += ["shellwords --version 0.1.0", "base64 --version 0.1.0", "resolv --version 0.2.1"] if Gem.rubygems_version < Gem::Version.new("3.3.3.a")
realworld_system_gems(*necessary_system_gems, :path => scoped_gem_path(bundled_app("bundle")))

build_gem "foo", "1.0.0", :to_system => true, :default => true do |s|
s.add_dependency "bar"
end

build_gem "bar", "1.0.0", :to_system => true, :default => true

build_repo4 do
build_gem "foo", "1.0.0" do |s|
s.add_dependency "bar"
end

build_gem "bar", "1.0.0"
end

gemfile <<-G
source "https://gem.repo4"
gem "foo"
G

bundle "lock", :dir => cwd, :artifice => "compact_index"
end

it "works" do
bundle "config set --local path #{bundled_app("bundle")}"
bundle :install, :standalone => true, :dir => cwd, :artifice => "compact_index", :env => { "BUNDLER_GEM_DEFAULT_DIR" => system_gem_path.to_s }
end
end

describe "with gems with native extension", :ruby_repo do
before do
bundle "config set --local path #{bundled_app("bundle")}"
Expand Down

0 comments on commit 3549c12

Please sign in to comment.