Automatically detect when use frameworks is used (#35636)
Summary: This PR introduce an automatic way to detect whether the user sets its podfile to use frameworks. In this way, users don't have to install pods with a specific environment flag but they can rely on the standard Cocoapods usage ## Changelog [IOS][ADDED] - Automatically detect whether use_frameworks! is used Pull Request resolved: https://github.com/facebook/react-native/pull/35636 Test Plan: - CircleCI is Green - Added unit tests - Tested locally with an app Reviewed By: dmytrorykun Differential Revision: D42029355 Pulled By: cipolleschi fbshipit-source-id: 76c92133deabbda59603b043a4d542737f10f044
This commit is contained in:
Родитель
c7e1e00b82
Коммит
f249bee171
|
@ -0,0 +1,12 @@
|
|||
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
class TargetDefinitionMock
|
||||
attr_reader :build_type
|
||||
|
||||
def initialize(build_type)
|
||||
@build_type = build_type
|
||||
end
|
||||
end
|
|
@ -13,6 +13,7 @@ require_relative "./test_utils/SysctlCheckerMock.rb"
|
|||
require_relative "./test_utils/FileMock.rb"
|
||||
require_relative "./test_utils/systemUtils.rb"
|
||||
require_relative "./test_utils/PathnameMock.rb"
|
||||
require_relative "./test_utils/TargetDefinitionMock.rb"
|
||||
|
||||
class UtilsTests < Test::Unit::TestCase
|
||||
def setup
|
||||
|
@ -30,6 +31,7 @@ class UtilsTests < Test::Unit::TestCase
|
|||
Environment.reset()
|
||||
ENV['RCT_NEW_ARCH_ENABLED'] = '0'
|
||||
ENV['USE_HERMES'] = '1'
|
||||
ENV['USE_FRAMEWORKS'] = nil
|
||||
system_reset_commands
|
||||
end
|
||||
|
||||
|
@ -481,6 +483,57 @@ class UtilsTests < Test::Unit::TestCase
|
|||
assert_equal(File.exist_invocation_params, ["/.xcode.env"])
|
||||
assert_equal($collected_commands, ["echo 'export NODE_BINARY=$(command -v node)' > /.xcode.env"])
|
||||
end
|
||||
|
||||
# ============================ #
|
||||
# Test - Detect Use Frameworks #
|
||||
# ============================ #
|
||||
def test_detectUseFrameworks_whenEnvAlreadySet_DoesNothing
|
||||
# Arrange
|
||||
ENV['USE_FRAMEWORKS'] = 'static'
|
||||
target_definition = TargetDefinitionMock.new('something')
|
||||
|
||||
# Act
|
||||
ReactNativePodsUtils.detect_use_frameworks(target_definition)
|
||||
|
||||
# Assert
|
||||
assert_equal(Pod::UI.collected_messages, [])
|
||||
end
|
||||
|
||||
def test_detectUseFrameworks_whenEnvNotSetAndNotUsed_setEnvVarToNil
|
||||
# Arrange
|
||||
target_definition = TargetDefinitionMock.new('static library')
|
||||
|
||||
# Act
|
||||
ReactNativePodsUtils.detect_use_frameworks(target_definition)
|
||||
|
||||
# Assert
|
||||
assert_equal(Pod::UI.collected_messages, ["Framework build type is static library"])
|
||||
assert_nil(ENV['USE_FRAMEWORKS'])
|
||||
end
|
||||
|
||||
def test_detectUseFrameworks_whenEnvNotSetAndStaticFrameworks_setEnvVarToStatic
|
||||
# Arrange
|
||||
target_definition = TargetDefinitionMock.new('static framework')
|
||||
|
||||
# Act
|
||||
ReactNativePodsUtils.detect_use_frameworks(target_definition)
|
||||
|
||||
# Assert
|
||||
assert_equal(Pod::UI.collected_messages, ["Framework build type is static framework"])
|
||||
assert_equal(ENV['USE_FRAMEWORKS'], 'static')
|
||||
end
|
||||
|
||||
def test_detectUseFrameworks_whenEnvNotSetAndDynamicFrameworks_setEnvVarToDynamic
|
||||
# Arrange
|
||||
target_definition = TargetDefinitionMock.new('dynamic framework')
|
||||
|
||||
# Act
|
||||
ReactNativePodsUtils.detect_use_frameworks(target_definition)
|
||||
|
||||
# Assert
|
||||
assert_equal(Pod::UI.collected_messages, ["Framework build type is dynamic framework"])
|
||||
assert_equal(ENV['USE_FRAMEWORKS'], 'dynamic')
|
||||
end
|
||||
end
|
||||
|
||||
def prepare_empty_user_project_mock
|
||||
|
|
|
@ -163,4 +163,26 @@ class ReactNativePodsUtils
|
|||
|
||||
system("echo 'export NODE_BINARY=$(command -v node)' > #{file_path}")
|
||||
end
|
||||
|
||||
# It examines the target_definition property and sets the appropriate value for
|
||||
# ENV['USE_FRAMEWORKS'] variable.
|
||||
#
|
||||
# - parameter target_definition: The current target definition
|
||||
def self.detect_use_frameworks(target_definition)
|
||||
if ENV['USE_FRAMEWORKS'] != nil
|
||||
return
|
||||
end
|
||||
|
||||
framework_build_type = target_definition.build_type.to_s
|
||||
|
||||
Pod::UI.puts("Framework build type is #{framework_build_type}")
|
||||
|
||||
if framework_build_type === "static framework"
|
||||
ENV['USE_FRAMEWORKS'] = 'static'
|
||||
elsif framework_build_type === "dynamic framework"
|
||||
ENV['USE_FRAMEWORKS'] = 'dynamic'
|
||||
else
|
||||
ENV['USE_FRAMEWORKS'] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -61,6 +61,10 @@ def use_react_native! (
|
|||
app_path: '..',
|
||||
config_file_dir: '')
|
||||
|
||||
# Current target definition is provided by Cocoapods and it refers to the target
|
||||
# that has invoked the `use_react_native!` function.
|
||||
ReactNativePodsUtils.detect_use_frameworks(current_target_definition)
|
||||
|
||||
CodegenUtils.clean_up_build_folder(app_path, $CODEGEN_OUTPUT_DIR)
|
||||
|
||||
# We are relying on this flag also in third parties libraries to proper install dependencies.
|
||||
|
|
Загрузка…
Ссылка в новой задаче