summaryrefslogtreecommitdiff
path: root/lib/rubygems/platform.rb
diff options
context:
space:
mode:
authorDavid Rodríguez <[email protected]>2022-08-04 13:02:18 +0200
committergit <[email protected]>2022-08-23 05:50:21 +0900
commit9819283044b6955f4e3b464e6a99196e84ed107a (patch)
tree72b22031a41969d4bccd3f4a199735829b86620b /lib/rubygems/platform.rb
parentf254b673f89c12c42538d84b431116cf5ed0cde7 (diff)
[rubygems/rubygems] Handle non-gnu libc on linux platforms in RubyGems
Attempting to install a gem published as both *-linux and *-linux-musl results in the incorrect gem being picked up, causing build failures due to binary incompatibility. This is caused by the `nil` wildcard swallowing the libc information upon version comparison. Handle the linux case by performing only non-wildcard equality on the version and asserting 'gnu' and nil equivalence, while preserving the current behaviour for other OSes. https://github.com/rubygems/rubygems/commit/9eead86abc Co-authored-by: Loic Nageleisen <[email protected]>
Diffstat (limited to 'lib/rubygems/platform.rb')
-rw-r--r--lib/rubygems/platform.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb
index 0c0520e1db..1f699c23e0 100644
--- a/lib/rubygems/platform.rb
+++ b/lib/rubygems/platform.rb
@@ -151,10 +151,17 @@ class Gem::Platform
##
# Does +other+ match this platform? Two platforms match if they have the
# same CPU, or either has a CPU of 'universal', they have the same OS, and
- # they have the same version, or either has no version.
+ # they have the same version, or either one has no version
#
# Additionally, the platform will match if the local CPU is 'arm' and the
# other CPU starts with "arm" (for generic ARM family support).
+ #
+ # Of note, this method is not commutative. Indeed the OS 'linux' has a
+ # special case: the version is the libc name, yet while "no version" stands
+ # as a wildcard for a binary gem platform (as for other OSes), for the
+ # runtime platform "no version" stands for 'gnu'. To be able to disinguish
+ # these, the method receiver is the gem platform, while the argument is
+ # the runtime platform.
def ===(other)
return nil unless Gem::Platform === other
@@ -171,7 +178,11 @@ class Gem::Platform
@os == other.os &&
# version
- (@version.nil? || other.version.nil? || @version == other.version)
+ (
+ (@os != "linux" && (@version.nil? || other.version.nil?)) ||
+ (@os == "linux" && (@version.nil? && !other.version.nil?)) ||
+ @version == other.version
+ )
end
##