cmakexbuild.cxx 2.0 KB

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