diff --git a/lib/cocoapods/installer/user_project_integrator.rb b/lib/cocoapods/installer/user_project_integrator.rb index 37435fc..cab50dd 100644 --- a/lib/cocoapods/installer/user_project_integrator.rb +++ b/lib/cocoapods/installer/user_project_integrator.rb @@ -112,6 +112,14 @@ module Pod @user_project ||= Xcodeproj::Project.new(user_project_path) end + # @return [Array] Returns the user’s targets, + # excluding aggregate targets. + def native_targets + user_project.targets.reject do |target| + target.is_a? Xcodeproj::Project::Object::PBXAggregateTarget + end + end + # 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 # specified, then the first encountered target is assumed. @@ -122,28 +130,40 @@ module Pod # @return [Array] Returns the list of targets that # the Pods lib should be linked with. def targets - @targets ||= begin - if link_with = @target_definition.link_with + if @targets.nil? + targets = nil # Find explicitly linked targets. - user_project.targets.select do |target| - link_with.include? target.name + if link_with = @target_definition.link_with + targets = native_targets.select do |target| + link_with.include? target.name + end + + # Otherwise try to find a target matching the name. + elsif @target_definition.name != :default + target = native_targets.find do |target| + target.name == @target_definition.name.to_s + end + unless target + raise Informative, "Unable to find a target named `#{@target_definition.name.to_s}'" + end + targets = [target] + + # Default to the first target, which in a simple project is + # probably an app target. + else + targets = [native_targets.first] end - elsif @target_definition.name != :default - # Find the target with the matching name. - target = user_project.targets.find { |target| target.name == @target_definition.name.to_s } - raise Informative, "Unable to find a target named `#{@target_definition.name.to_s}'" unless target - [target] - else - # Default to the first, which in a simple project is probably an app target. - [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_phase.files.any? do |build_file| - file_ref = build_file.file_ref - !file_ref.proxy? && file_ref.display_name == @target_definition.lib_name + + # Reject any target that already has this Pods library in one of + # its frameworks build phases + @targets = 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 == @target_definition.lib_name + end end end - end + @targets end def add_xcconfig_base_configuration diff --git a/spec/fixtures/SampleProject/SampleProject.xcodeproj/project.pbxproj b/spec/fixtures/SampleProject/SampleProject.xcodeproj/project.pbxproj index daa1d69..713678b 100644 --- a/spec/fixtures/SampleProject/SampleProject.xcodeproj/project.pbxproj +++ b/spec/fixtures/SampleProject/SampleProject.xcodeproj/project.pbxproj @@ -6,6 +6,19 @@ objectVersion = 46; objects = { +/* Begin PBXAggregateTarget section */ + 51D6A8AB16C445B800E174E1 /* AggregateTarget */ = { + isa = PBXAggregateTarget; + buildConfigurationList = 51D6A8B116C445B800E174E1 /* Build configuration list for PBXAggregateTarget "AggregateTarget" */; + buildPhases = ( + ); + dependencies = ( + ); + name = AggregateTarget; + productName = AggregateTarget; + }; +/* End PBXAggregateTarget section */ + /* Begin PBXBuildFile section */ 51075D4C1521D0C100E39B41 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A346497114F9BE9A0080D870 /* UIKit.framework */; }; 51075D4D1521D0C100E39B41 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A346497314F9BE9A0080D870 /* Foundation.framework */; }; @@ -224,6 +237,7 @@ targets = ( A346496C14F9BE9A0080D870 /* SampleProject */, 51075D491521D0C100E39B41 /* TestRunner */, + 51D6A8AB16C445B800E174E1 /* AggregateTarget */, ); }; /* End PBXProject section */ @@ -421,6 +435,34 @@ }; name = "App Store"; }; + 51D6A8AC16C445B800E174E1 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 51D6A8AD16C445B800E174E1 /* Test */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Test; + }; + 51D6A8AE16C445B800E174E1 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; + 51D6A8AF16C445B800E174E1 /* App Store */ = { + isa = XCBuildConfiguration; + buildSettings = { + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = "App Store"; + }; A346498314F9BE9A0080D870 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -502,6 +544,16 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 51D6A8B116C445B800E174E1 /* Build configuration list for PBXAggregateTarget "AggregateTarget" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 51D6A8AC16C445B800E174E1 /* Debug */, + 51D6A8AD16C445B800E174E1 /* Test */, + 51D6A8AE16C445B800E174E1 /* Release */, + 51D6A8AF16C445B800E174E1 /* App Store */, + ); + defaultConfigurationIsVisible = 0; + }; A346496714F9BE990080D870 /* Build configuration list for PBXProject "SampleProject" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/spec/unit/installer/user_project_integrator_spec.rb b/spec/unit/installer/user_project_integrator_spec.rb index f3748e4..55c5b6e 100644 --- a/spec/unit/installer/user_project_integrator_spec.rb +++ b/spec/unit/installer/user_project_integrator_spec.rb @@ -57,6 +57,11 @@ describe Pod::Installer::UserProjectIntegrator do lambda { @target_integrator.user_project_path }.should.raise Pod::Informative end + it "does not take aggregate targets into consideration" do + aggregate = Xcodeproj::Project::Object::PBXAggregateTarget + @target_integrator.native_targets.map(&:class).should.not.include aggregate + end + it "uses the target with the same name if the name is different from `:default'" do target_integrator = @integrator.target_integrators[1] target_integrator.target_definition.stubs(:name).returns('TestRunner')