Skip to content

Commit

Permalink
[command] Add verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
viteinfinite committed Jan 18, 2016
1 parent 36db604 commit 3442a20
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
6 changes: 6 additions & 0 deletions bin/slather
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
32 changes: 23 additions & 9 deletions lib/slather/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -129,20 +143,15 @@ 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

if self.binary_file == nil
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 3442a20

Please sign in to comment.