From: Khem Raj <raj.khem@gmail.com>
To: openembedded-core@lists.openembedded.org
Cc: Khem Raj <raj.khem@gmail.com>
Subject: [PATCH 04/19] scan-build.bbclass: Add class to enable clang static analyser
Date: Tue, 5 Nov 2024 10:45:23 -0800 [thread overview]
Message-ID: <20241105184540.3450302-4-raj.khem@gmail.com> (raw)
In-Reply-To: <20241105184540.3450302-1-raj.khem@gmail.com>
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
meta/classes-recipe/scan-build.bbclass | 60 ++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
create mode 100644 meta/classes-recipe/scan-build.bbclass
diff --git a/meta/classes-recipe/scan-build.bbclass b/meta/classes-recipe/scan-build.bbclass
new file mode 100644
index 00000000000..e1a72de993e
--- /dev/null
+++ b/meta/classes-recipe/scan-build.bbclass
@@ -0,0 +1,60 @@
+# Copyright (C) 2018 Khem Raj <raj.khem@gmail.com>
+# Released under the MIT license (see COPYING.MIT for the terms)
+
+EXTRA_ANALYZER_OPTIONS += "-analyze-headers"
+EXTRA_ANALYZER_OPTIONS += "--force-analyze-debug-code"
+SCAN_BUILD ??= "1"
+SCAN_BUILD:class-native = ""
+SCAN_BUILD:class-nativesdk = ""
+SCAN_BUILD:class-cross = ""
+SCAN_BUILD:class-crosssdk = ""
+SCAN_BUILD:class-cross-canadian = ""
+
+CLANG_SCAN_SERVER_IP ??= "0.0.0.0"
+CLANG_SCAN_PORT ??= "8181"
+SCAN_RESULTS_DIR ?= "${TMPDIR}/static-scan/${PN}"
+
+CCSCAN ?= "${HOST_PREFIX}${TOOLCHAIN}"
+CXXSCAN:toolchain-clang ?= "${HOST_PREFIX}clang++"
+CXXSCAN:toolchain-gcc ?= "${HOST_PREFIX}g++"
+
+do_scanbuild() {
+ rm -rf ${SCAN_RESULTS_DIR}
+ scan-build --use-cc ${CCSCAN} --use-c++ ${CXXSCAN} --analyzer-target ${HOST_SYS} --html-title ${BP} -o ${SCAN_RESULTS_DIR} ${EXTRA_ANALYZER_OPTIONS} ${MAKE} ${PARALLEL_MAKE} ${EXTRA_OEMAKE}
+}
+
+do_scanview() {
+ bbplain "================================================================"
+ bbplain "Starting scan-view server at: http://${CLANG_SCAN_SERVER_IP}:${CLANG_SCAN_PORT}"
+ bbplain "Use Ctrl-C to exit"
+ bbplain "================================================================"
+ scan-view --host ${CLANG_SCAN_SERVER_IP} --port ${CLANG_SCAN_PORT} --allow-all-hosts --no-browser ${SCAN_RESULTS_DIR}/*/
+}
+
+do_scanview[depends] += "${PN}:do_scanbuild"
+do_scanbuild[depends] += "clang-native:do_populate_sysroot"
+#do_scanbuild[cleandirs] += "${SCAN_RESULTS_DIR}"
+do_scanbuild[dirs] += "${B}"
+do_scanview[dirs] += "${SCAN_RESULTS_DIR}"
+#do_build[recrdeptask] += "do_scanbuild"
+
+do_scanbuild[doc] = "Build and scan static analysis data using clang"
+do_scanview[doc] = "Start a webserver to visualize static analysis data"
+
+addtask scanbuild after do_configure before do_compile
+addtask scanview after do_scanbuild
+python () {
+ # Remove scanbuild task when scanning is not enabled or recipe does not have do_configure
+ if not(d.getVar('SCAN_BUILD') == "1") or not(d.getVar('TOOLCHAIN') == "clang") or oe.utils.inherits(d, 'allarch'):
+ for i in ['do_scanbuild', 'do_scanview']:
+ bb.build.deltask(i, d)
+ else:
+ cflags = d.getVar('CFLAGS', False) + d.getVar('TARGET_CC_ARCH', False) + d.getVar('TOOLCHAIN_OPTIONS', False)
+ cxxflags = d.getVar('CXXFLAGS', False) + d.getVar('TARGET_CC_ARCH', False) + d.getVar('TOOLCHAIN_OPTIONS', False)
+ d.setVar('CFLAGS', cflags)
+ d.setVar('CXXFLAGS', cxxflags)
+ if oe.utils.inherits(d, 'autotools'):
+ cachedvar = d.getVar('CACHED_CONFIGUREVARS', False)
+ cachedvar = cachedvar + " scan-build " + " --analyzer-target " + d.getVar('HOST_SYS', False) + " --use-cc " + d.getVar('CCSCAN', False) + " --use-c++ " + d.getVar('CXXSCAN', False)
+ d.setVar('CACHED_CONFIGUREVARS', cachedvar)
+}
next prev parent reply other threads:[~2024-11-05 18:45 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-05 18:45 [PATCH 01/19] clang.inc: Global settings for clang toolchain Khem Raj
2024-11-05 18:45 ` [PATCH 02/19] nonclangable.inc: Add recipe which can not be built with clang Khem Raj
2025-01-07 13:52 ` [OE-core] " Richard Purdie
2024-11-05 18:45 ` [PATCH 03/19] nonscanable.inc: Includes recipes which can not be used with clang-scan Khem Raj
2024-11-05 18:45 ` Khem Raj [this message]
2025-01-07 13:50 ` [OE-core] [PATCH 04/19] scan-build.bbclass: Add class to enable clang static analyser Richard Purdie
2024-11-05 18:45 ` [PATCH 05/19] clang-native.bbclass: Abstraction to enable clang as native compiler Khem Raj
2024-11-05 18:45 ` [PATCH 06/19] cmake-native.bbclass: Abstraction to use cmake with native toolchains Khem Raj
2024-11-05 18:45 ` [PATCH 07/19] clang: Migrate clang and related recipes from meta-clang Khem Raj
2025-01-07 13:54 ` [OE-core] " Richard Purdie
2024-11-05 18:45 ` [PATCH 08/19] clang/recipes: Add missing SUMMARY field Khem Raj
2025-01-07 13:55 ` [OE-core] " Richard Purdie
2024-11-05 18:45 ` [PATCH 09/19] llvm: Delete Khem Raj
2024-11-05 18:45 ` [PATCH 10/19] spirv-llvm-translator: Add recipe Khem Raj
2024-11-05 18:45 ` [PATCH 11/19] multilib.conf: Add llvm-project-source recipe to NON_MULTILIB_RECIPES Khem Raj
2024-11-05 18:45 ` [PATCH 12/19] distro/defaultsetup: Inherit clang, nonclangable, and nonscanable Khem Raj
2024-11-05 18:45 ` [PATCH 13/19] maintainers.inc: Add myself as maintainer for clang family of recipes Khem Raj
2024-11-05 18:45 ` [PATCH 14/19] clang: PROVIDE llvm-native and llvm Khem Raj
2024-11-05 18:45 ` [PATCH 15/19] rpm: Use gcc to compile always Khem Raj
2024-11-05 18:45 ` [PATCH 16/19] sdks: Add clang toolchain to SDKs Khem Raj
2024-11-06 10:38 ` [OE-core] " Mathieu Dubois-Briand
2024-11-06 14:54 ` Khem Raj
2024-11-05 18:45 ` [PATCH 17/19] toolchain-scripts.bbclass: Add env variables in SDK to use clang/clang++ Khem Raj
2024-11-05 18:45 ` [PATCH 18/19] mesa: update 24.0.7 -> 24.2.2 Khem Raj
2024-11-06 11:30 ` [OE-core] " Alexander Kanavin
2024-11-06 14:53 ` Khem Raj
2024-11-05 18:45 ` [PATCH 19/19] mesa: add support for rusticl Khem Raj
2024-11-06 11:27 ` [OE-core] " Alexander Kanavin
2024-11-06 15:54 ` [OE-core] [PATCH 01/19] clang.inc: Global settings for clang toolchain Richard Purdie
2024-11-06 16:14 ` Khem Raj
2025-01-07 13:50 ` Richard Purdie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241105184540.3450302-4-raj.khem@gmail.com \
--to=raj.khem@gmail.com \
--cc=openembedded-core@lists.openembedded.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox