Skip to content

Commit

Permalink
Add arbitrary configuration settings to liftoffrc
Browse files Browse the repository at this point in the history
This allows the user to set arbitrary build configurations on a
per-build configuration basis. This is handled by the new `extra_config`
key in `liftoffrc`.
  • Loading branch information
gfontenot committed Sep 29, 2014
1 parent 57296f5 commit dc1a0cc
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/liftoff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@
require 'liftoff/template_generator'
require 'liftoff/version'
require 'liftoff/xcodeproj_helper'
require 'liftoff/xcodeproj_monkeypatch'
6 changes: 6 additions & 0 deletions lib/liftoff/launchpad.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def perform_project_actions
treat_warnings_as_errors
add_script_phases
enable_static_analyzer
perform_extra_config
save_project
generate_git
end

Expand Down Expand Up @@ -65,6 +67,10 @@ def enable_warnings
xcode_helper.enable_warnings(@config.warnings)
end

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

def enable_static_analyzer
xcode_helper.enable_static_analyzer(@config.enable_static_analyzer)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/liftoff/project_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class ProjectConfiguration
:use_cocoapods,
:run_script_phases,
:strict_prompts,
:xcode_command
:xcode_command,
:extra_config

attr_writer :author,
:company_identifier,
Expand Down
31 changes: 24 additions & 7 deletions lib/liftoff/xcodeproj_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@ def treat_warnings_as_errors(enable_errors)
def enable_warnings(warnings)
if warnings
puts 'Setting warnings at the project level'
xcode_project.build_configurations.each do |configuration|
warnings.each do |warning|
configuration.build_settings[warning] = 'YES'
end
warnings.each do |warning|
xcode_project.set_project_settings(warning, 'YES')
end
end
end

def enable_static_analyzer(enable_static_analyzer)
if enable_static_analyzer
puts 'Turning on Static Analyzer at the project level'
xcode_project.build_configurations.each do |configuration|
configuration.build_settings['RUN_CLANG_STATIC_ANALYZER'] = 'YES'
end
xcode_project.set_project_settings('RUN_CLANG_STATIC_ANALYZER', 'YES')
end
end

Expand All @@ -47,6 +43,27 @@ def add_script_phases(scripts)
end
end

def perform_extra_config(extra_config)
if extra_config
extra_config.each do |configuration|
name, settings = configuration.first
if name.downcase == "all"
object = target
else
object = target.build_settings(name)
end

if object
settings.each do |setting|
setting.each do |key, value|
object[key] = value
end
end
end
end
end
end

def save
xcode_project.save
end
Expand Down
23 changes: 23 additions & 0 deletions lib/liftoff/xcodeproj_monkeypatch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Xcodeproj
class Project
def set_project_settings(key, value)
self.build_configurations.each do |configuration|
configuration.build_settings[key] = value
end
end
end
end

module Xcodeproj
class Project
module Object
class PBXNativeTarget
def []=(key, value)
self.build_configurations.each do |configuration|
configuration.build_settings[key] = value
end
end
end
end
end
end
44 changes: 44 additions & 0 deletions man/liftoffrc.5
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,15 @@ file if it can't find one.
Set this key to
.Ic false
to disable the automatic-open functionality
.It Ic extra_config
type: array of dictionaries
.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.
.El
.
.Sh SCRIPT PHASES
Expand Down Expand Up @@ -459,6 +468,41 @@ and
.Ic UnitTests-Prefix.pch
files.
.
.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
.Ic extra_config
key in your
.Nm
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
.Bd -literal
extra_config:
- Debug:
- WARNING_CFLAGS:
- -Weverything
.Ed
.Pp
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
can use the special
.Ic all
key in the configuration:
.Pp
.Bd -literal
extra_config:
- all:
- WARNING_CFLAGS:
- -Weverything
.Ed
.
.Sh FILES
.Pa ~/.liftoffrc
.
Expand Down

0 comments on commit dc1a0cc

Please sign in to comment.