فهرست منبع

RunSingleCommand: Add a OUTPUT_NORMAL flag.

OUTPUT_NORMAL does no processing of the output streams, it just passes
them through the same streams as they were received on.
Johan Björk 14 سال پیش
والد
کامیت
642f10066a
5فایلهای تغییر یافته به همراه40 افزوده شده و 8 حذف شده
  1. 21 1
      Source/cmSystemTools.cxx
  2. 7 2
      Source/cmSystemTools.h
  3. 3 3
      Source/cmake.cxx
  4. 2 1
      Source/cmake.h
  5. 7 1
      Source/cmakemain.cxx

+ 21 - 1
Source/cmSystemTools.cxx

@@ -247,6 +247,12 @@ void cmSystemTools::Stdout(const char* s)
     }
 }
 
+void cmSystemTools::Stderr(const char* s, int length)
+{
+    std::cerr.write(s, length);
+    std::cerr.flush();
+}
+
 void cmSystemTools::Stdout(const char* s, int length)
 {
   if(s_StdoutCallback)
@@ -630,7 +636,21 @@ bool cmSystemTools::RunSingleCommand(std::vector<cmStdString>const& command,
         }
       if(outputflag != OUTPUT_NONE)
         {
-        cmSystemTools::Stdout(data, length);
+        if(outputflag == OUTPUT_MERGE)
+          {
+          cmSystemTools::Stdout(data, length);
+          }
+        else
+          {
+          if(pipe == cmsysProcess_Pipe_STDERR)
+            {
+            cmSystemTools::Stderr(data, length);
+            }
+          else if(pipe == cmsysProcess_Pipe_STDOUT)
+            {
+            cmSystemTools::Stdout(data, length);
+            }
+          }
         }
       }
     }

+ 7 - 2
Source/cmSystemTools.h

@@ -75,6 +75,9 @@ public:
   typedef  void (*StdoutCallback)(const char*, int length, void*);
   static void SetStdoutCallback(StdoutCallback, void* clientData=0);
 
+  ///! Send a string to stderr. Stdout callbacks will not be invoced.
+  static void Stderr(const char* s, int length);
+
   ///! Return true if there was an error at any point.
   static bool GetErrorOccuredFlag()
     {
@@ -196,7 +199,8 @@ public:
    * Output is controlled with outputflag. If outputflag is OUTPUT_NONE, no
    * user-viewable output from the program being run will be generated.
    * OUTPUT_MERGE is the legacy behaviour where stdout and stderr are merged
-   * into stdout.
+   * into stdout.  OUTPUT_NORMAL passes through the output to stdout/stderr as
+   * it was received.
    *
    * If timeout is specified, the command will be terminated after
    * timeout expires. Timeout is specified in seconds.
@@ -214,7 +218,8 @@ public:
    enum OutputOption
    {
      OUTPUT_NONE = 0,
-     OUTPUT_MERGE
+     OUTPUT_MERGE,
+     OUTPUT_NORMAL
    };
   static bool RunSingleCommand(const char* command, std::string* output = 0,
                                int* retVal = 0, const char* dir = 0,

+ 3 - 3
Source/cmake.cxx

@@ -4296,7 +4296,8 @@ int cmake::Build(const std::string& dir,
                  const std::string& target,
                  const std::string& config,
                  const std::vector<std::string>& nativeOptions,
-                 bool clean)
+                 bool clean,
+                 cmSystemTools::OutputOption outputflag)
 {
   if(!cmSystemTools::FileIsDirectory(dir.c_str()))
     {
@@ -4338,8 +4339,7 @@ int cmake::Build(const std::string& dir,
                     projName.c_str(), target.c_str(),
                     &output,
                     makeProgram.c_str(),
-                    config.c_str(), clean, false, 0,
-                    cmSystemTools::OUTPUT_MERGE,
+                    config.c_str(), clean, false, 0, outputflag,
                     0, nativeOptions);
 }
 

+ 2 - 1
Source/cmake.h

@@ -364,7 +364,8 @@ class cmake
             const std::string& target,
             const std::string& config,
             const std::vector<std::string>& nativeOptions,
-            bool clean);
+            bool clean,
+            cmSystemTools::OutputOption outputflag);
 
   void UnwatchUnusedCli(const char* var);
   void WatchUnusedCli(const char* var);

+ 7 - 1
Source/cmakemain.cxx

@@ -62,6 +62,7 @@ static const char * cmDocumentationDescription[][3] =
   "  --config <cfg> = For multi-configuration tools, choose <cfg>.\n"   \
   "  --clean-first  = Build target 'clean' first, then build.\n"        \
   "                   (To clean only, use --target 'clean'.)\n"         \
+  "  --use-stderr  =  Don't merge stdout/stderr.\n"                     \
   "  --             = Pass remaining options to the native tool.\n"
 
 //----------------------------------------------------------------------------
@@ -568,6 +569,7 @@ static int do_build(int ac, char** av)
   std::string dir;
   std::vector<std::string> nativeOptions;
   bool clean = false;
+  cmSystemTools::OutputOption outputflag = cmSystemTools::OUTPUT_MERGE;
 
   enum Doing { DoingNone, DoingDir, DoingTarget, DoingConfig, DoingNative};
   Doing doing = DoingDir;
@@ -590,6 +592,10 @@ static int do_build(int ac, char** av)
       clean = true;
       doing = DoingNone;
       }
+    else if(strcmp(av[i], "--use-stderr") == 0)
+      {
+        outputflag = cmSystemTools::OUTPUT_NORMAL;
+      }
     else if(strcmp(av[i], "--") == 0)
       {
       doing = DoingNative;
@@ -635,6 +641,6 @@ static int do_build(int ac, char** av)
     }
 
   cmake cm;
-  return cm.Build(dir, target, config, nativeOptions, clean);
+  return cm.Build(dir, target, config, nativeOptions, clean, outputflag);
 #endif
 }