bldsystemtools/commonbldutils/SFUpdateLicenceHeader.pl
branchRCL_3
changeset 3 8a441e81fe63
parent 2 99082257a271
equal deleted inserted replaced
2:99082257a271 3:8a441e81fe63
    27 ####################
    27 ####################
    28 # Constants
    28 # Constants
    29 ####################
    29 ####################
    30 
    30 
    31 # Tool version
    31 # Tool version
    32 use constant VERSION => '2.1';
    32 use constant VERSION => '2.22';
    33 # Version history: 0.8 Added copyright year pick-up
    33 # Version history: 0.8 Added copyright year pick-up
    34 # Version history: 0.9- Bug fixesg
    34 # Version history: 0.9- Bug fixesg
    35 # Version history: 0.95- EPL header support added
    35 # Version history: 0.95- EPL header support added
    36 # Version history: 0.96 Minor script adjustments
    36 # Version history: 0.96 Minor script adjustments
    37 # Version history: 0.97 Assembly files (.s, .cia, .asm) checked as well
    37 # Version history: 0.97 Assembly files (.s, .cia, .asm) checked as well
    78 # Version history: 2.0 handleDistributionValue() changes IDs 0-->3/7 and 3-->7, 
    78 # Version history: 2.0 handleDistributionValue() changes IDs 0-->3/7 and 3-->7, 
    79 #                      isGeneratedHeader() checks for file content added.
    79 #                      isGeneratedHeader() checks for file content added.
    80 # Version history: 2.01 checkPortionsCopyright implemented and applied
    80 # Version history: 2.01 checkPortionsCopyright implemented and applied
    81 # Version history: 2.02 Extra license word taken out from EPL header
    81 # Version history: 2.02 Extra license word taken out from EPL header
    82 # Version history: 2.1 -verify -epl support added and switchLicense() tried first for SFL --> EPL switching
    82 # Version history: 2.1 -verify -epl support added and switchLicense() tried first for SFL --> EPL switching
       
    83 # Version history: 2.20 Bug fixes.
    83 
    84 
    84 my $IGNORE_MAN ='Ignore-manually';
    85 my $IGNORE_MAN ='Ignore-manually';
    85 my $IGNORE ='Ignore';
    86 my $IGNORE ='Ignore';
    86 my $INTERNAL = 'internal';
    87 my $INTERNAL = '/internal/';
    87 use constant KEEP_SYMBIAN => 0;
    88 use constant KEEP_SYMBIAN => 0;
    88 use constant REMOVE_SYMBIAN => 1;
    89 use constant REMOVE_SYMBIAN => 1;
    89 
    90 
    90 
    91 
    91 #file extention list that headers should be replace
    92 #file extention list that headers should be replace
    92 my @extlist = ('.cpp', '.c', '.h', '.mmp', '.mmpi', '.rss', '.hrh', '.inl', '.inf', '.iby', '.oby',
    93 my @extlist = ('.cpp', '.c', '.h', '.mmp', '.mmpi', '.rss', '.hrh', '.inl', '.inf', '.iby', '.oby',
    93             '.loc', '.rh', '.ra', '.java', '.mk', '.bat', '.cmd', '.pkg', '.rls', '.rssi', '.pan', '.py', '.pl', '.s', '.asm', '.cia',
    94             '.loc', '.rh', '.ra', '.java', '.mk', '.bat', '.cmd', '.pkg', '.rls', '.rssi', '.pan', '.py', '.pl', '.s', '.asm', '.cia',
    94             '.s60', '.pm', '.hpp', '.mmh', '.script', 
    95             '.s60', '.pm', '.hpp', '.mmh', '.script', '.mrp',
    95             '.pro', '.pri');  # Qt specific
    96             '.pro', '.pri');  # Qt specific
    96 
    97 
    97 # Various header comment styles
    98 # Various header comment styles
    98 my @header_regexps = 
    99 my @header_regexps = 
    99 (
   100 (
   117 my $linenumtext = "1";  # Use this linenumer in LXR links
   118 my $linenumtext = "1";  # Use this linenumer in LXR links
   118 
   119 
   119 # Copyright patterns
   120 # Copyright patterns
   120 my $copyrYearPattern = 'Copyright\b.*\d{4}\s*([,-]\s*\d{4})*';
   121 my $copyrYearPattern = 'Copyright\b.*\d{4}\s*([,-]\s*\d{4})*';
   121 my $copyrYearPattern2 = '\d{4}(\s*[,-]\s*\d{4})*';
   122 my $copyrYearPattern2 = '\d{4}(\s*[,-]\s*\d{4})*';
   122 use constant DEFCOPYRIGHTYEAR => "2009";  # For error cases
   123 use constant DEFCOPYRIGHTYEAR => "2010";  # For error cases
   123 
   124 
   124 my $NokiaCopyrPattern = '\bCopyright\b.*Nokia.*(All Rights)?';
   125 my $NokiaCopyrPattern = '\bCopyright\b.*Nokia.*(All Rights)?';
   125 my $NonNokiaCopyrPattern = '\bCopyright\b.*(?!Nokia).*(All Rights)?';
   126 my $NonNokiaCopyrPattern = '\bCopyright\b.*(?!Nokia).*(All Rights)?';
   126 my $CopyrPattern = '\bCopyright\b';
   127 my $CopyrPattern = '\bCopyright\b';
   127 my $RemoveS60TextBlockPattern = 'This material.*Nokia';
   128 my $RemoveS60TextBlockPattern = 'This material.*Nokia';
   143 ###############
   144 ###############
   144 # SFL C/C++ style
   145 # SFL C/C++ style
   145 #
   146 #
   146 my $SFLicenseHeader = 
   147 my $SFLicenseHeader = 
   147 '/*
   148 '/*
   148 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
   149 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
   149 * All rights reserved.
   150 * All rights reserved.
   150 * This component and the accompanying materials are made available
   151 * This component and the accompanying materials are made available
   151 * under the terms of "Eclipse Public License v1.0"
   152 * under the terms of "Eclipse Public License v1.0"
   152 * which accompanies this distribution, and is available
   153 * which accompanies this distribution, and is available
   153 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
   154 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
   174  
   175  
   175 # SFL other comment styles (replace # with actual comment starter)
   176 # SFL other comment styles (replace # with actual comment starter)
   176 #
   177 #
   177 my $SFLicenseHeader_other_template = 
   178 my $SFLicenseHeader_other_template = 
   178 '#
   179 '#
   179 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
   180 # Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
   180 # All rights reserved.
   181 # All rights reserved.
   181 # This component and the accompanying materials are made available
   182 # This component and the accompanying materials are made available
   182 # under the terms of the License "Eclipse Public License v1.0"
   183 # under the terms of the License "Eclipse Public License v1.0"
   183 # which accompanies this distribution, and is available
   184 # which accompanies this distribution, and is available
   184 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
   185 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
   198 # EPL headers
   199 # EPL headers
   199 ###############
   200 ###############
   200 # C/C++ style
   201 # C/C++ style
   201 my $EPLLicenseHeader = 
   202 my $EPLLicenseHeader = 
   202 '/*
   203 '/*
   203 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
   204 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
   204 * All rights reserved.
   205 * All rights reserved.
   205 * This component and the accompanying materials are made available
   206 * This component and the accompanying materials are made available
   206 * under the terms of "Eclipse Public License v1.0"
   207 * under the terms of "Eclipse Public License v1.0"
   207 * which accompanies this distribution, and is available
   208 * which accompanies this distribution, and is available
   208 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
   209 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
   230 
   231 
   231 # EPL other comment styles (replace # with comment starter)
   232 # EPL other comment styles (replace # with comment starter)
   232 #
   233 #
   233 my $EPLLicenseHeader_other_template = 
   234 my $EPLLicenseHeader_other_template = 
   234 '#
   235 '#
   235 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
   236 # Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
   236 # All rights reserved.
   237 # All rights reserved.
   237 # This component and the accompanying materials are made available
   238 # This component and the accompanying materials are made available
   238 # under the terms of "Eclipse Public License v1.0"
   239 # under the terms of "Eclipse Public License v1.0"
   239 # which accompanies this distribution, and is available
   240 # which accompanies this distribution, and is available
   240 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
   241 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
   251 ##############
   252 ##############
   252 # LGPL headers
   253 # LGPL headers
   253 ##############
   254 ##############
   254 my $LGPLLicenseHeader = 
   255 my $LGPLLicenseHeader = 
   255 '/*
   256 '/*
   256 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
   257 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
   257 * All rights reserved.
   258 * All rights reserved.
   258 *
   259 *
   259 * This program is free software: you can redistribute it and/or modify
   260 * This program is free software: you can redistribute it and/or modify
   260 * it under the terms of the GNU Lesser General Public License as published by
   261 * it under the terms of the GNU Lesser General Public License as published by
   261 * the Free Software Foundation, version 2.1 of the License.
   262 * the Free Software Foundation, version 2.1 of the License.
   285 
   286 
   286 # LGPL other comment styles (replace # with comment starter)
   287 # LGPL other comment styles (replace # with comment starter)
   287 #
   288 #
   288 my $LGPLLicenseHeader_other_template = 
   289 my $LGPLLicenseHeader_other_template = 
   289 '#
   290 '#
   290 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
   291 # Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). 
   291 # All rights reserved.
   292 # All rights reserved.
   292 #
   293 #
   293 # This program is free software: you can redistribute it and/or modify
   294 # This program is free software: you can redistribute it and/or modify
   294 # it under the terms of the GNU Lesser General Public License as published by
   295 # it under the terms of the GNU Lesser General Public License as published by
   295 # the Free Software Foundation, version 2.1 of the License.
   296 # the Free Software Foundation, version 2.1 of the License.
   585         return; # All done
   586         return; # All done
   586     }
   587     }
   587     
   588     
   588 	elsif ( (lc($suffix) eq ".mk" ) or 
   589 	elsif ( (lc($suffix) eq ".mk" ) or 
   589           (lc($suffix) eq ".pl") or (lc($suffix) eq ".py") or (lc($suffix) eq ".pm") or # script
   590           (lc($suffix) eq ".pl") or (lc($suffix) eq ".py") or (lc($suffix) eq ".pm") or # script
   590           (lc($suffix) eq ".pro") or (lc($suffix) eq ".pri") )   # Qt specific
   591           (lc($suffix) eq ".pro") or (lc($suffix) eq ".pri") or    # Qt specific
       
   592           (lc($suffix) eq ".mrp") )
   591     {
   593     {
   592         # Makefile, Perl or Python script  (# comment)
   594         # Makefile, Perl or Python script  (# comment)
   593 		$cm = '#';
   595 		$cm = '#';
   594 		$cm2 = '#';
   596 		$cm2 = '#';
   595 		$newheader = &headerOf(OTHER_HEADER());
   597 		$newheader = &headerOf(OTHER_HEADER());
  1193 
  1195 
  1194     printLog(LOG_DEBUG, "$full_filename content=$content\n");
  1196     printLog(LOG_DEBUG, "$full_filename content=$content\n");
  1195 
  1197 
  1196     if ($dir =~ m/$INTERNAL/i)
  1198     if ($dir =~ m/$INTERNAL/i)
  1197     {
  1199     {
  1198         if ( ($content eq SFL_DISTRIBUTION_VALUE) || ($content eq EPL_DISTRIBUTION_VALUE) )
  1200         my $isSFId = &isSFDistribution($content);
  1199         {
  1201         if ( $isSFId )
  1200             # Internal directory has SFL or EPL distribution value, something is wrong !
  1202         {
       
  1203             # Internal directory has SF distribution value, something is wrong !
  1201             my $comment = "";  # Leave it just empty
  1204             my $comment = "";  # Leave it just empty
  1202             printResult(DISTRIBUTION_CONTEXT() . "$sep"."Internal directory going to SF (current value $content)$sep$comment$sep$sep$full_filename$sep$linenumtext\n");
  1205             printResult(DISTRIBUTION_CONTEXT() . "$sep"."Internal directory going to SF (current value $content)$sep$comment$sep$sep$full_filename$sep$linenumtext\n");
  1203             $verifyFailedCount[VERI_INTERNAL_TO_SF]++;
  1206             $verifyFailedCount[VERI_INTERNAL_TO_SF]++;
  1204         }
  1207         }
  1205     }
  1208     }
  1435 my $sflUrl = 'http://www.symbianfoundation.org/legal/sfl-v10.html';
  1438 my $sflUrl = 'http://www.symbianfoundation.org/legal/sfl-v10.html';
  1436 my $eplText = '"Eclipse Public License v1.0"';
  1439 my $eplText = '"Eclipse Public License v1.0"';
  1437 my $eplUrl = 'http://www.eclipse.org/legal/epl-v10.html';
  1440 my $eplUrl = 'http://www.eclipse.org/legal/epl-v10.html';
  1438 my $eplUrlPattern = 'http\:\/\/www\.eclipse\.org\/legal\/epl\-v10\.html';
  1441 my $eplUrlPattern = 'http\:\/\/www\.eclipse\.org\/legal\/epl\-v10\.html';
  1439 my $eplTextPattern = '"Eclipse\s*Public\s*License\s*v1\.0"';
  1442 my $eplTextPattern = '"Eclipse\s*Public\s*License\s*v1\.0"';
  1440 my $oldEplTextPattern = 'the\s*License\s*"Eclipse\s*Public\s*License\s*v1\.0'; # "the License" is unncessary
  1443 my $oldEplTextPattern = 'the\s*License\s*"Eclipse\s*Public\s*License\s*v1\.0"'; # "the License" is unncessary
  1441 
  1444 
  1442 sub switchLicense
  1445 sub switchLicense
  1443 {
  1446 {
  1444     my $filecontent_ref = shift;
  1447     my $filecontent_ref = shift;
  1445     my $header_ref = shift;
  1448     my $header_ref = shift;
  1826 
  1829 
  1827     #
  1830     #
  1828     # OK, it should be Nokia copyrighted file
  1831     # OK, it should be Nokia copyrighted file
  1829     #
  1832     #
  1830 
  1833 
       
  1834     my $isSFId = &isSFDistribution($lastDistributionValue);
       
  1835 
  1831     # Note that partial headers are manually quoted in the declaration
  1836     # Note that partial headers are manually quoted in the declaration
  1832     # Otherwise \Q$EPLText\E would be needed around those ones
  1837     # Otherwise \Q$EPLText\E would be needed around those ones
  1833     # because plain text contains special chars, like .
  1838     # because plain text contains special chars, like .
  1834     printLog(LOG_DEBUG, "handleVerify testheaders: $testValueEpl,$$header_ref\n");
  1839     printLog(LOG_DEBUG, "handleVerify testheaders: $testValueEpl,$$header_ref\n");
  1835 
  1840 
  1845             }
  1850             }
  1846             $verifyFailedCount[VERI_OK]++;
  1851             $verifyFailedCount[VERI_OK]++;
  1847             return 1;  # OK
  1852             return 1;  # OK
  1848        }
  1853        }
  1849 
  1854 
       
  1855         if (!$isSFId)
       
  1856         {
       
  1857             return 1;
       
  1858         }   
       
  1859 
  1850         if (($$header_ref =~ m/$testValueSfl/s) || ($$filecontent_ref =~ m/$testValueSfl/s))
  1860         if (($$header_ref =~ m/$testValueSfl/s) || ($$filecontent_ref =~ m/$testValueSfl/s))
  1851         {
  1861         {
  1852             #  Still SFL header in place
  1862             #  Still SFL header in place
  1853             printResult(HEADER_CONTEXT() . "$sep"."EPL header missing (SFL header used)$sep$sep$lastDistributionValue$sep$fullfilename$sep$linenumtext\n");
  1863             printResult(HEADER_CONTEXT() . "$sep"."EPL header missing (SFL header used)$sep$sep$lastDistributionValue$sep$fullfilename$sep$linenumtext\n");
  1854         }
  1864         }
  1863         $verifyFailedCount[VERI_MISSING_HEADER]++;
  1873         $verifyFailedCount[VERI_MISSING_HEADER]++;
  1864         return 0;
  1874         return 0;
  1865     }
  1875     }
  1866 
  1876 
  1867     # Cross header versus distribution ID
  1877     # Cross header versus distribution ID
  1868     if ($lastDistributionValue ne "")
  1878     if ($isSFId)
  1869     {
  1879     {
  1870         # Also other than 7 may be OK based on the config file
  1880         # Also other than 7 may be OK based on the config file
  1871         my $isSFId = &isSFDistribution($lastDistributionValue);
       
  1872         printLog(LOG_DEBUG, "DEBUG:handleVerify:Other ID OK=$isSFId\n");
  1881         printLog(LOG_DEBUG, "DEBUG:handleVerify:Other ID OK=$isSFId\n");
  1873         if ( ($$filecontent_ref =~ m/$testValueEpl/s) && ($lastDistributionValue ne EPL_DISTRIBUTION_VALUE) )
  1882         if ( ($$filecontent_ref =~ m/$testValueEpl/s) && ($lastDistributionValue ne EPL_DISTRIBUTION_VALUE) )
  1874         {
  1883         {
  1875             printResult(HEADER_CONTEXT() . "$sep"."EPL header vs. distribution id ($lastDistributionValue) mismatch$sep$sep$lastDistributionValue$sep$fullfilename$sep$linenumtext\n");
  1884             printResult(HEADER_CONTEXT() . "$sep"."EPL header vs. distribution id ($lastDistributionValue) mismatch$sep$sep$lastDistributionValue$sep$fullfilename$sep$linenumtext\n");
  1876             $verifyFailedCount[VERI_ID_HEADER_MISMATCH]++;
  1885             $verifyFailedCount[VERI_ID_HEADER_MISMATCH]++;