-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding support to creating custom schemes
- Loading branch information
1 parent
1599205
commit 4c99412
Showing
10 changed files
with
255 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |