Add support for controlling the number of jobs used by some cmake tasks#107
Add support for controlling the number of jobs used by some cmake tasks#107KazNX wants to merge 10 commits into
Conversation
- Add support for `build` arg `--cmake-jobs` to set the number of jobs to use. - Rename `_get_make_arguments()` to `_get_make_jobs_arguments()` for clarity
d1b7eb0 to
3b8132e
Compare
|
PR has been rebased onto master fixing the CI check failures. |
Slight reorganisation to change jobs variable initialisation. Co-authored-by: Michel Hidalgo <michel@ekumenlabs.com>
Rename `is_job_base_generator` to `is_job_based_generator` to be more correct
This better reflects the nature of the function.
hidmic
left a comment
There was a problem hiding this comment.
This looks great to me, but I'd appreciate @dirk-thomas or @cottsay input as well.
cottsay
left a comment
There was a problem hiding this comment.
Doesn't simply specifying the CMAKE_BUILD_PARALLEL_LEVEL environment variable work for Ninja?
| type=int, | ||
| help='Number of jobs to use for supported generators (e.g., Ninja ' | ||
| 'Makefiles). Negative values subtract from the maximum ' | ||
| 'available, so --jobs=-1 uses all bar 1 available threads.') |
There was a problem hiding this comment.
| 'available, so --jobs=-1 uses all bar 1 available threads.') | |
| 'available, so --jobs=-1 uses all but 1 available threads.') |
Co-authored-by: Michel Hidalgo <michel@ekumenlabs.com>
KazNX
left a comment
There was a problem hiding this comment.
Doesn't simply specifying the
CMAKE_BUILD_PARALLEL_LEVELenvironment variable work for Ninja?
@cottsay Not sure, but it was introduced in CMake 3.12. I'm working with baseline support for 3.10 as ships with Ubuntu 18.04.
| :rtype: bool | ||
| """ | ||
| known_jobs_base_multi_configuration_generators = ( | ||
| 'Ninja Multi-Config', |
There was a problem hiding this comment.
I originally made this change on top of PR 106 then pulled this out. You can view this as a defensive or pre-emptive change. It should have little to no impact until then as the ninja multi-config won't really work yet.
| cmd += ['--config', self._get_configuration(args)] | ||
| else: | ||
| job_args = self._get_make_arguments(env) | ||
| if jobs_base_generator: |
There was a problem hiding this comment.
Similarly, the removal of the else and replacing it with this separate condition check relates to ninja multi-config support, but should have no impact in isolation.
| # Finalise jobs as as CPU count deducting the limit specified. | ||
| jobs = max(jobs + jobs_args, 1) | ||
| return [ | ||
| '-j{jobs}'.format_map(locals()), |
There was a problem hiding this comment.
The rename of the function is based on this result. It can only return jobs. Will revert if appropriate.
| cmd += ['--config', self._get_configuration(args)] | ||
| elif allow_job_args: | ||
| job_args = self._get_make_arguments(env) | ||
| if allow_job_args: |
There was a problem hiding this comment.
This elif to if change also supports ninja multi-config.
| type=int, | ||
| help='Number of jobs to use for supported generators (e.g., Ninja ' | ||
| 'Makefiles). Negative values subtract from the maximum ' | ||
| 'available, so --jobs=-1 uses all bar 1 available threads.') |
|
@cottsay Looking at the CMake 3.12 release notes, it looks like they added This changes the context of this PR a bit and I see the need to revise the original code I modified to deal with that as well. I propose the ideal solution is to use the changes I've made with CMake < 3.12. For CMake 3.12+, change this function to return My question is, are the changes better made in this PR or a to push this through and start a new PR? |
I see two conceptual changes:
The latter can be done in this PR, I think. The former should probably be done in a new PR. Thoughts? |
I fully agree with point 1, but would add that it's not just using On point 2, the deprecation warning only makes sense if Again, I need more information aboug how the command line arguments interact with |
|
FYI,
|
Revised how jobs are specified. For cmake 3.12+, we use `cmake --build -jN`. For cmake < 3.12, we use `cmake --build [args] -- -jN -lN`, but only for Ninja and Makefiles generators. Note we no longer check if we have a jobs based generator. This is now managed internally to `_get_jobs_arguments()`. Also note we now add `--` inside `_get_jobs_arguments()` as it is not needed for CMake 3.12+
|
@cottsay @hidmic The changes are summaried as:
Note we no longer check if we have a jobs based generator. This is now managed internally to Also note we now add |
|
Since I don't have the spare time to review this change I leave it up to the co-maintainers to review and test this. A general - fairly significant - concern I have: the Travis CI integration for all |
Neither this PR nor master are getting test coverage on Linux or macOS because of the missing Travis builds.
I'm still not feeling great about merging a PR that adds a command line option to support such a narrow use case, especially one that has an official mechanism available in newer versions of CMake. Here's a completely different suggestion - could we expose a free-form |
Yes, I like this option. It does mean removing the |
|
I've created a new PR for the I managed to maintain We can deprecate this PR if the 110 is the preferred solution. |
This change adds support for
buildarg--cmake-jobsto set the number of jobs to use to preserve CPU for the OS. It also renames_get_make_arguments()to_get_make_jobs_arguments()to better reflect the responsibilities of the function.There is currently support to set the number of job threads to the maximum available, unless the
MAKEFLAGSenvironment variable is set. The assumption is thatMAKEFLAGSwill be used by the build framework to control the number of jobs. However, this is only true formake- as far as I can tell,ninjadoes not have any such environment variable based control (related issues reported against ninja 922, 1482).When
MAKEFLAGSis not set, colcon will maxout the-jargument for ninja. Since ninja is so efficient, this can make the computer unresponsive for the OS and other applications. This change has been made to allow the OS to remain somewhat responsive.As part of the change, I noted that
_get_make_arguments()appears to be misnamed as the only thing it does is set the number of jobs to use, as evidenced by the use of the returned values. I've renamed it_get_make_jobs_arguments()to better reflect this. Happy to revert this change if required.The
--cmake-jobsargs supports the following usage patterns: