Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 490 lines (410 sloc) 15.087 kB
a77ca27 @segiddins [RuboCop] Enable Style/StringLiterals
segiddins authored
1 require "fileutils"
2 require "pathname"
3 require "rbconfig"
7bfd52d @agis- Wrap sudo access prompts in a mutex
agis- authored
4 require "thread"
a77ca27 @segiddins [RuboCop] Enable Style/StringLiterals
segiddins authored
5 require "bundler/gem_path_manipulation"
6 require "bundler/rubygems_ext"
7 require "bundler/rubygems_integration"
8 require "bundler/version"
9 require "bundler/constants"
10 require "bundler/current_ruby"
33154fd @joshbuddy Add Bundler.with_clean_env for blocks of ruby without a bundled env
joshbuddy authored
11
152a50a Rename gemfile back to bundler
Carl Lerche authored
12 module Bundler
f4dc6c5 @drogus Always try to keep original GEM_PATH
drogus authored
13 preserve_gem_path
33154fd @joshbuddy Add Bundler.with_clean_env for blocks of ruby without a bundled env
joshbuddy authored
14 ORIGINAL_ENV = ENV.to_hash
7bfd52d @agis- Wrap sudo access prompts in a mutex
agis- authored
15 SUDO_MUTEX = Mutex.new
67859e4 Moving in thor
Carlhuda authored
16
a77ca27 @segiddins [RuboCop] Enable Style/StringLiterals
segiddins authored
17 autoload :Definition, "bundler/definition"
18 autoload :Dependency, "bundler/dependency"
19 autoload :DepProxy, "bundler/dep_proxy"
20 autoload :Deprecate, "bundler/deprecate"
21 autoload :Dsl, "bundler/dsl"
22 autoload :EndpointSpecification, "bundler/endpoint_specification"
23 autoload :Environment, "bundler/environment"
24 autoload :Env, "bundler/env"
25 autoload :Fetcher, "bundler/fetcher"
26 autoload :GemHelper, "bundler/gem_helper"
27 autoload :GemHelpers, "bundler/gem_helpers"
28 autoload :GemInstaller, "bundler/gem_installer"
29 autoload :Graph, "bundler/graph"
30 autoload :Index, "bundler/index"
31 autoload :Installer, "bundler/installer"
32 autoload :Injector, "bundler/injector"
33 autoload :LazySpecification, "bundler/lazy_specification"
34 autoload :LockfileParser, "bundler/lockfile_parser"
35 autoload :MatchPlatform, "bundler/match_platform"
36 autoload :RemoteSpecification, "bundler/remote_specification"
37 autoload :Resolver, "bundler/resolver"
38 autoload :Retry, "bundler/retry"
39 autoload :RubyVersion, "bundler/ruby_version"
40 autoload :RubyDsl, "bundler/ruby_dsl"
41 autoload :Runtime, "bundler/runtime"
42 autoload :Settings, "bundler/settings"
43 autoload :SharedHelpers, "bundler/shared_helpers"
44 autoload :SpecSet, "bundler/spec_set"
45 autoload :StubSpecification, "bundler/stub_specification"
46 autoload :Source, "bundler/source"
47 autoload :SourceList, "bundler/source_list"
48 autoload :Specification, "bundler/shared_helpers"
49 autoload :SystemRubyVersion, "bundler/ruby_version"
50 autoload :UI, "bundler/ui"
67859e4 Moving in thor
Carlhuda authored
51
de5054a Rescue all Bundler exceptions and exit with appropriate error code
Carlhuda authored
52 class BundlerError < StandardError
7c5e545 @indirect Better gem install failure error, no backtrace
indirect authored
53 def self.status_code(code)
0ae574c DslError should inherit from Bundler::Error so its exceptions are cau…
Carlhuda authored
54 define_method(:status_code) { code }
de5054a Rescue all Bundler exceptions and exit with appropriate error code
Carlhuda authored
55 end
56 end
57
77c9dd8 @indirect Fix Style/SpaceAroundOperators
indirect authored
58 class GemfileNotFound < BundlerError; status_code(10); end
59 class GemNotFound < BundlerError; status_code(7); end
60 class GemfileError < BundlerError; status_code(4); end
61 class InstallError < BundlerError; status_code(5); end
62 class InstallHookError < BundlerError; status_code(8); end
63 class PathError < BundlerError; status_code(13); end
64 class GitError < BundlerError; status_code(11); end
65 class DeprecatedError < BundlerError; status_code(12); end
66 class GemspecError < BundlerError; status_code(14); end
67 class InvalidOption < BundlerError; status_code(15); end
68 class ProductionError < BundlerError; status_code(16); end
69 class HTTPError < BundlerError; status_code(17); end
70 class RubyVersionMismatch < BundlerError; status_code(18); end
71 class SecurityError < BundlerError; status_code(19); end
72 class LockfileError < BundlerError; status_code(20); end
c0f5855 @esasse Fix Style/SpaceBeforeSemicolon
esasse authored
73 class CyclicDependencyError < BundlerError; status_code(21); end
77c9dd8 @indirect Fix Style/SpaceAroundOperators
indirect authored
74 class GemfileLockNotFound < BundlerError; status_code(22); end
67859e4 Moving in thor
Carlhuda authored
75
4c3b339 @indirect Fantastic and also useful update instructions for outdated Bundler co…
indirect authored
76 # Internal errors, should be rescued
77c9dd8 @indirect Fix Style/SpaceAroundOperators
indirect authored
77 class VersionConflict < BundlerError
3edfddb Hacked together some crap that doesn't really work
Carl Lerche authored
78 attr_reader :conflicts
79
80 def initialize(conflicts, msg = nil)
81 super(msg)
82 @conflicts = conflicts
83 end
84
85 status_code(6)
86 end
87
f668e28 @agis- Handle errors when requiring gems gracefully
agis- authored
88 class GemRequireError < BundlerError
89 attr_reader :orig_exception
90
91 def initialize(orig_exception, msg)
92 super(msg)
93 @orig_exception = orig_exception
94 end
95
96 status_code(24)
97 end
98
8511403 @tricknotes Remove unused class `Bundler::InvalidSpecSet`
tricknotes authored
99 class MarshalError < StandardError; end
cf736cf Use the Lockfile's specs as LazySpecifications instead of converting …
Carl Lerche authored
100
dc4814d @repinel Improves the message displayed when cannot create config
repinel authored
101 class PermissionError < BundlerError
36ca3f3 @segiddins Make the PermissionsError configurable by needed permission
segiddins authored
102 def initialize(file, permission_type = :write)
dc4814d @repinel Improves the message displayed when cannot create config
repinel authored
103 @file = file
411d6f1 @segiddins Actually store the permission type
segiddins authored
104 @permission_type = permission_type
dc4814d @repinel Improves the message displayed when cannot create config
repinel authored
105 end
106
107 def message
411d6f1 @segiddins Actually store the permission type
segiddins authored
108 action = case @permission_type
36ca3f3 @segiddins Make the PermissionsError configurable by needed permission
segiddins authored
109 when :read then "read from"
110 when :write then "write to"
111 when :executable then "execute"
411d6f1 @segiddins Actually store the permission type
segiddins authored
112 else @permission_type.to_s
36ca3f3 @segiddins Make the PermissionsError configurable by needed permission
segiddins authored
113 end
114 "There was an error while trying to #{action} `#{File.basename(@file)}`. " \
411d6f1 @segiddins Actually store the permission type
segiddins authored
115 "It is likely that you need to grant #{@permission_type} permissions for " \
36ca3f3 @segiddins Make the PermissionsError configurable by needed permission
segiddins authored
116 "the file at path: `#{File.expand_path(@file)}`."
dc4814d @repinel Improves the message displayed when cannot create config
repinel authored
117 end
118
119 status_code(23)
120 end
121
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
122 class << self
3ac4215 @segiddins Ensure the RubyGems UI reflects the current Bundler UI
segiddins authored
123 attr_writer :bundle_path
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
124
125 def configure
239e2a0 @indirect handle blank GEM_HOMEs, too
indirect authored
126 @configured ||= configure_gem_home_and_path
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
127 end
434fb42 First pass at output
Carlhuda authored
128
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
129 def ui
b7f59ff @segiddins [Bundler] silence warning about using uninitialized @ui
segiddins authored
130 (defined?(@ui) && @ui) || (self.ui = UI::Silent.new)
3ac4215 @segiddins Ensure the RubyGems UI reflects the current Bundler UI
segiddins authored
131 end
132
133 def ui=(ui)
304f1fb @segiddins Unset UI when yielding to other programs
segiddins authored
134 Bundler.rubygems.ui = ui ? UI::RGProxy.new(ui) : nil
3ac4215 @segiddins Ensure the RubyGems UI reflects the current Bundler UI
segiddins authored
135 @ui = ui
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
136 end
434fb42 First pass at output
Carlhuda authored
137
b4f4437 @radar Add basic documentation for bin_path and bundle_path
radar authored
138 # Returns absolute path of where gems are installed on the filesystem.
5ad1279 Add the ability to set bundle env settings in a .bundleconfig file
Carl Lerche authored
139 def bundle_path
5b2d02f Make bundle install [PATH] namespace its gems to specific rubies
Carlhuda authored
140 @bundle_path ||= Pathname.new(settings.path).expand_path(root)
5ad1279 Add the ability to set bundle env settings in a .bundleconfig file
Carl Lerche authored
141 end
142
b4f4437 @radar Add basic documentation for bin_path and bundle_path
radar authored
143 # Returns absolute location of where binstubs are installed to.
5f26a03 Have bundler generate executable stubs into ~/.bundler/bin that will …
Carl Lerche authored
144 def bin_path
145 @bin_path ||= begin
25ab2dc Make generating bin stubs an option
Carl Lerche authored
146 path = settings[:bin] || "bin"
4ff5d84 @indirect don't need to path up a path
indirect authored
147 path = Pathname.new(path).expand_path(root).expand_path
0891a38 @spastorino Revert "Don't try to create dirs if they already exists"
spastorino authored
148 FileUtils.mkdir_p(path)
4ff5d84 @indirect don't need to path up a path
indirect authored
149 path
5f26a03 Have bundler generate executable stubs into ~/.bundler/bin that will …
Carl Lerche authored
150 end
151 end
152
1674aef No need to alias setup and require in Bundler
Carl Lerche authored
153 def setup(*groups)
5ff5cbc @indirect Tests and fix for Bundler.require removing gems from
indirect authored
154 # Just return if all groups are already loaded
155 return @setup if defined?(@setup)
2c8d6ae @indirect Don't call #setup after loading env.rb in Bundler.load
indirect authored
156
018a3c3 @hone ruby version check for bundle#console and Bundler.setup
hone authored
157 definition.validate_ruby!
158
5dfc54c @indirect Don't call exit! if Bundler.setup has an exception
indirect authored
159 if groups.empty?
160 # Load all groups, but only once
161 @setup = load.setup
162 else
c65a44d @segiddins [Setup] Fix multiple non-additive invocations of Bundler.setup with d…
segiddins authored
163 load.setup(*groups)
4980111 @indirect Fix Bundler.setup so it can be called more than once safely
indirect authored
164 end
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
165 end
ce350cc Get a simple bbl install working
Carlhuda authored
166
1674aef No need to alias setup and require in Bundler
Carl Lerche authored
167 def require(*groups)
69acfd8 @indirect Call Bundler.setup from Bundler.require, only set up each group once
indirect authored
168 setup(*groups).require(*groups)
a8cbf77 @jeremy Group autorequire: pass :require => 'autorequire' option to gem depen…
jeremy authored
169 end
170
625818a @indirect Clean up bundler.rb a bit
indirect authored
171 def load
91c74f4 Bundle.load and Bundle.runtime are the same thing again.
Carl Lerche authored
172 @load ||= Runtime.new(root, definition)
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
173 end
67859e4 Moving in thor
Carlhuda authored
174
3687843 @kevmoo check only needs Environment (not Runtime)
kevmoo authored
175 def environment
176 Bundler::Environment.new(root, definition)
177 end
178
c0fbe04 @gnufied Add some documentation about definition class
gnufied authored
179 # Returns an instance of Bundler::Definition for given Gemfile and lockfile
180 #
181 # @param unlock [Hash, Boolean, nil] Gems that have been requested
182 # to be updated or true if all gems should be updated
183 # @return [Bundler::Definition]
8a4dc7a Remove a little bit of crazy from Definition
Carl Lerche authored
184 def definition(unlock = nil)
185 @definition = nil if unlock
2b9094e Scope specs in the lock file by source
Carl Lerche authored
186 @definition ||= begin
187 configure
e0e79df @indirect Upgrade 0.9 lockfiles to 1.0 lockfiles in-place
indirect authored
188 upgrade_lockfile
251b9c7 Use the Gemfile's name as a base for Gemfile.lock
Carl Lerche authored
189 Definition.build(default_gemfile, default_lockfile, unlock)
2b9094e Scope specs in the lock file by source
Carl Lerche authored
190 end
ab5b1fc Add Bundler.flexdef, move locking into Environment, and lock from fle…
Carlhuda authored
191 end
192
b89e304 @indirect extract Bundler.locked_gems
indirect authored
193 def locked_gems
43732e9 @joyicecloud Displays the previous version of the gem when run bundle update
joyicecloud authored
194 return @locked_gems if defined?(@locked_gems)
195 if Bundler.default_lockfile.exist?
b89e304 @indirect extract Bundler.locked_gems
indirect authored
196 lock = Bundler.read_file(Bundler.default_lockfile)
fe86617 @TimMoore Fix typo lock_gems -> locked_gems.
TimMoore authored
197 @locked_gems = LockfileParser.new(lock)
43732e9 @joyicecloud Displays the previous version of the gem when run bundle update
joyicecloud authored
198 else
199 @locked_gems = nil
b89e304 @indirect extract Bundler.locked_gems
indirect authored
200 end
201 end
202
eda7324 @wycats Git should never use sudo
wycats authored
203 def ruby_scope
76fa378 @indirect move ConfigMap into RubygemsIntegration
indirect authored
204 "#{Bundler.rubygems.ruby_engine}/#{Bundler.rubygems.config_map[:ruby_version]}"
eda7324 @wycats Git should never use sudo
wycats authored
205 end
206
207 def user_bundle_path
5f4a8f3 Phase 1 of rubygems/bundler reintegration
Evan Phoenix authored
208 Pathname.new(Bundler.rubygems.user_home).join(".bundler")
eda7324 @wycats Git should never use sudo
wycats authored
209 end
210
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
211 def home
625818a @indirect Clean up bundler.rb a bit
indirect authored
212 bundle_path.join("bundler")
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
213 end
f31835e More work towards awesomeness
Carlhuda authored
214
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
215 def install_path
216 home.join("gems")
217 end
0d2492d Add more stuff for git
Carl Lerche authored
218
0d92de7 @indirect Add Bundler::Source::BundlerGems, to distingush from SystemGems.
indirect authored
219 def specs_path
220 bundle_path.join("specifications")
221 end
222
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
223 def cache
0d92de7 @indirect Add Bundler::Source::BundlerGems, to distingush from SystemGems.
indirect authored
224 bundle_path.join("cache/bundler")
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
225 end
ee0e2c1 Start working on the environment.rb lock file
Carl Lerche authored
226
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
227 def root
d1c0f0b @dholdren `bundle config --local gemfile /foo/bar/MyGemfile` now works
dholdren authored
228 @root ||= begin
229 default_gemfile.dirname.expand_path
230 rescue GemfileNotFound
231 bundle_dir = default_bundle_dir
232 raise GemfileNotFound, "Could not locate Gemfile or .bundle/ directory" unless bundle_dir
233 Pathname.new(File.expand_path("..", bundle_dir))
234 end
2d87c36 Move <root>/vendor/cache to a Bundler class method
Carl Lerche authored
235 end
236
27800e7 Provide an environment variable to allow customizing the location of …
Carl Lerche authored
237 def app_config_path
83acfe3 @Koronen Fix Style/MultilineTernaryOperator
Koronen authored
238 if ENV["BUNDLE_APP_CONFIG"]
239 Pathname.new(ENV["BUNDLE_APP_CONFIG"]).expand_path(root)
240 else
a77ca27 @segiddins [RuboCop] Enable Style/StringLiterals
segiddins authored
241 root.join(".bundle")
83acfe3 @Koronen Fix Style/MultilineTernaryOperator
Koronen authored
242 end
27800e7 Provide an environment variable to allow customizing the location of …
Carl Lerche authored
243 end
244
ce668a1 @gjaldon --path changes directory where 'vendor/cache' is created
gjaldon authored
245 def app_cache(custom_path = nil)
246 path = custom_path || root
3c6c010 @indirect allow cache path to be configured
indirect authored
247 path.join(self.settings.app_cache_path)
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
248 end
249
bec906d @indirect er, one tmp per install run. yeah.
indirect authored
250 def tmp(name = Process.pid.to_s)
ae865a0 @indirect clean up tmp dirs if they get created
indirect authored
251 Pathname.new(Dir.mktmpdir(["bundler", name]))
32a2eb2 First pass at getting bundler to play well when $GEM_HOME is owned by…
Carl Lerche authored
252 end
253
ae865a0 @indirect clean up tmp dirs if they get created
indirect authored
254 def rm_rf(path)
255 FileUtils.remove_entry_secure(path) if path && File.exist?(path)
e7f2855 @obfusk cleanup tempdir
obfusk authored
256 end
257
ea08895 Add the ability to specify a location with bundle install
Carl Lerche authored
258 def settings
2cd5993 @indirect guarantee Bundler.settings will only parse once
indirect authored
259 return @settings if defined?(@settings)
260 @settings = Settings.new(app_config_path)
261 rescue GemfileNotFound
d1c0f0b @dholdren `bundle config --local gemfile /foo/bar/MyGemfile` now works
dholdren authored
262 @settings = Settings.new(Pathname.new(".bundle").expand_path)
ea08895 Add the ability to specify a location with bundle install
Carl Lerche authored
263 end
264
5cf3fde @wuputah with_clean_env clears bundler env vars
wuputah authored
265 def with_original_env
33154fd @joshbuddy Add Bundler.with_clean_env for blocks of ruby without a bundled env
joshbuddy authored
266 bundled_env = ENV.to_hash
267 ENV.replace(ORIGINAL_ENV)
268 yield
269 ensure
270 ENV.replace(bundled_env.to_hash)
271 end
272
5cf3fde @wuputah with_clean_env clears bundler env vars
wuputah authored
273 def with_clean_env
274 with_original_env do
a77ca27 @segiddins [RuboCop] Enable Style/StringLiterals
segiddins authored
275 ENV["MANPATH"] = ENV["BUNDLE_ORIG_MANPATH"]
4c462af @esasse Fix pending offenses
esasse authored
276 ENV.delete_if {|k, _| k[0, 7] == "BUNDLE_" }
6002eae @Koronen Fix Style/DeprecatedHashMethods
Koronen authored
277 if ENV.key? "RUBYOPT"
a77ca27 @segiddins [RuboCop] Enable Style/StringLiterals
segiddins authored
278 ENV["RUBYOPT"] = ENV["RUBYOPT"].sub "-rbundler/setup", ""
279 ENV["RUBYOPT"] = ENV["RUBYOPT"].sub "-I#{File.expand_path("..", __FILE__)}", ""
691c8ac @eric1234 Avoid passing RUBYOPT changes in with_clean_env block.
eric1234 authored
280 end
5cf3fde @wuputah with_clean_env clears bundler env vars
wuputah authored
281 yield
282 end
283 end
284
926836d @wuputah add Bundler.clean_system and Bundler.clean_exec
wuputah authored
285 def clean_system(*args)
286 with_clean_env { Kernel.system(*args) }
287 end
288
289 def clean_exec(*args)
290 with_clean_env { Kernel.exec(*args) }
291 end
292
fb1e725 Make bundler/setup something you can add to your .profile. To do this…
Carlhuda authored
293 def default_gemfile
294 SharedHelpers.default_gemfile
ee0e2c1 Start working on the environment.rb lock file
Carl Lerche authored
295 end
296
251b9c7 Use the Gemfile's name as a base for Gemfile.lock
Carl Lerche authored
297 def default_lockfile
298 SharedHelpers.default_lockfile
299 end
300
d1c0f0b @dholdren `bundle config --local gemfile /foo/bar/MyGemfile` now works
dholdren authored
301 def default_bundle_dir
302 SharedHelpers.default_bundle_dir
303 end
304
af6badf @indirect Add Bundler.system_bindir, defaulted to Gem.bindir
indirect authored
305 def system_bindir
306 # Gem.bindir doesn't always return the location that Rubygems will install
80b2d24 @indirect use Bundler.system_gems even when sudo is needed
indirect authored
307 # system binaries. If you put '-n foo' in your .gemrc, Rubygems will
af6badf @indirect Add Bundler.system_bindir, defaulted to Gem.bindir
indirect authored
308 # install binstubs there instead. Unfortunately, Rubygems doesn't expose
309 # that directory at all, so rather than parse .gemrc ourselves, we allow
310 # the directory to be set as well, via `bundle config bindir foo`.
80b2d24 @indirect use Bundler.system_gems even when sudo is needed
indirect authored
311 Bundler.settings[:system_bindir] || Bundler.rubygems.gem_bindir
af6badf @indirect Add Bundler.system_bindir, defaulted to Gem.bindir
indirect authored
312 end
313
32a2eb2 First pass at getting bundler to play well when $GEM_HOME is owned by…
Carl Lerche authored
314 def requires_sudo?
3fc6be1 @indirect improve sudo install support
indirect authored
315 return @requires_sudo if defined?(@requires_sudo_ran)
47e08d4 @indirect Memoize Bundler#requires_sudo? (thanks @tmm1)
indirect authored
316
3fc6be1 @indirect improve sudo install support
indirect authored
317 if settings.allow_sudo?
318 sudo_present = which "sudo"
319 end
320
321 if sudo_present
322 # the bundle path and subdirectories need to be writable for Rubygems
323 # to be able to unpack and install gems without exploding
324 path = bundle_path
325 path = path.parent until path.exist?
326
327 # bins are written to a different location on OS X
328 bin_dir = Pathname.new(Bundler.system_bindir)
329 bin_dir = bin_dir.parent until bin_dir.exist?
330
331 # if any directory is not writable, we need sudo
a77ca27 @segiddins [RuboCop] Enable Style/StringLiterals
segiddins authored
332 files = [path, bin_dir] | Dir[path.join("build_info/*").to_s] | Dir[path.join("*").to_s]
0f8bc78 @indirect Fix Style/SpaceInsideBlockBraces
indirect authored
333 sudo_needed = files.any? {|f| !File.writable?(f) }
3fc6be1 @indirect improve sudo install support
indirect authored
334 end
3f350e0 Add more sanity to the cases where bundler runs commands with sudo
Carlhuda authored
335
3fc6be1 @indirect improve sudo install support
indirect authored
336 @requires_sudo_ran = true
337 @requires_sudo = settings.allow_sudo? && sudo_present && sudo_needed
3f350e0 Add more sanity to the cases where bundler runs commands with sudo
Carlhuda authored
338 end
339
340 def mkdir_p(path)
341 if requires_sudo?
5bad314 @spastorino Avoid calling mkdir with sudo when not needed, you don't want to be a…
spastorino authored
342 sudo "mkdir -p '#{path}'" unless File.exist?(path)
3f350e0 Add more sanity to the cases where bundler runs commands with sudo
Carlhuda authored
343 else
344 FileUtils.mkdir_p(path)
0891a38 @spastorino Revert "Don't try to create dirs if they already exists"
spastorino authored
345 end
3f350e0 Add more sanity to the cases where bundler runs commands with sudo
Carlhuda authored
346 end
347
26fa77a @sferik Not all executables are binary
sferik authored
348 def which(executable)
628927b @rhysd Fix Bundler::which
rhysd authored
349 if File.file?(executable) && File.executable?(executable)
26fa77a @sferik Not all executables are binary
sferik authored
350 executable
a77ca27 @segiddins [RuboCop] Enable Style/StringLiterals
segiddins authored
351 elsif ENV["PATH"]
352 path = ENV["PATH"].split(File::PATH_SEPARATOR).find do |p|
b413574 @JMorimoto Fix Bundler::which
JMorimoto authored
353 abs_path = File.join(p, executable)
354 File.file?(abs_path) && File.executable?(abs_path)
1e82d7f @indirect fix shadowed variable warning
indirect authored
355 end
26fa77a @sferik Not all executables are binary
sferik authored
356 path && File.expand_path(executable, path)
d3a69d3 @tenderlove Search $PATH for a binary rather than shelling out to `which`
tenderlove authored
357 end
358 end
359
3f350e0 Add more sanity to the cases where bundler runs commands with sudo
Carlhuda authored
360 def sudo(str)
7bfd52d @agis- Wrap sudo access prompts in a mutex
agis- authored
361 SUDO_MUTEX.synchronize do
362 prompt = "\n\n" + <<-PROMPT.gsub(/^ {6}/, "").strip + " "
363 Your user account isn't allowed to install to the system Rubygems.
364 You can cancel this installation and run:
41476e2 @ixti Improves sudo propmt
ixti authored
365
7bfd52d @agis- Wrap sudo access prompts in a mutex
agis- authored
366 bundle install --path vendor/bundle
41476e2 @ixti Improves sudo propmt
ixti authored
367
7bfd52d @agis- Wrap sudo access prompts in a mutex
agis- authored
368 to install the gems into ./vendor/bundle/, or you can enter your password
369 and install the bundled gems to Rubygems using sudo.
41476e2 @ixti Improves sudo propmt
ixti authored
370
7bfd52d @agis- Wrap sudo access prompts in a mutex
agis- authored
371 Password:
372 PROMPT
41476e2 @ixti Improves sudo propmt
ixti authored
373
7bfd52d @agis- Wrap sudo access prompts in a mutex
agis- authored
374 `sudo -p "#{prompt}" #{str}`
375 end
32a2eb2 First pass at getting bundler to play well when $GEM_HOME is owned by…
Carl Lerche authored
376 end
377
94bad63 @wycats 1.8 doesn't support :mode
wycats authored
378 def read_file(file)
14a7eb2 @indirect Fix Style/SpaceInsideBlockBraces
indirect authored
379 File.open(file, "rb") {|f| f.read }
94bad63 @wycats 1.8 doesn't support :mode
wycats authored
380 end
381
bfc0632 @indirect abstract Marshal.load failures
indirect authored
382 def load_marshal(data)
383 Marshal.load(data)
384 rescue => e
385 raise MarshalError, "#{e.class}: #{e.message}"
386 end
387
7aaee7a @indirect RubyGems can only validate during chdir
indirect authored
388 def load_gemspec(file, validate = false)
26637b7 @dekellum Resurrect "Add simple cache to Bundler.load_gemspec"
dekellum authored
389 @gemspec_cache ||= {}
0310e95 @dekellum Fix for spec failure introduced in d24e788a, with gemspec cache.
dekellum authored
390 key = File.expand_path(file)
7aaee7a @indirect RubyGems can only validate during chdir
indirect authored
391 @gemspec_cache[key] ||= load_gemspec_uncached(file, validate)
0310e95 @dekellum Fix for spec failure introduced in d24e788a, with gemspec cache.
dekellum authored
392 # Protect against caching side-effected gemspecs by returning a
393 # new instance each time.
c7c13d0 @segiddins Restore deleted #dup for cached gemspecs
segiddins authored
394 @gemspec_cache[key].dup if @gemspec_cache[key]
26637b7 @dekellum Resurrect "Add simple cache to Bundler.load_gemspec"
dekellum authored
395 end
396
7aaee7a @indirect RubyGems can only validate during chdir
indirect authored
397 def load_gemspec_uncached(file, validate = false)
681a5cb @indirect Factor out Bundler.load_gemspec so Source::Path and GemHelper can use it
indirect authored
398 path = Pathname.new(file)
c9b74e6 @indirect clean up load_gemspec a bit, organize specs
indirect authored
399 # Eval the gemspec from its parent directory, because some gemspecs
400 # depend on "./" relative paths.
4be789d @eagletmt Prohibit Dir.pwd while another thread is doing Dir.chdir
eagletmt authored
401 SharedHelpers.chdir(path.dirname.to_s) do
c9b74e6 @indirect clean up load_gemspec a bit, organize specs
indirect authored
402 contents = path.read
403 if contents[0..2] == "---" # YAML header
7aaee7a @indirect RubyGems can only validate during chdir
indirect authored
404 spec = eval_yaml_gemspec(path, contents)
d1b6ced @tenderlove only parse specs as YAML if they look like YAML files, otherwise fall
tenderlove authored
405 else
7aaee7a @indirect RubyGems can only validate during chdir
indirect authored
406 spec = eval_gemspec(path, contents)
681a5cb @indirect Factor out Bundler.load_gemspec so Source::Path and GemHelper can use it
indirect authored
407 end
4d17371 @indirect fix validation exceptions by skipping on RG <1.7
indirect authored
408 Bundler.rubygems.validate(spec) if spec && validate
7aaee7a @indirect RubyGems can only validate during chdir
indirect authored
409 spec
681a5cb @indirect Factor out Bundler.load_gemspec so Source::Path and GemHelper can use it
indirect authored
410 end
9ed9afd @indirect completely backwards-compatible gemspec validation
indirect authored
411 rescue Gem::InvalidSpecificationException => e
3328f92 @indirect downgrade invalid specs to a warning for now
indirect authored
412 Bundler.ui.warn "The gemspec at #{file} is not valid. " \
9ed9afd @indirect completely backwards-compatible gemspec validation
indirect authored
413 "The validation error was '#{e.message}'"
b7b6d96 @indirect Update spec to fail, then fix it
indirect authored
414 nil
681a5cb @indirect Factor out Bundler.load_gemspec so Source::Path and GemHelper can use it
indirect authored
415 end
416
9a7099e @indirect argh, accidentally changed method name
indirect authored
417 def clear_gemspec_cache
32dfee4 @hone instance_variable_set is ugly, turn it into a method
hone authored
418 @gemspec_cache = {}
419 end
420
7bd8264 @joyicecloud Print a better error when git is not installed.
joyicecloud authored
421 def git_present?
f894bdf @indirect look for windows git too
indirect authored
422 return @git_present if defined?(@git_present)
423 @git_present = Bundler.which("git") || Bundler.which("git.exe")
7bd8264 @joyicecloud Print a better error when git is not installed.
joyicecloud authored
424 end
425
5efd1c5 @indirect extract into Bundler.ruby_version
indirect authored
426 def ruby_version
427 @ruby_version ||= SystemRubyVersion.new
428 end
429
f3588cf @smashwilson Bundler.reset! nukes the global Definition.
smashwilson authored
430 def reset!
431 @definition = nil
432 end
433
9ef6aa6 @indirect Disable rubygems more fully when unlocked
indirect authored
434 private
435
c9b74e6 @indirect clean up load_gemspec a bit, organize specs
indirect authored
436 def eval_yaml_gemspec(path, contents)
437 # If the YAML is invalid, Syck raises an ArgumentError, and Psych
438 # raises a Psych::SyntaxError. See psyched_yaml.rb for more info.
439 Gem::Specification.from_yaml(contents)
440 rescue YamlSyntaxError, ArgumentError, Gem::EndOfYAMLException, Gem::Exception
441 eval_gemspec(path, contents)
442 end
443
d1b6ced @tenderlove only parse specs as YAML if they look like YAML files, otherwise fall
tenderlove authored
444 def eval_gemspec(path, contents)
445 eval(contents, TOPLEVEL_BINDING, path.expand_path.to_s)
d0ad86f @indirect Ruby has an exception hierarchy! Who knew?
indirect authored
446 rescue ScriptError, StandardError => e
14a7eb2 @indirect Fix Style/SpaceInsideBlockBraces
indirect authored
447 original_line = e.backtrace.find {|line| line.include?(path.to_s) }
b779901 @segiddins [RuboCop] Update to 0.33.0
segiddins authored
448 msg = "There was a #{e.class} while loading #{path.basename}: \n#{e.message}"
d1b6ced @tenderlove only parse specs as YAML if they look like YAML files, otherwise fall
tenderlove authored
449 msg << " from\n #{original_line}" if original_line
450 msg << "\n"
451
452 if e.is_a?(LoadError) && RUBY_VERSION >= "1.9"
453 msg << "\nDoes it try to require a relative path? That's been removed in Ruby 1.9."
454 end
455
456 raise GemspecError, msg
457 end
458
739c0f3 Install bundles to ~/.bundle by default
Carlhuda authored
459 def configure_gem_home_and_path
a77ca27 @segiddins [RuboCop] Enable Style/StringLiterals
segiddins authored
460 blank_home = ENV["GEM_HOME"].nil? || ENV["GEM_HOME"].empty?
3d82929 Separate bundle install foo and bundle install --disable-shared-gems.
Carl Lerche authored
461 if settings[:disable_shared_gems]
a77ca27 @segiddins [RuboCop] Enable Style/StringLiterals
segiddins authored
462 ENV["GEM_PATH"] = ""
239e2a0 @indirect handle blank GEM_HOMEs, too
indirect authored
463 elsif blank_home || Bundler.rubygems.gem_dir != bundle_path.to_s
5f4a8f3 Phase 1 of rubygems/bundler reintegration
Evan Phoenix authored
464 possibles = [Bundler.rubygems.gem_dir, Bundler.rubygems.gem_path]
af69407 @segiddins [RuboCop] Enable Style/SymbolProc
segiddins authored
465 paths = possibles.flatten.compact.uniq.reject(&:empty?)
55509f2 @indirect Ignore paths like GEM_HOME that are empty strings
indirect authored
466 ENV["GEM_PATH"] = paths.join(File::PATH_SEPARATOR)
a132e47 @tenderlove do not clear RG cache unless we actually modify GEM_PATH and GEM_HOME
tenderlove authored
467 end
bdaf3b8 @simi Raise GemfileLockNotFound only for non-full update.
simi authored
468
44ff94f @narutosanjiv remove the duplicate code configure_gem and put it after if and else …
narutosanjiv authored
469 configure_gem_home
239e2a0 @indirect handle blank GEM_HOMEs, too
indirect authored
470 bundle_path
471 end
472
473 def configure_gem_home
474 # TODO: This mkdir_p is only needed for JRuby <= 1.5 and should go away (GH #602)
475 FileUtils.mkdir_p bundle_path.to_s rescue nil
476
a77ca27 @segiddins [RuboCop] Enable Style/StringLiterals
segiddins authored
477 ENV["GEM_HOME"] = File.expand_path(bundle_path, root)
239e2a0 @indirect handle blank GEM_HOMEs, too
indirect authored
478 Bundler.rubygems.clear_paths
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
479 end
e0e79df @indirect Upgrade 0.9 lockfiles to 1.0 lockfiles in-place
indirect authored
480
481 def upgrade_lockfile
251b9c7 Use the Gemfile's name as a base for Gemfile.lock
Carl Lerche authored
482 lockfile = default_lockfile
e0e79df @indirect Upgrade 0.9 lockfiles to 1.0 lockfiles in-place
indirect authored
483 if lockfile.exist? && lockfile.read(3) == "---"
91c3beb @indirect Back to deleting old lockfiles for the beta release
indirect authored
484 Bundler.ui.warn "Detected Gemfile.lock generated by 0.9, deleting..."
485 lockfile.rmtree
e0e79df @indirect Upgrade 0.9 lockfiles to 1.0 lockfiles in-place
indirect authored
486 end
487 end
ee0e2c1 Start working on the environment.rb lock file
Carl Lerche authored
488 end
a8cbf77 @jeremy Group autorequire: pass :require => 'autorequire' option to gem depen…
jeremy authored
489 end
Something went wrong with that request. Please try again.