Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions packages/react-native/scripts/cocoapods/__tests__/spm-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ def initialize(pods_project, aggregate_targets = [])
super
end
end
PodTargetStub = Struct.new(:name)
AggregateTargetStub = Struct.new(:name, :pod_targets, :embed_frameworks_script_path) do
def xcconfigs
{}
PodTargetStub = Struct.new(:name, :product_module_name)
AggregateTargetStub = Struct.new(:name, :pod_targets, :embed_frameworks_script_path, :xcconfigs) do
def initialize(name, pod_targets, embed_frameworks_script_path, xcconfigs = {})
super
end

def xcconfig_path(config_name)
Pathname(TMP_DIR) + "#{name}.#{config_name.downcase}.xcconfig"
end
end

Expand Down Expand Up @@ -202,4 +206,32 @@ def test_signature_cleanup_is_added_only_to_pods_not_built_into_the_shared_produ
assert_empty(phase_names.call(POD_NAME))
assert_loadable_project(project.path)
end

def test_module_map_references_use_the_module_name_of_pods_built_into_the_shared_products_dir
project = build_project(0)
project.new_target(:static_library, "rnmapbox-maps", :ios)
project.save
manager = SPMManager.new
[POD_NAME, "rnmapbox-maps"].each do |pod_name|
manager.dependency(
PodSpecStub.new(pod_name),
url: "https://github.com/rive-app/rive-ios.git",
requirement: { kind: "exactVersion", version: "6.26.0" },
products: ["RiveRuntime"]
)
end
flags = '$(inherited) -fmodule-map-file="${PODS_CONFIGURATION_BUILD_DIR}/%s" -fmodule-map-file="${PODS_CONFIGURATION_BUILD_DIR}/%s"'
config = Xcodeproj::Config.new(
"OTHER_CFLAGS" => flags % ["#{POD_NAME}/#{POD_NAME}.modulemap", "rnmapbox-maps/rnmapbox_maps.modulemap"],
"OTHER_SWIFT_FLAGS" => flags % ["#{POD_NAME}/#{POD_NAME}.modulemap", "rnmapbox-maps/rnmapbox_maps.modulemap"]
)
pod_targets = [PodTargetStub.new(POD_NAME, POD_NAME), PodTargetStub.new("rnmapbox-maps", "rnmapbox_maps")]
aggregate_target = AggregateTargetStub.new("Pods-App", pod_targets, File.join(TMP_DIR, "none.sh"), { "Debug" => config })

manager.apply_on_post_install(InstallerStub.new(project, [aggregate_target]))

expected = flags % ["#{POD_NAME}.modulemap", "rnmapbox_maps.modulemap"]
assert_equal(expected, config.attributes["OTHER_CFLAGS"])
assert_equal(expected, config.attributes["OTHER_SWIFT_FLAGS"])
end
end
18 changes: 11 additions & 7 deletions packages/react-native/scripts/cocoapods/spm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,25 @@ def add_signature_cleanup(project, pod_names)
end

# Flattening a pod's build dir moves its generated modulemap from
# "<Pod>/<Pod>.modulemap" to "<Pod>.modulemap"; the aggregate xcconfigs
# reference the old path via -fmodule-map-file. Must mutate the in-memory
# Config attributes — later post_install steps (NewArchitectureHelper) re-save
# the same Config objects and would clobber a plain file edit.
# "<Pod>/<Module>.modulemap" to "<Module>.modulemap"; the aggregate xcconfigs
# reference the old path via -fmodule-map-file. The module name differs from
# the pod name when the pod name isn't a C identifier (e.g. "rnmapbox-maps").
# Must mutate the in-memory Config attributes — later post_install steps
# (NewArchitectureHelper) re-save the same Config objects and would clobber a
# plain file edit.
def rewrite_aggregate_modulemap_references(installer, pod_names)
installer.aggregate_targets.each do |aggregate_target|
pod_targets = aggregate_target.pod_targets.select { |pod_target| pod_names.include?(pod_target.name) }
aggregate_target.xcconfigs.each do |config_name, config_file|
%w[OTHER_CFLAGS OTHER_SWIFT_FLAGS].each do |key|
value = config_file.attributes[key]
next unless value

updated_value = pod_names.reduce(value) do |acc, pod_name|
updated_value = pod_targets.reduce(value) do |acc, pod_target|
module_name = pod_target.product_module_name
acc.gsub(
"${PODS_CONFIGURATION_BUILD_DIR}/#{pod_name}/#{pod_name}.modulemap",
"${PODS_CONFIGURATION_BUILD_DIR}/#{pod_name}.modulemap"
"${PODS_CONFIGURATION_BUILD_DIR}/#{pod_target.name}/#{module_name}.modulemap",
"${PODS_CONFIGURATION_BUILD_DIR}/#{module_name}.modulemap"
)
end
config_file.attributes[key] = updated_value if updated_value != value
Expand Down
Loading