Commit 3d1b65a4 authored by Fabio Pelosin's avatar Fabio Pelosin

[UserProjectIntegrator] Fix missing targets.

This was caused by not reloading the user project from disk and losing
previous changes done to the same project.
parent c2ebd3c6
......@@ -192,18 +192,22 @@ module Pod
lib.support_files_root = sandbox.library_support_files_dir(lib.name)
if config.integrate_targets?
lib.user_project_path = compute_user_project_path(target_definition)
lib.user_project = Xcodeproj::Project.new(lib.user_project_path)
lib.user_targets = compute_user_project_targets(target_definition, lib.user_project)
lib.user_build_configurations = compute_user_build_configurations(target_definition, lib.user_targets)
lib.platform = compute_platform_for_target_definition(target_definition, lib.user_targets)
project_path = compute_user_project_path(target_definition)
user_project = Xcodeproj::Project.new(project_path)
targets = compute_user_project_targets(target_definition, user_project)
lib.user_project_path = project_path
lib.user_target_uuids = targets.map(&:uuid)
lib.user_build_configurations = compute_user_build_configurations(target_definition, targets)
lib.platform = compute_platform_for_target_definition(target_definition, targets)
else
unless target_definition.platform
raise Informative, "It is necessary to specify the platform in the Podfile if not integrating."
end
lib.user_project_path = config.installation_root
lib.user_project = nil
lib.user_targets = []
lib.user_target_uuids = []
lib.user_build_configurations = {}
lib.platform = target_definition.platform
raise Informative, "It is necessary to specify the platform in the Podfile if not integrating." unless target_definition.platform
end
libraries << lib
end
......@@ -411,15 +415,15 @@ module Pod
#
def compute_user_project_targets(target_definition, user_project)
if link_with = target_definition.link_with
targets = native_targets(user_project).select { |t| link_with.include? t.name }
targets = native_targets(user_project).select { |t| link_with.include?(t.name) }
raise Informative, "Unable to find the targets named `#{link_with.to_sentence}` to link with target definition `#{target_definition.name}`" if targets.empty?
elsif target_definition.name != :default
elsif target_definition.name == :default
targets = [ native_targets(user_project).first ].compact
raise Informative, "Unable to find a target" if targets.empty?
else
target = native_targets(user_project).find { |t| t.name == target_definition.name.to_s }
targets = [ target ].compact
raise Informative, "Unable to find a target named `#{target_definition.name.to_s}`" if targets.empty?
else
targets = [ native_targets(user_project).first ].compact
raise Informative, "Unable to find a target" if targets.empty?
end
targets
end
......
......@@ -201,16 +201,26 @@ module Pod
# @note A target is considered integrated if it already references
#
def targets
@targets ||= library.user_targets.reject do |target|
unless @targets
target_uuids = library.user_target_uuids
targets = target_uuids.map { |uuid| user_project.targets.find { |target| target.uuid == uuid } }
non_integrated = targets.reject do |target|
target.frameworks_build_phase.files.any? do |build_file|
file_ref = build_file.file_ref
!file_ref.proxy? && file_ref.display_name == library.product_name
end
end
@targets = non_integrated
end
@targets
end
# Read the project from the disk to ensure that it is up to date as
# other TargetIntegrator might have modified it.
#
def user_project
library.user_project
@user_project ||= Xcodeproj::Project.new(library.user_project_path)
end
# @return [String] a string representation suitable for debugging.
......
......@@ -54,18 +54,20 @@ module Pod
attr_accessor :support_files_root
# @return [Pathname] the path of the user project that this library will
# integrate.
# integrate as identified by the analyzer.
#
# @note The project instance is not stored to prevent editing different
# instances.
#
attr_accessor :user_project_path
# @return [Xcodeproj::Project] The project that will be integrated.
# @return [String] the list of the UUIDs of the user targets that will be
# integrated by this library as identified by the analizer.
#
attr_accessor :user_project
# @return [Array<PBXNativeTarget>] the list of the user targets that will
# be integrated by this library.
# @note The target instances are not stored to prevent editing different
# instances.
#
attr_accessor :user_targets
attr_accessor :user_target_uuids
# @return [Hash{String=>Symbol}] A hash representing the user build
# configurations where each key corresponds to the name of a
......
......@@ -81,8 +81,9 @@ module Pod
lib.support_files_root.should == config.sandbox.root
lib.user_project_path.to_s.should.include 'SampleProject/SampleProject'
lib.user_project.class.should == Xcodeproj::Project
lib.user_targets.map(&:name).should == ["SampleProject"]
lib.user_target_uuids.should == ["A346496C14F9BE9A0080D870"]
user_proj = Xcodeproj::Project.new(lib.user_project_path)
user_proj.objects_by_uuid[lib.user_target_uuids.first].name.should == 'SampleProject'
lib.user_build_configurations.should == {"Test"=>:release, "App Store"=>:release}
lib.platform.to_s.should == 'iOS 6.0'
end
......@@ -93,8 +94,7 @@ module Pod
lib = @analyzer.libraries.first
lib.user_project_path.should == config.installation_root
lib.user_project.should.be.nil
lib.user_targets.map(&:name).should == []
lib.user_target_uuids.should == []
lib.user_build_configurations.should == {}
lib.platform.to_s.should == 'iOS 6.0'
end
......
......@@ -27,12 +27,12 @@ module Pod
lib = Library.new(target_definition)
lib.user_project_path = sample_project_path
lib.target = @pods_project.new_target(:static_library, target_definition.label, target_definition.platform.name)
lib.user_targets = sample_project.targets.reject do |target|
lib.user_target_uuids = sample_project.targets.reject do |target|
target.is_a? Xcodeproj::Project::Object::PBXAggregateTarget
end
end.map(&:uuid)
lib.support_files_root = config.sandbox.root
lib.user_project = sample_project
lib.user_project_path = sample_project_path
lib
end
@integrator = Installer::UserProjectIntegrator.new(@podfile, config.sandbox, @installation_root, @libraries)
......@@ -95,9 +95,9 @@ module Pod
@lib.user_project_path = sample_project_path
pods_project = Project.new()
@lib.target = pods_project.new_target(:static_library, target_definition.label, :ios)
@lib.user_targets = [@target]
@lib.user_target_uuids = [@target.uuid]
@lib.support_files_root = config.sandbox.root
@lib.user_project = @sample_project
@lib.user_project_path = sample_project_path
@target_integrator = TargetIntegrator.new(@lib)
end
......@@ -108,6 +108,7 @@ module Pod
it 'returns the targets that need to be integrated' do
pods_library = @sample_project.frameworks_group.new_static_library('Pods')
@target.frameworks_build_phase.add_file_reference(pods_library)
Xcodeproj::Project.any_instance.stubs(:targets).returns([@target])
@target_integrator.targets.map(&:name).should.be.empty?
end
......@@ -132,15 +133,17 @@ module Pod
end
it 'adds references to the Pods static libraries to the Frameworks group' do
@sample_project["Frameworks/libPods.a"].should.not == nil
@target_integrator.user_project["Frameworks/libPods.a"].should.not == nil
end
it 'adds the libPods static library to the "Link binary with libraries" build phase of each target' do
@target.frameworks_build_phase.files.find { |f| f.file_ref.path == 'libPods.a'}.should.not == nil
target = @target_integrator.targets.first
target.frameworks_build_phase.files.find { |f| f.file_ref.path == 'libPods.a'}.should.not == nil
end
it 'adds a Copy Pods Resources build phase to each target' do
phase = @target.shell_script_build_phases.find { |bp| bp.name == "Copy Pods Resources" }
target = @target_integrator.targets.first
phase = target.shell_script_build_phases.find { |bp| bp.name == "Copy Pods Resources" }
phase.shell_script.strip.should == "\"${SRCROOT}/../Pods/Pods-resources.sh\""
end
end
......
......@@ -3,7 +3,6 @@ require File.expand_path('../../spec_helper', __FILE__)
module Pod
describe Validator do
# @return [void]
#
def write_podspec(text, name = 'JSONKit.podspec')
......
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