Skip to content

Commit

Permalink
Reduce breaking changes in use_frameworks! (#36305)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #36305

This change automate settings some search paths for 3rd parties libraries that are not using our `install_modules_dependencies` helper.

This will make the `use_frameworks!` changes less breaking.

## Changelog:
[iOS][Changed] - Automatically update Search Path on pods

Reviewed By: dmytrorykun

Differential Revision: D43596808

fbshipit-source-id: 9c5d7ff60a1e4cf73afbfd70b2499f03825cd764
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Feb 27, 2023
1 parent 05438c3 commit ad686b0
Show file tree
Hide file tree
Showing 3 changed files with 225 additions and 91 deletions.
13 changes: 11 additions & 2 deletions scripts/cocoapods/__tests__/test_utils/InstallerMock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,17 @@ class TargetMock
attr_reader :name
attr_reader :build_configurations
attr_reader :product_type

attr_reader :received_resolved_build_setting_parameters
attr_reader :dependencies

def initialize(name, build_configurations = [], product_type = nil)
def initialize(name, build_configurations = [], product_type = nil, dependencies = [])
@name = name
@build_configurations = build_configurations
unless product_type.nil?
@product_type = product_type
end
@received_resolved_build_setting_parameters = []
@dependencies = dependencies
end

def resolved_build_setting(key, resolve_against_xcconfig: false)
Expand Down Expand Up @@ -211,3 +212,11 @@ def initialize(target = TargetMock, native_target = TargetMock,
@app_resource_bundle_targets = app_resource_bundle_targets
end
end

class DependencyMock
attr_reader :name

def initialize(name)
@name = name
end
end
137 changes: 78 additions & 59 deletions scripts/cocoapods/__tests__/utils-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,13 @@ def test_updateSearchPaths_whenUseFrameworks_addsSearchPaths
# Arrange
ENV['USE_FRAMEWORKS'] = 'static'
first_target = prepare_target("FirstTarget")
second_target = prepare_target("SecondTarget")
second_target = prepare_target("SecondTarget", nil, [
DependencyMock.new("RCT-Folly"),
DependencyMock.new("React-Codegen"),
DependencyMock.new("ReactCommon"),
DependencyMock.new("React-RCTFabric"),
DependencyMock.new("React-ImageManager"),
])
third_target = prepare_target("ThirdTarget", "com.apple.product-type.bundle")
user_project_mock = UserProjectMock.new("a/path", [
prepare_config("Debug"),
Expand All @@ -563,9 +569,23 @@ def test_updateSearchPaths_whenUseFrameworks_addsSearchPaths
# Assert
user_project_mock.build_configurations.each do |config|
received_search_path = config.build_settings["HEADER_SEARCH_PATHS"]
expected_search_path = "$(inherited) ${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/core/platform/ios ${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/core ${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/samples/platform/ios ${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/samples"
expected_search_path = "$(inherited) ${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/samples ${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/core ${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/samples/platform/ios ${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/core/platform/ios ${PODS_CONFIGURATION_BUILD_DIR}/React-graphics/React_graphics.framework/Headers/react/renderer/graphics/platform/ios"
assert_equal(expected_search_path, received_search_path)
end

installer.target_installation_results.pod_target_installation_results.each do |pod_name, target_installation_result|
if pod_name == "SecondTarget"
target_installation_result.native_target.build_configurations.each do |config|
received_search_path = config.build_settings["HEADER_SEARCH_PATHS"]
expected_Search_path = "$(inherited) \"$(PODS_ROOT)/RCT-Folly\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/boost\" \"${PODS_CONFIGURATION_BUILD_DIR}/React-Codegen/React_Codegen.framework/Headers\" \"${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon/ReactCommon.framework/Headers\" \"${PODS_CONFIGURATION_BUILD_DIR}/ReactCommon/ReactCommon.framework/Headers/react/nativemodule/core\" \"${PODS_CONFIGURATION_BUILD_DIR}/React-RCTFabric/RCTFabric.framework/Headers\" \"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers\" \"${PODS_CONFIGURATION_BUILD_DIR}/React-Graphics/React_graphics.framework/Headers\" \"${PODS_CONFIGURATION_BUILD_DIR}/React-Graphics/React_graphics.framework/Headers/react/renderer/graphics/platform/ios\" \"${PODS_CONFIGURATION_BUILD_DIR}/React-Fabric/React_Fabric.framework/Headers/react/renderer/imagemanager/platform/ios\""
assert_equal(received_search_path, expected_Search_path)
end
else
target_installation_result.native_target.build_configurations.each do |config|
assert_nil(config.build_settings["HEADER_SEARCH_PATHS"])
end
end
end
end

def test_updateSearchPaths_whenNotUseFrameworks_addsSearchPaths
Expand Down Expand Up @@ -595,71 +615,70 @@ def test_updateSearchPaths_whenNotUseFrameworks_addsSearchPaths
assert_nil(config.build_settings["HEADER_SEARCH_PATHS"])
end
end
end

# ============================= #
# Test - Apply Flags For Fabric #
# ============================= #
def test_applyFlagsForFabric_whenFabricEnabled_addsTheFlag
# Arrange
first_target = prepare_target("FirstTarget")
second_target = prepare_target("SecondTarget")
third_target = prepare_target("ThirdTarget", "com.apple.product-type.bundle")
user_project_mock = UserProjectMock.new("a/path", [
prepare_config("Debug"),
prepare_config("Release"),
],
:native_targets => [
first_target,
second_target
]
)
pods_projects_mock = PodsProjectMock.new([third_target], {"hermes-engine" => {}})
installer = InstallerMock.new(pods_projects_mock, [
AggregatedProjectMock.new(user_project_mock)
])
# ============================= #
# Test - Apply Flags For Fabric #
# ============================= #
def test_applyFlagsForFabric_whenFabricEnabled_addsTheFlag
# Arrange
first_target = prepare_target("FirstTarget")
second_target = prepare_target("SecondTarget")
third_target = prepare_target("ThirdTarget", "com.apple.product-type.bundle")
user_project_mock = UserProjectMock.new("a/path", [
prepare_config("Debug"),
prepare_config("Release"),
],
:native_targets => [
first_target,
second_target
]
)
pods_projects_mock = PodsProjectMock.new([third_target], {"hermes-engine" => {}})
installer = InstallerMock.new(pods_projects_mock, [
AggregatedProjectMock.new(user_project_mock)
])

# Act
ReactNativePodsUtils.apply_flags_for_fabric(installer, fabric_enabled: true)
# Act
ReactNativePodsUtils.apply_flags_for_fabric(installer, fabric_enabled: true)

# Assert
user_project_mock.build_configurations.each do |config|
received_cflags = config.build_settings["OTHER_CFLAGS"]
expected_cflags = "$(inherited) -DRN_FABRIC_ENABLED"
assert_equal(received_cflags, expected_cflags)
end
# Assert
user_project_mock.build_configurations.each do |config|
received_cflags = config.build_settings["OTHER_CFLAGS"]
expected_cflags = "$(inherited) -DRN_FABRIC_ENABLED"
assert_equal(received_cflags, expected_cflags)
end

end
end

def test_applyFlagsForFabric_whenFabricDisabled_doNothing
# Arrange
first_target = prepare_target("FirstTarget")
second_target = prepare_target("SecondTarget")
third_target = prepare_target("ThirdTarget", "com.apple.product-type.bundle")
user_project_mock = UserProjectMock.new("a/path", [
prepare_config("Debug"),
prepare_config("Release"),
],
:native_targets => [
first_target,
second_target
]
)
pods_projects_mock = PodsProjectMock.new([third_target], {"hermes-engine" => {}})
installer = InstallerMock.new(pods_projects_mock, [
AggregatedProjectMock.new(user_project_mock)
])
def test_applyFlagsForFabric_whenFabricDisabled_doNothing
# Arrange
first_target = prepare_target("FirstTarget")
second_target = prepare_target("SecondTarget")
third_target = prepare_target("ThirdTarget", "com.apple.product-type.bundle")
user_project_mock = UserProjectMock.new("a/path", [
prepare_config("Debug"),
prepare_config("Release"),
],
:native_targets => [
first_target,
second_target
]
)
pods_projects_mock = PodsProjectMock.new([third_target], {"hermes-engine" => {}})
installer = InstallerMock.new(pods_projects_mock, [
AggregatedProjectMock.new(user_project_mock)
])

# Act
ReactNativePodsUtils.apply_flags_for_fabric(installer, fabric_enabled: false)
# Act
ReactNativePodsUtils.apply_flags_for_fabric(installer, fabric_enabled: false)

# Assert
user_project_mock.build_configurations.each do |config|
assert_nil(config.build_settings["OTHER_CFLAGS"])
# Assert
user_project_mock.build_configurations.each do |config|
assert_nil(config.build_settings["OTHER_CFLAGS"])
end
end
end


# ===== #
# UTILS #
# ===== #
Expand All @@ -679,11 +698,11 @@ def prepare_config(config_name)
]})
end

def prepare_target(name, product_type = nil)
def prepare_target(name, product_type = nil, dependencies = [])
return TargetMock.new(name, [
prepare_config("Debug"),
prepare_config("Release")
], product_type)
], product_type, dependencies)
end

def prepare_Code_Signing_build_configuration(name, param)
Expand Down

0 comments on commit ad686b0

Please sign in to comment.