Skip to content

Commit

Permalink
Workaround for #14873 (#14890) (#14893)
Browse files Browse the repository at this point in the history
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 281ce70)

Co-authored-by: João Duarte <jsvd@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and jsvd committed Feb 12, 2023
1 parent cbd66d2 commit 4f0229a
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion rubyUtils.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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) {
Expand Down Expand Up @@ -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")
Expand All @@ -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 == "" }
Expand Down

0 comments on commit 4f0229a

Please sign in to comment.