Rakefile in ruby_parser-3.17.0 vs Rakefile in ruby_parser-3.18.0

- old
+ new

@@ -11,21 +11,26 @@ Hoe.add_include_dirs "lib" Hoe.add_include_dirs "../../sexp_processor/dev/lib" Hoe.add_include_dirs "../../minitest/dev/lib" Hoe.add_include_dirs "../../oedipus_lex/dev/lib" -V2 = %w[20 21 22 23 24 25 26 27 30] -V2.replace [V2.last] if ENV["FAST"] # HACK +V2 = %w[20 21 22 23 24 25 26 27] +V3 = %w[30] +VERS = V2 + V3 + +ENV["FAST"] = VERS.last if ENV["FAST"] && !VERS.include?(ENV["FAST"]) +VERS.replace [ENV["FAST"]] if ENV["FAST"] + Hoe.spec "ruby_parser" do developer "Ryan Davis", "ryand-ruby@zenspider.com" license "MIT" - dependency "sexp_processor", ["~> 4.15", ">= 4.15.1"] + dependency "sexp_processor", "~> 4.16" dependency "rake", [">= 10", "< 15"], :developer - dependency "oedipus_lex", "~> 2.5", :developer + dependency "oedipus_lex", "~> 2.6", :developer # NOTE: Ryan!!! Stop trying to fix this dependency! Isolate just # can't handle having a faux-gem half-installed! Stop! Just `gem # install racc` and move on. Revisit this ONLY once racc-compiler # gets split out. @@ -33,15 +38,15 @@ dependency "racc", "~> 1.5", :developer require_ruby_version [">= 2.1", "< 4"] if plugin? :perforce then # generated files - V2.each do |n| + VERS.each do |n| self.perforce_ignore << "lib/ruby#{n}_parser.rb" end - V2.each do |n| + VERS.each do |n| self.perforce_ignore << "lib/ruby#{n}_parser.y" end self.perforce_ignore << "lib/ruby_lexer.rex.rb" end @@ -51,29 +56,62 @@ self.racc_flags << " --superclass RubyParser::Parser" # self.racc_flags << " --runtime ruby_parser" # TODO: broken in racc end end +def maybe_add_to_top path, string + file = File.read path + + return if file.start_with? string + + warn "Altering top of #{path}" + tmp_path = "#{path}.tmp" + File.open(tmp_path, "w") do |f| + f.puts string + f.puts + + f.write file + # TODO: make this deal with encoding comments properly? + end + File.rename tmp_path, path +end + V2.each do |n| file "lib/ruby#{n}_parser.y" => "lib/ruby_parser.yy" do |t| cmd = 'unifdef -tk -DV=%s -UDEAD %s > %s || true' % [n, t.source, t.name] sh cmd end file "lib/ruby#{n}_parser.rb" => "lib/ruby#{n}_parser.y" end +V3.each do |n| + file "lib/ruby#{n}_parser.y" => "lib/ruby3_parser.yy" do |t| + cmd = 'unifdef -tk -DV=%s -UDEAD %s > %s || true' % [n, t.source, t.name] + sh cmd + end + + file "lib/ruby#{n}_parser.rb" => "lib/ruby#{n}_parser.y" +end + file "lib/ruby_lexer.rex.rb" => "lib/ruby_lexer.rex" +task :parser do |t| + t.prerequisite_tasks.grep(Rake::FileTask).select(&:already_invoked).each do |f| + maybe_add_to_top f.name, "# frozen_string_literal: true" + end +end + task :generate => [:lexer, :parser] task :clean do rm_rf(Dir["**/*~"] + Dir["diff.diff"] + # not all diffs. bit me too many times Dir["coverage.info"] + Dir["coverage"] + Dir["lib/ruby2*_parser.y"] + + Dir["lib/ruby3*_parser.y"] + Dir["lib/*.output"]) end task :sort do sh "grepsort '^ +def' lib/ruby_lexer.rb" @@ -149,11 +187,11 @@ sh "ruby tool/id2token.rb --path-separator=.:./ id.h parse.y | expand > ../#{parse_y}" else sh "expand parse.y > ../#{parse_y}" end - ruby "-pi", "-e", 'gsub(/^%define\s+api\.pure/, "%pure-parser")', "../#{parse_y}" + ruby "-pi", "-e", 'gsub(/^%pure-parser/, "%define api.pure")', "../#{parse_y}" end sh "rm -rf #{ruby_dir}" end end @@ -246,11 +284,11 @@ ruby_parse "2.6.8" ruby_parse "2.7.4" ruby_parse "3.0.2" task :debug => :isolate do - ENV["V"] ||= V2.last + ENV["V"] ||= VERS.last Rake.application[:parser].invoke # this way we can have DEBUG set Rake.application[:lexer].invoke # this way we can have DEBUG set $:.unshift "lib" require "ruby_parser" @@ -261,11 +299,11 @@ parser = klass.new time = (ENV["RP_TIMEOUT"] || 10).to_i n = ENV["BUG"] - file = (n && "bug#{n}.rb") || ENV["F"] || ENV["FILE"] || "bug.rb" + file = (n && "bug#{n}.rb") || ENV["F"] || ENV["FILE"] || "debug.rb" ruby = ENV["R"] || ENV["RUBY"] if ruby then file = "env" else @@ -284,23 +322,26 @@ abort "on #{file}:#{lines.size}" end end task :debug3 do - file = ENV["F"] || "bug.rb" - verbose = ENV["V"] ? "-v" : "" + file = ENV["F"] || "debug.rb" + version = ENV["V"] || "" + verbose = ENV["VERBOSE"] ? "-v" : "" munge = "./tools/munge.rb #{verbose}" abort "Need a file to parse, via: F=path.rb" unless file ENV.delete "V" - sh "ruby -v" - sh "ruby -y #{file} 2>&1 | #{munge} > tmp/ruby" - sh "./tools/ripper.rb -d #{file} | #{munge} > tmp/rip" + ruby = "ruby#{version}" + + sh "#{ruby} -v" + sh "#{ruby} -y #{file} 2>&1 | #{munge} > tmp/ruby" + sh "#{ruby} ./tools/ripper.rb -d #{file} | #{munge} > tmp/rip" sh "rake debug F=#{file} DEBUG=1 2>&1 | #{munge} > tmp/rp" - sh "diff -U 999 -d tmp/{rip,rp}" + sh "diff -U 999 -d tmp/{ruby,rp}" end task :cmp do sh %(emacsclient --eval '(ediff-files "tmp/ruby" "tmp/rp")') end @@ -308,18 +349,27 @@ task :cmp3 do sh %(emacsclient --eval '(ediff-files3 "tmp/ruby" "tmp/rip" "tmp/rp")') end task :extract => :isolate do - ENV["V"] ||= V2.last + ENV["V"] ||= VERS.last Rake.application[:parser].invoke # this way we can have DEBUG set - file = ENV["F"] || ENV["FILE"] + file = ENV["F"] || ENV["FILE"] || abort("Need to provide F=<path>") ruby "-Ilib", "bin/ruby_parse_extract_error", file end +task :parse => :isolate do + ENV["V"] ||= VERS.last + Rake.application[:parser].invoke # this way we can have DEBUG set + + file = ENV["F"] || ENV["FILE"] || abort("Need to provide F=<path>") + + ruby "-Ilib", "bin/ruby_parse", file +end + task :bugs do - sh "for f in bug*.rb ; do #{Gem.ruby} -S rake debug F=$f && rm $f ; done" + sh "for f in bug*.rb bad*.rb ; do #{Gem.ruby} -S rake debug F=$f && rm $f ; done" end # vim: syntax=Ruby