Commit 1d71b582 authored by Eloy Duran's avatar Eloy Duran

Move getting paths relative to a Xcode project's ${SRCROOT} to

Pod::Podfile::TargetDefinition.
parent 57c3e267
platform :ios platform :ios
workspace "RelativePathProject/TheWorkspaceOfTheRelativeProject.xcworkspace"
xcodeproj "RelativePathProject/RelativePathProject.xcodeproj" xcodeproj "RelativePathProject/RelativePathProject.xcodeproj"
dependency "AFNetworking" dependency "AFNetworking"
<?xml version='1.0' encoding='UTF-8'?><Workspace version='1.0'><FileRef location='group:Pods/Pods.xcodeproj'/><FileRef location='group:RelativePathProject/RelativePathProject.xcodeproj'/></Workspace>
\ No newline at end of file
<?xml version='1.0' encoding='UTF-8'?><Workspace version='1.0'><FileRef location='group:RelativePathProject.xcodeproj'/><FileRef location='group:../Pods/Pods.xcodeproj'/><FileRef location='group:Pods/Pods.xcodeproj'/><FileRef location='group:RelativePathProject/RelativePathProject.xcodeproj'/></Workspace>
\ No newline at end of file
...@@ -17,7 +17,6 @@ module Pod ...@@ -17,7 +17,6 @@ module Pod
autoload :Podfile, 'cocoapods/podfile' autoload :Podfile, 'cocoapods/podfile'
autoload :Project, 'cocoapods/project' autoload :Project, 'cocoapods/project'
autoload :Resolver, 'cocoapods/resolver' autoload :Resolver, 'cocoapods/resolver'
autoload :PodPathResolver, 'cocoapods/pod_path_resolver'
autoload :Sandbox, 'cocoapods/sandbox' autoload :Sandbox, 'cocoapods/sandbox'
autoload :Source, 'cocoapods/source' autoload :Source, 'cocoapods/source'
autoload :Spec, 'cocoapods/specification' autoload :Spec, 'cocoapods/specification'
......
...@@ -13,7 +13,7 @@ module Pod ...@@ -13,7 +13,7 @@ module Pod
def xcconfig def xcconfig
@xcconfig ||= Xcodeproj::Config.new({ @xcconfig ||= Xcodeproj::Config.new({
# In a workspace this is where the static library headers should be found. # In a workspace this is where the static library headers should be found.
'PODS_ROOT' => Pod::PodPathResolver.new(@target_definition).pods_root, 'PODS_ROOT' => @target_definition.relative_pods_root,
'ALWAYS_SEARCH_USER_PATHS' => 'YES', # needed to make EmbedReader build 'ALWAYS_SEARCH_USER_PATHS' => 'YES', # needed to make EmbedReader build
'OTHER_LDFLAGS' => default_ld_flags, 'OTHER_LDFLAGS' => default_ld_flags,
}) })
...@@ -78,7 +78,7 @@ module Pod ...@@ -78,7 +78,7 @@ module Pod
config.base_configuration = xcconfig_file config.base_configuration = xcconfig_file
config.build_settings['OTHER_LDFLAGS'] = '' config.build_settings['OTHER_LDFLAGS'] = ''
config.build_settings['GCC_PREFIX_HEADER'] = @target_definition.prefix_header_name config.build_settings['GCC_PREFIX_HEADER'] = @target_definition.prefix_header_name
config.build_settings['PODS_ROOT'] = '$(SRCROOT)' config.build_settings['PODS_ROOT'] = '${SRCROOT}'
end end
end end
......
...@@ -63,6 +63,14 @@ module Pod ...@@ -63,6 +63,14 @@ module Pod
def integrate! def integrate!
return if targets.empty? return if targets.empty?
unless Config.instance.silent?
# TODO let's just use ActiveSupport.
plural = targets.size > 1
puts "-> Integrating `#{@target_definition.lib_name}' into target#{'s' if plural} " \
"`#{targets.map(&:name).join(', ')}' of Xcode project `#{user_project_path.basename}'.".green
end
add_xcconfig_base_configuration add_xcconfig_base_configuration
add_pods_library add_pods_library
add_copy_resources_script_phase add_copy_resources_script_phase
...@@ -106,16 +114,16 @@ module Pod ...@@ -106,16 +114,16 @@ module Pod
# Default to the first, which in a simple project is probably an app target. # Default to the first, which in a simple project is probably an app target.
[user_project.targets.first] [user_project.targets.first]
end.reject do |target| end.reject do |target|
# Reject any target that already has this Pods library in one of its frameworks build phases # Reject any target that already has this Pods library in one of its frameworks build phases
target.frameworks_build_phases.any? do |phase| target.frameworks_build_phases.any? do |phase|
phase.files.any? { |file| file.name == @target_definition.lib_name } phase.files.any? { |file| file.name == @target_definition.lib_name }
end
end end
end end
end
end end
def add_xcconfig_base_configuration def add_xcconfig_base_configuration
xcconfig = user_project.files.new('path' => "Pods/#{@target_definition.xcconfig_name}") # TODO use Sandbox? xcconfig = user_project.files.new('path' => @target_definition.xcconfig_relative_path)
targets.each do |target| targets.each do |target|
target.build_configurations.each do |config| target.build_configurations.each do |config|
config.base_configuration = xcconfig config.base_configuration = xcconfig
...@@ -134,7 +142,7 @@ module Pod ...@@ -134,7 +142,7 @@ module Pod
targets.each do |target| targets.each do |target|
phase = target.shell_script_build_phases.new phase = target.shell_script_build_phases.new
phase.name = 'Copy Pods Resources' phase.name = 'Copy Pods Resources'
phase.shell_script = %{"${SRCROOT}/Pods/#{@target_definition.copy_resources_script_name}"\n} phase.shell_script = %{"#{@target_definition.copy_resources_script_relative_path}"\n}
end end
end end
end end
......
module Pod
class PodPathResolver
include Config::Mixin
def initialize(target_definition)
@target_definition = target_definition
end
def relative_path_for_pods
pods_path = config.project_pods_root
xcode_proj_path = @target_definition.xcodeproj || ''
source_root = (config.project_root + xcode_proj_path).parent
pods_path.relative_path_from(source_root)
end
def pods_root
"$(SRCROOT)/#{relative_path_for_pods}"
end
end
end
...@@ -61,6 +61,16 @@ module Pod ...@@ -61,6 +61,16 @@ module Pod
end end
end end
# Returns a path, which is relative to the project_root, relative to the
# `$(SRCROOT)` of the user's project.
def relative_to_srcroot(path)
(config.project_root + path).relative_path_from(xcodeproj.dirname)
end
def relative_pods_root
"${SRCROOT}/#{relative_to_srcroot "Pods"}"
end
def lib_name def lib_name
"lib#{label}.a" "lib#{label}.a"
end end
...@@ -69,10 +79,18 @@ module Pod ...@@ -69,10 +79,18 @@ module Pod
"#{label}.xcconfig" "#{label}.xcconfig"
end end
def xcconfig_relative_path
relative_to_srcroot("Pods/#{xcconfig_name}").to_s
end
def copy_resources_script_name def copy_resources_script_name
"#{label}-resources.sh" "#{label}-resources.sh"
end end
def copy_resources_script_relative_path
"${SRCROOT}/#{relative_to_srcroot("Pods/#{copy_resources_script_name}")}"
end
def prefix_header_name def prefix_header_name
"#{label}-prefix.pch" "#{label}-prefix.pch"
end end
...@@ -142,7 +160,7 @@ module Pod ...@@ -142,7 +160,7 @@ module Pod
else else
projects = @target_definitions.map { |_, td| td.xcodeproj }.uniq projects = @target_definitions.map { |_, td| td.xcodeproj }.uniq
if projects.size == 1 && (xcodeproj = @target_definitions[:default].xcodeproj) if projects.size == 1 && (xcodeproj = @target_definitions[:default].xcodeproj)
xcodeproj.dirname + "#{xcodeproj.basename('.xcodeproj')}.xcworkspace" config.project_root + "#{xcodeproj.basename('.xcodeproj')}.xcworkspace"
end end
end end
end end
......
...@@ -39,7 +39,7 @@ module Pod ...@@ -39,7 +39,7 @@ module Pod
end end
def header_search_paths def header_search_paths
@header_search_paths.uniq.map { |path| "$(PODS_ROOT)/#{path}" } @header_search_paths.uniq.map { |path| "${PODS_ROOT}/#{path}" }
end end
def prepare_for_install def prepare_for_install
......
...@@ -47,14 +47,10 @@ describe Pod::Installer::UserProjectIntegrator do ...@@ -47,14 +47,10 @@ describe Pod::Installer::UserProjectIntegrator do
workspace.projpaths.find { |path| path =~ /Pods.xcodeproj/ }.should.not.be.nil workspace.projpaths.find { |path| path =~ /Pods.xcodeproj/ }.should.not.be.nil
end end
it 'adds the Pods xcconfig file to the project' do
@sample_project.files.where(:path => "Pods/Pods.xcconfig").should.not.be.nil
end
it 'sets the Pods xcconfig as the base config for each build configuration' do it 'sets the Pods xcconfig as the base config for each build configuration' do
@podfile.target_definitions.each do |_, definition| @podfile.target_definitions.each do |_, definition|
target = @sample_project.targets.where(:name => definition.link_with.first) target = @sample_project.targets.where(:name => definition.link_with.first)
xcconfig_file = @sample_project.files.where(:path => "Pods/#{definition.xcconfig_name}") xcconfig_file = @sample_project.files.where(:path => "${SRCROOT}/Pods/#{definition.xcconfig_name}")
target.build_configurations.each do |config| target.build_configurations.each do |config|
config.base_configuration.should == xcconfig_file config.base_configuration.should == xcconfig_file
end end
...@@ -78,7 +74,7 @@ describe Pod::Installer::UserProjectIntegrator do ...@@ -78,7 +74,7 @@ describe Pod::Installer::UserProjectIntegrator do
@podfile.target_definitions.each do |_, definition| @podfile.target_definitions.each do |_, definition|
target = @sample_project.targets.where(:name => definition.link_with.first) target = @sample_project.targets.where(:name => definition.link_with.first)
phase = target.shell_script_build_phases.where(:name => "Copy Pods Resources") phase = target.shell_script_build_phases.where(:name => "Copy Pods Resources")
phase.shell_script.strip.should == "\"${SRCROOT}/Pods/#{definition.copy_resources_script_name}\"".strip phase.shell_script.strip.should == "\"${SRCROOT}/Pods/#{definition.copy_resources_script_name}\""
end end
end end
......
...@@ -86,6 +86,7 @@ else ...@@ -86,6 +86,7 @@ else
commit = '2adcd0f81740d6b0cd4589af98790eee3bd1ae7b' commit = '2adcd0f81740d6b0cd4589af98790eee3bd1ae7b'
podfile = Pod::Podfile.new do podfile = Pod::Podfile.new do
self.platform :ios self.platform :ios
xcodeproj 'dummy'
dependency 'SSToolkit', :git => url, :commit => commit dependency 'SSToolkit', :git => url, :commit => commit
end end
...@@ -103,6 +104,7 @@ else ...@@ -103,6 +104,7 @@ else
url = 'https://raw.github.com/gist/1349824/3ec6aa60c19113573fc48eac19d0fafd6a69e033/Reachability.podspec' url = 'https://raw.github.com/gist/1349824/3ec6aa60c19113573fc48eac19d0fafd6a69e033/Reachability.podspec'
podfile = Pod::Podfile.new do podfile = Pod::Podfile.new do
self.platform :ios self.platform :ios
xcodeproj 'dummy'
# TODO use a local file instead of http? # TODO use a local file instead of http?
dependency 'Reachability', :podspec => url dependency 'Reachability', :podspec => url
end end
...@@ -120,6 +122,7 @@ else ...@@ -120,6 +122,7 @@ else
it "installs a library with a podspec defined inline" do it "installs a library with a podspec defined inline" do
podfile = Pod::Podfile.new do podfile = Pod::Podfile.new do
self.platform :ios self.platform :ios
xcodeproj 'dummy'
dependency do |s| dependency do |s|
s.name = 'JSONKit' s.name = 'JSONKit'
s.version = '1.2' s.version = '1.2'
...@@ -150,6 +153,7 @@ else ...@@ -150,6 +153,7 @@ else
it "creates targets for different platforms" do it "creates targets for different platforms" do
podfile = Pod::Podfile.new do podfile = Pod::Podfile.new do
self.platform :ios self.platform :ios
xcodeproj 'dummy'
dependency 'JSONKit', '1.4' dependency 'JSONKit', '1.4'
target :ios_target do target :ios_target do
# This brings in Reachability on iOS # This brings in Reachability on iOS
...@@ -179,6 +183,7 @@ else ...@@ -179,6 +183,7 @@ else
podfile = Pod::Podfile.new do podfile = Pod::Podfile.new do
self.platform :ios self.platform :ios
xcodeproj 'dummy'
dependency 'JSONKit', '1.4' dependency 'JSONKit', '1.4'
dependency 'SSToolkit' dependency 'SSToolkit'
end end
...@@ -203,6 +208,7 @@ else ...@@ -203,6 +208,7 @@ else
it "runs the optional post_install callback defined in the Podfile _before_ the project is saved to disk" do it "runs the optional post_install callback defined in the Podfile _before_ the project is saved to disk" do
podfile = Pod::Podfile.new do podfile = Pod::Podfile.new do
self.platform platform self.platform platform
xcodeproj 'dummy'
dependency 'SSZipArchive' dependency 'SSZipArchive'
post_install do |installer| post_install do |installer|
...@@ -224,6 +230,7 @@ else ...@@ -224,6 +230,7 @@ else
it "activates required pods and create a working static library xcode project" do it "activates required pods and create a working static library xcode project" do
podfile = Pod::Podfile.new do podfile = Pod::Podfile.new do
self.platform platform self.platform platform
xcodeproj 'dummy'
dependency 'Reachability', '> 2.0.5' if platform == :ios dependency 'Reachability', '> 2.0.5' if platform == :ios
dependency 'ASIWebPageRequest', '>= 1.8.1' dependency 'ASIWebPageRequest', '>= 1.8.1'
dependency 'JSONKit', '>= 1.0' dependency 'JSONKit', '>= 1.0'
...@@ -268,6 +275,7 @@ else ...@@ -268,6 +275,7 @@ else
it "does not activate pods that are only part of other pods" do it "does not activate pods that are only part of other pods" do
spec = Pod::Podfile.new do spec = Pod::Podfile.new do
self.platform platform self.platform platform
xcodeproj 'dummy'
dependency 'Reachability', '2.0.4' # only 2.0.4 is part of ASIHTTPRequest’s source. dependency 'Reachability', '2.0.4' # only 2.0.4 is part of ASIHTTPRequest’s source.
end end
...@@ -285,6 +293,7 @@ else ...@@ -285,6 +293,7 @@ else
it "adds resources to the xcode copy script" do it "adds resources to the xcode copy script" do
spec = Pod::Podfile.new do spec = Pod::Podfile.new do
self.platform platform self.platform platform
xcodeproj 'dummy'
dependency 'SSZipArchive' dependency 'SSZipArchive'
end end
...@@ -302,6 +311,7 @@ else ...@@ -302,6 +311,7 @@ else
it "overwrites an existing project.pbxproj file" do it "overwrites an existing project.pbxproj file" do
spec = Pod::Podfile.new do spec = Pod::Podfile.new do
self.platform platform self.platform platform
xcodeproj 'dummy'
dependency 'JSONKit' dependency 'JSONKit'
end end
installer = SpecHelper::Installer.new(spec) installer = SpecHelper::Installer.new(spec)
...@@ -309,6 +319,7 @@ else ...@@ -309,6 +319,7 @@ else
spec = Pod::Podfile.new do spec = Pod::Podfile.new do
self.platform platform self.platform platform
xcodeproj 'dummy'
dependency 'SSZipArchive' dependency 'SSZipArchive'
end end
installer = SpecHelper::Installer.new(spec) installer = SpecHelper::Installer.new(spec)
...@@ -321,6 +332,7 @@ else ...@@ -321,6 +332,7 @@ else
it "creates a project with multiple targets" do it "creates a project with multiple targets" do
podfile = Pod::Podfile.new do podfile = Pod::Podfile.new do
self.platform platform self.platform platform
xcodeproj 'dummy'
target(:debug) { dependency 'SSZipArchive' } target(:debug) { dependency 'SSZipArchive' }
target(:test, :exclusive => true) { dependency 'JSONKit' } target(:test, :exclusive => true) { dependency 'JSONKit' }
dependency 'ASIHTTPRequest' dependency 'ASIHTTPRequest'
...@@ -388,7 +400,7 @@ else ...@@ -388,7 +400,7 @@ else
target = project.targets.first target = project.targets.first
target.build_configurations.each do |config| target.build_configurations.each do |config|
config.base_configuration.path.should == 'Pods/Pods.xcconfig' config.base_configuration.path.should == '${SRCROOT}/Pods/Pods.xcconfig'
end end
target.frameworks_build_phases.first.files.should.include libPods target.frameworks_build_phases.first.files.should.include libPods
# should be the last phase # should be the last phase
...@@ -398,6 +410,7 @@ else ...@@ -398,6 +410,7 @@ else
it "should prevent duplication cleaning headers symlinks with multiple targets" do it "should prevent duplication cleaning headers symlinks with multiple targets" do
podfile = Pod::Podfile.new do podfile = Pod::Podfile.new do
self.platform platform self.platform platform
xcodeproj 'dummy'
target(:debug) { dependency 'SSZipArchive' } target(:debug) { dependency 'SSZipArchive' }
target(:test, :exclusive => true) { dependency 'JSONKit' } target(:test, :exclusive => true) { dependency 'JSONKit' }
dependency 'ASIHTTPRequest' dependency 'ASIHTTPRequest'
......
...@@ -5,17 +5,11 @@ TMP_POD_ROOT = ROOT + "tmp" + "podroot" unless defined? TMP_POD_ROOT ...@@ -5,17 +5,11 @@ TMP_POD_ROOT = ROOT + "tmp" + "podroot" unless defined? TMP_POD_ROOT
describe Pod::Installer::TargetInstaller do describe Pod::Installer::TargetInstaller do
before do before do
platform = Pod::Platform.ios @podfile = Pod::Podfile.new do
platform :ios
@target_definition = Pod::Podfile::TargetDefinition.new(:foo) xcodeproj 'dummy'
@target_definition.platform = platform end
@target_definition = @podfile.target_definitions[:default]
@podfile = stub('podfile',
:platform => platform,
:xcodeproj => 'dummy.xcodeproj',
:generate_bridge_support? => false,
:set_arc_compatibility_flag? => false
)
@project = Pod::Project.new @project = Pod::Project.new
@project.main_group.groups.new('name' => 'Targets Support Files') @project.main_group.groups.new('name' => 'Targets Support Files')
...@@ -24,7 +18,7 @@ describe Pod::Installer::TargetInstaller do ...@@ -24,7 +18,7 @@ describe Pod::Installer::TargetInstaller do
@sandbox = Pod::Sandbox.new(TMP_POD_ROOT) @sandbox = Pod::Sandbox.new(TMP_POD_ROOT)
@specification = fixture_spec('banana-lib/BananaLib.podspec') @specification = fixture_spec('banana-lib/BananaLib.podspec')
@pods = [Pod::LocalPod.new(@specification, @sandbox, platform)] @pods = [Pod::LocalPod.new(@specification, @sandbox, Pod::Platform.ios)]
end end
def do_install! def do_install!
......
...@@ -17,6 +17,7 @@ describe "Pod::Installer" do ...@@ -17,6 +17,7 @@ describe "Pod::Installer" do
before do before do
@xcconfig = Pod::Installer.new(Pod::Podfile.new do @xcconfig = Pod::Installer.new(Pod::Podfile.new do
platform :ios platform :ios
xcodeproj 'MyProject'
dependency 'JSONKit' dependency 'JSONKit'
end).target_installers.first.xcconfig.to_hash end).target_installers.first.xcconfig.to_hash
end end
......
require File.expand_path('../../spec_helper', __FILE__)
describe "Pod::PodPathResolver" do
it "should default to a path underneath source root" do
target_definition = Pod::Podfile::TargetDefinition.new(:default)
target_definition.xcodeproj = 'foo.xcodeproj'
resolver = Pod::PodPathResolver.new(target_definition)
resolver.pods_root.should == "$(SRCROOT)/Pods"
end
it "should work with source root one level deeper" do
target_definition = Pod::Podfile::TargetDefinition.new(:default)
target_definition.xcodeproj = 'subdir/foo.xcodeproj'
resolver = Pod::PodPathResolver.new(target_definition)
resolver.pods_root.should == "$(SRCROOT)/../Pods"
end
end
...@@ -217,12 +217,16 @@ describe "Pod::Podfile" do ...@@ -217,12 +217,16 @@ describe "Pod::Podfile" do
it "returns the name of the xcconfig file for the target" do it "returns the name of the xcconfig file for the target" do
@podfile.target_definitions[:default].xcconfig_name.should == 'Pods.xcconfig' @podfile.target_definitions[:default].xcconfig_name.should == 'Pods.xcconfig'
@podfile.target_definitions[:default].xcconfig_relative_path.should == 'Pods/Pods.xcconfig'
@podfile.target_definitions[:test].xcconfig_name.should == 'Pods-test.xcconfig' @podfile.target_definitions[:test].xcconfig_name.should == 'Pods-test.xcconfig'
@podfile.target_definitions[:test].xcconfig_relative_path.should == 'Pods/Pods-test.xcconfig'
end end
it "returns the name of the 'copy resources script' file for the target" do it "returns the name of the 'copy resources script' file for the target" do
@podfile.target_definitions[:default].copy_resources_script_name.should == 'Pods-resources.sh' @podfile.target_definitions[:default].copy_resources_script_name.should == 'Pods-resources.sh'
@podfile.target_definitions[:default].copy_resources_script_relative_path.should == '${SRCROOT}/Pods/Pods-resources.sh'
@podfile.target_definitions[:test].copy_resources_script_name.should == 'Pods-test-resources.sh' @podfile.target_definitions[:test].copy_resources_script_name.should == 'Pods-test-resources.sh'
@podfile.target_definitions[:test].copy_resources_script_relative_path.should == '${SRCROOT}/Pods/Pods-test-resources.sh'
end end
it "returns the name of the 'prefix header' file for the target" do it "returns the name of the 'prefix header' file for the target" do
...@@ -245,6 +249,25 @@ describe "Pod::Podfile" do ...@@ -245,6 +249,25 @@ describe "Pod::Podfile" do
@podfile.target_definitions[:osx_target].should.be.exclusive @podfile.target_definitions[:osx_target].should.be.exclusive
@podfile.target_definitions[:nested_osx_target].should.not.be.exclusive @podfile.target_definitions[:nested_osx_target].should.not.be.exclusive
end end
describe "with an Xcode project that's not in the project_root" do
before do
@target_definition = @podfile.target_definitions[:default]
@target_definition.stubs(:xcodeproj).returns(config.project_root + 'subdir/iOS Project.xcodeproj')
end
it "returns the $(PODS_ROOT) relative to the project's $(SRCROOT)" do
@target_definition.relative_pods_root.should == '${SRCROOT}/../Pods'
end
it "returns the xcconfig file path relative to the project's $(SRCROOT)" do
@target_definition.xcconfig_relative_path.should == '../Pods/Pods.xcconfig'
end
it "returns the 'copy resources script' path relative to the project's $(SRCROOT)" do
@target_definition.copy_resources_script_relative_path.should == '${SRCROOT}/../Pods/Pods-resources.sh'
end
end
end end
describe "concerning validations" do describe "concerning validations" do
......
...@@ -65,11 +65,11 @@ describe Pod::Sandbox do ...@@ -65,11 +65,11 @@ describe Pod::Sandbox do
File.open(@sandbox.root + path, "w") { |file| file.write('hello') } File.open(@sandbox.root + path, "w") { |file| file.write('hello') }
end end
@sandbox.add_header_files(namespace_path, relative_header_paths) @sandbox.add_header_files(namespace_path, relative_header_paths)
@sandbox.header_search_paths.should.include("$(PODS_ROOT)/Headers/ExampleLib") @sandbox.header_search_paths.should.include("${PODS_ROOT}/Headers/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
@sandbox.header_search_paths.should.include("$(PODS_ROOT)/Headers") @sandbox.header_search_paths.should.include("${PODS_ROOT}/Headers")
end end
it 'clears out its headers root when preparing for install' do it 'clears out its headers root when preparing for install' do
......
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