Unverified Commit bf310672 authored by Dimitris Koutsogiorgas's avatar Dimitris Koutsogiorgas Committed by GitHub

Merge pull request #7527 from CocoaPods/segiddins/path-list-only-realpath-headers

[PathList] Wait to resolve symlinks until checking header ACL
parents 800a49d4 3f5f1952
...@@ -182,8 +182,8 @@ module Pod ...@@ -182,8 +182,8 @@ module Pod
native_target = target.native_target_for_spec(consumer.spec) native_target = target.native_target_for_spec(consumer.spec)
headers = file_accessor.headers headers = file_accessor.headers
public_headers = file_accessor.public_headers public_headers = file_accessor.public_headers.map(&:realpath)
private_headers = file_accessor.private_headers private_headers = file_accessor.private_headers.map(&:realpath)
other_source_files = file_accessor.source_files.reject { |sf| SOURCE_FILE_EXTENSIONS.include?(sf.extname) } other_source_files = file_accessor.source_files.reject { |sf| SOURCE_FILE_EXTENSIONS.include?(sf.extname) }
{ {
......
...@@ -202,15 +202,14 @@ module Pod ...@@ -202,15 +202,14 @@ module Pod
# @return [PBXFileReference] The new file reference. # @return [PBXFileReference] The new file reference.
# #
def add_file_reference(absolute_path, group, reflect_file_system_structure = false, base_path = nil) def add_file_reference(absolute_path, group, reflect_file_system_structure = false, base_path = nil)
file_path_name = absolute_path.is_a?(Pathname) ? absolute_path : Pathname.new(absolute_path) file_path_name = absolute_path.is_a?(Pathname) ? absolute_path : Pathname(absolute_path)
group = group_for_path_in_group(file_path_name, group, reflect_file_system_structure, base_path) if ref = reference_for_path(file_path_name)
if ref = reference_for_path(file_path_name.realpath) return ref
@refs_by_absolute_path[absolute_path.to_s] = ref
ref
else
ref = group.new_file(file_path_name.realpath)
@refs_by_absolute_path[absolute_path.to_s] = ref
end end
group = group_for_path_in_group(file_path_name, group, reflect_file_system_structure, base_path)
ref = group.new_file(file_path_name.realpath)
@refs_by_absolute_path[file_path_name.to_s] = ref
end end
# Returns the file reference for the given absolute path. # Returns the file reference for the given absolute path.
...@@ -222,11 +221,12 @@ module Pod ...@@ -222,11 +221,12 @@ module Pod
# @return [Nil] If no file reference could be found. # @return [Nil] If no file reference could be found.
# #
def reference_for_path(absolute_path) def reference_for_path(absolute_path)
unless Pathname.new(absolute_path).absolute? absolute_path = absolute_path.is_a?(Pathname) ? absolute_path : Pathname(absolute_path)
unless absolute_path.absolute?
raise ArgumentError, "Paths must be absolute #{absolute_path}" raise ArgumentError, "Paths must be absolute #{absolute_path}"
end end
refs_by_absolute_path[absolute_path.to_s] refs_by_absolute_path[absolute_path.to_s] ||= refs_by_absolute_path[absolute_path.realpath.to_s]
end end
# Adds a file reference to the Podfile. # Adds a file reference to the Podfile.
......
...@@ -88,7 +88,7 @@ module Pod ...@@ -88,7 +88,7 @@ module Pod
# @return [Array<Pathname>] # @return [Array<Pathname>]
# #
def glob(patterns, options = {}) def glob(patterns, options = {})
relative_glob(patterns, options).map { |p| (root + p).realpath } relative_glob(patterns, options).map { |p| root.join(p) }
end end
# The list of relative paths that are case insensitively matched by a # The list of relative paths that are case insensitively matched by a
...@@ -205,35 +205,16 @@ module Pod ...@@ -205,35 +205,16 @@ module Pod
else else
patterns = [pattern] patterns = [pattern]
values_by_set.each do |set, values| values_by_set.each do |set, values|
patterns = patterns.map do |old_pattern| patterns = patterns.flat_map do |old_pattern|
values.map do |value| values.map do |value|
old_pattern.gsub(set, value) old_pattern.gsub(set, value)
end end
end.flatten end
end end
patterns patterns
end end
end end
# Escapes the glob metacharacters from a given path so it can used in
# Dir#glob and similar methods.
#
# @note See CocoaPods/CocoaPods#862.
#
# @param [String, Pathname] path
# The path to escape.
#
# @return [Pathname] The escaped path.
#
def escape_path_for_glob(path)
result = path.to_s
characters_to_escape = ['[', ']', '{', '}', '?', '*']
characters_to_escape.each do |character|
result.gsub!(character, "\\#{character}")
end
Pathname.new(result)
end
#-----------------------------------------------------------------------# #-----------------------------------------------------------------------#
end end
end end
......
...@@ -364,7 +364,7 @@ module Pod ...@@ -364,7 +364,7 @@ module Pod
@project.add_pod_group('BananaLib', config.sandbox.pod_dir('BananaLib'), false) @project.add_pod_group('BananaLib', config.sandbox.pod_dir('BananaLib'), false)
@file = config.sandbox.pod_dir('BananaLib') + 'file.m' @file = config.sandbox.pod_dir('BananaLib') + 'file.m'
@group = @project.group_for_spec('BananaLib') @group = @project.group_for_spec('BananaLib')
Pathname.any_instance.stubs(:realpath).returns(@file) @file.stubs(:realpath).returns(@file)
@project.add_file_reference(@file, @group) @project.add_file_reference(@file, @group)
end end
...@@ -375,6 +375,7 @@ module Pod ...@@ -375,6 +375,7 @@ module Pod
it 'returns nil if no reference for the given path is available' do it 'returns nil if no reference for the given path is available' do
another_file = config.sandbox.pod_dir('BananaLib') + 'another_file.m' another_file = config.sandbox.pod_dir('BananaLib') + 'another_file.m'
another_file.stubs(:realpath).returns(another_file)
ref = @project.reference_for_path(another_file) ref = @project.reference_for_path(another_file)
ref.should.be.nil ref.should.be.nil
end end
......
...@@ -192,6 +192,13 @@ module Pod ...@@ -192,6 +192,13 @@ module Pod
Resources/sub_dir Resources/sub_dir
) )
end end
it 'can glob for exact matches' do
paths = @path_list.relative_glob('libBananalib.a').map(&:to_s)
paths.sort.should == %w(
libBananalib.a
)
end
end end
describe 'Reading file system' do describe 'Reading file system' do
...@@ -260,15 +267,6 @@ module Pod ...@@ -260,15 +267,6 @@ module Pod
end end
#--------------------------------------# #--------------------------------------#
describe '#escape_path_for_glob' do
it 'escapes metacharacters' do
escaped = @path_list.send(:escape_path_for_glob, '[]{}?**')
escaped.to_s.should == '\[\]\{\}\?\*\*'
end
end
#--------------------------------------#
end end
#-------------------------------------------------------------------------# #-------------------------------------------------------------------------#
...@@ -300,14 +298,27 @@ module Pod ...@@ -300,14 +298,27 @@ module Pod
@path_list.instance_variable_set(:@files, nil) @path_list.instance_variable_set(:@files, nil)
File.symlink(@tmpfile, @symlink_file) File.symlink(@tmpfile, @symlink_file)
@path_list.files.map(&:to_s).include?('Classes/symlinked.h').should == true @path_list.files.map(&:to_s).should.include?('Classes/symlinked.h')
end
it 'includes symlinked file with a different basename' do
orange_h = @path_list.root.join('Classes', 'Orange.h')
File.symlink('Banana.h', orange_h)
begin
@path_list.glob('Classes/Orange.h').should == [
orange_h,
]
ensure
FileUtils.remove_entry(orange_h)
end
end end
it 'includes symlinked dir' do it 'includes symlinked dir' do
@path_list.instance_variable_set(:@dirs, nil) @path_list.instance_variable_set(:@dirs, nil)
File.symlink(@tmpdir, @symlink_dir) File.symlink(@tmpdir, @symlink_dir)
@path_list.dirs.map(&:to_s).include?('Classes/symlinked').should == true @path_list.dirs.map(&:to_s).should.include?('Classes/symlinked')
end end
it 'doesn\'t include file in symlinked dir' do it 'doesn\'t include file in symlinked dir' do
...@@ -315,7 +326,7 @@ module Pod ...@@ -315,7 +326,7 @@ module Pod
@path_list.instance_variable_set(:@dirs, nil) @path_list.instance_variable_set(:@dirs, nil)
File.symlink(@tmpdir, @symlink_dir) File.symlink(@tmpdir, @symlink_dir)
@path_list.files.map(&:to_s).include?('Classes/symlinked/someheader.h').should == false @path_list.files.map(&:to_s).should.not.include?('Classes/symlinked/someheader.h')
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