Commit f97108e5 authored by Samuel Giddins's avatar Samuel Giddins

[Installer] Add an API that just returns AggregateTargets from a sandbox

parent 6ed5ddf1
......@@ -66,8 +66,8 @@ module Pod
# @param [Lockfile] lockfile @see #lockfile
#
def initialize(sandbox, podfile, lockfile = nil)
@sandbox = sandbox || raise(ArgumentError, "need a sandbox")
@podfile = podfile || raise(ArgumentError, "need a podfile")
@sandbox = sandbox || raise(ArgumentError, 'need a sandbox')
@podfile = podfile || raise(ArgumentError, 'need a podfile')
@lockfile = lockfile
@use_default_plugins = true
......@@ -669,5 +669,30 @@ module Pod
end
#-------------------------------------------------------------------------#
public
# @!group Convenience Methods
def self.targets_from_sandbox(sandbox, podfile, lockfile)
raise Informative, 'You must run `pod install` to be able to generate target information' unless lockfile
new(sandbox, podfile, lockfile).instance_exec do
plugin_sources = run_source_provider_hooks
analyzer = create_analyzer(plugin_sources)
analyze(analyzer)
if analyzer.podfile_needs_install?(analyzer.result)
raise Pod::Informative, 'The Podfile has changed, you must run `pod install`'
elsif analyzer.sandbox_needs_install?(analyzer.result)
raise Pod::Informative, 'The `Pods` directory is out-of-date, you must run `pod install`'
end
create_file_accessors
aggregate_targets
end
end
#-------------------------------------------------------------------------#
end
end
......@@ -35,7 +35,7 @@ def generate_local_podfile
platform :ios
project SpecHelper.fixture('SampleProject/SampleProject'), 'Test' => :debug, 'App Store' => :release
target 'SampleProject' do
pod 'Reachability', :path => SpecHelper.fixture('integration/Reachability')
pod 'Reachability', :path => SpecHelper.fixture('integration/Reachability').to_s
target 'SampleProjectTests' do
inherit! :search_paths
end
......@@ -734,5 +734,96 @@ module Pod
@installer.install!
end
end
#-------------------------------------------------------------------------#
describe '.targets_from_sandbox' do
it 'raises when there is no lockfile' do
sandbox = config.sandbox
podfile = generate_podfile
lockfile = nil
should.raise Informative do
Installer.targets_from_sandbox(sandbox, podfile, lockfile)
end.message.should.include 'You must run `pod install` to be able to generate target information'
end
it 'raises when the podfile has changed' do
sandbox = config.sandbox
podfile = generate_podfile(['AFNetworking'])
lockfile = generate_lockfile
should.raise Informative do
Installer.targets_from_sandbox(sandbox, podfile, lockfile)
end.message.should.include 'The Podfile has changed, you must run `pod install`'
end
it 'raises when the sandbox has changed' do
sandbox = config.sandbox
podfile = generate_podfile
lockfile = generate_lockfile
lockfile.internal_data['DEPENDENCIES'] = podfile.dependencies.map(&:to_s)
should.raise Informative do
Installer.targets_from_sandbox(sandbox, podfile, lockfile)
end.message.should.include 'The `Pods` directory is out-of-date, you must run `pod install`'
end
it 'returns the aggregate targets without performing installation' do
podfile = generate_podfile
lockfile = generate_lockfile
@installer = Installer.new(config.sandbox, podfile, lockfile)
@installer.expects(:integrate_user_project)
@installer.install!
pod_targets = @installer.aggregate_targets.map(&:pod_targets)
::SpecHelper.reset_config_instance
aggregate_targets = Installer.targets_from_sandbox(config.sandbox, podfile, config.lockfile)
aggregate_targets.map(&:target_definition).should == [
podfile.target_definitions['SampleProject'], podfile.target_definitions['SampleProjectTests']
]
aggregate_targets.last.pod_targets.should == []
sample_project_target = aggregate_targets.first
sample_project_target.pod_targets.map(&:label).should == %w(JSONKit)
jsonkit = sample_project_target.pod_targets.first
jsonkit.sandbox.should == config.sandbox
jsonkit.file_accessors.flat_map(&:root).should == [config.sandbox.pod_dir('JSONKit')]
jsonkit.archs.should == []
end
it 'returns the aggregate targets without performing installation with local pods' do
podfile = generate_local_podfile
lockfile = generate_lockfile
@installer = Installer.new(config.sandbox, podfile, lockfile)
@installer.expects(:integrate_user_project)
@installer.install!
pod_targets = @installer.aggregate_targets.map(&:pod_targets)
::SpecHelper.reset_config_instance
aggregate_targets = Installer.targets_from_sandbox(config.sandbox, podfile, config.lockfile)
aggregate_targets.map(&:target_definition).should == [
podfile.target_definitions['SampleProject'], podfile.target_definitions['SampleProjectTests']
]
aggregate_targets.last.pod_targets.should == []
sample_project_target = aggregate_targets.first
sample_project_target.pod_targets.map(&:label).should == %w(Reachability)
jsonkit = sample_project_target.pod_targets.first
jsonkit.sandbox.should == config.sandbox
jsonkit.file_accessors.flat_map(&:root).should == [config.sandbox.pod_dir('Reachability')]
jsonkit.archs.should == []
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