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

Commit

Permalink
Merge pull request #1843 from Shopify/javy-arm64
Browse files Browse the repository at this point in the history
Support running javy on arm
  • Loading branch information
jacobsteves authored Dec 13, 2021
2 parents a18aa65 + 4a85ea0 commit eb2b04a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ From version 2.6.0, the sections in this file adhere to the [keep a changelog](h
## [Unreleased]
### Added
* [#1826](https://github.com/Shopify/shopify-cli/pull/1826): Support using `script.config.yml` file for script configuration
* [#1843](https://github.com/Shopify/shopify-cli/pull/1826): Support using javy on Apple ARM processors

### Fixed
* [#1811](https://github.com/Shopify/shopify-cli/pull/1811): Update theme-check to 1.9.0
Expand Down
1 change: 1 addition & 0 deletions ext/javy/hashes/javy-arm-macos-v0.1.0.gz.sha256
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
16e1a74c06eff6e5be79253a8ee96a08a404e95be3479a6e384c8926bb736e43
2 changes: 2 additions & 0 deletions ext/javy/javy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ def cpu
case ruby_config.fetch("host_cpu")
when "x64", "x86_64"
"x86_64"
when "arm"
"arm"
else
raise InstallationError.cpu_unsupported
end
Expand Down
49 changes: 36 additions & 13 deletions test/ext/javy/javy_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,40 @@ def setup

def test_install_existing_version_for_mac_os
stub_executable_download
stub_platform(PlatformHelper.macos_x64_config)

assert_kind_of(ShopifyCLI::Result::Success, install(PlatformHelper.macos_config))
assert_kind_of(ShopifyCLI::Result::Success, Javy.install)

assert File.file?(Javy::TARGET)
assert File.executable?(Javy::TARGET)
end

def test_install_existing_version_for_windows
stub_executable_download
stub_platform(PlatformHelper.windows_config)

expected_target = Javy::TARGET + ".exe"
assert_kind_of(ShopifyCLI::Result::Success, install(PlatformHelper.windows_config))
assert_kind_of(ShopifyCLI::Result::Success, Javy.install)

assert File.file?(expected_target)
assert File.executable?(expected_target)
end

def test_install_existing_version_for_linux
stub_executable_download
stub_platform(PlatformHelper.linux_config)

assert_kind_of(ShopifyCLI::Result::Success, install(PlatformHelper.linux_config))
assert_kind_of(ShopifyCLI::Result::Success, Javy.install)

assert File.file?(Javy::TARGET)
assert File.executable?(Javy::TARGET)
end

def test_install_raises_for_http_errors_during_asset_download
simulate_broken_asset_link
stub_platform(PlatformHelper.macos_x64_config)

result = install(PlatformHelper.macos_config)
result = Javy.install
assert_kind_of(ShopifyCLI::Result::Failure, result)
assert_kind_of(Javy::InstallationError, result.error)
assert_match("Unable to download javy", result.error.message)
Expand All @@ -58,7 +62,9 @@ def test_install_raises_for_http_errors_during_asset_download

def test_install_raises_when_binary_hash_is_unexpected
stub_executable_download(executable_sha: "invalid")
result = install(PlatformHelper.macos_config)
stub_platform(PlatformHelper.macos_x64_config)

result = Javy.install
assert_kind_of(ShopifyCLI::Result::Failure, result)
assert_kind_of(Javy::InstallationError, result.error)
assert_match("Invalid Javy binary downloaded", result.error.message)
Expand All @@ -67,32 +73,36 @@ def test_install_raises_when_binary_hash_is_unexpected

def test_install_strips_whitespace_when_comparing_shas
stub_executable_download(executable_sha: "#{DUMMY_ARCHIVE_SHA256} \n")
assert_kind_of(ShopifyCLI::Result::Success, install(PlatformHelper.macos_config))
stub_platform(PlatformHelper.macos_x64_config)

assert_kind_of(ShopifyCLI::Result::Success, Javy.install)

assert File.file?(Javy::TARGET)
assert File.executable?(Javy::TARGET)
end

def test_build_runs_javy_command_on_unix
stub_executable_download
install(PlatformHelper.macos_config)
stub_platform(PlatformHelper.macos_x64_config)
Javy.install
run_build_and_expect_execution
end

def test_build_runs_javy_command_on_windows
stub_executable_download
install(PlatformHelper.windows_config)
stub_platform(PlatformHelper.windows_config)
run_build_and_expect_execution(target: Javy::TARGET + ".exe")
end

def test_build_accepts_optional_dest_argument
stub_executable_download
install(PlatformHelper.macos_config)
stub_platform(PlatformHelper.macos_x64_config)
run_build_and_expect_execution(dest: nil)
end

def test_build_installs_javy_by_default
stub_executable_download
stub_platform(PlatformHelper.macos_x64_config)

refute File.file?(Javy::TARGET)
refute File.executable?(Javy::TARGET)
Expand All @@ -104,6 +114,8 @@ def test_build_installs_javy_by_default
end

def test_build_deletes_outdated_javy_installations_and_installs_new_one
stub_platform(PlatformHelper.macos_x64_config)

outdated_javy_target = File.join(Javy::BIN_FOLDER, "javy-0.0.0")
File.write(outdated_javy_target, "foo")

Expand All @@ -116,6 +128,8 @@ def test_build_deletes_outdated_javy_installations_and_installs_new_one
end

def test_build_does_not_reinstall_an_ok_javy_version
stub_platform(PlatformHelper.macos_x64_config)

File.write(Javy::TARGET, "")
File.chmod(0755, Javy::TARGET)
run_build_and_expect_execution
Expand All @@ -129,11 +143,17 @@ def test_recognizes_linux
end

def test_recognizes_mac_os
platform = Javy::Platform.new(PlatformHelper.macos_config)
platform = Javy::Platform.new(PlatformHelper.macos_x64_config)
assert_equal "x86_64-macos", platform.to_s
assert_equal "javy", platform.format_executable_path("javy")
end

def test_recognizes_mac_os_arm
platform = Javy::Platform.new(PlatformHelper.macos_arm_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 All @@ -149,10 +169,9 @@ def test_unsupported_on_32_bit_machines

private

def install(platform_config)
def stub_platform(platform_config)
stubbed_platform = Javy::Platform.new(platform_config)
Javy::Platform.stubs(:new).returns(stubbed_platform)
Javy.install
end

def run_build_and_expect_execution(source: "src/index.js", dest: "build/index.wasm", target: Javy::TARGET)
Expand Down Expand Up @@ -193,10 +212,14 @@ def self.linux_config
ruby_config(os: "linux-gnu", cpu: "x86_64")
end

def self.macos_config
def self.macos_x64_config
ruby_config(os: "darwin20.3.0", cpu: "x86_64")
end

def self.macos_arm_config
ruby_config(os: "darwin20.3.0", cpu: "arm")
end

def self.windows_config
ruby_config(os: "mingw32", cpu: "x64")
end
Expand Down

0 comments on commit eb2b04a

Please sign in to comment.