merge_copyrights revision 680cbc050aead48a0de9cdcea621f2747ca5ddc7
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt#!/usr/local/bin/perl -w
990d0e893f5b70e735cdf990af66e9ec6e91fa78Tinderbox User#
3e02c9e33656dcd9c364633d42dd785d3e6fdd66Automatic Updater# Copyright (C) 1998-2001, 2003-2007, 2009-2017 Internet Systems Consortium, Inc. ("ISC")
3e02c9e33656dcd9c364633d42dd785d3e6fdd66Automatic Updater#
c6fb85f9500350e5ce58c9a24f5d264c8a8bd6f4Automatic Updater# This Source Code Form is subject to the terms of the Mozilla Public
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt# License, v. 2.0. If a copy of the MPL was not distributed with this
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt# file, You can obtain one at http://mozilla.org/MPL/2.0/.
3e02c9e33656dcd9c364633d42dd785d3e6fdd66Automatic Updater
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt# $Id$
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
3e02c9e33656dcd9c364633d42dd785d3e6fdd66Automatic Updateruse strict;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Huntmy %file_types = ();
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Huntmy %file_years = ();
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Huntmy %exists = ();
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
ea94d370123a5892f6c47a97f21d1b28d44bb168Tinderbox Useropen(COPYRIGHTS, "<util/copyrights") || die "can't open ./util/copyrights: $!";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Huntwhile (<COPYRIGHTS>) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt chomp;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt my ($file, $type, $years) = split;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$file} = $type;
2cbb4ab75757fbb656997a82c14ca07db37d481aAutomatic Updater $file_years{$file} = $years;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt}
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Huntclose(COPYRIGHTS);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updatermy ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time());
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt$sec = $min = $hour = $mday = $mon = $wday = $yday = $isdst = 0;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt$year += 1900;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Huntopen(FILES, "git ls-files | sed 's;^;./;' |") || die "git ls-files: $!";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Huntwhile (<FILES>) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt chomp;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $exists{$_} = 1;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt}
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Huntclose(FILES);
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Huntopen(CHANGES, "sh util/recent_changes.sh |") || die "recent_changes.sh: $!";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Huntwhile (<CHANGES>) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt chomp;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt # this file isn't in the repository now
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt next unless ($exists{$_});
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt next if (m%/\.\# | # CVS old conflict file
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt /CVS/ | # CVS directory
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt /.git/ | # git directory
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt util/newcopyrights | # our output
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt \.bak$ | # created by update_copyrights
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt /(dnssafe|openssl)/.*\.[ch]$ | # imported
12bfbed87cfffa65ac300b72c5665ab38a355c2fAutomatic Updater doc/(draft|expired|rfc)/ # imported
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt %x);
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User if (!$file_types{$_}) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt # Strip any .in extension to find out the file's real type.
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt # .in files are processed by configure to produce the target file.
fd0b768f4c23d22c89f8a156a632831583b7fb68Automatic Updater my $base;
fd0b768f4c23d22c89f8a156a632831583b7fb68Automatic Updater ($base = $_) =~ s/\.in$//;
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt # Contributed code should maintain its own copyright.
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt if ($base =~ /\.\/contrib\//) {
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User $file_types{$_} = "X";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\.\/unit\/atf-src\//) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "X";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\/openssl-[a-z0-9.]*-patch$/) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "X";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\.(c|h|css)$/) {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater $file_types{$_} = "C";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\.y$/) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "YACC";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\.pl$/i) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "PERL";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\.py$/i) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "PYTHON";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\.sh$/) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "SH";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\.docbook$/ ||
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $base =~ /.xsl$/ ||
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $base =~ /.xml$/) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "SGML";
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updater } elsif ($base =~ /doc\/arm\/.*\.html$/) {
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User $file_types{$_} = "X";
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User } elsif ($base =~ /\.(sty|pdf|eps)$/) {
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User $file_types{$_} = "X";
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User } elsif ($base =~ /\.html$/) {
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User $file_types{$_} = "HTML";
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User $base =~ s/\.html$//;
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User $base = $base . ".docbook";
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User } elsif ($base =~ /\.(man|[0-9])$/) {
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User $file_types{$_} = "MAN";
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User $base =~ s/\.[0-9]$//;
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User $base = $base . ".docbook";
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User } elsif ($base =~ /\/Makefile$/) {
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User $file_types{$_} = "MAKE";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\/(named|rndc|good|bad).{0,2}\.conf$/) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "CONF-C";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\/checkconf\/(good|bad)-.*\.conf$/) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "CONF-C";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\/resolv.?\.conf$/) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "CONF-SH";
12bfbed87cfffa65ac300b72c5665ab38a355c2fAutomatic Updater } elsif ($base =~ /\.(db|hint)$/) {
12bfbed87cfffa65ac300b72c5665ab38a355c2fAutomatic Updater $file_types{$_} = "ZONE";
12bfbed87cfffa65ac300b72c5665ab38a355c2fAutomatic Updater } elsif ($base =~ /\.md$/) {
12bfbed87cfffa65ac300b72c5665ab38a355c2fAutomatic Updater $file_types{$_} = "MKD";
12bfbed87cfffa65ac300b72c5665ab38a355c2fAutomatic Updater } elsif ($base =~ /(\/\.(gitignore|gitattributes)|Atffile|Kyuafile|\.(gif|jpg))$/i) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "X";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\.(def|dep|dsp|dsw|mak|sln)$/i) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "X";
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User } elsif ($base =~ /\.(vcxproj(|\.(user|filters)))$/i) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "X";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\.rnc$/i) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "RNC";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /^\.\/EXCLUDED$/i) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "X";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\.bat$/i) {
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User $file_types{$_} = "BAT";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\.(key|private)$/i) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "X";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\/named\d{0,2}\.args$/i) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "X";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\/named\.port$/i) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "X";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\/named\.dropedns$/i) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "X";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\/named\.notcp$/i) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "X";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\/doc\/misc\/[-a-z]*\.zoneopt$/i) {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater $file_types{$_} = "X";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($base =~ /\/README$/i) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "TXT.BRIEF";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } else {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_types{$_} = "?";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt }
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt my $m_year = int(`sh util/file_year.sh $_`);
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater if (($file_types{$_} eq "MAN" || $file_types{$_} eq "HTML") &&
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $base =~ /\.docbook$/ && -e $base) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_years{$_} = "DOCBOOK";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } elsif ($m_year != $year) {
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt print "$_: must set copyright year(s) manually\n";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt $file_years{$_} = "????";
1bc5499c2a0fc5d2b11849e97cdd6305a64eb242Evan Hunt } else {
$file_years{$_} = "$year";
}
} else {
if (! defined($file_years{$_}) || $file_years{$_} eq "????") {
print "$_: must set copyright year(s) manually\n";
$file_years{$_} = "????";
next;
}
# track the modification years even if we are not going to be
# updating the copyrights.
# next if $file_types{$_} eq "X";
next if ($file_years{$_} =~ /^PARENT:/);
next if ($file_years{$_} eq "DOCBOOK");
my @years = split(/,/, $file_years{$_});
my $has_current = 0;
foreach my $fyear (@years) {
if ($fyear == $year) {
$has_current = 1;
}
}
if (!$has_current) {
$file_years{$_} .= ",$year";
}
}
}
close(CHANGES);
open(NEWCOPYRIGHTS, ">util/newcopyrights") ||
die "can't open newcopyrights: $!";
foreach my $file (sort(keys(%file_types))) {
print NEWCOPYRIGHTS "$file";
my $len = length($file);
my $tabs = 0;
if ($len >= 48) {
$tabs = 1;
} else {
my $needed = int (48 - $len);
$tabs = int ($needed / 8);
if ($needed % 8 != 0) {
$tabs++;
}
}
for (my $i = 0; $i < $tabs; $i++) {
printf NEWCOPYRIGHTS "\t";
}
printf NEWCOPYRIGHTS "%s\t%s\n", $file_types{$file}, $file_years{$file};
if (($file_years{$file} eq "????") || ($file_types{$file} eq "?")) {
print "Unknown file type or year: $file\n";
}
}
close(NEWCOPYRIGHTS);