[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen master] xen/misra: xen-analysis.py: fix parallel analysis Cppcheck errors



commit 45bfff651173d538239308648c6a6cd7cbe37172
Author:     Luca Fancellu <luca.fancellu@xxxxxxx>
AuthorDate: Thu May 4 14:12:43 2023 +0100
Commit:     Stefano Stabellini <stefano.stabellini@xxxxxxx>
CommitDate: Wed May 17 16:13:04 2023 -0700

    xen/misra: xen-analysis.py: fix parallel analysis Cppcheck errors
    
    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@xxxxxxx>
    Reviewed-by: Stefano Stabellini <sstabellini@xxxxxxxxxx>
---
 xen/scripts/xen_analysis/cppcheck_analysis.py |  8 +++-----
 xen/tools/cppcheck-cc.sh                      | 19 ++++++++++++++++++-
 2 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/xen/scripts/xen_analysis/cppcheck_analysis.py 
b/xen/scripts/xen_analysis/cppcheck_analysis.py
index ab52ce38d5..658795bb9f 100644
--- a/xen/scripts/xen_analysis/cppcheck_analysis.py
+++ b/xen/scripts/xen_analysis/cppcheck_analysis.py
@@ -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"
diff --git a/xen/tools/cppcheck-cc.sh b/xen/tools/cppcheck-cc.sh
index f6728e4c10..16a965edb7 100755
--- a/xen/tools/cppcheck-cc.sh
+++ b/xen/tools/cppcheck-cc.sh
@@ -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
--
generated by git-patchbot for /home/xen/git/xen.git#master



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.