diff --git a/lib/gym/build_command_generator.rb b/lib/gym/build_command_generator.rb index 52d7c99..32ad914 100644 --- a/lib/gym/build_command_generator.rb +++ b/lib/gym/build_command_generator.rb @@ -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] diff --git a/lib/gym/detect_values.rb b/lib/gym/detect_values.rb index fc79a8f..ab189eb 100644 --- a/lib/gym/detect_values.rb +++ b/lib/gym/detect_values.rb @@ -25,6 +25,7 @@ def self.set_additional_default_values end detect_scheme + detect_configuration config[:output_name] ||= Gym.project.app_name @@ -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 diff --git a/lib/gym/options.rb b/lib/gym/options.rb index c668598..58b0543 100644 --- a/lib/gym/options.rb +++ b/lib/gym/options.rb @@ -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", diff --git a/lib/gym/project.rb b/lib/gym/project.rb index f9d006d..ce39d44 100644 --- a/lib/gym/project.rb +++ b/lib/gym/project.rb @@ -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 @@ -60,7 +81,10 @@ def build_settings(key) end def raw_info - # e.g. + # Examples: + + # Standard: + # # Information about project "Example": # Targets: # Example @@ -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 diff --git a/spec/project_spec.rb b/spec/project_spec.rb index 78dd6eb..161f4df 100644 --- a/spec/project_spec.rb +++ b/spec/project_spec.rb @@ -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 @@ -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