From 3442a20cbb868ef7a8d67c546477e03b619df4ce Mon Sep 17 00:00:00 2001 From: Simone Civetta Date: Mon, 18 Jan 2016 15:48:05 +0100 Subject: [PATCH] [command] Add verbose mode --- bin/slather | 6 ++++++ lib/slather/project.rb | 32 +++++++++++++++++++++++--------- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/bin/slather b/bin/slather index caf6d561..79de53f4 100755 --- a/bin/slather +++ b/bin/slather @@ -27,6 +27,7 @@ Clamp do option ["--source-directory"], "SOURCE_DIRECTORY", "The directory where your source files are located." option ["--output-directory"], "OUTPUT_DIRECTORY", "The directory where your Cobertura XML report will be written to." option ["--ignore", "-i"], "IGNORE", "ignore files conforming to a path", :multivalued => true + option ["--verbose", "-v"], :flag, "Enable verbose mode" option ["--input-format"], "INPUT_FORMAT", "Input format (gcov, profdata)" option ["--scheme"], "SCHEME", "The scheme for which the coverage was generated" @@ -41,6 +42,7 @@ Clamp do setup_source_directory setup_output_directory setup_coverage_service + setup_verbose_mode setup_input_format setup_scheme setup_binary_file @@ -110,6 +112,10 @@ Clamp do end end + def setup_verbose_mode + project.verbose_mode = verbose? + end + def setup_input_format project.input_format = input_format end diff --git a/lib/slather/project.rb b/lib/slather/project.rb index e50e5275..9ed3f9e0 100644 --- a/lib/slather/project.rb +++ b/lib/slather/project.rb @@ -51,7 +51,7 @@ module Slather class Project < Xcodeproj::Project attr_accessor :build_directory, :ignore_list, :ci_service, :coverage_service, :coverage_access_token, :source_directory, - :output_directory, :xcodeproj, :show_html, :input_format, :scheme, :binary_file + :output_directory, :xcodeproj, :show_html, :verbose_mode, :input_format, :scheme, :binary_file alias_method :setup_for_coverage, :slather_setup_for_coverage @@ -113,6 +113,20 @@ def profdata_coverage_dir dir end + def profdata_file + profdata_coverage_dir = self.profdata_coverage_dir + if profdata_coverage_dir == nil + raise StandardError, "No coverage directory found. Please make sure the \"Code Coverage\" checkbox is enabled in your scheme's Test action or the build_directory property is set." + end + + file = Dir["#{profdata_coverage_dir}/**/Coverage.profdata"].first + unless file != nil + return nil + end + return File.expand_path(file) + end + private :profdata_file + def find_binary_file_for_app(app_bundle_file) app_bundle_file_name_noext = Pathname.new(app_bundle_file).basename.to_s.gsub(".app", "") Dir["#{app_bundle_file}/**/#{app_bundle_file_name_noext}"].first @@ -129,9 +143,8 @@ def find_binary_file_for_static_lib(xctest_bundle_file) end def unsafe_profdata_llvm_cov_output - profdata_coverage_dir = self.profdata_coverage_dir - - if profdata_coverage_dir == nil || (profdata_file_arg = Dir["#{profdata_coverage_dir}/**/Coverage.profdata"].first) == nil + profdata_file_arg = profdata_file + if profdata_file_arg == nil raise StandardError, "No Coverage.profdata files found. Please make sure the \"Code Coverage\" checkbox is enabled in your scheme's Test action or the build_directory property is set." end @@ -139,10 +152,6 @@ def unsafe_profdata_llvm_cov_output raise StandardError, "No binary file found." end - puts "\nProcessing coverage file: #{profdata_file_arg}" - puts "Against binary file: #{self.binary_file}\n\n" - - llvm_cov_args = %W(show -instr-profile #{profdata_file_arg} #{self.binary_file}) `xcrun llvm-cov #{llvm_cov_args.shelljoin}` end @@ -177,6 +186,11 @@ def configure configure_input_format configure_scheme configure_binary_file + + if self.verbose_mode + puts "\nProcessing coverage file: #{profdata_file}" + puts "Against binary file: #{self.binary_file}\n\n" + end end def configure_build_directory @@ -253,7 +267,7 @@ def coverage_service=(service) def configure_binary_file if self.input_format == "profdata" - self.binary_file ||= self.class.yml["binary_file"] || find_binary_file + self.binary_file ||= self.class.yml["binary_file"] || File.expand_path(find_binary_file) end end