From a36cf00dee5d7657bf95b66bd4559feaab010989 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 8 Feb 2024 11:58:58 +0000 Subject: 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 '; 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 --- examples/linux-listener-stats.rb | 1 + examples/middleware.ru | 1 + examples/watcher.ru | 1 + examples/watcher_demo.ru | 1 + examples/yahns.conf.rb | 1 + examples/zbatery.conf.rb | 1 + 6 files changed, 6 insertions(+) (limited to 'examples') diff --git a/examples/linux-listener-stats.rb b/examples/linux-listener-stats.rb index 7e767da..5f67633 100755 --- a/examples/linux-listener-stats.rb +++ b/examples/linux-listener-stats.rb @@ -1,5 +1,6 @@ #!/usr/bin/ruby # -*- encoding: binary -*- +# frozen_string_literal: false $stdout.sync = $stderr.sync = true # this is used to show or watch the number of active and queued # connections on any listener socket from the command line diff --git a/examples/middleware.ru b/examples/middleware.ru index 642016b..a485592 100644 --- a/examples/middleware.ru +++ b/examples/middleware.ru @@ -1,3 +1,4 @@ +# frozen_string_literal: false # sample stand-alone rackup application for Raindrops::Middleware require 'rack/lobster' require 'raindrops' diff --git a/examples/watcher.ru b/examples/watcher.ru index a3e7fdb..e2aa97c 100644 --- a/examples/watcher.ru +++ b/examples/watcher.ru @@ -1,3 +1,4 @@ +# frozen_string_literal: false # Sample standalone Rack application, recommended use is with Zbatery # See zbatery.conf.rb require "raindrops" diff --git a/examples/watcher_demo.ru b/examples/watcher_demo.ru index 91f4cca..7a6e675 100644 --- a/examples/watcher_demo.ru +++ b/examples/watcher_demo.ru @@ -1,3 +1,4 @@ +# frozen_string_literal: false # This is a snippet of the config that powers # https://yhbt.net/raindrops-demo/ # This may be used with the packaged zbatery.conf.rb diff --git a/examples/yahns.conf.rb b/examples/yahns.conf.rb index f5b4f10..75f0bd1 100644 --- a/examples/yahns.conf.rb +++ b/examples/yahns.conf.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false # Inlined rack app using yahns server (git clone git://yhbt.net/yahns.git) # Usage: yahns -c /path/to/this/file.conf.rb # There is no separate config.ru file for this example, diff --git a/examples/zbatery.conf.rb b/examples/zbatery.conf.rb index 5f94c0e..0537466 100644 --- a/examples/zbatery.conf.rb +++ b/examples/zbatery.conf.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: false # Used for running Raindrops::Watcher, which requires a multi-threaded # Rack server capable of streaming a response. Threads must be used, # so any multi-threaded Rack server may be used. -- cgit v1.2.3-24-ge0c7