From 00202d5a82e10c9cbea00c8dfb7597a890469d2f Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Tue, 25 Jul 2023 16:00:26 -0400 Subject: [PATCH] Allow JRuby to run Rake This PR allows: 1. JRuby to run rake tasks 2. Allow Java to compile any generated template code For near term use this means for development work in YARP I can change a template and know with a rake run that I generated something which is at least valid Java. Note: The yarp.jar created is just put into tmp since there is no immediate plan for JRuby to consume this code as a jar (it will be imported into JRuby repo). Longer term (when fiddle impl of the gem side of YARP has landed) it will allow JRuby to test like MRI does. --- Rakefile | 31 ++++++++++++++++++++++++------- tasks/test.rake | 24 +++++++++++++----------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/Rakefile b/Rakefile index 30c4e7f564d..91de08f743c 100644 --- a/Rakefile +++ b/Rakefile @@ -5,11 +5,13 @@ require "rake/extensiontask" require "rake/testtask" require "rake/clean" require "rdoc/task" -require "ruby_memcheck" Rake.add_rakelib("tasks") -RubyMemcheck.config(binary_name: "yarp") +if RUBY_ENGINE != "jruby" + require "ruby_memcheck" + RubyMemcheck.config(binary_name: "yarp") +end task compile: :make task compile_no_debug: :make_no_debug @@ -61,11 +63,26 @@ task build: [:templates, :check_manifest] # the C extension task "compile:yarp" => ["configure", "templates"] # must be before the ExtensionTask is created -Rake::ExtensionTask.new(:compile) do |ext| - ext.name = "yarp" - ext.ext_dir = "ext/yarp" - ext.lib_dir = "lib" - ext.gem_spec = Gem::Specification.load("yarp.gemspec") + +if RUBY_ENGINE == 'jruby' + require 'rake/javaextensiontask' + + # This compiles java to make sure any templating changes produces valid code. + Rake::JavaExtensionTask.new(:compile) do |ext| + ext.name = "yarp" + ext.ext_dir = "java" + ext.lib_dir = "tmp" + ext.source_version = "1.8" + ext.target_version = "1.8" + ext.gem_spec = Gem::Specification.load("yarp.gemspec") + end +else + Rake::ExtensionTask.new(:compile) do |ext| + ext.name = "yarp" + ext.ext_dir = "ext/yarp" + ext.lib_dir = "lib" + ext.gem_spec = Gem::Specification.load("yarp.gemspec") + end end # So `rake clobber` will delete generated files diff --git a/tasks/test.rake b/tasks/test.rake index 76403a1b3ac..fcabaed581a 100644 --- a/tasks/test.rake +++ b/tasks/test.rake @@ -21,17 +21,19 @@ class LldbTestTask < Rake::TestTask end namespace :test do - RubyMemcheck::TestTask.new(valgrind_internal: :compile, &test_config) - Rake::Task['test:valgrind_internal'].clear_comments # Hide test:valgrind_internal from rake -T + if RUBY_ENGINE != "jruby" + RubyMemcheck::TestTask.new(valgrind_internal: :compile, &test_config) + Rake::Task['test:valgrind_internal'].clear_comments # Hide test:valgrind_internal from rake -T + + desc "Run tests under valgrind" + task :valgrind do + # Recompile with YARP_DEBUG_MODE_BUILD=1 + ENV['YARP_DEBUG_MODE_BUILD'] = '1' + Rake::Task['clobber'].invoke + Rake::Task['test:valgrind_internal'].invoke + end - desc "Run tests under valgrind" - task :valgrind do - # Recompile with YARP_DEBUG_MODE_BUILD=1 - ENV['YARP_DEBUG_MODE_BUILD'] = '1' - Rake::Task['clobber'].invoke - Rake::Task['test:valgrind_internal'].invoke + GdbTestTask.new(gdb: :compile, &test_config) + LldbTestTask.new(lldb: :compile, &test_config) end - - GdbTestTask.new(gdb: :compile, &test_config) - LldbTestTask.new(lldb: :compile, &test_config) end