Skip to content

Commit

Permalink
Refactor: avoid loading polyglot (elastic#14175) (elastic#14227)
Browse files Browse the repository at this point in the history
* Refactor: require treetop/runtime - avoids loading polyglot
* Build: instruct Bundler not to auto-load polyglot/treetop

+ Build: these deps are properly required as needed
all of them only used in one place (outside of normal bootstrap)

(cherry picked from commit 433b341)

Co-authored-by: Karol Bucek <kares@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and kares committed Jun 8, 2022
1 parent 70eb25d commit 6036b3d
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 29 deletions.
8 changes: 5 additions & 3 deletions Gemfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ gem "logstash-core", :path => "./logstash-core"
gem "logstash-core-plugin-api", :path => "./logstash-core-plugin-api"

gem "paquet", "~> 0.2"
gem "pleaserun", "~>0.0.28"
gem "rake", "~> 12"
gem "ruby-progressbar", "~> 1"
gem "pleaserun", "~>0.0.28", require: false
gem "rake", "~> 12", require: false
gem "ruby-progressbar", "~> 1", require: false
gem "logstash-output-elasticsearch", ">= 10.4.2"
gem "polyglot", require: false
gem "treetop", require: false
gem "faraday", "~> 1", :require => false # due elasticsearch-transport (elastic-transport) depending faraday '~> 1'
gem "childprocess", "~> 4", :group => :build
gem "fpm", "~> 1", ">= 1.14.1", :group => :build # compound due to bugfix https://github.com/jordansissel/fpm/pull/1856
Expand Down
3 changes: 1 addition & 2 deletions logstash-core/lib/logstash/compiler/lscl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
# specific language governing permissions and limitations
# under the License.

require "logstash/patches/polyglot"
require "treetop"
require 'treetop/runtime'
require "logstash/compiler/treetop_monkeypatches"
require "logstash/compiler/lscl/helpers"
require "logstash/config/string_escape"
Expand Down
23 changes: 5 additions & 18 deletions logstash-core/lib/logstash/compiler/lscl/lscl_grammar.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
# Licensed to Elasticsearch B.V. under one or more contributor
# license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright
# ownership. Elasticsearch B.V. licenses this file to you under
# the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

require "treetop"
# Autogenerated from a Treetop grammar. Edits may be lost.


require "treetop/runtime"
require "logstash/compiler/lscl.rb"

module LogStashCompilerLSCLGrammar
Expand Down Expand Up @@ -3567,3 +3553,4 @@ def _nt_selector_element
class LogStashCompilerLSCLGrammarParser < Treetop::Runtime::CompiledParser
include LogStashCompilerLSCLGrammar
end

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "treetop"
require "treetop/runtime"
require "logstash/compiler/lscl.rb"

grammar LogStashCompilerLSCLGrammar
Expand Down
2 changes: 2 additions & 0 deletions logstash-core/lib/logstash/compiler/treetop_monkeypatches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# specific language governing permissions and limitations
# under the License.

require 'treetop/runtime'

class Treetop::Runtime::SyntaxNode
def get_meta(key)
@ast_metadata ||= {}
Expand Down
2 changes: 1 addition & 1 deletion logstash-core/lib/logstash/config/config_ast.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# under the License.

require "logstash/compiler/lscl/helpers"
require "treetop"
require 'treetop/runtime'

require "logstash/compiler/treetop_monkeypatches"

Expand Down
2 changes: 1 addition & 1 deletion logstash-core/lib/logstash/config/grammar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.

require "treetop"
require "treetop/runtime"
require "logstash/config/config_ast"

module LogStashConfig
Expand Down
2 changes: 1 addition & 1 deletion logstash-core/lib/logstash/config/grammar.treetop
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "treetop"
require "treetop/runtime"
require "logstash/config/config_ast"

grammar LogStashConfig
Expand Down
3 changes: 2 additions & 1 deletion logstash-core/lib/logstash/patches/polyglot.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# NOTE: this patch is meant to be used when polyglot (a tree-top dependency) is loaded.
# At runtime we avoid loading polyglot, it's only needed for the rake compile task atm.
require 'polyglot'


module Kernel
alias original_require require

Expand Down
1 change: 0 additions & 1 deletion x-pack/qa/integration/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@
require_relative "support/helpers"
require_relative "support/shared_examples"
require_relative "support/elasticsearch/api/actions/update_password"
require "logstash/patches/polyglot"
require "json"
require "json-schema"

0 comments on commit 6036b3d

Please sign in to comment.