2021-08-21 18:57:11 +08:00
|
|
|
#!/usr/bin/env perl
|
2020-03-23 21:44:29 +08:00
|
|
|
#***************************************************************************
|
|
|
|
# _ _ ____ _
|
|
|
|
# Project ___| | | | _ \| |
|
|
|
|
# / __| | | | |_) | |
|
|
|
|
# | (__| |_| | _ <| |___
|
|
|
|
# \___|\___/|_| \_\_____|
|
|
|
|
#
|
2023-01-02 20:51:48 +08:00
|
|
|
# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
2020-03-23 21:44:29 +08:00
|
|
|
#
|
|
|
|
# This software is licensed as described in the file COPYING, which
|
|
|
|
# you should have received as part of this distribution. The terms
|
2020-11-04 21:02:01 +08:00
|
|
|
# are also available at https://curl.se/docs/copyright.html.
|
2020-03-23 21:44:29 +08:00
|
|
|
#
|
|
|
|
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
|
|
# copies of the Software, and permit persons to whom the Software is
|
|
|
|
# furnished to do so, under the terms of the COPYING file.
|
|
|
|
#
|
|
|
|
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
# KIND, either express or implied.
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: curl
|
2022-05-17 17:16:50 +08:00
|
|
|
#
|
2020-03-23 21:44:29 +08:00
|
|
|
###########################################################################
|
|
|
|
#
|
|
|
|
# Invoke script in the root of the git checkout. Scans all files in git unless
|
|
|
|
# given a specific single file.
|
|
|
|
#
|
|
|
|
# Usage: copyright.pl [file]
|
|
|
|
#
|
|
|
|
|
2022-06-14 16:22:57 +08:00
|
|
|
my %skips;
|
2020-05-24 06:02:33 +08:00
|
|
|
|
2022-06-14 16:22:57 +08:00
|
|
|
# file names
|
|
|
|
my %skiplist = (
|
|
|
|
# REUSE-specific file
|
|
|
|
".reuse/dep5" => "<built-in>",
|
2022-03-18 16:15:15 +08:00
|
|
|
|
2022-06-14 16:22:57 +08:00
|
|
|
# License texts
|
|
|
|
"LICENSES/BSD-3-Clause.txt" => "<built-in>",
|
|
|
|
"LICENSES/BSD-4-Clause-UC.txt" => "<built-in>",
|
|
|
|
"LICENSES/ISC.txt" => "<built-in>",
|
|
|
|
"LICENSES/curl.txt" => "<built-in>",
|
|
|
|
"COPYING" => "<built-in>",
|
2022-06-14 05:50:45 +08:00
|
|
|
|
2020-03-23 21:44:29 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
sub scanfile {
|
|
|
|
my ($f) = @_;
|
|
|
|
my $line=1;
|
|
|
|
my $found = 0;
|
2022-01-10 05:28:04 +08:00
|
|
|
open(F, "<$f") || return -1;
|
2020-03-23 21:44:29 +08:00
|
|
|
while (<F>) {
|
|
|
|
chomp;
|
|
|
|
my $l = $_;
|
|
|
|
# check for a copyright statement and save the years
|
2023-01-28 18:22:35 +08:00
|
|
|
if($l =~ /.* ?copyright .* (\d\d\d\d|)/i) {
|
|
|
|
my $count = 0;
|
2020-03-23 21:44:29 +08:00
|
|
|
while($l =~ /([\d]{4})/g) {
|
|
|
|
push @copyright, {
|
|
|
|
year => $1,
|
|
|
|
line => $line,
|
|
|
|
col => index($l, $1),
|
|
|
|
code => $l
|
|
|
|
};
|
2023-01-28 18:22:35 +08:00
|
|
|
$count++;
|
2020-03-23 21:44:29 +08:00
|
|
|
}
|
2023-01-28 18:22:35 +08:00
|
|
|
if(!$count) {
|
|
|
|
# year-less
|
|
|
|
push @copyright, {
|
|
|
|
year => -1,
|
|
|
|
line => $line,
|
|
|
|
col => index($l, $1),
|
|
|
|
code => $l
|
|
|
|
};
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
$found = $count;
|
2020-03-23 21:44:29 +08:00
|
|
|
}
|
2022-06-13 15:51:32 +08:00
|
|
|
if($l =~ /SPDX-License-Identifier:/) {
|
|
|
|
$spdx = 1;
|
|
|
|
}
|
2020-03-23 21:44:29 +08:00
|
|
|
# allow within the first 100 lines
|
|
|
|
if(++$line > 100) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(F);
|
|
|
|
return $found;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub checkfile {
|
2022-06-14 16:22:57 +08:00
|
|
|
my ($file, $skipped, $pattern) = @_;
|
2022-06-13 15:51:32 +08:00
|
|
|
$spdx = 0;
|
2020-03-23 21:44:29 +08:00
|
|
|
my $found = scanfile($file);
|
|
|
|
|
2022-01-10 05:28:04 +08:00
|
|
|
if($found < 1) {
|
2022-06-14 16:22:57 +08:00
|
|
|
if($skipped) {
|
|
|
|
# just move on
|
|
|
|
$skips{$pattern}++;
|
|
|
|
return 0;
|
|
|
|
}
|
2022-01-10 05:28:04 +08:00
|
|
|
if(!$found) {
|
|
|
|
print "$file:1: missing copyright range\n";
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
# this means the file couldn't open - it might not exist, consider
|
|
|
|
# that fine
|
2022-02-01 23:21:58 +08:00
|
|
|
return 1;
|
2020-03-23 21:44:29 +08:00
|
|
|
}
|
2022-06-13 15:51:32 +08:00
|
|
|
if(!$spdx) {
|
2022-06-14 16:22:57 +08:00
|
|
|
if($skipped) {
|
|
|
|
# move on
|
|
|
|
$skips{$pattern}++;
|
|
|
|
return 0;
|
|
|
|
}
|
2022-06-13 15:51:32 +08:00
|
|
|
print "$file:1: missing SPDX-License-Identifier\n";
|
|
|
|
return 2;
|
|
|
|
}
|
2020-03-23 21:44:29 +08:00
|
|
|
|
2023-01-28 18:22:35 +08:00
|
|
|
if($skipped) {
|
2022-06-14 16:22:57 +08:00
|
|
|
print "$file:1: ignored superfluously by $pattern\n" if($verbose);
|
|
|
|
$superf{$pattern}++;
|
|
|
|
}
|
|
|
|
|
2023-01-28 18:22:35 +08:00
|
|
|
return 1;
|
2020-03-23 21:44:29 +08:00
|
|
|
}
|
|
|
|
|
2022-06-14 16:22:57 +08:00
|
|
|
sub dep5 {
|
|
|
|
my ($file) = @_;
|
|
|
|
my @files;
|
|
|
|
my $copy;
|
|
|
|
open(F, "<$file") || die "can't open $file";
|
|
|
|
my $line = 0;
|
|
|
|
while(<F>) {
|
|
|
|
$line++;
|
|
|
|
if(/^Files: (.*)/i) {
|
2024-03-31 17:52:28 +08:00
|
|
|
my @all = `git ls-files $1`;
|
|
|
|
if(!$all[0]) {
|
|
|
|
print STDERR "$1 matches no files\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
push @files, @all;
|
|
|
|
}
|
2022-06-14 16:22:57 +08:00
|
|
|
}
|
|
|
|
elsif(/^Copyright: (.*)/i) {
|
|
|
|
$copy = $1;
|
|
|
|
}
|
|
|
|
elsif(/^License: (.*)/i) {
|
|
|
|
my $license = $1;
|
|
|
|
for my $f (@files) {
|
|
|
|
chomp $f;
|
|
|
|
if($f =~ /\.gitignore\z/) {
|
|
|
|
# ignore .gitignore
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if($skiplist{$f}) {
|
|
|
|
print STDERR "$f already skipped at $skiplist{$f}\n";
|
|
|
|
}
|
|
|
|
$skiplist{$f} = "dep5:$line";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
undef @files;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(F);
|
|
|
|
}
|
|
|
|
|
|
|
|
dep5(".reuse/dep5");
|
|
|
|
|
2023-01-30 18:47:07 +08:00
|
|
|
my $checkall = 0;
|
2020-03-23 21:44:29 +08:00
|
|
|
my @all;
|
2022-01-07 16:49:42 +08:00
|
|
|
my $verbose;
|
|
|
|
if($ARGV[0] eq "-v") {
|
|
|
|
$verbose = 1;
|
|
|
|
shift @ARGV;
|
|
|
|
}
|
2020-03-23 21:44:29 +08:00
|
|
|
if($ARGV[0]) {
|
2022-01-07 17:06:16 +08:00
|
|
|
push @all, @ARGV;
|
2020-03-23 21:44:29 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
@all = `git ls-files`;
|
2023-01-30 18:47:07 +08:00
|
|
|
$checkall = 1;
|
2020-03-23 21:44:29 +08:00
|
|
|
}
|
2022-06-14 16:22:57 +08:00
|
|
|
|
2020-03-23 21:44:29 +08:00
|
|
|
for my $f (@all) {
|
|
|
|
chomp $f;
|
|
|
|
my $skipped = 0;
|
2022-06-14 16:22:57 +08:00
|
|
|
my $miss;
|
|
|
|
my $wro;
|
|
|
|
my $pattern;
|
|
|
|
if($skiplist{$f}) {
|
|
|
|
$pattern = $skip;
|
|
|
|
$skiplisted++;
|
|
|
|
$skipped = 1;
|
2023-01-30 18:47:07 +08:00
|
|
|
$skip{$f}++;
|
2020-03-23 21:44:29 +08:00
|
|
|
}
|
2022-06-14 16:22:57 +08:00
|
|
|
|
|
|
|
my $r = checkfile($f, $skipped, $pattern);
|
|
|
|
$mis=1 if($r == 2);
|
|
|
|
$wro=1 if(!$r);
|
|
|
|
|
2020-03-23 21:44:29 +08:00
|
|
|
if(!$skipped) {
|
2022-06-14 16:22:57 +08:00
|
|
|
$missing += $mis;
|
|
|
|
$wrong += $wro;
|
2020-03-23 21:44:29 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 16:49:42 +08:00
|
|
|
if($verbose) {
|
|
|
|
print STDERR "$missing files have no copyright\n" if($missing);
|
|
|
|
print STDERR "$wrong files have wrong copyright year\n" if ($wrong);
|
|
|
|
print STDERR "$skiplisted files are skipped\n" if ($skiplisted);
|
2022-06-14 16:22:57 +08:00
|
|
|
|
|
|
|
for my $s (@skiplist) {
|
|
|
|
if(!$skips{$s}) {
|
|
|
|
printf ("Never skipped pattern: %s\n", $s);
|
|
|
|
}
|
|
|
|
if($superf{$s}) {
|
|
|
|
printf ("%s was skipped superfluously %u times and legitimately %u times\n",
|
|
|
|
$s, $superf{$s}, $skips{$s});
|
|
|
|
}
|
|
|
|
}
|
2022-01-07 16:49:42 +08:00
|
|
|
}
|
2020-03-23 21:44:29 +08:00
|
|
|
|
2023-01-30 18:47:07 +08:00
|
|
|
if($checkall) {
|
|
|
|
for(keys %skiplist) {
|
|
|
|
if(!$skip{$_}) {
|
|
|
|
printf STDERR "$_ is marked for SKIP but is missing!\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-23 21:44:29 +08:00
|
|
|
exit 1 if($missing || $wrong);
|