Makefile: fix rule order for legal-info
PATCH 1/1 Makefile: fix rule order for legal-info
This command relies on the clean/prepare operations being in a specific order.
Currently the execution ordering of the clean/prepare operations may change, for example if --shuffle=reversed is set.
To ensure the evaluation order is always correct use double colon rules to make the evaluation order explicit as per make docs:
The double-colon rules for a target are executed in the order they appear in the makefile.
--- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Makefile +3 -1
@@ -839,7 +839,9 @@ legal-info-prepare: $(LEGAL_INFO_DIR) @cp $(BR2_CONFIG) $(LEGAL_INFO_DIR)/buildroot.config .PHONY: legal-info -legal-info: legal-info-clean legal-info-prepare $(foreach p,$(PACKAGES),$(p)-all-legal-info) \ +legal-info:: legal-info-clean +legal-info:: legal-info-prepare +legal-info:: $(foreach p,$(PACKAGES),$(p)-all-legal-info) \ $(REDIST_SOURCES_DIR_TARGET) $(REDIST_SOURCES_DIR_HOST) @cat support/legal-info/README.header >>$(LEGAL_REPORT) @if [ -r $(LEGAL_WARNINGS) ]; then \
Signature · 6 lines
2.34.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
James, All,
On 2023-02-11 11:43 -0700, James Hilliard spake thusly:
Quoted 11 lines
This command relies on the clean/prepare operations being in a specific order.
Currently the execution ordering of the clean/prepare operations may change, for example if --shuffle=reversed is set.
To ensure the evaluation order is always correct use double colon rules to make the evaluation order explicit as per make docs:
The double-colon rules for a target are executed in the order they appear in the makefile.
Thanks for this patch!
What bothers me a bit about using double-colon, is that the make manual explicitly state that "[d]ouble-colon rules are somewhat obscure and not often very useful; they provide a mechanism for cases in which the method used to update a target differs depending on which prerequisite files caused the update, and such cases are rare."
So, I understand that it does fix the issue, but I'm afraid that it is going to be so easy to forget about that issue, and what I get from the make manual is that we should not use them unless as a last resort in very special corner cases, and the case at hand is not identified by the manual, which somewhat implies that double-colon rules were written specifically to handle the case where "the method used to update a target differs depending on which prerequisite files caused the update", not specifically to ensure that the order is guarantedd. It even goes as far as suggesting that this should not really be relied upon:
The double-colon rules for a target are executed in the order they appear in the makefile. However, the cases where double-colon rules really make sense are those where the order of executing the recipes would not matter.
So, to me, the ordering is only a side-effect of the original goal, which is to have different commands to generate a target, based on what prerequisite caused the the update...
I am also afraid that there are so many other places around where we implicitly rely on the order the prerequisites are listed, and that we can't easily spot (that I spotted the legal-info issue and asked you about it, is pure chance, as I was looking at something completely different).
However, in the legal-info case, the rule is definitely not parallel-safe, and we do really want it and its dependencies *not* to execute in parallel in fact.
Indeed, all PKG-legal-info rules will emit a little blurb that is appended to the manisfest.csv, with commands like:
echo 'PKG,VERSION,blablsablab' >> manifest.csv
So, if we run that in parallel, this is going to explode [1].
So, I believe in this case, we do not want to use :: rules, but really ensure that legal-info and all PKG-legal-info rules are never run in parallel, *and* that they are executed in the order they are listed in the prerequisites.
We probably want to just add in the top-level Makefile:
.NOTPARALLEL: legal-info
and in package/pkg-generic.mk, something along the lines of:
.NOTPARALLEL: $(2)-legal-info #(2)-all-legal-info
Thoughts?
[0] https://www.gnu.org/software/make/manual/make.html#Double_002dColon
[1] with very nice and bright colors, but a bit too loud still
Regards,
Yann E. MORIN.
Quoted 27 lines
Signed-off-by James Hilliard <[email protected]>--- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Makefile +3
-1@@ -839,7 +839,9 @@ legal-info-prepare: $(LEGAL_INFO_DIR) @cp $(BR2_CONFIG) $(LEGAL_INFO_DIR)/buildroot.config .PHONY: legal-info -legal-info: legal-info-clean legal-info-prepare $(foreach p,$(PACKAGES),$(p)-all-legal-info) \ +legal-info:: legal-info-clean +legal-info:: legal-info-prepare +legal-info:: $(foreach p,$(PACKAGES),$(p)-all-legal-info) \ $(REDIST_SOURCES_DIR_TARGET) $(REDIST_SOURCES_DIR_HOST) @cat support/legal-info/README.header >>$(LEGAL_REPORT) @if [ -r $(LEGAL_WARNINGS) ]; then \Signature · 6 lines
2.34.1 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------' _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 43 lines · Yann E. MORIN
James, All,
On 2023-02-11 11:43 -0700, James Hilliard spake thusly:
Quoted 11 lines
This command relies on the clean/prepare operations being in a specific order.
Currently the execution ordering of the clean/prepare operations may change, for example if --shuffle=reversed is set.
To ensure the evaluation order is always correct use double colon rules to make the evaluation order explicit as per make docs:
The double-colon rules for a target are executed in the order they appear in the makefile.
Thanks for this patch!
What bothers me a bit about using double-colon, is that the make manual explicitly state that "[d]ouble-colon rules are somewhat obscure and not often very useful; they provide a mechanism for cases in which the method used to update a target differs depending on which prerequisite files caused the update, and such cases are rare."
So, I understand that it does fix the issue, but I'm afraid that it is going to be so easy to forget about that issue, and what I get from the make manual is that we should not use them unless as a last resort in very special corner cases, and the case at hand is not identified by the manual, which somewhat implies that double-colon rules were written specifically to handle the case where "the method used to update a target differs depending on which prerequisite files caused the update", not specifically to ensure that the order is guarantedd. It even goes as far as suggesting that this should not really be relied upon:
The double-colon rules for a target are executed in the order they appear in the makefile. However, the cases where double-colon rules really make sense are those where the order of executing the recipes would not matter.
So, to me, the ordering is only a side-effect of the original goal, which is to have different commands to generate a target, based on what prerequisite caused the the update...
Quoted 5 lines
I am also afraid that there are so many other places around where we implicitly rely on the order the prerequisites are listed, and that we can't easily spot (that I spotted the legal-info issue and asked you about it, is pure chance, as I was looking at something completely different).
Well we should be able to flush them out using make shuffle mode.
That's how I caught the other issues at least.
Quoted 10 lines
However, in the legal-info case, the rule is definitely not parallel-safe, and we do really want it and its dependencies *not* to execute in parallel in fact.
Indeed, all PKG-legal-info rules will emit a little blurb that is appended to the manisfest.csv, with commands like:
echo 'PKG,VERSION,blablsablab' >> manifest.csvSo, if we run that in parallel, this is going to explode [1].
Hmm, might just need a flock operation when doing the manifest.csv file echo append.
We do something like that for downloads already:
https://github.com/buildroot/buildroot/blob/2022.11.1/package/pkg-download.mk#L113
Quoted 5 lines
So, I believe in this case, we do not want to use :: rules, but really ensure that legal-info and all PKG-legal-info rules are never run in parallel, *and* that they are executed in the order they are listed in the prerequisites.
Well legal-info can take a while to run so it might make sense to make it work in parallel.
Quoted 10 lines
We probably want to just add in the top-level
Makefile:.NOTPARALLEL: legal-info
and in
package/pkg-generic.mk, something along the lines of:.NOTPARALLEL: $(2)-legal-info #(2)-all-legal-infoThoughts?
Might work...but it seems like using flock may be simpler and faster.
Quoted 37 lines
[0] https://www.gnu.org/software/make/manual/make.html#Double_002dColon
[1] with very nice and bright colors, but a bit too loud stillRegards,
Yann E. MORIN.Quoted 23 lines
Signed-off-by James Hilliard <[email protected]>--- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Makefile +3
-2@@ -839,7 +839,9 @@ legal-info-prepare: $(LEGAL_INFO_DIR) @cp $(BR2_CONFIG) $(LEGAL_INFO_DIR)/buildroot.config .PHONY: legal-info -legal-info: legal-info-clean legal-info-prepare $(foreach p,$(PACKAGES),$(p)-all-legal-info) \ +legal-info:: legal-info-clean +legal-info:: legal-info-prepare +legal-info:: $(foreach p,$(PACKAGES),$(p)-all-legal-info) \ $(REDIST_SOURCES_DIR_TARGET) $(REDIST_SOURCES_DIR_HOST) @cat support/legal-info/README.header >>$(LEGAL_REPORT) @if [ -r $(LEGAL_WARNINGS) ]; then \ --2.34.1
Quoted 4 lines
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot--
.-----------------.--------------------.------------------.--------------------.
Quoted 5 lines
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
James, All,
On 2023-02-12 03:12 -0700, James Hilliard spake thusly:
Quoted 4 lines · Yann E. MORIN
Quoted 3 lines
On 2023-02-11 11:43 -0700, James Hilliard spake thusly:
Quoted 2 lines
This command relies on the clean/prepare operations being in a specific order.
[--SNIP--]
Quoted 11 lines
Quoted 9 lines
However, in the legal-info case, the rule is definitely not parallel-safe, and we do really want it and its dependencies *not* to execute in parallel in fact.
Indeed, all PKG-legal-info rules will emit a little blurb that is appended to the manisfest.csv, with commands like:
echo 'PKG,VERSION,blablsablab' >> manifest.csvSo, if we run that in parallel, this is going to explode [1].
Hmm, might just need a flock operation when doing the manifest.csv file echo append.
Except we probably want, no, sorry: we do want, that the manifest to be reproducible (and alphabeticaly sorted), which would not be guaranteed with an flock.
Quoted 2 lines
We do something like that for downloads already:
https://github.com/buildroot/buildroot/blob/2022.11.1/package/pkg-download.mk#L113
Careful there: the flock is to protect against a concurrent Buildroot build, not an internal protection (although it also serves as an internal protection, when two packages have the same dl dir, like mesa3d and mesa3d-headers).
Quoted 7 lines
Quoted 4 lines
So, I believe in this case, we do not want to use :: rules, but really ensure that legal-info and all PKG-legal-info rules are never run in parallel, *and* that they are executed in the order they are listed in the prerequisites.
Well legal-info can take a while to run so it might make sense to make it work in parallel.
I understand that, but I still think legal-info should produce a reproducible output, and that can't be guaranteed if all we change is using an flock around the manifests.
Also, legal-info is probably run after a complete build, so the overhead of downloading, extracting, and patching, ahs already been paid during the build.
We talked about legal-info during the dev-days, and one idea that floated was that we need to generate an SBOM of the build, and the closest we have now is legal-info. The SBOM should always be generated, and I believe legal-info should awlays be generated, so the overhead point would be moot (but would be replaced by the overhead of running legal-info for every builds...) More needs to be dug on that topic...
Regards,
Yann E. MORIN.
Signature · 10 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------' _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 17 lines · Yann E. MORIN
James, All,
On 2023-02-12 03:12 -0700, James Hilliard spake thusly:
Quoted 4 lines · Yann E. MORIN
Quoted 3 lines
On 2023-02-11 11:43 -0700, James Hilliard spake thusly:
Quoted 2 lines
This command relies on the clean/prepare operations being in a specific order.
[--SNIP--]
Quoted 8 lines
Quoted 8 lines
However, in the legal-info case, the rule is definitely not parallel-safe, and we do really want it and its dependencies *not* to execute in parallel in fact.
Indeed, all PKG-legal-info rules will emit a little blurb that is appended to the manisfest.csv, with commands like:
echo 'PKG,VERSION,blablsablab' >> manifest.csv
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
So, if we run that in parallel, this is going to explode [1].
Hmm, might just need a flock operation when doing the manifest.csv file echo append.
Except we probably want, no, sorry: we do want, that the manifest to be reproducible (and alphabeticaly sorted), which would not be guaranteed with an flock.
Hmm, I thought we were sorting afterwards like this, guess that needs to be checked:
https://github.com/buildroot/buildroot/blob/59b2e826f2a6c1874c5d032d3a5852326028bc0e/Makefile#L851
Quoted 8 lines
Quoted 3 lines
We do something like that for downloads already:
https://github.com/buildroot/buildroot/blob/2022.11.1/package/pkg-download.mk#L113Careful there: the flock is to protect against a concurrent Buildroot build, not an internal protection (although it also serves as an internal protection, when two packages have the same dl dir, like mesa3d and mesa3d-headers).
I assumed it was mostly for packages with the same dl dir, I think it matters more what it can do rather than what it was designed to do ;).
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
So, I believe in this case, we do not want to use :: rules, but really ensure that legal-info and all PKG-legal-info rules are never run in parallel, *and* that they are executed in the order they are listed in the prerequisites.
Quoted 6 lines
Quoted 2 lines
Well legal-info can take a while to run so it might make sense to make it work in parallel.
I understand that, but I still think legal-info should produce a reproducible output, and that can't be guaranteed if all we change is using an flock around the manifests.
It should be reproducible if we run a sort right?
Quoted 4 lines
Also, legal-info is probably run after a complete build, so the overhead of downloading, extracting, and patching, ahs already been paid during the build.
Doesn't it still take a little while even if that's done?
Quoted 7 lines
We talked about legal-info during the dev-days, and one idea that floated was that we need to generate an SBOM of the build, and the closest we have now is legal-info. The SBOM should always be generated, and I believe legal-info should awlays be generated, so the overhead point would be moot (but would be replaced by the overhead of running legal-info for every builds...) More needs to be dug on that topic...
Well I think for both cases the faster the generation the better so parallel where possible has advantages there.
If something is too slow it's less likely to be used/tested.
Quoted 11 lines
Regards,
Yann E. MORIN.--
.-----------------.--------------------.------------------.--------------------.| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |'------------------------------^-------^------------------^--------------------'
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 22 lines · James Hilliard
This command relies on the clean/prepare operations being in a specific order.
Currently the execution ordering of the clean/prepare operations may change, for example if --shuffle=reversed is set.
To ensure the evaluation order is always correct use double colon rules to make the evaluation order explicit as per make docs:
The double-colon rules for a target are executed in the order they appear in the makefile.
Signed-off-by James Hilliard <[email protected]>--- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Makefile +0
-0
Makefile legal-info-prepare: $(LEGAL_INFO_DIR) · line 845
Quoted 8 lines
Makefile +3
-1@@ -839,7 +839,9 @@ legal-info-prepare: $(LEGAL_INFO_DIR) @cp $(BR2_CONFIG) $(LEGAL_INFO_DIR)/buildroot.config .PHONY: legal-info -legal-info: legal-info-clean legal-info-prepare $(foreach p,$(PACKAGES),$(p)-all-legal-info) \ +legal-info:: legal-info-clean +legal-info:: legal-info-prepare +legal-info:: $(foreach p,$(PACKAGES),$(p)-all-legal-info) \ $(REDIST_SOURCES_DIR_TARGET) $(REDIST_SOURCES_DIR_HOST)
Like for rebuild, reinstall, reconfigure I think the following should work:
legal-info-prepare: | legal-info-clean
$(1)-all-legal-info: | legal-info-prepare
(the last one would be in pkg-generic instead of here, of course).
Although in this case I think a full dependency should be even OK, so without the |
Regards,
Arnout
Makefile legal-info-prepare: $(LEGAL_INFO_DIR) · line 847
Quoted 2 lines
Makefile +0
-0@cat support/legal-info/README.header >>$(LEGAL_REPORT) @if [ -r $(LEGAL_WARNINGS) ]; then \
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot