Commit 73ef2fdf authored by Dimitris Koutsogiorgas's avatar Dimitris Koutsogiorgas Committed by GitHub

Merge pull request #6477 from dnkoutso/better-static-linking

Fix integration with vendored static frameworks and libraries
parents 514fce67 3d85899c
...@@ -14,6 +14,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -14,6 +14,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### Bug Fixes ##### Bug Fixes
* Fix integration with vendored static frameworks and libraries.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#6477](https://github.com/CocoaPods/CocoaPods/pull/6477)
* Use `${SRCROOT}` rather than `${PODS_ROOT}` in the generated manifest lock script phase. * Use `${SRCROOT}` rather than `${PODS_ROOT}` in the generated manifest lock script phase.
[Dimitris Koutsogiorgas](https://github.com/dnkoutso) [Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#5499](https://github.com/CocoaPods/CocoaPods/issues/5499) [#5499](https://github.com/CocoaPods/CocoaPods/issues/5499)
......
...@@ -103,13 +103,34 @@ module Pod ...@@ -103,13 +103,34 @@ module Pod
# #
def self.add_static_dependency_build_settings(aggregate_target, pod_target, xcconfig, file_accessor) def self.add_static_dependency_build_settings(aggregate_target, pod_target, xcconfig, file_accessor)
file_accessor.vendored_static_frameworks.each do |vendored_static_framework| file_accessor.vendored_static_frameworks.each do |vendored_static_framework|
if aggregate_target.nil? || aggregate_target.target_definition.inheritance != 'search_paths' adds_other_ldflags = XCConfigHelper.links_static_dependency?(aggregate_target, pod_target)
XCConfigHelper.add_framework_build_settings(vendored_static_framework, xcconfig, pod_target.sandbox.root) XCConfigHelper.add_framework_build_settings(vendored_static_framework, xcconfig, pod_target.sandbox.root, adds_other_ldflags)
end
end end
file_accessor.vendored_static_libraries.each do |vendored_static_library| file_accessor.vendored_static_libraries.each do |vendored_static_library|
XCConfigHelper.add_library_build_settings(vendored_static_library, xcconfig, pod_target.sandbox.root) adds_other_ldflags = XCConfigHelper.links_static_dependency?(aggregate_target, pod_target)
XCConfigHelper.add_library_build_settings(vendored_static_library, xcconfig, pod_target.sandbox.root, adds_other_ldflags)
end
end
# @param [AggregateTarget] aggregate_target
# The aggregate target, may be nil.
#
# @param [PodTarget] pod_target
# The pod target to link or not.
#
# @return [Boolean] Whether static dependency should be added to the 'OTHER_LDFLAGS'
# 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 end
false
end end
# Adds build settings for dynamic vendored frameworks and libraries. # Adds build settings for dynamic vendored frameworks and libraries.
...@@ -165,13 +186,13 @@ module Pod ...@@ -165,13 +186,13 @@ module Pod
# #
# @return [void] # @return [void]
# #
def self.add_framework_build_settings(framework_path, xcconfig, sandbox_root) def self.add_framework_build_settings(framework_path, xcconfig, sandbox_root, include_other_ldflags = true)
name = File.basename(framework_path, '.framework') name = File.basename(framework_path, '.framework')
dirname = '${PODS_ROOT}/' + framework_path.dirname.relative_path_from(sandbox_root).to_s dirname = '${PODS_ROOT}/' + framework_path.dirname.relative_path_from(sandbox_root).to_s
build_settings = { build_settings = {
'OTHER_LDFLAGS' => "-framework #{name}",
'FRAMEWORK_SEARCH_PATHS' => quote([dirname]), 'FRAMEWORK_SEARCH_PATHS' => quote([dirname]),
} }
build_settings['OTHER_LDFLAGS'] = "-framework #{name}" if include_other_ldflags
xcconfig.merge!(build_settings) xcconfig.merge!(build_settings)
end end
...@@ -189,14 +210,14 @@ module Pod ...@@ -189,14 +210,14 @@ module Pod
# #
# @return [void] # @return [void]
# #
def self.add_library_build_settings(library_path, xcconfig, sandbox_root) def self.add_library_build_settings(library_path, xcconfig, sandbox_root, include_other_ldflags = true)
extension = File.extname(library_path) extension = File.extname(library_path)
name = File.basename(library_path, extension).sub(/\Alib/, '') name = File.basename(library_path, extension).sub(/\Alib/, '')
dirname = '${PODS_ROOT}/' + library_path.dirname.relative_path_from(sandbox_root).to_s dirname = '${PODS_ROOT}/' + library_path.dirname.relative_path_from(sandbox_root).to_s
build_settings = { build_settings = {
'OTHER_LDFLAGS' => "-l#{name}",
'LIBRARY_SEARCH_PATHS' => '$(inherited) ' + quote([dirname]), 'LIBRARY_SEARCH_PATHS' => '$(inherited) ' + quote([dirname]),
} }
build_settings['OTHER_LDFLAGS'] = "-l#{name}" if include_other_ldflags
xcconfig.merge!(build_settings) xcconfig.merge!(build_settings)
end end
......
...@@ -233,12 +233,26 @@ module Pod ...@@ -233,12 +233,26 @@ module Pod
end end
it 'should not include static framework other ld flags when inheriting search paths' do it 'should not include static framework other ld flags when inheriting search paths' do
target_definition = stub(:inheritance => 'search_paths') target_definition = stub(:inheritance => 'search_paths', :non_inherited_dependencies => [])
aggregate_target = stub(:target_definition => target_definition) aggregate_target = stub(:target_definition => target_definition, :pod_targets => [])
pod_target = stub(:sandbox => config.sandbox) pod_target = stub(:sandbox => config.sandbox)
xcconfig = Xcodeproj::Config.new xcconfig = Xcodeproj::Config.new
@sut.add_static_dependency_build_settings(aggregate_target, pod_target, xcconfig, @accessor) @sut.add_static_dependency_build_settings(aggregate_target, pod_target, xcconfig, @accessor)
xcconfig.to_hash['OTHER_LDFLAGS'].should == '-l"Bananalib"' xcconfig.to_hash['LIBRARY_SEARCH_PATHS'].should == '$(inherited) "${PODS_ROOT}/../../spec/fixtures/banana-lib"'
xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should == '"${PODS_ROOT}/../../spec/fixtures/banana-lib"'
xcconfig.to_hash['OTHER_LDFLAGS'].should.be.nil
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])
pod_target = stub(:name => 'BananaLib', :sandbox => config.sandbox)
aggregate_target = stub(:target_definition => target_definition, :pod_targets => [pod_target])
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"'
xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should == '"${PODS_ROOT}/../../spec/fixtures/banana-lib"'
xcconfig.to_hash['OTHER_LDFLAGS'].should == '-l"Bananalib" -framework "Bananalib"'
end end
it 'should include static framework other ld flags when not inheriting search paths' do it 'should include static framework other ld flags when not inheriting search paths' do
...@@ -247,6 +261,8 @@ module Pod ...@@ -247,6 +261,8 @@ module Pod
pod_target = stub(:sandbox => config.sandbox) pod_target = stub(:sandbox => config.sandbox)
xcconfig = Xcodeproj::Config.new xcconfig = Xcodeproj::Config.new
@sut.add_static_dependency_build_settings(aggregate_target, pod_target, xcconfig, @accessor) @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"'
xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should == '"${PODS_ROOT}/../../spec/fixtures/banana-lib"'
xcconfig.to_hash['OTHER_LDFLAGS'].should == '-l"Bananalib" -framework "Bananalib"' xcconfig.to_hash['OTHER_LDFLAGS'].should == '-l"Bananalib" -framework "Bananalib"'
end end
...@@ -254,6 +270,8 @@ module Pod ...@@ -254,6 +270,8 @@ module Pod
pod_target = stub(:sandbox => config.sandbox) pod_target = stub(:sandbox => config.sandbox)
xcconfig = Xcodeproj::Config.new xcconfig = Xcodeproj::Config.new
@sut.add_static_dependency_build_settings(nil, pod_target, xcconfig, @accessor) @sut.add_static_dependency_build_settings(nil, pod_target, xcconfig, @accessor)
xcconfig.to_hash['LIBRARY_SEARCH_PATHS'].should == '$(inherited) "${PODS_ROOT}/../../spec/fixtures/banana-lib"'
xcconfig.to_hash['FRAMEWORK_SEARCH_PATHS'].should == '"${PODS_ROOT}/../../spec/fixtures/banana-lib"'
xcconfig.to_hash['OTHER_LDFLAGS'].should == '-l"Bananalib" -framework "Bananalib"' xcconfig.to_hash['OTHER_LDFLAGS'].should == '-l"Bananalib" -framework "Bananalib"'
end end
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