Correctly handle `OTHER_LDFLAGS` for targets with inherit search paths and source pods.

parent d597f715
......@@ -14,6 +14,11 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### Bug Fixes
* Correctly handle `OTHER_LDFLAGS` for targets with inherit search paths and source pods.
[Justin Martin](https://github.com/justinseanmartin)
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#6481](https://github.com/CocoaPods/CocoaPods/pull/6481)
* Do not generate `UIRequiredDeviceCapabilities` for `tvOS` Info.plists.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#6193](https://github.com/CocoaPods/CocoaPods/issues/6193)
......
......@@ -198,11 +198,11 @@ module Pod
if pod_target.requires_frameworks?
%(-framework "#{pod_target.product_basename}")
else
%(-l "#{pod_target.product_basename}")
%(-l "#{pod_target.product_basename}") if XCConfigHelper.links_dependency?(target, pod_target)
end
end
@xcconfig.merge!('OTHER_LDFLAGS' => other_ld_flags.join(' '))
@xcconfig.merge!('OTHER_LDFLAGS' => other_ld_flags.compact.join(' '))
end
# Ensure to add the default linker run path search paths as they could
......
......@@ -103,11 +103,11 @@ module Pod
#
def self.add_static_dependency_build_settings(aggregate_target, pod_target, xcconfig, file_accessor)
file_accessor.vendored_static_frameworks.each do |vendored_static_framework|
adds_other_ldflags = XCConfigHelper.links_static_dependency?(aggregate_target, pod_target)
adds_other_ldflags = XCConfigHelper.links_dependency?(aggregate_target, pod_target)
XCConfigHelper.add_framework_build_settings(vendored_static_framework, xcconfig, pod_target.sandbox.root, adds_other_ldflags)
end
file_accessor.vendored_static_libraries.each do |vendored_static_library|
adds_other_ldflags = XCConfigHelper.links_static_dependency?(aggregate_target, pod_target)
adds_other_ldflags = XCConfigHelper.links_dependency?(aggregate_target, pod_target)
XCConfigHelper.add_library_build_settings(vendored_static_library, xcconfig, pod_target.sandbox.root, adds_other_ldflags)
end
end
......@@ -122,15 +122,10 @@ module Pod
# of the aggregate target. Aggregate targets that inherit search paths will only link
# if the target has explicitly declared the pod dependency.
#
def self.links_static_dependency?(aggregate_target, pod_target)
return true if aggregate_target.nil? || aggregate_target.target_definition.inheritance != 'search_paths'
# Only link this static dependency if its explicitly defined for this target.
aggregate_target.target_definition.non_inherited_dependencies.each do |d|
if d.name == pod_target.name
return true
end
end
false
def self.links_dependency?(aggregate_target, pod_target)
return true if aggregate_target.nil? || aggregate_target.target_definition.inheritance == 'complete'
targets = aggregate_target.pod_targets - aggregate_target.search_paths_aggregate_targets.flat_map(&:pod_targets)
targets.include?(pod_target)
end
# Adds build settings for dynamic vendored frameworks and libraries.
......
......@@ -233,8 +233,8 @@ module Pod
end
it 'should not include static framework other ld flags when inheriting search paths' do
target_definition = stub(:inheritance => 'search_paths', :non_inherited_dependencies => [])
aggregate_target = stub(:target_definition => target_definition, :pod_targets => [])
target_definition = stub(:inheritance => 'search_paths')
aggregate_target = stub(:target_definition => target_definition, :pod_targets => [], :search_paths_aggregate_targets => [])
pod_target = stub(:sandbox => config.sandbox)
xcconfig = Xcodeproj::Config.new
@sut.add_static_dependency_build_settings(aggregate_target, pod_target, xcconfig, @accessor)
......@@ -244,10 +244,9 @@ module Pod
end
it 'should include static framework other ld flags when inheriting search paths but explicitly declared' do
dependency = stub(:name => 'BananaLib')
target_definition = stub(:inheritance => 'search_paths', :non_inherited_dependencies => [dependency])
target_definition = stub(:inheritance => 'search_paths')
pod_target = stub(:name => 'BananaLib', :sandbox => config.sandbox)
aggregate_target = stub(:target_definition => target_definition, :pod_targets => [pod_target])
aggregate_target = stub(:target_definition => target_definition, :pod_targets => [pod_target], :search_paths_aggregate_targets => [])
xcconfig = Xcodeproj::Config.new
@sut.add_static_dependency_build_settings(aggregate_target, pod_target, xcconfig, @accessor)
xcconfig.to_hash['LIBRARY_SEARCH_PATHS'].should == '$(inherited) "${PODS_ROOT}/../../spec/fixtures/banana-lib"'
......@@ -274,6 +273,60 @@ module Pod
xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should == '"${PODS_ROOT}/../../spec/fixtures/banana-lib"'
xcconfig.to_hash['OTHER_LDFLAGS'].should == '-l"Bananalib" -framework "Bananalib"'
end
it 'should link static dependency for pod targets' do
pod_target = stub(:name => 'BananaLib', :sandbox => config.sandbox)
@sut.links_dependency?(nil, pod_target).should.be.true
end
it 'should link static dependency when target explicitly specifies it' do
target_definition = stub(:inheritance => 'complete')
pod_target = stub(:name => 'BananaLib', :sandbox => config.sandbox)
aggregate_target = stub(:target_definition => target_definition, :pod_targets => [pod_target], :search_paths_aggregate_targets => [])
@sut.links_dependency?(aggregate_target, pod_target).should.be.true
end
it 'should link static dependency when target explicitly specifies it even with search paths' do
target_definition = stub(:inheritance => 'search_paths')
pod_target = stub(:name => 'BananaLib', :sandbox => config.sandbox)
aggregate_target = stub(:target_definition => target_definition, :pod_targets => [pod_target], :search_paths_aggregate_targets => [])
@sut.links_dependency?(aggregate_target, pod_target).should.be.true
end
it 'should not link static dependency when inheriting search paths and parent includes dependency' do
parent_target_definition = stub
child_target_definition = stub(:inheritance => 'search_paths')
pod_target = stub(:name => 'BananaLib', :sandbox => config.sandbox)
parent_aggregate_target = stub(:target_definition => parent_target_definition, :pod_targets => [pod_target], :search_paths_aggregate_targets => [])
child_aggregate_target = stub(:target_definition => child_target_definition, :pod_targets => [], :search_paths_aggregate_targets => [parent_aggregate_target])
@sut.links_dependency?(child_aggregate_target, pod_target).should.be.false
end
it 'should link static transitive dependencies if the parent does not link them' do
child_pod_target = stub(:name => 'ChildPod', :sandbox => config.sandbox)
parent_pod_target = stub(:name => 'ParentPod', :sandbox => config.sandbox, :dependent_targets => [child_pod_target])
parent_target_definition = stub
child_target_definition = stub(:inheritance => 'search_paths')
parent_aggregate_target = stub(:target_definition => parent_target_definition, :pod_targets => [], :search_paths_aggregate_targets => [])
child_aggregate_target = stub(:target_definition => child_target_definition, :pod_targets => [parent_pod_target, child_pod_target], :search_paths_aggregate_targets => [parent_aggregate_target])
@sut.links_dependency?(child_aggregate_target, child_pod_target).should.be.true
@sut.links_dependency?(child_aggregate_target, parent_pod_target).should.be.true
end
it 'should link static only transitive dependencies that the parent does not link' do
child_pod_target = stub(:name => 'ChildPod', :sandbox => config.sandbox)
parent_pod_target = stub(:name => 'ParentPod', :sandbox => config.sandbox, :dependent_targets => [child_pod_target])
parent_target_definition = stub
child_target_definition = stub(:inheritance => 'search_paths')
parent_aggregate_target = stub(:target_definition => parent_target_definition, :pod_targets => [child_pod_target], :search_paths_aggregate_targets => [])
child_aggregate_target = stub(:target_definition => child_target_definition, :pod_targets => [parent_pod_target, child_pod_target], :search_paths_aggregate_targets => [parent_aggregate_target])
@sut.links_dependency?(child_aggregate_target, child_pod_target).should.be.false
@sut.links_dependency?(child_aggregate_target, parent_pod_target).should.be.true
end
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