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

Stash

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