Files
react-native/scripts/cocoapods/__tests__/test_utils/InstallerMock.rb
T
Arkkeeper 2fb6a3393d Mac Catalyst patches (#34026)
Summary:
This PR adds a new method called **__apply_mac_catalyst_patches** to **scripts/react_native_pods.rb**. If it is enabled in the Podfile, it will apply three patches necessary for successful building not only for iOS and tvOS targets, but also for macOS using Apple's Mac Catalyst technology.

These 3 patches are:
- Fixing bundle signing issues by altering CODE_SIGN_IDENTITY
- Explicitly setting dead code stripping flag in project.pbxproj
- Modifying library search paths

The details were discussed here https://github.com/reactwg/react-native-releases/discussions/21#discussioncomment-2754289

## Changelog

[iOS] [Added] - Add Mac Catalyst compatibility (can be enabled in Podfile)

Pull Request resolved: https://github.com/facebook/react-native/pull/34026

Test Plan:
1. Go to project settings in Xcode, to General tab. Enable "iPad" and "Mac Catalyst" checkboxes
2. Go to "Signing & Capabilities" tab, ensure that a correct bundle id and development team are set
3. Edit Podfile, uncomment **__apply_mac_catalyst_patches(installer)** line
4. Run `pod install` in ios directory
5. Get back to Xcode, select "My Mac (Mac Catalyst)" as a target device
6. Build & run

Reviewed By: cipolleschi

Differential Revision: D37362054

Pulled By: cortinico

fbshipit-source-id: 74636f716f112289ab40968bbc8e52406c1e9579
2022-06-30 05:20:14 -07:00

188 lines
4.9 KiB
Ruby
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 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.
# This file replicate the structure of the Installer used Cocoapods in the post_install step.
#
# To use it, add `require_relative path/to/InstallerMock.rb` into your test file
#
# ## Initialization
# You can create a new mock with the `InstallerMock.new` statement. In this case, you will
# create an empty mock.
#
# It's possible to create complex with the initializer. To create an Installer with a pod, for example, we can
# use the following code:
#
# ```ruby
# installer = Installer.new(
# PodsProjectMock.new([
# TargetMock.new(
# "MyPod",
# [
# BuildConfigurationMock.new("Debug"),
# ]
# )
# )
# )
# ```
#
# ## Assert
# All the properties of these objects are accessible in read mode.
# To access the target's list, for example, you can use the following line:
#
# ```ruby
# targets = installer.pods_project.targets
# ```
class InstallerMock
attr_reader :pods_project
attr_reader :aggregate_targets
attr_reader :target_installation_results
def initialize(pods_project = PodsProjectMock.new, aggregate_targets = [AggregatedProjectMock.new], target_installation_results: [])
@pods_project = pods_project
@aggregate_targets = aggregate_targets
@target_installation_results = target_installation_results
end
def target_with_name(name)
return @pods_project.targets
.select { |target| target.name == name }
.first
end
end
class PodsProjectMock
attr_reader :targets
attr_reader :native_targets
attr_reader :path
attr_reader :build_configurations
@pod_group
attr_reader :save_invocation_count
def initialize(targets = [], pod_group = {}, path = "test/path-pod.xcodeproj", build_configurations = [], native_targets: [])
@targets = targets
@pod_group = pod_group
@path = path
@build_configurations = build_configurations
@save_invocation_count = 0
@native_targets = native_targets
end
def pod_group(name)
return @pod_group[name]
end
def save()
@save_invocation_count += 1
end
end
class AggregatedProjectMock
attr_reader :user_project
attr_reader :xcconfigs
@base_path
def initialize(user_project = UserProjectMock.new, xcconfigs: {}, base_path: "")
@user_project = user_project
@xcconfigs = xcconfigs
@base_path = base_path
end
def xcconfig_path(config_name)
return File.join(@base_path, "#{config_name}.xcconfig")
end
end
class UserProjectMock
attr_reader :path
attr_reader :build_configurations
attr_reader :native_targets
attr_reader :save_invocation_count
def initialize(path = "/test/path.xcproj", build_configurations = [], native_targets: [])
@path = path
@build_configurations = build_configurations
@native_targets = native_targets
@save_invocation_count = 0
end
def save()
@save_invocation_count += 1
end
end
class XCConfigMock
attr_reader :name
attr_accessor :attributes
attr_reader :save_as_invocation
def initialize(name, attributes: {})
@name = name
@attributes = attributes
@save_as_invocation = []
end
def save_as(file_path)
@save_as_invocation.push(file_path)
end
end
ReceivedCommonResolvedBuildSettings = Struct.new(:key, :resolve_against_xcconfig)
class TargetMock
attr_reader :name
attr_reader :build_configurations
attr_reader :product_type
attr_reader :received_resolved_build_setting_parameters
def initialize(name, build_configurations = [], product_type = nil)
@name = name
@build_configurations = build_configurations
unless product_type.nil?
@product_type = product_type
end
@received_resolved_build_setting_parameters = []
end
def resolved_build_setting(key, resolve_against_xcconfig: false)
received_resolved_build_setting_parameters.append(ReceivedCommonResolvedBuildSettings.new(key, resolve_against_xcconfig))
return {name: build_configurations[0].build_settings[key]}
end
end
class BuildConfigurationMock
attr_reader :name
attr_reader :build_settings
def initialize(name, build_settings = {})
@name = name
@build_settings = build_settings
end
end
class TargetInstallationResultsMock
attr_reader :pod_target_installation_results
def initialize(pod_target_installation_results: {})
@pod_target_installation_results = pod_target_installation_results
end
end
class PodTargetInstallationResultsMock
attr_reader :name
attr_reader :native_target
def initialize(name: "", native_target: TargetMock.new())
@name = name
@native_target = native_target
end
end