summaryrefslogtreecommitdiffstats
path: root/sbe
diff options
context:
space:
mode:
authorSangeetha T S <sangeet2@in.ibm.com>2016-06-28 05:11:43 -0500
committerSachin Gupta <sgupta2m@in.ibm.com>2016-07-01 07:29:52 -0400
commit82f9fe9c97b0a39261eef652765facdfd74e545b (patch)
tree040256c2012c1672668b4343f5f8b03f619aea11 /sbe
parentea84ca31e0fa859b4401a32fefc1e5cc3e33b004 (diff)
downloadtalos-sbe-82f9fe9c97b0a39261eef652765facdfd74e545b.tar.gz
talos-sbe-82f9fe9c97b0a39261eef652765facdfd74e545b.zip
Move hooks & related scripts to sbe/build/tools/hooks
Change-Id: I16dda4cefb65c64c2a0b888bf913176e166effa5 Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/26331 Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com> Reviewed-by: Sachin Gupta <sgupta2m@in.ibm.com>
Diffstat (limited to 'sbe')
-rwxr-xr-xsbe/build/citest/check-copyright2
-rwxr-xr-xsbe/build/citest/copyright-check.sh2
-rwxr-xr-xsbe/build/tools/hooks/addCopyright.pl1222
-rwxr-xr-xsbe/build/tools/hooks/gerrit-hostname79
-rwxr-xr-xsbe/build/tools/hooks/post-commit33
-rwxr-xr-xsbe/build/tools/hooks/pre-commit41
-rwxr-xr-xsbe/build/tools/hooks/pre-commit-actions49
-rwxr-xr-xsbe/build/tools/hooks/pre-commit-prologs47
-rwxr-xr-xsbe/build/tools/hooks/setupgithooks.sh64
-rwxr-xr-xsbe/build/tools/hooks/verify-commit359
10 files changed, 1896 insertions, 2 deletions
diff --git a/sbe/build/citest/check-copyright b/sbe/build/citest/check-copyright
index 6d0323db..86224452 100755
--- a/sbe/build/citest/check-copyright
+++ b/sbe/build/citest/check-copyright
@@ -25,7 +25,7 @@
# IBM_PROLOG_END_TAG
COPYRIGHT_CHECK=${SBEROOT}/sbe/build/citest/copyright-check.sh
-COMMIT_CHECK=${SBEROOT}/tools/hookScripts/verify-commit
+COMMIT_CHECK=${SBEROOT}/sbe/build/tools/hooks/verify-commit
$COPYRIGHT_CHECK || exit -1
$COMMIT_CHECK || exit -1
diff --git a/sbe/build/citest/copyright-check.sh b/sbe/build/citest/copyright-check.sh
index eb7c75b6..6df7dd55 100755
--- a/sbe/build/citest/copyright-check.sh
+++ b/sbe/build/citest/copyright-check.sh
@@ -30,7 +30,7 @@
#
export WORKSPACE_DIR=`pwd`
-export ADDCOPYRIGHT=${WORKSPACE_DIR}/tools/hookScripts/addCopyright.pl
+export ADDCOPYRIGHT=${WORKSPACE_DIR}/sbe/build/tools/hooks/addCopyright.pl
## run git show to get a list of checked in files
CHECKINFILES=`git show --pretty=format: --name-only -n1 | tr '\n' ' '`
diff --git a/sbe/build/tools/hooks/addCopyright.pl b/sbe/build/tools/hooks/addCopyright.pl
new file mode 100755
index 00000000..c72198d7
--- /dev/null
+++ b/sbe/build/tools/hooks/addCopyright.pl
@@ -0,0 +1,1222 @@
+#!/usr/bin/perl
+# IBM_PROLOG_BEGIN_TAG
+# This is an automatically generated prolog.
+#
+# $Source: sbe/build/tools/addCopyright.pl $
+#
+# OpenPOWER sbe Project
+#
+# Contributors Listed Below - COPYRIGHT 2016
+# [+] International Business Machines Corp.
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# IBM_PROLOG_END_TAG
+#################################### ABOUT ####################################
+# Forked from: #
+# Author: Mark Jerde (mjerde@us.ibm.com) #
+# Date: Fri Mar 19 17:40:32 2010 UTC #
+# #
+# addCopyright.pl will automatically insert appropriate copyright statements #
+# in source files following the IBM copyright guidelines (and templates) #
+# referenced below : #
+# FSP ClearCase Architecture #
+# Version 1.9 #
+# 10/12/2010 #
+# Editor: Alan Hlava #
+# #
+# Section 3.14.1 of the above doc has templates for different files #
+# #
+# NOTE: FSP uses the phrase "OCO Source materials" in their copyright #
+# block, which is classified as 'p1' . We will use the same #
+# classification here. #
+# NOTE: to list all files in src EXCEPT the build dir, run: #
+# make clean # remove autogenerated files #
+# find src -path 'src/build' -prune -o ! -type d -print | tr '\n' ' ' #
+# #
+# addCopyright.pl does not support piping, but you can send these #
+# to a file, add "addCopyright.pl update" to the beginning of the line, #
+# and run the file to update all #
+###############################################################################
+
+use strict;
+use warnings;
+use POSIX;
+use Getopt::Long;
+use File::Basename;
+use lib dirname (__FILE__);
+use Cwd;
+
+#------------------------------------------------------------------------------
+# Project-specific settings.
+#------------------------------------------------------------------------------
+my $ReleaseYear = `date +%Y`;
+chomp( $ReleaseYear );
+$ReleaseYear = $ENV{'DATE_OVERRIDE'} if defined $ENV{'DATE_OVERRIDE'};
+
+my $copyrightSymbol = "";
+# my $copyrightSymbol = "(C)"; # Uncomment if unable to use  character.
+
+# set by environment variable in project env.bash
+my $projectName = $ENV{'PROJECT_NAME'};
+my $copyrightPrefix = "Contributors Listed Below - ";
+my $copyrightStr = $copyrightPrefix."COPYRIGHT";
+my $projectRoot = $ENV{'SBEROOT'};
+# Relative path of import tree from project root
+my $importPrefix = $ENV{'IMPORT_REL_PATH'}."/";
+
+## note that these use single ticks so that the escape chars are NOT evaluated yet.
+my $OLD_DELIMITER_END = 'IBM_PROLOG_END';
+my $DELIMITER_END = 'IBM_PROLOG_END_TAG';
+my $DELIMITER_BEGIN = 'IBM_PROLOG_BEGIN_TAG';
+
+my $SOURCE_BEGIN_TAG = "\$Source:";
+my $SOURCE_END_TAG = "\$";
+
+# Desired License, set by environment variable in project env.bash
+my $LicenseFile = $ENV{'LICENSE'};
+use constant LICENSE_PROLOG => "LICENSE_PROLOG";
+
+#------------------------------------------------------------------------------
+# Contributer info
+#------------------------------------------------------------------------------
+
+# Constants for company's copyright
+# When adding a new company add constant here and to %fileContributorsCompany
+use constant IBM => 'International Business Machines Corp.';
+use constant GOOGLE => 'Google Inc.';
+
+# Create mapping for git contrubitors to companies
+my %fileContributorsCompany = (
+ "ibm.com" => IBM,
+ "ozlabs.org" => IBM,
+ "google.com" => GOOGLE,
+ "Google Shared Technology" => GOOGLE,
+);
+
+#------------------------------------------------------------------------------
+# Constants
+#------------------------------------------------------------------------------
+use constant RC_INVALID_PARAMETERS => 1;
+use constant RC_NO_COPYRIGHT_BLOCK => 2;
+use constant RC_BAD_CONTRIBUTORS_BLOCK => 3;
+use constant RC_INVALID_FILETYPE => 4;
+use constant RC_DIFFERS_FROM_LICENSE_PROLOG => 5;
+use constant RC_NO_LICENSE_PROLOG_FILE => 6;
+
+#------------------------------------------------------------------------------
+# Global Vars
+#------------------------------------------------------------------------------
+my $opt_help = 0;
+my $opt_debug = 0;
+my $operation = "";
+my $opt_logfile = "";
+
+my $DelimiterBegin = "";
+my $CopyrightBlock = "";
+my $DelimiterEnd = "";
+my $CopyRightString = "";
+my $copyright_check = 0;
+
+my $TempFile = "";
+my @Files = ();
+
+my $rc = 0;
+
+# NOTE: $OLD_DELIMITER_END is a subset of $DELIMITER_END so must match
+# $DELIMITER_END first in order to return the entire string.
+my $g_end_del_re = "($DELIMITER_END|$OLD_DELIMITER_END)";
+my $g_prolog_re = "($DELIMITER_BEGIN)((.|\n)+?)$g_end_del_re";
+
+#######################################################################
+# Main
+#######################################################################
+if (scalar(@ARGV) < 2)
+{
+ ## needs at least one filename and an operation as a parameter
+ usage();
+}
+
+
+my @SaveArgV = @ARGV;
+#------------------------------------------------------------------------------
+# Parse optional input arguments
+#------------------------------------------------------------------------------
+GetOptions( "help|?" => \$opt_help,
+ "validate" => sub { $operation="validate"; },
+ "update" => sub { $operation="update"; },
+ "copyright-check" => \$copyright_check,
+ "log-failed-files=s" => \$opt_logfile,
+ "debug" => \$opt_debug,
+ );
+
+## scan through remaining args and store all files in @Files
+## check for old-type parms, just in case
+foreach ( @ARGV )
+{
+ ## print $_;
+ if ( m/^debug$/ ) { $opt_debug = 1; next; }
+ if ( m/^update$/ ) { $operation = $_; next; }
+ if ( m/^validate$/ ) { $operation = $_; next; }
+
+ push @Files, $_ ;
+}
+
+
+if ( $opt_debug )
+{
+ print STDERR __LINE__, " : ---- DEBUG -----\n";
+ print STDERR "help = $opt_help\n";
+ print STDERR "debug = $opt_debug\n";
+ print STDERR "operation = $operation\n";
+ print STDERR "log-failed-files = $opt_logfile\n";
+
+ ## dump files specified
+ print STDERR "Files:\n";
+ print STDERR join( ' ', @Files ), "\n";
+
+ print STDERR "ReleaseYear = $ReleaseYear\n";
+
+ print "\n";
+}
+
+if ( $operation eq "" )
+{
+ print STDOUT "No operation specified\n";
+ usage();
+ exit RC_INVALID_PARAMETERS;
+}
+
+if ( ( $opt_logfile ne "" )
+ ## && ( $operation eq "validate" )
+ )
+{
+ my $logdate = `date +%Y-%m-%d:%H%M`;
+ chomp $logdate;
+ open( LOGFH, "> $opt_logfile" ) or die "ERROR $?: Failed to open $opt_logfile: $!";
+ print LOGFH "## logfile generated $logdate from command line:\n";
+ print LOGFH $0, " ", join( ' ', @SaveArgV );
+ print LOGFH "\nFAILING files:\n";
+}
+
+########################################################################
+## MAIN
+########################################################################
+# Loop through all files and process.
+foreach ( @Files )
+{
+
+ ## clear global vars
+ $DelimiterBegin = "";
+ $CopyrightBlock = "";
+ $DelimiterEnd = "";
+ $CopyRightString = "";
+ $rc = 0;
+
+
+ ## get filetype
+ my $filetype = filetype($_);
+ print STDOUT "File $_: Type $filetype\n";
+
+ ## set Temporary file name.
+ $TempFile = "$_.gitCPYWRT";
+ if ( $opt_debug ) { print STDERR __LINE__, ": Temporary file name = $TempFile\n"; }
+
+ ##
+ ## Special case is this file, just return 0 and add copyright manually.
+ ##
+ if ( m/addCopyright\.pl/ )
+ {
+ print STDOUT "---------------------------------------------------------\n";
+ print STDOUT "Skipping special case file: $_\n";
+ print STDOUT " Please add the copyright prolog manually.\n";
+ print STDOUT "---------------------------------------------------------\n";
+ next;
+ }
+
+ ##
+ ## Gerrit submissions can include deleted files, just warn and continue
+ if ( ! -e $_ )
+ {
+ print STDOUT "---------------------------------------------------------\n";
+ print STDOUT "Skipping deleted file: $_\n";
+ print STDOUT "---------------------------------------------------------\n";
+ next;
+ }
+
+ ##
+ ## Unknown files are valid, but should generate a warning.
+ if ("Unknown" eq $filetype)
+ {
+ print STDOUT "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
+ print STDOUT "WARNING:: File $_ :Unknown Filetype: $filetype\n";
+ print STDOUT " Skipping this file and continuing.\n";
+ print STDOUT " Please add the copyright prolog manually.\n";
+ print STDOUT "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
+
+ next;
+ }
+
+ ##
+ ## text files are valid, but should generate a warning.
+ if (("txt" eq $filetype) || "Initfile" eq $filetype)
+ {
+ print STDOUT "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
+ print STDOUT "WARNING:: File $_ : Filetype: $filetype\n";
+ print STDOUT " Skipping this file and continuing.\n";
+ print STDOUT " If needed, Please add the copyright \n";
+ print STDOUT " prolog manually.\n";
+ print STDOUT "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n";
+
+ next;
+ }
+
+ ##
+ ## We do not want to modify the prologs of files mirrored from EKB
+ ## Eventually we will enhance to allow different prologs, but at the time
+ ## this breaks the mirror tool.
+ if (m/^import/)
+ {
+ print STDOUT "---------------------------------------------------------\n";
+ print STDOUT "Skipping file mirrored from EKB: $_\n";
+ print STDOUT "---------------------------------------------------------\n";
+ next;
+ }
+
+ ##
+ ## Check if any parent directory below $projectRoot has a LICENSE_PROLOG file
+ ## Backtrack from the directory where the file lives and find the first
+ ## custom LICENSE_PROLOG file.
+ my $path = cwd."/".$_;
+ do
+ {
+ # Remove everything after last slash
+ $path =~ s|/[^/]*$||;
+ # Check if path has LICENSE_PROLOG file
+ my $custom_license_file = $path."/".LICENSE_PROLOG;
+ if (-e $custom_license_file)
+ {
+ # Set LicenseFile to closest custom LICENSE_PROLOG to file.
+ $LicenseFile = $custom_license_file;
+ # Exit loop, 'last' breaks out of both loops.
+ $path = $projectRoot;
+ }
+ } while ($path ne $projectRoot);
+
+ ## extract the existing copyright block
+ # Check if file from EKB in import tree
+ if (mirrored_file($_))
+ {
+ # Remove copyright prefix as EKB does not have it
+ $copyrightStr =~ s/$copyrightPrefix//;
+ }
+ $CopyrightBlock = extractCopyrightBlock( $_ );
+
+ ##
+ ## validate the file.
+ ## if $logfile exists, print failing filename to $logfile and
+ ## keep going.
+ ## Otherwise, exit with $rc
+ ##
+ if ( $operation =~ m/validate/i )
+ {
+ $rc = validate( $_ );
+ if ( $rc )
+ {
+ print STDOUT "$_ FAILED copyright validation: $rc \n";
+ if ( $opt_logfile ne "" )
+ {
+ print LOGFH "$_ # FAILED $rc \n";
+ }
+ else
+ {
+ exit $rc;
+ }
+ }
+
+ ## continue to next file
+ next;
+ } ## endif validate
+
+ ##
+ ## update
+ ##
+ if ($operation =~ m/update/i)
+ {
+ $rc = update( $_, $filetype );
+ if ( $rc )
+ {
+ print STDOUT "$_ FAILED copyright update: $rc \n";
+ exit $rc;
+ }
+
+ ## continue to next file
+ next;
+ } ## endif update
+
+} # end foreach
+
+if ( $opt_logfile ne "" )
+{
+ close( LOGFH );
+}
+
+#########################################################################
+## Subroutines
+#########################################################################
+
+#######################################
+## usage: print usage and quit
+#######################################
+sub usage
+{
+ print STDOUT "Usage: addCopyright.pl { update | validate } \n";
+ print STDOUT " [ --log-failed-files ]\n";
+ print STDOUT " [ --debug ] \n";
+ print STDOUT " file1 file2 ...\n";
+
+}
+
+#######################################
+## checks if file was mirrored from EKB
+## param[in] $filename to check
+## returns 1 mirrored from EKB
+#######################################
+sub mirrored_file
+{
+ my $filename = shift;
+
+ if ($filename =~ m/^$importPrefix/)
+ {
+ # Import tree expects to have EKB in the prolog
+ $projectName = "EKB";
+ return 1;
+ }
+ return 0;
+}
+
+#######################################
+## Converts mirrored filename to match its original in EKB
+## Mirroring prefixes the name with the import tree.
+## param[in] $filename to check
+## returns new $filename with prefix removed
+#######################################
+sub convert_mirror_file
+{
+ my $filename = shift;
+
+ if (mirrored_file($filename))
+ {
+ # Remove $importPrefix as EKB does not have it
+ $filename =~ s/^$importPrefix//;
+ }
+
+ return $filename
+}
+
+#######################################
+## validate the file
+## param[in] $filename to validate
+## returns 0 success, nonzero failure
+## See constants above for values of failure
+#######################################
+sub validate
+{
+ my ( $filename ) = @_;
+ my $rc = 0;
+
+ if ( $CopyrightBlock eq "" )
+ {
+ print STDOUT "WARNING: No copyright block.\n";
+ return RC_NO_COPYRIGHT_BLOCK;
+ }
+
+ my $converted_file = convert_mirror_file($filename);
+ $rc = checkCopyrightBlock( $CopyrightBlock, $converted_file);
+
+ # good file
+ return $rc;
+}
+
+##
+## @sub update the copyright block.
+##
+## @param[in] filename
+## @param[in] filetype
+##
+## @return success or failure (currently only return success)
+##
+sub update
+{
+ my ( $filename, $filetype ) = @_;
+ my $olddelimiter = 0;
+ my $localrc = 0;
+ $localrc = validate( $filename );
+
+ if ( $localrc != 0 )
+ {
+ print STDOUT "Copyright Block check returned $localrc , fixing...\n";
+
+ if ( $localrc != RC_NO_COPYRIGHT_BLOCK )
+ {
+ if ( $opt_debug) { print STDERR __LINE__, ": remove old copyright block...\n"; }
+ removeCopyrightBlock( $filename, $filetype );
+ }
+
+ if ($opt_debug) { print STDERR __LINE__, ": Add empty copyright block...\n"; }
+ addEmptyCopyrightBlock( $filename, $filetype, $localrc );
+
+ if ( $opt_debug ) { print STDERR __LINE__, ": fill in new copyright block...\n"; }
+ fillinEmptyCopyrightBlock( $filename, $filetype);
+ }
+
+ ## return OK by default.
+ return 0;
+}
+
+
+#####################################
+## Analyze file and return a text string of the file type
+#####################################
+sub filetype
+{
+ my $filename = shift;
+ my $fileinfo = `file $filename | sed 's/^.*: //'`;
+ chomp $fileinfo;
+
+ # Sorted by anticipated frequency of occurrence.
+ if ( $filename =~ m/\.xml$/i )
+ # Added XML file to the top of the list because some comments in
+ # an XML file cause older versions of 'file' to incorrectly return
+ # "ASCII C++ program text" even though the file is obviously XML.
+ # Specifically we are seeing "<!-- // ..." cause this trouble.
+ {
+ return "xml"
+ }
+ if ( $filename =~ m/\.txt$/i )
+ {
+ return "txt"
+ }
+ if ( $filename =~ m/\.initfile$/i )
+ {
+ return "Initfile"
+ }
+ if ( ( $filename =~ m/\.[cht]$/i )
+ ||( $filename =~ m/\.[cht]\+\+$/i )
+ ||( $filename =~ m/\.[cht]pp$/i )
+ ||( $filename =~ m/\.inl$/ ) # inline C functions
+ ||( $filename =~ m/\.y$/ ) # yacc
+ ||( $filename =~ m/\.lex$/ ) # flex
+ ||( $fileinfo =~ m/c program text/i )
+ ||( $fileinfo =~ m/c\+\+ program text/i )
+ ||( $fileinfo =~ m/c source/i )
+ ||( $fileinfo =~ m/c\+\+ source/i )
+ )
+ {
+ return "C";
+ }
+ if ( ( $filename =~ m/\.pl$/ )
+ ||( $filename =~ m/\.perl$/ )
+ ||( $filename =~ m/\.pm$/ )
+ ||( $fileinfo =~ m/perl.*script.*text executable/i) )
+ {
+ return "Perl";
+ }
+ if ($filename =~ m/\.s$/i)
+ {
+ return "Assembly";
+ }
+ if (($filename =~ m/Makefile$/i) or
+ ($filename =~ m/\.mk$/i))
+ {
+ return "Makefile";
+ }
+ if ( $filename =~ m/\.am$/i )
+ {
+ return "Automake";
+ }
+ if ( ($filename =~ m/configure\.ac$/i)
+ ||($filename =~ m/Makefile\.in$/i) )
+ {
+ return "Autoconf";
+ }
+ if ( ( $filename =~ m/\.[kc]{0,1}sh$/i )
+ ||( $filename =~ m/\.bash$/i )
+ ||( $fileinfo =~ m/shell script/i )
+ ||( $fileinfo =~ m/^a \/bin\/[af]sh( -x|) *script text( executable|)$/ )
+ ||( $fileinfo eq "Bourne shell script text")
+ ||( $fileinfo eq "Bourne shell script text executable")
+ ||( $fileinfo eq "Bourne-Again shell script text")
+ ||( $fileinfo eq "Bourne-Again shell script text executable") )
+ {
+ return "Shellscript";
+ }
+ if ( $filename =~ m/\.py$/ )
+ {
+ return "Python";
+ }
+ if ( $filename =~ m/\.tcl$/ )
+ {
+ return "Tcl";
+ }
+ if ( $filename =~ m/\.x$/ )
+ {
+ return "RPC";
+ }
+ if ( ($filename =~ m/^commitinfo$/)
+ ||($filename =~ m/^checkoutlist$/)
+ ||($filename =~ m/^loginfo$/) )
+ {
+ return "CVS";
+ }
+ if ( $filename =~ m/\.emx$/ )
+ {
+ # Used by Rational Software Architect. modelling file.
+ return "EmxFile";
+ }
+ if ( $filename =~ m/\.mof$/ )
+ {
+ return "MofFile";
+ }
+ if ( $filename =~ m/\.ld$/ )
+ {
+ return "LinkerScript";
+ }
+ if ( $filename =~ m/\.rule$/i )
+ {
+ return "PrdRuleFile"
+ }
+ if ( ( $filename =~ m/\.emx$/i )
+ ||( $filename =~ m/\.odt$/i )
+ ||( $filename =~ m/\.gitignore$/i )
+ ||( $filename =~ m/\.conf$/i )
+ ||( $filename =~ m/\.lidhdr$/i )
+ ||( $filename =~ m/\.vpdinfo$/i )
+ ||( $filename =~ m/\.pdf$/i )
+
+ )
+ {
+ # Known, but we can't deal with it so call it unknown.
+ return "Unknown";
+ }
+ if ( -f $filename )
+ {
+ my $type = `grep "\\\$Filetype:.*\\\$" $filename`;
+ if ( $type =~ m/\$Filetype:([^\$]*)\$/ )
+ {
+ $type = $1;
+ }
+ $type =~ s/^\s*//;
+ $type =~ s/\s*$//;
+ my %knownTypes = qw/Assembly Assembly Automake Automake Autoconf Autoconf C C CVS CVS EmxFile EmxFile LinkerScript LinkerScript Makefile Makefile MofFile MofFile Perl Perl PrdRuleFile PrdRuleFile Python Python RPC RPC Shellscript Shellscript Tcl Tcl/;
+ return $type if defined($knownTypes{$type});
+ }
+ { # Other random files containing non-printable characters.
+ my $file = `cat $filename`;
+ if ( $file =~ m/([^\x20-\x7E\s])/ )
+ {
+ return "Unknown";
+ }
+ }
+ return "Unknown";
+}
+
+########################################################################
+## extractCopyrightBlock
+##
+## param[in] $infile - filename
+##
+## param[out] returns block or ""
+########################################################################
+sub extractCopyrightBlock
+{
+ my ( $infile ) = shift;
+
+ # Extract the prolog
+ my $prolog = `sed -n \"/$DELIMITER_BEGIN/,/$DELIMITER_END/p\" $infile`;
+ # Critical to remove newline for validate step
+ chomp($prolog);
+
+ ## As long as we're here extract the copyright string within the block
+ ## and save it to a global var
+ $CopyRightString = $1 if ( $prolog =~ /(^.*$copyrightStr.*$)/m );
+
+ return $prolog;
+}
+
+
+#######################################
+## Check Copyright Block
+##
+## @param[in] - Copyright block
+## @parma[in] - filename
+##
+## @return 0 if success, nonzero otherwise
+#######################################
+use File::Temp;
+sub checkCopyrightBlock
+{
+ my ( $block, $filename ) = @_;
+
+ ## Check if custom LICENSE_PROLOG
+ if ($LicenseFile ne "")
+ {
+ ## Get desired license
+ my $license_prolog = genCopyrightBlock($filename, filetype($filename));
+
+ if ($block ne $license_prolog)
+ {
+ # Print strings to files to use unix diff, do not need to add the
+ # File::Diff module this way.
+ my ($blockHndl, $blockFile) = File::Temp::tempfile();
+ my ($licenseHndl, $licenseFile)= File::Temp::tempfile();
+ print $blockHndl $block;
+ print $licenseHndl $license_prolog;
+ close($blockHndl);
+ close($licenseHndl);
+
+ print STDOUT "\nERROR> Prolog not correct for $filename.\n";
+ print STDOUT "To fix run: git show --pretty=\"format:\" --name-only | xargs addCopyright.pl update\n";
+ print STDOUT "\nDiff:\n";
+ print STDOUT `diff $blockFile $licenseFile`;
+ my $relLicensePath = $LicenseFile;
+ $relLicensePath =~ s/$projectRoot//;
+ print STDOUT "\nWARNING: Copyright block does not match LICENSE_PROLOG file found at $relLicensePath\n";
+ system("rm -f $blockFile $licenseFile");
+ return RC_DIFFERS_FROM_LICENSE_PROLOG;
+ }
+ }
+ else
+ {
+ print STDOUT "WARNING: Missing LICNESE_PROLOG file in directory structure\n";
+ return RC_NO_LICENSE_PROLOG_FILE;
+ }
+
+ return 0;
+}
+
+sub createYearString
+{
+ my ( $filename ) = @_;
+ my $yearstr = "";
+ my @years = ();
+
+ ## Analyse the CopyRightString for begin and end years - this is for old
+ ## files that are checked in from FSP. In this case the earliest
+ ## year will be before it was checked into git . We have to construct
+ ## a yearstring based on the earliest year.
+ if ( $CopyRightString =~ m/$copyrightStr/ )
+ {
+ @years = ( $CopyRightString =~ /([0-9]{4})/g );
+ }
+ push @years, $ReleaseYear; # Add the current year.
+
+ ##
+ ## Make a call to git to find the earliest commit date of the file
+ ## new files will not have a log, so the "git log" call above will
+ # return nothing.
+ ## Push any year we find onto the @years array
+ my $cmd = "git log -- $filename | grep Date: | tail -n 1";
+ ## print "run $cmd\n";
+ my @logstrings = split( " ", `$cmd` );
+ if ( $? ) { die "ERROR $? : Could not run $cmd $!\n"; }
+
+ if ( scalar(@logstrings) >= 5 )
+ {
+ push @years, $logstrings[5] ;
+ }
+
+ ## sort and remove duplicates by loading it into a hash
+ my %temphash;
+ @temphash{@years} = ();
+ my @outyears = sort keys %temphash;
+
+ if ( $opt_debug )
+ { print STDERR __LINE__, ": years: ", join( ',', @outyears ), "\n"; }
+
+ ## lowest year, which may be the only one.
+ $yearstr = $outyears[0] ;
+
+ ## if there is more than one index then also output the highest one.
+ if ( $#outyears > 0 )
+ {
+ # A '-' is preferred but CMVC uses ',' so using ','.
+ $yearstr .= ",$outyears[$#outyears]";
+ }
+
+
+ return $yearstr;
+}
+
+###################################
+## Helper function for removeCopyrightBlock()
+###################################
+sub removeProlog
+{
+ my ( $data, $begin_re, $end_re ) = @_;
+
+ $data =~ s/(\n?)(.*?$begin_re.*$g_prolog_re(.|\n)*?$end_re.*?\n)/$1/;
+
+ return $data;
+}
+
+###################################
+## remove old Copyright Block in preparation for making a new one.
+## makes up a debug file named "<filename>.remove"
+###################################
+sub removeCopyrightBlock
+{
+ my ( $filename, $filetype ) = @_ ;
+ my $data = "" ;
+
+ ## Modify file in place with temp file Perl Cookbook 7.8
+ my $savedbgfile = "$filename.remove";
+ system( "cp -p $filename $TempFile" ); ## preserve file permissions
+ open( INPUT, "< $filename" ) or die " $? can't open $filename: $!" ;
+ read( INPUT, $data, -s INPUT ) or die "ERROR $? : reading $filename: $!";
+ close( INPUT ) or die " $? can't close $filename: $!" ;
+
+ open( OUTPUT, "> $TempFile" ) or die " $? can't open $TempFile: $!" ;
+ select( OUTPUT ); ## new default filehandle for print
+
+ ## preprocess to get rid of OLD_DELIMITER_END
+ $data =~ s/$OLD_DELIMITER_END(\s+?)/$DELIMITER_END$1/;
+
+ if ( "C" eq $filetype )
+ {
+ ## pre-process this for /* */ comments
+ $data = removeProlog( $data, '\/\*', '\*\/' );
+
+ ## Now apply filter for // comments
+ $data = removeProlog( $data, '\/\/', '' );
+ }
+ elsif ( ("RPC" eq $filetype) or
+ ("LinkerScript" eq $filetype)
+ )
+ {
+ $data = removeProlog( $data, '\/\*', '\*\/' );
+ }
+ elsif ( $filetype eq "xml" )
+ {
+ $data = removeProlog( $data, '<!--', '-->' );
+ }
+ elsif ( "Assembly" eq $filetype )
+ {
+ $data = removeProlog( $data, '\#', '' );
+ }
+ elsif ( ("Autoconf" eq $filetype) or
+ ("Automake" eq $filetype) or
+ ("CVS" eq $filetype) or
+ ("Makefile" eq $filetype) or
+ ("Perl" eq $filetype) or
+ ("PrdRuleFile" eq $filetype) or
+ ("Python" eq $filetype) or
+ ("Shellscript" eq $filetype) or
+ ("Tcl" eq $filetype)
+ )
+ {
+ # Don't wipe the the '#!' line at the top.
+ $data = removeProlog( $data, '\#', '' );
+ }
+ else
+ {
+ print STDOUT "ERROR: Don't know how to remove old block from $filetype file.\n";
+ close OUTPUT;
+ return RC_INVALID_FILETYPE;
+ }
+
+ print OUTPUT $data;
+
+ ## finish up the files
+ close( OUTPUT ) or die " $? can't close $TempFile: $!" ;
+ rename( $filename, "$savedbgfile" ) or die " $? can't rename $filename: $!" ;
+ rename( $TempFile, $filename ) or die " $? can't rename $TempFile: $!" ;
+ if ( !$opt_debug )
+ {
+ ## leave the files around for debug
+ unlink( $savedbgfile ) or die " $? can't delete $savedbgfile: $!";
+
+ }
+}
+
+###################################
+## Add an empty copyright block to the file, for example (C/C++ files):
+##
+## // IBM_PROLOG_BEGIN_TAG IBM_PROLOG_END_TAG
+##
+## - The block will be filled-in in the next step.
+##
+## @param[in] - filename to modify
+## @param[in] - filetype
+## @param[in] - returncode from validate
+##
+## @return none
+##
+## - Makes up a debug file called "<filename>.empty"
+##################################
+sub addEmptyCopyrightBlock
+{
+ my ( $filename, $filetype, $validaterc ) = @_;
+ my $line;
+
+ ## Modify file in place with temp file Perl Cookbook 7.8
+ my $savedbgfile = "$filename.empty";
+ system( "cp -p $filename $TempFile" ) ; ## preserve permissions
+ open( INPUT, "< $filename" ) or die " $? can't open $filename: $!" ;
+ open( OUTPUT, "> $TempFile" ) or die " $? can't open $TempFile: $!" ;
+ select( OUTPUT ); ## new default filehandle for print
+
+ if (("Autoconf" eq $filetype) or
+ ("Automake" eq $filetype) or
+ ("CVS" eq $filetype) or
+ ("Perl" eq $filetype) or
+ ("Python" eq $filetype) or
+ ("Shellscript" eq $filetype) or
+ ("Tcl" eq $filetype))
+ {
+ ## All files with a "shebang" at the beginning
+ $line = <INPUT>;
+ # Keep the '#!' line at the top.
+ ## The following says : if the first line is a "shebang" line
+ ## (e.g. "#!/usr/bin/perl"), then print it _before_ the copyright
+ ## block, otherwise (the unless line), print it _after_ the copyright
+ ## block.
+ if ($line =~ m/^#!/)
+ {
+ print OUTPUT $line;
+ }
+ print OUTPUT "$DELIMITER_BEGIN $DELIMITER_END\n";
+ unless ($line =~ m/^#!/)
+ {
+ print OUTPUT $line;
+ }
+ }
+ else
+ {
+ print OUTPUT "$DELIMITER_BEGIN $DELIMITER_END\n";
+ }
+
+ # Copy rest of file
+ while (defined($line = <INPUT>))
+ {
+ print OUTPUT $line;
+ }
+
+ ## finish up the files
+ close( INPUT ) or die " $? can't close $filename: $!" ;
+ close( OUTPUT ) or die " $? can't close $TempFile: $!" ;
+ rename( $filename, "$savedbgfile" ) or die " $? can't rename $filename: $!" ;
+ rename( $TempFile, $filename ) or die " $? can't rename $TempFile: $!" ;
+ if ( !$opt_debug )
+ {
+ ## leave the files around for debug
+ unlink( $savedbgfile ) or die " $? can't delete $savedbgfile: $!";
+ }
+}
+
+############################################
+## Helper functions for fillinEmptyCopyrightBlock()
+############################################
+sub addPrologComments
+{
+ my ( $data, $begin, $end ) = @_;
+
+ my @lines = split( /\n/, $data );
+
+ $data = '';
+ for my $line ( @lines )
+ {
+ # If there is an block comment end tag, fill the end of the line with
+ # spaces.
+ if ( $end )
+ {
+ my $max_line_len = 70;
+ my $len = length($line);
+ if ( $len < $max_line_len )
+ {
+ my $fill = ' ' x ($max_line_len - $len);
+ $line .= $fill;
+ }
+ }
+
+ # NOTE: CMVC prologs with inline comments will have a single trailing
+ # space at the end of the line. This is undesirable for most
+ # developers so it will not be added.
+ if ( $line =~ m/$DELIMITER_BEGIN/)
+ {
+ $line = "$line $end" if ( $end );
+ $line = "$begin $line\n";
+ }
+ elsif ( $line =~ m/$DELIMITER_END/ )
+ {
+ $line = "$line $end" if ( $end );
+ $line = "$begin $line";
+ }
+ else
+ {
+ if ( not $end and not $line )
+ {
+ # Compensate for blank lines with no end delimeter.
+ $line = "$begin\n";
+ }
+ else
+ {
+ $line = "$begin $line";
+ $line = "$line $end" if ( $end );
+ $line = "$line\n";
+ }
+ }
+
+ $data .= $line;
+ }
+
+ return $data;
+}
+
+############################################
+## Generates final copyright block
+##
+## @parma[in] filename
+##
+## @return final copyright block string
+############################################
+sub genCopyrightBlock
+{
+ my ($filename, $filetype) = @_;
+
+ my $copyrightYear = createYearString( $filename );
+
+ # Get copyright contributors based on hash so no duplicates
+ my %fileContributors = getFileContributors( $filename );
+ my $copyright_Contributors = "";
+
+ foreach my $key (sort keys %fileContributors)
+ {
+ $copyright_Contributors .= "[+] ".$key."\n";
+ }
+
+ ## Get desired license
+ my $LicenseContent = "";
+ open(LICENSE, "< $LicenseFile") or die " $? can't open $LicenseFile: $!" ;
+ while (my $line = <LICENSE>)
+ {
+ my $evalLine = eval "qq($line)";
+ $LicenseContent .= $evalLine;
+ }
+ close(LICENSE);
+
+ ## define the final copyright block template here.
+ my $IBMCopyrightBlock = <<EOF;
+$DELIMITER_BEGIN
+$LicenseContent
+$DELIMITER_END
+EOF
+
+ if ("Assembly" eq $filetype)
+ {
+ $IBMCopyrightBlock = addPrologComments($IBMCopyrightBlock, '#', '');
+ }
+ elsif ( ("Makefile" eq $filetype) or
+ ("PrdRuleFile" eq $filetype) )
+ {
+ $IBMCopyrightBlock = addPrologComments($IBMCopyrightBlock, '#', '');
+ }
+ elsif (("Autoconf" eq $filetype) or
+ ("Automake" eq $filetype) or
+ ("CVS" eq $filetype) or
+ ("Perl" eq $filetype) or
+ ("Python" eq $filetype) or
+ ("Shellscript" eq $filetype) or
+ ("Tcl" eq $filetype))
+ {
+ ## all files with a "shebang"
+ $IBMCopyrightBlock = addPrologComments($IBMCopyrightBlock, '#', '');
+ }
+ elsif ( "C" eq $filetype )
+ {
+ ## lex files are classified as C, but do not recognize '//' comments
+ $IBMCopyrightBlock = addPrologComments($IBMCopyrightBlock, '/*', '*/');
+ }
+ elsif ( ("RPC" eq $filetype) or
+ ("LinkerScript" eq $filetype)
+ )
+ {
+ $IBMCopyrightBlock = addPrologComments($IBMCopyrightBlock, '/*', '*/');
+ }
+ elsif ("EmxFile" eq $filetype)
+ {
+ # Not yet formatted correctly for EmxFile needs, but should coexist.
+ $IBMCopyrightBlock = "$DELIMITER_BEGIN IBM Confidential OCO Source Materials (C) Copyright IBM Corp. $copyrightYear The source code for this program is not published or otherwise divested of its trade secrets, irrespective of what has been deposited with the U.S. Copyright Office. $DELIMITER_END";
+ }
+ elsif ("MofFile" eq $filetype)
+ {
+ $IBMCopyrightBlock = addPrologComments($IBMCopyrightBlock, '//', '');
+ }
+ elsif ( "xml" eq $filetype)
+ {
+ $IBMCopyrightBlock = addPrologComments($IBMCopyrightBlock, '<!--', '-->');
+ }
+ else
+ {
+ print STDOUT "ERROR: Can\'t handle filetype: $filetype\n";
+ return RC_INVALID_FILETYPE;
+ }
+
+ return $IBMCopyrightBlock;
+}
+
+############################################
+## fill in the empty copyright block
+## Copyright guidelines from:
+## FSP ClearCase Architecture
+## Version 1.9
+## 10/12/2010
+## Editor: Alan Hlava
+##
+## Section 3.14.1 has templates for different files
+##
+############################################
+sub fillinEmptyCopyrightBlock
+{
+ my ( $filename, $filetype ) = @_;
+
+ my $copyrightYear = createYearString( $filename );
+
+ ## define the final copyright block template here.
+ my $converted_file = convert_mirror_file($filename);
+ my $IBMCopyrightBlock = genCopyrightBlock($converted_file,$filetype);
+
+ ## Modify file in place with temp file Perl Cookbook 7.8
+ my $savedbgfile = "$filename.fillin";
+ system( "cp -p $filename $TempFile" ); ## preserve file permissions
+ open( INPUT, "< $filename" ) or die " $? can't open $filename: $!" ;
+ my $newline;
+ my $lines = "";
+ while ( defined($newline = <INPUT>) ) { $lines .= $newline; }
+
+ # Replace existing block with the current content.
+ $lines =~ s/$DELIMITER_BEGIN[^\$]*$DELIMITER_END/$IBMCopyrightBlock/s;
+
+ open( OUTPUT, "> $TempFile" ) or die " $? can't open $TempFile: $!" ;
+ select( OUTPUT ); ## new default filehandle for print
+ print OUTPUT $lines;
+
+ ## finish up the files
+ close( INPUT ) or die " $? can't close $filename: $!" ;
+ close( OUTPUT ) or die " $? can't close $TempFile: $!" ;
+ rename( $filename, "$savedbgfile" ) or die " $? can't rename $filename: $!" ;
+ rename( $TempFile, $filename ) or die " $? can't rename $TempFile: $!" ;
+ if ( !$opt_debug )
+ {
+ ## leave the files around for debug
+ unlink( $savedbgfile ) or die " $? can't delete $savedbgfile: $!";
+ }
+}
+
+#######################################
+## Gets file contirbutors based on git log of a file
+##
+## @parma[in] filename
+##
+## @return hash of contributors (key,value) => (name/company, 1)
+#######################################
+sub getFileContributors
+{
+ my ( $filename ) = @_;
+ # Create a "set like" hash for file contributors to handle duplicates
+ # so key is the only important information
+ my %fileContributors = ();
+
+ # Check file for company Origin
+ my $gitDomain = `git log --follow --find-copies-harder -C85% -M85% -- $filename | grep Origin: | sort | uniq`;
+ my @gitDomain = split('\n', $gitDomain);
+ foreach my $origin (@gitDomain)
+ {
+ chomp($origin);
+ # Remove all characters through word "Origin:"
+ $origin =~ s/[^:]*\://;
+ # Remove white space after colon
+ $origin =~ s/^\s+//;
+ if (exists($fileContributorsCompany{$origin}))
+ {
+ # Add company info for copyright contribution
+ $fileContributors{$fileContributorsCompany{$origin}} = 1;
+ }
+ }
+
+ # Check file for all contributors
+ my $gitAuthors = `git log --follow --find-copies-harder -C85% -M85% --pretty="%aN <%aE>" -- $filename | sort | uniq`;
+ my @gitAuthors = split('\n', $gitAuthors);
+
+ # Add current commiter.
+ # If running copyright_check run 'git log' as a commit is not taking place
+ # Otherwise check using 'git config' as this is a pre-commit hook
+ my $curAuthorEmail = "";
+ if ($copyright_check)
+ {
+ $curAuthorEmail = `git log -n1 --pretty=format:"%aN <%aE>"`;
+ chomp($curAuthorEmail);
+ }
+ else
+ {
+ my $curAuthorName = `git config user.name`;
+ $curAuthorEmail = `git config user.email`;
+ chomp($curAuthorEmail);
+ $curAuthorEmail = "$curAuthorName <".$curAuthorEmail.">";
+ }
+ push(@gitAuthors, $curAuthorEmail);
+ foreach my $contributor (@gitAuthors)
+ {
+ my $companyExists = 0;
+ chomp($contributor);
+ # Grab company domain out of contributor's email
+ my $domain = substr ($contributor, index($contributor, '@') + 1, -1);
+
+ # Due to multiple prefixes for IBM like us, in, linux, etc will try
+ # removing characters up to each period (.) until correct domain
+ # address found
+ my @domainSections = split(/\./,$domain);
+ for (my $i = 0; $i < @domainSections; $i++)
+ {
+ if (exists($fileContributorsCompany{$domain}))
+ {
+ $companyExists = 1;
+ last;
+ }
+ # Remove all characters upto & including the first period (.) seen
+ $domain =~ s/[^.]*\.//;
+ }
+
+ #Check if contributor's company exists
+ if ($companyExists)
+ {
+ # Add company info for copyright contribution
+ $fileContributors{$fileContributorsCompany{$domain}} = 1;
+ }
+ else
+ {
+ my $name = substr ($contributor, 0, index($contributor, '<') -1);
+ if($name)
+ {
+ # Add individual info for copyright contribution
+ $fileContributors{$name} = 1;
+ }
+ else
+ {
+ die("Cannot find name of contributor in git commit");
+ }
+ }
+ }
+ return %fileContributors;
+}
diff --git a/sbe/build/tools/hooks/gerrit-hostname b/sbe/build/tools/hooks/gerrit-hostname
new file mode 100755
index 00000000..5299a014
--- /dev/null
+++ b/sbe/build/tools/hooks/gerrit-hostname
@@ -0,0 +1,79 @@
+#!/usr/bin/perl
+# IBM_PROLOG_BEGIN_TAG
+# This is an automatically generated prolog.
+#
+# $Source: sbe/build/tools/hooks/gerrit-hostname $
+#
+# OpenPOWER sbe Project
+#
+# Contributors Listed Below - COPYRIGHT 2016
+# [+] International Business Machines Corp.
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# IBM_PROLOG_END_TAG
+
+## Usage
+# It is imperative that there are no prints other than the die command or
+# "export GERRIT_SRV=$host" as this script is evaluated by env.bash and not
+# called directly
+
+use strict;
+
+my $homeDir = $ENV{'HOME'};
+my $sshConfigFile = $homeDir."/.ssh/config";
+# If the server changes location these will change
+my $gerritHostname = "ralgit01.raleigh.ibm.com";
+my $gerritPort = "29418";
+
+open(CONFIG, "< $sshConfigFile") or die " $? can't open $sshConfigFile: $!" ;
+
+my $host = "";
+my $hostname = "";
+my $port = "";
+while (my $line = <CONFIG>)
+{
+ # Whitespace after each constant is important
+ if ($line =~ m/^Host [^\s]/)
+ {
+ ($host) = $line =~ m/^Host (.*?)\s/
+ }
+ elsif ($line =~ m/Hostname [^\s]/)
+ {
+ ($hostname) = $line =~ m/^*Hostname (.*)/;
+ }
+ elsif ($line =~ m/Port [^\s]/)
+ {
+ ($port) = $line =~ m/^*Port (.*)/;
+ }
+
+ # Check if we found the gerrit host name
+ if ($host ne "" &&
+ $hostname eq $gerritHostname &&
+ $port eq $gerritPort)
+ {
+ last;
+ }
+}
+close(CONFIG);
+
+if ($host eq "")
+{
+ die "Error> Could not find gerrit host in $sshConfigFile";
+}
+else
+{
+ # Set gerrit server env variable by returning command to env.bash
+ print "export GERRIT_SRV=$host\n";
+}
diff --git a/sbe/build/tools/hooks/post-commit b/sbe/build/tools/hooks/post-commit
new file mode 100755
index 00000000..a993cd78
--- /dev/null
+++ b/sbe/build/tools/hooks/post-commit
@@ -0,0 +1,33 @@
+#!/bin/sh
+# IBM_PROLOG_BEGIN_TAG
+# This is an automatically generated prolog.
+#
+# $Source: sbe/build/tools/hooks/post-commit $
+#
+# OpenPOWER sbe Project
+#
+# Contributors Listed Below - COPYRIGHT 2016
+# [+] International Business Machines Corp.
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# IBM_PROLOG_END_TAG
+
+# NOTE: pre-commit hook and its associated helper functions are all
+# maintained same as that of Hoostboot except for minor changes to
+# suit the PPE environment.
+
+if [ -z $MIRROR ]; then
+ $TOOLSDIR/verify-commit
+fi
diff --git a/sbe/build/tools/hooks/pre-commit b/sbe/build/tools/hooks/pre-commit
new file mode 100755
index 00000000..324cd3c1
--- /dev/null
+++ b/sbe/build/tools/hooks/pre-commit
@@ -0,0 +1,41 @@
+#!/bin/sh
+# IBM_PROLOG_BEGIN_TAG
+# This is an automatically generated prolog.
+#
+# $Source: sbe/build/tools/hooks/pre-commit $
+#
+# OpenPOWER sbe Project
+#
+# Contributors Listed Below - COPYRIGHT 2016
+# [+] International Business Machines Corp.
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# IBM_PROLOG_END_TAG
+
+# NOTE: pre-commit hook and its associated helper functions are all
+# maintained same as that of Hoostboot except for minor changes to
+# suit the PPE environment.
+
+if [ -z $MIRROR ]; then
+ if [ -f $TOOLSDIR/pre-commit-actions ]; then
+ $TOOLSDIR/pre-commit-actions
+ # Legacy support for older releases
+ elif [ -f $TOOLSDIR/pre-commit-prologs ]; then
+ $TOOLSDIR/pre-commit-prologs
+ else
+ echo "Missing pre-commit files"
+ exit -1
+ fi
+fi
diff --git a/sbe/build/tools/hooks/pre-commit-actions b/sbe/build/tools/hooks/pre-commit-actions
new file mode 100755
index 00000000..348b0d0b
--- /dev/null
+++ b/sbe/build/tools/hooks/pre-commit-actions
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+# IBM_PROLOG_BEGIN_TAG
+# This is an automatically generated prolog.
+#
+# $Source: sbe/build/tools/hooks/pre-commit-actions $
+#
+# OpenPOWER sbe Project
+#
+# Contributors Listed Below - COPYRIGHT 2016
+# [+] International Business Machines Corp.
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# IBM_PROLOG_END_TAG
+# This hook is used to add or update copyright prolog statements and run
+# the code beautifier astyle.
+
+my $copyrightScript = "addCopyright.pl";
+
+## Make up a list of all staged files ( --cached --name-only )
+## Filter for only Added or Modified ( --diff-filter=AM )
+chomp( my @fileList = `git diff --cached --name-only --diff-filter=AM` );
+
+
+if ( @fileList )
+{
+ print "run $copyrightScript update ...\n";
+ print " $_\n" foreach @fileList;
+ print "\n";
+
+ system "$ENV{'TOOLSDIR'}/$copyrightScript update @fileList";
+ die("$?") if ($? != 0);
+
+ system "git add @fileList";
+ exit 1 if ($? != 0);
+}
+
+exit 0;
diff --git a/sbe/build/tools/hooks/pre-commit-prologs b/sbe/build/tools/hooks/pre-commit-prologs
new file mode 100755
index 00000000..95ae1874
--- /dev/null
+++ b/sbe/build/tools/hooks/pre-commit-prologs
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+# IBM_PROLOG_BEGIN_TAG
+# This is an automatically generated prolog.
+#
+# $Source: sbe/build/tools/hooks/pre-commit-prologs $
+#
+# OpenPOWER sbe Project
+#
+# Contributors Listed Below - COPYRIGHT 2016
+# [+] International Business Machines Corp.
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# IBM_PROLOG_END_TAG
+# This hook is used to add or update copyright prolog statements
+
+my $script = "addCopyright.pl";
+
+## Make up a list of all staged files ( --cached --name-only )
+## Filter for only Added or Modified ( --diff-filter=AM )
+chomp( my @fileList = `git diff --cached --name-only --diff-filter=AM` );
+
+if ( @fileList )
+{
+ print "run $script update ...\n";
+ print " $_\n" foreach @fileList;
+ print "\n";
+
+ system "$ENV{'TOOLS_DIR'}/$script update @fileList";
+ die("$?") if ($? != 0);
+
+ system "git add @fileList";
+ exit 1 if ($? != 0);
+}
+
+exit 0;
diff --git a/sbe/build/tools/hooks/setupgithooks.sh b/sbe/build/tools/hooks/setupgithooks.sh
new file mode 100755
index 00000000..b85300a9
--- /dev/null
+++ b/sbe/build/tools/hooks/setupgithooks.sh
@@ -0,0 +1,64 @@
+#!/bin/sh
+# IBM_PROLOG_BEGIN_TAG
+# This is an automatically generated prolog.
+#
+# $Source: sbe/build/tools/hooks/setupgithooks.sh $
+#
+# OpenPOWER sbe Project
+#
+# Contributors Listed Below - COPYRIGHT 2016
+# [+] International Business Machines Corp.
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# IBM_PROLOG_END_TAG
+
+# Each developer runs this from the git_repo base dir, where it will copy the
+# needed scripts into .git/hooks/ directory and make them executable.
+
+if [ -d $HOOKSDIR ]
+then
+
+ # Get hooks from Gerrit, if needed.
+ if [ ! -f $HOOKSDIR/commit-msg ]
+ then
+ echo "Copying Gerrit hooks..."
+ scp -p -q $GERRIT_SRV:hooks/commit-msg $HOOKSDIR
+ fi
+
+ # Copy custom pre/post commit hooks from tools directory.
+ if [ -f "$TOOLSDIR/pre-commit" -a \
+ -f "$TOOLSDIR/post-commit" ]
+ then
+ echo "Copying pre/post commit hooks..."
+
+ cp $TOOLSDIR/pre-commit $HOOKSDIR/
+ cp $TOOLSDIR/pre-commit $HOOKSDIR/pre-applypatch
+ cp $TOOLSDIR/post-commit $HOOKSDIR/
+
+ chmod u+x $HOOKSDIR/pre-commit
+ chmod u+x $HOOKSDIR/pre-applypatch
+ chmod u+x $HOOKSDIR/post-commit
+
+ else
+ echo "Cannot find or access pre or post commit scripts"
+ exit 1
+ fi
+
+else
+ echo "Cannot find or access .git/hooks directory"
+ exit 1
+fi
+
+exit 0
diff --git a/sbe/build/tools/hooks/verify-commit b/sbe/build/tools/hooks/verify-commit
new file mode 100755
index 00000000..c29ba9ac
--- /dev/null
+++ b/sbe/build/tools/hooks/verify-commit
@@ -0,0 +1,359 @@
+#!/usr/bin/perl
+# IBM_PROLOG_BEGIN_TAG
+# This is an automatically generated prolog.
+#
+# $Source: sbe/build/tools/hooks/verify-commit $
+#
+# OpenPOWER sbe Project
+#
+# Contributors Listed Below - COPYRIGHT 2016
+# [+] International Business Machines Corp.
+#
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+# implied. See the License for the specific language governing
+# permissions and limitations under the License.
+#
+# IBM_PROLOG_END_TAG
+
+use strict;
+
+my $issueFound = 0;
+my $errorFound = 0;
+
+my $projectName = $ENV{'PROJECT_NAME'};
+# Relative path of import tree from project root
+my $importPrefix = $ENV{'IMPORT_REL_PATH'}."/";
+
+verifyPatchSet(); # Verify the patch contents.
+verifyCommitMsg(); # Verify the commit message.
+
+# Finish out the divider.
+if ($issueFound)
+{
+ print "------------------------------------------------------------\n";
+}
+
+# Return a bad RC if we found an error. Let warnings pass.
+exit ($errorFound ? -1 : 0);
+
+
+########################### Subroutines ################################
+
+# @sub verifyPatchSet
+#
+# Extract the contents (lines changed) from the patch set and verify.
+#
+sub verifyPatchSet
+{
+ # git-diff options:
+ # * Diff against the previous commit (HEAD~1)
+ # * Filter only added and modified files (AM).
+ # * Show only the lines changed, with no context (U0).
+ # Grep only the lines marked with "+" (instead of "-") to find just the
+ # actions done by this patchset and not the content removed.
+ open PATCH_CONTENTS, "git diff HEAD~1 --diff-filter=AM -U0 | ".
+ "grep -e \"^+\" -e \"^@@.*+[0-9]\\+\" |";
+
+ my %fileContents = ();
+
+ my $lastFile = "";
+ my $fileLines = ();
+ my $lineCount = 0;
+ while (my $line = <PATCH_CONTENTS>)
+ {
+ chomp $line;
+
+ # Line starting with "+++ b/path/to/file" indicate a new file.
+ if ($line =~ m/^\+\+\+ b\/(.*)/)
+ {
+ # Save previous file into the map.
+ if ($lastFile ne "")
+ {
+ $fileContents{$lastFile} = $fileLines;
+ $fileLines = ();
+ $lineCount = 0;
+ }
+ $lastFile = $1;
+ }
+ # Lines starting with "@@" indicates a seek in the file, so update
+ # line numbers.
+ elsif ($line =~ m/^@@.*\+([0-9]+)/)
+ {
+ $lineCount = $1 - 1;
+ }
+ else
+ {
+ $line =~ s/^\+//; # filter off the leading + symbol.
+ $lineCount++;
+ push @{$fileLines}, [$line, $lineCount];
+ }
+ }
+ if ($lastFile ne "") # Save last file into the map.
+ {
+ $fileContents{$lastFile} = $fileLines;
+ $fileLines = ();
+ }
+
+ # Verify each line of each file.
+ foreach my $file (sort keys %fileContents)
+ {
+ foreach my $line (@{$fileContents{$file}})
+ {
+ verifyFileLine($file, @{$line}[0], @{$line}[1]);
+ }
+ }
+}
+
+# @sub verifyFileLine
+#
+# Checks a particular line of the file for the following issues:
+# * Warning: Lines longer than 80 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.
+# * Warning: NOMERGE tag found.
+#
+sub verifyFileLine
+{
+ my ($file,$line,$count) = @_;
+
+ # Check if file was mirrored
+ my $mirror = 0;
+ if ($file =~ m/^$importPrefix/)
+ {
+ $mirror = 1;
+ }
+
+ # Check line length.
+ if (length($line) > 80)
+ {
+ # 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)/))
+ {
+ }
+ else
+ {
+ warning($file,$line,$count,
+ (sprintf "Length is more than 80 characters (%d).",
+ length($line))
+ );
+ }
+ }
+
+ # Check trailing whitespace.
+ if ($line =~ m/\s$/)
+ {
+ warning($file,$line,$count,
+ "Trailing whitespace found.");
+ }
+
+ # Check tabs.
+ if ($line =~ m/\t/)
+ {
+ # Makefiles are ok (require tabs).
+ if (not (($file =~ m/makefile/) || ($file =~ m/\.mk/)))
+ {
+ warning($file,$line,$count,
+ "Tab character found.");
+ }
+ }
+
+ # Check "TODO" or "FIXME" type comments.
+ if (($line =~ m/TODO/i) || ($line =~ m/FIXME/i))
+ {
+ if ( (not ($line =~ m/RTC[\s:]\s*[0-9]+/)) &&
+ (not ($line =~ m/CQ[\s:]\s*[A-Z][A-Z][0-9]+/)))
+ {
+ warning($file,$line,$count,
+ "TODO/FIXME tag without corresponding RTC or CQ number.");
+ }
+ }
+
+ # Check "NOMERGE" type comment.
+ if ($line =~ m/NOMERGE/i)
+ {
+ warning($file,$line,$count,
+ "NOMERGE tag found.");
+ }
+
+ # Check for "Confidential", unless it's a mirrored commit
+ if ($line =~ m/Confidential/i && $projectName =~ m/HostBoot/i && !$mirror)
+ {
+ unless (($file =~ m/verify-commit/) ||
+ ($file =~ m/addCopyright.pl/))
+ {
+ error($file,$line,$count,
+ "File contains 'Confidential'.");
+ }
+ }
+}
+
+# @sub verifyCommitMsg
+#
+# Looks at the commit message to verify the following items:
+# * Topic is exactly 1 line long.
+# * Lines are less than 80 characters.
+# * No trailing whitespace.
+# * Tags, such as 'RTC:', are only found in the footer.
+# * Untagged lines are not found in the footer.
+# * RTC tag is formatted correctly.
+# * Warning for lacking RTC tag.
+#
+sub verifyCommitMsg
+{
+ open COMMIT_CONTENTS, "git log -n1 --pretty=format:%B |";
+ my $lineCount = 0;
+ my $rtcTag = "";
+ my $cqTag = "";
+ my $taggedLine = "";
+ my $untaggedLine = "";
+
+ while (my $line = <COMMIT_CONTENTS>)
+ {
+ $lineCount++;
+ chomp $line;
+
+ # Check line length over 80 characters.
+ if (length($line) > 80)
+ {
+ error("Commit Message",$line,$lineCount,
+ (sprintf "Length is more than 80 characters (%d).",
+ length($line))
+ );
+ }
+
+ # Check trailing whitespace.
+ if ($line =~ m/[^\s]+\s$/)
+ {
+ error("Commit Message",$line,$lineCount,
+ "Trailing whitespace found.");
+ }
+
+ # Blank line indicates a new "section".
+ if ($line =~ m/^$/)
+ {
+ # Check for tags outside of the footer.
+ # (new section implies previous section was not a footer)
+ if ("" ne $taggedLine)
+ {
+ error("Commit Message",$taggedLine,$lineCount,
+ "Tagged line found outside commit-msg footer.");
+ }
+
+ $rtcTag = "";
+ $cqTag = "";
+ $untaggedLine = "";
+ $taggedLine = "";
+ }
+ else
+ {
+ # Check for multi-line topic.
+ if ($lineCount == 2)
+ {
+ error("Commit Message",$line,$lineCount,
+ "Topic must be only one line long.");
+ }
+ }
+
+ # Verify format of RTC message.
+ if ($line =~ m/^\s*RTC:\s*[0-9]+(.*)/)
+ {
+ if ("" ne $rtcTag)
+ {
+ error("Commit Message",$line,$lineCount,
+ "Duplicate RTC tag found.");
+ }
+
+ $rtcTag = $line;
+ if ("" ne $1)
+ {
+ error("Commit Message",$line,$lineCount,
+ (sprintf "RTC tag format incorrect (%s).", $1));
+ }
+ }
+
+ if ($line =~ m/^\s*CQ:\s*[A-Z][A-Z][0-9]+(.*)/)
+ {
+ if ("" ne $cqTag)
+ {
+ error("Commit Message",$line,$lineCount,
+ "Duplicate CQ tag found.");
+ }
+
+ $cqTag = $line;
+ if ("" ne $1)
+ {
+ error("Commit Message",$line,$lineCount,
+ (sprintf "CQ tag 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)
+ {
+ $taggedLine = $line;
+ }
+ }
+ else
+ {
+ $untaggedLine = $line;
+ }
+ }
+
+ # Warn for missing RTC tag.
+ if (("" eq $rtcTag) && ("" eq $cqTag))
+ {
+ warning("Commit Message","<end-of-file>",$lineCount,
+ "Neither RTC nor CQ tag found.");
+ }
+
+ # Error for a mix of tag / untagged in the last section (ie. untagged
+ # lines in the footer).
+ if (("" ne $untaggedLine) && ("" ne $taggedLine))
+ {
+ error("Commit Message",$untaggedLine,$lineCount,
+ "Untagged line found in footer.");
+ }
+}
+
+sub warning
+{
+ my ($file, $line, $count, $statement) = @_;
+ print "------------------------------------------------------------\n";
+ print "WARNING: $statement\n";
+ print " $file:$count\n";
+ print " $line\n";
+
+ $issueFound = 1;
+}
+
+sub error
+{
+ my ($file, $line, $count, $statement) = @_;
+ print "------------------------------------------------------------\n";
+ print "ERROR: $statement\n";
+ print " $file:$count\n";
+ print " $line\n";
+
+ $issueFound = 1;
+ $errorFound = 1;
+}
+
OpenPOWER on IntegriCloud