-
Notifications
You must be signed in to change notification settings - Fork 105
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
Adding support to creating custom schemes #225
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
module Liftoff | ||
class SchemeBuilder | ||
def initialize(xcode_project, config) | ||
@xcode_project = xcode_project | ||
@config = config | ||
end | ||
|
||
def create_schemes | ||
xcode_project.generate_default_scheme | ||
|
||
config_schemes.each do |scheme_config| | ||
name = name_from_scheme_config(scheme_config) | ||
generate_scheme(name, scheme_config["actions"]) | ||
end | ||
end | ||
|
||
private | ||
|
||
attr_reader :xcode_project, :config | ||
|
||
def config_schemes | ||
config.schemes || [] | ||
end | ||
|
||
def name_from_scheme_config(scheme_config) | ||
string_renderer.render(scheme_config["name"]) | ||
end | ||
|
||
def generate_scheme(name, actions) | ||
actions ||= [] | ||
xcode_project.generate_scheme(name) do |scheme| | ||
actions.each do |action, action_config| | ||
add_action_to_scheme(action, action_config, scheme) | ||
end | ||
end | ||
end | ||
|
||
def add_action_to_scheme(action, action_config, scheme) | ||
action_elem = action_from_scheme(action, scheme) | ||
|
||
build_configuration = action_config["build_configuration"] | ||
if build_configuration | ||
action_elem.build_configuration = build_configuration | ||
end | ||
end | ||
|
||
def action_from_scheme(action_name, scheme) | ||
scheme.send("#{action_name.downcase}_action") | ||
end | ||
|
||
def string_renderer | ||
@renderer ||= StringRenderer.new(config) | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,6 +321,15 @@ Create a settings bundle. If you also have | |
.Ic use_cocoapods | ||
enabled, this settings bundle will automatically contain the acknowledgements | ||
for any installed pods. | ||
.It Ic schemes | ||
type: dictionary | ||
.br | ||
default: none | ||
.Pp | ||
Create additional custom schemes. By | ||
default this key isn't set. See | ||
.Sx CUSTOM SCHEMES | ||
for more information on the format of this key. | ||
.El | ||
. | ||
.Sh SCRIPT PHASES | ||
|
@@ -623,6 +632,42 @@ extra_config: | |
WARNING_CFLAGS: | ||
- -Weverything | ||
.Ed | ||
|
||
. | ||
.Sh CUSTOM SCHEMES | ||
.Ic liftoff | ||
can create additional custom schemes for your application. To do so, you need | ||
to specify a name and which build configuration will be used for each | ||
.Ic action | ||
(test, launch, profile, archive or analyze). In order to create additional | ||
schemes, you should add the | ||
.Ic schemes | ||
key in your | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this missing a word after "your"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, because |
||
.Nm , | ||
and add dictionaries that correspond to the schemes you'd like to create. | ||
For example, to create a scheme that will be used when distributing your | ||
app to the App Store, you can set the following: | ||
.Pp | ||
.Bd -literal | ||
schemes: | ||
- name: <%= project_name %>-AppStore | ||
actions: | ||
test: | ||
build_configuration: Debug | ||
launch: | ||
build_configuration: Debug | ||
profile: | ||
build_configuration: Release | ||
archive: | ||
build_configuration: Release | ||
analyze: | ||
build_configuration: Debug | ||
.Ed | ||
.Pp | ||
Note that the keys inside actions must match the predefined keys and the key | ||
for the build configuration must match the name of the build | ||
configuration you'd like to use exactly. | ||
.Ed | ||
. | ||
.Sh FILES | ||
.Pa ~/.liftoffrc | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,6 +128,38 @@ | |
expect(config.path).to eq 'Another Path' | ||
end | ||
end | ||
|
||
describe '#schemes' do | ||
it 'returns an array of schemes' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this test is only testing that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that it doesn't add much value, but IMO it's nice to have documented the hash format. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that not covered in your documentation above? |
||
schemes = [ | ||
{ | ||
"name" => "<%= project_name %>-CI", | ||
"actions" => { | ||
"test" => { | ||
"build_configuration" => "Debug" | ||
}, | ||
"profile" => { | ||
"build_configuration" => "Release" | ||
}, | ||
"analyze" => { | ||
"build_configuration" => "Debug" | ||
}, | ||
"archive" => { | ||
"build_configuration" => "Release" | ||
}, | ||
"launch" => { | ||
"build_configuration" => "Debug" | ||
} | ||
} | ||
} | ||
] | ||
|
||
config = Liftoff::ProjectConfiguration.new({}) | ||
config.schemes = schemes | ||
|
||
expect(config.schemes.to_a).to eq(schemes) | ||
end | ||
end | ||
end | ||
|
||
def build_config(name) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
require "spec_helper" | ||
|
||
describe Liftoff::SchemeBuilder do | ||
describe "#create_schemes" do | ||
it "creates schemes with the right names" do | ||
project = double("xcodeproj") | ||
config = build_config("FakeApp", build_schemes) | ||
scheme_builder = scheme_builder(project, config) | ||
|
||
allow(project).to receive(:generate_default_scheme) | ||
allow(project).to receive(:generate_scheme) | ||
|
||
scheme_builder.create_schemes | ||
|
||
expect(project).to have_received(:generate_default_scheme).with(no_args) | ||
expect(project).to have_received(:generate_scheme).with("FakeApp-CI") | ||
expect(project).to have_received(:generate_scheme).with("FakeApp-AppStore") | ||
end | ||
|
||
it "add build configurations to actions" do | ||
project = double("xcodeproj") | ||
schemes = [build_scheme("<%= project_name %>-CI")] | ||
config = build_config("FakeApp", schemes) | ||
scheme_builder = scheme_builder(project, config) | ||
|
||
scheme = Xcodeproj::XCScheme.new | ||
|
||
allow(project).to receive(:generate_default_scheme) | ||
allow(project).to receive(:generate_scheme).and_yield(scheme) | ||
|
||
scheme_builder.create_schemes | ||
|
||
expect(project).to have_received(:generate_default_scheme).with(no_args) | ||
expect(project).to have_received(:generate_scheme).with("FakeApp-CI") | ||
|
||
expect(scheme.test_action.build_configuration).to eq "Debug-CI" | ||
expect(scheme.profile_action.build_configuration).to eq "Release-CI" | ||
expect(scheme.analyze_action.build_configuration).to eq "Debug-CI" | ||
expect(scheme.archive_action.build_configuration).to eq "Release-CI" | ||
expect(scheme.launch_action.build_configuration).to eq "Debug-CI" | ||
end | ||
|
||
end | ||
|
||
def scheme_builder(project, config) | ||
Liftoff::SchemeBuilder.new(project, config) | ||
end | ||
|
||
def build_config(name, schemes) | ||
Liftoff::ProjectConfiguration.new({ | ||
:project_name => name, | ||
:schemes => schemes, | ||
}) | ||
end | ||
|
||
def build_scheme(name) | ||
{ | ||
"name" => name, | ||
"actions" => { | ||
"test" => { | ||
"build_configuration" => "Debug-CI" | ||
}, | ||
"profile" => { | ||
"build_configuration" => "Release-CI" | ||
}, | ||
"analyze" => { | ||
"build_configuration" => "Debug-CI" | ||
}, | ||
"archive" => { | ||
"build_configuration" => "Release-CI" | ||
}, | ||
"launch" => { | ||
"build_configuration" => "Debug-CI" | ||
} | ||
} | ||
} | ||
end | ||
|
||
def build_schemes | ||
[ | ||
build_scheme("<%= project_name %>-CI"), | ||
build_scheme("<%= project_name %>-AppStore"), | ||
] | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where the trailing comma is needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But isn't the rule only for lists? Is this any different than https://github.com/thoughtbot/guides/blob/master/style/ruby/sample.rb#L19? (I'm not a Ruby developer, so forgive me if I'm writing something dumb)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, what you linked to is a method definition. It's actually a syntax error there so we can't do it. The example that shows this case is here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I get an error if I try to add a comma:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops! I didn't see this was an attr_accessor list here. You're correct!