blob: e0de56bb983d6d31973182c5fbd36b252de5b55a [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001# Copyright (C) 2018 Khem Raj <raj.khem@gmail.com>
2# Released under the MIT license (see COPYING.MIT for the terms)
3
4CFLAGS =+ "${TARGET_CC_ARCH} ${TOOLCHAIN_OPTIONS}"
5CXXFLAGS =+ "${TARGET_CC_ARCH} ${TOOLCHAIN_OPTIONS}"
6
7#EXTRA_ANALYZER_OPTIONS ?= "-analyze-headers"
8CLANG_SCAN_ENABLED ??= "1"
9#CLANG_SCAN_SERVER_IP ??= "127.0.0.1"
10CLANG_SCAN_SERVER_IP ??= "10.0.0.10"
11CLANG_SCAN_PORT ??= "8181"
12SCAN_RESULTS_DIR ?= "${TMPDIR}/static-scan/${PN}"
13
14scanbuild_munge_cc_cxx() {
15 cc="`echo ${CC} | cut -f1 -d " "`"
16 cxx="`echo ${CXX} | cut -f1 -d " "`"
17 export CC="${cc}"
18 export CXX="${cxx}"
19}
20
21do_configure[prefuncs] += "scanbuild_munge_cc_cxx"
22
23do_scanbuild() {
24 cc="`echo ${CC} | cut -f1 -d " "`"
25 cxx="`echo ${CXX} | cut -f1 -d " "`"
26 #mk="scan-build --use-cc=${cc} --use-c++=${cxx} --analyzer-target=${HOST_SYS} --html-title="${BP}" -o ${SCAN_RESULTS_DIR} ${EXTRA_ANALYZER_OPTIONS} make"
27 #export MAKE="${mk}"
28 export CC="${cc}"
29 export CXX="${cxx}"
30 scan-build --use-cc=${cc} --use-c++=${cxx} --analyzer-target=${HOST_SYS} --html-title="${BP}" -o ${SCAN_RESULTS_DIR} ${EXTRA_ANALYZER_OPTIONS} ${MAKE} ${EXTRA_OEMAKE}
31}
32
33do_scanview() {
34 bbplain "================================================================"
35 bbplain "Stating scan-view server at: http://${CLANG_SCAN_SERVER_IP}:${CLANG_SCAN_PORT}"
36 bbplain "Use Ctrl-C to exit"
37 bbplain "================================================================"
38 scan-view --host ${CLANG_SCAN_SERVER_IP} --port ${CLANG_SCAN_PORT} --allow-all-hosts ${SCAN_RESULTS_DIR}/*/
39}
40
41do_scanview[depends] += "${PN}:do_scanbuild"
42do_scanbuild[cleandirs] += "${SCAN_RESULTS_DIR}"
43do_scanbuild[dirs] += "${B}"
44do_scanview[dirs] += "${SCAN_RESULTS_DIR}"
45#do_build[recrdeptask] += "do_scanbuild"
46
47do_scanbuild[doc] = "Build and scan static analysis data using clang"
48do_scanview[doc] = "Start a webserver to visualize static analysis data"
49
50addtask scanbuild after do_configure before do_compile
51addtask scanview
52
53python () {
54 # Remove scanbuild task when scanning is not enabled
55 if not(d.getVar('CLANG_SCAN_ENABLED') == "1"):
56 for i in ['do_scanbuild', 'do_scanview']:
57 bb.build.deltask(i, d)
58}