Skip to content

Commit

Permalink
Add add_legacy_target method to ProjectHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
dnkoutso committed Jun 1, 2017
1 parent 76932aa commit dd4cec3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

##### Enhancements

* Add add_legacy_target method to ProjectHelper
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#488](https://github.com/CocoaPods/Xcodeproj/pull/488)

* Use `test_target_type?` when adding testable reference
[Dimitris Koutsogiorgas](https://github.com/dnkoutso)
[#487](https://github.com/CocoaPods/Xcodeproj/pull/487)
Expand Down
36 changes: 36 additions & 0 deletions lib/xcodeproj/project/project_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,42 @@ def self.new_aggregate_target(project, name)
target
end

# Creates a new legacy target and adds it to the project.
#
# The target is configured for the given platform.
#
# @param [Project] project
# the project to which the target should be added.
#
# @param [String] name
# the name of the aggregate target.
#
# @param [String] build_tool_path
# the build tool path to use for this target.
#
# @param [String] build_arguments_string
# the build arguments string to use for this target.
#
# @param [String] build_working_directory
# the build working directory to use for this target.
#
# @param [String] pass_build_settings_in_environment
# whether to pass build settings in the environment during execution of this target.
#
# @return [PBXLegacyTarget] the target.
#
def self.new_legacy_target(project, name, build_tool_path = '/usr/bin/make', build_arguments_string = '$(ACTION)', build_working_directory = nil, pass_build_settings_in_environment = '1')
target = project.new(PBXLegacyTarget)
project.targets << target
target.name = name
target.build_configuration_list = configuration_list(project)
target.build_tool_path = build_tool_path
target.build_arguments_string = build_arguments_string
target.build_working_directory = build_working_directory
target.pass_build_settings_in_environment = pass_build_settings_in_environment
target
end

# @!group Private Helpers

#-----------------------------------------------------------------------#
Expand Down
17 changes: 17 additions & 0 deletions spec/project/project_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,23 @@ module ProjectSpecs

target.build_phases.count.should == 0
end

it 'creates a new legacy target' do
target = @helper.new_legacy_target(@project, 'Pods')
target.name.should == 'Pods'
target.build_tool_path.should == '/usr/bin/make'
target.build_arguments_string.should == '$(ACTION)'
target.build_working_directory.should.be.nil
target.pass_build_settings_in_environment.should == '1'

target.build_configuration_list.should.not.be.nil
configurations = target.build_configuration_list.build_configurations
configurations.map(&:name).sort.should == %w(Debug Release)

@project.targets.should.include target

target.build_phases.count.should == 0
end
end

#-------------------------------------------------------------------------#
Expand Down

0 comments on commit dd4cec3

Please sign in to comment.