Skip to content

Commit

Permalink
Merge pull request #4106 from CocoaPods/use-realpath-for-development-…
Browse files Browse the repository at this point in the history
…pods

Fix Swift code completion for Development Pods
  • Loading branch information
segiddins committed Nov 15, 2015
2 parents 313ffd3 + 67e4aca commit dfd3ed6
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -136,6 +136,11 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
[Samuel Giddins](https://github.com/segiddins)
[#4514](https://github.com/CocoaPods/CocoaPods/issues/4514)

* Fix Swift code completion for Development Pods by using `realpath` for
symlinked source files.
[Boris Bügling](https://github.com/neonichu)
[#3777](https://github.com/CocoaPods/CocoaPods/issues/3777)


## 0.39.0 (2015-10-09)

Expand Down
6 changes: 3 additions & 3 deletions lib/cocoapods/project.rb
Expand Up @@ -179,13 +179,13 @@ def pod_support_files_group(pod_name, dir)
# @return [PBXFileReference] The new file reference.
#
def add_file_reference(absolute_path, group, reflect_file_system_structure = false)
file_path_name = Pathname.new(absolute_path)
file_path_name = absolute_path.is_a?(Pathname) ? absolute_path : Pathname.new(absolute_path)
group = group_for_path_in_group(file_path_name, group, reflect_file_system_structure)

if ref = reference_for_path(absolute_path)
if ref = reference_for_path(file_path_name.realpath)
ref
else
ref = group.new_file(absolute_path)
ref = group.new_file(file_path_name.realpath)
@refs_by_absolute_path[absolute_path.to_s] = ref
end
end
Expand Down
14 changes: 10 additions & 4 deletions spec/unit/installer_spec.rb
Expand Up @@ -252,24 +252,30 @@ def @installer.analyze(*)
pod 'monkey', :path => (fixture_path + 'monkey').to_s
end
@lockfile = generate_lockfile

@file = Pathname('/yolo.m')
@file.stubs(:realpath).returns(@file)

@lib_thing = Pathname('/libThing.a')
@lib_thing.stubs(:realpath).returns(@lib_thing)
end

it 'detects transitive static dependencies which are linked directly to the user target' do
Sandbox::FileAccessor.any_instance.stubs(:vendored_libraries).returns([Pathname('/libThing.a')])
Sandbox::FileAccessor.any_instance.stubs(:vendored_libraries).returns([@lib_thing])
@installer = Installer.new(config.sandbox, @podfile, @lockfile)
should.raise(Informative) { @installer.install! }.message.should.match /transitive.*libThing/
end

it 'allows transitive static dependencies which contain other source code' do
Sandbox::FileAccessor.any_instance.stubs(:source_files).returns([Pathname('/yolo.m')])
Sandbox::FileAccessor.any_instance.stubs(:vendored_libraries).returns([Pathname('/libThing.a')])
Sandbox::FileAccessor.any_instance.stubs(:source_files).returns([@file])
Sandbox::FileAccessor.any_instance.stubs(:vendored_libraries).returns([@lib_thing])
@installer = Installer.new(config.sandbox, @podfile, @lockfile)
should.not.raise(Informative) { @installer.install! }
end

it 'allows transitive static dependencies when both dependencies are linked against the user target' do
PodTarget.any_instance.stubs(:should_build? => false)
Sandbox::FileAccessor.any_instance.stubs(:vendored_libraries).returns([Pathname('/libThing.a')])
Sandbox::FileAccessor.any_instance.stubs(:vendored_libraries).returns([@lib_thing])
@installer = Installer.new(config.sandbox, @podfile, @lockfile)
should.not.raise(Informative) { @installer.install! }
end
Expand Down
20 changes: 20 additions & 0 deletions spec/unit/project_spec.rb
Expand Up @@ -174,39 +174,46 @@ def settings_for_root_configs(key)
end

it 'adds a file references to the given file' do
Pathname.any_instance.stubs(:realpath).returns(@file)
ref = @project.add_file_reference(@file, @group)
ref.hierarchy_path.should == '/Pods/BananaLib/file.m'
end

it 'adds subgroups for a file reference if requested' do
Pathname.any_instance.stubs(:realpath).returns(@nested_file)
ref = @project.add_file_reference(@nested_file, @group, true)
ref.hierarchy_path.should == '/Pods/BananaLib/Dir/SubDir/nested_file.m'
end

it 'does not add subgroups for a file reference if not requested' do
Pathname.any_instance.stubs(:realpath).returns(@nested_file)
ref = @project.add_file_reference(@nested_file, @group)
ref.hierarchy_path.should == '/Pods/BananaLib/nested_file.m'
end

it 'does not add subgroups for a file reference if requested not to' do
Pathname.any_instance.stubs(:realpath).returns(@nested_file)
ref = @project.add_file_reference(@nested_file, @group, false)
ref.hierarchy_path.should == '/Pods/BananaLib/nested_file.m'
end

it "it doesn't duplicate file references for a single path" do
Pathname.any_instance.stubs(:realpath).returns(@file)
ref_1 = @project.add_file_reference(@file, @group)
ref_2 = @project.add_file_reference(@file, @group)
ref_1.uuid.should == ref_2.uuid
@group.children.count.should == 1
end

it 'creates variant group for localized file' do
Pathname.any_instance.stubs(:realpath).returns(@localized_file)
ref = @project.add_file_reference(@localized_file, @group)
ref.hierarchy_path.should == '/Pods/BananaLib/Foo/Foo.strings'
ref.parent.class.should == Xcodeproj::Project::Object::PBXVariantGroup
end

it 'creates variant group for localized file in subgroup' do
Pathname.any_instance.stubs(:realpath).returns(@localized_file)
ref = @project.add_file_reference(@localized_file, @group, true)
ref.hierarchy_path.should == '/Pods/BananaLib/Dir/SubDir/Foo/Foo.strings'
ref.parent.class.should == Xcodeproj::Project::Object::PBXVariantGroup
Expand All @@ -217,6 +224,18 @@ def settings_for_root_configs(key)
@project.add_file_reference('relative/path/to/file.m', @group)
end.message.should.match /Paths must be absolute/
end

it 'uses realpath for resolving symlinks' do
file = Pathname.new(Dir.tmpdir) + 'file.m'
FileUtils.rm_f(file)
File.open(file, 'w') { |f| f.write('') }
sym_file = Pathname.new(Dir.tmpdir) + 'symlinked_file.m'
FileUtils.rm_f(sym_file)
File.symlink(file, sym_file)

ref = @project.add_file_reference(sym_file, @group)
ref.hierarchy_path.should == '/Pods/BananaLib/file.m'
end
end

#----------------------------------------#
Expand Down Expand Up @@ -312,6 +331,7 @@ def settings_for_root_configs(key)
@project.add_pod_group('BananaLib', config.sandbox.pod_dir('BananaLib'), false)
@file = config.sandbox.pod_dir('BananaLib') + 'file.m'
@group = @project.group_for_spec('BananaLib')
Pathname.any_instance.stubs(:realpath).returns(@file)
@project.add_file_reference(@file, @group)
end

Expand Down
4 changes: 3 additions & 1 deletion spec/unit/validator_spec.rb
Expand Up @@ -729,9 +729,11 @@ def setup_validator
def test_swiftpod
podspec = stub_podspec(/.*source_files.*/, '"source_files": "*.swift",')
file = write_podspec(podspec)
pathname = Pathname.new('/Foo.swift')
pathname.stubs(:realpath).returns(pathname)

Podfile::TargetDefinition.any_instance.stubs(:uses_frameworks?).returns(true)
Pod::Sandbox::FileAccessor.any_instance.stubs(:source_files).returns([Pathname.new('/Foo.swift')])
Pod::Sandbox::FileAccessor.any_instance.stubs(:source_files).returns([pathname])
validator = Validator.new(file, SourcesManager.master.map(&:url))
validator.stubs(:build_pod)
validator.stubs(:validate_url)
Expand Down

0 comments on commit dfd3ed6

Please sign in to comment.