diff --git a/Tools/ardupilotwaf/boards.py b/Tools/ardupilotwaf/boards.py index 7ef8e1e51e4..25d7b020767 100644 --- a/Tools/ardupilotwaf/boards.py +++ b/Tools/ardupilotwaf/boards.py @@ -248,6 +248,24 @@ class Board: return (int(major) < want_major or (int(major) == want_major and int(minor) <= want_minor)) + def configure_coverage(self, cfg): + """Apply the coverage flags. + + Called after the configure checks have run, rather than from + configure_env: cfg.check() links small probe programs, and + instrumenting those drags in libgcov, whose malloc call + -Wl,--wrap,malloc rewrites into an undefined __wrap_malloc. The + probe then fails to link and waf records the feature it was + probing for as missing. + """ + if not cfg.env.COVERAGE: + return + cfg.env.CFLAGS += ['-fprofile-arcs', '-ftest-coverage'] + cfg.env.CXXFLAGS += ['-fprofile-arcs', '-ftest-coverage'] + cfg.env.LINKFLAGS += ['-lgcov', '-coverage'] + # cfg.env is post-merge, where DEFINES is a list of NAME=value + cfg.env.DEFINES += ['HAL_COVERAGE_BUILD=1'] + def configure_env(self, cfg, env): # Use a dictionary instead of the conventional list for definitions to # make easy to override them. Convert back to list before consumption. @@ -342,23 +360,6 @@ class Board: env.CFLAGS += [ '-g', ] - if cfg.env.COVERAGE: - env.CFLAGS += [ - '-fprofile-arcs', - '-ftest-coverage', - ] - env.CXXFLAGS += [ - '-fprofile-arcs', - '-ftest-coverage', - ] - env.LINKFLAGS += [ - '-lgcov', - '-coverage', - ] - env.DEFINES.update( - HAL_COVERAGE_BUILD = 1, - ) - if cfg.options.bootloader: # don't let bootloaders try and pull scripting in cfg.options.disable_scripting = True diff --git a/wscript b/wscript index fdefe1073b2..f4201de9eef 100644 --- a/wscript +++ b/wscript @@ -628,6 +628,7 @@ def configure(cfg): else: cfg.end_msg('disabled', color='YELLOW') + cfg.get_board().configure_coverage(cfg) cfg.start_msg('Coverage build') if cfg.env.COVERAGE: cfg.end_msg('enabled')