bootsnap 1.4.7 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -34,9 +34,9 @@ module Bootsnap
34
34
  end
35
35
 
36
36
  def self.supported?
37
- # only enable on 'ruby' (MRI), POSIX (darwin, linux, *bsd), and >= 2.3.0
37
+ # only enable on 'ruby' (MRI), POSIX (darwin, linux, *bsd), Windows (RubyInstaller2) and >= 2.3.0
38
38
  RUBY_ENGINE == 'ruby' &&
39
- RUBY_PLATFORM =~ /darwin|linux|bsd/ &&
39
+ RUBY_PLATFORM =~ /darwin|linux|bsd|mswin|mingw|cygwin/ &&
40
40
  Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.3.0")
41
41
  end
42
42
  end
@@ -9,13 +9,13 @@ module Bootsnap
9
9
  attr_accessor(:cache_dir)
10
10
  end
11
11
 
12
- def self.input_to_storage(_, path)
12
+ def self.input_to_storage(_, path, _args)
13
13
  RubyVM::InstructionSequence.compile_file(path).to_binary
14
14
  rescue SyntaxError
15
15
  raise(Uncompilable, 'syntax error')
16
16
  end
17
17
 
18
- def self.storage_to_output(binary)
18
+ def self.storage_to_output(binary, _args)
19
19
  RubyVM::InstructionSequence.load_from_binary(binary)
20
20
  rescue RuntimeError => e
21
21
  if e.message == 'broken binary format'
@@ -26,7 +26,16 @@ module Bootsnap
26
26
  end
27
27
  end
28
28
 
29
- def self.input_to_output(_)
29
+ def self.fetch(path, cache_dir: ISeq.cache_dir)
30
+ Bootsnap::CompileCache::Native.fetch(
31
+ cache_dir,
32
+ path.to_s,
33
+ Bootsnap::CompileCache::ISeq,
34
+ nil,
35
+ )
36
+ end
37
+
38
+ def self.input_to_output(_data, _kwargs)
30
39
  nil # ruby handles this
31
40
  end
32
41
 
@@ -35,11 +44,7 @@ module Bootsnap
35
44
  # Having coverage enabled prevents iseq dumping/loading.
36
45
  return nil if defined?(Coverage) && Bootsnap::CompileCache::Native.coverage_running?
37
46
 
38
- Bootsnap::CompileCache::Native.fetch(
39
- Bootsnap::CompileCache::ISeq.cache_dir,
40
- path.to_s,
41
- Bootsnap::CompileCache::ISeq
42
- )
47
+ Bootsnap::CompileCache::ISeq.fetch(path.to_s)
43
48
  rescue Errno::EACCES
44
49
  Bootsnap::CompileCache.permission_error(path)
45
50
  rescue RuntimeError => e
@@ -60,6 +65,7 @@ module Bootsnap
60
65
  crc = Zlib.crc32(option.inspect)
61
66
  Bootsnap::CompileCache::Native.compile_option_crc32 = crc
62
67
  end
68
+ compile_option_updated
63
69
 
64
70
  def self.install!(cache_dir)
65
71
  Bootsnap::CompileCache::ISeq.cache_dir = cache_dir
@@ -5,56 +5,84 @@ module Bootsnap
5
5
  module CompileCache
6
6
  module YAML
7
7
  class << self
8
- attr_accessor(:msgpack_factory)
9
- end
8
+ attr_accessor(:msgpack_factory, :cache_dir, :supported_options)
10
9
 
11
- def self.input_to_storage(contents, _)
12
- raise(Uncompilable) if contents.index("!ruby/object")
13
- obj = ::YAML.load(contents)
14
- msgpack_factory.packer.write(obj).to_s
15
- rescue NoMethodError, RangeError
16
- # if the object included things that we can't serialize, fall back to
17
- # Marshal. It's a bit slower, but can encode anything yaml can.
18
- # NoMethodError is unexpected types; RangeError is Bignums
19
- Marshal.dump(obj)
20
- end
10
+ def input_to_storage(contents, _, kwargs)
11
+ raise(Uncompilable) if contents.index("!ruby/object")
12
+ obj = ::YAML.load(contents, **(kwargs || {}))
13
+ msgpack_factory.dump(obj)
14
+ rescue NoMethodError, RangeError
15
+ # if the object included things that we can't serialize, fall back to
16
+ # Marshal. It's a bit slower, but can encode anything yaml can.
17
+ # NoMethodError is unexpected types; RangeError is Bignums
18
+ Marshal.dump(obj)
19
+ end
20
+
21
+ def storage_to_output(data, kwargs)
22
+ # This could have a meaning in messagepack, and we're being a little lazy
23
+ # about it. -- but a leading 0x04 would indicate the contents of the YAML
24
+ # is a positive integer, which is rare, to say the least.
25
+ if data[0] == 0x04.chr && data[1] == 0x08.chr
26
+ Marshal.load(data)
27
+ else
28
+ msgpack_factory.load(data, **(kwargs || {}))
29
+ end
30
+ end
21
31
 
22
- def self.storage_to_output(data)
23
- # This could have a meaning in messagepack, and we're being a little lazy
24
- # about it. -- but a leading 0x04 would indicate the contents of the YAML
25
- # is a positive integer, which is rare, to say the least.
26
- if data[0] == 0x04.chr && data[1] == 0x08.chr
27
- Marshal.load(data)
28
- else
29
- msgpack_factory.unpacker.feed(data).read
32
+ def input_to_output(data, kwargs)
33
+ ::YAML.load(data, **(kwargs || {}))
30
34
  end
31
- end
32
35
 
33
- def self.input_to_output(data)
34
- ::YAML.load(data)
36
+ def install!(cache_dir)
37
+ self.cache_dir = cache_dir
38
+ init!
39
+ ::YAML.singleton_class.prepend(Patch)
40
+ end
41
+
42
+ def init!
43
+ require('yaml')
44
+ require('msgpack')
45
+
46
+ # MessagePack serializes symbols as strings by default.
47
+ # We want them to roundtrip cleanly, so we use a custom factory.
48
+ # see: https://github.com/msgpack/msgpack-ruby/pull/122
49
+ factory = MessagePack::Factory.new
50
+ factory.register_type(0x00, Symbol)
51
+ self.msgpack_factory = factory
52
+
53
+ self.supported_options = []
54
+ params = ::YAML.method(:load).parameters
55
+ if params.include?([:key, :symbolize_names])
56
+ self.supported_options << :symbolize_names
57
+ end
58
+ if params.include?([:key, :freeze])
59
+ if factory.load(factory.dump('yaml'), freeze: true).frozen?
60
+ self.supported_options << :freeze
61
+ end
62
+ end
63
+ self.supported_options.freeze
64
+ end
35
65
  end
36
66
 
37
- def self.install!(cache_dir)
38
- require('yaml')
39
- require('msgpack')
67
+ module Patch
68
+ extend self
40
69
 
41
- # MessagePack serializes symbols as strings by default.
42
- # We want them to roundtrip cleanly, so we use a custom factory.
43
- # see: https://github.com/msgpack/msgpack-ruby/pull/122
44
- factory = MessagePack::Factory.new
45
- factory.register_type(0x00, Symbol)
46
- Bootsnap::CompileCache::YAML.msgpack_factory = factory
70
+ def load_file(path, *args)
71
+ return super if args.size > 1
72
+ if kwargs = args.first
73
+ return super unless kwargs.is_a?(Hash)
74
+ return super unless (kwargs.keys - ::Bootsnap::CompileCache::YAML.supported_options).empty?
75
+ end
47
76
 
48
- klass = class << ::YAML; self; end
49
- klass.send(:define_method, :load_file) do |path|
50
77
  begin
51
- Bootsnap::CompileCache::Native.fetch(
52
- cache_dir,
78
+ ::Bootsnap::CompileCache::Native.fetch(
79
+ Bootsnap::CompileCache::YAML.cache_dir,
53
80
  path,
54
- Bootsnap::CompileCache::YAML
81
+ ::Bootsnap::CompileCache::YAML,
82
+ kwargs,
55
83
  )
56
84
  rescue Errno::EACCES
57
- Bootsnap::CompileCache.permission_error(path)
85
+ ::Bootsnap::CompileCache.permission_error(path)
58
86
  end
59
87
  end
60
88
  end
@@ -61,7 +61,7 @@ module Bootsnap
61
61
 
62
62
  def supported?
63
63
  RUBY_ENGINE == 'ruby' &&
64
- RUBY_PLATFORM =~ /darwin|linux|bsd/
64
+ RUBY_PLATFORM =~ /darwin|linux|bsd|mswin|mingw|cygwin/
65
65
  end
66
66
  end
67
67
  end
@@ -38,7 +38,11 @@ module Kernel
38
38
  rescue Bootsnap::LoadPathCache::ReturnFalse
39
39
  false
40
40
  rescue Bootsnap::LoadPathCache::FallbackScan
41
- require_with_bootsnap_lfi(path)
41
+ fallback = true
42
+ ensure
43
+ if fallback
44
+ require_with_bootsnap_lfi(path)
45
+ end
42
46
  end
43
47
 
44
48
  alias_method(:require_relative_without_bootsnap, :require_relative)
@@ -67,7 +71,11 @@ module Kernel
67
71
  rescue Bootsnap::LoadPathCache::ReturnFalse
68
72
  false
69
73
  rescue Bootsnap::LoadPathCache::FallbackScan
70
- load_without_bootsnap(path, wrap)
74
+ fallback = true
75
+ ensure
76
+ if fallback
77
+ load_without_bootsnap(path, wrap)
78
+ end
71
79
  end
72
80
  end
73
81
 
@@ -88,6 +96,10 @@ class Module
88
96
  rescue Bootsnap::LoadPathCache::ReturnFalse
89
97
  false
90
98
  rescue Bootsnap::LoadPathCache::FallbackScan
91
- autoload_without_bootsnap(const, path)
99
+ fallback = true
100
+ ensure
101
+ if fallback
102
+ autoload_without_bootsnap(const, path)
103
+ end
92
104
  end
93
105
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Bootsnap
3
- VERSION = "1.4.7"
3
+ VERSION = "1.5.1"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootsnap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.7
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Burke Libbey
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-22 00:00:00.000000000 Z
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,36 +97,22 @@ dependencies:
97
97
  description: Boot large ruby/rails apps faster
98
98
  email:
99
99
  - burke.libbey@shopify.com
100
- executables: []
100
+ executables:
101
+ - bootsnap
101
102
  extensions:
102
103
  - ext/bootsnap/extconf.rb
103
104
  extra_rdoc_files: []
104
105
  files:
105
- - ".github/CODEOWNERS"
106
- - ".github/probots.yml"
107
- - ".gitignore"
108
- - ".rubocop.yml"
109
- - ".travis.yml"
110
106
  - CHANGELOG.md
111
- - CODE_OF_CONDUCT.md
112
- - CONTRIBUTING.md
113
- - Gemfile
114
107
  - LICENSE.txt
115
- - README.jp.md
116
108
  - README.md
117
- - Rakefile
118
- - bin/ci
119
- - bin/console
120
- - bin/setup
121
- - bin/test-minimal-support
122
- - bin/testunit
123
- - bootsnap.gemspec
124
- - dev.yml
109
+ - exe/bootsnap
125
110
  - ext/bootsnap/bootsnap.c
126
111
  - ext/bootsnap/bootsnap.h
127
112
  - ext/bootsnap/extconf.rb
128
113
  - lib/bootsnap.rb
129
114
  - lib/bootsnap/bundler.rb
115
+ - lib/bootsnap/cli.rb
130
116
  - lib/bootsnap/compile_cache.rb
131
117
  - lib/bootsnap/compile_cache/iseq.rb
132
118
  - lib/bootsnap/compile_cache/yaml.rb
@@ -144,7 +130,6 @@ files:
144
130
  - lib/bootsnap/load_path_cache/store.rb
145
131
  - lib/bootsnap/setup.rb
146
132
  - lib/bootsnap/version.rb
147
- - shipit.rubygems.yml
148
133
  homepage: https://github.com/Shopify/bootsnap
149
134
  licenses:
150
135
  - MIT
@@ -152,6 +137,7 @@ metadata:
152
137
  bug_tracker_uri: https://github.com/Shopify/bootsnap/issues
153
138
  changelog_uri: https://github.com/Shopify/bootsnap/blob/master/CHANGELOG.md
154
139
  source_code_uri: https://github.com/Shopify/bootsnap
140
+ allowed_push_host: https://rubygems.org
155
141
  post_install_message:
156
142
  rdoc_options: []
157
143
  require_paths:
@@ -167,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
153
  - !ruby/object:Gem::Version
168
154
  version: '0'
169
155
  requirements: []
170
- rubygems_version: 3.0.2
156
+ rubygems_version: 3.0.3
171
157
  signing_key:
172
158
  specification_version: 4
173
159
  summary: Boot large ruby/rails apps faster
@@ -1,2 +0,0 @@
1
- # mvm:maintainer
2
- * @burke
@@ -1,2 +0,0 @@
1
- enabled:
2
- - cla
data/.gitignore DELETED
@@ -1,17 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- *.gem
15
- *.db
16
- mkmf.log
17
- .rubocop-*
@@ -1,20 +0,0 @@
1
- inherit_from:
2
- - http://shopify.github.io/ruby-style-guide/rubocop.yml
3
-
4
- AllCops:
5
- Exclude:
6
- - 'vendor/**/*'
7
- - 'tmp/**/*'
8
- TargetRubyVersion: '2.3'
9
-
10
- # This doesn't take into account retrying from an exception
11
- Lint/SuppressedException:
12
- Enabled: false
13
-
14
- # allow String.new to create mutable strings
15
- Style/EmptyLiteral:
16
- Enabled: false
17
-
18
- # allow the use of globals which makes sense in a CLI app like this
19
- Style/GlobalVars:
20
- Enabled: false
@@ -1,25 +0,0 @@
1
- language: ruby
2
- sudo: false
3
-
4
- os:
5
- - linux
6
- - osx
7
-
8
- rvm:
9
- - '2.4'
10
- - '2.5'
11
- - '2.6'
12
- - '2.7'
13
- - ruby-head
14
-
15
- matrix:
16
- allow_failures:
17
- - rvm: ruby-head
18
- include:
19
- - rvm: jruby
20
- os: linux
21
- env: MINIMAL_SUPPORT=1
22
- - rvm: truffleruby
23
- os: linux
24
- env: MINIMAL_SUPPORT=1
25
- script: bin/ci
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at burke@libbey.me. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/