Skip to content

Commit 9289c96

Browse files
committed
Introducing coverage format auto-detection based on Xcode version
* Change "--input-format" option of "slather setup" to "--format", more appropriate name in the context of setup * Supporting auto for `slather setup --format` and `slather coverage --input-format` which will use profdata if Xcode 7, gcov if earlier * Checking the validity of the parameters given to `--format` / `--input-format`
1 parent 8b7a535 commit 9289c96

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

bin/slather

+2-3
Original file line numberDiff line numberDiff line change
@@ -120,16 +120,15 @@ Clamp do
120120

121121
parameter "[xcodeproj]", "Path to the xcodeproj", :attribute_name => :xcodeproj_path
122122

123-
option ["--input-format"], "INPUT_FORMAT", "Input format (gcov, profdata)"
123+
option ["--format"], "FORMAT", "Type of coverage to use (gcov, clang, auto)"
124124

125125
def execute
126126
xcodeproj_path_to_open = xcodeproj_path || Slather::Project.yml["xcodeproj"]
127127
unless xcodeproj_path_to_open
128128
raise StandardError, "Must provide an xcodeproj through .slather.yml"
129129
end
130130
project = Slather::Project.open(xcodeproj_path_to_open)
131-
project.input_format = input_format
132-
project.setup_for_coverage
131+
project.setup_for_coverage(format ? format.to_sym : :auto)
133132
project.save
134133
end
135134

lib/slather.rb

+6
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ def self.prepare_pods(pods)
1919
Pod::UI.warn("[Slather] prepare_pods is now deprecated. The call to prepare_pods in your Podfile can simply be ommitted.")
2020
end
2121

22+
def self.xcode_version
23+
xcode_path = `xcode-select -p`.strip
24+
xcode_version = `mdls -name kMDItemVersion -raw #{xcode_path.shellescape}/../..`.strip
25+
xcode_version.split('.').map(&:to_i)
26+
end
27+
2228
end

lib/slather/project.rb

+25-7
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,28 @@
55
require 'shellwords'
66

77
module Xcodeproj
8+
89
class Project
910

10-
def slather_setup_for_coverage(input_format = "gcov")
11+
def slather_setup_for_coverage(format = :auto)
12+
unless [:gcov, :clang, :auto].include?(format)
13+
raise StandardError, "Only supported formats for setup are gcov, clang or auto"
14+
end
15+
if format == :auto
16+
format = Slather.xcode_version[0] < 7 ? :gcov : :clang
17+
end
18+
1119
build_configurations.each do |build_configuration|
12-
build_configuration.build_settings["GCC_INSTRUMENT_PROGRAM_FLOW_ARCS"] = "YES"
13-
if input_format == "profdata"
20+
if format == :clang
1421
build_configuration.build_settings["CLANG_ENABLE_CODE_COVERAGE"] = "YES"
1522
else
23+
build_configuration.build_settings["GCC_INSTRUMENT_PROGRAM_FLOW_ARCS"] = "YES"
1624
build_configuration.build_settings["GCC_GENERATE_TEST_COVERAGE_FILES"] = "YES"
1725
end
1826
end
1927

2028
# Patch xcschemes too
21-
if input_format == "profdata"
29+
if format == :clang
2230
if Gem::Requirement.new('~> 0.27') =~ Gem::Version.new(Xcodeproj::VERSION)
2331
# @todo This will require to bump the xcodeproj dependency to ~> 0.27
2432
# (which would require to bump cocoapods too)
@@ -44,9 +52,7 @@ class Project < Xcodeproj::Project
4452

4553
attr_accessor :build_directory, :ignore_list, :ci_service, :coverage_service, :coverage_access_token, :source_directory, :output_directory, :xcodeproj, :show_html, :input_format, :scheme
4654

47-
def setup_for_coverage
48-
slather_setup_for_coverage(self.input_format)
49-
end
55+
alias_method :setup_for_coverage, :slather_setup_for_coverage
5056

5157
def self.open(xcodeproj)
5258
proj = super
@@ -226,5 +232,17 @@ def coverage_service=(service)
226232
end
227233
@coverage_service = service
228234
end
235+
236+
def input_format=(format)
237+
format ||= "auto"
238+
unless %w(gcov profdata auto).include?(format)
239+
raise StandardError, "Only supported input formats are gcov, profdata or auto"
240+
end
241+
if format == "auto"
242+
@input_format = Slather.xcode_version[0] < 7 ? "gcov" : "profdata"
243+
else
244+
@input_format = format
245+
end
246+
end
229247
end
230248
end

0 commit comments

Comments
 (0)