Class: Bundler::Runtime
Constant Summary
collapse
- REQUIRE_ERRORS =
[
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
/^dlopen\([^)]*\): Library not loaded: (.+)$/i,
].freeze
Instance Attribute Summary
#gem_loaded
Attributes inherited from Environment
#root
Instance Method Summary
collapse
#chdir, #const_get_safely, #default_bundle_dir, #default_gemfile, #default_lockfile, #filesystem_access, #in_bundle?, #pwd, #set_bundle_environment, #with_clean_git_env
Methods inherited from Environment
#current_dependencies, #dependencies, #initialize, #inspect, #lock, #requested_specs, #specs, #update
Instance Method Details
#cache(custom_path = nil) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# File 'lib/bundler/runtime.rb', line 120
def cache(custom_path = nil)
cache_path = Bundler.app_cache(custom_path)
SharedHelpers.filesystem_access(cache_path) do |p|
FileUtils.mkdir_p(p)
end unless File.exist?(cache_path)
Bundler.ui.info "Updating files in #{Bundler.settings.app_cache_path}"
root_gem_name = nil
if gemspec_cache_hash = Bundler.instance_variable_get(:@gemspec_cache)
gemspec = gemspec_cache_hash.values.first
root_gem_name = gemspec.name unless gemspec.nil?
end
specs.each do |spec|
next if spec.name == "bundler"
next if !Dir.glob("*.gemspec").empty? && spec.source.class == Bundler::Source::Path && root_gem_name && spec.name == root_gem_name
spec.source.send(:fetch_gem, spec) if Bundler.settings[:cache_all_platforms] && spec.source.respond_to?(:fetch_gem, true)
spec.source.cache(spec, custom_path) if spec.source.respond_to?(:cache)
end
Dir[cache_path.join("*/.git")].each do |git_dir|
FileUtils.rm_rf(git_dir)
FileUtils.touch(File.expand_path("../.bundlecache", git_dir))
end
prune_cache(cache_path) unless Bundler.settings[:no_prune]
end
|
#clean(dry_run = false) ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/bundler/runtime.rb', line 159
def clean(dry_run = false)
gem_bins = Dir["#{Gem.dir}/bin/*"]
git_dirs = Dir["#{Gem.dir}/bundler/gems/*"]
git_cache_dirs = Dir["#{Gem.dir}/cache/bundler/git/*"]
gem_dirs = Dir["#{Gem.dir}/gems/*"]
gem_files = Dir["#{Gem.dir}/cache/*.gem"]
gemspec_files = Dir["#{Gem.dir}/specifications/*.gemspec"]
spec_gem_paths = []
spec_git_paths = @definition.spec_git_paths
spec_git_cache_dirs = []
spec_gem_executables = []
spec_cache_paths = []
spec_gemspec_paths = []
specs.each do |spec|
spec_gem_paths << spec.full_gem_path
md = %r{(.+bundler/gems/.+-[a-f0-9]{7,12})}.match(spec.full_gem_path)
spec_git_paths << md[1] if md
spec_gem_executables << spec.executables.collect do |executable|
e = "#{Bundler.rubygems.gem_bindir}/#{executable}"
[e, "#{e}.bat"]
end
spec_cache_paths << spec.cache_file
spec_gemspec_paths << spec.spec_file
spec_git_cache_dirs << spec.source.cache_path.to_s if spec.source.is_a?(Bundler::Source::Git)
end
spec_gem_paths.uniq!
spec_gem_executables.flatten!
stale_gem_bins = gem_bins - spec_gem_executables
stale_git_dirs = git_dirs - spec_git_paths - ["#{Gem.dir}/bundler/gems/extensions"]
stale_git_cache_dirs = git_cache_dirs - spec_git_cache_dirs
stale_gem_dirs = gem_dirs - spec_gem_paths
stale_gem_files = gem_files - spec_cache_paths
stale_gemspec_files = gemspec_files - spec_gemspec_paths
removed_stale_gem_dirs = stale_gem_dirs.collect {|dir| remove_dir(dir, dry_run) }
removed_stale_git_dirs = stale_git_dirs.collect {|dir| remove_dir(dir, dry_run) }
output = removed_stale_gem_dirs + removed_stale_git_dirs
unless dry_run
stale_files = stale_gem_bins + stale_gem_files + stale_gemspec_files
stale_files.each do |file|
SharedHelpers.filesystem_access(File.dirname(file)) do |_p|
FileUtils.rm(file) if File.exist?(file)
end
end
stale_git_cache_dirs.each do |cache_dir|
SharedHelpers.filesystem_access(cache_dir) do |dir|
FileUtils.rm_rf(dir) if File.exist?(dir)
end
end
end
output
end
|
#dependencies_for(*groups) ⇒ Object
110
111
112
113
114
115
116
|
# File 'lib/bundler/runtime.rb', line 110
def dependencies_for(*groups)
if groups.empty?
dependencies
else
dependencies.select {|d| (groups & d.groups).any? }
end
end
|
#prune_cache(cache_path) ⇒ Object
150
151
152
153
154
155
156
157
|
# File 'lib/bundler/runtime.rb', line 150
def prune_cache(cache_path)
SharedHelpers.filesystem_access(cache_path) do |p|
FileUtils.mkdir_p(p)
end unless File.exist?(cache_path)
resolve = @definition.resolve
prune_gem_cache(resolve, cache_path)
prune_git_and_path_cache(resolve, cache_path)
end
|
#require(*groups) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/bundler/runtime.rb', line 66
def require(*groups)
groups.map!(&:to_sym)
groups = [:default] if groups.empty?
@definition.dependencies.each do |dep|
next unless (dep.groups & groups).any? && dep.current_platform?
required_file = nil
begin
Array(dep.autorequire || dep.name).each do |file|
file = dep.name if file == true
required_file = file
begin
Kernel.require file
rescue => e
raise e if e.is_a?(LoadError) raise Bundler::GemRequireError.new e,
"There was an error while trying to load the gem '#{file}'."
end
end
rescue LoadError => e
REQUIRE_ERRORS.find {|r| r =~ e.message }
raise if dep.autorequire || $1 != required_file
if dep.autorequire.nil? && dep.name.include?("-")
begin
namespaced_file = dep.name.tr("-", "/")
Kernel.require namespaced_file
rescue LoadError => e
REQUIRE_ERRORS.find {|r| r =~ e.message }
raise if $1 != namespaced_file
end
end
end
end
end
|
#setup(*groups) ⇒ Object
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/bundler/runtime.rb', line 8
def setup(*groups)
groups.map!(&:to_sym)
clean_load_path
specs = groups.any? ? @definition.specs_for(groups) : requested_specs
SharedHelpers.set_bundle_environment
Bundler.rubygems.replace_entrypoints(specs)
load_paths = specs.map do |spec|
unless spec.loaded_from
raise GemNotFound, "#{spec.full_name} is missing. Run `bundle` to get it."
end
if (activated_spec = Bundler.rubygems.loaded_specs(spec.name)) && activated_spec.version != spec.version
e = Gem::LoadError.new "You have already activated #{activated_spec.name} #{activated_spec.version}, " \
"but your Gemfile requires #{spec.name} #{spec.version}. Prepending " \
"`bundle exec` to your command may solve this."
e.name = spec.name
if e.respond_to?(:requirement=)
e.requirement = Gem::Requirement.new(spec.version.to_s)
else
e.version_requirement = Gem::Requirement.new(spec.version.to_s)
end
raise e
end
Bundler.rubygems.mark_loaded(spec)
spec.load_paths.reject {|path| $LOAD_PATH.include?(path) }
end.reverse.flatten
if insert_index = Bundler.rubygems.load_path_insert_index
$LOAD_PATH.insert(insert_index, *load_paths)
else
$LOAD_PATH.unshift(*load_paths)
end
setup_manpath
lock(:preserve_unknown_sections => true)
self
end
|