Skip to content

Commit

Permalink
waf: added --enable-new-checking option
Browse files Browse the repository at this point in the history
this allows CI to check for violations of new, calling without
NEW_NOTHROW
  • Loading branch information
tridge committed Jun 1, 2024
1 parent 00aa0b0 commit b47ecfb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
30 changes: 23 additions & 7 deletions Tools/ardupilotwaf/boards.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import sys, os
import fnmatch
import platform

import waflib
from waflib import Utils
Expand Down Expand Up @@ -45,8 +46,8 @@ def configure(self, cfg):
cfg.load('toolchain')
cfg.load('cxx_checks')

# check elf symbols by default
cfg.env.CHECK_SYMBOLS = True
# don't check elf symbols by default
cfg.env.CHECK_SYMBOLS = False

env = waflib.ConfigSet.ConfigSet()
def srcpath(path):
Expand Down Expand Up @@ -751,6 +752,11 @@ def configure_env(self, cfg, env):
'SITL',
]

# wrap malloc to ensure memory is zeroed
# don't do this on MacOS as ld doesn't support --wrap
if platform.system() != 'Darwin':
env.LINKFLAGS += ['-Wl,--wrap,malloc']

if cfg.options.enable_sfml:
if not cfg.check_SFML(env):
cfg.fatal("Failed to find SFML libraries")
Expand Down Expand Up @@ -794,8 +800,6 @@ def configure_env(self, cfg, env):

if Utils.unversioned_sys_platform() == 'cygwin':
env.CXXFLAGS += ['-DCYGWIN_BUILD']
# can't do symbol checking on cygwin due to exception usage in system libraries
env.CHECK_SYMBOLS = False

if 'clang++' in cfg.env.COMPILER_CXX:
print("Disabling SLP for clang++")
Expand Down Expand Up @@ -1007,6 +1011,8 @@ def expand_path(p):
env.CXXFLAGS.remove('-Werror=undef')
env.CXXFLAGS.remove('-Werror=shadow')

# wrap malloc to ensure memory is zeroed
env.LINKFLAGS += ['-Wl,--wrap,malloc']

env.INCLUDES += [
cfg.srcnode.find_dir('libraries/AP_HAL_ESP32/boards').abspath(),
Expand Down Expand Up @@ -1260,6 +1266,16 @@ def configure_env(self, cfg, env):
cfg.msg("Checking for intelhex module:", 'disabled', color='YELLOW')
env.HAVE_INTEL_HEX = False

if cfg.options.enable_new_checking:
env.CHECK_SYMBOLS = True
else:
# disable new checking on ChibiOS by default to save flash
# we enable it in a CI test to catch incorrect usage
env.CXXFLAGS += [
"-DNEW_NOTHROW=new",
"-fcheck-new", # rely on -fcheck-new ensuring nullptr checks
]

def build(self, bld):
super(chibios, self).build(bld)
bld.ap_version_append_str('CHIBIOS_GIT_VERSION', bld.git_submodule_head_hash('ChibiOS', short=True))
Expand Down Expand Up @@ -1289,9 +1305,6 @@ def configure_env(self, cfg, env):
self.with_can = True
super(linux, self).configure_env(cfg, env)

# can't do symbol checking on Linux due to exception usage in libc++
env.CHECK_SYMBOLS = False

env.BOARD_CLASS = "LINUX"

env.DEFINES.update(
Expand Down Expand Up @@ -1319,6 +1332,9 @@ def configure_env(self, cfg, env):
'AP_HAL_Linux',
]

# wrap malloc to ensure memory is zeroed
env.LINKFLAGS += ['-Wl,--wrap,malloc']

if cfg.options.force_32bit:
env.DEFINES.update(
HAL_FORCE_32BIT = 1,
Expand Down
5 changes: 5 additions & 0 deletions wscript
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,11 @@ configuration in order to save typing.
type='int',
default=0,
help='zero time on boot in microseconds')

g.add_option('--enable-new-checking',
action='store_true',
default=False,
help='enables checking of new to ensure NEW_NOTHROW is used')

def _collect_autoconfig_files(cfg):
for m in sys.modules.values():
Expand Down

0 comments on commit b47ecfb

Please sign in to comment.