Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make empty target definitions integrate properly
  • Loading branch information
segiddins committed Dec 30, 2015
1 parent 7a1b2ad commit 92a04dc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 16 deletions.
4 changes: 2 additions & 2 deletions lib/cocoapods/installer.rb
Expand Up @@ -629,13 +629,13 @@ def install_file_references
def install_libraries
UI.message '- Installing targets' do
pod_targets.sort_by(&:name).each do |pod_target|
next if pod_target.target_definitions.flat_map(&:dependencies).empty?
next if pod_target.target_definitions.all?(&:abstract?)
target_installer = PodTargetInstaller.new(sandbox, pod_target)
target_installer.install!
end

aggregate_targets.sort_by(&:name).each do |target|
next if target.target_definition.dependencies.empty?
next if target.target_definition.abstract?
target_installer = AggregateTargetInstaller.new(sandbox, target)
target_installer.install!
end
Expand Down
2 changes: 1 addition & 1 deletion lib/cocoapods/installer/user_project_integrator.rb
Expand Up @@ -234,7 +234,7 @@ def user_projects
end

def targets_to_integrate
targets.reject { |target| target.target_definition.empty? }
targets.reject { |target| target.target_definition.abstract? }
end

# Prints a warning informing the user that a build configuration of
Expand Down
34 changes: 23 additions & 11 deletions spec/unit/installer/user_project_integrator_spec.rb
Expand Up @@ -9,18 +9,23 @@ module Pod
@podfile = Podfile.new do
platform :ios
xcodeproj sample_project_path
pod 'JSONKit'
target :empty do
target 'SampleProject' do
pod 'JSONKit'
target :empty do
end
end
end
config.sandbox.project = Project.new(config.sandbox.project_path)
config.sandbox.project.save
@target = AggregateTarget.new(@podfile.target_definitions['Pods'], config.sandbox)
@target = AggregateTarget.new(@podfile.target_definitions['SampleProject'], config.sandbox)
@target.client_root = sample_project_path.dirname
@target.user_project = Xcodeproj::Project.open(@sample_project_path)
@target.user_target_uuids = ['A346496C14F9BE9A0080D870']
empty_library = AggregateTarget.new(@podfile.target_definitions[:empty], config.sandbox)
@integrator = UserProjectIntegrator.new(@podfile, config.sandbox, temporary_directory, [@target, empty_library])
@empty_library = AggregateTarget.new(@podfile.target_definitions[:empty], config.sandbox)
@empty_library.client_root = sample_project_path.dirname
@empty_library.user_project = @target.user_project
@empty_library.user_target_uuids = ['C0C495321B9E5C47004F9854']
@integrator = UserProjectIntegrator.new(@podfile, config.sandbox, temporary_directory, [@target, @empty_library])
end

#-----------------------------------------------------------------------#
Expand All @@ -42,12 +47,13 @@ module Pod
end

it 'integrates the user targets' do
UserProjectIntegrator::TargetIntegrator.any_instance.expects(:integrate!)
UserProjectIntegrator::TargetIntegrator.any_instance.expects(:integrate!).twice
@integrator.integrate!
end

it 'warns if the podfile does not contain any dependency' do
Podfile::TargetDefinition.any_instance.stubs(:empty?).returns(true)
@podfile = Pod::Podfile.new
@integrator.stubs(:podfile).returns(@podfile)
@integrator.integrate!
UI.warnings.should.include?('The Podfile does not contain any dependencies')
end
Expand All @@ -57,7 +63,7 @@ module Pod
Deintegrator.any_instance.expects(:deintegrate_target).with additional_project.new_target(:application, 'Other App', :ios)
user_project = @target.user_project
user_project.native_targets.each do |target|
next if target.name == 'SampleProject'
next if %w(SampleProject SampleProjectTests).include?(target.name)
Deintegrator.any_instance.expects(:deintegrate_target).with(target)
end
@integrator.stubs(:user_projects).returns([additional_project, user_project])
Expand Down Expand Up @@ -201,9 +207,15 @@ module Pod
@integrator.send(:user_project_paths).should == [@sample_project_path]
end

it 'skips libraries with empty target definitions' do
@integrator.targets.map(&:name).should == ['Pods', 'Pods-empty']
@integrator.send(:targets_to_integrate).map(&:name).should == ['Pods']
it 'does not skip libraries with empty target definitions' do
@integrator.targets.map(&:name).should == ['Pods-SampleProject', 'Pods-SampleProject-empty']
@integrator.send(:targets_to_integrate).map(&:name).should == ['Pods-SampleProject', 'Pods-SampleProject-empty']
end

it 'does skip libraries with only abstract target definitions' do
@integrator.targets.map(&:name).should == ['Pods-SampleProject', 'Pods-SampleProject-empty']
@podfile.target_definition_list.each { |td| td.abstract = true }
@integrator.send(:targets_to_integrate).map(&:name).should == []
end

it 'skips saving projects that are not dirtied (but touches them instead)' do
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/installer_spec.rb
Expand Up @@ -646,13 +646,13 @@ def @installer.analyze(*)
@installer.send(:install_libraries)
end

it 'skips empty pod targets' do
it 'does not skip empty pod targets' do
spec = fixture_spec('banana-lib/BananaLib.podspec')
target_definition = Podfile::TargetDefinition.new(:default, nil)
pod_target = PodTarget.new([spec], [target_definition], config.sandbox)
@installer.stubs(:aggregate_targets).returns([])
@installer.stubs(:pod_targets).returns([pod_target])
Installer::PodTargetInstaller.any_instance.expects(:install!).never
Installer::PodTargetInstaller.any_instance.expects(:install!).once
@installer.send(:install_libraries)
end

Expand Down

0 comments on commit 92a04dc

Please sign in to comment.