Skip to content

Commit

Permalink
Support pods
Browse files Browse the repository at this point in the history
  • Loading branch information
marklarr committed Jun 26, 2014
1 parent f3e6921 commit 475d471
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
6 changes: 6 additions & 0 deletions bin/slather
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Clamp do
option ["--simple-output", "-s"], :flag, "Post coverage results to coveralls"

option ["--build-directory", "-b"], "BUILD_DIRECTORY", "The directory where gcno files will be written to. Defaults to derived data."
option ["--source-directory"], "SOURCE_DIRECTORY", "The directory where your source files are located."
option ["--ignore", "-i"], "IGNORE", "ignore files conforming to a path", :multivalued => true

def execute
Expand All @@ -25,6 +26,7 @@ Clamp do
setup_service_name
setup_ignore_list
setup_build_directory
setup_source_directory
setup_coverage_service

post
Expand All @@ -36,6 +38,10 @@ Clamp do
project.build_directory = build_directory if build_directory
end

def setup_source_directory
project.source_directory = source_directory if source_directory
end

def setup_ignore_list
project.ignore_list = ignore_list if !ignore_list.empty?
end
Expand Down
6 changes: 6 additions & 0 deletions lib/slather.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@ module Slather

Encoding.default_external = "utf-8"

def self.prepare_pods(pods)
pods.post_install do |installer|
installer.project.slather_setup_for_coverage
end
end

end
13 changes: 10 additions & 3 deletions lib/slather/coverage_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,15 @@ def source_file_pathname
@source_file_pathname ||= begin
base_filename = gcno_file_pathname.basename.sub_ext("")
# TODO: Handle Swift
pbx_file = project.files.detect { |pbx_file| pbx_file.real_path.basename.to_s == "#{base_filename}.m" }
pbx_file && pbx_file.real_path
path = nil
if project.source_directory
path = Dir["#{project.source_directory}/**/#{base_filename}.m"].first
path &&= Pathname(path)
else
pbx_file = project.files.detect { |pbx_file| pbx_file.real_path.basename.to_s == "#{base_filename}.m" }
path = pbx_file && pbx_file.real_path
end
path
end
end

Expand All @@ -26,7 +33,7 @@ def source_data
end

def source_file_pathname_relative_to_repo_root
source_file_pathname.relative_path_from(Pathname("./").realpath)
source_file_pathname.realpath.relative_path_from(Pathname("./").realpath)
end

def gcov_data
Expand Down
29 changes: 21 additions & 8 deletions lib/slather/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@
require 'json'
require 'yaml'

module Xcodeproj
class Project

def slather_setup_for_coverage
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"
end
end

end
end

module Slather
class Project < Xcodeproj::Project

attr_accessor :build_directory, :ignore_list, :ci_service, :coverage_service
attr_accessor :build_directory, :ignore_list, :ci_service, :coverage_service, :source_directory

alias_method :setup_for_coverage, :slather_setup_for_coverage

def self.open(xcodeproj)
proj = super
Expand Down Expand Up @@ -51,12 +66,17 @@ def configure_from_yml
configure_ignore_list_from_yml
configure_ci_service_from_yml
configure_coverage_service_from_yml
configure_source_directory_from_yml
end

def configure_build_directory_from_yml
self.build_directory = self.class.yml["build_directory"] if self.class.yml["build_directory"] && !@build_directory
end

def configure_source_directory_from_yml
self.source_directory ||= self.class.yml["source_directory"] if self.class.yml["source_directory"]
end

def configure_ignore_list_from_yml
self.ignore_list ||= [(self.class.yml["ignore"] || [])].flatten
end
Expand Down Expand Up @@ -85,13 +105,6 @@ def coverage_service=(service)
@coverage_service = service
end

def setup_for_coverage
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"
end
end

end
end

0 comments on commit 475d471

Please sign in to comment.