Skip to content
Newer
Older
100644 243 lines (202 sloc) 6.2 KB
63b636b First pass at gemfile pack
Carlhuda authored
1 require 'fileutils'
ce350cc Get a simple bbl install working
Carlhuda authored
2 require 'pathname'
88741e6 First pass at bbl lock
Carlhuda authored
3 require 'yaml'
820bb93 Rename rubygems-ext to rubygems_ext
Carl Lerche authored
4 require 'bundler/rubygems_ext'
1da7eb3 Don't generate bundler.gemspec anymore
Carlhuda authored
5 require 'bundler/version'
33154fd @joshbuddy Add Bundler.with_clean_env for blocks of ruby without a bundled env
joshbuddy authored
6
152a50a Rename gemfile back to bundler
Carl Lerche authored
7 module Bundler
33154fd @joshbuddy Add Bundler.with_clean_env for blocks of ruby without a bundled env
joshbuddy authored
8 ORIGINAL_ENV = ENV.to_hash
67859e4 Moving in thor
Carlhuda authored
9
152a50a Rename gemfile back to bundler
Carl Lerche authored
10 autoload :Definition, 'bundler/definition'
11 autoload :Dependency, 'bundler/dependency'
12 autoload :Dsl, 'bundler/dsl'
13 autoload :Environment, 'bundler/environment'
f414889 @kevmoo 'bundle viz'
kevmoo authored
14 autoload :Graph, 'bundler/graph'
152a50a Rename gemfile back to bundler
Carl Lerche authored
15 autoload :Index, 'bundler/index'
16 autoload :Installer, 'bundler/installer'
f779dee First pass at lockfile parser
Carlhuda authored
17 autoload :LazySpecification, 'bundler/lazy_specification'
ba579f4 Remove temporary flex stuff
Carlhuda authored
18 autoload :LockfileParser, 'bundler/lockfile_parser'
152a50a Rename gemfile back to bundler
Carl Lerche authored
19 autoload :RemoteSpecification, 'bundler/remote_specification'
20 autoload :Resolver, 'bundler/resolver'
c0f8641 Persist spec groups to the lockfile
Carl Lerche authored
21 autoload :Runtime, 'bundler/runtime'
ea08895 Add the ability to specify a location with bundle install
Carl Lerche authored
22 autoload :Settings, 'bundler/settings'
f7bfdde Actually disable system gems in .bundle/environment.rb
Carlhuda authored
23 autoload :SharedHelpers, 'bundler/shared_helpers'
529d792 Use tsort to order specifications. It makes teh crazy work.
Carl Lerche authored
24 autoload :SpecSet, 'bundler/spec_set'
152a50a Rename gemfile back to bundler
Carl Lerche authored
25 autoload :Source, 'bundler/source'
0f97e4f @indirect Gems from git need their full_gem_path fixed, even when locked
indirect authored
26 autoload :Specification, 'bundler/shared_helpers'
434fb42 First pass at output
Carlhuda authored
27 autoload :UI, 'bundler/ui'
67859e4 Moving in thor
Carlhuda authored
28
de5054a Rescue all Bundler exceptions and exit with appropriate error code
Carlhuda authored
29 class BundlerError < StandardError
30 def self.status_code(code = nil)
31 return @code unless code
32 @code = code
33 end
34
35 def status_code
36 self.class.status_code
37 end
38 end
39
5894862 Print useful warnings when deprecated options are used
Yehuda Katz authored
40 class GemfileNotFound < BundlerError; status_code(10) ; end
41 class GemNotFound < BundlerError; status_code(7) ; end
42 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
43 class PathError < BundlerError; status_code(13) ; end
5894862 Print useful warnings when deprecated options are used
Yehuda Katz authored
44 class GitError < BundlerError; status_code(11) ; end
6a82ed0 @indirect Add GemspecError so it can be raised
indirect authored
45 class GemspecError < BundlerError; status_code(14) ; end
5894862 Print useful warnings when deprecated options are used
Yehuda Katz authored
46 class DeprecatedMethod < BundlerError; status_code(12) ; end
47 class DeprecatedOption < BundlerError; status_code(12) ; end
2a24019 @indirect Print a useful error if a gemspec require fails
indirect authored
48 class GemspecError < BundlerError; status_code(14) ; end
7514b20 @wycats If an option is invalid, don't fail silently
wycats authored
49 class InvalidOption < BundlerError; status_code(15) ; end
67859e4 Moving in thor
Carlhuda authored
50
3edfddb Hacked together some crap that doesn't really work
Carl Lerche authored
51 class VersionConflict < BundlerError
52 attr_reader :conflicts
53
54 def initialize(conflicts, msg = nil)
55 super(msg)
56 @conflicts = conflicts
57 end
58
59 status_code(6)
60 end
61
cf736cf Use the Lockfile's specs as LazySpecifications instead of converting …
Carl Lerche authored
62 # Internal errors, should be rescued
63 class InvalidSpecSet < StandardError; end
64
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
65 class << self
78a6b48 Rename vendor/lock.yml to Gemfile.lock
Carl Lerche authored
66 attr_writer :ui, :bundle_path
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
67
68 def configure
69 @configured ||= begin
739c0f3 Install bundles to ~/.bundle by default
Carlhuda authored
70 configure_gem_home_and_path
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
71 true
72 end
73 end
434fb42 First pass at output
Carlhuda authored
74
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
75 def ui
76 @ui ||= UI.new
77 end
434fb42 First pass at output
Carlhuda authored
78
5ad1279 Add the ability to set bundle env settings in a .bundleconfig file
Carl Lerche authored
79 def bundle_path
5b2d02f Make bundle install [PATH] namespace its gems to specific rubies
Carlhuda authored
80 # STDERR.puts settings.path
81 @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
82 end
83
5f26a03 Have bundler generate executable stubs into ~/.bundler/bin that will …
Carl Lerche authored
84 def bin_path
85 @bin_path ||= begin
ce7db1b Go back to generating ./bin/gem_bin_stub
Carl Lerche authored
86 path = settings[:bin] || "#{root}/bin"
5f26a03 Have bundler generate executable stubs into ~/.bundler/bin that will …
Carl Lerche authored
87 FileUtils.mkdir_p(path)
88 Pathname.new(path).expand_path
89 end
90 end
91
1674aef No need to alias setup and require in Bundler
Carl Lerche authored
92 def setup(*groups)
9cd1836 @lenary avoid warning: instance variable @setup not initialized
lenary authored
93 return @setup if defined?(@setup) && @setup
2c8d6ae @indirect Don't call #setup after loading env.rb in Bundler.load
indirect authored
94
5dfc54c @indirect Don't call exit! if Bundler.setup has an exception
indirect authored
95 if groups.empty?
96 # Load all groups, but only once
97 @setup = load.setup
98 else
99 # Figure out which groups haven't been loaded yet
100 unloaded = groups - (@completed_groups || [])
101 # Record groups that are now loaded
102 @completed_groups = groups | (@completed_groups || [])
103 # Load any groups that are not yet loaded
104 unloaded.any? ? load.setup(*unloaded) : load
4980111 @indirect Fix Bundler.setup so it can be called more than once safely
indirect authored
105 end
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
106 end
ce350cc Get a simple bbl install working
Carlhuda authored
107
1674aef No need to alias setup and require in Bundler
Carl Lerche authored
108 def require(*groups)
69acfd8 @indirect Call Bundler.setup from Bundler.require, only set up each group once
indirect authored
109 setup(*groups).require(*groups)
a8cbf77 @jeremy Group autorequire: pass :require => 'autorequire' option to gem depen…
jeremy authored
110 end
111
625818a @indirect Clean up bundler.rb a bit
indirect authored
112 def load
91c74f4 Bundle.load and Bundle.runtime are the same thing again.
Carl Lerche authored
113 @load ||= Runtime.new(root, definition)
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
114 end
67859e4 Moving in thor
Carlhuda authored
115
3687843 @kevmoo check only needs Environment (not Runtime)
kevmoo authored
116 def environment
117 Bundler::Environment.new(root, definition)
118 end
119
8a4dc7a Remove a little bit of crazy from Definition
Carl Lerche authored
120 def definition(unlock = nil)
121 @definition = nil if unlock
2b9094e Scope specs in the lock file by source
Carl Lerche authored
122 @definition ||= begin
123 configure
e0e79df @indirect Upgrade 0.9 lockfiles to 1.0 lockfiles in-place
indirect authored
124 upgrade_lockfile
2b9094e Scope specs in the lock file by source
Carl Lerche authored
125 lockfile = root.join("Gemfile.lock")
8a4dc7a Remove a little bit of crazy from Definition
Carl Lerche authored
126 Definition.build(default_gemfile, lockfile, unlock)
2b9094e Scope specs in the lock file by source
Carl Lerche authored
127 end
ab5b1fc Add Bundler.flexdef, move locking into Environment, and lock from fle…
Carlhuda authored
128 end
129
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
130 def home
625818a @indirect Clean up bundler.rb a bit
indirect authored
131 bundle_path.join("bundler")
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
132 end
f31835e More work towards awesomeness
Carlhuda authored
133
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
134 def install_path
135 home.join("gems")
136 end
0d2492d Add more stuff for git
Carl Lerche authored
137
0d92de7 @indirect Add Bundler::Source::BundlerGems, to distingush from SystemGems.
indirect authored
138 def specs_path
139 bundle_path.join("specifications")
140 end
141
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
142 def cache
0d92de7 @indirect Add Bundler::Source::BundlerGems, to distingush from SystemGems.
indirect authored
143 bundle_path.join("cache/bundler")
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
144 end
ee0e2c1 Start working on the environment.rb lock file
Carl Lerche authored
145
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
146 def root
2d87c36 Move <root>/vendor/cache to a Bundler class method
Carl Lerche authored
147 default_gemfile.dirname.expand_path
148 end
149
150 def app_cache
151 root.join("vendor/cache")
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
152 end
153
32a2eb2 First pass at getting bundler to play well when $GEM_HOME is owned by…
Carl Lerche authored
154 def tmp
155 "#{Gem.user_home}/.bundler/tmp"
156 end
157
ea08895 Add the ability to specify a location with bundle install
Carl Lerche authored
158 def settings
159 @settings ||= Settings.new(root)
160 end
161
33154fd @joshbuddy Add Bundler.with_clean_env for blocks of ruby without a bundled env
joshbuddy authored
162 def with_clean_env
163 bundled_env = ENV.to_hash
164 ENV.replace(ORIGINAL_ENV)
165 yield
166 ensure
167 ENV.replace(bundled_env.to_hash)
168 end
169
fb1e725 Make bundler/setup something you can add to your .profile. To do this…
Carlhuda authored
170 def default_gemfile
171 SharedHelpers.default_gemfile
ee0e2c1 Start working on the environment.rb lock file
Carl Lerche authored
172 end
173
16259ea @wycats Improve sudo support
wycats authored
174 WINDOWS = Config::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw)!
175 NULL = WINDOWS ? "NUL" : "/dev/null"
176
32a2eb2 First pass at getting bundler to play well when $GEM_HOME is owned by…
Carl Lerche authored
177 def requires_sudo?
3f350e0 Add more sanity to the cases where bundler runs commands with sudo
Carlhuda authored
178 path = bundle_path
179 path = path.parent until path.exist?
180
32a2eb2 First pass at getting bundler to play well when $GEM_HOME is owned by…
Carl Lerche authored
181 case
3f350e0 Add more sanity to the cases where bundler runs commands with sudo
Carlhuda authored
182 when File.writable?(path) ||
16259ea @wycats Improve sudo support
wycats authored
183 `which sudo 2>#{NULL}`.empty? ||
3f350e0 Add more sanity to the cases where bundler runs commands with sudo
Carlhuda authored
184 File.owned?(path)
32a2eb2 First pass at getting bundler to play well when $GEM_HOME is owned by…
Carl Lerche authored
185 false
186 else
187 true
188 end
3f350e0 Add more sanity to the cases where bundler runs commands with sudo
Carlhuda authored
189 end
190
191 def mkdir_p(path)
192 if requires_sudo?
193 sudo "mkdir -p '#{path}'"
194 else
195 FileUtils.mkdir_p(path)
196 end
197 end
198
199 def sudo(str)
200 `sudo -p 'Enter your password to install the bundled RubyGems to your system: ' -E #{str}`
32a2eb2 First pass at getting bundler to play well when $GEM_HOME is owned by…
Carl Lerche authored
201 end
202
9ef6aa6 @indirect Disable rubygems more fully when unlocked
indirect authored
203 private
204
739c0f3 Install bundles to ~/.bundle by default
Carlhuda authored
205 def configure_gem_home_and_path
3d82929 Separate bundle install foo and bundle install --disable-shared-gems.
Carl Lerche authored
206 if settings[:disable_shared_gems]
739c0f3 Install bundles to ~/.bundle by default
Carlhuda authored
207 ENV['GEM_PATH'] = ''
9ef6aa6 @indirect Disable rubygems more fully when unlocked
indirect authored
208 ENV['GEM_HOME'] = File.expand_path(bundle_path, root)
739c0f3 Install bundles to ~/.bundle by default
Carlhuda authored
209 else
7a7628c @indirect Don't duplicate gem paths
indirect authored
210 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
211 ENV["GEM_PATH"] = paths.join(File::PATH_SEPARATOR)
739c0f3 Install bundles to ~/.bundle by default
Carlhuda authored
212 ENV["GEM_HOME"] = bundle_path.to_s
213 end
214
bc310f7 First pass at being able to set the bundle install path.
Carl Lerche authored
215 Gem.clear_paths
216 end
e0e79df @indirect Upgrade 0.9 lockfiles to 1.0 lockfiles in-place
indirect authored
217
218 def upgrade_lockfile
219 lockfile = root.join("Gemfile.lock")
220 if lockfile.exist? && lockfile.read(3) == "---"
91c3beb @indirect Back to deleting old lockfiles for the beta release
indirect authored
221 Bundler.ui.warn "Detected Gemfile.lock generated by 0.9, deleting..."
222 lockfile.rmtree
223 # lock = YAML.load_file(lockfile)
224 #
225 # source_uris = lock["sources"].map{|s| s["Rubygems"]["uri"] }
226 # sources = [Bundler::Source::Rubygems.new({"remotes" => source_uris})]
227 #
228 # deps = lock["dependencies"].map do |name, opts|
229 # version = opts.delete("version")
230 # Bundler::Dependency.new(name, version, opts)
231 # end
232 #
233 # definition = Bundler::Definition.new(nil, deps, sources, {})
234 #
235 # File.open(lockfile, 'w') do |f|
236 # f.write definition.to_lock
237 # end
e0e79df @indirect Upgrade 0.9 lockfiles to 1.0 lockfiles in-place
indirect authored
238 end
239 end
240
ee0e2c1 Start working on the environment.rb lock file
Carl Lerche authored
241 end
a8cbf77 @jeremy Group autorequire: pass :require => 'autorequire' option to gem depen…
jeremy authored
242 end
Something went wrong with that request. Please try again.