class Alcove

Constants

TEMP_DIR
VERSION

Public Class Methods

new(options) click to toggle source

Public: Initializes a new instance.

# File lib/alcove.rb, line 12
def initialize(options)
  @verbose = options.verbose
end

Public Instance Methods

copy_input_files_to_temp(search_directory, product_name) click to toggle source

Public: Searches for the .gcno and .gcda files required to generate the

report and copies them into the temp directory.

search_directory - The directory to search for .gcno and .gcda files. product_name - The product name (${PRODUCT_NAME}) from the Xcode

project, which will be used to determine what .gcno and
.gcda files to copy.

Returns nothing.

# File lib/alcove.rb, line 39
def copy_input_files_to_temp(search_directory, product_name)
  build_path = "/Intermediates/#{product_name}.build/"
  puts " 📦  Gathering .gcno and .gcda files..." if @verbose
  puts "  Searching in #{search_directory} for #{build_path}..." if @verbose
  found_files = false
  Find.find(search_directory) do |path|
    if path.match(/#{build_path}.*\.gcda\Z/) || path.match(/#{build_path}.*\.gcno\Z/)
      found_files = true
      puts "  👍  .#{path.sub(search_directory, "")}".green if @verbose
      FileUtils.cp(path, "#{Alcove::TEMP_DIR}/")
    end
  end
  return found_files
end
extract_percent_from_summary(summary) click to toggle source

Public: Extracts the percentage from the lcov summary string.

summary - The summary string output by lcov or genhtml

# File lib/alcove.rb, line 102
def extract_percent_from_summary(summary)
  summary[/lines.*: (.*)%/, 1].to_f
end
gen_info_files(filename) click to toggle source

Public: Calls the geninfo command to generate information files for

lcov to process.

filename - The name of the file to be created by geninfo.

Returns the result of the geninfo command.

# File lib/alcove.rb, line 60
def gen_info_files(filename)
  absolute_temp_dir = File.join(Dir.pwd, Alcove::TEMP_DIR)
  gen_info_cmd = "geninfo #{absolute_temp_dir}/*.gcno --output-filename #{filename}"
  gen_info_cmd << " --quiet" unless @verbose
  system gen_info_cmd
end
genhtml(lcov_file_path, output_directory) click to toggle source

Public: Calls the genhtml command to generate an HTML report from the

lcov information file.

lcov_file_path - The path to the file generated by lcov. output_directory - The directory where output files should be placed.

Returns the result of the genhtml command.

# File lib/alcove.rb, line 88
def genhtml(lcov_file_path, output_directory)
  FileUtils.mkpath(output_directory)
  genhtml_cmd = "genhtml --no-function-coverage --no-branch-coverage --output-directory #{output_directory} #{lcov_file_path}"

  stdout, stderr, exit_status = Open3.capture3(genhtml_cmd)
  puts stdout if @verbose
  puts stderr if stderr.length > 0
  summary_string = extract_percent_from_summary(stdout)
  return exit_status.success?, summary_string
end
get_search_directory() click to toggle source

Public: Determines the directory to use when searching for .gcno and .gcda

files.

Returns the directory to search.

# File lib/alcove.rb, line 20
def get_search_directory
  if ENV["XCS_SOURCE_DIR"]
    puts "  Xcode Server found." if @verbose
    ENV["XCS_SOURCE_DIR"].sub("Source", "DerivedData")
  else
    puts "  Development machine found." if @verbose
    File.join(Etc.getpwuid.dir, "/Library/Developer/Xcode/DerivedData")
  end
end
lcov(info_filename, filenames_to_remove, lcov_file) click to toggle source

Public: Calls the lcov command to generate coverage information files.

info_filename - The name of the file generated by geninfo filenames_to_remove - An array of filters to remove from the report. lcov_file - The file in which lcov will place the generated info.

Returns the result of the lcov command.

# File lib/alcove.rb, line 74
def lcov(info_filename, filenames_to_remove, lcov_file)
  all_removals = filenames_to_remove.map { |i| "\"#{i.to_s}\"" }.join(" ")
  lcov_cmd = "lcov --remove #{info_filename} #{all_removals} > #{lcov_file}"
  lcov_cmd << " --quiet" unless @verbose
  system lcov_cmd
end