android_build/tools/makeparallel
Dan Willemsen f0e2986cbf Wait for children to exit in makeparallel
This is a partial revert to the last makeparallel change, since now we
were being killed by the signal before waiting for our child to exit. So
instead of not installing the handlers, only pass the signal along if
it's a SIGTERM.

Bug: 35214134
Test: Ensure that we're still only getting one signal for SIGINT
Test: Ctrl-C, ensure that all the soong_ui lines are before the make
      error line.
Change-Id: I26fff9483a3abfd79ceb5a9ea47e3f7572d9e923
2017-02-21 17:53:35 -08:00
..
.gitignore Implement makeparallel 2015-09-14 14:33:50 -07:00
Android.bp Allow building kati & makeparallel with soong 2016-01-13 13:08:29 -08:00
Makefile Convert -j to a reasonable parallelism for kati 2017-01-18 14:50:50 -08:00
Makefile.test makeparallel: prepend flags to ninja command line 2015-10-20 17:05:49 -07:00
makeparallel.cpp Wait for children to exit in makeparallel 2017-02-21 17:53:35 -08:00
README.md Implement makeparallel 2015-09-14 14:33:50 -07:00

makeparallel

makeparallel communicates with the GNU make jobserver in order claim all available jobs, and then passes the number of jobs claimed to a subprocess with -j<jobs>.

The number of available jobs is determined by reading tokens from the jobserver until a read would block. If the makeparallel rule is the only one running the number of jobs will be the total size of the jobserver pool, i.e. the value passed to make with -j. Any jobs running in parallel with with the makeparellel rule will reduce the measured value, and thus reduce the parallelism available to the subprocess.

To run a multi-thread or multi-process binary inside GNU make using makeparallel, add

	+makeparallel subprocess arguments

to a rule. For example, to wrap ninja in make, use something like:

	+makeparallel ninja -f build.ninja

To determine the size of the jobserver pool, add

	+makeparallel echo > make.jobs

to a rule that is guarantee to run alone (i.e. all other rules are either dependencies of the makeparallel rule, or the depend on the makeparallel rule. The output file will contain the -j<num> flag passed to the parent make process, or -j1 if no flag was found. Since GNU make will run makeparallel during the execution phase, after all variables have been set and evaluated, it is not possible to get the output of makeparallel into a make variable. Instead, use a shell substitution to read the output file directly in a recipe. For example:

	echo Make was started with $$(cat make.jobs)