diff options
Diffstat (limited to 'Source/cmcmd.cxx')
-rw-r--r-- | Source/cmcmd.cxx | 102 |
1 files changed, 44 insertions, 58 deletions
diff --git a/Source/cmcmd.cxx b/Source/cmcmd.cxx index 2ac9d8e..94f4d38 100644 --- a/Source/cmcmd.cxx +++ b/Source/cmcmd.cxx @@ -11,6 +11,8 @@ #include <cm3p/uv.h> #include <fcntl.h> +#include "cm_fileno.hxx" + #include "cmCommandLineArgument.h" #include "cmConsoleBuf.h" #include "cmCryptoHash.h" @@ -72,7 +74,6 @@ #include "cmsys/Directory.hxx" #include "cmsys/FStream.hxx" -#include "cmsys/Process.h" #include "cmsys/RegularExpression.hxx" #include "cmsys/Terminal.h" @@ -295,14 +296,8 @@ int CLCompileAndDependencies(const std::vector<std::string>& args) } } - std::unique_ptr<cmsysProcess, void (*)(cmsysProcess*)> cp( - cmsysProcess_New(), cmsysProcess_Delete); - std::vector<const char*> argv(command.size() + 1); - std::transform(command.begin(), command.end(), argv.begin(), - [](std::string const& s) { return s.c_str(); }); - argv.back() = nullptr; - cmsysProcess_SetCommand(cp.get(), argv.data()); - cmsysProcess_SetWorkingDirectory(cp.get(), currentBinaryDir.c_str()); + cmUVProcessChainBuilder builder; + builder.AddCommand(command).SetWorkingDirectory(currentBinaryDir); cmsys::ofstream fout(depFile.c_str()); if (!fout) { @@ -313,22 +308,18 @@ int CLCompileAndDependencies(const std::vector<std::string>& args) CLOutputLogger errLogger(std::cerr); // Start the process. - cmProcessTools::RunProcess(cp.get(), &includeParser, &errLogger); + auto result = + cmProcessTools::RunProcess(builder, &includeParser, &errLogger); + auto const& subStatus = result.front(); int status = 0; // handle status of process - switch (cmsysProcess_GetState(cp.get())) { - case cmsysProcess_State_Exited: - status = cmsysProcess_GetExitValue(cp.get()); - break; - case cmsysProcess_State_Exception: - status = 1; - break; - case cmsysProcess_State_Error: - status = 2; - break; - default: - break; + if (subStatus.SpawnResult != 0) { + status = 2; + } else if (subStatus.TermSignal != 0) { + status = 1; + } else { + status = static_cast<int>(subStatus.ExitStatus); } if (status != 0) { @@ -1116,7 +1107,8 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args, int ret = 0; auto time_start = std::chrono::steady_clock::now(); - cmSystemTools::RunSingleCommand(command, nullptr, nullptr, &ret); + cmSystemTools::RunSingleCommand(command, nullptr, nullptr, &ret, nullptr, + cmSystemTools::OUTPUT_PASSTHROUGH); auto time_finish = std::chrono::steady_clock::now(); std::chrono::duration<double> time_elapsed = time_finish - time_start; @@ -1892,21 +1884,6 @@ int cmcmd::ExecuteLinkScript(std::vector<std::string> const& args) } } - // Allocate a process instance. - cmsysProcess* cp = cmsysProcess_New(); - if (!cp) { - std::cerr << "Error allocating process instance in link script." - << std::endl; - return 1; - } - - // Children should share stdout and stderr with this process. - cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDOUT, 1); - cmsysProcess_SetPipeShared(cp, cmsysProcess_Pipe_STDERR, 1); - - // Run the command lines verbatim. - cmsysProcess_SetOption(cp, cmsysProcess_Option_Verbatim, 1); - // Read command lines from the script. cmsys::ifstream fin(args[2].c_str()); if (!fin) { @@ -1924,9 +1901,24 @@ int cmcmd::ExecuteLinkScript(std::vector<std::string> const& args) continue; } + // Allocate a process instance. + cmUVProcessChainBuilder builder; + + // Children should share stdout and stderr with this process. + builder + .SetExternalStream(cmUVProcessChainBuilder::Stream_OUTPUT, + cm_fileno(stdout)) + .SetExternalStream(cmUVProcessChainBuilder::Stream_ERROR, + cm_fileno(stderr)); + // Setup this command line. - const char* cmd[2] = { command.c_str(), nullptr }; - cmsysProcess_SetCommand(cp, cmd); + std::vector<std::string> args2; +#ifdef _WIN32 + cmSystemTools::ParseWindowsCommandLine(command.c_str(), args2); +#else + cmSystemTools::ParseUnixCommandLine(command.c_str(), args2); +#endif + builder.AddCommand(args2); // Report the command if verbose output is enabled. if (verbose) { @@ -1934,35 +1926,29 @@ int cmcmd::ExecuteLinkScript(std::vector<std::string> const& args) } // Run the command and wait for it to exit. - cmsysProcess_Execute(cp); - cmsysProcess_WaitForExit(cp, nullptr); + auto chain = builder.Start(); + chain.Wait(); // Report failure if any. - switch (cmsysProcess_GetState(cp)) { - case cmsysProcess_State_Exited: { - int value = cmsysProcess_GetExitValue(cp); - if (value != 0) { - result = value; + auto const& status = chain.GetStatus(0); + auto exception = status.GetException(); + switch (exception.first) { + case cmUVProcessChain::ExceptionCode::None: + if (status.ExitStatus != 0) { + result = static_cast<int>(status.ExitStatus); } - } break; - case cmsysProcess_State_Exception: - std::cerr << "Error running link command: " - << cmsysProcess_GetExceptionString(cp) << std::endl; - result = 1; break; - case cmsysProcess_State_Error: - std::cerr << "Error running link command: " - << cmsysProcess_GetErrorString(cp) << std::endl; + case cmUVProcessChain::ExceptionCode::Spawn: + std::cerr << "Error running link command: " << exception.second; result = 2; break; default: + std::cerr << "Error running link command: " << exception.second; + result = 1; break; } } - // Free the process instance. - cmsysProcess_Delete(cp); - // Return the final resulting return value. return result; } |