Commit c189b4cf authored by Eloy Duran's avatar Eloy Duran

Only integrate targets that have not yet been integrated.

parent 9cac4b54
...@@ -17,10 +17,12 @@ module Pod ...@@ -17,10 +17,12 @@ module Pod
def integrate! def integrate!
create_workspace! create_workspace!
return if project_already_integrated?
targets.each(&:integrate!) # Only need to write out the user's project if any of the target
# integrators actually did some work.
if targets.map(&:integrate!).any?
@user_project.save_as(user_project_path) @user_project.save_as(user_project_path)
end
unless config.silent? unless config.silent?
# TODO this really shouldn't be here # TODO this really shouldn't be here
...@@ -49,10 +51,6 @@ module Pod ...@@ -49,10 +51,6 @@ module Pod
workspace.save_as(workspace_path) workspace.save_as(workspace_path)
end end
def project_already_integrated?
@user_project.files.find { |file| file.path =~ /libPods\.a$/ }
end
class Target class Target
attr_reader :integrator, :target_definition attr_reader :integrator, :target_definition
...@@ -61,24 +59,36 @@ module Pod ...@@ -61,24 +59,36 @@ module Pod
end end
def integrate! def integrate!
return false if targets.empty?
add_xcconfig_base_configuration add_xcconfig_base_configuration
add_pods_library add_pods_library
add_copy_resources_script_phase add_copy_resources_script_phase
true
end end
# This returns a list of the targets from the user’s project to which # This returns a list of the targets from the user’s project to which
# this Pods static library should be linked. If no explicit target was # this Pods static library should be linked. If no explicit target was
# specified, then the first encountered target is assumed. # specified, then the first encountered target is assumed.
# #
# In addition this will only return targets that do **not** already
# have the Pods library in their frameworks build phase.
#
# @return [Array<PBXNativeTarget>] Returns the list of targets that # @return [Array<PBXNativeTarget>] Returns the list of targets that
# the Pods lib should be linked with. # the Pods lib should be linked with.
def targets def targets
@targets ||= begin
if link_with = @target_definition.link_with if link_with = @target_definition.link_with
@integrator.user_project.targets.select do |target| @integrator.user_project.targets.select do |target|
link_with.include? target.name link_with.include? target.name
end end
else else
[@integrator.user_project.targets.first] [@integrator.user_project.targets.first]
end.reject do |target|
# reject any target that already has this Pods library in one of its frameworks build phases
target.frameworks_build_phases.any? do |phase|
phase.files.any? { |build_file| build_file.file.name == @target_definition.lib_name }
end
end
end end
end end
......
...@@ -113,9 +113,26 @@ describe Pod::Project::Integrator do ...@@ -113,9 +113,26 @@ describe Pod::Project::Integrator do
it 'adds a Copy Pods Resources build phase to each target' do it 'adds a Copy Pods Resources build phase to each target' do
@podfile.target_definitions.each do |_, definition| @podfile.target_definitions.each do |_, definition|
target = @sample_project.targets.where(:name => definition.link_with.first) target = @sample_project.targets.where(:name => definition.link_with.first)
expected_phase = target.shell_script_build_phases.where(:name => "Copy Pods Resources") phase = target.shell_script_build_phases.where(:name => "Copy Pods Resources")
expected_phase.shell_script.strip.should == "\"${SRCROOT}/Pods/#{definition.copy_resources_script_name}\"".strip phase.shell_script.strip.should == "\"${SRCROOT}/Pods/#{definition.copy_resources_script_name}\"".strip
end end
end end
it "only tries to integrate Pods libraries into user targets that haven't been integrated yet" do
app, test_runner = @integrator.user_project.targets.to_a
test_runner.frameworks_build_phases.first.files.last.destroy
targets = @integrator.targets
@integrator.stubs(:targets).returns(targets)
targets.first.expects(:add_pods_library).never
targets.last.expects(:add_pods_library)
@integrator.integrate!
end
it "does not even try to save the project if none of the target integrators had any work to do" do
@integrator.user_project.expects(:save_as).never
@integrator.integrate!
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