Skip to content

Commit

Permalink
Use PRODUCTION envvar directly in hermes-engine Pod to determine buil…
Browse files Browse the repository at this point in the history
…d type (#34776)

Summary:
Pull Request resolved: #34776

CocoaPods is not used when Hermes is built in Circle CI, so we cannot rely on the React Native CocoaPods scripts to be loaded.
The get_hermes_build_type function is removed from the RN CocoaPods scripts and in its place, the ENV['PRODUCTION'] envvar is accessed directly.

Changelog: [Internal]

Reviewed By: cipolleschi

Differential Revision: D39778190

fbshipit-source-id: 12083b7b4533b4ad7bb7a08612883983a0583616
  • Loading branch information
hramos authored and facebook-github-bot committed Sep 23, 2022
1 parent 1d70802 commit c557f25
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 60 deletions.
52 changes: 0 additions & 52 deletions scripts/cocoapods/__tests__/hermes-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def teardown
Pod::Config.reset()
Pod::UI.reset()
podSpy_cleanUp()
ENV['PRODUCTION'] = '0'
end

# ============================= #
Expand Down Expand Up @@ -84,55 +83,4 @@ def test_installHermesIfEnabled_whenHermesIsEnabledAndHermesScriptSucceeds_insta
assert_equal($podInvocation["libevent"][:version], "~> 2.1.12")
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: 0 additions & 4 deletions scripts/cocoapods/hermes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,3 @@ 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
11 changes: 7 additions & 4 deletions sdks/hermes-engine/hermes-engine.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ require "json"

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

# Whether Hermes is built for Release or Debug is determined by the PRODUCTION envvar.
build_type = ENV['PRODUCTION'] == "1" ? :release : :debug

# package.json
package_file = File.join(react_native_path, "package.json")
package = JSON.parse(File.read(package_file))
Expand Down Expand Up @@ -35,7 +38,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-#{get_hermes_build_type.to_s}-v#{version}.tar.gz"
source[:http] = "https://github.com/facebook/react-native/releases/download/v#{version}/hermes-runtime-darwin-#{build_type.to_s}-v#{version}.tar.gz"
end

Pod::Spec.new do |spec|
Expand All @@ -49,7 +52,7 @@ Pod::Spec.new do |spec|
spec.source = source
spec.platforms = { :osx => "10.13", :ios => "12.4" }

spec.preserve_paths = ["destroot/bin/*"].concat(get_hermes_build_type == :debug ? ["**/*.{h,c,cpp}"] : [])
spec.preserve_paths = ["destroot/bin/*"].concat(build_type == :debug ? ["**/*.{h,c,cpp}"] : [])
spec.source_files = "destroot/include/**/*.h"
spec.header_mappings_dir = "destroot/include"

Expand All @@ -59,12 +62,12 @@ Pod::Spec.new do |spec|
spec.xcconfig = {
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
"CLANG_CXX_LIBRARY" => "compiler-default",
"GCC_PREPROCESSOR_DEFINITIONS" => "HERMES_ENABLE_DEBUGGER=#{get_hermes_build_type == :debug ? "1" : "0"}"
"GCC_PREPROCESSOR_DEFINITIONS" => "HERMES_ENABLE_DEBUGGER=#{build_type == :debug ? "1" : "0"}"
}

if source[:git] then
spec.prepare_command = <<-EOS
BUILD_TYPE=#{get_hermes_build_type.to_s.capitalize}
BUILD_TYPE=#{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}" : ""}
Expand Down

0 comments on commit c557f25

Please sign in to comment.