简体   繁体   中英

Debugging CMake/Make dependencies for a parallel build

I manage for work a complex C++ project, whose build definitions are written in CMake and the build itself is obtained by invoking make . The source tree is composed by many modules and it is highly parallelizable.

A linear build always succeeds, while a parallel build is successful most of the times. When a dependency problem is encountered during such a build, I usually go and fix it, but I would like to test dependencies programmatically, instead of fixing problems as they occur.

The ideal solution would be to go through all dependencies in CMake and fix them, but this is not always possible in practice, because we make heavy use of custom macros for some kind of dependencies that are specific to our source tree (I cannot go into details, sorry). So, I was thinking of solving the problem differently (and, possibly, efficiently), trying to reuse standard tools as much as possible.

  1. My first thought was injecting some kind of "randomness" in the Make job scheduling, so a building machine could try indefinitely to exercise different compilation paths by rebuilding the tree until a failure is encountered. Another question (here) , however, pointed out that this feature is not available in Make .

  2. So i tried with another solution: I created a wrapper script around g++ that sleeps for a $RANDOM number of seconds, to bring some noise in the Make jobs scheduler. The downside of this solution is, of course, an increased compilation time.
    This partial solution, however, has a fundamental flaw: if a problem is found, it is proof that a dependency is missing, but, if no error is generated, we cannot prove that all dependencies are correct.

What do you think? How could I achieve my goal? I would prefer solutions that reuse standard tools and can be applied to a wide audience.

Thanks.

I think you need to use a better make if you really want to solve this problem efficiently. Electric Make (part of ElectricAccelerator) is a GNU make-compatible variant of make which monitors the filesystem access during your build and will automatically detect and correct problems caused by out-of-order execution . In addition, ElectricMake can generate an annotated build log that will show you which files were accessed by each job in the build, as well as the dependencies (explicit and implicit) between the jobs, which you could use to correct missing dependencies in your makefiles.

You can download and try ElectricAccelerator Huddle , the freemium version of ElectricAccelerator.

Disclaimer: I am the architect and technical lead for ElectricAccelerator.

You might try analyzing the dependencies themselves. Cmake can generate dependency graphs in dot/graphviz fairly easily: http://www.cmake.org/Wiki/CMake:For_CMake_Hackers

Some graph theory might help in your analysis: http://en.wikipedia.org/wiki/Graph_theory

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM