Module: XCodeBuildHelper
- Defined in:
- lib/rules.rb,
lib/xcode.rb,
lib/device.rb,
lib/execute.rb,
lib/version.rb,
lib/lint_plan.rb,
lib/test_plan.rb,
lib/coverage_plan.rb,
lib/xcodebuild-helper.rb,
lib/coverage_html_converter.rb
Defined Under Namespace
Classes: CoverageHtmlConverter, CoveragePlan, Device, Execute, LintPlan, Rules, TestPlan, XCode
Constant Summary
collapse
- VERSION =
"1.2.5"
- LINE_NUMBER_CLASS =
"num"
- COVERAGE_CLASS =
"coverage"
- SRC_CLASS =
"src"
- LINE_BREAK_DELIMITER =
"\n"
- LINE_INFO_DELIMITER =
"|"
Class Method Summary
collapse
Class Method Details
.[](name) ⇒ Object
8
9
10
|
# File 'lib/xcodebuild-helper.rb', line 8
def self.[](name)
@registry[name]
end
|
.app_binary_location(project) ⇒ Object
78
79
80
|
# File 'lib/xcodebuild-helper.rb', line 78
def self.app_binary_location(project)
Dir.glob(base_app_location(project) + "/CodeCoverage/#{project.get_scheme}/Products/#{project.get_config}-#{project.get_sdk}/#{project.get_workspace.gsub(/\s+/, '\\ ')}.app/#{project.get_workspace.gsub(/\s+/,"\\ ")}").first
end
|
.base_app_location(xcode) ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/xcodebuild-helper.rb', line 61
def self.base_app_location(xcode)
unless xcode == nil
cmd = create_base_cmd(xcode)
result = XCodeBuildHelper::Execute.call(cmd + "-showBuildSettings")
parse_app_settings(result)
end
end
|
.build(name, device = nil) ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/xcodebuild-helper.rb', line 25
def self.build(name, device = nil)
xcode = @registry[name]
unless xcode == nil
cmd = create_base_cmd(xcode)
if device != nil
cmd += parse_destination(xcode.get_device(device))
end
XCodeBuildHelper::Execute.call(cmd + "clean build | bundle exec xcpretty --color --report json-compilation-database")
end
end
|
.create_base_cmd(project) ⇒ Object
49
50
51
|
# File 'lib/xcodebuild-helper.rb', line 49
def self.create_base_cmd(project)
"xcodebuild -workspace \"#{project.get_workspace}.xcworkspace\" -scheme #{project.get_scheme} -sdk #{project.get_sdk} -config #{project.get_config} "
end
|
.define(name, &block) ⇒ Object
16
17
18
19
20
21
22
23
|
# File 'lib/xcodebuild-helper.rb', line 16
def self.define(name, &block)
xcode = @registry[name]
if xcode == nil
xcode = XCodeBuildHelper::XCode.new
end
xcode.instance_eval(&block)
@registry[name] = xcode
end
|
.gem_location ⇒ Object
12
13
14
|
# File 'lib/xcodebuild-helper.rb', line 12
def self.gem_location
File.expand_path(File.dirname(__dir__))
end
|
.generate_coverage(name, plan) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/xcodebuild-helper.rb', line 99
def self.generate_coverage(name, plan)
xcode = @registry[name]
unless xcode == nil
coverage_plan = xcode.get_coverage_plan(plan)
src_files = Dir.glob(coverage_plan.get_source_files.first).map{|file| file.gsub(/ /, "\\ ") }.join(' ')
result = XCodeBuildHelper::Execute.call("xcrun llvm-cov show -instr-profile \"#{profdata_location(xcode)}\" \"#{app_binary_location(xcode)}\" #{src_files}")
result = result.gsub(/^warning:.*\n/, '')
all_results = []
result.split("\n\n").each do |file|
converted_result = XCodeBuildHelper::CoverageHtmlConverter.convert_file file
all_results << converted_result
if converted_result
FileUtils::mkdir_p coverage_plan.get_output
basename = File.basename(converted_result[:title])
File.write(File.join(coverage_plan.get_output, basename + '.html'), converted_result[:content].to_html)
end
end
unless all_results.empty?
index_file = XCodeBuildHelper::CoverageHtmlConverter.create_index all_results
File.write(File.join(coverage_plan.get_output, 'index.html'), index_file.to_html)
end
FileUtils::cp(File.join(gem_location, 'assets/style.css'), coverage_plan.get_output)
end
end
|
.get_binary(xcode) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/xcodebuild-helper.rb', line 82
def self.get_binary(xcode)
unless xcode == nil
cmd = create_base_cmd(xcode)
settings = XCodeBuildHelper::Execute.call(cmd + "-showBuildSettings")
result = /TARGET_BUILD_DIR = ([a-zA-Z0-9\/ _\-]+)/.match(settings)
if(result != nil)
result[1] + "/#{xcode.get_workspace.gsub(/\s+/, '\\ ')}.app"
else
""
end
end
end
|
.launch(name, device) ⇒ Object
149
150
151
152
153
154
155
156
157
|
# File 'lib/xcodebuild-helper.rb', line 149
def self.launch(name, device)
xcode = @registry[name]
unless xcode == nil
device = xcode.get_device(device)
log_location = "./simulator-debug.log"
XCodeBuildHelper::Execute.call("bundle exec ios-sim launch \"#{get_binary(xcode)}\" --devicetypeid \"#{device.get_name.gsub(/\s+/, '-')}, #{device.get_os}\" --log #{log_location}")
end
end
|
.lint(name, plan) ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/xcodebuild-helper.rb', line 126
def self.lint(name, plan)
xcode = @registry[name]
lint_plan = xcode.get_lint_plan(plan)
cmd = "bundle exec oclint-json-compilation-database"
if(lint_plan.get_ignore)
cmd += " -e \"#{lint_plan.get_ignore}\""
end
cmd += " --"
if(lint_plan.get_report_type && lint_plan.get_output)
cmd += " -report-type #{lint_plan.get_report_type} -o #{lint_plan.get_output}"
end
rules = lint_plan.get_rules
rules.get_attribute_list.each do |key|
u_key = rules.send("key_" + key.to_s)
value = rules.send("get_" + key.to_s)
cmd += " -rc #{u_key}=#{value}"
end
XCodeBuildHelper::Execute.call(cmd)
end
|
.parse_app_settings(settings) ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'lib/xcodebuild-helper.rb', line 69
def self.parse_app_settings(settings)
result = /OBJROOT = ([a-zA-Z0-9\/ _\-]+)/.match(settings)
if result != nil
result[1]
else
""
end
end
|
.parse_destination(device) ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/xcodebuild-helper.rb', line 53
def self.parse_destination(device)
if device == nil
""
else
"-destination 'platform=#{device.get_platform},name=#{device.get_name},OS=#{device.get_os}' "
end
end
|
.profdata_location(project) ⇒ Object
95
96
97
|
# File 'lib/xcodebuild-helper.rb', line 95
def self.profdata_location(project)
Dir.glob(base_app_location(project) + "/CodeCoverage/#{project.get_scheme}/Coverage.profdata").first
end
|
.test_suite(name, plan, device = nil) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/xcodebuild-helper.rb', line 37
def self.test_suite(name, plan, device = nil)
xcode = @registry[name]
unless xcode == nil
cmd = create_base_cmd(xcode)
if device != nil
cmd += parse_destination(xcode.get_device(device))
end
XCodeBuildHelper::Execute.call(cmd + "test | bundle exec xcpretty --color --report #{xcode.get_test_plan(plan).get_report_type}")
end
end
|