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