bundler 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bundler might be problematic. Click here for more details.

@@ -4,7 +4,7 @@ require 'yaml'
4
4
  require 'bundler/rubygems'
5
5
 
6
6
  module Bundler
7
- VERSION = "0.9.2"
7
+ VERSION = "0.9.3"
8
8
 
9
9
  autoload :Definition, 'bundler/definition'
10
10
  autoload :Dependency, 'bundler/dependency'
@@ -106,9 +106,11 @@ module Bundler
106
106
  @settings ||= Settings.new(root)
107
107
  end
108
108
 
109
- private
110
-
111
109
  def default_gemfile
110
+ if ENV['BUNDLE_GEMFILE']
111
+ return Pathname.new(ENV['BUNDLE_GEMFILE'])
112
+ end
113
+
112
114
  current = Pathname.new(Dir.pwd)
113
115
 
114
116
  until current.root?
@@ -120,6 +122,8 @@ module Bundler
120
122
  raise GemfileNotFound, "The default Gemfile was not found"
121
123
  end
122
124
 
125
+ private
126
+
123
127
  def configure_gem_home_and_path
124
128
  if path = settings[:path]
125
129
  ENV['GEM_HOME'] = File.expand_path(path, root)
@@ -93,11 +93,22 @@ module Bundler
93
93
  desc "exec", "Run the command in context of the bundle"
94
94
  def exec(*)
95
95
  ARGV.delete('exec')
96
- ENV["RUBYOPT"] = %W(
97
- -I#{File.expand_path('../..', __FILE__)}
98
- -rbundler/setup
99
- #{ENV["RUBYOPT"]}
100
- ).compact.join(' ')
96
+
97
+ # Set PATH
98
+ paths = (ENV['PATH'] || "").split(File::PATH_SEPARATOR)
99
+ paths.unshift "#{Bundler.bundle_path}/bin"
100
+ ENV["PATH"] = paths.uniq.join(File::PATH_SEPARATOR)
101
+
102
+ # Set BUNDLE_GEMFILE
103
+ ENV['BUNDLE_GEMFILE'] = Bundler.default_gemfile
104
+
105
+ # Set RUBYOPT
106
+ rubyopt = [ENV["RUBYOPT"]].compact
107
+ rubyopt.unshift "-rbundler/setup"
108
+ rubyopt.unshift "-I#{File.expand_path('../..', __FILE__)}"
109
+ ENV["RUBYOPT"] = rubyopt.join(' ')
110
+
111
+ # Run
101
112
  Kernel.exec *ARGV
102
113
  end
103
114
 
@@ -19,7 +19,7 @@ module Bundler
19
19
  # TODO: Switch to using equivalent?
20
20
  hash = Digest::SHA1.hexdigest(File.read("#{Bundler.root}/Gemfile"))
21
21
  unless locked_definition.hash == hash
22
- raise GemfileError, "You changed your Gemfile after locking. Please relock using `gem lock`"
22
+ raise GemfileError, "You changed your Gemfile after locking. Please relock using `bundle lock`"
23
23
  end
24
24
 
25
25
  locked_definition
@@ -21,7 +21,9 @@ module Bundler
21
21
  Bundler.ui.debug " * Not in requested group; skipping."
22
22
  next
23
23
  end
24
+
24
25
  spec.source.install(spec)
26
+
25
27
  Bundler.ui.info ""
26
28
  end
27
29
 
@@ -148,8 +148,23 @@ module Bundler
148
148
 
149
149
  if matching_versions.empty?
150
150
  if current.required_by.empty?
151
+ if current.source
152
+ name = current.name
153
+ versions = @source_requirements[name][name].map { |s| s.version }
154
+ message = "Could not find gem '#{current}' in #{current.source}.\n"
155
+ if versions.any?
156
+ message << "Source contains '#{current.name}' at: #{versions.join(', ')}"
157
+ else
158
+ message << "Source does not contain any versions of '#{current}'"
159
+ end
160
+
161
+ raise GemNotFound, message
162
+ else
163
+ raise GemNotFound, "Could not find gem '#{current}' in any of the sources."
164
+ end
151
165
  location = current.source ? current.source.to_s : "any of the sources"
152
- raise GemNotFound, "Could not find gem '#{current}' in #{location}"
166
+ raise GemNotFound, "Could not find gem '#{current}' in #{location}.\n" \
167
+ "Source contains fo"
153
168
  else
154
169
  @errors[current.name] = [nil, current]
155
170
  end
@@ -1,13 +1,17 @@
1
- require "digest/md5"
1
+ require "digest/sha1"
2
2
 
3
3
  module Bundler
4
4
  class Runtime < Environment
5
5
  def setup(*groups)
6
6
  # Has to happen first
7
- cripple_rubygems
7
+ clean_load_path
8
+
9
+ specs = specs_for(*groups)
10
+
11
+ cripple_rubygems(specs)
8
12
 
9
13
  # Activate the specs
10
- specs_for(*groups).each do |spec|
14
+ specs.each do |spec|
11
15
  Gem.loaded_specs[spec.name] = spec
12
16
  $LOAD_PATH.unshift(*spec.load_paths)
13
17
  end
@@ -118,32 +122,6 @@ module Bundler
118
122
  specs.map { |s| s.load_paths }.flatten
119
123
  end
120
124
 
121
- def cripple_rubygems
122
- # handle 1.9 where system gems are always on the load path
123
- if defined?(::Gem)
124
- me = File.expand_path("../../", __FILE__)
125
- $LOAD_PATH.reject! do |p|
126
- p != File.dirname(__FILE__) &&
127
- Gem.path.any? { |gp| p.include?(gp) }
128
- end
129
- $LOAD_PATH.unshift me
130
- $LOAD_PATH.uniq!
131
- end
132
-
133
- # Disable rubygems' gem activation system
134
- ::Kernel.class_eval do
135
- if private_method_defined?(:gem_original_require)
136
- alias rubygems_require require
137
- alias require gem_original_require
138
- end
139
-
140
- undef gem
141
- def gem(*)
142
- # Silently ignore calls to gem
143
- end
144
- end
145
- end
146
-
147
125
  def write_rb_lock
148
126
  template = File.read(File.expand_path("../templates/environment.erb", __FILE__))
149
127
  erb = ERB.new(template, nil, '-')
@@ -161,7 +139,7 @@ module Bundler
161
139
 
162
140
  def details
163
141
  details = {}
164
- details["hash"] = Digest::SHA1.hexdigest(File.read("#{root}/Gemfile"))
142
+ details["hash"] = gemfile_fingerprint
165
143
  details["sources"] = sources.map { |s| { s.class.name.split("::").last => s.options} }
166
144
 
167
145
  details["specs"] = specs.map do |s|
@@ -174,6 +152,10 @@ module Bundler
174
152
  details
175
153
  end
176
154
 
155
+ def gemfile_fingerprint
156
+ Digest::SHA1.hexdigest(File.read("#{root}/Gemfile"))
157
+ end
158
+
177
159
  def autorequires_for_groups(*groups)
178
160
  autorequires = Hash.new { |h,k| h[k] = [] }
179
161
  @definition.dependencies.each do |dep|
@@ -188,5 +170,92 @@ module Bundler
188
170
  groups.inject({}) { |h,g| h[g] = autorequires[g]; h }
189
171
  end
190
172
  end
173
+
174
+ def clean_load_path
175
+ # handle 1.9 where system gems are always on the load path
176
+ if defined?(::Gem)
177
+ me = File.expand_path("../../", __FILE__)
178
+ $LOAD_PATH.reject! do |p|
179
+ p != File.dirname(__FILE__) &&
180
+ Gem.path.any? { |gp| p.include?(gp) }
181
+ end
182
+ $LOAD_PATH.unshift me
183
+ $LOAD_PATH.uniq!
184
+ end
185
+ end
186
+
187
+ def reverse_rubygems_kernel_mixin
188
+ # Disable rubygems' gem activation system
189
+ ::Kernel.class_eval do
190
+ if private_method_defined?(:gem_original_require)
191
+ alias rubygems_require require
192
+ alias require gem_original_require
193
+ end
194
+
195
+ undef gem
196
+ end
197
+ end
198
+
199
+ def cripple_rubygems(specs)
200
+ reverse_rubygems_kernel_mixin
201
+
202
+ executables = specs.map { |s| s.executables }.flatten
203
+
204
+ ::Kernel.send(:define_method, :gem) do |dep, *reqs|
205
+ if executables.include? File.basename(caller.first.split(':').first)
206
+ return
207
+ end
208
+ opts = reqs.last.is_a?(Hash) ? reqs.pop : {}
209
+
210
+ unless dep.respond_to?(:name) && dep.respond_to?(:version_requirements)
211
+ dep = Gem::Dependency.new(dep, reqs)
212
+ end
213
+
214
+ spec = specs.find { |s| s.name == dep.name }
215
+
216
+ if spec.nil?
217
+ e = Gem::LoadError.new "#{dep} is not part of the bundle. Add it to Gemfile."
218
+ e.name = dep.name
219
+ e.version_requirement = dep.version_requirements
220
+ raise e
221
+ elsif dep !~ spec
222
+ e = Gem::LoadError.new "can't activate #{dep}, already activated #{spec.full_name}. " \
223
+ "Make sure all dependencies are added to Gemfile."
224
+ e.name = dep.name
225
+ e.version_requirement = dep.version_requirements
226
+ raise e
227
+ end
228
+
229
+ true
230
+ end
231
+
232
+ # === Following hacks are to improve on the generated bin wrappers ===
233
+
234
+ # Yeah, talk about a hack
235
+ source_index_class = (class << Gem::SourceIndex ; self ; end)
236
+ source_index_class.send(:define_method, :from_gems_in) do |*args|
237
+ source_index = Gem::SourceIndex.new
238
+ source_index.add_specs *specs
239
+ source_index
240
+ end
241
+
242
+ # OMG more hacks
243
+ gem_class = (class << Gem ; self ; end)
244
+ gem_class.send(:define_method, :bin_path) do |name, *args|
245
+ exec_name, *reqs = args
246
+
247
+ spec = nil
248
+
249
+ if exec_name
250
+ spec = specs.find { |s| s.executables.include?(exec_name) }
251
+ spec or raise Gem::Exception, "can't find executable #{exec_name}"
252
+ else
253
+ spec = specs.find { |s| s.name == name }
254
+ exec_name = spec.default_executable or raise Gem::Exception, "no default executable for #{spec.full_name}"
255
+ end
256
+
257
+ File.join(spec.full_gem_path, spec.bindir, exec_name)
258
+ end
259
+ end
191
260
  end
192
261
  end
@@ -30,8 +30,11 @@ module Bundler
30
30
  gem_path = Gem::RemoteFetcher.fetcher.download(spec, uri, destination)
31
31
  Bundler.ui.debug " * Installing"
32
32
  installer = Gem::Installer.new gem_path,
33
- :install_dir => Gem.dir,
34
- :ignore_dependencies => true
33
+ :install_dir => Gem.dir,
34
+ :ignore_dependencies => true,
35
+ :wrappers => true,
36
+ :env_shebang => true,
37
+ :bin_dir => "#{Gem.dir}/bin"
35
38
 
36
39
  installer.install
37
40
  end
@@ -115,8 +118,11 @@ module Bundler
115
118
 
116
119
  Bundler.ui.debug " * Installing from pack"
117
120
  installer = Gem::Installer.new "#{@path}/#{spec.full_name}.gem",
118
- :install_dir => Gem.dir,
119
- :ignore_dependencies => true
121
+ :install_dir => Gem.dir,
122
+ :ignore_dependencies => true,
123
+ :wrappers => true,
124
+ :env_shebang => true,
125
+ :bin_dir => "#{Gem.dir}/bin"
120
126
 
121
127
  installer.install
122
128
  end
@@ -173,10 +179,29 @@ module Bundler
173
179
 
174
180
  def install(spec)
175
181
  Bundler.ui.debug " * Using path #{path}"
182
+ generate_bin(spec)
176
183
  end
177
184
 
178
185
  alias specs local_specs
179
186
 
187
+ private
188
+
189
+ def generate_bin(spec)
190
+ # HAX -- Generate the bin
191
+ bin_dir = "#{Gem.dir}/bin"
192
+ gem_dir = spec.full_gem_path
193
+ installer = Gem::Installer.allocate
194
+ installer.instance_eval do
195
+ @spec = spec
196
+ @bin_dir = bin_dir
197
+ @gem_dir = gem_dir
198
+ @wrappers = true
199
+ @env_shebang = false
200
+ @format_executable = false
201
+ end
202
+ installer.generate_bin
203
+ end
204
+
180
205
  end
181
206
 
182
207
  class Git < Path
@@ -238,6 +263,7 @@ module Bundler
238
263
  checkout
239
264
  @installed = true
240
265
  end
266
+ generate_bin(spec)
241
267
  end
242
268
 
243
269
  def lock
@@ -1,16 +1,27 @@
1
+ require 'digest/sha1'
2
+
1
3
  # DO NOT MODIFY THIS FILE
2
4
  module Bundler
5
+ FINGERPRINT = <%= gemfile_fingerprint.inspect %>
3
6
  LOAD_PATHS = <%= load_paths.inspect %>
4
7
  AUTOREQUIRES = <%= autorequires_for_groups.inspect %>
5
8
 
9
+ def self.match_fingerprint
10
+ print = Digest::SHA1.hexdigest(File.read(File.expand_path('../../Gemfile', __FILE__)))
11
+ unless print == FINGERPRINT
12
+ abort 'Gemfile changed since you last locked. Please `bundle lock` to relock.'
13
+ end
14
+ end
15
+
6
16
  def self.setup(*groups)
17
+ match_fingerprint
7
18
  LOAD_PATHS.each { |path| $LOAD_PATH.unshift path }
8
19
  end
9
20
 
10
21
  def self.require(*groups)
11
22
  groups = [:default] if groups.empty?
12
23
  groups.each do |group|
13
- AUTOREQUIRES[group].each { |file| Kernel.require file }
24
+ (AUTOREQUIRES[group] || []).each { |file| Kernel.require file }
14
25
  end
15
26
  end
16
27
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Lerche
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-02-04 00:00:00 -08:00
13
+ date: 2010-02-05 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies: []
16
16