[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    icecream/client
From:       Luboš Luňák <l.lunak () kde ! org>
Date:       2012-07-08 8:56:02
Message-ID: 20120708085602.2082EAC7A9 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1304575 by lunakl:

clang has its own color support, use that instead of icecream's own



 M  +11 -0     arg.cpp  
 M  +1 -0      client.h  
 M  +6 -1      local.cpp  
 M  +1 -1      remote.cpp  
 M  +16 -2     util.cpp  
 M  +2 -1      util.h  


--- trunk/icecream/client/arg.cpp #1304574:1304575
@@ -110,6 +110,7 @@
     bool seen_s = false;
     bool seen_mf = false;
     bool seen_md = false;
+    bool fno_color_diagnostics = false;
     if( icerun ) {
         always_local = true;
         job.setLanguage( CompileJob::Lang_Custom );
@@ -293,6 +294,12 @@
                  || str_equal("-MG", a)
                  || str_equal("-MP", a)) {
                 args.append(a, Arg_Local);
+            } else if (str_equal("-fno-color-diagnostics", a)) {
+                fno_color_diagnostics = true;
+                args.append( a, Arg_Rest );
+            } else if (str_equal("-fcolor-diagnostics", a)) {
+                fno_color_diagnostics = false;
+                args.append( a, Arg_Rest );
             } else
                 args.append( a, Arg_Rest );
         } else {
@@ -402,6 +409,10 @@
     if ( ofile.empty() || (!stat( ofile.c_str(), &st ) && !S_ISREG( st.st_mode )))
         always_local = true;
 
+    // redirecting Clang's output will turn off its automatic coloring, so force it, unless disabled
+    if (compiler_is_clang(job.language()) && colorify_possible() && !fno_color_diagnostics)
+        args.append("-fcolor-diagnostics", Arg_Rest);
+
     job.setFlags( args );
     job.setOutputFile( ofile );
 
--- trunk/icecream/client/client.h #1304574:1304575
@@ -49,6 +49,7 @@
 extern int build_local (CompileJob& job, MsgChannel *daemon, struct rusage *usage =0);
 extern std::string find_compiler( CompileJob::Language lang );
 extern std::string find_compiler( const CompileJob& job );
+extern bool compiler_is_clang( CompileJob::Language lang );
 
 /* In remote.cpp - permill is the probability it will be compiled three times */
 extern int build_remote (CompileJob &job, MsgChannel *scheduler, const Environments &envs, int permill);
--- trunk/icecream/client/local.cpp #1304574:1304575
@@ -143,6 +143,11 @@
     return path_lookup(compiler);
 }
 
+bool compiler_is_clang( CompileJob::Language lang )
+{
+    return get_compiler_name( lang ).find("clang") != string::npos;
+}
+
 static volatile int lock_fd = 0;
 static volatile int user_break_signal = 0;
 static volatile pid_t child_pid;
@@ -220,7 +225,7 @@
     }
 
     bool color_output = job.language() != CompileJob::Lang_Custom
-        && colorify_wanted();
+        && colorify_wanted(job.language());
     int pf[2];
 
     if (color_output && pipe(pf))
--- trunk/icecream/client/remote.cpp #1304574:1304575
@@ -423,7 +423,7 @@
     {
         write(STDOUT_FILENO, crmsg->out.c_str(), crmsg->out.size() );
 
-        if(colorify_wanted())
+        if(colorify_wanted(job.language()))
             colorify_output(crmsg->err);
         else
             write(STDERR_FILENO, crmsg->err.c_str(), crmsg->err.size() );
--- trunk/icecream/client/util.cpp #1304574:1304575
@@ -37,7 +37,9 @@
 #include <sys/stat.h>
 #include <sys/file.h>
 
+#include "client.h"
 #include "exitcode.h"
+#include "job.h"
 #include "logging.h"
 #include "util.h"
 
@@ -201,13 +203,25 @@
     }
 }
 
-bool colorify_wanted()
+bool colorify_possible()
 {
   const char* term_env = getenv("TERM");
 
-  return isatty(2) && !getenv("EMACS") && term_env && strcasecmp(term_env, "DUMB");
+  return isatty(2) && term_env && strcasecmp(term_env, "DUMB");
 }
 
+bool colorify_wanted(CompileJob::Language lang)
+{
+    // Clang has coloring, and an explicit option to force it even if output is not a tty.
+    if (compiler_is_clang(lang))
+        return false;
+
+    if (getenv("EMACS"))
+        return false;
+
+    return colorify_possible();
+}
+
 void colorify_output(const string& _s_ccout)
 {
     string s_ccout(_s_ccout);
--- trunk/icecream/client/util.h #1304574:1304575
@@ -28,7 +28,8 @@
 
 extern std::string find_basename(const std::string &sfile);
 extern void colorify_output(const std::string &s_ccout);
-extern bool colorify_wanted();
+extern bool colorify_wanted(CompileJob::Language lang);
+extern bool colorify_possible();
 
 extern bool dcc_unlock(int lock_fd);
 extern bool dcc_lock_host(int &lock_fd);
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic