Skip to content

Commit

Permalink
Merge pull request #1 from AliSoftware/feature-profdata
Browse files Browse the repository at this point in the history
Fixes for your profdata support
  • Loading branch information
Matt Delves committed Sep 22, 2015
2 parents 8aa1c12 + b8997fe commit 510b60c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
require "bundler/gem_tasks"

desc 'Execute tests'
task :spec do
sh 'bundle exec rspec spec'
end

10 changes: 8 additions & 2 deletions bin/slather
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,15 @@ Clamp do

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

option ["--format"], "FORMAT", "Type of coverage to use (gcov, clang, auto)"

def execute
project = Slather::Project.open(xcodeproj_path)
project.setup_for_coverage
xcodeproj_path_to_open = xcodeproj_path || Slather::Project.yml["xcodeproj"]
unless xcodeproj_path_to_open
raise StandardError, "Must provide an xcodeproj through .slather.yml"
end
project = Slather::Project.open(xcodeproj_path_to_open)
project.setup_for_coverage(format ? format.to_sym : :auto)
project.save
end

Expand Down
6 changes: 6 additions & 0 deletions lib/slather.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ def self.prepare_pods(pods)
Pod::UI.warn("[Slather] prepare_pods is now deprecated. The call to prepare_pods in your Podfile can simply be ommitted.")
end

def self.xcode_version
xcode_path = `xcode-select -p`.strip
xcode_version = `mdls -name kMDItemVersion -raw #{xcode_path.shellescape}/../..`.strip
xcode_version.split('.').map(&:to_i)
end

end
54 changes: 48 additions & 6 deletions lib/slather/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,45 @@
require 'xcodeproj'
require 'json'
require 'yaml'
require 'shellwords'

module Xcodeproj

class Project

def slather_setup_for_coverage
def slather_setup_for_coverage(format = :auto)
unless [:gcov, :clang, :auto].include?(format)
raise StandardError, "Only supported formats for setup are gcov, clang or auto"
end
if format == :auto
format = Slather.xcode_version[0] < 7 ? :gcov : :clang
end

build_configurations.each do |build_configuration|
build_configuration.build_settings["GCC_INSTRUMENT_PROGRAM_FLOW_ARCS"] = "YES"
build_configuration.build_settings["GCC_GENERATE_TEST_COVERAGE_FILES"] = "YES"
if format == :clang
build_configuration.build_settings["CLANG_ENABLE_CODE_COVERAGE"] = "YES"
else
build_configuration.build_settings["GCC_INSTRUMENT_PROGRAM_FLOW_ARCS"] = "YES"
build_configuration.build_settings["GCC_GENERATE_TEST_COVERAGE_FILES"] = "YES"
end
end

# Patch xcschemes too
if format == :clang
if Gem::Requirement.new('~> 0.27') =~ Gem::Version.new(Xcodeproj::VERSION)
# @todo This will require to bump the xcodeproj dependency to ~> 0.27
# (which would require to bump cocoapods too)
schemes_path = Xcodeproj::XCScheme.shared_data_dir(self.path)
Xcodeproj::Project.schemes(self.path).each do |scheme_name|
xcscheme_path = "#{schemes_path + scheme_name}.xcscheme"
xcscheme = Xcodeproj::XCScheme.new(xcscheme_path)
xcscheme.test_action.xml_element.attributes['codeCoverageEnabled'] = 'YES'
xcscheme.save_as(self.path, scheme_name)
end
else
# @todo In the meantime, simply inform the user to do it manually
puts %Q(Ensure you enabled "Gather coverage data" in each of your scheme's Test action)
end
end
end

Expand Down Expand Up @@ -110,9 +141,8 @@ def profdata_llvm_cov_output
if profdata_coverage_dir == nil || (coverage_profdata = Dir["#{profdata_coverage_dir}/**/Coverage.profdata"].first) == 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
xcode_path = `xcode-select -p`.strip
llvm_cov_command = File.join(xcode_path, "Toolchains/XcodeDefault.xctoolchain/usr/bin/llvm-cov show -instr-profile #{coverage_profdata} #{binary_file}")
`#{llvm_cov_command}`
llvm_cov_args = %W(show -instr-profile #{coverage_profdata} #{binary_file})
`xcrun llvm-cov #{llvm_cov_args.shelljoin}`
end
private :profdata_llvm_cov_output

Expand Down Expand Up @@ -200,5 +230,17 @@ def coverage_service=(service)
end
@coverage_service = service
end

def input_format=(format)
format ||= "auto"
unless %w(gcov profdata auto).include?(format)
raise StandardError, "Only supported input formats are gcov, profdata or auto"
end
if format == "auto"
@input_format = Slather.xcode_version[0] < 7 ? "gcov" : "profdata"
else
@input_format = format
end
end
end
end

0 comments on commit 510b60c

Please sign in to comment.