bootsnap 1.4.9 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +14 -1
- data/exe/bootsnap +5 -0
- data/lib/bootsnap/cli.rb +136 -0
- data/lib/bootsnap/compile_cache/iseq.rb +11 -6
- data/lib/bootsnap/version.rb +1 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2540d5dccef7466e75321e3c503b9c6d10aa6195ea905ed75336ad56f6eea2d0
|
4
|
+
data.tar.gz: 2d36002c885f981b1dd77e211cdc5583a97328995a15c14ca4a127fa74043214
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 672246870422714d082b8233c9bd51d45cf96db5ff6f37f609aafeee208e74822619059df66af56562650c61c655b73c550767b24d76ee9018c088283838bd2e
|
7
|
+
data.tar.gz: 6e6aa8e96453eda1f8c46ffa0aedf7e39a59168d31ef1dc54aaf1de1d86d8bcd67324f668406b068a6f8a42b13178d91c301a9bbe8512058a4907de9233787b7
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Bootsnap [![
|
1
|
+
# Bootsnap [![Actions Status](https://github.com/Shopify/bootsnap/workflows/ci/badge.svg)](https://github.com/Shopify/bootsnap/actions)
|
2
2
|
|
3
3
|
Bootsnap is a library that plugs into Ruby, with optional support for `ActiveSupport` and `YAML`,
|
4
4
|
to optimize and cache expensive computations. See [How Does This Work](#how-does-this-work).
|
@@ -294,6 +294,19 @@ open /c/nope.bundle -> -1
|
|
294
294
|
# (nothing!)
|
295
295
|
```
|
296
296
|
|
297
|
+
## Precompilation
|
298
|
+
|
299
|
+
In development environments the bootsnap compilation cache is generated on the fly when source files are loaded.
|
300
|
+
But in production environments, such as docker images, you might need to precompile the cache.
|
301
|
+
|
302
|
+
To do so you can use the `bootsnap precompile` command.
|
303
|
+
|
304
|
+
Example:
|
305
|
+
|
306
|
+
```bash
|
307
|
+
$ bundle exec bootsnap precompile --gemfile app/ lib/
|
308
|
+
```
|
309
|
+
|
297
310
|
## When not to use Bootsnap
|
298
311
|
|
299
312
|
*Alternative engines*: Bootsnap is pretty reliant on MRI features, and parts are disabled entirely on alternative ruby
|
data/exe/bootsnap
ADDED
data/lib/bootsnap/cli.rb
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bootsnap'
|
4
|
+
require 'optparse'
|
5
|
+
require 'fileutils'
|
6
|
+
|
7
|
+
module Bootsnap
|
8
|
+
class CLI
|
9
|
+
unless Regexp.method_defined?(:match?)
|
10
|
+
module RegexpMatchBackport
|
11
|
+
refine Regepx do
|
12
|
+
def match?(string)
|
13
|
+
!!match(string)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
using RegexpMatchBackport
|
18
|
+
end
|
19
|
+
|
20
|
+
attr_reader :cache_dir, :argv
|
21
|
+
|
22
|
+
attr_accessor :compile_gemfile, :exclude
|
23
|
+
|
24
|
+
def initialize(argv)
|
25
|
+
@argv = argv
|
26
|
+
self.cache_dir = 'tmp/cache'
|
27
|
+
self.compile_gemfile = false
|
28
|
+
self.exclude = nil
|
29
|
+
end
|
30
|
+
|
31
|
+
def precompile_command(*sources)
|
32
|
+
require 'bootsnap/compile_cache/iseq'
|
33
|
+
|
34
|
+
Bootsnap::CompileCache::ISeq.cache_dir = self.cache_dir
|
35
|
+
|
36
|
+
if compile_gemfile
|
37
|
+
sources += $LOAD_PATH
|
38
|
+
end
|
39
|
+
|
40
|
+
sources.map { |d| File.expand_path(d) }.each do |path|
|
41
|
+
if !exclude || !exclude.match?(path)
|
42
|
+
list_ruby_files(path).each do |ruby_file|
|
43
|
+
if !exclude || !exclude.match?(ruby_file)
|
44
|
+
CompileCache::ISeq.fetch(ruby_file, cache_dir: cache_dir)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
0
|
50
|
+
end
|
51
|
+
|
52
|
+
dir_sort = begin
|
53
|
+
Dir['.', sort: false]
|
54
|
+
true
|
55
|
+
rescue ArgumentError, TypeError
|
56
|
+
false
|
57
|
+
end
|
58
|
+
|
59
|
+
if dir_sort
|
60
|
+
def list_ruby_files(path)
|
61
|
+
if File.directory?(path)
|
62
|
+
Dir[File.join(path, '**/*.rb'), sort: false]
|
63
|
+
elsif File.exist?(path)
|
64
|
+
[path]
|
65
|
+
else
|
66
|
+
[]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
else
|
70
|
+
def list_ruby_files(path)
|
71
|
+
if File.directory?(path)
|
72
|
+
Dir[File.join(path, '**/*.rb')]
|
73
|
+
elsif File.exist?(path)
|
74
|
+
[path]
|
75
|
+
else
|
76
|
+
[]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def run
|
82
|
+
parser.parse!(argv)
|
83
|
+
command = argv.shift
|
84
|
+
method = "#{command}_command"
|
85
|
+
if respond_to?(method)
|
86
|
+
public_send(method, *argv)
|
87
|
+
else
|
88
|
+
invalid_usage!("Unknown command: #{command}")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def invalid_usage!(message)
|
95
|
+
STDERR.puts message
|
96
|
+
STDERR.puts
|
97
|
+
STDERR.puts parser
|
98
|
+
1
|
99
|
+
end
|
100
|
+
|
101
|
+
def cache_dir=(dir)
|
102
|
+
@cache_dir = File.expand_path(File.join(dir, 'bootsnap-compile-cache'))
|
103
|
+
end
|
104
|
+
|
105
|
+
def parser
|
106
|
+
@parser ||= OptionParser.new do |opts|
|
107
|
+
opts.banner = "Usage: bootsnap COMMAND [ARGS]"
|
108
|
+
opts.separator ""
|
109
|
+
opts.separator "GLOBAL OPTIONS"
|
110
|
+
opts.separator ""
|
111
|
+
|
112
|
+
help = <<~EOS
|
113
|
+
Path to the bootsnap cache directory. Defaults to tmp/cache
|
114
|
+
EOS
|
115
|
+
opts.on('--cache-dir DIR', help.strip) do |dir|
|
116
|
+
self.cache_dir = dir
|
117
|
+
end
|
118
|
+
|
119
|
+
opts.separator ""
|
120
|
+
opts.separator "COMMANDS"
|
121
|
+
opts.separator ""
|
122
|
+
opts.separator " precompile [DIRECTORIES...]: Precompile all .rb files in the passed directories"
|
123
|
+
|
124
|
+
help = <<~EOS
|
125
|
+
Precompile the gems in Gemfile
|
126
|
+
EOS
|
127
|
+
opts.on('--gemfile', help) { self.compile_gemfile = true }
|
128
|
+
|
129
|
+
help = <<~EOS
|
130
|
+
Path pattern to not precompile. e.g. --exclude 'aws-sdk|google-api'
|
131
|
+
EOS
|
132
|
+
opts.on('--exclude PATTERN', help) { |pattern| self.exclude = Regexp.new(pattern) }
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -26,6 +26,15 @@ module Bootsnap
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
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
|
+
|
29
38
|
def self.input_to_output(_, _)
|
30
39
|
nil # ruby handles this
|
31
40
|
end
|
@@ -35,12 +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::
|
39
|
-
Bootsnap::CompileCache::ISeq.cache_dir,
|
40
|
-
path.to_s,
|
41
|
-
Bootsnap::CompileCache::ISeq,
|
42
|
-
nil,
|
43
|
-
)
|
47
|
+
Bootsnap::CompileCache::ISeq.fetch(path.to_s)
|
44
48
|
rescue Errno::EACCES
|
45
49
|
Bootsnap::CompileCache.permission_error(path)
|
46
50
|
rescue RuntimeError => e
|
@@ -61,6 +65,7 @@ module Bootsnap
|
|
61
65
|
crc = Zlib.crc32(option.inspect)
|
62
66
|
Bootsnap::CompileCache::Native.compile_option_crc32 = crc
|
63
67
|
end
|
68
|
+
compile_option_updated
|
64
69
|
|
65
70
|
def self.install!(cache_dir)
|
66
71
|
Bootsnap::CompileCache::ISeq.cache_dir = cache_dir
|
data/lib/bootsnap/version.rb
CHANGED
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
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Burke Libbey
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,7 +97,8 @@ 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: []
|
@@ -105,11 +106,13 @@ files:
|
|
105
106
|
- CHANGELOG.md
|
106
107
|
- LICENSE.txt
|
107
108
|
- README.md
|
109
|
+
- exe/bootsnap
|
108
110
|
- ext/bootsnap/bootsnap.c
|
109
111
|
- ext/bootsnap/bootsnap.h
|
110
112
|
- ext/bootsnap/extconf.rb
|
111
113
|
- lib/bootsnap.rb
|
112
114
|
- lib/bootsnap/bundler.rb
|
115
|
+
- lib/bootsnap/cli.rb
|
113
116
|
- lib/bootsnap/compile_cache.rb
|
114
117
|
- lib/bootsnap/compile_cache/iseq.rb
|
115
118
|
- lib/bootsnap/compile_cache/yaml.rb
|