* Called by ctest --start-instrumentation. * * This creates a detached process which waits for the parent process (i.e., * the build system) to die before running the postBuild hook. In this way, the * postBuild hook triggers after every invocation of the build system, * regardless of whether the build passed or failed. */
| 842 | * regardless of whether the build passed or failed. |
| 843 | */ |
| 844 | int cmInstrumentation::SpawnBuildDaemon() |
| 845 | { |
| 846 | // Do not inherit handles from the parent process, so that the daemon is |
| 847 | // fully detached. This helps prevent deadlock between the two. |
| 848 | uv_disable_stdio_inheritance(); |
| 849 | |
| 850 | // preBuild Hook |
| 851 | if (this->LockBuildDaemon()) { |
| 852 | // Release lock before spawning the build daemon, to prevent blocking it. |
| 853 | this->buildLock.Release(); |
| 854 | this->CollectTimingData(cmInstrumentationQuery::Hook::PreBuild); |
| 855 | } |
| 856 | |
| 857 | // postBuild Hook |
| 858 | auto ppid = uv_os_getppid(); |
| 859 | if (ppid) { |
| 860 | std::vector<std::string> args; |
| 861 | args.push_back(cmSystemTools::GetCTestCommand()); |
| 862 | args.push_back("--wait-and-collect-instrumentation"); |
| 863 | args.push_back(this->binaryDir); |
| 864 | args.push_back(std::to_string(ppid)); |
| 865 | auto builder = cmUVProcessChainBuilder().SetDetached().AddCommand(args); |
| 866 | auto chain = builder.Start(); |
| 867 | uv_run(&chain.GetLoop(), UV_RUN_DEFAULT); |
| 868 | } |
| 869 | return 0; |
| 870 | } |
| 871 | |
| 872 | // Prevent multiple build daemons from running simultaneously |
| 873 | bool cmInstrumentation::LockBuildDaemon() |