diff --git a/scripts/cocoapods/__tests__/hermes-test.rb b/scripts/cocoapods/__tests__/hermes-test.rb index 0d22d40a02f687..a69bb29d1ee4d5 100644 --- a/scripts/cocoapods/__tests__/hermes-test.rb +++ b/scripts/cocoapods/__tests__/hermes-test.rb @@ -22,8 +22,12 @@ def teardown Pod::Config.reset() Pod::UI.reset() podSpy_cleanUp() + ENV['PRODUCTION'] = '0' end + # ============================= # + # TEST - installHermesIfEnabled # + # ============================= # def test_installHermesIfEnabled_whenHermesIsDisabled_doesNothing # Arrange @@ -81,5 +85,54 @@ def test_installHermesIfEnabled_whenHermesIsEnabledAndHermesScriptSucceeds_insta assert_equal($podInvocation["hermes-engine"][:podspec], "../../sdks/hermes/hermes-engine.podspec") end + # ========================= # + # TEST - getHermesBuildType # + # ========================= # + def test_getHermesBuildType_whenNotInProduction + # Arrange + ENV['PRODUCTION'] = '0' + + # Act + build_type = get_hermes_build_type + + # Assert + assert_equal(build_type, :debug) + end + + def test_getHermesBuildType_whenInProduction + # Arrange + ENV['PRODUCTION'] = '1' + + # Act + build_type = get_hermes_build_type + + # Assert + assert_equal(build_type, :release) + end + + def test_getHermesBuildType_whenProductionIsNotSet + # Arrange + ENV.delete 'PRODUCTION' + + # Act + build_type = get_hermes_build_type + + # Assert + assert_equal(build_type, :debug) + end + + def test_getHermesBuildType_symbolsMatchStrings + # Arrange + ENV['PRODUCTION'] = '0' + + # Act + build_type = get_hermes_build_type + + # Assert + assert_equal(build_type, :debug) + assert_equal(build_type.to_s, "debug") + assert_equal(build_type.to_s.capitalize, "Debug") + end + end diff --git a/scripts/cocoapods/hermes.rb b/scripts/cocoapods/hermes.rb index 747b744c87d7df..a88b8dc4c0af0c 100644 --- a/scripts/cocoapods/hermes.rb +++ b/scripts/cocoapods/hermes.rb @@ -18,3 +18,7 @@ def install_hermes_if_enabled(hermes_enabled, react_native_path) pod 'libevent', '~> 2.1.12' pod 'hermes-engine', :podspec => "#{react_native_path}/sdks/hermes/hermes-engine.podspec" end + +def get_hermes_build_type() + return ENV['PRODUCTION'] == "1" ? :release : :debug +end diff --git a/sdks/hermes-engine/hermes-engine.podspec b/sdks/hermes-engine/hermes-engine.podspec index 3bced58061f2b8..1d5d4aa17c3b12 100644 --- a/sdks/hermes-engine/hermes-engine.podspec +++ b/sdks/hermes-engine/hermes-engine.podspec @@ -5,11 +5,6 @@ require "json" -module HermesHelper - BUILD_TYPE = :debug - # BUILD_TYPE = :release -end - react_native_path = File.join(__dir__, "..", "..") # package.json @@ -40,7 +35,7 @@ elsif File.exists?(hermestag_file) && isInCI source[:git] = git source[:tag] = hermestag else - source[:http] = "https://github.com/facebook/react-native/releases/download/v#{version}/hermes-runtime-darwin-v#{version}.tar.gz" + source[:http] = "https://github.com/facebook/react-native/releases/download/v#{version}/hermes-runtime-darwin-#{get_hermes_build_type.to_s}-v#{version}.tar.gz" end Pod::Spec.new do |spec| @@ -54,7 +49,7 @@ Pod::Spec.new do |spec| spec.source = source spec.platforms = { :osx => "10.13", :ios => "12.4" } - spec.preserve_paths = ["destroot/bin/*"].concat(HermesHelper::BUILD_TYPE == :debug ? ["**/*.{h,c,cpp}"] : []) + spec.preserve_paths = ["destroot/bin/*"].concat(get_hermes_build_type == :debug ? ["**/*.{h,c,cpp}"] : []) spec.source_files = "destroot/include/**/*.h" spec.header_mappings_dir = "destroot/include" @@ -64,22 +59,22 @@ Pod::Spec.new do |spec| spec.xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++17", "CLANG_CXX_LIBRARY" => "compiler-default", - "GCC_PREPROCESSOR_DEFINITIONS" => "HERMES_ENABLE_DEBUGGER=#{HermesHelper::BUILD_TYPE == :debug ? "1" : "0"}" + "GCC_PREPROCESSOR_DEFINITIONS" => "HERMES_ENABLE_DEBUGGER=#{get_hermes_build_type == :debug ? "1" : "0"}" } if source[:git] then spec.prepare_command = <<-EOS - BUILD_TYPE=#{HermesHelper::BUILD_TYPE == :debug ? "Debug" : "Release"} + BUILD_TYPE=#{get_hermes_build_type.to_s.capitalize} - # Set HERMES_OVERRIDE_HERMESC_PATH if pre-built HermesC is available - #{File.exist?(import_hermesc_file) ? "export HERMES_OVERRIDE_HERMESC_PATH=#{import_hermesc_file}" : ""} - #{File.exist?(import_hermesc_file) ? "echo \"Overriding HermesC path...\"" : ""} + # Set HERMES_OVERRIDE_HERMESC_PATH if pre-built HermesC is available + #{File.exist?(import_hermesc_file) ? "export HERMES_OVERRIDE_HERMESC_PATH=#{import_hermesc_file}" : ""} + #{File.exist?(import_hermesc_file) ? "echo \"Overriding HermesC path...\"" : ""} - # Build iOS framework - ./utils/build-ios-framework.sh + # Build iOS framework + ./utils/build-ios-framework.sh - # Build Mac framework - ./utils/build-mac-framework.sh + # Build Mac framework + ./utils/build-mac-framework.sh EOS end end