Class: Slather::Project
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#slather_setup_for_coverage
Instance Attribute Details
#binary_basename ⇒ Object
Returns the value of attribute binary_basename.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def binary_basename
@binary_basename
end
|
#binary_file ⇒ Object
Returns the value of attribute binary_file.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def binary_file
@binary_file
end
|
#build_directory ⇒ Object
Returns the value of attribute build_directory.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def build_directory
@build_directory
end
|
#ci_service ⇒ Object
Returns the value of attribute ci_service.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def ci_service
@ci_service
end
|
#coverage_access_token ⇒ Object
Returns the value of attribute coverage_access_token.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def coverage_access_token
@coverage_access_token
end
|
#coverage_service ⇒ Object
Returns the value of attribute coverage_service.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def coverage_service
@coverage_service
end
|
#decimals ⇒ Object
Returns the value of attribute decimals.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def decimals
@decimals
end
|
#ignore_list ⇒ Object
Returns the value of attribute ignore_list.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def ignore_list
@ignore_list
end
|
Returns the value of attribute input_format.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def input_format
@input_format
end
|
#llvm_version ⇒ Object
Returns the value of attribute llvm_version.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def llvm_version
@llvm_version
end
|
#output_directory ⇒ Object
Returns the value of attribute output_directory.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def output_directory
@output_directory
end
|
#scheme ⇒ Object
Returns the value of attribute scheme.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def scheme
@scheme
end
|
#show_html ⇒ Object
Returns the value of attribute show_html.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def show_html
@show_html
end
|
#source_directory ⇒ Object
Returns the value of attribute source_directory.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def source_directory
@source_directory
end
|
#source_files ⇒ Object
Returns the value of attribute source_files.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def source_files
@source_files
end
|
#verbose_mode ⇒ Object
Returns the value of attribute verbose_mode.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def verbose_mode
@verbose_mode
end
|
#workspace ⇒ Object
Returns the value of attribute workspace.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def workspace
@workspace
end
|
#xcodeproj ⇒ Object
Returns the value of attribute xcodeproj.
53
54
55
|
# File 'lib/slather/project.rb', line 53
def xcodeproj
@xcodeproj
end
|
Class Method Details
.open(xcodeproj) ⇒ Object
59
60
61
62
63
|
# File 'lib/slather/project.rb', line 59
def self.open(xcodeproj)
proj = super
proj.xcodeproj = xcodeproj
proj
end
|
.yml ⇒ Object
226
227
228
|
# File 'lib/slather/project.rb', line 226
def self.yml
@yml ||= File.exist?(yml_filename) ? YAML.load_file(yml_filename) : {}
end
|
.yml_filename ⇒ Object
222
223
224
|
# File 'lib/slather/project.rb', line 222
def self.yml_filename
'.slather.yml'
end
|
Instance Method Details
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
# File 'lib/slather/project.rb', line 230
def configure
begin
configure_scheme
configure_workspace
configure_build_directory
configure_ignore_list
configure_ci_service
configure_coverage_access_token
configure_coverage_service
configure_source_directory
configure_output_directory
configure_input_format
configure_binary_file
configure_decimals
self.llvm_version = `xcrun llvm-cov --version`.match(/Apple LLVM version ([\d\.]+)/).captures[0]
rescue => e
puts e.message
puts failure_help_string
puts "\n"
raise
end
if self.verbose_mode
puts "\nProcessing coverage file: #{profdata_file}"
puts "Against binary files:"
self.binary_file.each do |binary_file|
puts "\t#{binary_file}"
end
puts "\n"
end
end
|
346
347
348
349
350
|
# File 'lib/slather/project.rb', line 346
def configure_binary_file
if self.input_format == "profdata"
self.binary_file = load_option_array("binary_file") || find_binary_files
end
end
|
263
264
265
|
# File 'lib/slather/project.rb', line 263
def configure_build_directory
self.build_directory ||= self.class.yml["build_directory"] || derived_data_path
end
|
279
280
281
|
# File 'lib/slather/project.rb', line 279
def configure_ci_service
self.ci_service ||= (self.class.yml["ci_service"] || :travis_ci)
end
|
321
322
323
|
# File 'lib/slather/project.rb', line 321
def configure_coverage_access_token
self.coverage_access_token ||= (ENV["COVERAGE_ACCESS_TOKEN"] || self.class.yml["coverage_access_token"] || "")
end
|
317
318
319
|
# File 'lib/slather/project.rb', line 317
def configure_coverage_service
self.coverage_service ||= (self.class.yml["coverage_service"] || :terminal)
end
|
303
304
305
306
307
|
# File 'lib/slather/project.rb', line 303
def configure_decimals
return if self.decimals
self.decimals ||= self.class.yml["decimals"] if self.class.yml["decimals"]
self.decimals = self.decimals ? Integer(self.decimals) : 2
end
|
275
276
277
|
# File 'lib/slather/project.rb', line 275
def configure_ignore_list
self.ignore_list ||= [(self.class.yml["ignore"] || [])].flatten
end
|
283
284
285
|
# File 'lib/slather/project.rb', line 283
def configure_input_format
self.input_format ||= (self.class.yml["input_format"] || "auto")
end
|
271
272
273
|
# File 'lib/slather/project.rb', line 271
def configure_output_directory
self.output_directory ||= self.class.yml["output_directory"] if self.class.yml["output_directory"]
end
|
299
300
301
|
# File 'lib/slather/project.rb', line 299
def configure_scheme
self.scheme ||= self.class.yml["scheme"] if self.class.yml["scheme"]
end
|
267
268
269
|
# File 'lib/slather/project.rb', line 267
def configure_source_directory
self.source_directory ||= self.class.yml["source_directory"] if self.class.yml["source_directory"]
end
|
309
310
311
|
# File 'lib/slather/project.rb', line 309
def configure_workspace
self.workspace ||= self.class.yml["workspace"] if self.class.yml["workspace"]
end
|
#coverage_files ⇒ Object
103
104
105
106
107
108
109
|
# File 'lib/slather/project.rb', line 103
def coverage_files
if self.input_format == "profdata"
profdata_coverage_files
else
gcov_coverage_files
end
end
|
#decimal_f(decimal_arg) ⇒ Object
352
353
354
355
356
357
|
# File 'lib/slather/project.rb', line 352
def decimal_f decimal_arg
configure_decimals unless decimals
decimal = "%.#{decimals}f" % decimal_arg
return decimal if decimals == 2 decimal.to_f.to_s
end
|
#failure_help_string ⇒ Object
65
66
67
|
# File 'lib/slather/project.rb', line 65
def failure_help_string
"\n\tAre you sure your project is generating coverage? Make sure you enable code coverage in the Test section of your Xcode scheme.\n\tDid you specify your Xcode scheme? (--scheme or 'scheme' in .slather.yml)\n\tIf you're using a workspace, did you specify it? (--workspace or 'workspace' in .slather.yml)"
end
|
#find_binary_file_in_bundle(bundle_file) ⇒ Object
359
360
361
362
363
364
365
366
|
# File 'lib/slather/project.rb', line 359
def find_binary_file_in_bundle(bundle_file)
if File.directory? bundle_file
bundle_file_noext = File.basename(bundle_file, File.extname(bundle_file))
Dir["#{bundle_file}/**/#{bundle_file_noext}"].first
else
bundle_file
end
end
|
#find_binary_files ⇒ Object
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
|
# File 'lib/slather/project.rb', line 368
def find_binary_files
binary_basename = load_option_array("binary_basename")
found_binaries = []
if self.scheme
schemes_path = Xcodeproj::XCScheme.shared_data_dir(self.path)
xcscheme_path = "#{schemes_path + self.scheme}.xcscheme"
if !File.file?(xcscheme_path)
schemes_path = Xcodeproj::XCScheme.user_data_dir(self.path)
xcscheme_path = "#{schemes_path + self.scheme}.xcscheme"
end
if self.workspace and !File.file?(xcscheme_path)
schemes_path = Xcodeproj::XCScheme.shared_data_dir(self.workspace)
xcscheme_path = "#{schemes_path + self.scheme}.xcscheme"
if !File.file?(xcscheme_path)
schemes_path = Xcodeproj::XCScheme.user_data_dir(self.workspace)
xcscheme_path = "#{schemes_path + self.scheme}.xcscheme"
end
end
raise StandardError, "No scheme named '#{self.scheme}' found in #{self.path}" unless File.exists? xcscheme_path
xcscheme = Xcodeproj::XCScheme.new(xcscheme_path)
configuration = xcscheme.test_action.build_configuration
search_list = binary_basename || find_buildable_names(xcscheme)
search_list.each do |search_for|
found_product = Dir["#{profdata_coverage_dir}/Products/#{configuration}*/#{search_for}*"].sort { |x, y|
File.basename(x, File.extname(x)) <=> File.basename(y, File.extname(y))
}.reject { |path|
path.end_with? ".dSYM"
}.first
if found_product and File.directory? found_product
found_binary = find_binary_file_in_bundle(found_product)
else
found_binary = found_product
end
if found_binary
found_binaries.push(found_binary)
end
end
else
xctest_bundle = Dir["#{profdata_coverage_dir}/**/*.xctest"].reject { |bundle|
bundle.include? "-Runner.app/PlugIns/"
}.first
search_list = binary_basename || ['*']
search_list.each do |search_for|
xctest_bundle_file_directory = Pathname.new(xctest_bundle).dirname
app_bundle = Dir["#{xctest_bundle_file_directory}/#{search_for}.app"].first
matched_xctest_bundle = Dir["#{xctest_bundle_file_directory}/#{search_for}.xctest"].first
dynamic_lib_bundle = Dir["#{xctest_bundle_file_directory}/#{search_for}.{framework,dylib}"].first
if app_bundle != nil
found_binary = find_binary_file_in_bundle(app_bundle)
elsif matched_xctest_bundle != nil
found_binary = find_binary_file_in_bundle(matched_xctest_bundle)
elsif dynamic_lib_bundle != nil
found_binary = find_binary_file_in_bundle(dynamic_lib_bundle)
else
found_binary = find_binary_file_in_bundle(xctest_bundle)
end
if found_binary
found_binaries.push(found_binary)
end
end
end
raise StandardError, "No product binary found in #{profdata_coverage_dir}." unless found_binaries.count > 0
found_binaries.map { |binary| File.expand_path(binary) }
end
|
#find_buildable_names(xcscheme) ⇒ Object
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
|
# File 'lib/slather/project.rb', line 457
def find_buildable_names(xcscheme)
found_buildable_names = []
begin
xcscheme.build_action.entries.each do |entry|
buildable_name = entry.buildable_references[0].buildable_name
if !buildable_name.end_with? ".a"
found_buildable_names.push(buildable_name)
end
end
rescue
end
begin
xcscheme.test_action.testables.each do |entry|
buildable_name = entry.buildable_references[0].buildable_name
found_buildable_names.push(buildable_name)
end
rescue
end
found_buildable_names.uniq
end
|
#find_source_files ⇒ Object
488
489
490
491
492
493
494
495
496
497
498
499
500
|
# File 'lib/slather/project.rb', line 488
def find_source_files
source_files = load_option_array("source_files")
return if source_files.nil?
current_dir = Pathname("./").realpath
paths = source_files.flat_map { |pattern| Dir.glob(pattern) }.uniq
paths.map do |path|
source_file_absolute_path = Pathname(path).realpath
source_file_relative_path = source_file_absolute_path.relative_path_from(current_dir)
self.ignore_list.any? { |ignore| File.fnmatch(ignore, source_file_relative_path) } ? nil : source_file_absolute_path
end.compact
end
|
#first_product_name ⇒ Object
157
158
159
160
161
162
|
# File 'lib/slather/project.rb', line 157
def first_product_name
first_product = self.products.first
first_product.name || remove_extension(first_product.path)
end
|
#load_option_array(option) ⇒ Object
502
503
504
505
506
507
508
509
510
511
512
513
514
515
|
# File 'lib/slather/project.rb', line 502
def load_option_array(option)
value = self.send(option.to_sym)
if !value
value_yml = self.class.yml[option]
if value_yml and value_yml.is_a? Array
value = value_yml
elsif value_yml
value = [value_yml]
end
end
value
end
|
#profdata_coverage_dir ⇒ Object
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/slather/project.rb', line 164
def profdata_coverage_dir
raise StandardError, "The specified build directory (#{self.build_directory}) does not exist" unless File.exists?(self.build_directory)
dir = nil
if self.scheme
dir = Dir[File.join("#{build_directory}","/**/CodeCoverage/#{self.scheme}")].first
else
dir = Dir[File.join("#{build_directory}","/**/#{first_product_name}")].first
end
if dir == nil
dir = Dir[File.join("#{build_directory}","/**/CodeCoverage")].first
end
raise StandardError, "No coverage directory found." unless dir != nil
dir
end
|
#remove_extension(path) ⇒ Object
153
154
155
|
# File 'lib/slather/project.rb', line 153
def remove_extension(path)
path.split(".")[0..-2].join(".")
end
|