treewide: future-proof frozen_string_literal changes
commita36cf00dee5d7657bf95b66bd4559feaab010989
authorEric Wong <bofh@yhbt.net>
Thu, 8 Feb 2024 11:58:58 +0000 (8 11:58 +0000)
committerEric Wong <bofh@yhbt.net>
Sat, 23 Mar 2024 17:30:48 +0000 (23 17:30 +0000)
tree7e17cce1d259715baec9846846c21bb876707a69
parent0a20ff1ffabf99de80182be438f43f2c5e03e25b
treewide: future-proof frozen_string_literal changes

Once again Ruby seems ready to introduce more incompatibilities
and force busywork upon maintainers[1].  In order to avoid
incompatibilities in the future, I used the following Perl
script to prepend `frozen_string_literal: false' to every
Ruby file:

use v5.12;
use autodie;
my $usage = 'perl /path/to/script <LIST_OF_RB_FILES>';
my $fsl = "# frozen_string_literal: false\n";
for my $f (@ARGV) {
open my $fh, '<', $f;
my $s = do { local $/; <$fh> } // die "read($f): $!";
next if $s =~ /^#\s*frozen_string_literal:/sm;

# fsl must be after encoding: line if it exists:
if ($s =~ s/^([ \t]*\#[ \t\-\*\#]+encoding:[^\n]+\n)/$1$fsl/sm
# or after the shebang
|| $s =~ s/^(#![^\n]+\n)/$1$fsl/
# or after embedded switches in rackup files:
|| ($f =~ /\.ru$/ &&
$s =~ s/^(#\\[^\n]+\n)/$1$fsl/)
# or prepend as a last resort:
|| (substr($s, 0, 0) = $fsl)) {
open $fh, '>', $f;
print $fh $s;
close $fh;
}
}

Somebody interested will have to go through every Ruby source
file and enable frozen_string_literal once they've thoroughly
verified it's safe to do so.

[1] https://bugs.ruby-lang.org/issues/20205
38 files changed:
examples/linux-listener-stats.rb
examples/middleware.ru
examples/watcher.ru
examples/watcher_demo.ru
examples/yahns.conf.rb
examples/zbatery.conf.rb
ext/raindrops/extconf.rb
lib/raindrops.rb
lib/raindrops/aggregate.rb
lib/raindrops/aggregate/last_data_recv.rb
lib/raindrops/aggregate/pmq.rb
lib/raindrops/last_data_recv.rb
lib/raindrops/linux.rb
lib/raindrops/middleware.rb
lib/raindrops/middleware/proxy.rb
lib/raindrops/struct.rb
lib/raindrops/watcher.rb
setup.rb
test/ipv6_enabled.rb
test/rack_unicorn.rb
test/test_aggregate_pmq.rb
test/test_inet_diag_socket.rb
test/test_last_data_recv.rb
test/test_last_data_recv_unicorn.rb
test/test_linux.rb
test/test_linux_all_tcp_listen_stats.rb
test/test_linux_all_tcp_listen_stats_leak.rb
test/test_linux_ipv6.rb
test/test_linux_middleware.rb
test/test_linux_reuseport_tcp_listen_stats.rb
test/test_middleware.rb
test/test_middleware_unicorn.rb
test/test_middleware_unicorn_ipv6.rb
test/test_raindrops.rb
test/test_raindrops_gc.rb
test/test_struct.rb
test/test_tcp_info.rb
test/test_watcher.rb