Commit a9d87406 authored by Fabio Pelosin's avatar Fabio Pelosin

[Installer] Use aggregate target for library reppresentation

Closes #1157
parent 6827f83d
......@@ -59,8 +59,8 @@ module Pod
#
def specs_by_lib
result = {}
installer.pod_targets.each do |lib|
result[installer.library_rep(lib)] = lib.specs
installer.aggregate_targets.each do |aggregate_target|
result[installer.library_rep(aggregate_target)] = aggregate_target.specs
end
result
end
......
......@@ -83,6 +83,7 @@ module Pod
def initialize(sandbox, library)
@sandbox = sandbox
@library = library
raise "[BUG]" unless library.is_a?(AggregateTarget)
end
#-----------------------------------------------------------------------#
......
......@@ -547,14 +547,14 @@ module Pod
# @return [LibraryRepresentation]
#
def library_rep(library)
Hooks::LibraryRepresentation.new(sandbox, library)
def library_rep(aggregate_target)
Hooks::LibraryRepresentation.new(sandbox, aggregate_target)
end
# @return [Array<LibraryRepresentation>]
#
def library_reps
@library_reps ||= pod_targets.map { |lib| library_rep(lib) }
@library_reps ||= aggregate_targets.map { |lib| library_rep(lib) }
end
# @return [Array<PodRepresentation>]
......@@ -571,7 +571,9 @@ module Pod
# @return [Array<Library>] The library.
#
def libraries_using_spec(spec)
pod_targets.select { |pod_target| pod_target.specs.include?(spec) }
aggregate_targets.select do |aggregate_target|
aggregate_target.pod_targets.any? { |pod_target| pod_target.specs.include?(spec) }
end
end
# @return [Array<Library>] The libraries generated by the installation
......
......@@ -38,7 +38,7 @@ module Pod
# @return [String] A string suitable for debugging.
#
def inspect
"<#{self.class} name=#{name} platform=#{platform}>"
"<#{self.class} name=#{name} >"
end
#-------------------------------------------------------------------------#
......
......@@ -56,9 +56,16 @@ module Pod
#
attr_accessor :pod_targets
# @return [Array<SpecConsumer>]
# @return [Array<Specification>] The specifications used by this aggregate target.
#
def specs
pod_targets.map(&:specs).flatten
end
# @return [Array<Specification::Consumer>] The consumers of the Pod.
#
def spec_consumers
pod_targets.map(&:specs).flatten.map { |spec| spec.consumer(platform) }
specs.map { |spec| spec.consumer(platform) }
end
# @return [Pathname] The absolute path of acknowledgements file.
......
PODS:Reachability (3.1.0) TARGETS:Pods-Reachability
PODS:Reachability (3.1.0) TARGETS:Pods
......@@ -40,13 +40,13 @@ module Pod
end
it "the hook representation of the libraries" do
@rep.libraries.map(&:name).sort.should == ['Pods-JSONKit'].sort
@rep.libraries.map(&:name).sort.should == ['Pods'].sort
end
it "returns the specs by library representation" do
specs_by_lib = @rep.specs_by_lib
lib_rep = specs_by_lib.keys.first
lib_rep.name.should == 'Pods-JSONKit'
lib_rep.name.should == 'Pods'
specs_by_lib.should == { lib_rep => @specs }
end
......
......@@ -7,7 +7,7 @@ module Pod
@target_definition = Podfile::TargetDefinition.new('MyApp', nil)
@spec = Spec.new
@spec.name = 'RestKit'
@lib = PodTarget.new([@spec], @target_definition, config.sandbox)
@lib = AggregateTarget.new(@target_definition, config.sandbox)
@rep = Hooks::LibraryRepresentation.new(config.sandbox, @lib)
end
......@@ -16,7 +16,7 @@ module Pod
describe "Public Hooks API" do
it "returns the name" do
@rep.name.should == 'Pods-MyApp-RestKit'
@rep.name.should == 'Pods-MyApp'
end
it "returns the dependencies" do
......@@ -29,7 +29,11 @@ module Pod
end
it "returns the path of the prefix header" do
@rep.prefix_header_path.should == temporary_directory + 'Pods/Pods-MyApp-RestKit-prefix.pch'
@rep.prefix_header_path.should == temporary_directory + 'Pods/Pods-MyApp-prefix.pch'
end
it "returns the path of the copy resources script" do
@rep.copy_resources_script_path.should == temporary_directory + 'Pods/Pods-MyApp-resources.sh'
end
it "returns the pods project" do
......
......@@ -383,7 +383,7 @@ module Pod
@specs = @installer.pod_targets.map(&:specs).flatten
@spec = @specs.find { |spec| spec && spec.name == 'JSONKit' }
@installer.stubs(:installed_specs).returns(@specs)
@lib = @installer.aggregate_targets.first.pod_targets.first
@aggregate_target = @installer.aggregate_targets.first
end
it "runs the pre install hooks" do
......@@ -393,7 +393,7 @@ module Pod
@installer.expects(:installer_rep).returns(installer_rep)
@installer.expects(:pod_rep).with('JSONKit').returns(pod_rep)
@installer.expects(:library_rep).with(@lib).returns(library_rep)
@installer.expects(:library_rep).with(@aggregate_target).returns(library_rep)
@spec.expects(:pre_install!)
@installer.podfile.expects(:pre_install!).with(installer_rep)
@installer.send(:run_pre_install_hooks)
......@@ -404,7 +404,7 @@ module Pod
target_installer_data = stub()
@installer.expects(:installer_rep).returns(installer_rep)
@installer.expects(:library_rep).with(@lib).returns(target_installer_data)
@installer.expects(:library_rep).with(@aggregate_target).returns(target_installer_data)
@spec.expects(:post_install!)
@installer.podfile.expects(:post_install!).with(installer_rep)
@installer.send(:run_post_install_hooks)
......@@ -417,15 +417,14 @@ module Pod
pod_target_osx.stubs(:name).returns('label')
library_ios_rep = stub()
library_osx_rep = stub()
target_installer_data = stub()
@installer.stubs(:pod_targets).returns([pod_target_ios, pod_target_osx])
@installer.stubs(:installer_rep).returns(stub())
@installer.stubs(:library_rep).with(pod_target_ios).returns(library_ios_rep)
@installer.stubs(:library_rep).with(pod_target_osx).returns(library_osx_rep)
@installer.stubs(:library_rep).with(@aggregate_target).returns(target_installer_data).twice
@installer.podfile.expects(:pre_install!)
@spec.expects(:post_install!).with(library_ios_rep)
@spec.expects(:post_install!).with(library_osx_rep)
@spec.expects(:post_install!).with(target_installer_data).once
@installer.send(:run_pre_install_hooks)
@installer.send(:run_post_install_hooks)
......@@ -438,15 +437,15 @@ module Pod
it "returns the hook representation of a pod" do
file_accessor = stub(:spec => @spec)
@lib.stubs(:file_accessors).returns([file_accessor])
@aggregate_target.pod_targets.first.stubs(:file_accessors).returns([file_accessor])
rep = @installer.send(:pod_rep, 'JSONKit')
rep.name.should == 'JSONKit'
rep.root_spec.should == @spec
end
it "returns the hook representation of a library" do
rep = @installer.send(:library_rep, @lib)
rep.send(:library).name.should == 'Pods-JSONKit'
it "returns the hook representation of an aggregate target" do
rep = @installer.send(:library_rep, @aggregate_target)
rep.send(:library).name.should == 'Pods'
end
it "returns the hook representation of all the pods" do
......@@ -454,14 +453,14 @@ module Pod
reps.map(&:name).should == ['JSONKit']
end
it "returns the hook representation of all the target installers" do
it "returns the hook representation of all the aggregate target" do
reps = @installer.send(:library_reps)
reps.map(&:name).sort.should == ['Pods-JSONKit'].sort
reps.map(&:name).sort.should == ['Pods'].sort
end
it "returns the targets which use a given Pod" do
it "returns the aggregate targets which use a given Pod" do
libs = @installer.send(:libraries_using_spec, @spec)
libs.map(&:name).should == ['Pods-JSONKit']
libs.map(&:name).should == ['Pods']
end
end
......
......@@ -79,8 +79,13 @@ module Pod
@target.pod_targets = [pod_target]
end
it "returns the specs of the Pods used by this aggregate target" do
@target.specs.map(&:name).should == ["BananaLib"]
end
it "returns the spec consumers for the pod targets" do
@target.spec_consumers.should.not == nil
consumer_reps = @target.spec_consumers.map { |consumer| [consumer.spec.name, consumer.platform_name ] }
consumer_reps.should == [["BananaLib", :ios]]
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