Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 306 lines (250 sloc) 8.543 kB
dfe5d10 @spastorino Config is deprecated on 1.8.8 and 1.9.3, use RbConfig
spastorino authored
1 require 'rbconfig'
63b636b First pass at gemfile pack
Carlhuda authored
2 require 'fileutils'
ce350cc Get a simple bbl install working
Carlhuda authored
3 require 'pathname'
a318f91 @tenderlove adding requires and default yaml parser to psych if possible
tenderlove authored
4
5 begin
6 require 'psych'
7 rescue LoadError
8 end
9
88741e6 First pass at bbl lock
Carlhuda authored
10 require 'yaml'
820bb93 Rename rubygems-ext to rubygems_ext
Carl Lerche authored
11 require 'bundler/rubygems_ext'
5f4a8f3 Phase 1 of rubygems/bundler reintegration
Evan Phoenix authored
12 require 'bundler/rubygems_integration'
1da7eb3 Don't generate bundler.gemspec anymore
Carlhuda authored
13 require 'bundler/version'
33154fd @joshbuddy Add Bundler.with_clean_env for blocks of ruby without a bundled env
joshbuddy authored
14
152a50a Rename gemfile back to bundler
Carl Lerche authored
15 module Bundler
33154fd @joshbuddy Add Bundler.with_clean_env for blocks of ruby without a bundled env
joshbuddy authored
16 ORIGINAL_ENV = ENV.to_hash
67859e4 Moving in thor
Carlhuda authored
17
207179d @hone put endpoint dependency info into a bundler spec
hone authored
18 autoload :Definition, 'bundler/definition'
19 autoload :Dependency, 'bundler/dependency'
20 autoload :Dsl, 'bundler/dsl'
21 autoload :EndpointSpecification, 'bundler/endpoint_specification'
22 autoload :Environment, 'bundler/environment'
23 autoload :Fetcher, 'bundler/fetcher'
24 autoload :GemHelper, 'bundler/gem_helper'
25 autoload :Graph, 'bundler/graph'
26 autoload :Index, 'bundler/index'
27 autoload :Installer, 'bundler/installer'
28 autoload :LazySpecification, 'bundler/lazy_specification'
29 autoload :LockfileParser, 'bundler/lockfile_parser'
30 autoload :RemoteSpecification, 'bundler/remote_specification'
31 autoload :Resolver, 'bundler/resolver'
32 autoload :Runtime, 'bundler/runtime'
33 autoload :Settings, 'bundler/settings'
34 autoload :SharedHelpers, 'bundler/shared_helpers'
35 autoload :SpecSet, 'bundler/spec_set'
36 autoload :Source, 'bundler/source'
37 autoload :Specification, 'bundler/shared_helpers'
38 autoload :UI, 'bundler/ui'
67859e4 Moving in thor
Carlhuda authored
39
de5054a Rescue all Bundler exceptions and exit with appropriate error code
Carlhuda authored
40 class BundlerError < StandardError
41 def self.status_code(code = nil)
0ae574c DslError should inherit from Bundler::Error so its exceptions are cau…
Carlhuda authored
42 define_method(:status_code) { code }
de5054a Rescue all Bundler exceptions and exit with appropriate error code
Carlhuda authored
43 end
44 end
45
5894862 Print useful warnings when deprecated options are used
Yehuda Katz authored
46 class GemfileNotFound < BundlerError; status_code(10) ; end
47 class GemNotFound < BundlerError; status_code(7) ; end
48 class GemfileError < BundlerError; status_code(4) ; end
248ca34 Raise a better error in the case that a git repo is not cloned yet.
Carl Lerche authored
49 class PathError < BundlerError; status_code(13) ; end
5894862 Print useful warnings when deprecated options are used
Yehuda Katz authored
50 class GitError < BundlerError; status_code(11) ; end
d7e1dc1 @wycats Remove standalone #git in the DSL. Instead, use the block form of #gi…
wycats authored
51 class DeprecatedError < BundlerError; status_code(12) ; end
2a24019 @indirect Print a useful error if a gemspec require fails
indirect authored
52 class GemspecError < BundlerError; status_code(14) ; end
0ae574c DslError should inherit from Bundler::Error so its exceptions are cau…
Carlhuda authored
53 class DslError < BundlerError; status_code(15) ; end
cb3ec8e Update --production to yell if the user changed their Gemfile without…
Carlhuda authored
54 class ProductionError < BundlerError; status_code(16) ; end
0ae574c DslError should inherit from Bundler::Error so its exceptions are cau…
Carlhuda authored
55 class InvalidOption < DslError ; end
8a3e4bc @hone move HTTPError to lib/bundler.rb
hone authored
56 class HTTPError < BundlerError; status_code(17) ; end
67859e4 Moving in thor
Carlhuda authored
57
67e3310 Integrate the new bundler man pages with bundle help
Carl Lerche authored
58
59 WINDOWS = RbConfig::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw)!
9db9102 @indirect Install with RB_USER_INSTALL on BSDs
indirect authored
60 FREEBSD = RbConfig::CONFIG["host_os"] =~ /bsd/
67e3310 Integrate the new bundler man pages with bundle help
Carl Lerche authored
61 NULL = WINDOWS ? "NUL" : "/dev/null"
62
4c3b339 @indirect Fantastic and also useful update instructions for outdated Bundler co…
indirect authored
63 # Internal errors, should be rescued
3edfddb Hacked together some crap that doesn't really work
Carl Lerche authored
64 class VersionConflict < BundlerError
65 attr_reader :conflicts
66
67 def initialize(conflicts, msg = nil)
68 super(msg)
69 @conflicts = conflicts
70 end
71
72 status_code(6)
73 end
74
cf736cf Use the Lockfile's specs as LazySpecifications instead of converting …
Carl Lerche authored
75 class InvalidSpecSet < StandardError; end
76
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
77 class << self
78a6b48 Rename vendor/lock.yml to Gemfile.lock
Carl Lerche authored
78 attr_writer :ui, :bundle_path
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
79
80 def configure
81 @configured ||= begin
739c0f3 Install bundles to ~/.bundle by default
Carlhuda authored
82 configure_gem_home_and_path
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
83 true
84 end
85 end
434fb42 First pass at output
Carlhuda authored
86
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
87 def ui
88 @ui ||= UI.new
89 end
434fb42 First pass at output
Carlhuda authored
90
5ad1279 Add the ability to set bundle env settings in a .bundleconfig file
Carl Lerche authored
91 def bundle_path
5b2d02f Make bundle install [PATH] namespace its gems to specific rubies
Carlhuda authored
92 @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
93 end
94
5f26a03 Have bundler generate executable stubs into ~/.bundler/bin that will …
Carl Lerche authored
95 def bin_path
96 @bin_path ||= begin
25ab2dc Make generating bin stubs an option
Carl Lerche authored
97 path = settings[:bin] || "bin"
98 path = Pathname.new(path).expand_path(root)
0891a38 @spastorino Revert "Don't try to create dirs if they already exists"
spastorino authored
99 FileUtils.mkdir_p(path)
5f26a03 Have bundler generate executable stubs into ~/.bundler/bin that will …
Carl Lerche authored
100 Pathname.new(path).expand_path
101 end
102 end
103
1674aef No need to alias setup and require in Bundler
Carl Lerche authored
104 def setup(*groups)
5ff5cbc @indirect Tests and fix for Bundler.require removing gems from
indirect authored
105 # Just return if all groups are already loaded
106 return @setup if defined?(@setup)
2c8d6ae @indirect Don't call #setup after loading env.rb in Bundler.load
indirect authored
107
5dfc54c @indirect Don't call exit! if Bundler.setup has an exception
indirect authored
108 if groups.empty?
109 # Load all groups, but only once
110 @setup = load.setup
111 else
e2e60c2 @indirect clean up setup
indirect authored
112 @completed_groups ||= []
5dfc54c @indirect Don't call exit! if Bundler.setup has an exception
indirect authored
113 # Figure out which groups haven't been loaded yet
e2e60c2 @indirect clean up setup
indirect authored
114 unloaded = groups - @completed_groups
5dfc54c @indirect Don't call exit! if Bundler.setup has an exception
indirect authored
115 # Record groups that are now loaded
c3b93d3 @indirect Allow groups to be loaded again if they been cleared
indirect authored
116 @completed_groups = groups
5dfc54c @indirect Don't call exit! if Bundler.setup has an exception
indirect authored
117 # Load any groups that are not yet loaded
118 unloaded.any? ? load.setup(*unloaded) : load
4980111 @indirect Fix Bundler.setup so it can be called more than once safely
indirect authored
119 end
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
120 end
ce350cc Get a simple bbl install working
Carlhuda authored
121
1674aef No need to alias setup and require in Bundler
Carl Lerche authored
122 def require(*groups)
69acfd8 @indirect Call Bundler.setup from Bundler.require, only set up each group once
indirect authored
123 setup(*groups).require(*groups)
a8cbf77 @jeremy Group autorequire: pass :require => 'autorequire' option to gem depen…
jeremy authored
124 end
125
625818a @indirect Clean up bundler.rb a bit
indirect authored
126 def load
91c74f4 Bundle.load and Bundle.runtime are the same thing again.
Carl Lerche authored
127 @load ||= Runtime.new(root, definition)
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
128 end
67859e4 Moving in thor
Carlhuda authored
129
3687843 @kevmoo check only needs Environment (not Runtime)
kevmoo authored
130 def environment
131 Bundler::Environment.new(root, definition)
132 end
133
8a4dc7a Remove a little bit of crazy from Definition
Carl Lerche authored
134 def definition(unlock = nil)
135 @definition = nil if unlock
2b9094e Scope specs in the lock file by source
Carl Lerche authored
136 @definition ||= begin
137 configure
e0e79df @indirect Upgrade 0.9 lockfiles to 1.0 lockfiles in-place
indirect authored
138 upgrade_lockfile
251b9c7 Use the Gemfile's name as a base for Gemfile.lock
Carl Lerche authored
139 Definition.build(default_gemfile, default_lockfile, unlock)
2b9094e Scope specs in the lock file by source
Carl Lerche authored
140 end
ab5b1fc Add Bundler.flexdef, move locking into Environment, and lock from fle…
Carlhuda authored
141 end
142
eda7324 @wycats Git should never use sudo
wycats authored
143 def ruby_scope
5f4a8f3 Phase 1 of rubygems/bundler reintegration
Evan Phoenix authored
144 "#{Bundler.rubygems.ruby_engine}/#{Gem::ConfigMap[:ruby_version]}"
eda7324 @wycats Git should never use sudo
wycats authored
145 end
146
147 def user_bundle_path
5f4a8f3 Phase 1 of rubygems/bundler reintegration
Evan Phoenix authored
148 Pathname.new(Bundler.rubygems.user_home).join(".bundler")
eda7324 @wycats Git should never use sudo
wycats authored
149 end
150
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
151 def home
625818a @indirect Clean up bundler.rb a bit
indirect authored
152 bundle_path.join("bundler")
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
153 end
f31835e More work towards awesomeness
Carlhuda authored
154
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
155 def install_path
156 home.join("gems")
157 end
0d2492d Add more stuff for git
Carl Lerche authored
158
0d92de7 @indirect Add Bundler::Source::BundlerGems, to distingush from SystemGems.
indirect authored
159 def specs_path
160 bundle_path.join("specifications")
161 end
162
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
163 def cache
0d92de7 @indirect Add Bundler::Source::BundlerGems, to distingush from SystemGems.
indirect authored
164 bundle_path.join("cache/bundler")
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
165 end
ee0e2c1 Start working on the environment.rb lock file
Carl Lerche authored
166
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
167 def root
2d87c36 Move <root>/vendor/cache to a Bundler class method
Carl Lerche authored
168 default_gemfile.dirname.expand_path
169 end
170
27800e7 Provide an environment variable to allow customizing the location of …
Carl Lerche authored
171 def app_config_path
172 ENV['BUNDLE_APP_CONFIG'] ?
173 Pathname.new(ENV['BUNDLE_APP_CONFIG']).expand_path(root) :
174 root.join('.bundle')
175 end
176
2d87c36 Move <root>/vendor/cache to a Bundler class method
Carl Lerche authored
177 def app_cache
178 root.join("vendor/cache")
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
179 end
180
32a2eb2 First pass at getting bundler to play well when $GEM_HOME is owned by…
Carl Lerche authored
181 def tmp
7432798 @joshbuddy use Process.pid in the tmp directory
joshbuddy authored
182 user_bundle_path.join("tmp", Process.pid.to_s)
32a2eb2 First pass at getting bundler to play well when $GEM_HOME is owned by…
Carl Lerche authored
183 end
184
ea08895 Add the ability to specify a location with bundle install
Carl Lerche authored
185 def settings
27800e7 Provide an environment variable to allow customizing the location of …
Carl Lerche authored
186 @settings ||= Settings.new(app_config_path)
ea08895 Add the ability to specify a location with bundle install
Carl Lerche authored
187 end
188
5cf3fde @wuputah with_clean_env clears bundler env vars
wuputah authored
189 def with_original_env
33154fd @joshbuddy Add Bundler.with_clean_env for blocks of ruby without a bundled env
joshbuddy authored
190 bundled_env = ENV.to_hash
191 ENV.replace(ORIGINAL_ENV)
192 yield
193 ensure
194 ENV.replace(bundled_env.to_hash)
195 end
196
5cf3fde @wuputah with_clean_env clears bundler env vars
wuputah authored
197 def with_clean_env
198 with_original_env do
199 ENV.delete_if { |k,_| k[0,7] == 'BUNDLE_' }
200 yield
201 end
202 end
203
926836d @wuputah add Bundler.clean_system and Bundler.clean_exec
wuputah authored
204 def clean_system(*args)
205 with_clean_env { Kernel.system(*args) }
206 end
207
208 def clean_exec(*args)
209 with_clean_env { Kernel.exec(*args) }
210 end
211
fb1e725 Make bundler/setup something you can add to your .profile. To do this…
Carlhuda authored
212 def default_gemfile
213 SharedHelpers.default_gemfile
ee0e2c1 Start working on the environment.rb lock file
Carl Lerche authored
214 end
215
251b9c7 Use the Gemfile's name as a base for Gemfile.lock
Carl Lerche authored
216 def default_lockfile
217 SharedHelpers.default_lockfile
218 end
219
32a2eb2 First pass at getting bundler to play well when $GEM_HOME is owned by…
Carl Lerche authored
220 def requires_sudo?
8dfa734 @jackdempsey fixes 'instance variable @checked_for_sudo not initialized'
jackdempsey authored
221 return @requires_sudo if defined?(@checked_for_sudo) && @checked_for_sudo
47e08d4 @indirect Memoize Bundler#requires_sudo? (thanks @tmm1)
indirect authored
222
3f350e0 Add more sanity to the cases where bundler runs commands with sudo
Carlhuda authored
223 path = bundle_path
224 path = path.parent until path.exist?
7585837 @indirect fix checking for sudo, and use !(`which foo` rescue '').empty? everyw…
indirect authored
225 sudo_present = !(`which sudo` rescue '').empty?
d3291ee @hone require_sudo when Gem.bindir isn't writeable
hone authored
226 bin_dir = Pathname.new(Bundler.rubygems.gem_bindir)
227 bin_dir = bin_dir.parent until bin_dir.exist?
3f350e0 Add more sanity to the cases where bundler runs commands with sudo
Carlhuda authored
228
47e08d4 @indirect Memoize Bundler#requires_sudo? (thanks @tmm1)
indirect authored
229 @checked_for_sudo = true
d3291ee @hone require_sudo when Gem.bindir isn't writeable
hone authored
230 can_write_gems = !File.writable?(path) || !File.writable?(bin_dir)
231 @requires_sudo = settings.allow_sudo? && can_write_gems && sudo_present
3f350e0 Add more sanity to the cases where bundler runs commands with sudo
Carlhuda authored
232 end
233
234 def mkdir_p(path)
235 if requires_sudo?
5bad314 @spastorino Avoid calling mkdir with sudo when not needed, you don't want to be a…
spastorino authored
236 sudo "mkdir -p '#{path}'" unless File.exist?(path)
3f350e0 Add more sanity to the cases where bundler runs commands with sudo
Carlhuda authored
237 else
238 FileUtils.mkdir_p(path)
0891a38 @spastorino Revert "Don't try to create dirs if they already exists"
spastorino authored
239 end
3f350e0 Add more sanity to the cases where bundler runs commands with sudo
Carlhuda authored
240 end
241
242 def sudo(str)
c5f25d6 Remove sudo -E, which never actually worked for what we wanted, and d…
Carlhuda authored
243 `sudo -p 'Enter your password to install the bundled RubyGems to your system: ' #{str}`
32a2eb2 First pass at getting bundler to play well when $GEM_HOME is owned by…
Carl Lerche authored
244 end
245
94bad63 @wycats 1.8 doesn't support :mode
wycats authored
246 def read_file(file)
1837d67 @wycats Fix warnings in bundler
wycats authored
247 File.open(file, "rb") { |f| f.read }
94bad63 @wycats 1.8 doesn't support :mode
wycats authored
248 end
249
681a5cb @indirect Factor out Bundler.load_gemspec so Source::Path and GemHelper can use it
indirect authored
250 def load_gemspec(file)
251 path = Pathname.new(file)
252 # Eval the gemspec from its parent directory
c5af1b0 @indirect Stringify some paths for MacRuby
indirect authored
253 Dir.chdir(path.dirname.to_s) do
f0e9ca3 @sumbach Pass Gem::Specification.from_yaml a string containing the gemspec (in…
sumbach authored
254 contents = File.read(path.basename.to_s)
681a5cb @indirect Factor out Bundler.load_gemspec so Source::Path and GemHelper can use it
indirect authored
255 begin
f0e9ca3 @sumbach Pass Gem::Specification.from_yaml a string containing the gemspec (in…
sumbach authored
256 Gem::Specification.from_yaml(contents)
681a5cb @indirect Factor out Bundler.load_gemspec so Source::Path and GemHelper can use it
indirect authored
257 # Raises ArgumentError if the file is not valid YAML
258 rescue ArgumentError, SyntaxError, Gem::EndOfYAMLException, Gem::Exception
259 begin
f0e9ca3 @sumbach Pass Gem::Specification.from_yaml a string containing the gemspec (in…
sumbach authored
260 eval(contents, TOPLEVEL_BINDING, path.expand_path.to_s)
681a5cb @indirect Factor out Bundler.load_gemspec so Source::Path and GemHelper can use it
indirect authored
261 rescue LoadError => e
262 original_line = e.backtrace.find { |line| line.include?(path.to_s) }
263 msg = "There was a LoadError while evaluating #{path.basename}:\n #{e.message}"
264 msg << " from\n #{original_line}" if original_line
265 msg << "\n"
266
267 if RUBY_VERSION >= "1.9.0"
268 msg << "\nDoes it try to require a relative path? That doesn't work in Ruby 1.9."
269 end
270
271 raise GemspecError, msg
272 end
273 end
274 end
275 end
276
9ef6aa6 @indirect Disable rubygems more fully when unlocked
indirect authored
277 private
278
739c0f3 Install bundles to ~/.bundle by default
Carlhuda authored
279 def configure_gem_home_and_path
3d82929 Separate bundle install foo and bundle install --disable-shared-gems.
Carl Lerche authored
280 if settings[:disable_shared_gems]
739c0f3 Install bundles to ~/.bundle by default
Carlhuda authored
281 ENV['GEM_PATH'] = ''
9ef6aa6 @indirect Disable rubygems more fully when unlocked
indirect authored
282 ENV['GEM_HOME'] = File.expand_path(bundle_path, root)
5f4a8f3 Phase 1 of rubygems/bundler reintegration
Evan Phoenix authored
283 elsif Bundler.rubygems.gem_dir != bundle_path.to_s
284 possibles = [Bundler.rubygems.gem_dir, Bundler.rubygems.gem_path]
285 paths = possibles.flatten.compact.uniq.reject { |p| p.empty? }
55509f2 @indirect Ignore paths like GEM_HOME that are empty strings
indirect authored
286 ENV["GEM_PATH"] = paths.join(File::PATH_SEPARATOR)
739c0f3 Install bundles to ~/.bundle by default
Carlhuda authored
287 ENV["GEM_HOME"] = bundle_path.to_s
288 end
289
f43bfe6 @nicksieger Rescue from mkdir_p errors in configure_gem_home_and_path
nicksieger authored
290 # TODO: This mkdir_p is only needed for JRuby <= 1.5 and should go away (GH #602)
291 FileUtils.mkdir_p bundle_path.to_s rescue nil
292
5f4a8f3 Phase 1 of rubygems/bundler reintegration
Evan Phoenix authored
293 Bundler.rubygems.clear_paths
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
294 end
e0e79df @indirect Upgrade 0.9 lockfiles to 1.0 lockfiles in-place
indirect authored
295
296 def upgrade_lockfile
251b9c7 Use the Gemfile's name as a base for Gemfile.lock
Carl Lerche authored
297 lockfile = default_lockfile
e0e79df @indirect Upgrade 0.9 lockfiles to 1.0 lockfiles in-place
indirect authored
298 if lockfile.exist? && lockfile.read(3) == "---"
91c3beb @indirect Back to deleting old lockfiles for the beta release
indirect authored
299 Bundler.ui.warn "Detected Gemfile.lock generated by 0.9, deleting..."
300 lockfile.rmtree
e0e79df @indirect Upgrade 0.9 lockfiles to 1.0 lockfiles in-place
indirect authored
301 end
302 end
303
ee0e2c1 Start working on the environment.rb lock file
Carl Lerche authored
304 end
a8cbf77 @jeremy Group autorequire: pass :require => 'autorequire' option to gem depen…
jeremy authored
305 end
Something went wrong with that request. Please try again.