bootsnap-pr-184 1.3.1.pr.pre.184.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bootsnap
4
+ module LoadPathCache
5
+ class RealpathCache
6
+ def initialize
7
+ @cache = Hash.new { |h, k| h[k] = realpath(*k) }
8
+ end
9
+
10
+ def call(*key)
11
+ @cache[key]
12
+ end
13
+
14
+ private
15
+
16
+ def realpath(caller_location, path)
17
+ base = File.dirname(caller_location)
18
+ file = find_file(File.expand_path(path, base))
19
+ dir = File.dirname(file)
20
+ File.join(dir, File.basename(file))
21
+ end
22
+
23
+ def find_file(name)
24
+ ['', *CACHED_EXTENSIONS].each do |ext|
25
+ filename = "#{name}#{ext}"
26
+ return File.realpath(filename) if File.exist?(filename)
27
+ end
28
+ name
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,84 @@
1
+ require_relative '../explicit_require'
2
+
3
+ Bootsnap::ExplicitRequire.with_gems('msgpack') { require 'msgpack' }
4
+ Bootsnap::ExplicitRequire.from_rubylibdir('fileutils')
5
+
6
+ module Bootsnap
7
+ module LoadPathCache
8
+ class Store
9
+ NestedTransactionError = Class.new(StandardError)
10
+ SetOutsideTransactionNotAllowed = Class.new(StandardError)
11
+
12
+ def initialize(store_path)
13
+ @store_path = store_path
14
+ @in_txn = false
15
+ @dirty = false
16
+ load_data
17
+ end
18
+
19
+ def get(key)
20
+ @data[key]
21
+ end
22
+
23
+ def fetch(key)
24
+ raise SetOutsideTransactionNotAllowed unless @in_txn
25
+ v = get(key)
26
+ unless v
27
+ @dirty = true
28
+ v = yield
29
+ @data[key] = v
30
+ end
31
+ v
32
+ end
33
+
34
+ def set(key, value)
35
+ raise SetOutsideTransactionNotAllowed unless @in_txn
36
+ if value != @data[key]
37
+ @dirty = true
38
+ @data[key] = value
39
+ end
40
+ end
41
+
42
+ def transaction
43
+ raise NestedTransactionError if @in_txn
44
+ @in_txn = true
45
+ yield
46
+ ensure
47
+ commit_transaction
48
+ @in_txn = false
49
+ end
50
+
51
+ private
52
+
53
+ def commit_transaction
54
+ if @dirty
55
+ dump_data
56
+ @dirty = false
57
+ end
58
+ end
59
+
60
+ def load_data
61
+ @data = begin
62
+ MessagePack.load(File.binread(@store_path))
63
+ # handle malformed data due to upgrade incompatability
64
+ rescue Errno::ENOENT, MessagePack::MalformedFormatError, MessagePack::UnknownExtTypeError, EOFError
65
+ {}
66
+ end
67
+ end
68
+
69
+ def dump_data
70
+ # Change contents atomically so other processes can't get invalid
71
+ # caches if they read at an inopportune time.
72
+ tmp = "#{@store_path}.#{Process.pid}.#{(rand * 100000).to_i}.tmp"
73
+ FileUtils.mkpath(File.dirname(tmp))
74
+ exclusive_write = File::Constants::CREAT | File::Constants::EXCL | File::Constants::WRONLY
75
+ # `encoding:` looks redundant wrt `binwrite`, but necessary on windows
76
+ # because binary is part of mode.
77
+ File.binwrite(tmp, MessagePack.dump(@data), mode: exclusive_write, encoding: Encoding::BINARY)
78
+ FileUtils.mv(tmp, @store_path)
79
+ rescue Errno::EEXIST
80
+ retry
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,41 @@
1
+ require_relative '../bootsnap'
2
+
3
+ env = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || ENV['ENV']
4
+ development_mode = ['', nil, 'development'].include?(env)
5
+
6
+ # only enable on 'ruby' (MRI), POSIX (darwin, linux, *bsd), and >= 2.3.0
7
+ enable_cc =
8
+ RUBY_ENGINE == 'ruby' &&
9
+ RUBY_PLATFORM =~ /darwin|linux|bsd/ &&
10
+ Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.3.0")
11
+
12
+ cache_dir = ENV['BOOTSNAP_CACHE_DIR']
13
+ unless cache_dir
14
+ config_dir_frame = caller.detect do |line|
15
+ line.include?('/config/')
16
+ end
17
+
18
+ unless config_dir_frame
19
+ $stderr.puts "[bootsnap/setup] couldn't infer cache directory! Either:"
20
+ $stderr.puts "[bootsnap/setup] 1. require bootsnap/setup from your application's config directory; or"
21
+ $stderr.puts "[bootsnap/setup] 2. Define the environment variable BOOTSNAP_CACHE_DIR"
22
+
23
+ raise "couldn't infer bootsnap cache directory"
24
+ end
25
+
26
+ path = config_dir_frame.split(/:\d+:/).first
27
+ path = File.dirname(path) until File.basename(path) == 'config'
28
+ app_root = File.dirname(path)
29
+
30
+ cache_dir = File.join(app_root, 'tmp', 'cache')
31
+ end
32
+
33
+ Bootsnap.setup(
34
+ cache_dir: cache_dir,
35
+ development_mode: development_mode,
36
+ load_path_cache: true,
37
+ autoload_paths_cache: true, # assume rails. open to PRs to impl. detection
38
+ disable_trace: false,
39
+ compile_cache_iseq: enable_cc,
40
+ compile_cache_yaml: enable_cc
41
+ )
@@ -0,0 +1,3 @@
1
+ module Bootsnap
2
+ VERSION = "1.3.1.pr-184.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ dependencies:
2
+ bundler:
3
+ without:
4
+ - development
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootsnap-pr-184
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.1.pr.pre.184.1
5
+ platform: ruby
6
+ authors:
7
+ - Burke Libbey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mocha
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: msgpack
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ description: Boot large ruby/rails apps faster
98
+ email:
99
+ - burke.libbey@shopify.com
100
+ executables: []
101
+ extensions:
102
+ - ext/bootsnap/extconf.rb
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".rubocop.yml"
107
+ - ".travis.yml"
108
+ - CHANGELOG.md
109
+ - CODE_OF_CONDUCT.md
110
+ - CONTRIBUTING.md
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.jp.md
114
+ - README.md
115
+ - Rakefile
116
+ - bin/console
117
+ - bin/setup
118
+ - bin/testunit
119
+ - bootsnap-pr-184.gemspec
120
+ - dev.yml
121
+ - ext/bootsnap/bootsnap.c
122
+ - ext/bootsnap/bootsnap.h
123
+ - ext/bootsnap/extconf.rb
124
+ - lib/bootsnap.rb
125
+ - lib/bootsnap/bundler.rb
126
+ - lib/bootsnap/compile_cache.rb
127
+ - lib/bootsnap/compile_cache/iseq.rb
128
+ - lib/bootsnap/compile_cache/yaml.rb
129
+ - lib/bootsnap/explicit_require.rb
130
+ - lib/bootsnap/load_path_cache.rb
131
+ - lib/bootsnap/load_path_cache/cache.rb
132
+ - lib/bootsnap/load_path_cache/change_observer.rb
133
+ - lib/bootsnap/load_path_cache/core_ext/active_support.rb
134
+ - lib/bootsnap/load_path_cache/core_ext/kernel_require.rb
135
+ - lib/bootsnap/load_path_cache/loaded_features_index.rb
136
+ - lib/bootsnap/load_path_cache/path.rb
137
+ - lib/bootsnap/load_path_cache/path_scanner.rb
138
+ - lib/bootsnap/load_path_cache/realpath_cache.rb
139
+ - lib/bootsnap/load_path_cache/store.rb
140
+ - lib/bootsnap/setup.rb
141
+ - lib/bootsnap/version.rb
142
+ - shipit.rubygems.yml
143
+ homepage: https://github.com/Shopify/bootsnap
144
+ licenses:
145
+ - MIT
146
+ metadata: {}
147
+ post_install_message:
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: 2.0.0
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">"
159
+ - !ruby/object:Gem::Version
160
+ version: 1.3.1
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 2.5.2
164
+ signing_key:
165
+ specification_version: 4
166
+ summary: Boot large ruby/rails apps faster
167
+ test_files: []