Class: Fastlane::Actions::LcovAction

Inherits:
Fastlane::Action show all
Defined in:
lib/fastlane/actions/lcov.rb

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, details, output, return_value, sh, step_text

Class Method Details

.authorObject



45
46
47
# File 'lib/fastlane/actions/lcov.rb', line 45

def self.author
  "thiagolioy"
end

.available_optionsObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fastlane/actions/lcov.rb', line 20

def self.available_options
  [

    FastlaneCore::ConfigItem.new(key: :project_name,
                                 env_name: "FL_LCOV_PROJECT_NAME",
                                 description: "Name of the project"),

    FastlaneCore::ConfigItem.new(key: :scheme,
                                 env_name: "FL_LCOV_SCHEME",
                                 description: "Scheme of the project"),

    FastlaneCore::ConfigItem.new(key: :arch,
                                 env_name: "FL_LCOV_ARCH",
                                 description: "The build arch where will search .gcda files",
                                 default_value: "i386"),

    FastlaneCore::ConfigItem.new(key: :output_dir,
                                 env_name: "FL_LCOV_OUTPUT_DIR",
                                 description: "The output directory that coverage data will be stored. If not passed will use coverage_reports as default value",
                                 optional: true,
                                 is_string: true,
                                 default_value: "coverage_reports")
  ]
end

.derived_data_dir(options) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/fastlane/actions/lcov.rb', line 67

def self.derived_data_dir(options)
  pn = options[:project_name]
  sc = options[:scheme]
  arch = options[:arch]

  initial_path = "#{Dir.home}/Library/Developer/Xcode/DerivedData/"
  end_path = "/Build/Intermediates/#{pn}.build/Debug-iphonesimulator/#{sc}.build/Objects-normal/#{arch}/"

  match = find_project_dir(pn, initial_path)

  "#{initial_path}#{match}#{end_path}"
end

.descriptionObject



16
17
18
# File 'lib/fastlane/actions/lcov.rb', line 16

def self.description
  "Generates coverage data using lcov"
end

.exclude_dirsObject



84
85
86
# File 'lib/fastlane/actions/lcov.rb', line 84

def self.exclude_dirs
  ["/Applications/*", "/Frameworks/*"]
end

.find_project_dir(project_name, path) ⇒ Object



80
81
82
# File 'lib/fastlane/actions/lcov.rb', line 80

def self.find_project_dir(project_name, path)
  `ls -t #{path}| grep #{project_name} | head -1`.to_s.gsub(/\n/, "")
end

.gen_cov(options) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/fastlane/actions/lcov.rb', line 49

def self.gen_cov(options)
  tmp_cov_file = "/tmp/coverage.info"
  output_dir = options[:output_dir]
  derived_data_path = derived_data_dir(options)

  system("lcov --capture --directory \"#{derived_data_path}\" --output-file #{tmp_cov_file}")
  system(gen_lcov_cmd(tmp_cov_file))
  system("genhtml #{tmp_cov_file} --output-directory #{output_dir}")
end

.gen_lcov_cmd(cov_file) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/fastlane/actions/lcov.rb', line 59

def self.gen_lcov_cmd(cov_file)
  cmd = "lcov "
  exclude_dirs.each do |e|
    cmd << "--remove #{cov_file} \"#{e}\" "
  end
  cmd << "--output #{cov_file} "
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/fastlane/actions/lcov.rb', line 5

def self.is_supported?(platform)
  [:ios, :mac].include? platform
end

.run(options) ⇒ Object



9
10
11
12
13
14
# File 'lib/fastlane/actions/lcov.rb', line 9

def self.run(options)
  unless Helper.test?
    raise 'lcov not installed, please install using `brew install lcov`'.red if `which lcov`.length == 0
  end
  gen_cov(options)
end