Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/rubygems/specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,12 @@ def self.find_by_name(name, *requirements)
Gem::Dependency.new(name, *requirements).to_spec
end

##
# Find the best specification matching a +full_name+.
def self.find_by_full_name(full_name)
stubs.find {|s| s.full_name == full_name }&.to_spec
end

##
# Return the best specification that contains the file matching +path+.

Expand Down Expand Up @@ -1606,6 +1612,8 @@ def build_args
def build_extensions # :nodoc:
return if extensions.empty?
return if default_gem?
# we need to fresh build when same name and version of default gems
return if self.class.find_by_full_name(full_name)&.default_gem?
return if File.exist? gem_build_complete_path
return if !File.writable?(base_dir)
return if !File.exist?(File.join(base_dir, "extensions"))
Expand Down
17 changes: 17 additions & 0 deletions test/rubygems/test_gem_specification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3726,6 +3726,23 @@ def test_find_by_name_prerelease
assert Gem::Specification.find_by_name "b", ">1"
end

def test_find_by_full_name
pl = Gem::Platform.new "x86_64-linux"

a = util_spec "a", "1"
install_specs a

a_pl = util_spec("a", "1") {|s| s.platform = pl }
install_specs a_pl

assert_equal a, Gem::Specification.find_by_full_name("a-1")
assert_equal a_pl, Gem::Specification.find_by_full_name("a-1-x86_64-linux")

assert_nil Gem::Specification.find_by_full_name("a-2")
assert_nil Gem::Specification.find_by_full_name("b-1")
assert_nil Gem::Specification.find_by_full_name("a-1-arm64-linux")
end

def test_find_by_path
a = util_spec "foo", "1", nil, "lib/foo.rb"

Expand Down