Commit be84c8df authored by Michael Melanson's avatar Michael Melanson Committed by Kyle Fuller

[CocoaPods/CocoaPods#1249] Separate header paths for different targets in .xcconfig files.

parent 4c4895f8
...@@ -178,6 +178,10 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides ...@@ -178,6 +178,10 @@ To install or update CocoaPods see this [guide](http://docs.cocoapods.org/guides
[Kra Larivain](https://github.com/olarivain) [Kra Larivain](https://github.com/olarivain)
[#2532](https://github.com/CocoaPods/CocoaPods/pull/2532) [#2532](https://github.com/CocoaPods/CocoaPods/pull/2532)
* Proper scoping of header search paths to the target platform.
[Michael Melanson](https://github.com/michaelmelanson)
[#1249](https://github.com/CocoaPods/CocoaPods/issues/1249)
## 0.34.1 ## 0.34.1
......
...@@ -47,11 +47,11 @@ module Pod ...@@ -47,11 +47,11 @@ module Pod
# @return [Xcodeproj::Config] # @return [Xcodeproj::Config]
# #
def generate def generate
header_search_path_flags = target.sandbox.public_headers.search_paths header_search_path_flags = target.sandbox.public_headers.search_paths(target.platform)
@xcconfig = Xcodeproj::Config.new( @xcconfig = Xcodeproj::Config.new(
'OTHER_LDFLAGS' => XCConfigHelper.default_ld_flags(target), 'OTHER_LDFLAGS' => XCConfigHelper.default_ld_flags(target),
'OTHER_LIBTOOLFLAGS' => '$(OTHER_LDFLAGS)', 'OTHER_LIBTOOLFLAGS' => '$(OTHER_LDFLAGS)',
'HEADER_SEARCH_PATHS' => XCConfigHelper.quote(target.sandbox.public_headers.search_paths), 'HEADER_SEARCH_PATHS' => XCConfigHelper.quote(header_search_path_flags),
'PODS_ROOT' => target.relative_pods_root, 'PODS_ROOT' => target.relative_pods_root,
'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1', 'GCC_PREPROCESSOR_DEFINITIONS' => '$(inherited) COCOAPODS=1',
'OTHER_CFLAGS' => '$(inherited) ' + XCConfigHelper.quote(header_search_path_flags, '-isystem') 'OTHER_CFLAGS' => '$(inherited) ' + XCConfigHelper.quote(header_search_path_flags, '-isystem')
......
...@@ -45,7 +45,10 @@ module Pod ...@@ -45,7 +45,10 @@ module Pod
# @return [Xcodeproj::Config] # @return [Xcodeproj::Config]
# #
def generate def generate
search_paths = target.build_headers.search_paths.concat(target.sandbox.public_headers.search_paths) target_search_paths = target.build_headers.search_paths(target.platform)
sandbox_search_paths = target.sandbox.public_headers.search_paths(target.platform)
search_paths = target_search_paths.concat(sandbox_search_paths).uniq
config = { config = {
'OTHER_LDFLAGS' => XCConfigHelper.default_ld_flags(target), 'OTHER_LDFLAGS' => XCConfigHelper.default_ld_flags(target),
'PODS_ROOT' => '${SRCROOT}', 'PODS_ROOT' => '${SRCROOT}',
......
...@@ -114,15 +114,15 @@ module Pod ...@@ -114,15 +114,15 @@ module Pod
libraries.each do |library| libraries.each do |library|
library.file_accessors.each do |file_accessor| library.file_accessors.each do |file_accessor|
headers_sandbox = Pathname.new(file_accessor.spec.root.name) headers_sandbox = Pathname.new(file_accessor.spec.root.name)
library.build_headers.add_search_path(headers_sandbox) library.build_headers.add_search_path(headers_sandbox, library.platform)
sandbox.public_headers.add_search_path(headers_sandbox) sandbox.public_headers.add_search_path(headers_sandbox, library.platform)
header_mappings(headers_sandbox, file_accessor, file_accessor.headers).each do |namespaced_path, files| header_mappings(headers_sandbox, file_accessor, file_accessor.headers).each do |namespaced_path, files|
library.build_headers.add_files(namespaced_path, files) library.build_headers.add_files(namespaced_path, files, library.platform)
end end
header_mappings(headers_sandbox, file_accessor, file_accessor.public_headers).each do |namespaced_path, files| header_mappings(headers_sandbox, file_accessor, file_accessor.public_headers).each do |namespaced_path, files|
sandbox.public_headers.add_files(namespaced_path, files) sandbox.public_headers.add_files(namespaced_path, files, library.platform)
end end
end end
end end
......
...@@ -23,16 +23,18 @@ module Pod ...@@ -23,16 +23,18 @@ module Pod
def initialize(sandbox, relative_path) def initialize(sandbox, relative_path)
@sandbox = sandbox @sandbox = sandbox
@relative_path = relative_path @relative_path = relative_path
@search_paths = [relative_path] @search_paths = []
end end
# @return [Array<String>] All the search paths of the header directory in # @return [Array<String>] All the search paths of the header directory in
# xcconfig format. The paths are specified relative to the pods # xcconfig format. The paths are specified relative to the pods
# root with the `${PODS_ROOT}` variable. # root with the `${PODS_ROOT}` variable.
# #
def search_paths def search_paths(platform)
platform_search_paths = @search_paths.select { |entry| entry[:platform] == platform }
headers_dir = root.relative_path_from(sandbox.root).dirname headers_dir = root.relative_path_from(sandbox.root).dirname
@search_paths.uniq.map { |path| "${PODS_ROOT}/#{headers_dir}/#{path}" } ["${PODS_ROOT}/#{headers_dir}/#{@relative_path}"] + platform_search_paths.uniq.map { |entry| "${PODS_ROOT}/#{headers_dir}/#{entry[:path]}" }
end end
# Removes the directory as it is regenerated from scratch during each # Removes the directory as it is regenerated from scratch during each
...@@ -64,8 +66,8 @@ module Pod ...@@ -64,8 +66,8 @@ module Pod
# #
# @return [Pathname] # @return [Pathname]
# #
def add_files(namespace, relative_header_paths) def add_files(namespace, relative_header_paths, platform)
add_search_path(namespace) add_search_path(namespace, platform)
namespaced_path = root + namespace namespaced_path = root + namespace
namespaced_path.mkpath unless File.exist?(namespaced_path) namespaced_path.mkpath unless File.exist?(namespaced_path)
...@@ -84,10 +86,13 @@ module Pod ...@@ -84,10 +86,13 @@ module Pod
# @param [Pathname] path # @param [Pathname] path
# the path tho add. # the path tho add.
# #
# @param [String] platform
# the platform the search path applies to
#
# @return [void] # @return [void]
# #
def add_search_path(path) def add_search_path(path, platform)
@search_paths << Pathname.new(@relative_path) + path @search_paths << {:platform => platform, :path => (Pathname.new(@relative_path) + path) }
end end
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
......
...@@ -58,12 +58,12 @@ module Pod ...@@ -58,12 +58,12 @@ module Pod
end end
it 'adds the sandbox public headers search paths to the xcconfig, with quotes, as header search paths' do it 'adds the sandbox public headers search paths to the xcconfig, with quotes, as header search paths' do
expected = "\"#{config.sandbox.public_headers.search_paths.join('" "')}\"" expected = "\"#{config.sandbox.public_headers.search_paths(:ios).join('" "')}\""
@xcconfig.to_hash['HEADER_SEARCH_PATHS'].should == expected @xcconfig.to_hash['HEADER_SEARCH_PATHS'].should == expected
end end
it 'adds the sandbox public headers search paths to the xcconfig, with quotes, as system headers' do it 'adds the sandbox public headers search paths to the xcconfig, with quotes, as system headers' do
expected = "$(inherited) -isystem \"#{config.sandbox.public_headers.search_paths.join('" -isystem "')}\"" expected = "$(inherited) -isystem \"#{config.sandbox.public_headers.search_paths(:ios).join('" -isystem "')}\""
@xcconfig.to_hash['OTHER_CFLAGS'].should == expected @xcconfig.to_hash['OTHER_CFLAGS'].should == expected
end end
......
...@@ -44,8 +44,8 @@ module Pod ...@@ -44,8 +44,8 @@ module Pod
end end
it 'adds the library build headers and public headers search paths to the xcconfig, with quotes' do it 'adds the library build headers and public headers search paths to the xcconfig, with quotes' do
private_headers = "\"#{@pod_target.build_headers.search_paths.join('" "')}\"" private_headers = "\"#{@pod_target.build_headers.search_paths(:ios).join('" "')}\""
public_headers = "\"#{config.sandbox.public_headers.search_paths.join('" "')}\"" public_headers = "\"#{config.sandbox.public_headers.search_paths(:ios).join('" "')}\""
@xcconfig.to_hash['HEADER_SEARCH_PATHS'].should.include private_headers @xcconfig.to_hash['HEADER_SEARCH_PATHS'].should.include private_headers
@xcconfig.to_hash['HEADER_SEARCH_PATHS'].should.include public_headers @xcconfig.to_hash['HEADER_SEARCH_PATHS'].should.include public_headers
end end
......
...@@ -6,6 +6,7 @@ module Pod ...@@ -6,6 +6,7 @@ module Pod
before do before do
@file_accessor = fixture_file_accessor('banana-lib/BananaLib.podspec') @file_accessor = fixture_file_accessor('banana-lib/BananaLib.podspec')
@pod_target = PodTarget.new([], nil, config.sandbox) @pod_target = PodTarget.new([], nil, config.sandbox)
@pod_target.stubs(:platform).returns(Platform.new(:ios, '6.0'))
@pod_target.file_accessors = [@file_accessor] @pod_target.file_accessors = [@file_accessor]
@project = Project.new(config.sandbox.project_path) @project = Project.new(config.sandbox.project_path)
@project.add_pod_group('BananaLib', fixture('banana-lib')) @project.add_pod_group('BananaLib', fixture('banana-lib'))
......
...@@ -22,7 +22,7 @@ module Pod ...@@ -22,7 +22,7 @@ module Pod
relative_header_paths.each do |path| relative_header_paths.each do |path|
File.open(@sandbox.root + path, 'w') { |file| file.write('hello') } File.open(@sandbox.root + path, 'w') { |file| file.write('hello') }
end end
symlink_paths = @header_dir.add_files(namespace_path, relative_header_paths) symlink_paths = @header_dir.add_files(namespace_path, relative_header_paths, :fake_platform)
symlink_paths.each do |path| symlink_paths.each do |path|
path.should.be.symlink path.should.be.symlink
File.read(path).should == 'hello' File.read(path).should == 'hello'
...@@ -39,12 +39,12 @@ module Pod ...@@ -39,12 +39,12 @@ module Pod
relative_header_paths.each do |path| relative_header_paths.each do |path|
File.open(@sandbox.root + path, 'w') { |file| file.write('hello') } File.open(@sandbox.root + path, 'w') { |file| file.write('hello') }
end end
@header_dir.add_files(namespace_path, relative_header_paths) @header_dir.add_files(namespace_path, relative_header_paths, :fake_platform)
@header_dir.search_paths.should.include('${PODS_ROOT}/Headers/Public/ExampleLib') @header_dir.search_paths(:fake_platform).should.include('${PODS_ROOT}/Headers/Public/ExampleLib')
end end
it 'always adds the Headers root to the header search paths' do it 'always adds the Headers root to the header search paths' do
@header_dir.search_paths.should.include('${PODS_ROOT}/Headers/Public') @header_dir.search_paths(:fake_platform).should.include('${PODS_ROOT}/Headers/Public')
end end
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