-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
188 lines (146 loc) · 4.37 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
PROJECTNAME = 'ObjectiveGumbo'.freeze
begin
require 'bundler'
Bundler.configure
rescue LoadError
end
require 'pathname'
require 'xctool'
begin
require 'stcoverage'
require 'stcoveralls'
rescue LoadError
end
task :default => 'analyze'
desc "Clean #{PROJECTNAME}-iOS and -mac"
task :clean => [ 'ios', 'mac' ].map { |x| 'clean:' + x }
namespace :clean do
desc "Clean #{PROJECTNAME}-iOS"
task :ios do IosSim.clean or fail end
desc "Clean #{PROJECTNAME}-mac"
task :mac do Mac.clean or fail end
end
desc "Analyze #{PROJECTNAME}-iOS and -mac"
task :analyze => [ 'ios', 'mac' ].map { |x| 'analyze:' + x }
namespace :analyze do
desc "Analyze #{PROJECTNAME}-iOS"
task :ios do IosSim.analyze or fail end
desc "Analyze #{PROJECTNAME}-mac"
task :mac do Mac.analyze or fail end
end
desc "Compile #{PROJECTNAME}-iOS and -mac"
task :build => [ 'ios', 'mac' ].map { |x| 'build:' + x }
namespace :build do
desc "Compile #{PROJECTNAME}-iOS"
task :ios do IosSim.build or fail end
desc "Compile #{PROJECTNAME}-mac"
task :mac do Mac.build or fail end
end
desc "Execute #{PROJECTNAME}Tests-iOS and -mac"
task :test => [ 'ios', 'mac' ].map { |x| 'test:' + x }
namespace :test do
desc "Execute #{PROJECTNAME}Tests-iOS"
task :ios do IosSim.test or fail end
desc "Execute #{PROJECTNAME}Tests-mac"
task :mac do Mac.test or fail end
end
if defined?(Stcoverage)
desc "Calculate test coverage for #{PROJECTNAME}-iOS and -mac"
task :coverage => [ 'ios', 'mac' ].map { |x| 'coverage:' + x }
namespace :coverage do
desc "Calculate test coverage -iOS"
task :ios do IosSim.coverage or fail end
desc "Calculate test coverage -iOS"
task :mac do Mac.coverage or fail end
end
if defined?(Stcoveralls)
namespace :coveralls do
desc "Submit coverage data to coveralls -iOS"
task :ios do IosSim.coveralls or fail end
desc "Submit coverage data to coveralls -mac"
task :mac do Mac.coveralls or fail end
end
end
end
module BuildCommands
def clean
Xctool.exec(@xctool_args, 'clean')
end
def analyze
Xctool.exec(@xctool_args, 'analyze', ['-failOnWarnings'])
end
def build
Xctool.exec(@xctool_args, 'build')
end
def test
xctool_args = @xctool_args + [
'-configuration', 'Debug',
'GCC_GENERATE_TEST_COVERAGE_FILES=YES',
'GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES',
]
Xctool.exec(xctool_args, 'test')
end
if defined?(Stcoverage)
def coverage
cwd = Pathname.getwd
cwds = cwd.to_s
coverage = stcoverage
source_lines = 0
covered_lines = 0
coverage.each do |k, v|
next unless k.start_with? cwds
path = Pathname.new k
next unless path.file? && path.readable?
relpath = path.relative_path_from cwd
file_source_lines = v.count
file_covered_lines = v.count {|k, v| v > 0}
file_coverage_fraction = (file_covered_lines / file_source_lines.to_f unless file_source_lines == 0) || 0
puts "#{relpath.to_s}: #{file_covered_lines}/#{file_source_lines} #{(file_coverage_fraction * 100).floor}%"
source_lines += file_source_lines
covered_lines += file_covered_lines
end
coverage_fraction = (covered_lines / source_lines.to_f unless source_lines == 0) || 0
puts "Overall: #{(coverage_fraction * 100).floor}%"
true
end
if defined?(Stcoveralls)
def coveralls
cov = stcoverage
Stcoveralls.coveralls do |c|
c.add_stcoverage_local(cov)
end
end
end
end
private
if defined?(Stcoverage)
def stcoverage
xctool_args = @xctool_args + [
'-configuration', 'Debug',
]
object_file_path = Xctool.platform_object_files_path(xctool_args)
return {} if object_file_path.nil?
object_file_path = Pathname.new(object_file_path)
return {} unless object_file_path.exist?
gcfilenames = object_file_path.children.map{ |c| c.cleanpath.to_s if c.fnmatch? '*.gc??' }.compact
Stcoverage.coverage(gcfilenames)
end
end
end
class IosSim
@xctool_args = [
'-project', "#{PROJECTNAME}.xcodeproj",
'-scheme', "#{PROJECTNAME}-iOS",
'-sdk', 'iphonesimulator',
'ONLY_ACTIVE_ARCH=NO',
].freeze
extend BuildCommands
end
class Mac
@xctool_args = [
'-project', "#{PROJECTNAME}.xcodeproj",
'-scheme', "#{PROJECTNAME}-mac",
'-sdk', 'macosx',
].freeze
extend BuildCommands
end