[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Are prerequisites made in deterministic order when parallelism is di
From: |
Paul Smith |
Subject: |
Re: Are prerequisites made in deterministic order when parallelism is disabled? |
Date: |
Wed, 14 Jun 2017 15:30:37 -0400 |
On Tue, 2017-06-13 at 10:33 -0500, Brett Stahlman wrote:
> I don't see anything in the Make docs that guarantees prerequisites
> will be processed in left to right order. Opinions on the web seems to
> be split into 2 camps:
>
> 1. Make always builds dependencies in left to right order, but a
> well-designed Makefile won't rely upon it.
> 2. Make is free to build dependencies in any order it likes, provided
> it respects the stated dependencies.
The answer is #1, with a caveat: all the prerequisites in the rule
defining the recipe are always checked first (in the order they appear
in that rule), regardless of the order in which the recipe rule
appears. So, in both of these situations:
foo: biz ; @echo $<
foo: bar
foo: boz
and also:
foo: bar
foo: boz
foo: biz ; @echo $<
the order of dependency checking will always be "biz bar boz" (and $<
will be "biz" of course).
But, in this situation:
foo: boz
foo: biz blah bleah; @echo $<
foo: bar
then the order will be "biz blah bleah boz bar". The order is always
the same and deterministic in a non-parallel build.
When parallelism is introduced, GNU make still follows the same order
of checking prerequisites. However, because some prerequisites will be
blocked waiting for others, the algorithm will skip those and move on
to other parts of the DAG and the actual order in which recipes are
invoked is not deterministic (unless the time taken for each build is
completely deterministic).