From patchwork Wed Dec 12 15:22:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 10726563 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 72C4F16B1 for ; Wed, 12 Dec 2018 15:34:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 636C428635 for ; Wed, 12 Dec 2018 15:34:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61C6E2B1AE; Wed, 12 Dec 2018 15:34:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D003428938 for ; Wed, 12 Dec 2018 15:34:16 +0000 (UTC) Received: from localhost ([::1]:45608 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX6Wd-0008N0-Jr for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Dec 2018 10:34:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52183) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gX6MX-0000mJ-Hv for qemu-devel@nongnu.org; Wed, 12 Dec 2018 10:23:51 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gX6MW-0000DA-DB for qemu-devel@nongnu.org; Wed, 12 Dec 2018 10:23:49 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:55392) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gX6MU-0008Lx-Ip for qemu-devel@nongnu.org; Wed, 12 Dec 2018 10:23:48 -0500 Received: by mail-wm1-x334.google.com with SMTP id y139so6132166wmc.5 for ; Wed, 12 Dec 2018 07:23:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jkiJU8pzboGzQe6MMzZPXG/hBj0o/LdIbK/KigkNsKo=; b=D9+Yr8IkuF0ieinCpttMPbZ7ix9o1Plv74zdsKoGItZRoQOLbBdm6EYXW2BAzg8f2E kw3HwdexrifYTs6/BwPpHrcw8G0LvbqYHwJQ9EoCSP27/wSsKwEHg+4FwQaxyqslAqlS 41+qo6qjyg/qcdkUaZcN7uFx9Sd8wp7NhznKiO0PuTjGZ/+Xgk/Eht5YKpWwOvXqA5cp st0Yfu3h4bE9IwCwzzvg8uzOp483mgQTW7CFqYhr2Ohsh6nlimFUf+XUPy2MWbaPzmxK wHNr14uZf6rt77GHGLefMDyp+OHT3vPZvO9QbqsXUibkmSEYbjg9P2PrwwBi6iBHQtRk hhPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=jkiJU8pzboGzQe6MMzZPXG/hBj0o/LdIbK/KigkNsKo=; b=GO91qkG6c8uA7of92A5O05FmF8HI9x1xjWZCV3oZVnmBEqMMpf48y3bfVQnuy8kqj6 48dePR/beA40GjG/VAgSvZ/iykI6rQV6tKcKQS3aaThK5E/ib8f6loT24dKDQ8ep/MPQ Uzv7wTwT5moXPbxq45mjgxeagsS4COgnNlSqFRVzlaSQI3JsX15UNWraz04EsqjCdNEP xODXZprvuUdsH4xd/SM3GqE58svsbsSKe5etGHExQG/08RuGb1lDVlCCedegmFlZWdSq 9gL5NWI6otCqRj/qgV//M6lqMRSw2v+aMu0VDhE1aw2wlPwJIkfDM3NOy098hiJlPHpy pRUw== X-Gm-Message-State: AA+aEWaJuYPL/+5iEDdEaxN1He8YIunnB+P0hnbCrUkCeBhq/T1JE+p5 BVB9NArJlKYkSY6TEaxe5UbXgY81 X-Google-Smtp-Source: AFSGD/UhOq3fqgNG/BC/1tri+Z6dH5+5EgCg2itpR5ZKGfzEMiKPTVIwHkDFgAM2LafHQOJpFJMqpA== X-Received: by 2002:a7b:cc86:: with SMTP id p6mr710626wma.19.1544628205103; Wed, 12 Dec 2018 07:23:25 -0800 (PST) Received: from 640k.lan ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id u10sm15878859wrr.33.2018.12.12.07.23.23 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Dec 2018 07:23:23 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 12 Dec 2018 16:22:27 +0100 Message-Id: <1544628195-37728-7-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1544628195-37728-1-git-send-email-pbonzini@redhat.com> References: <1544628195-37728-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::334 Subject: [Qemu-devel] [PULL 06/54] checkpatch: colorize output to terminal X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add optional colors to make seeing message types a bit easier. The default is to show them on a tty. Inspired by Linux commits 57230297116fa ("checkpatch: colorize output to terminal") and 737c0767758b ("checkpatch: change format of --color argument to --color[=WHEN]"). Signed-off-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daudé --- scripts/checkpatch.pl | 49 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 2edb4e2..a8d6e44 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -7,6 +7,7 @@ use strict; use warnings; +use Term::ANSIColor qw(:constants); my $P = $0; $P =~ s@.*/@@g; @@ -26,6 +27,7 @@ my $tst_only; my $emacs = 0; my $terse = 0; my $file = undef; +my $color = "auto"; my $no_warnings = 0; my $summary = 1; my $mailback = 0; @@ -64,6 +66,8 @@ Options: is all off) --test-only=WORD report only warnings/errors containing WORD literally + --color[=WHEN] Use colors 'always', 'never', or only when output + is a terminal ('auto'). Default is 'auto'. -h, --help, --version display this help and exit When FILE is - read standard input. @@ -72,6 +76,14 @@ EOM exit($exitcode); } +# Perl's Getopt::Long allows options to take optional arguments after a space. +# Prevent --color by itself from consuming other arguments +foreach (@ARGV) { + if ($_ eq "--color" || $_ eq "-color") { + $_ = "--color=$color"; + } +} + GetOptions( 'q|quiet+' => \$quiet, 'tree!' => \$tree, @@ -89,6 +101,8 @@ GetOptions( 'debug=s' => \%debug, 'test-only=s' => \$tst_only, + 'color=s' => \$color, + 'no-color' => sub { $color = 'never'; }, 'h|help' => \$help, 'version' => \$help ) or help(1); @@ -144,6 +158,16 @@ if (!$chk_patch && !$chk_branch && !$file) { die "One of --file, --branch, --patch is required\n"; } +if ($color =~ /^always$/i) { + $color = 1; +} elsif ($color =~ /^never$/i) { + $color = 0; +} elsif ($color =~ /^auto$/i) { + $color = (-t STDOUT); +} else { + die "Invalid color mode: $color\n"; +} + my $dbg_values = 0; my $dbg_possible = 0; my $dbg_type = 0; @@ -372,7 +396,9 @@ if ($chk_branch) { close($FILE); $vname = substr($hash, 0, 12) . ' (' . $git_commits{$hash} . ')'; if ($num_patches > 1 && $quiet == 0) { - print "$i/$num_patches Checking commit $vname\n"; + my $prefix = "$i/$num_patches"; + $prefix = BLUE . BOLD . $prefix . RESET if $color; + print "$prefix Checking commit $vname\n"; $vname = "Patch $i/$num_patches"; } else { $vname = "Commit " . $vname; @@ -1182,14 +1208,23 @@ sub possible { my $prefix = ''; sub report { - if (defined $tst_only && $_[0] !~ /\Q$tst_only\E/) { + my ($level, $msg) = @_; + if (defined $tst_only && $msg !~ /\Q$tst_only\E/) { return 0; } - my $line = $prefix . $_[0]; - $line = (split('\n', $line))[0] . "\n" if ($terse); + my $output = ''; + $output .= BOLD if $color; + $output .= $prefix; + $output .= RED if $color && $level eq 'ERROR'; + $output .= MAGENTA if $color && $level eq 'WARNING'; + $output .= $level . ':'; + $output .= RESET if $color; + $output .= ' ' . $msg . "\n"; + + $output = (split('\n', $output))[0] . "\n" if ($terse); - push(our @report, $line); + push(our @report, $output); return 1; } @@ -1197,13 +1232,13 @@ sub report_dump { our @report; } sub ERROR { - if (report("ERROR: $_[0]\n")) { + if (report("ERROR", $_[0])) { our $clean = 0; our $cnt_error++; } } sub WARN { - if (report("WARNING: $_[0]\n")) { + if (report("WARNING", $_[0])) { our $clean = 0; our $cnt_warn++; }