On Sun, Jun 19, 2011 at 09:06:02PM +0100, Roger Leigh wrote:
> On Sun, Jun 19, 2011 at 09:54:07PM +0200, Cyril Brulebois wrote:
> > Roger Leigh <[email protected]> (19/06/2011):
> > > I've committed a patch for this onto git master.  Lintian passes are
> > > highlighted in green, failures in red.
> > 
> > Thanks.
> > 
> > > If there are any other parts of the build log you would like
> > > highlighting in the same way, it's just a list of regexes in
> > > Sbuild::Build::open_build_log that are checked in the logger
> > > process.
> > 
> > It might be a good idea to highlight packages not targetting unstable
> > (remember ifupdown? :p), so some random colour for the “Distribution:
> > experimental” (and others), maybe?
> 
> That would be very useful.  It's easy enough to get the
> distribution from the changelog and check if it's different.
> Passing it to the logger process will be a little harder
> though--it's a coprocess which receives the output from
> sbuild, dpkg-buildpackage and all their child processes,
> and then sends it on to the logfile, terminal etc.
> I'll have to consider how best to pass the information over
> since we don't know at the time the logger is started.

diff --git a/NEWS b/NEWS
index 4f2967c..4cffeb1 100644
--- a/NEWS
+++ b/NEWS
@@ -9,7 +9,11 @@ configuration.
 
 * Major changes in 0.62.4:
 
-  None.
+  1) The distribution in the build summary is coloured yellow if it
+     does not match the distribution in the changelog.  This is to
+     indicate that there may be a potential problem, such as
+     potentially uploading a package intended for experimental to
+     unstable by building for unstable by accident.
 
 * Major changes in 0.62.3:
 
diff --git a/debian/changelog b/debian/changelog
index 82dc0ae..f5be697 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -3,8 +3,13 @@ sbuild (0.62.4-1) unstable; urgency=low
   * New release.
   * Failing lintian checks are highlighted in red, and passes in
     green (Closes: #631060).
+  * The distribution in the build summary is coloured yellow if it
+    does not match the distribution in the changelog.  This is to
+    indicate that there may be a potential problem, such as 
+    potentially uploading a package intended for experimental to
+    unstable by building for unstable by accident.
 
- -- Roger Leigh <[email protected]>  Sun, 19 Jun 2011 20:41:35 +0100
+ -- Roger Leigh <[email protected]>  Sun, 19 Jun 2011 22:34:01 +0100
 
 sbuild (0.62.3-1) unstable; urgency=low
 
diff --git a/lib/Sbuild/Build.pm b/lib/Sbuild/Build.pm
index 8ec7684..d31c1e1 100644
--- a/lib/Sbuild/Build.pm
+++ b/lib/Sbuild/Build.pm
@@ -473,6 +473,17 @@ sub run_chroot_session {
                           DIR =>  $session->get('Location') . "/build"));
 
        $self->set('Build Dir', $session->strip_chroot_path($self->get('Chroot 
Build Dir')));
+
+       # Log colouring
+       $self->build_log_colour('red', '^E: ');
+       $self->build_log_colour('yellow', '^W: ');
+       $self->build_log_colour('green', '^I: ');
+       $self->build_log_colour('red', '^Status:');
+       $self->build_log_colour('green', '^Status: successful$');
+       $self->build_log_colour('red', '^Lintian:');
+       $self->build_log_colour('green', '^Lintian: pass$');
+
+       # Log filtering
        my $filter;
        $filter = $self->get('Build Dir') . '/' . $self->get('DSC Dir');
        $filter =~ s;^/;;;
@@ -483,6 +494,7 @@ sub run_chroot_session {
        $filter = $session->get('Location');
        $filter =~ s;^/;;;
        $self->build_log_filter($filter , 'CHROOT');
+
        # Need tempdir to be writable and readable by sbuild group.
        $self->check_abort();
        $session->run_command(
@@ -1335,6 +1347,28 @@ sub build {
        }
     }
 
+    my $pipe = $self->get('Session')->pipe_command(
+       { COMMAND => ['dpkg-parsechangelog'],
+         USER => $self->get_conf('BUILD_USER'),
+         PRIORITY => 0,
+         DIR => $self->get('Session')->strip_chroot_path($dscdir) });
+    my $clog = do { local $/; <$pipe> };
+    close($pipe);
+    if ($?) {
+       $self->log("FAILED [dpkg-parsechangelog died]\n");
+       return 0;
+    }
+
+    my ($name) = $clog =~ /^Source:\s*(.*)$/m;
+    my ($version) = $clog =~ /^Version:\s*(.*)$/m;
+    my ($dists) = $clog =~ /^Distribution:\s*(.*)$/m;
+    my ($urgency) = $clog =~ /^Urgency:\s*(.*)$/m;
+    my ($date) = $clog =~ /^Date:\s*(.*)$/m;
+    if ($dists ne $self->get_conf('DISTRIBUTION')) {
+       $self->build_log_colour('yellow',
+                               "^Distribution: " . 
$self->get_conf('DISTRIBUTION') . "\$");
+    }
+
     if ($self->get_conf('BIN_NMU') || $self->get_conf('APPEND_TO_VERSION')) {
        if (!$self->get_conf('MAINTAINER_NAME')) {
            Sbuild::Exception::Build->throw(error => "No maintainer specified.",
@@ -1347,23 +1381,6 @@ sub build {
            my $text = do { local $/; <F> };
            close( F );
 
-           my $pipe = $self->get('Session')->pipe_command(
-               { COMMAND => ['dpkg-parsechangelog'],
-                 USER => $self->get_conf('BUILD_USER'),
-                 PRIORITY => 0,
-                 DIR => $self->get('Session')->strip_chroot_path($dscdir) });
-           my $clog = do { local $/; <$pipe> };
-           close($pipe);
-           if ($?) {
-               $self->log("FAILED [dpkg-parsechangelog died]\n");
-               return 0;
-           }
-
-           my ($name) = $clog =~ /^Source:\s*(.*)$/m;
-           my ($version) = $clog =~ /^Version:\s*(.*)$/m;
-           my ($dists) = $clog =~ /^Distribution:\s*(.*)$/m;
-           my ($urgency) = $clog =~ /^Urgency:\s*(.*)$/m;
-           my ($date) = $clog =~ /^Date:\s*(.*)$/m;
 
            my $NMUversion = $self->get('Version');
            if (!open( F, ">$dscdir/debian/changelog" )) {
@@ -1585,9 +1602,9 @@ sub build {
                       $self->get('Build End Time')-$self->get('Build Start 
Time'));
     $self->write_stats('install-download-time',
                       $self->get('Install End Time')-$self->get('Install Start 
Time'));
-    my $date = strftime("%Y%m%d-%H%M",localtime($self->get('Build End Time')));
+    my $finish_date = strftime("%Y%m%d-%H%M",localtime($self->get('Build End 
Time')));
     $self->log_sep();
-    $self->log("Build finished at $date\n");
+    $self->log("Build finished at $finish_date\n");
 
     my @space_files = ("$dscdir");
 
@@ -2051,6 +2068,16 @@ sub build_log_filter {
     }
 }
 
+sub build_log_colour {
+    my $self = shift;
+    my $regex = shift;
+    my $colour = shift;
+
+    if ($self->get_conf('LOG_COLOUR')) {
+       $self->log($self->get('COLOUR_PREFIX') . $colour . ':' . $regex . "\n");
+    }
+}
+
 sub open_build_log {
     my $self = shift;
 
@@ -2058,6 +2085,8 @@ sub open_build_log {
 
     my $filter_prefix = '__SBUILD_FILTER_' . $$ . ':';
     $self->set('FILTER_PREFIX', $filter_prefix);
+    my $colour_prefix = '__SBUILD_COLOUR_' . $$ . ':';
+    $self->set('COLOUR_PREFIX', $colour_prefix);
 
     my $filename = $self->get_conf('LOG_DIR') . '/' .
        $self->get('Package_SVersion') . '-' .
@@ -2105,8 +2134,10 @@ sub open_build_log {
        my $verbose = $self->get_conf('VERBOSE');
        my $log_colour = $self->get_conf('LOG_COLOUR');
        my @filter = ();
+       my @colour = ();
        my ($text, $replacement);
        my $filter_regex = "^$filter_prefix(.*):(.*)\$";
+       my $colour_regex = "^$colour_prefix(.*):(.*)\$";
        my @ignore = ();
 
        while (<STDIN>) {
@@ -2117,6 +2148,11 @@ sub open_build_log {
                $replacement = "«$replacement»";
                push (@filter, [$text, $replacement]);
                $_ = "I: NOTICE: Log filtering will replace '$text' with 
'$replacement'\n";
+           } elsif (m/$colour_regex/) {
+               my ($colour, $regex);
+               ($colour,$regex)=($1,$2);
+               push (@colour, [$colour, $regex]);
+               $_ = "I: NOTICE: Log colouring will colour '$regex' in 
$colour\n";
            } else {
                # Filter out any matching patterns
                foreach my $pattern (@filter) {
@@ -2136,13 +2172,11 @@ sub open_build_log {
            if ($nolog || $verbose) {
                if (-t $saved_stdout && $log_colour) {
                    my $colour = 'reset';
-                   $colour = 'red' if (m/^E: /);
-                   $colour = 'yellow' if (m/^W: /);
-                   $colour = 'green' if (m/^I: /);
-                   $colour = 'red' if (m/^Status:/);
-                   $colour = 'green' if (m/^Status: successful$/);
-                   $colour = 'red' if (m/^Lintian:/);
-                   $colour = 'green' if (m/^Lintian: pass$/);
+                   foreach my $pattern (@colour) {
+                       if (m/$$pattern[0]/) {
+                           $colour = $$pattern[1];
+                       }
+                   }
                    print $saved_stdout color $colour;
                }
 
diff --git a/lib/Sbuild/Conf.pm b/lib/Sbuild/Conf.pm
index da3cad1..e9be547 100644
--- a/lib/Sbuild/Conf.pm
+++ b/lib/Sbuild/Conf.pm
@@ -362,6 +362,13 @@ sub setup ($) {
            DEFAULT => 1,
            HELP => 'Filter variable strings from log messages such as the 
chroot name and build directory'
        },
+       'LOG_COLOUR'                            => {
+           TYPE => 'BOOL',
+           VARNAME => 'log_colour',
+           GROUP => 'Logging options',
+           DEFAULT => 1,
+           HELP => 'Colour log messages such as critical failures, warnings 
and sucess'
+       },
        'LOG_DIR_AVAILABLE'                     => {
            TYPE => 'BOOL',
            GROUP => '__INTERNAL',

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.

Attachment: signature.asc
Description: Digital signature

Reply via email to