Added support for coverage.

pull/15/head
Jussi Pakkanen 12 years ago
parent 9418ece26a
commit f7d7888b70
  1. 28
      environment.py
  2. 33
      generators.py
  3. 2
      meson.py

@ -53,6 +53,12 @@ class CCompiler():
def get_debug_flags(self):
return ['-g']
def get_coverage_flags(self):
return ['--coverage']
def get_coverage_link_flags(self):
return ['-lgcov']
def get_std_exe_link_flags(self):
return []
@ -195,6 +201,28 @@ class ArLinker():
def get_output_flags(self):
return []
def get_coverage_link_flags(self):
return []
def find_coverage_tools():
gcovr_exe = 'gcovr'
lcov_exe = 'lcov'
genhtml_exe = 'genhtml'
pg = subprocess.Popen([gcovr_exe, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
pg.communicate()
if pg.returncode != 0:
gcovr_exe = None
pl = subprocess.Popen([lcov_exe, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
pl.communicate()
if pl.returncode != 0:
lcov_exe = None
ph = subprocess.Popen([genhtml_exe, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
ph.communicate()
if ph.returncode != 0:
genhtml_exe = None
return (gcovr_exe, lcov_exe, genhtml_exe)
header_suffixes = ['h', 'hh', 'hpp', 'hxx', 'H']
class Environment():

@ -16,6 +16,7 @@
import os, stat, re, pickle
import interpreter, nodes
import environment
from builder_install import InstallData
def shell_quote(cmdlist):
@ -126,6 +127,8 @@ class Generator():
commands += compiler.get_debug_flags()
if self.environment.options.buildtype == 'optimized':
commands += compiler.get_std_opt_flags()
if self.environment.options.coverage:
commands += compiler.get_coverage_flags()
commands += compiler.get_std_warn_flags()
if isinstance(target, interpreter.SharedLibrary):
commands += compiler.get_pic_flags()
@ -174,9 +177,37 @@ class NinjaGenerator(Generator):
self.generate_tests(outfile)
outfile.write('# Install rules\n\n')
self.generate_install(outfile)
if self.environment.options.coverage:
outfile.write('# Coverage rules\n\n')
self.generate_coverage_rules(outfile)
outfile.write('# Suffix\n\n')
self.generate_ending(outfile)
def generate_coverage_rules(self, outfile):
(gcovr_exe, lcov_exe, genhtml_exe) = environment.find_coverage_tools()
if gcovr_exe:
xmlbuild = 'build coverage-xml: CUSTOM_COMMAND\n\n'
xmlcommand = " COMMAND = '%s' -x -r '%s' -o coverage.xml\n\n" %\
(ninja_quote(gcovr_exe), ninja_quote(self.environment.get_build_dir()))
outfile.write(xmlbuild)
outfile.write(xmlcommand)
textbuild = 'build coverage-text: CUSTOM_COMMAND\n'
textcommand = " COMMAND = '%s' -r '%s' -o coverage.txt\n\n" %\
(ninja_quote(gcovr_exe), ninja_quote(self.environment.get_build_dir()))
outfile.write(textbuild)
outfile.write(textcommand)
if lcov_exe and genhtml_exe:
phony = 'build coverage-html: phony coveragereport/index.html\n'
htmlbuild = 'build coveragereport/index.html: CUSTOM_COMMAND\n'
lcov_command = "'%s' --directory '%s' --capture --output-file coverage.info --no-checksum" %\
(ninja_quote(lcov_exe), ninja_quote(self.environment.get_build_dir()))
genhtml_command = "'%s' --prefix='%s' --output-directory coveragereport --title='Code coverage' --legend --show-details coverage.info" %\
(ninja_quote(genhtml_exe), ninja_quote(self.environment.get_build_dir()))
command = ' COMMAND = %s && %s\n\n' % (lcov_command, genhtml_command)
outfile.write(phony)
outfile.write(htmlbuild)
outfile.write(command)
def generate_install(self, outfile):
script_root = self.get_script_root()
install_script = os.path.join(script_root, 'builder_install.py')
@ -394,6 +425,8 @@ class NinjaGenerator(Generator):
commands += dep.get_link_flags()
dependencies = target.get_dependencies()
commands += self.build_target_link_arguments(dependencies)
if self.environment.options.coverage:
commands += linker.get_coverage_link_flags()
if len(dependencies) == 0:
dep_targets = ''
else:

@ -48,6 +48,8 @@ parser.add_option('--buildtype', default='debug', type='choice', choices=build_t
help=buildtype_help)
parser.add_option('--strip', action='store_true', dest='strip', default=False,\
help='strip targets on install (default: %default)')
parser.add_option('--enable-gcov', action='store_true', dest='coverage', default=False,\
help='measure test coverage')
class BuilderApp():

Loading…
Cancel
Save