Skip to content

HTTPS clone URL

Subversion checkout URL

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