cmakexbuild.cxx 2.6 KB

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