Skip to content

Commit 6569aeb

Browse files
committed
fix(iOS): use the module name when rewriting module map paths of spm_dependency pods
1 parent 27e7721 commit 6569aeb

2 files changed

Lines changed: 47 additions & 11 deletions

File tree

‎packages/react-native/scripts/cocoapods/__tests__/spm-test.rb‎

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ def initialize(pods_project, aggregate_targets = [])
1818
super
1919
end
2020
end
21-
PodTargetStub = Struct.new(:name)
22-
AggregateTargetStub = Struct.new(:name, :pod_targets, :embed_frameworks_script_path) do
23-
def xcconfigs
24-
{}
21+
PodTargetStub = Struct.new(:name, :product_module_name)
22+
AggregateTargetStub = Struct.new(:name, :pod_targets, :embed_frameworks_script_path, :xcconfigs) do
23+
def initialize(name, pod_targets, embed_frameworks_script_path, xcconfigs = {})
24+
super
25+
end
26+
27+
def xcconfig_path(config_name)
28+
Pathname(TMP_DIR) + "#{name}.#{config_name.downcase}.xcconfig"
2529
end
2630
end
2731

@@ -202,4 +206,32 @@ def test_signature_cleanup_is_added_only_to_pods_not_built_into_the_shared_produ
202206
assert_empty(phase_names.call(POD_NAME))
203207
assert_loadable_project(project.path)
204208
end
209+
210+
def test_module_map_references_use_the_module_name_of_pods_built_into_the_shared_products_dir
211+
project = build_project(0)
212+
project.new_target(:static_library, "rnmapbox-maps", :ios)
213+
project.save
214+
manager = SPMManager.new
215+
[POD_NAME, "rnmapbox-maps"].each do |pod_name|
216+
manager.dependency(
217+
PodSpecStub.new(pod_name),
218+
url: "https://github.com/rive-app/rive-ios.git",
219+
requirement: { kind: "exactVersion", version: "6.26.0" },
220+
products: ["RiveRuntime"]
221+
)
222+
end
223+
flags = '$(inherited) -fmodule-map-file="${PODS_CONFIGURATION_BUILD_DIR}/%s" -fmodule-map-file="${PODS_CONFIGURATION_BUILD_DIR}/%s"'
224+
config = Xcodeproj::Config.new(
225+
"OTHER_CFLAGS" => flags % ["#{POD_NAME}/#{POD_NAME}.modulemap", "rnmapbox-maps/rnmapbox_maps.modulemap"],
226+
"OTHER_SWIFT_FLAGS" => flags % ["#{POD_NAME}/#{POD_NAME}.modulemap", "rnmapbox-maps/rnmapbox_maps.modulemap"]
227+
)
228+
pod_targets = [PodTargetStub.new(POD_NAME, POD_NAME), PodTargetStub.new("rnmapbox-maps", "rnmapbox_maps")]
229+
aggregate_target = AggregateTargetStub.new("Pods-App", pod_targets, File.join(TMP_DIR, "none.sh"), { "Debug" => config })
230+
231+
manager.apply_on_post_install(InstallerStub.new(project, [aggregate_target]))
232+
233+
expected = flags % ["#{POD_NAME}.modulemap", "rnmapbox_maps.modulemap"]
234+
assert_equal(expected, config.attributes["OTHER_CFLAGS"])
235+
assert_equal(expected, config.attributes["OTHER_SWIFT_FLAGS"])
236+
end
205237
end

‎packages/react-native/scripts/cocoapods/spm.rb‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,25 @@ def add_signature_cleanup(project, pod_names)
142142
end
143143

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

156-
updated_value = pod_names.reduce(value) do |acc, pod_name|
159+
updated_value = pod_targets.reduce(value) do |acc, pod_target|
160+
module_name = pod_target.product_module_name
157161
acc.gsub(
158-
"${PODS_CONFIGURATION_BUILD_DIR}/#{pod_name}/#{pod_name}.modulemap",
159-
"${PODS_CONFIGURATION_BUILD_DIR}/#{pod_name}.modulemap"
162+
"${PODS_CONFIGURATION_BUILD_DIR}/#{pod_target.name}/#{module_name}.modulemap",
163+
"${PODS_CONFIGURATION_BUILD_DIR}/#{module_name}.modulemap"
160164
)
161165
end
162166
config_file.attributes[key] = updated_value if updated_value != value

0 commit comments

Comments
 (0)