Skip to content

Commit

Permalink
Configuring targets for running uses internal methods allowing commna…
Browse files Browse the repository at this point in the history
…d line tools and apps to be executable.
  • Loading branch information
dostrander committed Oct 8, 2018
1 parent 371315d commit 817b4eb
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 10 deletions.
9 changes: 6 additions & 3 deletions lib/xcodeproj/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ def self.schemes(project_path)
# folder) and optionally hides them.
#
# @param [Bool] visible
# Wether the schemes should be visible or hidden.
# Whether the schemes should be visible or hidden.
#
# @return [void]
#
Expand All @@ -826,8 +826,11 @@ def recreate_user_schemes(visible = true)

targets.each do |target|
scheme = XCScheme.new
scheme.add_build_target(target)
scheme.add_test_target(target) if target.respond_to?(:test_target_type?) && target.test_target_type?

test_target = target if target.respond_to?(:test_target_type?) && target.test_target_type?
launch_target = target.respond_to?(:launchable_target_type?) && target.launchable_target_type?
scheme.configure_with_targets(target, test_target, :launch_target => launch_target)

yield scheme, target if block_given?
scheme.save_as(path, target.name, false)
xcschememanagement['SchemeUserState']["#{target.name}.xcscheme"] = {}
Expand Down
9 changes: 9 additions & 0 deletions lib/xcodeproj/project/object/native_target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,15 @@ def extension_target_type?
end
end

def launchable_target_type?
case symbol_type
when :application, :command_line_tool
true
else
false
end
end

# Adds source files to the target.
#
# @param [Array<PBXFileReference>] file_references
Expand Down
16 changes: 9 additions & 7 deletions lib/xcodeproj/scheme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ def initialize(file_path = nil)
# @param [Xcodeproj::Project::Object::PBXAbstractTarget] test_target
# The target to use for the 'Test' action
#
def configure_with_targets(runnable_target, test_target)
build_action.add_entry BuildAction::Entry.new(runnable_target) if runnable_target
build_action.add_entry BuildAction::Entry.new(test_target) if test_target

test_action.add_testable TestAction::TestableReference.new(test_target) if test_target
launch_action.buildable_product_runnable = BuildableProductRunnable.new(runnable_target, 0) if runnable_target
profile_action.buildable_product_runnable = BuildableProductRunnable.new(runnable_target) if runnable_target
def configure_with_targets(runnable_target, test_target, launch_target: false)
if runnable_target
add_build_target(runnable_target)
set_launch_target(runnable_target) if launch_target
end
if test_target
add_build_target(test_target, false) if test_target != runnable_target
add_test_target(test_target)
end
end

public
Expand Down
21 changes: 21 additions & 0 deletions spec/project/object/native_target_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,27 @@ module ProjectSpecs
end
end

describe '#launchable_target_type?' do
it 'returns true for command line tools and applications' do
@target.stubs(:symbol_type => :application)
@target.should.be.launchable_target_type?

@target.stubs(:symbol_type => :command_line_tool)
@target.should.be.launchable_target_type?
end

it 'returns false for non launchable types' do
@target.stubs(:symbol_type => :octest_bundle)
@target.should.not.be.launchable_target_type?

@target.stubs(:symbol_type => :unit_test_bundle)
@target.should.not.be.launchable_target_type?

@target.stubs(:symbol_type => :ui_test_bundle)
@target.should.not.be.launchable_target_type?
end
end

describe '#extension_target_type?' do
it 'returns true for extension target types' do
@target.stubs(:symbol_type => :app_extension)
Expand Down

0 comments on commit 817b4eb

Please sign in to comment.