Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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