diff options
| -rwxr-xr-x | src/build/citest/cxxtest-start.sh | 44 | ||||
| -rwxr-xr-x | src/build/tools/addCopyright.pl | 622 | ||||
| -rwxr-xr-x | src/build/tools/copyright-check.sh | 49 | ||||
| -rwxr-xr-x | src/build/tools/pre-commit | 26 | ||||
| -rwxr-xr-x | src/build/tools/pre-commit-prologs | 48 | ||||
| -rwxr-xr-x | src/build/tools/pre-receive | 89 | ||||
| -rwxr-xr-x | src/build/tools/setupgithooks.sh | 55 | 
7 files changed, 928 insertions, 5 deletions
diff --git a/src/build/citest/cxxtest-start.sh b/src/build/citest/cxxtest-start.sh index e7b6e08d2..2793b0722 100755 --- a/src/build/citest/cxxtest-start.sh +++ b/src/build/citest/cxxtest-start.sh @@ -1,17 +1,51 @@  #!/bin/sh +#  IBM_PROLOG_BEGIN_TAG +#  This is an automatically generated prolog.  # -#   Front end to autocitest - script to execute unit tests under simics. +#  $Source: src/build/citest/cxxtest-start.sh $ +# +#  IBM CONFIDENTIAL +# +#  COPYRIGHT International Business Machines Corp. 2011 +# +#  p1 +# +#  Object Code Only (OCO) source materials +#  Licensed Internal Code Source Materials +#  IBM HostBoot Licensed Internal Code +# +#  The source code for this program is not published or other- +#  wise divested of its trade secrets, irrespective of what has +#  been deposited with the U.S. Copyright Office. +# +#  Origin: 30 +# +#  IBM_PROLOG_END  # - -##  when jenkins runs it will create a workspace with the built code tree -##  and drop us into it. -  export WORKSPACE_DIR=`pwd` +export COPYRIGHT_CHECK=${WORKSPACE_DIR}/src/build/tools/copyright-check.sh  export AUTOCITEST=${WORKSPACE_DIR}/src/build/citest/autocitest  export BACKING_BUILD=`cat ${WORKSPACE_DIR}/src/build/citest/etc/bbuild`  CXXTEST_REMOTE_SANDBOX="cxxtest_sb"  HOSTBOOT_IMAGE=img/hbicore_test.bin +# +#   Validate Copyright blocks +if [ -f $COPYRIGHT_CHECK ]; then +    $COPYRIGHT_CHECK +    if [ $? -ne 0 ]; then +        exit 1 +    fi +fi + +# +#   Front end to autocitest - script to execute unit tests under simics. +# +##  when jenkins runs it will create a workspace with the built code tree +##  and drop us into it. + + +  ##  klog to get access to simics tools  AFSPASSWD="/gsa/ausgsa/projects/h/hostboot/gerrit-server/afspasswd.sh"  $AFSPASSWD | klog -cell austin -pipe diff --git a/src/build/tools/addCopyright.pl b/src/build/tools/addCopyright.pl new file mode 100755 index 000000000..f5fc3f4f1 --- /dev/null +++ b/src/build/tools/addCopyright.pl @@ -0,0 +1,622 @@ +#!/usr/bin/perl +#  IBM_PROLOG_BEGIN_TAG +#  This is an automatically generated prolog. +# +#  $Source: src/build/tools/addCopyright.pl $ +# +#  IBM CONFIDENTIAL +# +#  COPYRIGHT International Business Machines Corp. 2011 +# +#  p1 +# +#  Object Code Only (OCO) source materials +#  Licensed Internal Code Source Materials +#  IBM HostBoot Licensed Internal Code +# +#  The source code for this program is not published or other- +#  wise divested of its trade secrets, irrespective of what has +#  been deposited with the U.S. Copyright Office. +# +#  Origin: 30 +# +#  IBM_PROLOG_END + +# Forked from: +# Author: Mark Jerde (mjerde@us.ibm.com) +# Date: Fri Mar 19 17:40:32 2010 UTC +# +# CVS Information: +# $Revision: 1.55 $ +# $Date: 2011/01/10 19:23:05 $ +# $RCSfile: addCopyright.pl,v $ + +use strict; +use warnings; + +#################################### ABOUT #################################### +# 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 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                                        # +############################################################################### + +# Project-specific settings. +# +## my $releaseYear = "2011"; +my $releaseYear = `date +%Y`; +chomp( $releaseYear ); +my $copyrightSymbol = ""; +# my $copyrightSymbol = "(C)";  # Uncomment if unable to use  character. + +my  $projectName            =   "HostBoot"; +my  $DELIMITER_END          =   "IBM_PROLOG_END"; +my  $DELIMITER_BEGIN        =   "IBM_PROLOG_BEGIN_TAG"; +my  $DELIMITER_WARNING_TEXT =   "This is an automatically generated prolog."; +my  $PVALUE                 =   "p1";       ## my best guess + +my  $PVALUE_TEXT            = +"Object Code Only (OCO) source materials +  Licensed Internal Code Source Materials +  IBM $projectName Licensed Internal Code + +  The source code for this program is not published or other- +  wise divested of its trade secrets, irrespective of what has +  been deposited with the U.S. Copyright Office."; +my  $ORIGIN                 =   "30"; + + +# End Project-specific settings + +####################################################################### +# Main +####################################################################### + +if (scalar(@ARGV) < 2) +{ +    usage(); +} + +## +my $operation = shift; +if (not ($operation =~ m/update/i) and +    not ($operation =~ m/validate/i)) +{ +    print "Operation update or validate is required\n"; +    usage(); +} + +##  check for debug mode +my  $debug  =   shift( @ARGV ); +# print   "$debug\n"; +if ( $debug =~ m/debug/i ) +{ +    print   STDERR  "debug mode\n"; +    $debug  =   1; +} +else +{ +    print   STDERR "normal mode\n"; +    unshift( @ARGV , $debug ); +    $debug  =   0; +} + +# Read files and process. +while (defined($_ = shift)) +{ +    my $filetype = filetype($_); +    print "File $_: Type $filetype\n"; + + + +    ## +    ##  validate +    ##      Exit 1 for unknown filetype +    ##      Exit 2 if has old copyright block +    ##      Exit 3 if no copyright block +    ## +    if ( $operation =~  m/validate/i ) +    { +        if  ("Unknown" eq $filetype) +        { +            print "ERROR: File $_ :Unknown Filetype: $_"; +            exit 1; +        } +        if ( hasoldcopyrightblock( $_, $filetype )    ) +        { +            print "ERROR File $_: has old copyright block, please fix\n"; +            exit 2; +        } +         +        if ( ! hascopyrightblock( $_, $filetype )  ) +        { +            print "ERROR File $_: Missing Copyright notice!!!\n"; +            exit 3; +        } +         +        #   good file +        next; +    } + +    ## +    ##  update +    ##  Continue with a warning for unknown filetype -  +    ## +    if ($operation =~ m/update/i) +    { +        if  ("Unknown" eq $filetype) +        { +            print "!!!!! WARNING: File $_ :Unknown Filetype: $_\n"; +            next; +        } +        ##  do a check for the old  "$IBMCopyright:  $"  block +        if ( hasoldcopyrightblock ( $_, $filetype )  ) +        { +            print "ERROR File $_: has old copyright block, please fix\n"; +            exit 2; +        } + +        if ( ! hascopyrightblock( $_, $filetype ) ) +        { +            if ($debug) { print "Add empty copyright block\n";    } +            addEmptyCopyrightBlock( $_, $filetype ); +            ##  check that the first part worked +            if ( ! hascopyrightblock( $_, $filetype ) ) +            { +                print STDERR "Failed to create Copyright block, please fix\n"; +                exit 2; +            } + +            fillInEmptyCopyrightBlock( $_, $filetype ); +        } +    } + +}   #   endwhile + + + +######################################################################### +##  Subroutines +######################################################################### + +####################################### +##  usage:  print usage and quit +####################################### +sub usage +{ +    print "Usage: addCopyright.pl { update | validate } [ debug ] file1 ...\n\n"; +    exit 1; +} + +##################################### +##  log unknown file type - unfinished +##################################### +sub logUnknownFiletype +{ +    my $filename = shift; +    my $fileinfo = shift; + +    # TODO +    print "Unknown filetype: $filename $fileinfo\n"; +} + +##################################### +##  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/\.[cht]$/i ) +       ||( $filename =~ m/\.[cht]\+\+$/i ) +       ||( $filename =~ m/\.[cht]pp$/i ) +       ||( $fileinfo =~ m/c program text/i ) +       ||( $fileinfo =~ m/c\+\+ program text/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/\.xml$/i ) +    { +        return "xml" +    } +    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 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"; +        } +    } +    logUnknownFiletype($filename,$fileinfo); +    return "Unknown"; +} + +###################################### +##  Figure out the first copyright year for the file +##      return as a string +###################################### +sub copyrightFirstYearForFile +{ +    my $file = shift; +    my $fileContent = shift; +    my $year = $releaseYear; +    my @logstrings; +    # TODO find multiple copyright statements and pick the earliest one +    # Search for earlier years from prior release. +    if ($fileContent =~ m/Copyright IBM Corp. (\d{4})/) +    { +        $year = $1 if ($1 < $year); +    } + +    my  $cmd = "git log -- $file | grep Date: | tail --line=1"; +    ## print "run $cmd\n"; +    @logstrings = split( " ", `$cmd` ); + +    #   new files will not have a log, so the "git log" call above will +    #       return nothing.  In this case, just return the old calculated +    #       value. +    if ( (scalar(@logstrings) < 5)  or ($year lt $logstrings[5]) ) +    { +        return $year; +    } +    else +    { +        return $logstrings[5]; +    } +} + +######################################## +##  Figure out the last copyright year for file +##      Return as a string +######################################## +sub copyrightLastYearForFile +{ +    return $releaseYear; +} + + + +####################################### +##  Check for old $IBMCopyrightBlock signature +##      return 1 if it's there, otherwise 0 +####################################### +sub hasoldcopyrightblock +{ +    my ( $filename, $filetype ) =   @_; +    my $file = `head -180 $filename`;       # Must appear in first 180 lines. + +    if ( $file =~ m/\$IBMCopyrightBlock:.*\$/s ) +    { +        return  1; +    } + +    return  0; +} + +####################################### +##  Check for new IBM_PROLOG_BEGIN_TAG signature +##      return 1 if it's there, otherwise 0 +####################################### +sub hascopyrightblock +{ +    my ( $filename, $filetype ) =   @_; +    my $file = `head -180 $filename`;       # Must appear in first 180 lines. +     +    #print $filename; +    #print $file; +    #print   $DELIMITER_BEGIN; +    #print   $DELIMITER_END; + + +    if ( $file =~ m/$DELIMITER_BEGIN.*$DELIMITER_END/s ) +    { +        return  1; +    } + +    return  0; +} +################################### +##  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. +##  - Makes up a temporary file called "<filename>.cvsCPYRT" +################################## +sub addEmptyCopyrightBlock +{ +    my ( $filename, $filetype)  =   @_; +    my $line; +    open(INPUT, $_) or exit; +    system "touch $_.cvsCPYRT"; +    open(OUTPUT, ">$_.cvsCPYRT") or exit; + +    if ("Assembly" eq $filetype) +    { +        ## print OUTPUT ";// \$IBMCopyrightBlock: \$\n"; +        print OUTPUT "#  $DELIMITER_BEGIN $DELIMITER_END\n"; +    } +    elsif (("Autoconf" eq $filetype) or +        ("Automake" eq $filetype) or +        ("CVS" eq $filetype) or +        ("Makefile" eq $filetype) or +        ("Perl" eq $filetype) or +        ("Python" eq $filetype) or +        ("Shellscript" eq $filetype) or +        ("Tcl" eq $filetype)) +    { +        $line = <INPUT>; +        # Keep the '#!' line at the top. +        if ($line =~ m/^#!/) +        { +            print OUTPUT $line; +        } +        ## print OUTPUT "# \$IBMCopyrightBlock: \$\n"; +        print OUTPUT "# $DELIMITER_BEGIN $DELIMITER_END\n"; +        unless ($line =~ m/^#!/) +        { +            print OUTPUT $line; +        } +    } +    elsif ( ("C" eq $filetype) +           ) +    { +        ##print OUTPUT " * \$IBMCopyrightBlock: \$\n"; +        print OUTPUT "// $DELIMITER_BEGIN $DELIMITER_END\n"; +    } +    elsif ( ("RPC" eq $filetype) or +            ("LinkerScript" eq $filetype) +          ) +    { +        # ld stubbornly refuses to use modern comment lines. +        print OUTPUT "/* $DELIMITER_BEGIN $DELIMITER_END\n */\n"; +    } +    elsif ("MofFile" eq $filetype) +    { +        ##print OUTPUT "// \$IBMCopyrightBlock: \$\n"; +        print OUTPUT "// $DELIMITER_BEGIN $DELIMITER_END\n"; +    } +    elsif ("xml" eq $filetype ) +    { +        print   OUTPUT "<!-- $DELIMITER_BEGIN $DELIMITER_END -->\n"; +    } +    else +    { +        print   STDERR  "Can\'t handle filetype:  $filetype\n"; +        exit    1; +    } + +    # Copy rest of file +    while (defined($line = <INPUT>)) +    { +        print OUTPUT $line; +    } +    close OUTPUT; +    close INPUT; +    system "cat $_.cvsCPYRT > $_"; +    system "rm -f $_.cvsCPYRT"; +    system "touch $_"; + +} + +############################################ +##  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 $file = `cat $_`; +    my $firstYear = copyrightFirstYearForFile($_, $file); +    my $lastYear = copyrightLastYearForFile($_); +    my $copyrightYear = $firstYear; +    $copyrightYear .= " - $lastYear" unless ( "$firstYear" eq "$lastYear" ); +    ##  define the final copyright block template here. +    my $IBMCopyrightBlock = +" $DELIMITER_BEGIN +  $DELIMITER_WARNING_TEXT + +  \$Source: $filename \$ + +  IBM CONFIDENTIAL + +  COPYRIGHT International Business Machines Corp. $copyrightYear + +  $PVALUE + +  $PVALUE_TEXT + +  Origin: $ORIGIN + +  $DELIMITER_END"; + + +    if (($file =~ m/$DELIMITER_BEGIN*.$DELIMITER_END/s ) and +        ("Unknown" ne $filetype)) +    { +        open(INPUT, $_ ) or exit; +        system "touch $_.cvsCPYRT"; +        open(OUTPUT, ">$_.cvsCPYRT") or exit; + +        my $newline; +        my $lines = ""; +        while ( defined($newline = <INPUT>) ) { $lines .= $newline; } + +        if ("Assembly" eq $filetype) +        { +            ## assembly +            $IBMCopyrightBlock =~ s/\n/\n# /sg; +        } +        if (("Autoconf" eq $filetype) or +            ("Automake" eq $filetype) or +            ("CVS" eq $filetype) or +            ("Makefile" eq $filetype) or +            ("Perl" eq $filetype) or +            ("Python" eq $filetype) or +            ("Shellscript" eq $filetype) or +            ("Tcl" eq $filetype)) +        { +            $IBMCopyrightBlock =~ s/\n/\n#/sg; +        } +        if (("C" eq $filetype) +           ) +        { +            # Use C++ style comments +            $IBMCopyrightBlock =~ s|\n|\n//|sg; +        } +        if (("RPC" eq $filetype) or +            ("LinkerScript" eq $filetype) +           ) +        { +            $IBMCopyrightBlock =~ s|\n|\n *|sg; +        } +        if ("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"; +        } +        if ("MofFile" eq $filetype) +        { +            $IBMCopyrightBlock =~ s|\n|\n//|sg; +        } +        if ( "xml" eq $filetype) +        { +            $IBMCopyrightBlock =~ s|\n|\n   |sg; +        } + +        # Replace existing block with the current content. +        # $lines =~ s/\$IBMCopyrightBlock:[^\$]*\$/$IBMCopyrightBlock/s; +        $lines =~ s/$DELIMITER_BEGIN[^\$]*$DELIMITER_END/$IBMCopyrightBlock/s; + +        print OUTPUT $lines; +        close OUTPUT; +        close INPUT; + +        system "cat $_.cvsCPYRT > $_"; +        system "rm -f $_.cvsCPYRT"; +        system "touch $_"; +    } +    else +    { +        print "Cannot find empty copyright block\n"; +        exit 1; +    } +} diff --git a/src/build/tools/copyright-check.sh b/src/build/tools/copyright-check.sh new file mode 100755 index 000000000..e2f2421cd --- /dev/null +++ b/src/build/tools/copyright-check.sh @@ -0,0 +1,49 @@ +#!/bin/sh +#  IBM_PROLOG_BEGIN_TAG +#  This is an automatically generated prolog. +# +#  $Source: src/build/tools/copyright-check.sh $ +# +#  IBM CONFIDENTIAL +# +#  COPYRIGHT International Business Machines Corp. 2011 +# +#  p1 +# +#  Object Code Only (OCO) source materials +#  Licensed Internal Code Source Materials +#  IBM HostBoot Licensed Internal Code +# +#  The source code for this program is not published or other- +#  wise divested of its trade secrets, irrespective of what has +#  been deposited with the U.S. Copyright Office. +# +#  Origin: 30 +# +#  IBM_PROLOG_END + +# +#   Front end to addCopyright.pl - script to check for copyright block during +#   Gerrit checkin.   +# + +export WORKSPACE_DIR=`pwd` +export ADDCOPYRIGHT=${WORKSPACE_DIR}/src/build/tools/addCopyright.pl + +##  run git show to get a list of checked in files +CHECKINFILES=`git show --pretty=format: --name-only -n1 | tr '\n' ' '` + +echo "========================================================================" + +echo "  Checking Copyright blocks for checked-in files:" +echo "  $CHECKINFILES" +echo +$ADDCOPYRIGHT validate  $CHECKINFILES + +if [ $? -eq 0 ]; then +    echo "Copyright Check passed OK, $?" +    exit 0 +else        +    echo "ERROR: $?"  +    exit 1 +fi diff --git a/src/build/tools/pre-commit b/src/build/tools/pre-commit new file mode 100755 index 000000000..fd75c73a4 --- /dev/null +++ b/src/build/tools/pre-commit @@ -0,0 +1,26 @@ +#!/bin/sh +#  IBM_PROLOG_BEGIN_TAG +#  This is an automatically generated prolog. +# +#  $Source: src/build/tools/pre-commit $ +# +#  IBM CONFIDENTIAL +# +#  COPYRIGHT International Business Machines Corp. 2011 +# +#  p1 +# +#  Object Code Only (OCO) source materials +#  Licensed Internal Code Source Materials +#  IBM HostBoot Licensed Internal Code +# +#  The source code for this program is not published or other- +#  wise divested of its trade secrets, irrespective of what has +#  been deposited with the U.S. Copyright Office. +# +#  Origin: 30 +# +#  IBM_PROLOG_END + +export GIT_DIR=$GIT_DIR +$GIT_DIR/hooks/pre-commit-prologs diff --git a/src/build/tools/pre-commit-prologs b/src/build/tools/pre-commit-prologs new file mode 100755 index 000000000..775eaaa4d --- /dev/null +++ b/src/build/tools/pre-commit-prologs @@ -0,0 +1,48 @@ +#!/usr/bin/perl +#  IBM_PROLOG_BEGIN_TAG +#  This is an automatically generated prolog. +# +#  $Source: src/build/tools/pre-commit-prologs $ +# +#  IBM CONFIDENTIAL +# +#  COPYRIGHT International Business Machines Corp. 2011 +# +#  p1 +# +#  Object Code Only (OCO) source materials +#  Licensed Internal Code Source Materials +#  IBM HostBoot Licensed Internal Code +# +#  The source code for this program is not published or other- +#  wise divested of its trade secrets, irrespective of what has +#  been deposited with the U.S. Copyright Office. +# +#  Origin: 30 +# +#  IBM_PROLOG_END + +# This hook is used to add or update copyright prolog statements + +$COPYRIGHT_SCRIPT=".git/hooks/addCopyright.pl"; + +##  make up a list of all staged files ( --cached --name-only ) +##      filter for only Added or Modified ( --diff-filter=AM ) +##      paste puts them all on one line.     +my $fileList = `git diff --cached --name-only --diff-filter=AM | paste -s -`; +chomp($fileList); + + +if (length($fileList) > 0) +{ +    my $cmd = "$COPYRIGHT_SCRIPT update $fileList"; +    print   "run $cmd...\n"; +    system $cmd; +    die("$?") if ($? != 0); + +#    print   "re-adding files $fileList\n"; +    system "git add $fileList"; +    exit 1 if ($? != 0); +} + +exit 0; diff --git a/src/build/tools/pre-receive b/src/build/tools/pre-receive new file mode 100755 index 000000000..60b07d4ed --- /dev/null +++ b/src/build/tools/pre-receive @@ -0,0 +1,89 @@ +#!/usr/bin/perl +#  IBM_PROLOG_BEGIN_TAG +#  This is an automatically generated prolog. +# +#  $Source: src/build/tools/pre-receive $ +# +#  IBM CONFIDENTIAL +# +#  COPYRIGHT International Business Machines Corp. 2011 +# +#  p1 +# +#  Object Code Only (OCO) source materials +#  Licensed Internal Code Source Materials +#  IBM HostBoot Licensed Internal Code +# +#  The source code for this program is not published or other- +#  wise divested of its trade secrets, irrespective of what has +#  been deposited with the U.S. Copyright Office. +# +#  Origin: 30 +# +#  IBM_PROLOG_END + +# +#   From "git help githooks" : +#   "This hook executes once for the receive operation. It takes no arguments,  +#       but for each ref to be updated it receives on standard input a line of  +#       the format: +# +#       <old-value> SP <new-value> SP <ref-name> LF +# +#       where <old-value> is the old object name stored in the ref,  +#       <new-value> is the new object name to be stored in the ref,  +#       and <ref-name> is the full name of the ref.  +#       When creating a new ref, <old-value> is 40 0." +# + +$COPYRIGHT_SCRIPT=".git/hooks/addCopyright.pl"; + +print "Processing pre-receive script\n"; + +while (<STDIN>) +{ +    my $refsLine = $_; +    if ($refsLine =~ /([0-9a-f]*) ([0-9a-f]*) (.*)/) +    { +        my ($oldRef, $newRef, $refName) = ($1, $2, $3); +        print "$oldRef, $newRef, $refName\n"; + +        my @diffTreeList = split('\n', `git diff-tree -r --diff-filter=AM $newRef $oldRef`); +        foreach my $diffTreeLine (@diffTreeList) +        { +            #print "$diffTreeLine\n"; +            if ($diffTreeLine =~ m/^:\d*\s*\d*\s*(\S*)\s*(\S*)\s*(\S*)\s*(\S*)/) +            { +                my ($diffNewRef, $diffOldRef, $type, $name) = ($1, $2, $3, $4); +                my $namePart = $name; +                if ($name =~ m/\/([^\/]*)$/) +                { +                    $namePart = $1; +                } + +                if ($diffNewRef != 0) +                { +                    my $tmpName = "/tmp/git_$<_$diffNewRef"."_$namePart"; + +                    system("git show $diffNewRef > $tmpName"); +                    if ($? != 0) +                    { +                        print "Unable to git show $diffNewRef on file $name type $type\n"; +                        exit 1; +                    } +                    # system("/gsa/rchgsa/projects/p/powerhal/tools/addCopyright.pl validate $tmpName"); +                    system( "$COPYRIGHT_SCRIPT validate $tmpname" ); +                    if ($? != 0) +                    { +                        print "File $name does not have a correct prolog\n"; +                        system("rm -f $tmpName"); +                        exit 1; +                    } +                    system("rm -f $tmpName"); +                } +            } +        } +    } +} + +exit 0; diff --git a/src/build/tools/setupgithooks.sh b/src/build/tools/setupgithooks.sh new file mode 100755 index 000000000..64b22c158 --- /dev/null +++ b/src/build/tools/setupgithooks.sh @@ -0,0 +1,55 @@ +#!/bin/sh +#  IBM_PROLOG_BEGIN_TAG +#  This is an automatically generated prolog. +# +#  $Source: src/build/tools/setupgithooks.sh $ +# +#  IBM CONFIDENTIAL +# +#  COPYRIGHT International Business Machines Corp. 2011 +# +#  p1 +# +#  Object Code Only (OCO) source materials +#  Licensed Internal Code Source Materials +#  IBM HostBoot Licensed Internal Code +# +#  The source code for this program is not published or other- +#  wise divested of its trade secrets, irrespective of what has +#  been deposited with the U.S. Copyright Office. +# +#  Origin: 30 +# +#  IBM_PROLOG_END + +#   each developer runs this from the git_repo base dir.   +#   will copy the scripts into .git/hooks/ dir and make them runnable + +ROOTDIR=. +TOOLSDIR=$ROOTDIR/src/build/tools +preCommitScript=pre-commit-prologs +addCopyrightScript=addCopyright.pl + +if [ -f "$TOOLSDIR/$preCommitScript" ] +then +    if [ -d ".git/hooks" ] +    then +        echo "copy files into .git/hooks dir..." +        cp -v $ROOTDIR/src/build/tools/pre-commit          $ROOTDIR/.git/hooks/. +        cp -v $ROOTDIR/src/build/tools/$preCommitScript    $ROOTDIR/.git/hooks/. +        cp -v $ROOTDIR/src/build/tools/$addCopyrightScript $ROOTDIR/.git/hooks/. +         +        chmod u+x $ROOTDIR/.git/hooks/pre-commit +        chmod u+x $ROOTDIR/.git/hooks/$preCommitScript +        chmod u+x $ROOTDIR/.git/hooks/addCopyright.pl +         +    else +        echo "Does not appear that the current working directory is the root of a git repository\n" +        exit 1 +    fi +else +    echo "Cannot find or access $preCommitScript\n" +    exit 1 +fi + +exit 0  | 

