Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

[scripts] use RUBY_PLATFORM instead of RbConfig to check platform details for Javy installation #1853

Merged
merged 2 commits into from
Dec 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 7 additions & 8 deletions ext/javy/javy.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require "rbconfig"
require "open-uri"
require "zlib"
require "open3"
Expand Down Expand Up @@ -162,17 +161,17 @@ def validate_sha!(source)
end
end

Platform = Struct.new(:ruby_config) do
def initialize(ruby_config = RbConfig::CONFIG)
super(ruby_config)
Platform = Struct.new(:ruby_platform) do
def initialize(ruby_platform = RUBY_PLATFORM)
super(ruby_platform)
end

def to_s
format("%{cpu}-%{os}", cpu: cpu, os: os)
end

def os
case ruby_config.fetch("host_os")
case ruby_platform
when /linux/
"linux"
when /darwin/
Expand All @@ -183,10 +182,10 @@ def os
end

def cpu
case ruby_config.fetch("host_cpu")
when "x64", "x86_64"
case ruby_platform
when /x64/, /x86_64/
"x86_64"
when "arm"
when /arm/
"arm"
else
raise InstallationError.cpu_unsupported
Expand Down
15 changes: 11 additions & 4 deletions test/ext/javy/javy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ def test_recognizes_mac_os_arm
assert_equal "javy", platform.format_executable_path("javy")
end

def test_recognizes_underlying_cpu_in_universal_distributions
platform = Javy::Platform.new(PlatformHelper.macos_universal_config)
assert_equal "arm-macos", platform.to_s
assert_equal "javy", platform.format_executable_path("javy")
end

def test_recognizes_windows
platform = Javy::Platform.new(PlatformHelper.windows_config)
assert_equal "x86_64-windows", platform.to_s
Expand Down Expand Up @@ -220,6 +226,10 @@ def self.macos_arm_config
ruby_config(os: "darwin20.3.0", cpu: "arm")
end

def self.macos_universal_config
ruby_config(os: "darwin20.3.0", cpu: "universal.arm64")
end

def self.windows_config
ruby_config(os: "mingw32", cpu: "x64")
end
Expand All @@ -229,10 +239,7 @@ def self.windows_32_bit_config
end

def self.ruby_config(os:, cpu:)
{
"host_os" => os,
"host_cpu" => cpu,
}
"#{cpu}-#{os}"
end
end
end