about summary refs log tree commit homepage
path: root/setup.rb
diff options
context:
space:
mode:
authorEric Wong <bofh@yhbt.net>2024-02-08 11:58:58 +0000
committerEric Wong <bofh@yhbt.net>2024-03-23 17:30:48 +0000
commita36cf00dee5d7657bf95b66bd4559feaab010989 (patch)
tree7e17cce1d259715baec9846846c21bb876707a69 /setup.rb
parent0a20ff1ffabf99de80182be438f43f2c5e03e25b (diff)
downloadraindrops-a36cf00dee5d7657bf95b66bd4559feaab010989.tar.gz
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
Diffstat (limited to 'setup.rb')
-rw-r--r--setup.rb1
1 files changed, 1 insertions, 0 deletions
diff --git a/setup.rb b/setup.rb
index 5eb5006..b382468 100644
--- a/setup.rb
+++ b/setup.rb
@@ -1,4 +1,5 @@
 # -*- encoding: binary -*-
+# frozen_string_literal: false
 #
 # setup.rb
 #