Skip to content

Commit

Permalink
Use debug/release tarballs in hermes-engine Pod (#34761)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #34761

Separate debug and release tarballs are built in CI. Use the appropriate Hermes artifacts tarball when building hermes-engine.

Add hermes.rb tests.

Changelog:
[iOS] [Changed] - Remove debugger from Hermes when building for release

Reviewed By: cipolleschi

Differential Revision: D39698499

fbshipit-source-id: e6b10d34c7f94c2f86fc47d8b97466011aaa75cc
  • Loading branch information
hramos authored and facebook-github-bot committed Sep 23, 2022
1 parent 996c7a6 commit 2fc44ac
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 16 deletions.
53 changes: 53 additions & 0 deletions scripts/cocoapods/__tests__/hermes-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions scripts/cocoapods/hermes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
27 changes: 11 additions & 16 deletions sdks/hermes-engine/hermes-engine.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@

require "json"

module HermesHelper
BUILD_TYPE = :debug
# BUILD_TYPE = :release
end

react_native_path = File.join(__dir__, "..", "..")

# package.json
Expand Down Expand Up @@ -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|
Expand All @@ -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"

Expand All @@ -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

0 comments on commit 2fc44ac

Please sign in to comment.