Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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