8000 [PodTargetInstaller] Allow swift static frameworks to have custom module maps by segiddins · Pull Request #8278 · CocoaPods/CocoaPods · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[PodTargetInstaller] Allow swift static frameworks to have custom module maps #8278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,10 @@ def install!
create_info_plist_file(target.info_plist_path, native_target, target.version, target.platform)
end
create_build_phase_to_symlink_header_folders(native_target)
elsif target.uses_swift?
add_swift_static_library_compatibility_header_phase(native_target)
end

if target.build_as_library? && target.uses_swift?
add_swift_library_compatibility_header_phase(native_target)
end

unless skip_pch?(target.library_specs)
Expand Down Expand Up @@ -923,7 +925,7 @@ def add_placeholder_target
native_target
end

# Adds a shell script phase, intended only for static library targets that contain swift,
# Adds a shell script phase, intended only for 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. Since the module map has been moved, the umbrella header
Expand All @@ -934,7 +936,7 @@ def add_placeholder_target
#
# @return [Void]
#
def add_swift_static_library_compatibility_header_phase(native_target)
def add_swift_library_compatibility_header_phase(native_target)
if custom_module_map
raise Informative, 'Using Swift static libraries with custom module maps is currently not supported. ' \
"Please build `#{target.label}` as a framework or remove the custom module map."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,44 @@ class PodsProjectGenerator
eos
end
end

it 'adds swift compatibility header phase for swift static libraries' do
@watermelon_pod_target.stubs(:build_type => Target::BuildType.static_library, :uses_swift? => true)

@installer.install!

native_target = @project.targets.find { |t| t.name == @watermelon_pod_target.label }
compatibility_header_phase = native_target.build_phases.find { |ph| ph.display_name == 'Copy generated compatibility header' }
compatibility_header_phase.shell_script.should == <<-'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"

ditto "${DERIVED_SOURCES_DIR}/${PRODUCT_MODULE_NAME}-Swift.h" "${COMPATIBILITY_HEADER_PATH}"
ditto "${PODS_ROOT}/Headers/Public/WatermelonLib/WatermelonLib.modulemap" "${MODULE_MAP_PATH}"
ditto "${PODS_ROOT}/Headers/Public/WatermelonLib/WatermelonLib-umbrella.h" "${BUILT_PRODUCTS_DIR}"
printf "\n\nmodule ${PRODUCT_MODULE_NAME}.Swift {\n header \"${COMPATIBILITY_HEADER_PATH}\"\n requires objc\n}\n" >> "${MODULE_MAP_PATH}"
SH
compatibility_header_phase.input_paths.should == %w(${DERIVED_SOURCES_DIR}/${PRODUCT_MODULE_NAME}-Swift.h ${PODS_ROOT}/Headers/Public/WatermelonLib/WatermelonLib.modulemap ${PODS_ROOT}/Headers/Public/WatermelonLib/WatermelonLib-umbrella.h)
compatibility_header_phase.output_paths.should == %w(${BUILT_PRODUCTS_DIR}/${PRODUCT_MODULE_NAME}.modulemap ${BUILT_PRODUCTS_DIR}/WatermelonLib-umbrella.h ${BUILT_PRODUCTS_DIR}/Swift\ Compatibility\ Header/${PRODUCT_MODULE_NAME}-Swift.h)
end

it 'does not add swift compatibility header phase for swift static frameworks' do
@watermelon_pod_target.stubs(:build_type => Target::BuildType.static_framework, :uses_swift? => true)

@installer.install!

native_target = @project.targets.find { |t| t.name == @watermelon_pod_target.label }
compatibility_header_phase = native_target.build_phases.find { |ph| ph.display_name == 'Copy generated compatibility header' }
compatibility_header_phase.should.be.nil
end

it 'raises for swift static libraries with custom module maps' do
@watermelon_pod_target.stubs(:build_type => Target::BuildType.static_library, :uses_swift? => true)
@installer.stubs(:custom_module_map => mock('custom_module_map', :read => ''))

e = ->() { @installer.install! }.should.raise(Informative)
e.message.should.include '[!] Using Swift static libraries with custom module maps is currently not supported. Please build `WatermelonLib` as a framework or remove the custom module map.'
end
end

describe 'test other files under sources' do
Expand Down
0