Skip to content

Commit f04d50c

Browse files
authored
Merge pull request #7242 from rubygems/improve-default-gem-handling
Improve default gem handling by treating default gems as any other gem
2 parents b9e8504 + 091b4fc commit f04d50c

File tree

7 files changed

+20
-36
lines changed

7 files changed

+20
-36
lines changed

bundler/lib/bundler/cli/common.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def self.select_spec(name, regex_match = nil)
5757
specs << spec if regexp && spec.name =~ regexp
5858
end
5959

60+
default_spec = default_gem_spec(name)
61+
specs << default_spec if default_spec
62+
6063
case specs.count
6164
when 0
6265
dep_in_other_group = Bundler.definition.current_dependencies.find {|dep|dep.name == name }
@@ -75,6 +78,12 @@ def self.select_spec(name, regex_match = nil)
7578
raise GemNotFound, gem_not_found_message(name, Bundler.definition.dependencies)
7679
end
7780

81+
def self.default_gem_spec(name)
82+
return unless Gem::Specification.respond_to?(:find_all_by_name)
83+
gem_spec = Gem::Specification.find_all_by_name(name).last
84+
gem_spec if gem_spec&.default_gem?
85+
end
86+
7887
def self.ask_for_spec_from(specs)
7988
specs.each_with_index do |spec, index|
8089
Bundler.ui.info "#{index.succ} : #{spec.name}", true

bundler/lib/bundler/cli/info.rb

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,8 @@ def run
2525

2626
private
2727

28-
def spec_for_gem(gem_name)
29-
spec = Bundler.definition.specs.find {|s| s.name == gem_name }
30-
spec || default_gem_spec(gem_name) || Bundler::CLI::Common.select_spec(gem_name, :regex_match)
31-
end
32-
33-
def default_gem_spec(gem_name)
34-
return unless Gem::Specification.respond_to?(:find_all_by_name)
35-
gem_spec = Gem::Specification.find_all_by_name(gem_name).last
36-
gem_spec if gem_spec&.default_gem?
37-
end
38-
39-
def spec_not_found(gem_name)
40-
raise GemNotFound, Bundler::CLI::Common.gem_not_found_message(gem_name, Bundler.definition.dependencies)
28+
def spec_for_gem(name)
29+
Bundler::CLI::Common.select_spec(name, :regex_match)
4130
end
4231

4332
def print_gem_version(spec)

bundler/lib/bundler/rubygems_integration.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ def path_separator
509509
end
510510

511511
def all_specs
512-
Gem::Specification.stubs.map do |stub|
512+
Gem::Specification.stubs.reject(&:default_gem?).map do |stub|
513513
StubSpecification.from_stub(stub)
514514
end
515515
end

bundler/lib/bundler/source/rubygems.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,7 @@ def cached_built_in_gem(spec)
225225
cached_path = cached_path(spec)
226226
if cached_path.nil?
227227
remote_spec = remote_specs.search(spec).first
228-
if remote_spec
229-
cached_path = fetch_gem(remote_spec)
230-
else
231-
Bundler.ui.warn "#{spec.full_name} is built in to Ruby, and can't be cached because your Gemfile doesn't have any sources that contain it."
232-
end
228+
cached_path = fetch_gem(remote_spec)
233229
end
234230
cached_path
235231
end

bundler/spec/cache/gems_spec.rb

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@
102102

103103
it "uses builtin gems when installing to system gems" do
104104
bundle "config set path.system true"
105-
install_gemfile %(source "#{file_uri_for(gem_repo1)}"; gem 'json', '#{default_json_version}'), verbose: true
106-
expect(out).to include("Using json #{default_json_version}")
105+
install_gemfile %(source "#{file_uri_for(gem_repo2)}"; gem 'json', '#{default_json_version}'), verbose: true
106+
expect(out).to include("Installing json #{default_json_version}")
107107
end
108108

109109
it "caches remote and builtin gems" do
@@ -143,19 +143,6 @@
143143
bundle "install --local"
144144
expect(the_bundle).to include_gems("builtin_gem_2 1.0.2")
145145
end
146-
147-
it "errors if the builtin gem isn't available to cache" do
148-
bundle "config set path.system true"
149-
150-
install_gemfile <<-G
151-
source "#{file_uri_for(gem_repo1)}"
152-
gem 'json', '#{default_json_version}'
153-
G
154-
155-
bundle :cache, raise_on_error: false
156-
expect(exitstatus).to_not eq(0)
157-
expect(err).to include("json-#{default_json_version} is built in to Ruby, and can't be cached")
158-
end
159146
end
160147

161148
describe "when there are also git sources" do

bundler/spec/commands/open_spec.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@
164164

165165
install_gemfile <<-G
166166
source "#{file_uri_for(gem_repo1)}"
167-
gem "json"
168167
G
169168
end
170169

bundler/spec/runtime/setup_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,10 @@ def lock_with(ruby_version = nil)
12811281

12821282
describe "with gemified standard libraries" do
12831283
it "does not load Digest", :ruby_repo do
1284+
build_repo2 do
1285+
build_gem "digest"
1286+
end
1287+
12841288
build_git "bar", gemspec: false do |s|
12851289
s.write "lib/bar/version.rb", %(BAR_VERSION = '1.0')
12861290
s.write "bar.gemspec", <<-G
@@ -1299,7 +1303,7 @@ def lock_with(ruby_version = nil)
12991303
end
13001304

13011305
gemfile <<-G
1302-
source "#{file_uri_for(gem_repo1)}"
1306+
source "#{file_uri_for(gem_repo2)}"
13031307
gem "bar", :git => "#{lib_path("bar-1.0")}"
13041308
G
13051309

0 commit comments

Comments
 (0)