class Xcodeproj::Project

Public Instance Methods

slather_setup_for_coverage(format = :auto) click to toggle source
# File lib/slather/project.rb, line 11
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|
    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
    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
  end
end