Commit 17549920 authored by Morgan McKenzie's avatar Morgan McKenzie

[PathList] Actually return absolute paths from glob

Fixes issue #7463 - when a glob is contained within a symlinked
directory, it doesn't return actual absolute path and therefore
public headers aren't set as public for a static framework.
parent 212a5d3c
......@@ -105,6 +105,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Ruenzuo](https://github.com/Ruenzuo)
[#6964](https://github.com/CocoaPods/CocoaPods/issues/6964)
* Fix returning absolute paths from glob, fixes issue with static framework and public headers.
[Morgan McKenzie](https://github.com/rmtmckenzie)
[#7463](https://github.com/CocoaPods/CocoaPods/issues/7463)
## 1.4.0 (2018-01-18)
##### Enhancements
......
......@@ -88,7 +88,7 @@ module Pod
# @return [Array<Pathname>]
#
def glob(patterns, options = {})
relative_glob(patterns, options).map { |p| root + p }
relative_glob(patterns, options).map { |p| (root + p).realpath }
end
# The list of relative paths that are case insensitively matched by a
......
......@@ -412,21 +412,25 @@ module Pod
end
it 'raises when source file reference is not found' do
File.symlink(@first_source_file, @source_symlink_file)
file_path = @first_source_file.dirname + "notthere-#{@first_source_file.basename}"
File.symlink(file_path, @source_symlink_file)
path_list = Sandbox::PathList.new(fixture('banana-lib'))
file_accessor = Sandbox::FileAccessor.new(path_list, @spec.consumer(:ios))
@pod_target.file_accessors = [file_accessor]
exception = lambda { @installer.install! }.should.raise Informative
exception.message.should.include "Unable to find source ref for #{@source_symlink_file} for target BananaLib."
exception = lambda { @installer.install! }.should.raise Errno::ENOENT
exception.message.should.include 'No such file or directory'
exception.message.should.include file_path.to_s
end
it 'raises when header file reference is not found' do
File.symlink(@first_header_file, @header_symlink_file)
file_path = @first_header_file.dirname + "notthere-#{@first_header_file.basename}"
File.symlink(file_path, @header_symlink_file)
path_list = Sandbox::PathList.new(fixture('banana-lib'))
file_accessor = Sandbox::FileAccessor.new(path_list, @spec.consumer(:ios))
@pod_target.file_accessors = [file_accessor]
exception = lambda { @installer.install! }.should.raise Informative
exception.message.should.include "Unable to find header ref for #{@header_symlink_file} for target BananaLib."
exception = lambda { @installer.install! }.should.raise Errno::ENOENT
exception.message.should.include 'No such file or directory'
exception.message.should.include file_path.to_s
end
it 'does not raise when header file reference is found' do
......@@ -452,6 +456,58 @@ module Pod
#--------------------------------------#
describe 'in symlinked directory' do
before do
# copy banana-lib to a temp directory, make symlink to this dir
@tmpdir = Pathname.new(Dir.mktmpdir)
old_path_root = Sandbox::PathList.new(fixture('banana-lib')).root
FileUtils.copy_entry(old_path_root.to_s, @tmpdir + 'banana-lib')
@symlink_dir = old_path_root.dirname + 'banana-lib-symlinked'
FileUtils.remove_entry(@symlink_dir) if File.symlink?(@symlink_dir)
File.symlink(@tmpdir + 'banana-lib', @symlink_dir.to_s)
# reset project to use symlinked dir
@project = Project.new(config.sandbox.project_path)
config.sandbox.project = @project
path_list = Sandbox::PathList.new(fixture('banana-lib-symlinked/'))
@spec = fixture_spec('banana-lib-symlinked/BananaLib.podspec')
file_accessor = Sandbox::FileAccessor.new(path_list, @spec.consumer(:ios))
@project.add_pod_group('BananaLib', fixture('banana-lib-symlinked/'))
group = @project.group_for_spec('BananaLib')
file_accessor.source_files.each do |file|
@project.add_file_reference(file, group)
end
file_accessor.resources.each do |resource|
@project.add_file_reference(resource, group)
end
@pod_target = PodTarget.new([@spec], [@target_definition], config.sandbox)
@pod_target.file_accessors = [file_accessor]
@pod_target.user_build_configurations = { 'Debug' => :debug, 'Release' => :release }
@installer = PodTargetInstaller.new(config.sandbox, @pod_target)
end
after do
FileUtils.remove_entry(@tmpdir) if Dir.exist?(@tmpdir)
FileUtils.remove_entry(@symlink_dir) if File.symlink?(@symlink_dir)
end
it 'headers are public if podspec directory is symlinked for static lib' do
@pod_target.stubs(:static_framework?).returns(true)
@pod_target.stubs(:requires_frameworks?).returns(true)
@installer.install!
@project.targets.first.headers_build_phase.files.find do |hf|
hf.display_name == 'Banana.h' && hf.settings['ATTRIBUTES'] == ['Public']
end.should.not.nil?
end
end
#--------------------------------------#
it 'adds framework resources to the framework target' do
@pod_target.stubs(:requires_frameworks? => true)
@installer.install!
......
......@@ -109,6 +109,29 @@ module Pod
paths.all?(&:absolute?).should == true
end
describe 'Symlinked Directory' do
before do
@tmpdir = Pathname.new(Dir.mktmpdir)
FileUtils.copy_entry(@path_list.root.to_s, @tmpdir + 'banana-lib')
@symlink_dir = @path_list.root.dirname + 'banana-lib-symlinked'
FileUtils.remove_entry(@symlink_dir) if File.symlink?(@symlink_dir)
end
after do
FileUtils.remove_entry(@tmpdir) if Dir.exist?(@tmpdir)
FileUtils.remove_entry(@symlink_dir) if File.symlink?(@symlink_dir)
end
it 'glob returns the absolute path when root is a symlinked directory' do
File.symlink(@tmpdir + 'banana-lib', @symlink_dir.to_s)
@path_list = Sandbox::PathList.new(fixture('banana-lib-symlinked/'))
paths = @path_list.glob('Classes/*.{h,m}')
paths.first.realpath.to_s.should.include? @tmpdir.to_s
end
end
it 'can return the relative paths from glob' do
paths = @path_list.relative_glob('Classes/*.{h,m}')
paths.any?(&:absolute?).should == false
......@@ -249,5 +272,53 @@ module Pod
end
#-------------------------------------------------------------------------#
describe 'Symlinks' do
before do
@symlink_dir = @path_list.root + 'Classes' + 'symlinked'
@symlink_dir_file = @symlink_dir + 'someheader.h'
@symlink_file = @path_list.root + 'Classes' + 'symlinked.h'
@tmpdir = Pathname.new(Dir.mktmpdir)
tmpfile = Tempfile.new(['base', '.h'])
@tmpfile = tmpfile.path
tmpfile.close
@tmpdirheader = @tmpdir + 'someheader.h'
File.write(@tmpdirheader.to_s, '// this file does nothing. \n')
File.write(@tmpfile.to_s, '// this file also does nothing. \n')
FileUtils.remove_entry(@symlink_dir) if File.symlink?(@symlink_dir)
FileUtils.remove_entry(@symlink_file) if File.symlink?(@symlink_file)
end
after do
FileUtils.remove_entry(@tmpdir) if Dir.exist?(@tmpdir)
FileUtils.remove_entry(@tmpfile) if File.exist?(@tmpfile)
FileUtils.remove_entry(@symlink_dir) if File.symlink?(@symlink_dir)
FileUtils.remove_entry(@symlink_file) if File.symlink?(@symlink_file)
end
it 'includes symlinked file' do
@path_list.instance_variable_set(:@files, nil)
File.symlink(@tmpfile, @symlink_file)
@path_list.files.map(&:to_s).include?('Classes/symlinked.h').should == true
end
it 'includes symlinked dir' do
@path_list.instance_variable_set(:@dirs, nil)
File.symlink(@tmpdir, @symlink_dir)
@path_list.dirs.map(&:to_s).include?('Classes/symlinked').should == true
end
it 'doesn\'t include file in symlinked dir' do
@path_list.instance_variable_set(:@files, nil)
@path_list.instance_variable_set(:@dirs, nil)
File.symlink(@tmpdir, @symlink_dir)
@path_list.files.map(&:to_s).include?('Classes/symlinked/someheader.h').should == false
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