Class: Alcove
- Inherits:
-
Object
- Object
- Alcove
- Defined in:
- lib/alcove.rb,
lib/alcove/version.rb
Constant Summary collapse
- TEMP_DIR =
"alcove-temp"
- VERSION =
'0.2.3'
Instance Method Summary collapse
-
#copy_input_files_to_temp(search_directory, product_name) ⇒ Object
Public: Searches for the .gcno and .gcda files required to generate the report and copies them into the temp directory.
-
#extract_percent_from_summary(summary) ⇒ Object
Public: Extracts the percentage from the lcov summary string.
-
#gen_info_files(filename) ⇒ Object
Public: Calls the geninfo command to generate information files for lcov to process.
-
#genhtml(lcov_file_path, output_directory) ⇒ Object
Public: Calls the genhtml command to generate an HTML report from the lcov information file.
-
#get_search_directory ⇒ Object
Public: Determines the directory to use when searching for .gcno and .gcda files.
-
#initialize(options) ⇒ Alcove
constructor
Public: Initializes a new instance.
-
#lcov(info_filename, filenames_to_remove, lcov_file) ⇒ Object
Public: Calls the lcov command to generate coverage information files.
Constructor Details
#initialize(options) ⇒ Alcove
Public: Initializes a new instance.
12 13 14 |
# File 'lib/alcove.rb', line 12 def initialize() @verbose = .verbose end |
Instance Method Details
#copy_input_files_to_temp(search_directory, product_name) ⇒ Object
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.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# 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) ⇒ Object
Public: Extracts the percentage from the lcov summary string.
summary - The summary string output by lcov or genhtml
102 103 104 |
# File 'lib/alcove.rb', line 102 def extract_percent_from_summary(summary) summary[/lines.*: (.*)%/, 1].to_f end |
#gen_info_files(filename) ⇒ Object
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.
60 61 62 63 64 65 |
# 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) ⇒ Object
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.
88 89 90 91 92 93 94 95 96 97 |
# 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 ⇒ Object
Public: Determines the directory to use when searching for .gcno and .gcda
files.
Returns the directory to search.
20 21 22 23 24 25 26 27 28 |
# 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) ⇒ Object
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.
74 75 76 77 78 79 |
# 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 |