Skip to content

Commit

Permalink
[Analyzer] Ensure CLI dynamic lib warning only occurs when the CLI ta…
Browse files Browse the repository at this point in the history
…rget uses dynamic linkage for its dependencies

Closes #9498
  • Loading branch information
amorde committed Jan 26, 2020
1 parent e62532c commit 9e00467
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
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
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
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

0 comments on commit 9e00467

Please sign in to comment.