diff options
author | Stephen Cprek <smcprek@us.ibm.com> | 2015-09-01 09:58:09 -0500 |
---|---|---|
committer | A. Patrick Williams III <iawillia@us.ibm.com> | 2015-09-11 13:21:05 -0500 |
commit | 5e2c65da962ea1b62d2f4cd160e17d6720c2832a (patch) | |
tree | 2a1421f450d2d8eed1884b36dc6ee8b25ac87d28 /src/build | |
parent | 2b0eccd26fe5e8f9516b14f4af689bbb085a43c0 (diff) | |
download | talos-hostboot-5e2c65da962ea1b62d2f4cd160e17d6720c2832a.tar.gz talos-hostboot-5e2c65da962ea1b62d2f4cd160e17d6720c2832a.zip |
Allow custom LICENSE_PROLOGS in subdirectories
For files that cannot use the main LICENSE_PROLOG, a custom
LICENSE_PROLOG can be used instead affecting the dir it lives in
and all subdirectories.
Change-Id: Ic6e837ed519590db0fcfbe30f6ebba620bb9555b
Depends-on: I26b6f2326314936b0316f64272230730ecd3f9ee
Reviewed-on: http://gfw160.aus.stglabs.ibm.com:8080/gerrit/20266
Tested-by: Jenkins Server
Tested-by: Jenkins OP Build CI
Tested-by: Jenkins OP HW
Tested-by: FSP CI Jenkins
Reviewed-by: A. Patrick Williams III <iawillia@us.ibm.com>
Diffstat (limited to 'src/build')
-rwxr-xr-x | src/build/tools/addCopyright.pl | 101 |
1 files changed, 78 insertions, 23 deletions
diff --git a/src/build/tools/addCopyright.pl b/src/build/tools/addCopyright.pl index c89ddbf5f..baec244a5 100755 --- a/src/build/tools/addCopyright.pl +++ b/src/build/tools/addCopyright.pl @@ -58,6 +58,7 @@ use POSIX; use Getopt::Long; use File::Basename; use lib dirname (__FILE__); +use Cwd; #------------------------------------------------------------------------------ # Project-specific settings. @@ -72,6 +73,7 @@ my $copyrightSymbol = ""; # set by environment variable in project env.bash my $projectName = $ENV{'PROJECT_NAME'}; my $copyrightStr = "Contributors Listed Below - COPYRIGHT"; +my $projectRoot = $ENV{'PROJECT_ROOT'}; ## note that these use single ticks so that the escape chars are NOT evaluated yet. my $OLD_DELIMITER_END = 'IBM_PROLOG_END'; @@ -83,6 +85,7 @@ 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 @@ -114,6 +117,7 @@ use constant RC_PROJECT_DOES_NOT_MATCH => 7; use constant RC_BAD_CONTRIBUTORS_BLOCK => 8; use constant RC_NO_COPYRIGHT_STRING => 9; use constant RC_INVALID_FILETYPE => 10; +use constant RC_DIFFERS_FROM_CUSTOM_LICENSE_PROLOG => 11; #------------------------------------------------------------------------------ # Global Vars @@ -293,6 +297,26 @@ foreach ( @Files ) 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 ( $DelimiterBegin, $CopyrightBlock, $DelimiterEnd ) = extractCopyrightBlock( $_ ); @@ -589,8 +613,6 @@ sub extractCopyrightBlock( $ ) read( FH, $data, -s FH ) or die "ERROR $? : reading $infile: $!"; close FH; - ## print $data; - # Extract the prolog into beginning delimiter, block data, and end delimiter my @prolog = ( '', '', '' ); @prolog = ($1, $2, $4) if ( $data =~ m/$g_prolog_re/ ); @@ -655,6 +677,22 @@ sub checkCopyrightBlock( $$ ) return RC_PROJECT_DOES_NOT_MATCH; } + ## Check if custom LICENSE_PROLOG + if ($LicenseFile ne $ENV{'LICENSE'}) + { + ## Get desired license + my $custom_prolog = genCopyrightBlock($filename, filetype($filename)); + # Remove delimiter portions that don't exist in $block + # BEGIN and END plus trailing white space + $custom_prolog =~ s/$DELIMITER_BEGIN//; + $custom_prolog =~ s/$DELIMITER_END\s+//; + if ($block ne $custom_prolog) + { + print STDOUT "WARNING: Copyright block does not match custom license prolog file found in $LicenseFile\n"; + return RC_DIFFERS_FROM_CUSTOM_LICENSE_PROLOG; + } + } + ## split into lines and check for specific things ## $Source: src/usr/initservice/istepdispatcher/istepdispatcher.H $ my %blockFileContributorsHash = (); @@ -1059,21 +1097,17 @@ sub addPrologComments($$$) } ############################################ -## fill in the empty copyright block -## Copyright guidelines from: -## FSP ClearCase Architecture -## Version 1.9 -## 10/12/2010 -## Editor: Alan Hlava +## Generates final copyright block ## -## Section 3.14.1 has templates for different files +## @parma[in] filename ## +## @return final copyright block string ############################################ -sub fillinEmptyCopyrightBlock( $$ ) +sub genCopyrightBlock { - my ( $filename, $filetype ) = @_; + my ($filename, $filetype) = @_; - my $copyrightYear = createYearString( $filename ); + my $copyrightYear = createYearString( $filename ); # Get copyright contributors based on hash so no duplicates my %fileContributors = getFileContributors( $filename ); @@ -1100,17 +1134,6 @@ $LicenseContent $DELIMITER_END EOF - ## 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: $!" ; - open( OUTPUT, "> $TempFile" ) or die " $? can't open $TempFile: $!" ; - select( OUTPUT ); ## new default filehandle for print - - my $newline; - my $lines = ""; - while ( defined($newline = <INPUT>) ) { $lines .= $newline; } - if ("Assembly" eq $filetype) { $IBMCopyrightBlock = addPrologComments($IBMCopyrightBlock, '#', ''); @@ -1161,10 +1184,42 @@ EOF 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 $IBMCopyrightBlock = genCopyrightBlock($filename,$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 |