Skip to content

Commit

Permalink
Adding support to creating custom schemes
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelofabri authored and jakecraige committed Sep 8, 2015
1 parent 1599205 commit 4c99412
Show file tree
Hide file tree
Showing 10 changed files with 255 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'

group :dist do
gem 'xcodeproj', '~> 0.19.3'
gem 'xcodeproj', '~> 0.27.1'
gem 'highline', '~> 1.6'
end

Expand Down
28 changes: 20 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (3.2.19)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
activesupport (4.2.4)
i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1)
claide (0.9.1)
colored (1.2)
diff-lcs (1.2.5)
highline (1.6.21)
i18n (0.6.11)
multi_json (1.10.1)
i18n (0.7.0)
json (1.8.3)
minitest (5.8.0)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
Expand All @@ -17,8 +22,12 @@ GEM
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
xcodeproj (0.19.3)
activesupport (~> 3.0)
thread_safe (0.3.5)
tzinfo (1.2.2)
thread_safe (~> 0.1)
xcodeproj (0.27.1)
activesupport (>= 3)
claide (~> 0.9.1)
colored (~> 1.2)

PLATFORMS
Expand All @@ -27,4 +36,7 @@ PLATFORMS
DEPENDENCIES
highline (~> 1.6)
rspec
xcodeproj (~> 0.19.3)
xcodeproj (~> 0.27.1)

BUNDLED WITH
1.10.6
1 change: 1 addition & 0 deletions lib/liftoff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
require 'liftoff/project'
require 'liftoff/project_builder'
require 'liftoff/project_configuration'
require 'liftoff/scheme_builder'
require 'liftoff/string_renderer'
require 'liftoff/template_finder'
require 'liftoff/template_generator'
Expand Down
11 changes: 9 additions & 2 deletions lib/liftoff/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@ def new_group(name, path)
xcode_project.new_group(name, path)
end

def generate_scheme
def generate_default_scheme
generate_scheme(@name)
end

def generate_scheme(name)
scheme = Xcodeproj::XCScheme.new
scheme.add_build_target(app_target)
scheme.add_test_target(unit_test_target)
scheme.set_launch_target(app_target)
scheme.save_as(xcode_project.path, @name)
if block_given?
yield scheme
end
scheme.save_as(xcode_project.path, name)
end

private
Expand Down
6 changes: 5 additions & 1 deletion lib/liftoff/project_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def create_project
end

xcode_project.save
xcode_project.generate_scheme
scheme_builder.create_schemes
end

private
Expand Down Expand Up @@ -118,5 +118,9 @@ def file_manager
def string_renderer
@renderer ||= StringRenderer.new(@config)
end

def scheme_builder
@scheme_builder ||= SchemeBuilder.new(xcode_project, @config)
end
end
end
3 changes: 2 additions & 1 deletion lib/liftoff/project_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class ProjectConfiguration
:xcode_command,
:extra_config,
:extra_test_config,
:deployment_target
:deployment_target,
:schemes

attr_writer :author,
:company_identifier,
Expand Down
55 changes: 55 additions & 0 deletions lib/liftoff/scheme_builder.rb
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
45 changes: 45 additions & 0 deletions man/liftoffrc.5
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
.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
Expand Down
32 changes: 32 additions & 0 deletions spec/project_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,38 @@
expect(config.path).to eq 'Another Path'
end
end

describe '#schemes' do
it 'returns an array of schemes' do
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

describe "#dependency_manager_enabled?" do
Expand Down
85 changes: 85 additions & 0 deletions spec/scheme_builder_spec.rb
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

0 comments on commit 4c99412

Please sign in to comment.