diff --git a/Rakefile b/Rakefile index 797929ad..d4416d95 100644 --- a/Rakefile +++ b/Rakefile @@ -16,18 +16,6 @@ RDoc::Task.new(:docs) do |rd| rd.options << "-t #{title}" end -require 'rake/testtask' - -Rake::TestTask.new(:test) do |t| - t.libs << "test/lib" - t.ruby_opts << "-rhelper" - t.test_files = FileList["test/**/test_*.rb"] - if RUBY_VERSION >= "2.6" - t.ruby_opts << "--enable-frozen-string-literal" - t.ruby_opts << "--debug=frozen-string-literal" if RUBY_ENGINE != "truffleruby" - end -end - def java? /java/ === RUBY_PLATFORM end @@ -39,12 +27,16 @@ file 'lib/racc/parser-text.rb' => ['lib/racc/parser.rb', __FILE__] do |t| source = 'lib/racc/parser.rb' text = File.read(source) + text.sub!(/\A# *frozen[-_]string[-_]literal:.*\n/, '') text.gsub!(/^require '(.*)'$/) do - %[unless $".find {|p| p.end_with?('/#$1.rb')}\n$".push "\#{__dir__}/#$1.rb"\n#{File.read("lib/#{$1}.rb")}\nend\n] + lib = $1 + code = File.read("lib/#{lib}.rb") + code.sub!(/\A(?:#.*\n)+/, '') + %[unless $".find {|p| p.end_with?('/#{lib}.rb')}\n$".push "\#{__dir__}/#{lib}.rb"\n#{code}\nend\n] rescue $& end - open(t.name, 'wb') { |io| + File.open(t.name, 'wb') { |io| io.write(<<-eorb) module Racc PARSER_TEXT = <<'__end_of_file__' @@ -58,10 +50,10 @@ end if jruby? # JRUBY require "rake/javaextensiontask" - Rake::JavaExtensionTask.new("cparse") do |ext| + extask = Rake::JavaExtensionTask.new("cparse") do |ext| jruby_home = RbConfig::CONFIG['prefix'] - ext.lib_dir = File.join 'lib', 'racc' - ext.ext_dir = File.join 'ext', 'racc' + ext.lib_dir = 'lib/java/racc' + ext.ext_dir = 'ext/racc' # source/target jvm ext.source_version = '1.8' ext.target_version = '1.8' @@ -69,19 +61,31 @@ if jruby? ext.classpath = jars.map { |x| File.expand_path x }.join( ':' ) ext.name = 'cparse-jruby' end - - task :compile => ['lib/racc/parser-text.rb'] else # MRI require "rake/extensiontask" - Rake::ExtensionTask.new "cparse" do |ext| - ext.lib_dir = File.join 'lib', 'racc' - ext.ext_dir = File.join 'ext', 'racc', 'cparse' + extask = Rake::ExtensionTask.new "cparse" do |ext| + ext.lib_dir << "/#{RUBY_VERSION}/#{ext.platform}/racc" + ext.ext_dir = 'ext/racc/cparse' end - - task :compile => 'lib/racc/parser-text.rb' end +task :compile => ['lib/racc/parser-text.rb'] + task :build => "lib/racc/parser-text.rb" task :test => :compile + +require 'rake/testtask' + +Rake::TestTask.new(:test) do |t| + ENV["RUBYOPT"] = "-I" + [extask.lib_dir, "test/lib"].join(File::PATH_SEPARATOR) + t.libs << extask.lib_dir + t.libs << "test/lib" + t.ruby_opts << "-rhelper" + t.test_files = FileList["test/**/test_*.rb"] + if RUBY_VERSION >= "2.6" + t.ruby_opts << "--enable-frozen-string-literal" + t.ruby_opts << "--debug=frozen-string-literal" if RUBY_ENGINE != "truffleruby" + end +end diff --git a/lib/racc/info.rb b/lib/racc/info.rb index b0fc9055..a6bd249c 100644 --- a/lib/racc/info.rb +++ b/lib/racc/info.rb @@ -1,3 +1,4 @@ +# frozen_string_literal: true #-- # # diff --git a/lib/racc/parser.rb b/lib/racc/parser.rb index ab1e5bcc..c4c74fae 100644 --- a/lib/racc/parser.rb +++ b/lib/racc/parser.rb @@ -1,4 +1,4 @@ -# frozen_string_literal: false +# frozen_string_literal: true #-- # Copyright (c) 1999-2006 Minero Aoki #