[PATCH] CI: Fix cppcheck parallel build more

Andrew Cooper posted 1 patch 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20241031165505.3007713-1-andrew.cooper3@citrix.com
xen/tools/cppcheck-cc.sh | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
[PATCH] CI: Fix cppcheck parallel build more
Posted by Andrew Cooper 1 month ago
A recent cppcheck run was found to fail:

  https://gitlab.com/xen-project/people/andyhhp/xen/-/jobs/8237167472

with:

  "type mismatch! call is<type>() before get<type>()" && is<std::string>()
  make[3]: *** [arch/x86/boot/Makefile:28: arch/x86/boot/reloc-trampoline.32.o] Error 1

This turns out to be a parallel build issue, combined with a recent change to
x86.  Notably, we now have a case where we build both:

  CC      arch/x86/boot/reloc-trampoline.32.o
  CC      arch/x86/boot/reloc-trampoline.o

from the same original C file, and cppcheck uses the source C file as the key
for generating it's intermediate files.

Switch cppcheck to use the object file as the unique key instead.

Fixes: 45bfff651173 ("xen/misra: xen-analysis.py: fix parallel analysis Cppcheck errors")
Fixes: db8acf31f96b ("x86/boot: Reuse code to relocate trampoline")
Suggested-by: Luca Fancellu <luca.fancellu@arm.com>
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Luca Fancellu <luca.fancellu@arm.com>
CC: Jan Beulich <JBeulich@suse.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien@xen.org>

https://gitlab.com/xen-project/people/andyhhp/xen/-/pipelines/1522120661

which seems to suggest that cppcheck is still happy.
---
 xen/tools/cppcheck-cc.sh | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/xen/tools/cppcheck-cc.sh b/xen/tools/cppcheck-cc.sh
index 16a965edb7ec..8a58c3aa86b3 100755
--- a/xen/tools/cppcheck-cc.sh
+++ b/xen/tools/cppcheck-cc.sh
@@ -26,6 +26,7 @@ EOF
 
 BUILD_DIR=""
 CC_FILE=""
+OBJ_FILE=""
 COMPILER=""
 CPPCHECK_HTML="n"
 CPPCHECK_PLAT_PATH=""
@@ -56,6 +57,7 @@ do
         then
             # This must be the path to the obj file, turn off flag and save path
             OBJTREE_PATH="$(dirname "${OPTION}")"
+            OBJ_FILE="$(basename "${OPTION}")"
             obj_arg_content="n"
         fi
         # Forward any argument to the compiler
@@ -177,12 +179,12 @@ then
     done
     if [ "${IGNORE_PATH}" = "n" ]
     then
-        JDB_FILE="${OBJTREE_PATH}/$(basename "${CC_FILE}".json)"
+        JDB_FILE="${OBJTREE_PATH}/${OBJ_FILE}.json"
 
         # Prepare the Json Compilation Database for the file
         create_jcd "${COMPILER} ${FORWARD_FLAGS}"
 
-        out_file="${OBJTREE_PATH}/$(basename "${CC_FILE%.c}".cppcheck.txt)"
+        out_file="${OBJTREE_PATH}/${OBJ_FILE}.cppcheck.txt"
 
         # Select the right target platform, ARCH is generated from Xen Makefile
         case ${ARCH} in
@@ -211,7 +213,7 @@ then
         fi
 
         # Generate build directory for the analysed file
-        cppcheck_build_dir="${BUILD_DIR}/${OBJTREE_PATH}"
+        cppcheck_build_dir="${BUILD_DIR}/${OBJTREE_PATH}/${OBJ_FILE}"
         mkdir -p "${cppcheck_build_dir}"
 
         # Shellcheck complains about missing quotes on CPPCHECK_TOOL_ARGS, but

base-commit: 2478bed83fc6d8be1d129d9a9617eda2ab3c9790
-- 
2.39.5
Re: [PATCH] CI: Fix cppcheck parallel build more
Posted by Luca Fancellu 1 month ago
Hi Andrew,

> On 31 Oct 2024, at 16:55, Andrew Cooper <andrew.cooper3@citrix.com> wrote:
> 
> A recent cppcheck run was found to fail:
> 
>  https://gitlab.com/xen-project/people/andyhhp/xen/-/jobs/8237167472
> 
> with:
> 
>  "type mismatch! call is<type>() before get<type>()" && is<std::string>()
>  make[3]: *** [arch/x86/boot/Makefile:28: arch/x86/boot/reloc-trampoline.32.o] Error 1
> 
> This turns out to be a parallel build issue, combined with a recent change to
> x86.  Notably, we now have a case where we build both:
> 
>  CC      arch/x86/boot/reloc-trampoline.32.o
>  CC      arch/x86/boot/reloc-trampoline.o
> 
> from the same original C file, and cppcheck uses the source C file as the key
> for generating it's intermediate files.
> 
> Switch cppcheck to use the object file as the unique key instead.
> 
> Fixes: 45bfff651173 ("xen/misra: xen-analysis.py: fix parallel analysis Cppcheck errors")
> Fixes: db8acf31f96b ("x86/boot: Reuse code to relocate trampoline")
> Suggested-by: Luca Fancellu <luca.fancellu@arm.com>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> —

Looks good to me!
I’ve also checked with and without the patch and I can’t see any regression in terms of cppcheck
issues report.

Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Tested-by: Luca Fancellu <luca.fancellu@arm.com>

Re: [PATCH] CI: Fix cppcheck parallel build more
Posted by Andrew Cooper 1 month ago
On 31/10/2024 5:11 pm, Luca Fancellu wrote:
> Hi Andrew,
>
>> On 31 Oct 2024, at 16:55, Andrew Cooper <andrew.cooper3@citrix.com> wrote:
>>
>> A recent cppcheck run was found to fail:
>>
>>  https://gitlab.com/xen-project/people/andyhhp/xen/-/jobs/8237167472
>>
>> with:
>>
>>  "type mismatch! call is<type>() before get<type>()" && is<std::string>()
>>  make[3]: *** [arch/x86/boot/Makefile:28: arch/x86/boot/reloc-trampoline.32.o] Error 1
>>
>> This turns out to be a parallel build issue, combined with a recent change to
>> x86.  Notably, we now have a case where we build both:
>>
>>  CC      arch/x86/boot/reloc-trampoline.32.o
>>  CC      arch/x86/boot/reloc-trampoline.o
>>
>> from the same original C file, and cppcheck uses the source C file as the key
>> for generating it's intermediate files.
>>
>> Switch cppcheck to use the object file as the unique key instead.
>>
>> Fixes: 45bfff651173 ("xen/misra: xen-analysis.py: fix parallel analysis Cppcheck errors")
>> Fixes: db8acf31f96b ("x86/boot: Reuse code to relocate trampoline")
>> Suggested-by: Luca Fancellu <luca.fancellu@arm.com>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
>> —
> Looks good to me!
> I’ve also checked with and without the patch and I can’t see any regression in terms of cppcheck
> issues report.
>
> Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
> Tested-by: Luca Fancellu <luca.fancellu@arm.com>
>

Thanks.  I'll get this committed right away.

~Andrew