From 33ec53c9dea7df21e112583dae1508d2975fe302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Duarte?= Date: Sat, 11 Feb 2023 12:20:58 +0000 Subject: [PATCH] Workaround for #14873 (#14890) import platform-specific ffi binaries from JRuby 9.3.9.0 to overcome jruby/jruby#7579 Since JRuby ignores the files in "lib/jni" and uses the ones inside "lib/jruby.jar" instead, we have to inject the older versions into the new JRuby's "jruby.jar" fixes #14873 (cherry picked from commit 281ce70d86c59847bd3812931bc7e72a240a2b10) --- rubyUtils.gradle | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/rubyUtils.gradle b/rubyUtils.gradle index a30087c2e92..c4680ee8461 100644 --- a/rubyUtils.gradle +++ b/rubyUtils.gradle @@ -189,6 +189,8 @@ def versionsPath = project.hasProperty("LOGSTASH_CORE_PATH") ? LOGSTASH_CORE_PAT versionMap = (Map) (new Yaml()).load(new File("${versionsPath}").text) String jRubyURL +String previousJRubyVersion = "9.3.9.0" +String previousJRubyURL = "https://repo1.maven.org/maven2/org/jruby/jruby-dist/${previousJRubyVersion}/jruby-dist-${previousJRubyVersion}-bin.tar.gz" String jRubyVersion String jRubySha1 Boolean doChecksum @@ -204,6 +206,7 @@ if (versionMap["jruby-runtime-override"]) { doChecksum = true } def jrubyTarPath = "${projectDir}/vendor/_/jruby-dist-${jRubyVersion}-bin.tar.gz" +def previousJrubyTarPath = "${projectDir}/vendor/_/jruby-dist-${previousJRubyVersion}-bin.tar.gz" def customJRubyDir = project.hasProperty("custom.jruby.path") ? project.property("custom.jruby.path") : "" def customJRubyVersion = customJRubyDir == "" ? "" : Files.readAllLines(Paths.get(customJRubyDir, "VERSION")).get(0).trim() @@ -218,6 +221,15 @@ tasks.register("downloadJRuby", Download) { dest new File("${projectDir}/vendor/_", "jruby-dist-${jRubyVersion}-bin.tar.gz") } +tasks.register("downloadPreviousJRuby", Download) { + description "Download previous JRuby artifact from this specific URL: ${previousJRubyURL}" + src previousJRubyURL + onlyIfNewer true + inputs.file(versionsPath) + outputs.file(previousJrubyTarPath) + dest new File("${projectDir}/vendor/_", "jruby-dist-${previousJRubyVersion}-bin.tar.gz") +} + downloadJRuby.onlyIf { customJRubyDir == "" } tasks.register("verifyFile", Verify) { @@ -262,9 +274,26 @@ tasks.register("installCustomJRuby", Copy) { installCustomJRuby.onlyIf { customJRubyDir != "" } +tasks.register("downloadAndInstallPreviousJRubyFFI", Copy) { + dependsOn=[downloadPreviousJRuby] + description "Install previous JRuby FFI files in the new JRuby directory" + inputs.file(previousJrubyTarPath) + outputs.dir("${projectDir}/vendor/jruby/tmp") + from tarTree(downloadPreviousJRuby.dest) + eachFile { f -> + f.path = f.path.replaceFirst("^jruby-${previousJRubyVersion}", '') + } + // Copy only the previous builds of libjffi that changed from JRuby 9.3.9.0 to 9.3.10.0 + include "**/lib/jni/**/*" + + includeEmptyDirs = false + into "${projectDir}/vendor/jruby/tmp" +} + tasks.register("downloadAndInstallJRuby", Copy) { - dependsOn=[verifyFile, installCustomJRuby] + // TODO remove downloadAndInstallPreviousJRubyFFI after https://github.com/elastic/logstash/issues/14873 is fixed + dependsOn=[verifyFile, downloadAndInstallPreviousJRubyFFI, installCustomJRuby] description "Install JRuby in the vendor directory" inputs.file(jrubyTarPath) outputs.dir("${projectDir}/vendor/jruby") @@ -274,9 +303,18 @@ tasks.register("downloadAndInstallJRuby", Copy) { } exclude "**/stdlib/rdoc/**" exclude "**/did_you_mean-*/evaluation/**" // licensing issue https://github.com/jruby/jruby/issues/6471 + exclude "**/lib/jni/**/**" includeEmptyDirs = false into "${projectDir}/vendor/jruby" + + doLast { + ant.jar(destfile: "${projectDir}/vendor/jruby/lib/jruby.jar", update: true) { + fileset(dir: "${projectDir}/vendor/jruby/tmp/lib") + } + delete files("${projectDir}/vendor/jruby/tmp") + } + } downloadAndInstallJRuby.onlyIf { customJRubyDir == "" }