Skip to content

Commit

Permalink
Fix matching of linux platforms with eabi modifiers
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Dalessio <mike.dalessio@gmail.com>
  • Loading branch information
deivid-rodriguez and flavorjones committed Sep 29, 2022
1 parent 4075771 commit 89362c1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
8 changes: 4 additions & 4 deletions bundler/lib/bundler/rubygems_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def ===(other)
# version
(
(@os != "linux" && (@version.nil? || other.version.nil?)) ||
(@os == "linux" && (normalized_linux_version_ext == other.normalized_linux_version_ext || other.version == "musl#{@version}")) ||
(@os == "linux" && (normalized_linux_version_ext == other.normalized_linux_version_ext || other.version == "musl#{@version}" || other.version == "musleabi#{@version}")) ||
@version == other.version
)
end
Expand All @@ -271,10 +271,10 @@ def ===(other)
def normalized_linux_version_ext
return nil unless @version

without_gnu = @version.sub(/\Agnu/, "")
return nil if without_gnu.empty?
without_gnu_nor_abi_modifiers = @version.sub(/\Agnu/, "").sub(/eabi\Z/, "")
return nil if without_gnu_nor_abi_modifiers.empty?

without_gnu
without_gnu_nor_abi_modifiers
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/rubygems/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,18 @@ def ===(other)
# version
(
(@os != "linux" && (@version.nil? || other.version.nil?)) ||
(@os == "linux" && (normalized_linux_version == other.normalized_linux_version || other.version == "musl#{@version}")) ||
(@os == "linux" && (normalized_linux_version == other.normalized_linux_version || other.version == "musl#{@version}" || other.version == "musleabi#{@version}")) ||
@version == other.version
)
end

def normalized_linux_version
return nil unless @version

without_gnu = @version.sub(/\Agnu/, "")
return nil if without_gnu.empty?
without_gnu_nor_abi_modifiers = @version.sub(/\Agnu/, "").sub(/eabi\Z/, "")
return nil if without_gnu_nor_abi_modifiers.empty?

without_gnu
without_gnu_nor_abi_modifiers
end

##
Expand Down
20 changes: 20 additions & 0 deletions test/rubygems/test_gem_platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,26 @@ def test_eabi_version_is_stricter_for_linux_os
refute(arm_linux_uclibceabi === arm_linux_eabi, "linux-uclibceabi =~ linux-eabi")
end

def test_eabi_and_nil_version_combination_strictness
arm_linux = Gem::Platform.new "arm-linux"
arm_linux_eabi = Gem::Platform.new "arm-linux-eabi"
arm_linux_gnueabi = Gem::Platform.new "arm-linux-gnueabi"
arm_linux_musleabi = Gem::Platform.new "arm-linux-musleabi"
arm_linux_uclibceabi = Gem::Platform.new "arm-linux-uclibceabi"

# generic arm host runtime with eabi modifier accepts generic arm gems
assert(arm_linux === arm_linux_eabi, "arm-linux =~ arm-linux-eabi")

# explicit gnu arm host runtime with eabi modifier accepts generic arm gems
assert(arm_linux === arm_linux_gnueabi, "arm-linux =~ arm-linux-gnueabi")

# musl arm host runtime accepts libc-generic or statically linked gems...
assert(arm_linux === arm_linux_musleabi, "arm-linux =~ arm-linux-musleabi")

# other libc arm hosts are not glibc compatible
refute(arm_linux === arm_linux_uclibceabi, "arm-linux =~ arm-linux-uclibceabi")
end

def test_equals3_cpu_arm
arm = Gem::Platform.new "arm-linux"
armv5 = Gem::Platform.new "armv5-linux"
Expand Down

0 comments on commit 89362c1

Please sign in to comment.