-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
SPM: allow podspecs to declare Swift Package Manager dependencies with spm_dependency #11953
Open
mfazekas
wants to merge
2
commits into
CocoaPods:master
Choose a base branch
from
mfazekas:podspec-spm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ gemspec | |
|
||
group :development do | ||
cp_gem 'claide', 'CLAide' | ||
cp_gem 'cocoapods-core', 'Core' | ||
# cp_gem 'cocoapods-core', 'Core' | ||
gem 'cocoapods-core', :git => 'https://github.com/mfazekas/Core', branch: 'podspec-spm' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be reverted before merge |
||
cp_gem 'cocoapods-deintegrate', 'cocoapods-deintegrate' | ||
cp_gem 'cocoapods-downloader', 'cocoapods-downloader' | ||
cp_gem 'cocoapods-plugins', 'cocoapods-plugins' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -193,6 +193,67 @@ def wire_target_dependencies(target_installation_results) | |||||||||
PodTargetDependencyInstaller.new(sandbox, pod_target_installation_results_hash, metadata_cache).install! | ||||||||||
end | ||||||||||
|
||||||||||
def _merge_spm_requirements(url, requirements) | ||||||||||
if requirements.count > 1 | ||||||||||
requirements.reduce(requirements.first) do |acc, req| | ||||||||||
if acc != req | ||||||||||
error "SPM dependencies with different requirements: #{requirements} for #{url} is not yet supported" | ||||||||||
end | ||||||||||
acc | ||||||||||
end | ||||||||||
else | ||||||||||
requirements.first | ||||||||||
end | ||||||||||
end | ||||||||||
|
||||||||||
def install_spm_dedpendecies(project, pod_targets) | ||||||||||
spm_dependencies = pod_targets.flat_map { |target| target.root_spec.consumer(target.platform).spm_dependencies } | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updating this line to get the dependencies on all the specs lets us define spm dependencies at the subspec level 🙂
Suggested change
|
||||||||||
spm_dependencies_by_url = spm_dependencies.group_by { |dep| dep[:url] } | ||||||||||
merged_spm_dependencies = spm_dependencies_by_url.map do |url, deps| | ||||||||||
[url, _merge_spm_requirements(url, deps.map { |dep| dep[:requirement] })] | ||||||||||
end | ||||||||||
|
||||||||||
spm_dependencies_by_url = merged_spm_dependencies.map do |url, requirement| | ||||||||||
[url, project.add_spm_dependency(url, requirement.to_h)] | ||||||||||
end | ||||||||||
|
||||||||||
spm_dependencies_by_url.to_h | ||||||||||
end | ||||||||||
|
||||||||||
def _spm_deps_workaround_for_swift(native_target) | ||||||||||
# Seems to be an XCode issue where subprojects SWITFT_INCLUDE_PATHS doesn't the added SPM dependency's products | ||||||||||
# without this Swift code trying to import the SPM dependency's product will fail with "No such module" | ||||||||||
search_path = '${SYMROOT}/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}/' | ||||||||||
native_target.build_configurations.each do |config| | ||||||||||
build_settings = native_target.build_settings(config.name) | ||||||||||
build_settings['SWIFT_INCLUDE_PATHS'] ||= ['$(inherited)'] | ||||||||||
unless build_settings['SWIFT_INCLUDE_PATHS'].include?(search_path) | ||||||||||
build_settings['SWIFT_INCLUDE_PATHS'].push(search_path) | ||||||||||
end | ||||||||||
end | ||||||||||
end | ||||||||||
|
||||||||||
def wire_target_spm_dependencies(target_installation_results, spm_dependencies_by_url) | ||||||||||
target_installation_results.pod_target_installation_results.each_value do |pod_target_installation_result| | ||||||||||
target = pod_target_installation_result.target | ||||||||||
spm_deps_to_wire = target.spec_consumers.flat_map(&:spm_dependencies) | ||||||||||
spm_deps_to_wire.each do |spm_dep| | ||||||||||
native_target = pod_target_installation_result.native_target | ||||||||||
project = native_target.project | ||||||||||
|
||||||||||
spm_dep[:products].each do |product_name| | ||||||||||
product_reference = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency) | ||||||||||
product_reference.product_name = product_name | ||||||||||
product_reference.package = spm_dependencies_by_url[spm_dep[:url]] | ||||||||||
|
||||||||||
native_target.package_product_dependencies << product_reference | ||||||||||
|
||||||||||
_spm_deps_workaround_for_swift(native_target) | ||||||||||
end | ||||||||||
end | ||||||||||
end | ||||||||||
end | ||||||||||
|
||||||||||
# @param [String] pod The root name of the development pod. | ||||||||||
# | ||||||||||
# @return [Boolean] whether the scheme for the given development pod should be | ||||||||||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule cocoapods-integration-specs
updated
27 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be reverted before merge