cmCTestRunScriptCommand.cxx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file LICENSE.rst or https://cmake.org/licensing for details. */
  3. #include "cmCTestRunScriptCommand.h"
  4. #include <vector>
  5. #include "cmCTestScriptHandler.h"
  6. #include "cmExecutionStatus.h"
  7. #include "cmMakefile.h"
  8. #include "cmSystemTools.h"
  9. bool cmCTestRunScriptCommand::InitialPass(std::vector<std::string> const& args,
  10. cmExecutionStatus& status) const
  11. {
  12. if (args.empty()) {
  13. status.SetError("called with incorrect number of arguments");
  14. return false;
  15. }
  16. cmMakefile& mf = status.GetMakefile();
  17. bool np = false;
  18. unsigned int i = 0;
  19. if (args[i] == "NEW_PROCESS") {
  20. np = true;
  21. i++;
  22. }
  23. int start = i;
  24. // run each script
  25. std::string returnVariable;
  26. for (i = start; i < args.size(); ++i) {
  27. if (args[i] == "RETURN_VALUE") {
  28. ++i;
  29. if (i < args.size()) {
  30. returnVariable = args[i];
  31. }
  32. }
  33. }
  34. for (i = start; i < args.size(); ++i) {
  35. if (args[i] == "RETURN_VALUE") {
  36. ++i;
  37. } else {
  38. int ret;
  39. cmCTestScriptHandler::RunScript(
  40. this->CTest, &mf, cmSystemTools::CollapseFullPath(args[i]), !np, &ret);
  41. mf.AddDefinition(returnVariable, std::to_string(ret));
  42. }
  43. }
  44. return true;
  45. }