cmakexbuild.cxx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 "cmConfigure.h" // IWYU pragma: keep
  4. #include "cmsys/Process.h"
  5. #include <iostream>
  6. #include <string>
  7. #include <vector>
  8. #include "cmSystemTools.h"
  9. // This is a wrapper program for xcodebuild
  10. // it calls xcodebuild, and does two things
  11. // it removes much of the output, all the setenv
  12. // stuff. Also, it checks for the text file busy
  13. // error, and re-runs xcodebuild until that error does
  14. // not show up.
  15. int RunXCode(std::vector<const char*>& argv, bool& hitbug)
  16. {
  17. hitbug = false;
  18. cmsysProcess* cp = cmsysProcess_New();
  19. cmsysProcess_SetCommand(cp, &*argv.begin());
  20. cmsysProcess_SetTimeout(cp, 0);
  21. cmsysProcess_Execute(cp);
  22. std::vector<char> out;
  23. std::vector<char> err;
  24. std::string line;
  25. int pipe = cmSystemTools::WaitForLine(cp, line, 100.0, out, err);
  26. while (pipe != cmsysProcess_Pipe_None) {
  27. if (line.find("/bin/sh: bad interpreter: Text file busy") !=
  28. std::string::npos) {
  29. hitbug = true;
  30. std::cerr << "Hit xcodebuild bug : " << line << "\n";
  31. }
  32. // if the bug is hit, no more output should be generated
  33. // because it may contain bogus errors
  34. // also remove all output with setenv in it to tone down
  35. // the verbosity of xcodebuild
  36. if (!hitbug && (line.find("setenv") == std::string::npos)) {
  37. if (pipe == cmsysProcess_Pipe_STDERR) {
  38. std::cerr << line << "\n";
  39. } else if (pipe == cmsysProcess_Pipe_STDOUT) {
  40. std::cout << line << "\n";
  41. }
  42. }
  43. pipe = cmSystemTools::WaitForLine(cp, line, 100, out, err);
  44. }
  45. cmsysProcess_WaitForExit(cp, 0);
  46. if (cmsysProcess_GetState(cp) == cmsysProcess_State_Exited) {
  47. return cmsysProcess_GetExitValue(cp);
  48. }
  49. if (cmsysProcess_GetState(cp) == cmsysProcess_State_Error) {
  50. return -1;
  51. }
  52. return -1;
  53. }
  54. int main(int ac, char* av[])
  55. {
  56. std::vector<const char*> argv;
  57. argv.push_back("xcodebuild");
  58. for (int i = 1; i < ac; i++) {
  59. argv.push_back(av[i]);
  60. }
  61. argv.push_back(0);
  62. bool hitbug = true;
  63. int ret = 0;
  64. while (hitbug) {
  65. ret = RunXCode(argv, hitbug);
  66. }
  67. if (ret < 0) {
  68. return 255;
  69. }
  70. return ret;
  71. }