Skip to content

Commit 3442a20

Browse files
committed
[command] Add verbose mode
1 parent 36db604 commit 3442a20

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

bin/slather

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Clamp do
2727
option ["--source-directory"], "SOURCE_DIRECTORY", "The directory where your source files are located."
2828
option ["--output-directory"], "OUTPUT_DIRECTORY", "The directory where your Cobertura XML report will be written to."
2929
option ["--ignore", "-i"], "IGNORE", "ignore files conforming to a path", :multivalued => true
30+
option ["--verbose", "-v"], :flag, "Enable verbose mode"
3031

3132
option ["--input-format"], "INPUT_FORMAT", "Input format (gcov, profdata)"
3233
option ["--scheme"], "SCHEME", "The scheme for which the coverage was generated"
@@ -41,6 +42,7 @@ Clamp do
4142
setup_source_directory
4243
setup_output_directory
4344
setup_coverage_service
45+
setup_verbose_mode
4446
setup_input_format
4547
setup_scheme
4648
setup_binary_file
@@ -110,6 +112,10 @@ Clamp do
110112
end
111113
end
112114

115+
def setup_verbose_mode
116+
project.verbose_mode = verbose?
117+
end
118+
113119
def setup_input_format
114120
project.input_format = input_format
115121
end

lib/slather/project.rb

+23-9
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ module Slather
5151
class Project < Xcodeproj::Project
5252

5353
attr_accessor :build_directory, :ignore_list, :ci_service, :coverage_service, :coverage_access_token, :source_directory,
54-
:output_directory, :xcodeproj, :show_html, :input_format, :scheme, :binary_file
54+
:output_directory, :xcodeproj, :show_html, :verbose_mode, :input_format, :scheme, :binary_file
5555

5656
alias_method :setup_for_coverage, :slather_setup_for_coverage
5757

@@ -113,6 +113,20 @@ def profdata_coverage_dir
113113
dir
114114
end
115115

116+
def profdata_file
117+
profdata_coverage_dir = self.profdata_coverage_dir
118+
if profdata_coverage_dir == nil
119+
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."
120+
end
121+
122+
file = Dir["#{profdata_coverage_dir}/**/Coverage.profdata"].first
123+
unless file != nil
124+
return nil
125+
end
126+
return File.expand_path(file)
127+
end
128+
private :profdata_file
129+
116130
def find_binary_file_for_app(app_bundle_file)
117131
app_bundle_file_name_noext = Pathname.new(app_bundle_file).basename.to_s.gsub(".app", "")
118132
Dir["#{app_bundle_file}/**/#{app_bundle_file_name_noext}"].first
@@ -129,20 +143,15 @@ def find_binary_file_for_static_lib(xctest_bundle_file)
129143
end
130144

131145
def unsafe_profdata_llvm_cov_output
132-
profdata_coverage_dir = self.profdata_coverage_dir
133-
134-
if profdata_coverage_dir == nil || (profdata_file_arg = Dir["#{profdata_coverage_dir}/**/Coverage.profdata"].first) == nil
146+
profdata_file_arg = profdata_file
147+
if profdata_file_arg == nil
135148
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."
136149
end
137150

138151
if self.binary_file == nil
139152
raise StandardError, "No binary file found."
140153
end
141154

142-
puts "\nProcessing coverage file: #{profdata_file_arg}"
143-
puts "Against binary file: #{self.binary_file}\n\n"
144-
145-
146155
llvm_cov_args = %W(show -instr-profile #{profdata_file_arg} #{self.binary_file})
147156
`xcrun llvm-cov #{llvm_cov_args.shelljoin}`
148157
end
@@ -177,6 +186,11 @@ def configure
177186
configure_input_format
178187
configure_scheme
179188
configure_binary_file
189+
190+
if self.verbose_mode
191+
puts "\nProcessing coverage file: #{profdata_file}"
192+
puts "Against binary file: #{self.binary_file}\n\n"
193+
end
180194
end
181195

182196
def configure_build_directory
@@ -253,7 +267,7 @@ def coverage_service=(service)
253267

254268
def configure_binary_file
255269
if self.input_format == "profdata"
256-
self.binary_file ||= self.class.yml["binary_file"] || find_binary_file
270+
self.binary_file ||= self.class.yml["binary_file"] || File.expand_path(find_binary_file)
257271
end
258272
end
259273

0 commit comments

Comments
 (0)