cmSetTestsPropertiesCommand.cxx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmSetTestsPropertiesCommand.h"
  4. #include <iterator>
  5. #include <cmext/algorithm>
  6. #include "cmExecutionStatus.h"
  7. #include "cmMakefile.h"
  8. #include "cmStringAlgorithms.h"
  9. #include "cmTest.h"
  10. static bool SetOneTest(const std::string& tname,
  11. std::vector<std::string>& propertyPairs, cmMakefile* mf,
  12. std::string& errors);
  13. bool cmSetTestsPropertiesCommand(std::vector<std::string> const& args,
  14. cmExecutionStatus& status)
  15. {
  16. if (args.empty()) {
  17. status.SetError("called with incorrect number of arguments");
  18. return false;
  19. }
  20. cmMakefile& mf = status.GetMakefile();
  21. // first collect up the list of files
  22. std::vector<std::string> propertyPairs;
  23. int numFiles = 0;
  24. std::vector<std::string>::const_iterator j;
  25. for (j = args.begin(); j != args.end(); ++j) {
  26. if (*j == "PROPERTIES") {
  27. // now loop through the rest of the arguments, new style
  28. ++j;
  29. if (std::distance(j, args.end()) % 2 != 0) {
  30. status.SetError("called with incorrect number of arguments.");
  31. return false;
  32. }
  33. cm::append(propertyPairs, j, args.end());
  34. break;
  35. }
  36. numFiles++;
  37. }
  38. if (propertyPairs.empty()) {
  39. status.SetError("called with illegal arguments, maybe "
  40. "missing a PROPERTIES specifier?");
  41. return false;
  42. }
  43. // now loop over all the targets
  44. int i;
  45. for (i = 0; i < numFiles; ++i) {
  46. std::string errors;
  47. bool ret = SetOneTest(args[i], propertyPairs, &mf, errors);
  48. if (!ret) {
  49. status.SetError(errors);
  50. return ret;
  51. }
  52. }
  53. return true;
  54. }
  55. static bool SetOneTest(const std::string& tname,
  56. std::vector<std::string>& propertyPairs, cmMakefile* mf,
  57. std::string& errors)
  58. {
  59. if (cmTest* test = mf->GetTest(tname)) {
  60. // now loop through all the props and set them
  61. unsigned int k;
  62. for (k = 0; k < propertyPairs.size(); k = k + 2) {
  63. if (!propertyPairs[k].empty()) {
  64. test->SetProperty(propertyPairs[k], propertyPairs[k + 1].c_str());
  65. }
  66. }
  67. } else {
  68. errors = cmStrCat("Can not find test to add properties to: ", tname);
  69. return false;
  70. }
  71. return true;
  72. }