]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
xen/misra: xen-analysis.py: fix parallel analysis Cppcheck errors
authorLuca Fancellu <luca.fancellu@arm.com>
Thu, 4 May 2023 13:12:43 +0000 (14:12 +0100)
committerStefano Stabellini <stefano.stabellini@amd.com>
Wed, 17 May 2023 23:13:04 +0000 (16:13 -0700)
Currently Cppcheck has a limitation that prevents to use make with
parallel build and have a parallel Cppcheck invocation on each
translation unit (the .c files), because of spurious internal errors.

The issue comes from the fact that when using the build directory,
Cppcheck saves temporary files as <filename>.c.<many-extensions>, but
this doesn't work well when files with the same name are being
analysed at the same time, leading to race conditions.

Fix the issue creating, under the build directory, the same directory
structure of the file being analysed to avoid any clash.

Fixes: 02b26c02c7c4 ("xen/scripts: add cppcheck tool to the xen-analysis.py script")
Signed-off-by: Luca Fancellu <luca.fancellu@arm.com>
Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>
xen/scripts/xen_analysis/cppcheck_analysis.py
xen/tools/cppcheck-cc.sh

index ab52ce38d5023e57be98ef4af348a2ad40f1d7eb..658795bb9f5b0f14b2fc881219087b4d925a7a1a 100644 (file)
@@ -139,7 +139,6 @@ def generate_cppcheck_deps():
     # Compiler defines are in compiler-def.h which is included in config.h
     #
     cppcheck_flags="""
---cppcheck-build-dir={}/{}
  --max-ctu-depth=10
  --enable=style,information,missingInclude
  --template=\'{{file}}({{line}},{{column}}):{{id}}:{{severity}}:{{message}}\'
@@ -150,8 +149,7 @@ def generate_cppcheck_deps():
  --suppress='unusedStructMember:*'
  --include={}/include/xen/config.h
  -DCPPCHECK
-""".format(settings.outdir, CPPCHECK_BUILD_DIR, settings.xen_dir,
-           settings.outdir, settings.xen_dir)
+""".format(settings.xen_dir, settings.outdir, settings.xen_dir)
 
     invoke_cppcheck = utils.invoke_command(
             "{} --version".format(settings.cppcheck_binpath),
@@ -204,9 +202,9 @@ def generate_cppcheck_deps():
 
     cppcheck_cc_flags = """--compiler={} --cppcheck-cmd={} {}
  --cppcheck-plat={}/cppcheck-plat --ignore-path=tools/
- --ignore-path=arch/x86/efi/check.c
+ --ignore-path=arch/x86/efi/check.c --build-dir={}/{}
 """.format(xen_cc, settings.cppcheck_binpath, cppcheck_flags,
-           settings.tools_dir)
+           settings.tools_dir, settings.outdir, CPPCHECK_BUILD_DIR)
 
     if settings.cppcheck_html:
         cppcheck_cc_flags = cppcheck_cc_flags + " --cppcheck-html"
index f6728e4c10847010cff01aaea59ae647be975d85..16a965edb7ec3b977011fb687d69b30b54a5aa6f 100755 (executable)
@@ -24,6 +24,7 @@ Options:
 EOF
 }
 
+BUILD_DIR=""
 CC_FILE=""
 COMPILER=""
 CPPCHECK_HTML="n"
@@ -66,6 +67,10 @@ do
             help
             exit 0
             ;;
+        --build-dir=*)
+            BUILD_DIR="${OPTION#*=}"
+            sm_tool_args="n"
+            ;;
         --compiler=*)
             COMPILER="${OPTION#*=}"
             sm_tool_args="n"
@@ -107,6 +112,12 @@ then
     exit 1
 fi
 
+if [ "${BUILD_DIR}" = "" ]
+then
+    echo "--build-dir arg is mandatory."
+    exit 1
+fi
+
 function create_jcd() {
     local line="${1}"
     local arg_num=0
@@ -199,13 +210,18 @@ then
             exit 1
         fi
 
+        # Generate build directory for the analysed file
+        cppcheck_build_dir="${BUILD_DIR}/${OBJTREE_PATH}"
+        mkdir -p "${cppcheck_build_dir}"
+
         # Shellcheck complains about missing quotes on CPPCHECK_TOOL_ARGS, but
         # they can't be used here
         # shellcheck disable=SC2086
         ${CPPCHECK_TOOL} ${CPPCHECK_TOOL_ARGS} \
             --project="${JDB_FILE}" \
             --output-file="${out_file}" \
-            --platform="${platform}"
+            --platform="${platform}" \
+            --cppcheck-build-dir=${cppcheck_build_dir}
 
         if [ "${CPPCHECK_HTML}" = "y" ]
         then
@@ -216,6 +232,7 @@ then
                 --project="${JDB_FILE}" \
                 --output-file="${out_file%.txt}.xml" \
                 --platform="${platform}" \
+                --cppcheck-build-dir=${cppcheck_build_dir} \
                 -q \
                 --xml
         fi