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

Add arbitrary configuration settings to liftoffrc #174

Merged
merged 1 commit into from
Sep 30, 2014
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
18 changes: 18 additions & 0 deletions lib/liftoff/xcodeproj_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ def add_script_phases(scripts)
end
end

def perform_extra_config(extra_config)
if extra_config
Copy link

Choose a reason for hiding this comment

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

Is extra_config a hash? Can it sometimes be nil? You may want to use the Hash() method: http://www.ruby-doc.org/core-2.1.3/Kernel.html#method-i-Hash

[1] pry(main)> Hash(nil)
=> {}
[2] pry(main)> Hash({})
=> {}
[3] pry(main)> Hash({k: 'v'})
=> {:k=>"v"}

Copy link
Member Author

Choose a reason for hiding this comment

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

It's actually set inside the config file. I was thinking about doing a refactor to make sure that a lot of these variables don't end up nil, but I'm not sure it's worth it since I'm considering porting the entire project to Swift.

extra_config.each do |name, settings|
if name.downcase == "all"
object = target
else
object = target.build_settings(name)
end
Copy link

Choose a reason for hiding this comment

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

Thoughts on extracting this conditional to a private method?

object = find_or_build_target(name)

Copy link
Member Author

Choose a reason for hiding this comment

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

That's not actually what this is doing. This is all fetching. It either gets the target, or it gets the build_settings from the target for the build configuration with the specified name. And if that build configuration doesn't exist, it returns nil. Not sure how that would be named.


if object
Copy link

Choose a reason for hiding this comment

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

Do you need to check for nil here? object is guaranteed to be either target or target.build_settings(name).

Copy link
Member Author

Choose a reason for hiding this comment

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

If name isn't all, it will try to get the configuration with target.build_settings(name). But if there isn't a build configuration with that name, that method will return nil.

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

def save
xcode_project.save
end
Expand Down
13 changes: 13 additions & 0 deletions lib/liftoff/xcodeproj_monkeypatch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module Xcodeproj
class Project
module Object
class PBXNativeTarget
def []=(key, value)
Copy link

Choose a reason for hiding this comment

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

Although I'm not sure why you're doing this I'm guessing you probably can't extract this one so... I guess leave this one :/

Copy link
Member Author

Choose a reason for hiding this comment

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

All of this is basically to serve this line

Since setting the build settings on all configurations in the target is a different API than setting a build setting on a single configuration, I'm just trying to make my life a little easier.

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