Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove custom bundler #15066

Merged
merged 2 commits into from
Jun 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 3 additions & 27 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -290,18 +290,8 @@ def assemblyDeps = [downloadAndInstallJRuby, assemble] + subprojects.collect {
it.tasks.findByName("assemble")
}

def bundlerVersion = "~> 2"

tasks.register("installBundler") {
dependsOn assemblyDeps
outputs.files file("${projectDir}/vendor/bundle/jruby/3.1.0/bin/bundle")
doLast {
gem(projectDir, buildDir, "bundler", bundlerVersion, "${projectDir}/vendor/bundle/jruby/3.1.0")
}
}

tasks.register("bootstrap") {
dependsOn installBundler
dependsOn assemblyDeps
doLast {
setupJruby(projectDir, buildDir)
}
@@ -417,19 +407,9 @@ tasks.register("unpackTarDistribution", Copy) {

def qaBuildPath = "${buildDir}/qa/integration"
def qaVendorPath = "${qaBuildPath}/vendor"
def qaBundledGemPath = "${qaVendorPath}/jruby/3.1.0".toString()
def qaBundleBin = "${qaBundledGemPath}/bin/bundle"

tasks.register("installIntegrationTestBundler"){
dependsOn unpackTarDistribution
outputs.files file("${qaBundleBin}")
doLast {
gem(projectDir, buildDir, "bundler", bundlerVersion, qaBundledGemPath)
}
}

tasks.register("installIntegrationTestGems") {
dependsOn installIntegrationTestBundler
dependsOn unpackTarDistribution
def gemfilePath = file("${projectDir}/qa/integration/Gemfile")
inputs.files gemfilePath
inputs.files file("${projectDir}/qa/integration/integration_tests.gemspec")
@@ -439,11 +419,7 @@ tasks.register("installIntegrationTestGems") {
outputs.files fileTree("${qaVendorPath}")
outputs.files file("${projectDir}/qa/integration/Gemfile.lock")
doLast {
bundleWithEnv(
projectDir, buildDir,
qaBuildPath, qaBundleBin, ['install', '--path', qaVendorPath, '--gemfile', gemfilePath],
[ GEM_PATH: qaBundledGemPath, GEM_HOME: qaBundledGemPath ]
)
bundleQAGems(projectDir, qaBuildPath)
}
}

2 changes: 1 addition & 1 deletion lib/bootstrap/bundler.rb
Original file line number Diff line number Diff line change
@@ -163,7 +163,7 @@ def execute_bundler_with_retry(options)
begin
execute_bundler(options)
break
rescue ::Bundler::SolveFailure => e
rescue ::Bundler::VersionConflict => e
$stderr.puts("Plugin version conflict, aborting")
raise(e)
rescue ::Bundler::GemNotFound => e
5 changes: 0 additions & 5 deletions rakelib/artifacts.rake
Original file line number Diff line number Diff line change
@@ -99,11 +99,6 @@ namespace "artifact" do
@exclude_paths << 'vendor/**/gems/**/Gemfile.lock'
@exclude_paths << 'vendor/**/gems/**/Gemfile'

# jruby's bundler artifacts
@exclude_paths << 'vendor/jruby/bin/bundle*'
@exclude_paths << 'vendor/jruby/lib/ruby/stdlib/bundler*'
@exclude_paths << 'vendor/jruby/lib/ruby/gems/shared/specifications/default/bundler-*.gemspec'
@exclude_paths << 'vendor/jruby/lib/ruby/gems/shared/gems/bundler-*'
@exclude_paths << 'vendor/jruby/lib/ruby/gems/shared/gems/rake-*'

@exclude_paths
jsvd marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 9 additions & 2 deletions rakelib/plugins_docs_dependencies.rake
Original file line number Diff line number Diff line change
@@ -126,6 +126,7 @@ class PluginVersionWorking
end

def try_plugin(plugin, successful_dependencies)
Bundler::DepProxy.__clear!
builder = Bundler::Dsl.new
gemfile = LogStash::Gemfile.new(File.new(LogStash::Environment::GEMFILE_PATH, "r+")).load
gemfile.update(plugin)
@@ -135,8 +136,6 @@ class PluginVersionWorking
definition.resolve_remotely!
from = PLUGIN_METADATA.fetch(plugin, {}).fetch("default-plugins", false) ? :default : :missing
extract_versions(definition, successful_dependencies, from)
builder.instance_eval { @sources = [] }
builder.instance_eval { @dependencies = [] }
end

def extract_versions(definition, dependencies, from)
@@ -205,6 +204,14 @@ task :generate_plugins_version do
end
end
end
DepProxy.class_eval do
yaauie marked this conversation as resolved.
Show resolved Hide resolved
# Bundler caches it's dep-proxy objects (which contain Gem::Dependency objects) from all resolutions.
# The Hash itself continues to grow between dependency resolutions and hold up a lot of memory, to avoid
# the issue we expose a way of clear-ing the cached objects before each plugin resolution.
def self.__clear!
@proxies.clear
end
end

Fetcher::CompactIndex.class_eval do
alias_method :__bundle_worker, :bundle_worker
19 changes: 18 additions & 1 deletion rubyUtils.gradle
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ import java.nio.file.Paths
ext {
bundle = this.&bundle
bundleWithEnv = this.&bundleWithEnv
bundleQAGems = this.&bundleQAGems
gem = this.&gem
buildGem = this.&buildGem
rake = this.&rake
@@ -87,6 +88,22 @@ void bundleWithEnv(File projectDir, File buildDir, String pwd, String bundleBin,
}
}

void bundleQAGems(File projectDir, String qaBuildPath) {
def jruby = new ScriptingContainer()
jruby.setLoadPaths(["${projectDir}/vendor/jruby/lib/ruby/stdlib".toString()])
try {
jruby.currentDirectory = qaBuildPath
jruby.runScriptlet("""
require "bundler"
require "bundler/cli"
Bundler::CLI.start(['install', '--path', "${qaBuildPath}/vendor", '--gemfile', "${projectDir}/qa/integration/Gemfile"])
""")
} finally {
jruby.terminate()
Ruby.clearGlobalRuntime()
}
}

/**
* Installs a Gem with the given version to the given path.
* @param projectDir Gradle projectDir
@@ -169,7 +186,7 @@ Object executeJruby(File projectDir, File buildDir, Closure<?> /* Object*/ block
def jruby = new ScriptingContainer()
def env = jruby.environment
def gemDir = "${projectDir}/vendor/bundle/jruby/3.1.0".toString()
jruby.setLoadPaths(["${projectDir}/vendor/bundle/jruby/3.1.0/gems/bundler-2.4.14/lib".toString(), "${projectDir}/vendor/jruby/lib/ruby/stdlib".toString()])
jruby.setLoadPaths(["${projectDir}/vendor/jruby/lib/ruby/stdlib".toString()])
env.put "USE_RUBY", "1"
env.put "GEM_HOME", gemDir
env.put "GEM_SPEC_CACHE", "${buildDir}/cache".toString()
4 changes: 2 additions & 2 deletions spec/unit/bootstrap/bundler_spec.rb
Original file line number Diff line number Diff line change
@@ -88,8 +88,8 @@

context 'abort with an exception' do
it 'gem conflict' do
allow(::Bundler::CLI).to receive(:start).with(bundler_args) { raise ::Bundler::SolveFailure.new('conflict') }
expect { subject }.to raise_error(::Bundler::SolveFailure)
allow(::Bundler::CLI).to receive(:start).with(bundler_args) { raise ::Bundler::VersionConflict.new('conflict') }
yaauie marked this conversation as resolved.
Show resolved Hide resolved
expect { subject }.to raise_error(::Bundler::VersionConflict)
end

it 'gem is not found' do