Commit c76fb93a authored by Eloy Duran's avatar Eloy Duran

Make the workspace configurable with Podfile#workspace(path).

* If no workspace is specified, then the basename of the default
  target's project will be used.
* If no workspace is specified and multiple projects have been
  specified (in several target definitions), an Informative error
  will be raised indicating that the user should specify one
  explicitely.
parent 5d756c88
GIT
remote: git://github.com/CocoaPods/Xcodeproj.git
revision: c7a2acb7f49005823a37cea0089e558ff4a13af7
revision: 2817d17a0ea88dba76e898a1c71cbac615d76fc2
specs:
xcodeproj (0.1.0)
......@@ -21,9 +21,9 @@ GEM
mocha (>= 0.9.8)
open4 (1.3.0)
rake (0.9.2.2)
rb-fsevent (0.9.0)
rb-fsevent (0.9.1)
vcr (2.0.1)
webmock (1.8.5)
webmock (1.8.6)
addressable (>= 2.2.7)
crack (>= 0.1.7)
......
......@@ -11,7 +11,7 @@ module Pod
The Xcode project file should be specified in your `Podfile` like this:
xcodeproj 'path/to/project.xcodeproj'
xcodeproj 'path/to/XcodeProject'
If no xcodeproj is specified, then a search for an Xcode project will
be made. If more than one Xcode project is found, the command will
......@@ -47,19 +47,6 @@ module Pod
raise Informative, "No `Podfile' found in the current working directory."
end
if config.integrate_targets?
# TODO this should be done for all targets (?)
unless 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
if xcodeproj && !xcodeproj.exist?
raise Informative, "The specified project `#{xcodeproj}' does not exist."
end
end
if @update_repo
puts "\nUpdating Spec Repositories\n".yellow if config.verbose?
Repo.new(ARGV.new(["update"])).run
......
......@@ -25,7 +25,8 @@ module Pod
end
def workspace_path
config.project_root + "#{@podfile.target_definitions[:default].xcodeproj.basename('.xcodeproj')}.xcworkspace"
@podfile.workspace || raise(Informative, "Could not automatically select an Xcode workspace. " \
"Specify one in your Podfile.")
end
def pods_project_path
......@@ -70,8 +71,21 @@ module Pod
user_project.save_as(@target_definition.xcodeproj)
end
def user_project_path
if path = @target_definition.xcodeproj
unless path.exist?
raise Informative, "The Xcode project `#{path}' does not exist."
end
path
else
raise Informative, "Could not automatically select an Xcode project.\n" \
"Specify one in your Podfile like so:\n\n" \
" xcodeproj 'path/to/XcodeProject'"
end
end
def user_project
@user_project ||= Xcodeproj::Project.new(@target_definition.xcodeproj)
@user_project ||= Xcodeproj::Project.new(user_project_path)
end
# This returns a list of the targets from the user’s project to which
......
module Pod
class Podfile
class TargetDefinition
include Config::Mixin
attr_reader :name, :target_dependencies
attr_accessor :xcodeproj, :link_with, :platform, :parent, :exclusive
......@@ -27,7 +29,7 @@ module Pod
def xcodeproj=(path)
path = path.to_s
@xcodeproj = Pathname.new(File.extname(path) == '.xcodeproj' ? path : "#{path}.xcodeproj")
@xcodeproj = config.project_root + (File.extname(path) == '.xcodeproj' ? path : "#{path}.xcodeproj")
end
def xcodeproj
......@@ -36,7 +38,7 @@ module Pod
elsif @parent
@parent.xcodeproj
else
xcodeprojs = Config.instance.project_root.glob('*.xcodeproj')
xcodeprojs = config.project_root.glob('*.xcodeproj')
@xcodeproj = xcodeprojs.first if xcodeprojs.size == 1
end
end
......@@ -135,6 +137,19 @@ module Pod
@target_definition.link_with = targets
end
def workspace(path = nil)
if path
@workspace = config.project_root + (File.extname(path) == '.xcworkspace' ? path : "#{path}.xcworkspace")
elsif @workspace
@workspace
else
projects = @target_definitions.map { |_, td| td.xcodeproj }.uniq
if projects.size == 1 && (xcodeproj = @target_definitions[:default].xcodeproj)
xcodeproj.dirname + "#{xcodeproj.basename('.xcodeproj')}.xcworkspace"
end
end
end
# 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)
......
......@@ -2,60 +2,7 @@ require File.expand_path('../../../spec_helper', __FILE__)
describe "Pod::Command::Install" do
it "should include instructions on how to reference the xcode project" do
Pod::Command::Install.banner.should.match %r{xcodeproj 'path/to/project\.xcodeproj'}
end
before do
@config_before = config
Pod::Config.instance = nil
config.silent = true
end
after do
Pod::Config.instance = @config_before
end
describe "When the Podfile does not specify the xcodeproject" do
before do
config.stubs(:podfile).returns(Pod::Podfile.new { platform :ios; dependency 'AFNetworking'})
@installer = Pod::Command::Install.new(Pod::Command::ARGV.new)
end
it "raises an informative error" do
should.raise(Pod::Informative) { @installer.run }
end
it "should include an informative message" do
begin
@installer.run
rescue Pod::Informative => err
err.message.should.match %r{xcodeproj 'path/to/project\.xcodeproj'}
end
end
end
describe "When the Podfile specifies xcodeproj to an invalid path" do
before do
config.stubs(:podfile).returns(Pod::Podfile.new do
platform :ios
xcodeproj 'nonexistent/project.xcodeproj'
dependency 'AFNetworking'
end)
@installer = Pod::Command::Install.new(Pod::Command::ARGV.new)
end
it "raises an informative error" do
should.raise(Pod::Informative) { @installer.run }
end
it "should include an informative message" do
begin
@installer.run
rescue Pod::Informative => err
err.message.should.match /The specified project `nonexistent\/project\.xcodeproj'/
end
end
Pod::Command::Install.banner.should.match %r{xcodeproj 'path/to/XcodeProject'}
end
end
......@@ -25,10 +25,15 @@ describe Pod::Installer::UserProjectIntegrator do
config.project_root = nil
end
it "returns the path to the workspace in the project's root" do
it "returns the path to the workspace from the Podfile" do
@integrator.workspace_path.should == config.project_root + 'SampleProject.xcworkspace'
end
it "raises if no workspace could be selected" do
@podfile.stubs(:workspace)
lambda { @integrator.workspace_path }.should.raise Pod::Informative
end
it "returns the path to the Pods.xcodeproj document" do
@integrator.pods_project_path.should == config.project_root + 'Pods/Pods.xcodeproj'
end
......@@ -37,9 +42,27 @@ describe Pod::Installer::UserProjectIntegrator do
@integrator.target_integrators.map(&:target_definition).should == @podfile.target_definitions.values
end
before do
@target_integrator = @integrator.target_integrators.first
end
it "returns the the user's project, that contains the target, from the Podfile" do
@target_integrator.user_project_path.should == @sample_project_path
@target_integrator.user_project.should == Xcodeproj::Project.new(@sample_project_path)
end
it "raises if no project could be selected" do
@target_integrator.target_definition.stubs(:xcodeproj).returns(nil)
lambda { @target_integrator.user_project_path }.should.raise Pod::Informative
end
it "raises if the project path doesn't exist" do
@target_integrator.target_definition.xcodeproj.stubs(:exist?).returns(false)
lambda { @target_integrator.user_project_path }.should.raise Pod::Informative
end
it "uses the first target in the user's project if no explicit target is specified" do
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]
@target_integrator.target_definition.stubs(:link_with).returns(nil)
@target_integrator.targets.should == [Xcodeproj::Project.new(@sample_project_path).targets.first]
end
end
......@@ -63,6 +63,48 @@ describe "Pod::Podfile" do
yielded.should == :an_installer
end
it "assumes the xcode project is the only existing project in the root" do
podfile = Pod::Podfile.new do
target(:another_target) {}
end
path = config.project_root + 'MyProject.xcodeproj'
config.project_root.expects(:glob).with('*.xcodeproj').returns([path])
podfile.target_definitions[:default].xcodeproj.should == path
podfile.target_definitions[:another_target].xcodeproj.should == path
end
it "assumes the basename of the workspace is the same as the default target's project basename" do
path = config.project_root + 'MyProject.xcodeproj'
config.project_root.expects(:glob).with('*.xcodeproj').returns([path])
Pod::Podfile.new {}.workspace.should == config.project_root + 'MyProject.xcworkspace'
Pod::Podfile.new do
xcodeproj 'AnotherProject.xcodeproj'
end.workspace.should == config.project_root + 'AnotherProject.xcworkspace'
end
it "does not base the workspace name on the default target's project if there are multiple projects specified" do
Pod::Podfile.new do
xcodeproj 'MyProject'
target :another_target do
xcodeproj 'AnotherProject'
end
end.workspace.should == nil
end
it "specifies the Xcode workspace to use" do
Pod::Podfile.new do
xcodeproj 'AnotherProject'
workspace 'MyWorkspace'
end.workspace.should == config.project_root + 'MyWorkspace.xcworkspace'
Pod::Podfile.new do
xcodeproj 'AnotherProject'
workspace 'MyWorkspace.xcworkspace'
end.workspace.should == config.project_root + 'MyWorkspace.xcworkspace'
end
describe "concerning targets (dependency groups)" do
it "returns wether or not a target has any dependencies" do
Pod::Podfile.new do
......@@ -136,11 +178,11 @@ describe "Pod::Podfile" do
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')
target.xcodeproj.should == config.project_root + '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')
target.xcodeproj.should == config.project_root + 'OSX Project.xcodeproj'
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