Skip to content

Commit

Permalink
Porting ekb verify-commit enhancements to hostboot
Browse files Browse the repository at this point in the history
Change-Id: I6eccfca504b9396e1998f5999053b2b2f0908d73
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/34366
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
  • Loading branch information
Ilya Smirnov authored and dcrowell77 committed Feb 3, 2017
1 parent 03e362b commit f288201
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/build/citest/check-copyright
Expand Up @@ -6,7 +6,7 @@
#
# OpenPOWER HostBoot Project
#
# Contributors Listed Below - COPYRIGHT 2014,2015
# Contributors Listed Below - COPYRIGHT 2014,2017
# [+] International Business Machines Corp.
#
#
Expand All @@ -25,7 +25,7 @@
# IBM_PROLOG_END_TAG

COPYRIGHT_CHECK=${PROJECT_ROOT}/src/build/tools/copyright-check.sh
COMMIT_CHECK=${PROJECT_ROOT}/src/build/tools/verify-commit
COMMIT_CHECK="${PROJECT_ROOT}/src/build/tools/verify-commit --show-all"

$COPYRIGHT_CHECK || exit -1
$COMMIT_CHECK || exit -1
72 changes: 59 additions & 13 deletions src/build/tools/verify-commit
Expand Up @@ -6,7 +6,7 @@
#
# OpenPOWER HostBoot Project
#
# Contributors Listed Below - COPYRIGHT 2013,2016
# Contributors Listed Below - COPYRIGHT 2013,2017
# [+] International Business Machines Corp.
#
#
Expand All @@ -25,9 +25,15 @@
# IBM_PROLOG_END_TAG

use strict;
use Getopt::Long qw(:config pass_through);

my $issueFound = 0;
my $errorFound = 0;
my $warningCount = 0;
my $showAll = 0;

use constant MAX_WARNINGS => 5;
use constant MAX_CODE_LINE_LENGTH => 80;

my $projectName = $ENV{'PROJECT_NAME'};
# Relative path of import tree from project root
Expand All @@ -36,6 +42,8 @@ my $importPrefix = $ENV{'IMPORT_REL_PATH'}."/";
my $rtcNumber = rtc_workitem_num();
my $cqNumber = cq_workitem_num();

GetOptions("show-all" => \$showAll);

verifyPatchSet(); # Verify the patch contents.
verifyCommitMsg(); # Verify the commit message.
verifyTodoFixme(); # Make sure there are no TODO/FIXME
Expand All @@ -45,6 +53,13 @@ verifyTodoFixme(); # Make sure there are no TODO/FIXME
if ($issueFound)
{
print "------------------------------------------------------------\n";
my $hiddenWarnings = $warningCount - MAX_WARNINGS;
if ($hiddenWarnings > 0 && !$showAll)
{
print " $hiddenWarnings Warning(s) Hidden\n";
print " Run 'verify-commit --show-all'\n";
print "------------------------------------------------------------\n";
}
}

# Return a bad RC if we found an error. Let warnings pass.
Expand Down Expand Up @@ -121,7 +136,7 @@ sub verifyPatchSet
# @sub verifyFileLine
#
# Checks a particular line of the file for the following issues:
# * Warning: Lines longer than 80 characters, except in trace statement.
# * Warning: Lines longer than MAX_CODE_LINE_LENGTH characters, except in trace statement.
# * Warning: Trailing whitespace.
# * Warning: Tab characters outside of makefiles.
# * Warning: TODO or FIXME type tag without a corresponding RTC number.
Expand All @@ -139,21 +154,21 @@ sub verifyFileLine
}

# Check line length.
if (length($line) > 80)
if (length($line) > MAX_CODE_LINE_LENGTH)
{
# Allow trace statements to slide.
if (($line =~ m/TRAC[DSFU]/) ||
($line =~m/TS_FAIL/) ||
($line =~m/printk/) ||
($line =~m/displayf/) ||
($line =~ m/FAPI_(INF|IMP|ERR|DBG|SCAN)/))
($line =~ m/FAPI_(INF|IMP|ERR|DBG|SCAN)/) ||
($line =~ m/print/))
{
}
else
{
warning($file,$line,$count,
(sprintf "Length is more than 80 characters (%d).",
length($line))
(sprintf "Length is more than %d characters (%d).",
MAX_CODE_LINE_LENGTH, length($line))
);
}
}
Expand All @@ -169,7 +184,8 @@ sub verifyFileLine
if ($line =~ m/\t/)
{
# Makefiles are ok (require tabs).
if (not (($file =~ m/makefile/) || ($file =~ m/\.mk/)))
if (not (($file =~ m/makefile/) || ($file =~ m/Makefile/) ||
($file =~ m/\.mk/)))
{
warning($file,$line,$count,
"Tab character found.");
Expand Down Expand Up @@ -223,6 +239,7 @@ sub verifyCommitMsg
my $lineCount = 0;
my $rtcTag = "";
my $cqTag = "";
my $changeId = "";
my $taggedLine = "";
my $untaggedLine = "";

Expand Down Expand Up @@ -306,13 +323,30 @@ sub verifyCommitMsg
}
}

if ($line =~ m/^\s*Change-Id:\s*[I][\w]+(.*)/)
{
if ("" ne $changeId)
{
error("Commit Message",$line,$lineCount,
"Mulitple Change-Id's found.");
}

$changeId = $line;
if ("" ne $1)
{
error("Commit Message",$line,$lineCount,
(sprintf "Change-Id format incorrect (%s).", $1));
}
}

# Identify if this is a tagged line or a non-tagged line and store
# away.
if ($line =~ m/^\s*[A-Za-z0-9\-_]+:[^:]/)
{
# We allow lines that look like tags in the topic like...
# "FOO: Adding support for BAR."
if ($lineCount > 1)
# Unless the Change-Id is in the topic
if ($lineCount > 1 || ($line =~ m/Change-Id/))
{
$taggedLine = $line;
}
Expand All @@ -330,6 +364,13 @@ sub verifyCommitMsg
"Neither RTC nor CQ tag found.");
}

# Error for missing Change-Id.
if ("" eq $changeId)
{
error("Commit Message","<end-of-file>",$lineCount,
"Change-Id not found.");
}

# Error for a mix of tag / untagged in the last section (ie. untagged
# lines in the footer).
if (("" ne $untaggedLine) && ("" ne $taggedLine))
Expand Down Expand Up @@ -406,12 +447,17 @@ sub check_cq_todo_fixme
sub warning
{
my ($file, $line, $count, $statement) = @_;
print "------------------------------------------------------------\n";
print "WARNING: $statement\n";
print " $file:$count\n";
print " $line\n";

if ($warningCount < MAX_WARNINGS || $showAll)
{
print "------------------------------------------------------------\n";
print "WARNING: $statement\n";
print " $file:$count\n";
print " $line\n";
}

$issueFound = 1;
$warningCount++;
}

sub strong_warning
Expand Down

0 comments on commit f288201

Please sign in to comment.