xcjobs 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xcjobs/coverage.rb +167 -0
- data/lib/xcjobs/distribute.rb +1 -0
- data/lib/xcjobs/version.rb +1 -1
- data/lib/xcjobs/xcodebuild.rb +29 -0
- data/lib/xcjobs.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa2ca15377b59c6a3fe73d1aad2f4ef14511e3e8
|
4
|
+
data.tar.gz: 9cd9a4f8dd1a8f2ab9888d76fe5753baad89af5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e207db9d73f1d33d3c88cf3e0731cdb099c2cf4ea0d2f2d74c2e1d7d102e4211949b4c1725b51ed38890b2fe3a6e7be43219f875b5a61005358fe75f72e74e87
|
7
|
+
data.tar.gz: afe3af894b8d54827ba0f0c863cf76fc59c5d5ba179a3a9d36d6da2523655ddba61e6b92dea00e0283439d6312a71aa64a03cf99e3a5c2c2c14c2169b824882a
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'rake/tasklib'
|
2
|
+
require 'json'
|
3
|
+
require 'pathname'
|
4
|
+
require 'tempfile'
|
5
|
+
require 'open3'
|
6
|
+
|
7
|
+
module XCJobs
|
8
|
+
module Coverage
|
9
|
+
|
10
|
+
def self.run_gcov(configuration_temp_dir)
|
11
|
+
Dir.glob("#{configuration_temp_dir}/**/*.gcda").each do |file|
|
12
|
+
system %[(cd "#{File.dirname(file)}" && gcov -l "#{file}")]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Coveralls < Rake::TaskLib
|
17
|
+
include Rake::DSL if defined?(Rake::DSL)
|
18
|
+
|
19
|
+
attr_accessor :repo_token
|
20
|
+
attr_accessor :service_name
|
21
|
+
attr_accessor :service_job_id
|
22
|
+
|
23
|
+
def initialize()
|
24
|
+
@service_name = 'travis-ci'
|
25
|
+
@service_job_id = ENV['TRAVIS_JOB_ID']
|
26
|
+
|
27
|
+
@extensions = []
|
28
|
+
@excludes = []
|
29
|
+
@exclude_patterns = []
|
30
|
+
|
31
|
+
yield self if block_given?
|
32
|
+
define
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_extension(extension)
|
36
|
+
@extensions << extension
|
37
|
+
end
|
38
|
+
|
39
|
+
def add_exclude(exclude)
|
40
|
+
@excludes << exclude
|
41
|
+
end
|
42
|
+
|
43
|
+
def add_exclude_pattern(exclude_pattern)
|
44
|
+
if !exclude_pattern.kind_of?(Regexp)
|
45
|
+
exclude_pattern = Regexp.new(exclude_pattern)
|
46
|
+
end
|
47
|
+
@exclude_patterns << exclude_pattern
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def define
|
53
|
+
namespace :coverage do
|
54
|
+
desc 'send coverage report to Coveralls'
|
55
|
+
task :coveralls do
|
56
|
+
root = %x[git rev-parse --show-toplevel].strip
|
57
|
+
report = collect(root)
|
58
|
+
file = write_report(report)
|
59
|
+
upload(file)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def collect(base_dir)
|
65
|
+
report = {}
|
66
|
+
report['repo_token'] = repo_token if repo_token
|
67
|
+
report['service_name'] = service_name if service_name
|
68
|
+
report['service_job_id'] = service_job_id if service_job_id
|
69
|
+
report['source_files'] = []
|
70
|
+
|
71
|
+
Dir.glob("#{base_dir}/**/*.gcov").each do |file|
|
72
|
+
File.open(file, "r") do |handle|
|
73
|
+
source_file = {}
|
74
|
+
name = ''
|
75
|
+
source = ''
|
76
|
+
coverage = []
|
77
|
+
|
78
|
+
handle.each_line do |line|
|
79
|
+
match = /^[ ]*([0-9]+|-|#####):[ ]*([0-9]+):(.*)/.match(line)
|
80
|
+
next unless match.to_a.count == 4
|
81
|
+
count, number, text = match.to_a[1..3]
|
82
|
+
|
83
|
+
if number.to_i == 0
|
84
|
+
key, val = /([^:]+):(.*)$/.match(text).to_a[1..2]
|
85
|
+
if key == 'Source'
|
86
|
+
name = Pathname(val).relative_path_from(Pathname(base_dir)).to_s
|
87
|
+
end
|
88
|
+
else
|
89
|
+
source << text + '\n'
|
90
|
+
coverage[number.to_i - 1] = case count.strip
|
91
|
+
when "-"
|
92
|
+
nil
|
93
|
+
when "#####"
|
94
|
+
if text.strip == '}'
|
95
|
+
nil
|
96
|
+
else
|
97
|
+
0
|
98
|
+
end
|
99
|
+
else count.to_i
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
if !is_excluded_path(name)
|
105
|
+
source_file['name'] = name
|
106
|
+
source_file['source'] = source
|
107
|
+
source_file['coverage'] = coverage
|
108
|
+
|
109
|
+
report['source_files'] << source_file
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
report
|
115
|
+
end
|
116
|
+
|
117
|
+
def is_excluded_path(filepath)
|
118
|
+
if filepath.start_with?('..')
|
119
|
+
return true
|
120
|
+
end
|
121
|
+
@excludes.each do |exclude|
|
122
|
+
if filepath.start_with?(exclude)
|
123
|
+
return true
|
124
|
+
end
|
125
|
+
end
|
126
|
+
@exclude_patterns.each do |pattern|
|
127
|
+
if filepath.match(pattern)
|
128
|
+
return true
|
129
|
+
end
|
130
|
+
end
|
131
|
+
if !@extensions.empty?
|
132
|
+
@extensions.each do |extension|
|
133
|
+
if File.extname(filepath) == extension
|
134
|
+
return false
|
135
|
+
end
|
136
|
+
end
|
137
|
+
return true
|
138
|
+
else
|
139
|
+
return false
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def write_report(report)
|
144
|
+
temp = Tempfile.new('report')
|
145
|
+
temp.puts(report.to_json)
|
146
|
+
temp.path
|
147
|
+
end
|
148
|
+
|
149
|
+
def upload(json_file)
|
150
|
+
curl_options = ['curl', '-sSf', '-F', "json_file=@#{json_file}", 'https://coveralls.io/api/v1/jobs']
|
151
|
+
puts curl_options.join(' ')
|
152
|
+
Open3.popen2e(*curl_options) do |stdin, stdout_err, wait_thr|
|
153
|
+
output = ''
|
154
|
+
while line = stdout_err.gets
|
155
|
+
puts line
|
156
|
+
output << line
|
157
|
+
end
|
158
|
+
|
159
|
+
status = wait_thr.value
|
160
|
+
if !status.success?
|
161
|
+
fail "upload failed (exited with status: #{status.exitstatus})"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
data/lib/xcjobs/distribute.rb
CHANGED
data/lib/xcjobs/version.rb
CHANGED
data/lib/xcjobs/xcodebuild.rb
CHANGED
@@ -17,6 +17,7 @@ module XCJobs
|
|
17
17
|
attr_accessor :signing_identity
|
18
18
|
attr_accessor :provisioning_profile
|
19
19
|
attr_accessor :build_dir
|
20
|
+
attr_accessor :coverage
|
20
21
|
attr_accessor :formatter
|
21
22
|
|
22
23
|
attr_reader :destinations
|
@@ -41,6 +42,21 @@ module XCJobs
|
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
45
|
+
def coverage=(coverage)
|
46
|
+
@coverage = coverage
|
47
|
+
if coverage
|
48
|
+
add_build_setting('GCC_INSTRUMENT_PROGRAM_FLOW_ARCS', 'YES')
|
49
|
+
add_build_setting('GCC_GENERATE_TEST_COVERAGE_FILES', 'YES')
|
50
|
+
else
|
51
|
+
@build_settings.delete('GCC_INSTRUMENT_PROGRAM_FLOW_ARCS')
|
52
|
+
@build_settings.delete('GCC_GENERATE_TEST_COVERAGE_FILES')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def coverage_enabled
|
57
|
+
@coverage
|
58
|
+
end
|
59
|
+
|
44
60
|
def before_action(&block)
|
45
61
|
@before_action = block
|
46
62
|
end
|
@@ -67,6 +83,11 @@ module XCJobs
|
|
67
83
|
def run(cmd)
|
68
84
|
@before_action.call if @before_action
|
69
85
|
|
86
|
+
if coverage_enabled
|
87
|
+
out, status = Open3.capture2(*(cmd + ['-showBuildSettings']))
|
88
|
+
configuration_temp_dir = out.lines.grep(/\bCONFIGURATION_TEMP_DIR\b/).first.split('=').last.strip
|
89
|
+
end
|
90
|
+
|
70
91
|
if @formatter
|
71
92
|
puts (cmd + ['|', @formatter]).join(" ")
|
72
93
|
else
|
@@ -83,6 +104,10 @@ module XCJobs
|
|
83
104
|
|
84
105
|
status = wait_thrs.first.value
|
85
106
|
if status.success?
|
107
|
+
if coverage_enabled
|
108
|
+
XCJobs::Coverage.run_gcov(configuration_temp_dir)
|
109
|
+
end
|
110
|
+
|
86
111
|
@after_action.call(output, status) if @after_action
|
87
112
|
else
|
88
113
|
fail "xcodebuild failed (exited with status: #{status.exitstatus})"
|
@@ -98,6 +123,10 @@ module XCJobs
|
|
98
123
|
|
99
124
|
status = wait_thr.value
|
100
125
|
if status.success?
|
126
|
+
if coverage_enabled
|
127
|
+
XCJobs::Coverage.run_gcov(configuration_temp_dir)
|
128
|
+
end
|
129
|
+
|
101
130
|
@after_action.call(output, status) if @after_action
|
102
131
|
else
|
103
132
|
fail "xcodebuild failed (exited with status: #{status.exitstatus})"
|
data/lib/xcjobs.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xcjobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kishikawa katsumi
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- Rakefile
|
83
83
|
- lib/xcjobs.rb
|
84
84
|
- lib/xcjobs/certificate.rb
|
85
|
+
- lib/xcjobs/coverage.rb
|
85
86
|
- lib/xcjobs/distribute.rb
|
86
87
|
- lib/xcjobs/helper.rb
|
87
88
|
- lib/xcjobs/info_plist.rb
|