rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | # Copyright (C) 2018 Khem Raj <raj.khem@gmail.com> |
| 2 | # Released under the MIT license (see COPYING.MIT for the terms) |
| 3 | |
| 4 | CFLAGS =+ "${TARGET_CC_ARCH} ${TOOLCHAIN_OPTIONS}" |
| 5 | CXXFLAGS =+ "${TARGET_CC_ARCH} ${TOOLCHAIN_OPTIONS}" |
| 6 | |
| 7 | #EXTRA_ANALYZER_OPTIONS ?= "-analyze-headers" |
| 8 | CLANG_SCAN_ENABLED ??= "1" |
| 9 | #CLANG_SCAN_SERVER_IP ??= "127.0.0.1" |
| 10 | CLANG_SCAN_SERVER_IP ??= "10.0.0.10" |
| 11 | CLANG_SCAN_PORT ??= "8181" |
| 12 | SCAN_RESULTS_DIR ?= "${TMPDIR}/static-scan/${PN}" |
| 13 | |
| 14 | scanbuild_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 | |
| 21 | do_configure[prefuncs] += "scanbuild_munge_cc_cxx" |
| 22 | |
| 23 | do_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 | |
| 33 | do_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 | |
| 41 | do_scanview[depends] += "${PN}:do_scanbuild" |
| 42 | do_scanbuild[cleandirs] += "${SCAN_RESULTS_DIR}" |
| 43 | do_scanbuild[dirs] += "${B}" |
| 44 | do_scanview[dirs] += "${SCAN_RESULTS_DIR}" |
| 45 | #do_build[recrdeptask] += "do_scanbuild" |
| 46 | |
| 47 | do_scanbuild[doc] = "Build and scan static analysis data using clang" |
| 48 | do_scanview[doc] = "Start a webserver to visualize static analysis data" |
| 49 | |
| 50 | addtask scanbuild after do_configure before do_compile |
| 51 | addtask scanview |
| 52 | |
| 53 | python () { |
| 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 | } |