mirror of https://github.com/ARMmbed/mbed-os.git
Added cppcheck support for libraries
parent
9aaf2c1220
commit
f930af5ffc
|
|
@ -31,7 +31,7 @@ from workspace_tools.targets import TARGET_NAMES, TARGET_MAP
|
|||
from workspace_tools.options import get_default_options_parser
|
||||
from workspace_tools.build_api import build_mbed_libs, build_lib
|
||||
from workspace_tools.build_api import mcu_toolchain_matrix
|
||||
from workspace_tools.build_api import static_analysis_scan
|
||||
from workspace_tools.build_api import static_analysis_scan, static_analysis_scan_lib, static_analysis_scan_library
|
||||
from workspace_tools.settings import CPPCHECK_CMD, CPPCHECK_MSG_FORMAT
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
@ -109,6 +109,8 @@ if __name__ == '__main__':
|
|||
if options.ublox:
|
||||
libraries.extend(["rtx", "rtos", "usb_host", "ublox"])
|
||||
|
||||
notify = print_notify_verbose if options.extra_verbose_notify else None # Special notify for CI (more verbose)
|
||||
|
||||
# Build results
|
||||
failures = []
|
||||
successes = []
|
||||
|
|
@ -123,6 +125,10 @@ if __name__ == '__main__':
|
|||
static_analysis_scan(mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, verbose=options.verbose)
|
||||
for lib_id in libraries:
|
||||
# Static check for library
|
||||
static_analysis_scan_lib(lib_id, mcu, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT,
|
||||
options=options.options,
|
||||
notify=notify, verbose=options.verbose, clean=options.clean,
|
||||
macros=options.macros)
|
||||
pass
|
||||
except Exception, e:
|
||||
if options.verbose:
|
||||
|
|
@ -130,14 +136,13 @@ if __name__ == '__main__':
|
|||
traceback.print_exc(file=sys.stdout)
|
||||
sys.exit(1)
|
||||
print e
|
||||
else:
|
||||
else:
|
||||
# Build
|
||||
for toolchain in toolchains:
|
||||
for target in targets:
|
||||
tt_id = "%s::%s" % (toolchain, target)
|
||||
try:
|
||||
mcu = TARGET_MAP[target]
|
||||
notify = print_notify_verbose if options.extra_verbose_notify else None # Special notify for CI (more verbose)
|
||||
build_mbed_libs(mcu, toolchain, options=options.options,
|
||||
notify=notify, verbose=options.verbose, clean=options.clean,
|
||||
macros=options.macros)
|
||||
|
|
|
|||
|
|
@ -335,3 +335,79 @@ def static_analysis_scan(target, toolchain_name, CPPCHECK_CMD, CPPCHECK_MSG_FORM
|
|||
if verbose:
|
||||
print stdout
|
||||
print stderr
|
||||
|
||||
|
||||
def static_analysis_scan_lib(lib_id, target, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT, options=None, verbose=False, clean=False, macros=None, notify=None):
|
||||
lib = Library(lib_id)
|
||||
if lib.is_supported(target, toolchain):
|
||||
static_analysis_scan_library(lib.source_dir, lib.build_dir, target, toolchain, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT,
|
||||
lib.dependencies, options,
|
||||
verbose=verbose, clean=clean, macros=macros, notify=notify)
|
||||
else:
|
||||
print 'Library "%s" is not yet supported on target %s with toolchain %s' % (lib_id, target.name, toolchain)
|
||||
|
||||
|
||||
def static_analysis_scan_library(src_paths, build_path, target, toolchain_name, CPPCHECK_CMD, CPPCHECK_MSG_FORMAT,
|
||||
dependencies_paths=None, options=None, name=None, clean=False,
|
||||
notify=None, verbose=False, macros=None):
|
||||
if type(src_paths) != ListType: src_paths = [src_paths]
|
||||
|
||||
for src_path in src_paths:
|
||||
if not exists(src_path):
|
||||
raise Exception("The library source folder does not exist: %s", src_path)
|
||||
|
||||
|
||||
# Toolchain instance
|
||||
toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros, notify=notify)
|
||||
toolchain.VERBOSE = verbose
|
||||
|
||||
# The first path will give the name to the library
|
||||
name = basename(src_paths[0])
|
||||
toolchain.info(">>> STATIC ANALYSIS FOR LIBRARY %s (%s, %s)" % (name.upper(), target.name, toolchain_name))
|
||||
|
||||
# Scan Resources
|
||||
resources = []
|
||||
for src_path in src_paths:
|
||||
resources.append(toolchain.scan_resources(src_path))
|
||||
|
||||
# Dependencies Include Paths
|
||||
dependencies_include_dir = []
|
||||
if dependencies_paths is not None:
|
||||
for path in dependencies_paths:
|
||||
lib_resources = toolchain.scan_resources(path)
|
||||
dependencies_include_dir.extend(lib_resources.inc_dirs)
|
||||
|
||||
# Create the desired build directory structure
|
||||
bin_path = join(build_path, toolchain.obj_path)
|
||||
mkdir(bin_path)
|
||||
tmp_path = join(build_path, '.temp', toolchain.obj_path)
|
||||
mkdir(tmp_path)
|
||||
|
||||
# Gather include paths, c, cpp sources and macros to transfer to cppcheck command line
|
||||
includes = ["-I%s " % i for i in dependencies_include_dir + src_paths]
|
||||
c_sources = " "
|
||||
cpp_sources = " "
|
||||
macros = ['-D%s ' % s for s in toolchain.get_symbols() + toolchain.macros]
|
||||
|
||||
# Copy Headers
|
||||
for resource in resources:
|
||||
toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path)
|
||||
includes += ["-I%s " % i for i in resource.inc_dirs]
|
||||
c_sources += " ".join(resource.c_sources) + " "
|
||||
cpp_sources += " ".join(resource.cpp_sources) + " "
|
||||
|
||||
dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs)
|
||||
|
||||
check_cmd = " ".join(CPPCHECK_CMD) + " "
|
||||
check_cmd += " ".join(CPPCHECK_MSG_FORMAT) + " "
|
||||
check_cmd += " ".join(includes)
|
||||
check_cmd += " ".join(macros)
|
||||
check_cmd += " " + c_sources
|
||||
check_cmd += " " + cpp_sources
|
||||
|
||||
#['cppcheck', includes, c_sources, cpp_sources]
|
||||
stdout, stderr, rc = run_cmd(check_cmd)
|
||||
|
||||
if verbose:
|
||||
print stdout
|
||||
print stderr
|
||||
|
|
|
|||
Loading…
Reference in New Issue