Commit 5df26a6f authored by Eloy Duran's avatar Eloy Duran

Stash

parent d51f5a06
......@@ -44,14 +44,15 @@ module Pod
raise Informative, "No `Podfile' found in the current working directory."
end
if podfile.xcodeproj.nil?
# TODO this should be done for all targets (?)
if xcodeproj = podfile.target_definitions[:default].xcodeproj
raise Informative, "Please specify a valid xcodeproj path in your Podfile.\n\n" +
"Usage:\n\t" +
"xcodeproj 'path/to/project.xcodeproj'"
end
unless File.exist?(podfile.xcodeproj)
raise Informative, "The specified project `#{podfile.xcodeproj}' does not exist."
if xcodeproj && !xcodeproj.exist?
raise Informative, "The specified project `#{xcodeproj}' does not exist."
end
if @update_repo
......
......@@ -20,12 +20,8 @@ module Pod
def initialize
@repos_dir = Pathname.new(File.expand_path("~/.cocoapods"))
@clean = true
@verbose = false
@silent = false
@doc = true
@doc_install = true
@force_doc = false
@verbose = @silent = @force_doc = false
@clean = @doc = @doc_install = true
end
def project_root
......
......@@ -91,7 +91,8 @@ module Pod
puts "* Writing Xcode project file to `#{@sandbox.project_path}'\n\n" if config.verbose?
project.save_as(@sandbox.project_path)
UserProjectIntegrator.new(@podfile).integrate! if @podfile.xcodeproj
# The conditional is actually only so we omit the integration when running the specs.
UserProjectIntegrator.new(@podfile).integrate! if @podfile.xcodeproj(false)
end
def run_post_install_hooks
......
......@@ -10,11 +10,10 @@ module Pod
@podfile, @project, @target_definition = podfile, project, target_definition
end
def xcconfig
@xcconfig ||= Xcodeproj::Config.new({
# In a workspace this is where the static library headers should be found.
'PODS_ROOT' => Pod::PodPathResolver.new(@podfile).pods_root,
'PODS_ROOT' => Pod::PodPathResolver.new(@target_definition).pods_root,
'ALWAYS_SEARCH_USER_PATHS' => 'YES', # needed to make EmbedReader build
'OTHER_LDFLAGS' => default_ld_flags,
})
......
......@@ -16,9 +16,7 @@ module Pod
# Only need to write out the user's project if any of the target
# integrators actually did some work.
if targets.map(&:integrate!).any?
user_project.save_as(user_project_path)
end
target_integrators.map(&:integrate!)
unless config.silent?
# TODO this really shouldn't be here
......@@ -26,24 +24,18 @@ module Pod
end
end
def user_project_path
@podfile.xcodeproj
end
def user_project
@user_project ||= Xcodeproj::Project.new(user_project_path)
end
def workspace_path
config.project_root + "#{user_project_path.basename('.xcodeproj')}.xcworkspace"
config.project_root + "#{@podfile.target_definitions[:default].xcodeproj.basename('.xcodeproj')}.xcworkspace"
end
def pods_project_path
config.project_root + "Pods/Pods.xcodeproj"
end
def targets
@podfile.target_definitions.values.map { |definition| Target.new(self, definition) }
def target_integrators
@podfile.target_definitions.values.map do |definition|
TargetIntegrator.new(definition)
end
end
def create_workspace!
......@@ -55,19 +47,23 @@ module Pod
workspace.save_as(workspace_path)
end
class Target
attr_reader :integrator, :target_definition
class TargetIntegrator
attr_reader :target_definition
def initialize(integrator, target_definition)
@integrator, @target_definition = integrator, target_definition
def initialize(target_definition)
@target_definition = target_definition
end
def integrate!
return false if targets.empty?
return if targets.empty?
add_xcconfig_base_configuration
add_pods_library
add_copy_resources_script_phase
true
user_project.save_as(@target_definition.xcodeproj)
end
def user_project
@user_project ||= Xcodeproj::Project.new(@target_definition.xcodeproj)
end
# This returns a list of the targets from the user’s project to which
......@@ -82,11 +78,11 @@ module Pod
def targets
@targets ||= begin
if link_with = @target_definition.link_with
@integrator.user_project.targets.select do |target|
user_project.targets.select do |target|
link_with.include? target.name
end
else
[@integrator.user_project.targets.first]
[user_project.targets.first]
end.reject do |target|
# reject any target that already has this Pods library in one of its frameworks build phases
target.frameworks_build_phases.any? do |phase|
......@@ -97,7 +93,7 @@ module Pod
end
def add_xcconfig_base_configuration
xcconfig = @integrator.user_project.files.new('path' => "Pods/#{@target_definition.xcconfig_name}") # TODO use Sandbox?
xcconfig = user_project.files.new('path' => "Pods/#{@target_definition.xcconfig_name}") # TODO use Sandbox?
targets.each do |target|
target.build_configurations.each do |config|
config.base_configuration = xcconfig
......@@ -106,7 +102,7 @@ module Pod
end
def add_pods_library
pods_library = @integrator.user_project.group("Frameworks").files.new_static_library(@target_definition.label)
pods_library = user_project.group("Frameworks").files.new_static_library(@target_definition.label)
targets.each do |target|
target.frameworks_build_phases.each { |build_phase| build_phase << pods_library }
end
......
......@@ -2,13 +2,13 @@ module Pod
class PodPathResolver
include Config::Mixin
def initialize(podfile)
@podfile = podfile
def initialize(target_definition)
@target_definition = target_definition
end
def relative_path_for_pods
pods_path = config.project_pods_root
xcode_proj_path = @podfile.xcodeproj || ''
xcode_proj_path = @target_definition.xcodeproj || ''
source_root = (config.project_root + xcode_proj_path).parent
pods_path.relative_path_from(source_root)
end
......
......@@ -3,7 +3,7 @@ module Pod
class TargetDefinition
attr_reader :name, :target_dependencies
attr_accessor :link_with, :platform, :parent, :exclusive
attr_accessor :xcodeproj, :link_with, :platform, :parent, :exclusive
def initialize(name, options = {})
@name, @target_dependencies = name, []
......@@ -25,6 +25,22 @@ module Pod
end
alias_method :exclusive?, :exclusive
def xcodeproj=(path)
path = path.to_s
@xcodeproj = Pathname.new(File.extname(path) == '.xcodeproj' ? path : "#{path}.xcodeproj")
end
def xcodeproj
if @xcodeproj
@xcodeproj
elsif @parent
@parent.xcodeproj
else
xcodeprojs = Config.instance.project_root.glob('*.xcodeproj')
@xcodeproj = xcodeprojs.first if xcodeprojs.size == 1
end
end
def link_with=(targets)
@link_with = targets.is_a?(Array) ? targets : [targets]
end
......@@ -121,8 +137,8 @@ module Pod
# Specifies the path of the xcode project so it doesn't require the project to be specified
# when running pod install each time.
def xcodeproj(path = nil)
path ? @xcodeproj = path : @xcodeproj
def xcodeproj(path)
@target_definition.xcodeproj = path
end
# Specifies a dependency of the project.
......
......@@ -34,11 +34,11 @@ describe Pod::Installer::UserProjectIntegrator do
end
it "returns a Pod::Installer::UserProjectIntegrator::Target for each target definition in the Podfile" do
@integrator.targets.map(&:target_definition).should == @podfile.target_definitions.values
@integrator.target_integrators.map(&:target_definition).should == @podfile.target_definitions.values
end
it "uses the first target in the user's project if no explicit target is specified" do
target_integrator = @integrator.targets.first
target_integrator = @integrator.target_integrators.first
target_integrator.target_definition.stubs(:link_with).returns(nil)
target_integrator.targets.should == [Xcodeproj::Project.new(@sample_project_path).targets.first]
end
......
......@@ -2,14 +2,16 @@ require File.expand_path('../../spec_helper', __FILE__)
describe "Pod::PodPathResolver" do
it "should default to a path underneath source root" do
podfile = Pod::Podfile.new {platform :ios; xcodeproj 'foo.xcodeproj'}
resolver = Pod::PodPathResolver.new(podfile)
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
podfile = Pod::Podfile.new {platform :ios; xcodeproj 'subdir/foo.xcodeproj'}
resolver = Pod::PodPathResolver.new(podfile)
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
......@@ -11,11 +11,6 @@ describe "Pod::Podfile" do
podfile.target_definitions[:default].platform.should == :ios
end
it "assigns the xcodeproj attribute" do
podfile = Pod::Podfile.new { platform :ios; xcodeproj "foo.xcodeproj" }
podfile.xcodeproj.should == "foo.xcodeproj"
end
it "adds dependencies" do
podfile = Pod::Podfile.new { dependency 'ASIHTTPRequest'; dependency 'SSZipArchive', '>= 0.1' }
podfile.dependencies.size.should == 2
......@@ -80,6 +75,7 @@ describe "Pod::Podfile" do
before do
@podfile = Pod::Podfile.new do
platform :ios
xcodeproj 'iOS Project'
target :debug do
dependency 'SSZipArchive'
......@@ -95,6 +91,7 @@ describe "Pod::Podfile" do
target :osx_target do
platform :osx
xcodeproj 'OSX Project.xcodeproj'
link_with 'OSXTarget'
dependency 'ASIHTTPRequest'
target :nested_osx_target do
......@@ -136,6 +133,31 @@ describe "Pod::Podfile" do
target.dependencies.should == [Pod::Dependency.new('Reachability'), Pod::Dependency.new('JSONKit')]
end
it "returns the Xcode project that contains the target to link with" do
[:default, :debug, :test, :subtarget].each do |target_name|
target = @podfile.target_definitions[target_name]
target.xcodeproj.should == Pathname.new('iOS Project.xcodeproj')
end
[:osx_target, :nested_osx_target].each do |target_name|
target = @podfile.target_definitions[target_name]
target.xcodeproj.should == Pathname.new('OSX Project.xcodeproj')
end
end
it "returns a Xcode project found in the working dir when no explicit project is specified" do
xcodeproj1 = config.project_root + '1.xcodeproj'
target = Pod::Podfile::TargetDefinition.new(:implicit)
config.project_root.expects(:glob).with('*.xcodeproj').returns([xcodeproj1])
target.xcodeproj.should == xcodeproj1
end
it "returns `nil' if more than one Xcode project was found in the working when no explicit project is specified" do
xcodeproj1, xcodeproj2 = config.project_root + '1.xcodeproj', config.project_root + '2.xcodeproj'
target = Pod::Podfile::TargetDefinition.new(:implicit)
config.project_root.expects(:glob).with('*.xcodeproj').returns([xcodeproj1, xcodeproj2])
target.xcodeproj.should == nil
end
it "leaves the name of the target, to link with, to be automatically resolved" do
target = @podfile.target_definitions[:default]
target.link_with.should == nil
......
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