Skip to content

Commit

Permalink
Require ruby 2.6+
Browse files Browse the repository at this point in the history
  • Loading branch information
byroot committed Nov 9, 2022
1 parent bbd7bad commit b6f0b3f
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: '2.5'
ruby-version: '2.6'
bundler-cache: true
- run: bundle exec rubocop

Expand All @@ -43,7 +43,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu]
ruby: ['2.5', '2.6', '2.7', '3.0', '3.1', 'ruby-head', 'debug']
ruby: ['2.6', '2.7', '3.0', '3.1', 'ruby-head', 'debug']
runs-on: ${{ matrix.os }}-latest
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AllCops:
Exclude:
- 'vendor/**/*'
- 'tmp/**/*'
TargetRubyVersion: 2.5
TargetRubyVersion: 2.6
NewCops: enable
SuggestExtensions: false

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

* Require Ruby 2.6.
* Add a way to skip direcftories during load path scanning.
If you have large non-ruby directories in the middle of your load path, it can severly slow down scanning.
Typically this is a problem with `node_modules`. See #277.
Expand Down
2 changes: 1 addition & 1 deletion bootsnap.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
spec.bindir = "exe"
spec.executables = %w(bootsnap)

spec.required_ruby_version = ">= 2.5.0"
spec.required_ruby_version = ">= 2.6.0"

if RUBY_PLATFORM =~ /java/
spec.platform = "java"
Expand Down
14 changes: 1 addition & 13 deletions lib/bootsnap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@ def setup(
compile_cache_yaml: true,
compile_cache_json: true
)
if compile_cache_iseq && !iseq_cache_supported?
warn "Ruby 2.5 has a bug that break code tracing when code is loaded from cache. It is recommened " \
"to turn `compile_cache_iseq` off on Ruby 2.5"
end

if load_path_cache
Bootsnap::LoadPathCache.setup(
cache_path: "#{cache_dir}/bootsnap/load-path-cache",
Expand All @@ -69,13 +64,6 @@ def unload_cache!
LoadPathCache.unload!
end

def iseq_cache_supported?
return @iseq_cache_supported if defined? @iseq_cache_supported

ruby_version = Gem::Version.new(RUBY_VERSION)
@iseq_cache_supported = ruby_version < Gem::Version.new("2.5.0") || ruby_version >= Gem::Version.new("2.6.0")
end

def default_setup
env = ENV["RAILS_ENV"] || ENV["RACK_ENV"] || ENV["ENV"]
development_mode = ["", nil, "development"].include?(env)
Expand Down Expand Up @@ -110,7 +98,7 @@ def default_setup
cache_dir: cache_dir,
development_mode: development_mode,
load_path_cache: !ENV["DISABLE_BOOTSNAP_LOAD_PATH_CACHE"],
compile_cache_iseq: !ENV["DISABLE_BOOTSNAP_COMPILE_CACHE"] && iseq_cache_supported?,
compile_cache_iseq: !ENV["DISABLE_BOOTSNAP_COMPILE_CACHE"],
compile_cache_yaml: !ENV["DISABLE_BOOTSNAP_COMPILE_CACHE"],
compile_cache_json: !ENV["DISABLE_BOOTSNAP_COMPILE_CACHE"],
ignore_directories: ignore_directories,
Expand Down
4 changes: 2 additions & 2 deletions lib/bootsnap/load_path_cache/loaded_features_index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def initialize

# /a/b/lib/my/foo.rb
# ^^^^^^^^^
short = feat[(lpe.length + 1)..-1]
short = feat[(lpe.length + 1)..]
stripped = strip_extension_if_elidable(short)
@lfi[short] = hash
@lfi[stripped] = hash
Expand Down Expand Up @@ -76,7 +76,7 @@ def cursor(short)
end

def identify(short, cursor)
$LOADED_FEATURES[cursor..-1].detect do |feat|
$LOADED_FEATURES[cursor..].detect do |feat|
offset = 0
while (offset = feat.index(short, offset))
if feat.index(".", offset + 1) && !feat.index("/", offset + 2)
Expand Down
2 changes: 1 addition & 1 deletion test/compile_cache_key_format_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_fetch
assert_equal("NEATO #{target.upcase}", actual)

data = File.read(expected_file)
assert_equal("neato #{target}", data.force_encoding(Encoding::BINARY)[64..-1])
assert_equal("neato #{target}", data.force_encoding(Encoding::BINARY)[64..])

actual = Bootsnap::CompileCache::Native.fetch(@tmp_dir, target, TestHandler, nil)
assert_equal("NEATO #{target.upcase}", actual)
Expand Down
2 changes: 1 addition & 1 deletion test/load_path_cache/cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_path_obj_equal?
assert_equal("#{@dir1}/a.rb", cache.find("a"))
end

if RUBY_VERSION >= "2.5" && RbConfig::CONFIG["host_os"] !~ /mswin|mingw|cygwin/
if RbConfig::CONFIG["host_os"] !~ /mswin|mingw|cygwin/
# https://github.com/ruby/ruby/pull/4061
# https://bugs.ruby-lang.org/issues/17517
OS_ASCII_PATH_ENCODING = RUBY_VERSION >= "3.1" ? Encoding::UTF_8 : Encoding::US_ASCII
Expand Down
10 changes: 5 additions & 5 deletions test/setup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_default_setup
cache_dir: @tmp_dir,
development_mode: true,
load_path_cache: true,
compile_cache_iseq: Bootsnap.iseq_cache_supported?,
compile_cache_iseq: true,
compile_cache_yaml: true,
compile_cache_json: true,
ignore_directories: nil,
Expand All @@ -35,7 +35,7 @@ def test_default_setup_with_ENV_not_dev
cache_dir: @tmp_dir,
development_mode: false,
load_path_cache: true,
compile_cache_iseq: Bootsnap.iseq_cache_supported?,
compile_cache_iseq: true,
compile_cache_yaml: true,
compile_cache_json: true,
ignore_directories: nil,
Expand All @@ -51,7 +51,7 @@ def test_default_setup_with_DISABLE_BOOTSNAP_LOAD_PATH_CACHE
cache_dir: @tmp_dir,
development_mode: true,
load_path_cache: false,
compile_cache_iseq: Bootsnap.iseq_cache_supported?,
compile_cache_iseq: true,
compile_cache_yaml: true,
compile_cache_json: true,
ignore_directories: nil,
Expand Down Expand Up @@ -90,7 +90,7 @@ def test_default_setup_with_BOOTSNAP_LOG
cache_dir: @tmp_dir,
development_mode: true,
load_path_cache: true,
compile_cache_iseq: Bootsnap.iseq_cache_supported?,
compile_cache_iseq: true,
compile_cache_yaml: true,
compile_cache_json: true,
ignore_directories: nil,
Expand All @@ -107,7 +107,7 @@ def test_default_setup_with_BOOTSNAP_IGNORE_DIRECTORIES
cache_dir: @tmp_dir,
development_mode: true,
load_path_cache: true,
compile_cache_iseq: Bootsnap.iseq_cache_supported?,
compile_cache_iseq: true,
compile_cache_yaml: true,
compile_cache_json: true,
ignore_directories: %w[foo bar],
Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def cache_path(dir, file, args_key = nil)
end

hex = hash.to_s(16).rjust(16, "0")
"#{dir}/#{hex[0..1]}/#{hex[2..-1]}"
"#{dir}/#{hex[0..1]}/#{hex[2..]}"
end

def fnv1a_64(data)
Expand Down

0 comments on commit b6f0b3f

Please sign in to comment.