Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let users add arbitrary configuration to tests #213

Merged
merged 4 commits into from
Feb 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/liftoff/launchpad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def enable_warnings
end

def perform_extra_config
xcode_helper.perform_extra_config(@config.extra_config)
xcode_helper.perform_extra_config(@config.extra_config, @config.extra_test_config)
end

def enable_static_analyzer
Expand Down
1 change: 1 addition & 0 deletions lib/liftoff/project_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ProjectConfiguration
:strict_prompts,
:xcode_command,
:extra_config,
:extra_test_config,
:deployment_target

attr_writer :author,
Expand Down
52 changes: 32 additions & 20 deletions lib/liftoff/xcodeproj_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class XcodeprojHelper
def treat_warnings_as_errors(enable_errors)
if enable_errors
puts 'Setting GCC_TREAT_WARNINGS_AS_ERRORS for Release builds'
target.build_settings('Release')['GCC_TREAT_WARNINGS_AS_ERRORS'] = 'YES'
application_target.build_settings('Release')['GCC_TREAT_WARNINGS_AS_ERRORS'] = 'YES'
end
end

Expand Down Expand Up @@ -53,18 +53,18 @@ def add_script_phases(scripts)
end
end

def perform_extra_config(extra_config)
if extra_config
extra_config.each do |name, settings|
if name.downcase == "all"
object = target
else
object = target.build_settings(name)
end
def perform_extra_config(app_config, test_config)
{app_config => application_target, test_config => test_target}.each do |config, target|
if config
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do .compact.each to remove this if statement. .compact removes nils.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How functional!

config.each do |name, settings|
if name.downcase == "all"
object = target
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this now be application_target?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, it's whatever target we've associated with the config on line 56.

else
object = target.build_settings(name)
end

if object
settings.each do |key, value|
object[key] = value
if object
object.merge!(settings)
end
end
end
Expand All @@ -77,28 +77,40 @@ def save

private

def target
@target ||= ObjectPicker.choose_item('target', available_targets)
def application_target
@target ||= ObjectPicker.choose_item('target', application_targets)
end

def test_target
@test_target ||= ObjectPicker.choose_item('test target', test_targets)
end

def application_targets
all_targets.reject { |t| t.name.end_with?('Tests') }
end

def test_targets
all_targets.select { |t| t.name.end_with?('Tests') }
end

def available_targets
xcode_project.targets.to_a.reject { |t| t.name.end_with?('Tests') }
def all_targets
xcode_project.targets.to_a
end

def add_shell_script_build_phase(script, name, index)
if build_phase_does_not_exist_with_name?(name)
build_phase = target.new_shell_script_build_phase(name)
build_phase = application_target.new_shell_script_build_phase(name)
build_phase.shell_script = script

target.build_phases.delete(build_phase)
target.build_phases.insert(index, build_phase)
application_target.build_phases.delete(build_phase)
application_target.build_phases.insert(index, build_phase)

xcode_project.save
end
end

def build_phase_does_not_exist_with_name?(name)
target.build_phases.to_a.none? { |phase| phase.display_name == name }
application_target.build_phases.to_a.none? { |phase| phase.display_name == name }
end

def file_manager
Expand Down
6 changes: 6 additions & 0 deletions lib/liftoff/xcodeproj_monkeypatch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ def []=(key, value)
configuration.build_settings[key] = value
end
end

def merge!(hash)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hash.each do |key, value|
self[key] = value
end
end
end
end
end
Expand Down
25 changes: 18 additions & 7 deletions man/liftoffrc.5
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,23 @@ Set this key to
.Ic false
to disable the automatic-open functionality
.It Ic extra_config
type: array of dictionaries
type: dictionary
.br
default: none
.Pp
Add additional per-configuration settings to the main application target. By
default this key isn't set. See
.Sx EXTRA CONFIGURATION
for more information on the format of this key.
.It Ic extra_test_config
type: dictionary
.br
default: none
.Pp
Add additional per-configuration settings to the test target. By default this
key isn't set. See
.Sx EXTRA CONFIGURATION
for more information on the format of this key.
.El
.
.Sh SCRIPT PHASES
Expand Down Expand Up @@ -559,13 +568,15 @@ in your
.Sh EXTRA CONFIGURATION
.Ic liftoff
can perform additional arbitrary configuration to the main application target
on a per-build configuration basis. In order to add arbitrary settings, you
should add keys to the
or the test target on a per-build configuration basis. In order to add
arbitrary settings, you should add the
.Ic extra_config
or the
.Ic extra_test_config
key in your
.Nm
that correspond to the build configuration you'd like to modify. For example,
to set all warnings on your
.Nm ,
and add dictionaries that correspond to the build configuration you'd like to
modify. For example, to set all warnings on your
.Ic Debug
build configuration, you can set the following:
.Pp
Expand All @@ -579,7 +590,7 @@ extra_config:
Note that the key for the build configuration must match the name of the build
configuration you'd like to modify exactly.
.Pp
If you would like to set a project-wide setting for the application target, you
If you would like to add a setting for all available build configurations, you
can use the special
.Ic all
key in the configuration:
Expand Down