Commit 628a49b8 authored by Fabio Pelosin's avatar Fabio Pelosin

[Project] Don't duplicate file references

parent b806590e
...@@ -99,9 +99,6 @@ module Pod ...@@ -99,9 +99,6 @@ module Pod
# @return [Array<Sandbox::FileAccessor>] The file accessors for all the # @return [Array<Sandbox::FileAccessor>] The file accessors for all the
# specs platform combinations. # specs platform combinations.
# #
# TODO Ideally the file accessors should be created one per spec per
# platform in a single installation.
#
def file_accessors def file_accessors
@file_accessors ||= libraries.map(&:file_accessors).flatten.compact @file_accessors ||= libraries.map(&:file_accessors).flatten.compact
end end
......
...@@ -92,8 +92,8 @@ module Pod ...@@ -92,8 +92,8 @@ module Pod
def add_spec_group(spec_name, root_group) def add_spec_group(spec_name, root_group)
current_group = root_group current_group = root_group
group = nil group = nil
spec_name.split('/').each do |spec_name| spec_name.split('/').each do |name|
group = current_group[spec_name] || current_group.new_group(spec_name) group = current_group[name] || current_group.new_group(name)
current_group = group current_group = group
end end
group group
...@@ -106,7 +106,12 @@ module Pod ...@@ -106,7 +106,12 @@ module Pod
# @!group File references # @!group File references
# Adds a file reference for each one of the given files in the specified # Adds a file reference for each one of the given files in the specified
# group, namespaced by specification. # group, namespaced by specification unless a file reference for the given
# path alrady exits.
#
# @note With this set-up different subspecs might not reference the same
# file (i.e. the first will win). Not sure thought if this is a
# limitation or a feature.
# #
# @param [Array<Pathname,String>] paths # @param [Array<Pathname,String>] paths
# The files for which the file reference is needed. # The files for which the file reference is needed.
...@@ -119,14 +124,17 @@ module Pod ...@@ -119,14 +124,17 @@ module Pod
# #
# @return [void] # @return [void]
# #
def add_file_references(paths, spec_name, parent_group) def add_file_references(absolute_path, spec_name, parent_group)
group = add_spec_group(spec_name, parent_group) group = add_spec_group(spec_name, parent_group)
paths.each do |file| absolute_path.each do |file|
existing = file_reference(file)
unless existing
file = Pathname.new(file) file = Pathname.new(file)
ref = group.new_file(relativize(file)) ref = group.new_file(relativize(file))
@refs_by_absolute_path[file] = ref @refs_by_absolute_path[file] = ref
end end
end end
end
# Returns the file reference for the given absolute file path. # Returns the file reference for the given absolute file path.
# #
...@@ -137,7 +145,7 @@ module Pod ...@@ -137,7 +145,7 @@ module Pod
# @return [Nil] If no file reference could be found. # @return [Nil] If no file reference could be found.
# #
def file_reference(absolute_path) def file_reference(absolute_path)
source_file = Pathname.new(absolute_path) absolute_path = Pathname.new(absolute_path)
refs_by_absolute_path[absolute_path] refs_by_absolute_path[absolute_path]
end end
......
...@@ -52,7 +52,7 @@ $:.unshift((ROOT + 'spec').to_s) ...@@ -52,7 +52,7 @@ $:.unshift((ROOT + 'spec').to_s)
require 'spec_helper/bacon' require 'spec_helper/bacon'
require 'colored' require 'colored'
require 'diffy' require 'diffy'
require 'Xcodeproj' require 'Xcodeproj' # For Differ
# @return [Pathname The folder where the CocoaPods binary should operate. # @return [Pathname The folder where the CocoaPods binary should operate.
# #
...@@ -221,11 +221,16 @@ def yaml_should_match(expected, produced) ...@@ -221,11 +221,16 @@ def yaml_should_match(expected, produced)
# Remove CocoaPods version # Remove CocoaPods version
expected_yaml.delete('COCOAPODS') expected_yaml.delete('COCOAPODS')
produced_yaml.delete('COCOAPODS') produced_yaml.delete('COCOAPODS')
desc = "YAML comparison error `#{expected}`" desc = []
desc << "\n EXPECTED:\n#{expected_yaml.inspect.cyan}\n" desc << "YAML comparison error `#{expected}`"
desc << "\n PRODUCED:\n#{produced_yaml.inspect.cyan}\n" diff_options = {:key_1 => "$produced", :key_2 => "$expected"}
# TODO extract Xcodeproj diff logic a provide a diff diff = Xcodeproj::Differ.diff(produced_yaml, expected_yaml, diff_options).to_yaml
expected_yaml.should.satisfy(desc) do |expected_yaml| diff.gsub!("$produced", "produced".green)
diff.gsub!("$expected", "expected".red)
desc << ("--- DIFF " << "-" * 70)
desc << diff
desc << ("--- END " << "-" * 70)
expected_yaml.should.satisfy(desc * "\n\n") do
if RUBY_VERSION < "1.9" if RUBY_VERSION < "1.9"
true # CP is not sorting array derived from hashes whose order is true # CP is not sorting array derived from hashes whose order is
# undefined in 1.8.7 # undefined in 1.8.7
...@@ -277,11 +282,9 @@ def file_should_match(expected, produced) ...@@ -277,11 +282,9 @@ def file_should_match(expected, produced)
else description << line.gsub("\n",'') else description << line.gsub("\n",'')
end end
end end
description << "" << ("--- PRODUCED " << "-" * 66) << ""
description << File.read(produced)
description << ("--- END " << "-" * 70) description << ("--- END " << "-" * 70)
description << "" description << ""
is_equal.should.satisfy(description * "\n") do |is_equal| is_equal.should.satisfy(description * "\n") do
is_equal == true is_equal == true
end end
end end
......
...@@ -57,6 +57,15 @@ describe Pod::Project do ...@@ -57,6 +57,15 @@ describe Pod::Project do
group.children.map(&:path).should == [ "A_POD/some_file.m" ] group.children.map(&:path).should == [ "A_POD/some_file.m" ]
end end
it "adds the only one file reference for a given absolute path" do
source_files = [ config.sandbox.root + "A_POD/some_file.m" ]
@project.add_file_references(source_files, 'BananaLib', @project.pods)
@project.add_file_references(source_files, 'BananaLib', @project.pods)
group = @project['Pods/BananaLib']
group.children.count.should == 1
group.children.first.path.should == "A_POD/some_file.m"
end
it "returns the file reference for a given source file" do it "returns the file reference for a given source file" do
file = config.sandbox.root + "A_POD/some_file.m" file = config.sandbox.root + "A_POD/some_file.m"
@project.add_file_references([file], 'BananaLib', @project.pods) @project.add_file_references([file], 'BananaLib', @project.pods)
......
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