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