Skip to content

Commit

Permalink
Improve tool/update_copyright.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jan 16, 2024
1 parent 2512cc9 commit 57b867a
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tool/update_copyright.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# GNU General Public License version 2, or
# GNU Lesser General Public License version 2.1.

abort "USAGE: ruby #{$0} NEW_YEAR" unless ARGV.first
abort "USAGE: [ADD_ONLY=1] ruby #{$0} NEW_YEAR" unless ARGV.first
year = Integer(ARGV.first)
new_copyright_year = year

Expand All @@ -33,11 +33,13 @@
*/
EOS

C_COPYRIGHT = JAVA_COPYRIGHT + "\n"

NEW_COPYRIGHT = {
'.rb' => RB_COPYRIGHT,
'.java' => JAVA_COPYRIGHT,
'.c' => JAVA_COPYRIGHT,
'.h' => JAVA_COPYRIGHT,
'.c' => C_COPYRIGHT,
'.h' => C_COPYRIGHT,
}

EXTENSIONS = %w[.java .rb .c .h .md]
Expand All @@ -52,11 +54,13 @@
/Copyright \(c\) \d{4}-\d{4} The JRuby project/, # io/console
/Copyright \(C\) \d{4}-\d{4} Wayne Meissner/, # FFI
/Copyright \(c\) \d{4}, Brian Shirai/, # rubysl-socket
/Copyright \(c\) \d{4}, \d{4} Todd C\. Miller <Todd\.Miller@courtesan\.com>/, # strlcpy.c
/Ruby is copyrighted free software by Yukihiro Matsumoto/, # MRI license
/Copyright(?:::)?\s+\(C\)\s+\d{4}\s+Network Applied Communication Laboratory, Inc\./, # MRI stdlibs: thread, timeout
/\* BEGIN LICENSE BLOCK \**\s*\n\s*\*\s*Version: EPL 2\.0\/GPL 2\.0\/LGPL 2\.1/,
/#+\s*BEGIN LICENSE BLOCK\s*#+\s*\n\s*#\s*Version: EPL 2\.0\/GPL 2\.0\/LGPL 2\.1/,
/This file is part of ruby-ffi\./,
/This is a public domain/,
]

truffle_paths = %w[
Expand All @@ -81,7 +85,6 @@
lib/truffle/pathname
lib/truffle/securerandom
src/main/c/bigdecimal
src/main/c/cext/st.c
src/main/c/date
src/main/c/etc
src/main/c/io-console
Expand All @@ -91,7 +94,9 @@
src/main/c/rbconfig-sizeof
src/main/c/ripper
src/main/c/syslog
src/main/c/yarp
src/main/c/zlib
src/yarp
spec/truffle/fixtures/hello-world
test/truffle/pack-real-usage.rb
test/truffle/cexts
Expand All @@ -115,7 +120,7 @@
excludes.none? { |prefix| path.start_with? prefix } &&
!excluded_files.include?(File.basename(path)) &&
File.exist?(path) &&
File.readlines(path).size > 2
File.readlines(path).size > 5
}

paths.each do |file|
Expand All @@ -134,9 +139,12 @@
next
end

next if ENV["ADD_ONLY"]

copyright, year1, sep, year2 = $~[:copyright], $~[:year1], $~[:sep], $~[:year2]
year1 = Integer(year1)
year2 = Integer(year2 || year1)
sep ||= md ? '-' : ', '

if year > year2
contents = File.read(file)
Expand Down

0 comments on commit 57b867a

Please sign in to comment.