Skip to content
This repository has been archived by the owner on Oct 2, 2018. It is now read-only.

Commit

Permalink
Added dynamic configuration value
Browse files Browse the repository at this point in the history
Configuration is fetched from the project/workspace
Updated tests
  • Loading branch information
KrauseFx committed Aug 14, 2015
1 parent 9048fb8 commit a6d859d
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/gym/build_command_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def options

options = []
options += project_path_array
options << "-configuration '#{config[:configuration]}'" # We need `Release` to export the DSYM file as well
options << "-configuration '#{config[:configuration]}'" if config[:configuration]
options << "-sdk '#{config[:sdk]}'" if config[:sdk]
options << "-destination '#{config[:destination]}'" if config[:destination]
options << "-xcconfig '#{config[:xcconfig]}'" if config[:xcconfig]
Expand Down
66 changes: 51 additions & 15 deletions lib/gym/detect_values.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def self.set_additional_default_values
end

detect_scheme
detect_configuration

config[:output_name] ||= Gym.project.app_name

Expand Down Expand Up @@ -96,31 +97,66 @@ def self.choose_project

def self.detect_scheme
config = Gym.config
proj_schemes = Gym.project.schemes

if config[:scheme].to_s.length > 0
# Verify the scheme is available
unless Gym.project.schemes.include?(config[:scheme].to_s)
unless proj_schemes.include?(config[:scheme].to_s)
Helper.log.error "Couldn't find specified scheme '#{config[:scheme]}'.".red
config[:scheme] = nil
end
end

if config[:scheme].to_s.length == 0
proj_schemes = Gym.project.schemes
if proj_schemes.count == 1
config[:scheme] = proj_schemes.last
elsif proj_schemes.count > 1
if Helper.is_ci?
Helper.log.error "Multiple schemes found but you haven't specified one.".red
Helper.log.error "Since this is a CI, please pass one using the `scheme` option".red
raise "Multiple schemes found".red
else
puts "Select Scheme: "
config[:scheme] = choose(*(proj_schemes))
end
return if config[:scheme].to_s.length > 0

if proj_schemes.count == 1
config[:scheme] = proj_schemes.last
elsif proj_schemes.count > 1
if Helper.is_ci?
Helper.log.error "Multiple schemes found but you haven't specified one.".red
Helper.log.error "Since this is a CI, please pass one using the `scheme` option".red
raise "Multiple schemes found".red
else
puts "Select Scheme: "
config[:scheme] = choose(*(proj_schemes))
end
else
raise "Couldn't find any schemes in this project".red
end
end

# Detects the available configurations (e.g. Debug, Release)
def self.detect_configuration
config = Gym.config
configurations = Gym.project.configurations
if config[:configuration]
# Verify the configuration is available
unless configurations.include?(config[:configuration])
Helper.log.error "Couldn't find specified configuration '#{config[:configuration]}'.".red
config[:configuration] = nil
end
end

# Usually we want `Release`
# We prefer `Release` to export the DSYM file as well
config[:configuration] ||= "Release" if configurations.include?("Release")

return if config[:configuration].to_s.length > 0
return if configurations.count == 0 # this is an optional value anyway

if configurations.count == 1
config[:configuration] = configurations.last
else
if Helper.is_ci?
Helper.log.error "Multiple configurations found but you haven't specified one.".red
Helper.log.error "Since this is a CI, please pass one using the `configuration` option".red
raise "Multiple configurations found".red
else
raise "Couldn't find any schemes in this project".red
puts "Select Configuration: "
config[:configuration] = choose(*(configurations))
end
end
end

end
end
2 changes: 1 addition & 1 deletion lib/gym/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def self.plain_options
short_option: "-q",
env_name: "GYM_CONFIGURATION",
description: "The configuration to use when building the app. Defaults to 'Release'",
default_value: "Release"),
optional: true),
FastlaneCore::ConfigItem.new(key: :silent,
short_option: "-t",
env_name: "GYM_SILENT",
Expand Down
35 changes: 34 additions & 1 deletion lib/gym/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ def schemes
results
end

# Get all available configurations in an array
def configurations
results = []
splitted = raw_info.split("Configurations:")
return [] if splitted.count != 2 # probably a CocoaPods project

output = splitted.last.split(":").first
output.split("\n").each_with_index do |current, index|
current = current.strip

if current.length == 0
next if index == 0
break # as we want to break on the empty line
end

results << current
end

results
end

def app_name
# WRAPPER_NAME: Example.app
# WRAPPER_SUFFIX: .app
Expand Down Expand Up @@ -60,7 +81,10 @@ def build_settings(key)
end

def raw_info
# e.g.
# Examples:

# Standard:
#
# Information about project "Example":
# Targets:
# Example
Expand All @@ -76,6 +100,15 @@ def raw_info
# Example
# ExampleUITests

# CococaPods
#
# Example.xcworkspace
# Information about workspace "Example":
# Schemes:
# Example
# HexColors
# Pods-Example

return @raw if @raw

# Unfortunately since we pass the workspace we also get all the
Expand Down
10 changes: 9 additions & 1 deletion spec/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
expect(@project.schemes).to eq(["Example"])
end

it "#configurations returns all available configurations" do
expect(@project.configurations).to eq(["Debug", "Release"])
end

it "#app_name" do
expect(@project.app_name).to eq("ExampleProductName")
end
Expand All @@ -39,9 +43,13 @@
@workspace = Gym::Project.new(Gym.config)
end

it "#schemes returns all schemes - but not the CocoaPods schemes" do
it "#schemes returns all schemes" do
expect(@workspace.schemes).to eq(["Example", "HexColors", "Pods-Example"])
end

it "#schemes returns all configurations" do
expect(@workspace.configurations).to eq([])
end
end
end
end

0 comments on commit a6d859d

Please sign in to comment.