packaging: Initial packaging
[platform/upstream/cmake.git] / Source / cmakexbuild.cxx
1 /*============================================================================
2   CMake - Cross Platform Makefile Generator
3   Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
4
5   Distributed under the OSI-approved BSD License (the "License");
6   see accompanying file Copyright.txt for details.
7
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"
15
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
21 // not show up.
22
23 int RunXCode(std::vector<const char*>& argv, bool& hitbug)
24 {
25   hitbug = false;
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;
32   std::string line;
33   int pipe = cmSystemTools::WaitForLine(cp, line, 100.0, out, err);
34   while(pipe != cmsysProcess_Pipe_None)
35     {
36     if(line.find("/bin/sh: bad interpreter: Text file busy")
37        != line.npos)
38       {
39       hitbug = true;
40       std::cerr << "Hit xcodebuild bug : " << line << "\n";
41       }
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))
47       {
48       if(pipe == cmsysProcess_Pipe_STDERR)
49         {
50         std::cerr << line << "\n";
51         }
52       else if(pipe == cmsysProcess_Pipe_STDOUT)
53         {
54         std::cout << line << "\n";
55         }
56       }
57     pipe = cmSystemTools::WaitForLine(cp, line, 100, out, err);
58     }
59   cmsysProcess_WaitForExit(cp, 0);
60   if(cmsysProcess_GetState(cp) == cmsysProcess_State_Exited)
61     {
62     return cmsysProcess_GetExitValue(cp);
63     }
64   if(cmsysProcess_GetState(cp) == cmsysProcess_State_Error)
65     {
66     return -1;
67     }
68   return -1;
69 }
70
71 int main(int ac, char*av[])
72 {
73   std::vector<const char*> argv;
74   argv.push_back("xcodebuild");
75   for(int i =1; i < ac; i++)
76     {
77     argv.push_back(av[i]);
78     }
79   argv.push_back(0);
80   bool hitbug = true;
81   int ret = 0;
82   while(hitbug)
83     {
84     ret = RunXCode(argv, hitbug);
85     }
86   if(ret < 0)
87     {
88     return 255;
89     }
90   return ret;
91 }
92