[PATCH v2] build: correct cppcheck-misra make rule

Jan Beulich posted 1 patch 1 year, 7 months ago
Failed in applying to current master (apply log)
[PATCH v2] build: correct cppcheck-misra make rule
Posted by Jan Beulich 1 year, 7 months ago
Having cppcheck-misra.json depend on cppcheck-misra.txt does not
properly address the multiple targets problem. If cppcheck-misra.json
is deleted from the build tree but cppcheck-misra.txt is still there,
nothing will re-generate cppcheck-misra.json.

With GNU make 4.3 or newer we could use the &: grouped target separator,
but since we support older make as well we need to use some other
mechanism. Convert the rule to a pattern one (with "cppcheck" kind of
arbitrarily chosen as the stem), thus making known to make that both
files are created by a single command invocation. Since, as a result,
the JSON file is now "intermediate" from make's perspective, prevent it
being deleted again by making it a prereq of .PRECIOUS.

Fixes: 57caa5375321 ("xen: Add MISRA support to cppcheck make rule")
Signed-off-by: Jan Beulich <jbeulich@suse.com>
---
v2: Add comment. Add Fixes: tag.
---
It has been bothering me for a while that I made a bad suggestion during
review; I'm sorry for that.

--- a/xen/Makefile
+++ b/xen/Makefile
@@ -746,11 +746,12 @@ cppcheck-version:
 # documentation file. Also generate a json file with the right arguments for
 # cppcheck in json format including the list of rules to ignore.
 #
-cppcheck-misra.txt: $(XEN_ROOT)/docs/misra/rules.rst $(srctree)/tools/convert_misra_doc.py
-	$(Q)$(PYTHON) $(srctree)/tools/convert_misra_doc.py -i $< -o $@ -j $(@:.txt=.json)
-
-# convert_misra_doc is generating both files.
-cppcheck-misra.json: cppcheck-misra.txt
+# convert_misra_doc.py, producing both targets at the same time, should be
+# executed only once. Utilize a pattern rule to achieve this effect, with the
+# stem kind of arbitrarily chosen to be "cppcheck".
+.PRECIOUS: %-misra.json
+%-misra.txt %-misra.json: $(XEN_ROOT)/docs/misra/rules.rst $(srctree)/tools/convert_misra_doc.py
+	$(Q)$(PYTHON) $(srctree)/tools/convert_misra_doc.py -i $< -o $*-misra.txt -j $*-misra.json
 
 # Put this in generated headers this way it is cleaned by include/Makefile
 $(objtree)/include/generated/compiler-def.h:
Re: [PATCH v2] build: correct cppcheck-misra make rule
Posted by Bertrand Marquis 1 year, 7 months ago
Hi Jan,

> On 12 Sep 2022, at 07:46, Jan Beulich <jbeulich@suse.com> wrote:
> 
> Having cppcheck-misra.json depend on cppcheck-misra.txt does not
> properly address the multiple targets problem. If cppcheck-misra.json
> is deleted from the build tree but cppcheck-misra.txt is still there,
> nothing will re-generate cppcheck-misra.json.
> 
> With GNU make 4.3 or newer we could use the &: grouped target separator,
> but since we support older make as well we need to use some other
> mechanism. Convert the rule to a pattern one (with "cppcheck" kind of
> arbitrarily chosen as the stem), thus making known to make that both
> files are created by a single command invocation. Since, as a result,
> the JSON file is now "intermediate" from make's perspective, prevent it
> being deleted again by making it a prereq of .PRECIOUS.
> 
> Fixes: 57caa5375321 ("xen: Add MISRA support to cppcheck make rule")
> Signed-off-by: Jan Beulich <jbeulich@suse.com>

Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>

Cheers
Bertrand

> ---
> v2: Add comment. Add Fixes: tag.
> ---
> It has been bothering me for a while that I made a bad suggestion during
> review; I'm sorry for that.
> 
> --- a/xen/Makefile
> +++ b/xen/Makefile
> @@ -746,11 +746,12 @@ cppcheck-version:
> # documentation file. Also generate a json file with the right arguments for
> # cppcheck in json format including the list of rules to ignore.
> #
> -cppcheck-misra.txt: $(XEN_ROOT)/docs/misra/rules.rst $(srctree)/tools/convert_misra_doc.py
> -	$(Q)$(PYTHON) $(srctree)/tools/convert_misra_doc.py -i $< -o $@ -j $(@:.txt=.json)
> -
> -# convert_misra_doc is generating both files.
> -cppcheck-misra.json: cppcheck-misra.txt
> +# convert_misra_doc.py, producing both targets at the same time, should be
> +# executed only once. Utilize a pattern rule to achieve this effect, with the
> +# stem kind of arbitrarily chosen to be "cppcheck".
> +.PRECIOUS: %-misra.json
> +%-misra.txt %-misra.json: $(XEN_ROOT)/docs/misra/rules.rst $(srctree)/tools/convert_misra_doc.py
> +	$(Q)$(PYTHON) $(srctree)/tools/convert_misra_doc.py -i $< -o $*-misra.txt -j $*-misra.json
> 
> # Put this in generated headers this way it is cleaned by include/Makefile
> $(objtree)/include/generated/compiler-def.h: