Class: Scan::TestCommandGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/scan/test_command_generator.rb

Overview

Responsible for building the fully working xcodebuild command

Class Method Summary collapse

Class Method Details

.actionsObject



43
44
45
46
47
48
49
50
51
52
# File 'lib/scan/test_command_generator.rb', line 43

def actions
  config = Scan.config

  actions = []
  actions << :clean if config[:clean]
  actions << :build
  actions << :test

  actions
end

.build_pathObject

The path to set the Derived Data to



81
82
83
84
85
86
87
88
89
# File 'lib/scan/test_command_generator.rb', line 81

def build_path
  unless Scan.cache[:build_path]
    day = Time.now.strftime("%F") # e.g. 2015-08-07

    Scan.cache[:build_path] = File.expand_path("~/Library/Developer/Xcode/Archives/#{day}/")
    FileUtils.mkdir_p Scan.cache[:build_path]
  end
  Scan.cache[:build_path]
end

.generateObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/scan/test_command_generator.rb', line 5

def generate
  parts = prefix
  parts << "xcodebuild"
  parts += options
  parts += actions
  parts += suffix
  parts += pipe

  parts
end

.optionsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/scan/test_command_generator.rb', line 29

def options
  config = Scan.config

  options = []
  options += project_path_array
  options << "-configuration '#{config[:configuration]}'" if config[:configuration]
  options << "-sdk '#{config[:sdk]}'" if config[:sdk]
  options << "-destination '#{config[:destination]}'" # generated in `detect_values`
  options << "-xcconfig '#{config[:xcconfig]}'" if config[:xcconfig]
  options << config[:xcargs] if config[:xcargs]

  options
end

.pipeObject



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/scan/test_command_generator.rb', line 59

def pipe
  # During building we just show the output in the terminal
  # Check out the ReportCollector class for more xcpretty things
  formatter = ""
  if Helper.ci?
    formatter = "-f `xcpretty-travis-formatter`"
    Helper.log.info "Automatically switched to Travis formatter".green
  end

  ["| tee '#{xcodebuild_log_path}' | xcpretty #{formatter}"]
end

.prefixObject



16
17
18
# File 'lib/scan/test_command_generator.rb', line 16

def prefix
  ["set -o pipefail &&"]
end

.project_path_arrayArray

Path to the project or workspace as parameter This will also include the scheme (if given)

Returns:

  • (Array)

    The array with all the components to join



23
24
25
26
27
# File 'lib/scan/test_command_generator.rb', line 23

def project_path_array
  proj = Scan.project.xcodebuild_parameters
  return proj if proj.count > 0
  raise "No project/workspace found"
end

.suffixObject



54
55
56
57
# File 'lib/scan/test_command_generator.rb', line 54

def suffix
  suffix = []
  suffix
end

.xcodebuild_log_pathObject

Store the raw file



72
73
74
75
76
77
78
# File 'lib/scan/test_command_generator.rb', line 72

def xcodebuild_log_path
  file_name = "#{Scan.project.app_name}-#{Scan.config[:scheme]}.log"
  containing = File.expand_path(Scan.config[:buildlog_path])
  FileUtils.mkdir_p(containing)

  return File.join(containing, file_name)
end