Class: Xcodeproj::Project

Inherits:
Object
  • Object
show all
Defined in:
lib/slather/project.rb

Direct Known Subclasses

Slather::Project

Instance Method Summary collapse

Instance Method Details

#slather_setup_for_coverage(format = :auto) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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