Commit 83787fab authored by Samuel Giddins's avatar Samuel Giddins

Ensure Swift static library pods work

parent 8c98adf3
......@@ -329,19 +329,41 @@ module Pod
build_settings['CONFIGURATION_BUILD_DIR'] = target.configuration_build_dir(CONFIGURATION_BUILD_DIR_VARIABLE)
end
module_map_files = []
unless dependent_targets.empty?
framework_search_paths = []
library_search_paths = []
swift_import_paths = []
dependent_targets.each do |dependent_target|
if dependent_target.requires_frameworks?
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}")
end
swift_import_paths << dependent_target.configuration_build_dir(CONFIGURATION_BUILD_DIR_VARIABLE)
end
build_settings['FRAMEWORK_SEARCH_PATHS'] = XCConfigHelper.quote(framework_search_paths.uniq)
build_settings['LIBRARY_SEARCH_PATHS'] = XCConfigHelper.quote(library_search_paths.uniq)
build_settings['SWIFT_INCLUDE_PATHS'] = XCConfigHelper.quote(swift_import_paths.uniq)
end
other_swift_flags = module_map_files.tap(&:uniq!).flat_map { |f| ['-Xcc', f] }
if target.is_a?(PodTarget) && !target.requires_frameworks?
# 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
# unconditionally set these, because of (the possibility of) having to add the pod targets own module map file
build_settings['OTHER_CFLAGS'] = module_map_files.join(' ')
build_settings['OTHER_SWIFT_FLAGS'] = other_swift_flags.join(' ')
build_settings
end
......
......@@ -27,6 +27,8 @@ 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
create_umbrella_header do |generator|
file_accessors = target.file_accessors
......@@ -47,9 +49,8 @@ module Pod
if target.static_framework?
create_build_phase_to_move_static_framework_archive
end
else
add_copy_module_map_build_phase
add_copy_umbrella_header_build_phase
elsif target.uses_swift?
add_swift_static_library_compatibility_header_phase
end
unless skip_pch?(target.non_test_specs)
path = target.prefix_header_path
......@@ -99,6 +100,11 @@ module Pod
if target.swift_version
settings['SWIFT_VERSION'] = target.swift_version
end
if target.requires_frameworks? || target.uses_swift?
settings['DEFINES_MODULE'] = 'YES'
end
settings
end
......@@ -589,10 +595,7 @@ module Pod
# @return [PBXFileReference] the file reference of the added file.
#
def add_file_to_support_group(path)
pod_name = target.pod_name
dir = target.support_files_dir
group = project.pod_support_files_group(pod_name, dir)
group.new_file(path)
support_files_group.new_file(path)
end
def apply_xcconfig_file_ref_to_resource_bundle_targets(resource_bundle_targets, xcconfig_file_ref)
......@@ -664,14 +667,6 @@ module Pod
copy_phase.symbol_dst_subfolder_spec = :products_directory
copy_phase.dst_path = "$(#{acl.upcase}_HEADERS_FOLDER_PATH)/#{sub_dir}"
copy_phase.add_file_reference(file_ref, true)
elsif acl != 'Project'
relative_path = file_ref.real_path.basename
copy_phase_name = "Copy #{acl} Headers"
copy_phase = native_target.copy_files_build_phases.find { |bp| bp.name == copy_phase_name } ||
native_target.new_copy_files_build_phase(copy_phase_name)
copy_phase.symbol_dst_subfolder_spec = :products_directory
copy_phase.dst_path = 'Headers/'
copy_phase.add_file_reference(file_ref, true)
else
build_file.settings ||= {}
build_file.settings['ATTRIBUTES'] = [acl]
......@@ -679,33 +674,28 @@ module Pod
end
def support_files_group
pod_name = target.pod_name
dir = target.support_files_dir
project.pod_support_files_group(pod_name, dir)
pod_name = target.pod_name
dir = target.support_files_dir
project.pod_support_files_group(pod_name, dir)
end
def add_copy_module_map_build_phase(path = target.module_map_path.relative_path_from(target.support_files_dir))
if !target.requires_frameworks? && !target.uses_swift?
file_ref = support_files_group.find_file_by_path(path.to_s)
copy_phase_name = 'Copy modulemap'
copy_phase = native_target.copy_files_build_phases.find { |bp| bp.name == copy_phase_name } ||
native_target.new_copy_files_build_phase(copy_phase_name)
copy_phase.symbol_dst_subfolder_spec = :products_directory
copy_phase.add_file_reference(file_ref, false)
end
end
# Adds a shell script phase, intended only for static library targets that contain swift,
# to copy the ObjC compatibility header (the -Swift.h file that the swift compiler generates)
# to the built products directory. Additionally, the script phase copies the module map, appending a `.Swift`
# submodule that references the (moved) compatibility header.
#
# @return [Void]
#
def add_swift_static_library_compatibility_header_phase
build_phase = native_target.new_shell_script_build_phase('Copy generated compatibility header')
build_phase.shell_script = <<-SH.strip_heredoc
COMPATIBILITY_HEADER_PATH="${BUILT_PRODUCTS_DIR}/Swift Compatibility Header/${PRODUCT_MODULE_NAME}-Swift.h"
MODULE_MAP_PATH="${BUILT_PRODUCTS_DIR}/${PRODUCT_MODULE_NAME}.modulemap"
# FIXME: Umbrella header should be copied as part of copy public headers?
def add_copy_umbrella_header_build_phase(path = target.umbrella_header_path.relative_path_from(target.support_files_dir))
if !target.requires_frameworks? && !target.uses_swift?
file_ref = support_files_group.find_file_by_path(path.to_s)
copy_phase_name = 'Copy umbrella header'
copy_phase = native_target.copy_files_build_phases.find { |bp| bp.name == copy_phase_name } ||
native_target.new_copy_files_build_phase(copy_phase_name)
copy_phase.symbol_dst_subfolder_spec = :products_directory
copy_phase.dst_path = 'Headers/'
copy_phase.add_file_reference(file_ref, false)
end
ditto "${DERIVED_SOURCES_DIR}/${PRODUCT_MODULE_NAME}-Swift.h" "${COMPATIBILITY_HEADER_PATH}"
ditto "${PODS_ROOT}/#{target.module_map_path.relative_path_from(target.sandbox.root)}" "${MODULE_MAP_PATH}"
printf "\\n\\nmodule ${PRODUCT_MODULE_NAME}.Swift {\\n header \\"${COMPATIBILITY_HEADER_PATH}\\"\\n requires objc\\n}\\n" >> "${MODULE_MAP_PATH}"
SH
end
#-----------------------------------------------------------------------#
......
......@@ -146,7 +146,7 @@ module Pod
end
it 'adds the sandbox public headers search paths to the xcconfig, with quotes, as system headers' do
expected = '$(inherited) -isystem "${PODS_ROOT}/Headers/Public/BananaLib"'
expected = '$(inherited) -fmodule-map-file="${PODS_ROOT}/Target Support Files/BananaLib/BananaLib.modulemap" -isystem "${PODS_ROOT}/Headers/Public/BananaLib"'
@xcconfig.to_hash['OTHER_CFLAGS'].should == expected
end
......
......@@ -479,6 +479,7 @@ module Pod
'BananaLib-Pods-SampleProject-dummy.m',
'BananaLib-Pods-SampleProject-prefix.pch',
'BananaLib-Pods-SampleProject.xcconfig',
'BananaLib.modulemap',
]
end
......@@ -490,6 +491,7 @@ module Pod
'BananaLib-Pods-SampleProject-dummy.m',
'BananaLib-Pods-SampleProject-prefix.pch',
'BananaLib-Pods-SampleProject.xcconfig',
'BananaLib.modulemap',
]
end
......@@ -500,6 +502,7 @@ module Pod
group.children.map(&:display_name).sort.should == [
'BananaLib-Pods-SampleProject-dummy.m',
'BananaLib-Pods-SampleProject.xcconfig',
'BananaLib.modulemap',
]
end
......@@ -567,6 +570,7 @@ module Pod
group.children.map(&:display_name).sort.should == [
'BananaLib-dummy.m',
'BananaLib-prefix.pch',
'BananaLib.modulemap',
'BananaLib.xcconfig',
]
end
......@@ -577,6 +581,7 @@ module Pod
group = @project['Pods/BananaLib/Support Files']
group.children.map(&:display_name).sort.should == [
'BananaLib-dummy.m',
'BananaLib.modulemap',
'BananaLib.xcconfig',
]
end
......
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