Class: Gym::BuildCommandGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/gym/generators/build_command_generator.rb

Overview

Responsible for building the fully working xcodebuild command

Class Method Summary collapse

Class Method Details

.actionsObject



44
45
46
47
48
49
50
51
52
# File 'lib/gym/generators/build_command_generator.rb', line 44

def actions
  config = Gym.config

  actions = []
  actions << :clean if config[:clean]
  actions << :archive

  actions
end

.archive_pathObject



83
84
85
86
87
88
89
90
# File 'lib/gym/generators/build_command_generator.rb', line 83

def archive_path
  Gym.cache[:archive_path] ||= Gym.config[:archive_path]
  unless Gym.cache[:archive_path]
    file_name = [Gym.config[:output_name], Time.now.strftime("%F %H.%M.%S")] # e.g. 2015-08-07 14.49.12
    Gym.cache[:archive_path] = File.join(build_path, file_name.join(" ") + ".xcarchive")
  end
  return Gym.cache[:archive_path]
end

.build_pathObject

The path to set the Derived Data to



73
74
75
76
77
78
79
80
81
# File 'lib/gym/generators/build_command_generator.rb', line 73

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

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

.generateObject



5
6
7
8
9
10
11
12
13
14
# File 'lib/gym/generators/build_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
42
# File 'lib/gym/generators/build_command_generator.rb', line 29

def options
  config = Gym.config

  options = []
  options += project_path_array
  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]
  options << "-archivePath '#{archive_path}'"
  options << config[:xcargs] if config[:xcargs]

  options
end

.pipeObject



60
61
62
# File 'lib/gym/generators/build_command_generator.rb', line 60

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

.prefixObject



16
17
18
# File 'lib/gym/generators/build_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/gym/generators/build_command_generator.rb', line 23

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

.suffixObject



54
55
56
57
58
# File 'lib/gym/generators/build_command_generator.rb', line 54

def suffix
  suffix = []
  suffix << "CODE_SIGN_IDENTITY='#{Gym.config[:codesigning_identity]}'" if Gym.config[:codesigning_identity]
  suffix
end

.xcodebuild_log_pathObject



64
65
66
67
68
69
70
# File 'lib/gym/generators/build_command_generator.rb', line 64

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

  return File.join(containing, file_name)
end