Commit a4f5bdc6 authored by Samuel Giddins's avatar Samuel Giddins

[PodTarget] Only create module maps for targets that define a module

By default, targets integrated as static libraries _will not_ get a module map, unless they opt-in by including `DEFINES_MODULE = YES` in their specification's `pod_target_xcconfig`
parent 847e309e
......@@ -339,13 +339,15 @@ module Pod
framework_search_paths << dependent_target.configuration_build_dir(CONFIGURATION_BUILD_DIR_VARIABLE)
else
library_search_paths << dependent_target.configuration_build_dir(CONFIGURATION_BUILD_DIR_VARIABLE)
module_map_file = if dependent_target.uses_swift?
# for swift, we have a custom build phase that copies in the module map, appending the .Swift module
"${PODS_CONFIGURATION_BUILD_DIR}/#{dependent_target.label}/#{dependent_target.product_module_name}.modulemap"
else
"${PODS_ROOT}/#{dependent_target.module_map_path.relative_path_from(dependent_target.sandbox.root)}"
end
module_map_files << %(-fmodule-map-file="#{module_map_file}")
if dependent_target.defines_module?
module_map_file = if dependent_target.uses_swift?
# for swift, we have a custom build phase that copies in the module map, appending the .Swift module
"${PODS_CONFIGURATION_BUILD_DIR}/#{dependent_target.label}/#{dependent_target.product_module_name}.modulemap"
else
"${PODS_ROOT}/#{dependent_target.module_map_path.relative_path_from(dependent_target.sandbox.root)}"
end
module_map_files << %(-fmodule-map-file="#{module_map_file}")
end
end
swift_import_paths << dependent_target.configuration_build_dir(CONFIGURATION_BUILD_DIR_VARIABLE)
end
......@@ -356,7 +358,7 @@ module Pod
end
other_swift_flags = module_map_files.tap(&:uniq!).flat_map { |f| ['-Xcc', f] }
if target.is_a?(PodTarget) && !target.requires_frameworks?
if target.is_a?(PodTarget) && !target.requires_frameworks? && target.defines_module?
# make it possible for a mixed swift/objc static library to be able to import the objc from within swift
other_swift_flags += ['-import-underlying-module', '-Xcc', '-fmodule-map-file="${SRCROOT}/${MODULEMAP_FILE}"']
end
......
......@@ -27,22 +27,24 @@ module Pod
add_files_to_build_phases
create_xcconfig_file
create_test_xcconfig_files if target.contains_test_specifications?
# TODO: determine if it is safe to unconditionally create (& 'link') module maps & umbrella
# headers for _all_ static libraries -- we've caused bugs by trying to do this in the past
create_module_map do |generator|
generator.headers.concat module_map_additional_headers
end
create_umbrella_header do |generator|
file_accessors = target.file_accessors
file_accessors = file_accessors.reject { |f| f.spec.test_specification? } if target.contains_test_specifications?
generator.imports += if header_mappings_dir
file_accessors.flat_map(&:public_headers).map do |pathname|
pathname.relative_path_from(header_mappings_dir)
end
else
file_accessors.flat_map(&:public_headers).map(&:basename)
end
if target.defines_module?
create_module_map do |generator|
generator.headers.concat module_map_additional_headers
end
create_umbrella_header do |generator|
file_accessors = target.file_accessors
file_accessors = file_accessors.reject { |f| f.spec.test_specification? } if target.contains_test_specifications?
generator.imports += if header_mappings_dir
file_accessors.flat_map(&:public_headers).map do |pathname|
pathname.relative_path_from(header_mappings_dir)
end
else
file_accessors.flat_map(&:public_headers).map(&:basename)
end
end
end
if target.requires_frameworks?
unless target.static_framework?
create_info_plist_file(target.info_plist_path, native_target, target.version, target.platform)
......@@ -54,6 +56,7 @@ module Pod
elsif target.uses_swift?
add_swift_static_library_compatibility_header_phase
end
unless skip_pch?(target.non_test_specs)
path = target.prefix_header_path
file_accessors = target.file_accessors.reject { |f| f.spec.test_specification? }
......
......@@ -146,6 +146,13 @@ module Pod
end
it 'adds the sandbox public headers search paths to the xcconfig, with quotes, as system headers' do
expected = "$(inherited) -isystem \"#{config.sandbox.public_headers.search_paths(Platform.ios).join('" -isystem "')}\""
@xcconfig.to_hash['OTHER_CFLAGS'].should == expected
end
it 'adds the dependent pods module map file to OTHER_CFLAGS' do
@pod_targets.each { |pt| pt.stubs(:defines_module? => true) }
@xcconfig = @generator.generate
expected = '$(inherited) -fmodule-map-file="${PODS_ROOT}/Headers/Private/BananaLib/BananaLib.modulemap" -isystem "${PODS_ROOT}/Headers/Public/BananaLib"'
@xcconfig.to_hash['OTHER_CFLAGS'].should == expected
end
......
......@@ -478,7 +478,6 @@ module Pod
group.children.map(&:display_name).sort.should == [
'BananaLib-Pods-SampleProject-dummy.m',
'BananaLib-Pods-SampleProject-prefix.pch',
'BananaLib-Pods-SampleProject.modulemap',
'BananaLib-Pods-SampleProject.xcconfig',
]
end
......@@ -490,7 +489,6 @@ module Pod
group.children.map(&:display_name).sort.should == [
'BananaLib-Pods-SampleProject-dummy.m',
'BananaLib-Pods-SampleProject-prefix.pch',
'BananaLib-Pods-SampleProject.modulemap',
'BananaLib-Pods-SampleProject.xcconfig',
]
end
......@@ -501,6 +499,17 @@ module Pod
group = @project['Pods/BananaLib/Support Files']
group.children.map(&:display_name).sort.should == [
'BananaLib-Pods-SampleProject-dummy.m',
'BananaLib-Pods-SampleProject.xcconfig',
]
end
it 'adds the module map when the target defines a module' do
@pod_target.stubs(:defines_module?).returns(true)
@installer.install!
group = @project['Pods/BananaLib/Support Files']
group.children.map(&:display_name).sort.should == [
'BananaLib-Pods-SampleProject-dummy.m',
'BananaLib-Pods-SampleProject-prefix.pch',
'BananaLib-Pods-SampleProject.modulemap',
'BananaLib-Pods-SampleProject.xcconfig',
]
......@@ -570,7 +579,6 @@ module Pod
group.children.map(&:display_name).sort.should == [
'BananaLib-dummy.m',
'BananaLib-prefix.pch',
'BananaLib.modulemap',
'BananaLib.xcconfig',
]
end
......@@ -581,6 +589,17 @@ module Pod
group = @project['Pods/BananaLib/Support Files']
group.children.map(&:display_name).sort.should == [
'BananaLib-dummy.m',
'BananaLib.xcconfig',
]
end
it 'adds the module map when the target defines a module' do
@pod_target.stubs(:defines_module?).returns(true)
@installer.install!
group = @project['Pods/BananaLib/Support Files']
group.children.map(&:display_name).sort.should == [
'BananaLib-dummy.m',
'BananaLib-prefix.pch',
'BananaLib.modulemap',
'BananaLib.xcconfig',
]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment