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

[Project] Don't duplicate file references

parent b806590e
......@@ -99,9 +99,6 @@ module Pod
# @return [Array<Sandbox::FileAccessor>] The file accessors for all the
# specs platform combinations.
#
# TODO Ideally the file accessors should be created one per spec per
# platform in a single installation.
#
def file_accessors
@file_accessors ||= libraries.map(&:file_accessors).flatten.compact
end
......
......@@ -92,8 +92,8 @@ module Pod
def add_spec_group(spec_name, root_group)
current_group = root_group
group = nil
spec_name.split('/').each do |spec_name|
group = current_group[spec_name] || current_group.new_group(spec_name)
spec_name.split('/').each do |name|
group = current_group[name] || current_group.new_group(name)
current_group = group
end
group
......@@ -106,7 +106,12 @@ module Pod
# @!group File references
# 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
# The files for which the file reference is needed.
......@@ -119,12 +124,15 @@ module Pod
#
# @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)
paths.each do |file|
file = Pathname.new(file)
ref = group.new_file(relativize(file))
@refs_by_absolute_path[file] = ref
absolute_path.each do |file|
existing = file_reference(file)
unless existing
file = Pathname.new(file)
ref = group.new_file(relativize(file))
@refs_by_absolute_path[file] = ref
end
end
end
......@@ -137,7 +145,7 @@ module Pod
# @return [Nil] If no file reference could be found.
#
def file_reference(absolute_path)
source_file = Pathname.new(absolute_path)
absolute_path = Pathname.new(absolute_path)
refs_by_absolute_path[absolute_path]
end
......
......@@ -52,7 +52,7 @@ $:.unshift((ROOT + 'spec').to_s)
require 'spec_helper/bacon'
require 'colored'
require 'diffy'
require 'Xcodeproj'
require 'Xcodeproj' # For Differ
# @return [Pathname The folder where the CocoaPods binary should operate.
#
......@@ -221,11 +221,16 @@ def yaml_should_match(expected, produced)
# Remove CocoaPods version
expected_yaml.delete('COCOAPODS')
produced_yaml.delete('COCOAPODS')
desc = "YAML comparison error `#{expected}`"
desc << "\n EXPECTED:\n#{expected_yaml.inspect.cyan}\n"
desc << "\n PRODUCED:\n#{produced_yaml.inspect.cyan}\n"
# TODO extract Xcodeproj diff logic a provide a diff
expected_yaml.should.satisfy(desc) do |expected_yaml|
desc = []
desc << "YAML comparison error `#{expected}`"
diff_options = {:key_1 => "$produced", :key_2 => "$expected"}
diff = Xcodeproj::Differ.diff(produced_yaml, expected_yaml, diff_options).to_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"
true # CP is not sorting array derived from hashes whose order is
# undefined in 1.8.7
......@@ -277,11 +282,9 @@ def file_should_match(expected, produced)
else description << line.gsub("\n",'')
end
end
description << "" << ("--- PRODUCED " << "-" * 66) << ""
description << File.read(produced)
description << ("--- END " << "-" * 70)
description << ""
is_equal.should.satisfy(description * "\n") do |is_equal|
is_equal.should.satisfy(description * "\n") do
is_equal == true
end
end
......
......@@ -57,6 +57,15 @@ describe Pod::Project do
group.children.map(&:path).should == [ "A_POD/some_file.m" ]
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
file = config.sandbox.root + "A_POD/some_file.m"
@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