Skip to content
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

[Analyzer] Ensure CLI dynamic lib warning only occurs when the CLI target uses dynamic linkage for its dependencies #9505

Merged
merged 1 commit into from
Jan 27, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Igor Makarov](https://github.com/igor-makarov)
[#9431](https://github.com/CocoaPods/CocoaPods/pull/9431)

* Fix an issue that caused an incorrect warning to be emitted for CLI targets with static libraries
[Eric Amorde](https://github.com/amorde)
[#9498](https://github.com/CocoaPods/CocoaPods/issues/9498)

## 1.9.0.beta.2 (2019-12-17)

##### Enhancements
Expand Down
15 changes: 8 additions & 7 deletions lib/cocoapods/installer/analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,16 @@ def embedded_target_pod_targets_by_host(aggregate_target, embedded_aggregate_tar
#
def analyze_host_targets_in_podfile(aggregate_targets, embedded_aggregate_targets)
target_definitions_by_uuid = {}
cli_host_with_frameworks = []
cli_host_with_dynamic_linkage = []
cli_product_type = 'com.apple.product-type.tool'
# Collect aggregate target definitions by uuid to later lookup host target
# definitions and verify their compatibility with their embedded targets
aggregate_targets.each do |target|
target.user_targets.each do |user_target|
target_definitions_by_uuid[user_target.uuid] = target.target_definition
if user_target.product_type == cli_product_type
cli_host_with_frameworks << user_target
target_definition = target.target_definition
target_definitions_by_uuid[user_target.uuid] = target_definition
if user_target.product_type == cli_product_type && target_definition.build_type.linkage == :dynamic
cli_host_with_dynamic_linkage << user_target
end
end
end
Expand All @@ -368,10 +369,10 @@ def analyze_host_targets_in_podfile(aggregate_targets, embedded_aggregate_target
end
end

unless cli_host_with_frameworks.empty?
UI.warn "The Podfile contains command line tool target(s) (#{cli_host_with_frameworks.map(&:name).to_sentence}) which are attempting to integrate dynamic frameworks." \
unless cli_host_with_dynamic_linkage.empty?
UI.warn "The Podfile contains command line tool target(s) (#{cli_host_with_dynamic_linkage.map(&:name).to_sentence}) which are attempting to integrate dynamic frameworks or libraries." \
"\n" \
'This may not behave as expected, because command line tools are usually distributed as a single binary and cannot contain their own dynamic frameworks.'
'This may not behave as expected, because command line tools are usually distributed as a single binary and cannot contain their own dynamic dependencies.'
end

unless embedded_targets_missing_hosts.empty?
Expand Down
17 changes: 16 additions & 1 deletion spec/unit/installer/analyzer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2006,7 +2006,22 @@ module Pod
end
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile)
analyzer.analyze
UI.warnings.should.match /The Podfile contains command line tool target\(s\) \(SampleCommandLineTool\) which are attempting to integrate dynamic frameworks\./
UI.warnings.should.match /The Podfile contains command line tool target\(s\) \(SampleCommandLineTool\) which are attempting to integrate dynamic frameworks or libraries\./
end

it 'does not warn when using static libraries with CLI targets' do
project_path = fixture('Sample Extensions Project/Sample Extensions Project')
podfile = Pod::Podfile.new do
source SpecHelper.test_repo_url
platform :ios, '8.0'
project project_path
target 'SampleCommandLineTool' do
pod 'monkey'
end
end
analyzer = Pod::Installer::Analyzer.new(config.sandbox, podfile)
analyzer.analyze
UI.warnings.should.be.empty?
end

it 'raises when the extension calls use_frameworks!, but the host target does not' do
Expand Down