Skip to content

Commit 2c43d91

Browse files
committed
[project] Refactor configuration steps
1 parent 6a16699 commit 2c43d91

10 files changed

+327
-294
lines changed

bin/slather

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Clamp do
4545
setup_scheme
4646
setup_binary_file
4747

48+
project.configure_from_yml
49+
4850
post
4951

5052
puts "Slathered"

lib/slather/project.rb

+33-39
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class Project < Xcodeproj::Project
5757

5858
def self.open(xcodeproj)
5959
proj = super
60-
proj.configure_from_yml
6160
proj.xcodeproj = xcodeproj
6261
proj
6362
end
@@ -67,10 +66,6 @@ def derived_data_path
6766
end
6867
private :derived_data_path
6968

70-
def build_directory
71-
@build_directory || derived_data_path
72-
end
73-
7469
def coverage_files
7570
if self.input_format == "profdata"
7671
profdata_coverage_files
@@ -118,27 +113,6 @@ def profdata_coverage_dir
118113
dir
119114
end
120115

121-
def find_binary_file
122-
xctest_bundle = Dir["#{profdata_coverage_dir}/**/*.xctest"].reject { |bundle|
123-
bundle.include? "-Runner.app/PlugIns/"
124-
}.first
125-
raise StandardError, "No product binary found in #{profdata_coverage_dir}. Are you sure your project is setup for generating coverage files? Try `slather setup your/project.xcodeproj`" unless xctest_bundle != nil
126-
127-
# Find the matching binary file
128-
xctest_bundle_file_directory = Pathname.new(xctest_bundle).dirname
129-
app_bundle = Dir["#{xctest_bundle_file_directory}/*.app"].first
130-
dynamic_lib_bundle = Dir["#{xctest_bundle_file_directory}/*.framework"].first
131-
132-
if app_bundle != nil
133-
find_binary_file_for_app(app_bundle)
134-
elsif dynamic_lib_bundle != nil
135-
find_binary_file_for_dynamic_lib(dynamic_lib_bundle)
136-
else
137-
find_binary_file_for_static_lib(xctest_bundle)
138-
end
139-
end
140-
private :find_binary_file
141-
142116
def find_binary_file_for_app(app_bundle_file)
143117
app_bundle_file_name_noext = Pathname.new(app_bundle_file).basename.to_s.gsub(".app", "")
144118
Dir["#{app_bundle_file}/**/#{app_bundle_file_name_noext}"].first
@@ -162,7 +136,7 @@ def unsafe_profdata_llvm_cov_output
162136
end
163137

164138
if self.binary_file == nil
165-
raise StandardError, "No binary file found. Please help slather by adding the \"scheme\" argument"
139+
raise StandardError, "No binary file found."
166140
end
167141

168142
puts "\nProcessing coverage file: #{profdata_file_arg}"
@@ -206,7 +180,7 @@ def configure_from_yml
206180
end
207181

208182
def configure_build_directory_from_yml
209-
self.build_directory = self.class.yml["build_directory"] if self.class.yml["build_directory"] && !@build_directory
183+
self.build_directory ||= self.class.yml["build_directory"] || derived_data_path
210184
end
211185

212186
def configure_source_directory_from_yml
@@ -226,7 +200,19 @@ def configure_ci_service_from_yml
226200
end
227201

228202
def configure_input_format_from_yml
229-
self.input_format ||= self.class.yml["input_format"] if self.class.yml["input_format"]
203+
self.input_format ||= self.class.yml["input_format"] || input_format
204+
end
205+
206+
def input_format=(format)
207+
format ||= "auto"
208+
unless %w(gcov profdata auto).include?(format)
209+
raise StandardError, "Only supported input formats are gcov, profdata or auto"
210+
end
211+
if format == "auto"
212+
@input_format = Slather.xcode_version[0] < 7 ? "gcov" : "profdata"
213+
else
214+
@input_format = format
215+
end
230216
end
231217

232218
def configure_scheme_from_yml
@@ -266,20 +252,28 @@ def coverage_service=(service)
266252
end
267253

268254
def configure_binary_file_from_yml
269-
if input_format == "profdata"
270-
self.binary_file = self.class.yml["binary_file"] ? self.class.yml["binary_file"] : find_binary_file
255+
if self.input_format == "profdata"
256+
self.binary_file ||= self.class.yml["binary_file"] || find_binary_file
271257
end
272258
end
273259

274-
def input_format=(format)
275-
format ||= "auto"
276-
unless %w(gcov profdata auto).include?(format)
277-
raise StandardError, "Only supported input formats are gcov, profdata or auto"
278-
end
279-
if format == "auto"
280-
@input_format = Slather.xcode_version[0] < 7 ? "gcov" : "profdata"
260+
def find_binary_file
261+
xctest_bundle = Dir["#{profdata_coverage_dir}/**/*.xctest"].reject { |bundle|
262+
bundle.include? "-Runner.app/PlugIns/"
263+
}.first
264+
raise StandardError, "No product binary found in #{profdata_coverage_dir}. Are you sure your project is setup for generating coverage files? Try `slather setup your/project.xcodeproj`" unless xctest_bundle != nil
265+
266+
# Find the matching binary file
267+
xctest_bundle_file_directory = Pathname.new(xctest_bundle).dirname
268+
app_bundle = Dir["#{xctest_bundle_file_directory}/*.app"].first
269+
dynamic_lib_bundle = Dir["#{xctest_bundle_file_directory}/*.framework"].first
270+
271+
if app_bundle != nil
272+
find_binary_file_for_app(app_bundle)
273+
elsif dynamic_lib_bundle != nil
274+
find_binary_file_for_dynamic_lib(dynamic_lib_bundle)
281275
else
282-
@input_format = format
276+
find_binary_file_for_static_lib(xctest_bundle)
283277
end
284278
end
285279

spec/slather/coverage_file_spec.rb

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
let(:fixtures_project) do
66
project = Slather::Project.open(FIXTURES_PROJECT_PATH)
77
project.build_directory = TEMP_DERIVED_DATA_PATH
8+
project.send(:configure_from_yml)
9+
project.stub(:input_format).and_return("gcov")
810
project
911
end
1012

spec/slather/coverage_service/cobertura_xml_spec.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
let(:fixtures_project) do
77
proj = Slather::Project.open(FIXTURES_PROJECT_PATH)
8-
proj.extend(Slather::CoverageService::CoberturaXmlOutput)
98
proj.build_directory = TEMP_DERIVED_DATA_PATH
9+
proj.input_format = "gcov"
10+
proj.coverage_service = "cobertura_xml"
11+
proj.configure_from_yml
1012
proj
1113
end
1214

0 commit comments

Comments
 (0)