Hi,

I'm using colorgcc 1.3.2 (Ubuntu package version 1.3.2.0-10).

While I generally like this tool, I think 2 issues are somewhat
annoying.

(1) One has to define all different kinds of compiler binaries
    (cpp, gcc, cc, c++, g++, ...) of all versions (3.3, 3.4, 4.0, ...)
    explicitly in its configuration file. I know the 'gccVersion'
    option, but it isn't of much use if using several different
    versions at once.
(2) colorgcc silently defaults to a default binary (/usr/bin/gcc, ...),
    which is the standard version on a platform, if nothing else
    is configured.

This took me several hours of searching, because I silently compiled
using the wrong compiler, that was already known to break builds.

So why doesn't colorgcc just search the compiler binary itself,
skipping those that are again symlinks to itself? This way one doesn't
have to configure the paths in colorgcc anymore and can fully rely on
the usual environment variables and build systems.

The attached patch tries to accomplish that and also lets the script die,
if it doesn't find a compiler.

ciao,
Mario

-- 
 Wo das Chaos auf die Ordnung trifft, gewinnt meist das Chaos,
 weil es besser organisiert ist.
     - Friedrich Nietzsche -

--
    _____    ________
   /     \  /   ____/  Mario Schwalbe
  /  \ /  \ \____  \
 /    Y    \/       \  eMail: schwa...@inf.tu-dresden.de,
 \____|__  /______  /         s4700...@inf.tu-dresden.de
         \/       \/

          key ID: 7DA9 DAFF
 key fingerprint: 2979 AA20 4A93 B527 90CC  45E5 4B28 511A 7DA9 DAFF
--- /usr/bin/colorgcc	2009-04-29 09:55:55.000000000 +0200
+++ local/scripts/colorgcc	2009-11-05 16:11:16.965312475 +0100
@@ -177,6 +177,32 @@ sub loadPreferences
    }
 }
 
+sub searchCompiler($$)
+{
+# Usage: searchCompiler($progName, $realName)
+#    $progName -- the compiler to look for without any path
+#    $realName -- the scripts' real name after following any symlinks
+
+   my ($progName, $realName) = @_;
+
+   foreach my $dir (split ':', $ENV{'PATH'})
+   {
+      my $compiler = $dir."/".$progName;
+      next unless (-l $compiler) || (-f $compiler);
+
+      if (defined (my $target = readlink $compiler)) {
+      	 # a link, but not to ourselves: use it
+      	 return $compiler if $target ne $realName;
+      }
+      else {
+      	 # not a link: use it
+      	 return $compiler;
+      }
+   }
+
+   return undef;
+}
+
 sub srcscan
 {
 # Usage: srcscan($text, $normalColor)
@@ -221,7 +247,15 @@ if (-f $configFile)
 $0 =~ m%.*/(.*)$%;
 $progName = $1 || $0;
 
-$compiler = $compilerPaths{$progName} || $compilerPaths{"gcc"};
+# Figure out which is our real script name. Might be an absolute path
+# depending on the symlink.
+$realName = readlink $0;
+
+# Maybe it's better to not use $compilerPaths{"gcc"} as default if the search
+# yields nothing and output an error message instead.
+$compiler = $compilerPaths{$progName} || searchCompiler($progName, $realName);
+die "$realName: no compiler found that provides '$progName'\n" unless defined $compiler;
+
 @comp_list = split /\s+/, $compiler;
 $compiler = $comp_list[0];
 @comp_args = ( @comp_list[1 .. $#comp_list], @ARGV );
@@ -274,7 +308,7 @@ while(<GCCOUT>)
 	 print($colors{"warningNumberColor"}, "$field2:", color("reset"));
 	 srcscan($field3, $colors{"warningMessageColor"});
       }
-      else 
+      else
       {
 	 # Error
 	 print($colors{"errorFileNameColor"}, "$field1:", color("reset"));
@@ -329,7 +363,3 @@ while(<GCCOUT>)
 waitpid($compiler_pid, 0);
 exit ($? >> 8);
 
-
-
-
-

Attachment: signature.asc
Description: OpenPGP digital signature

-- 
Ubuntu-motu mailing list
Ubuntu-motu@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/ubuntu-motu

Reply via email to