bundler 1.1.pre.1 → 1.1.pre.2

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.

@@ -16,7 +16,7 @@ module Bundler
16
16
  end
17
17
 
18
18
  def delete(key)
19
- @local_config
19
+ @local_config.delete(key_for(key))
20
20
  end
21
21
 
22
22
  def set_global(key, value)
@@ -79,7 +79,7 @@ module Bundler
79
79
  if path = self[:path]
80
80
  "#{path}/#{Bundler.ruby_scope}"
81
81
  else
82
- Gem.dir
82
+ Bundler.rubygems.gem_dir
83
83
  end
84
84
  end
85
85
 
@@ -106,7 +106,7 @@ module Bundler
106
106
  end
107
107
 
108
108
  def global_config_file
109
- file = ENV["BUNDLE_CONFIG"] || File.join(Gem.user_home, ".bundle/config")
109
+ file = ENV["BUNDLE_CONFIG"] || File.join(Bundler.rubygems.user_home, ".bundle/config")
110
110
  Pathname.new(file)
111
111
  end
112
112
 
@@ -1,6 +1,9 @@
1
1
  require 'pathname'
2
2
  require 'rubygems'
3
- Gem.source_index # ensure Rubygems is fully loaded in Ruby 1.9
3
+
4
+ require 'bundler/rubygems_integration'
5
+
6
+ Bundler.rubygems.fully_load!
4
7
 
5
8
  module Gem
6
9
  class Dependency
@@ -59,109 +62,12 @@ module Bundler
59
62
  $LOAD_PATH.reject! do |p|
60
63
  next if File.expand_path(p) =~ /^#{me}/
61
64
  p != File.dirname(__FILE__) &&
62
- Gem.path.any?{|gp| p =~ /^#{gp}/ }
65
+ Bundler.rubygems.gem_path.any?{|gp| p =~ /^#{gp}/ }
63
66
  end
64
67
  $LOAD_PATH.uniq!
65
68
  end
66
69
  end
67
70
 
68
- def reverse_rubygems_kernel_mixin
69
- # Disable rubygems' gem activation system
70
- ::Kernel.class_eval do
71
- if private_method_defined?(:gem_original_require)
72
- alias rubygems_require require
73
- alias require gem_original_require
74
- end
75
-
76
- undef gem
77
- end
78
- end
79
-
80
- def cripple_rubygems(specs)
81
- reverse_rubygems_kernel_mixin
82
-
83
- executables = specs.map { |s| s.executables }.flatten
84
- Gem.source_index # ensure RubyGems is fully loaded
85
-
86
- ::Kernel.send(:define_method, :gem) do |dep, *reqs|
87
- if executables.include? File.basename(caller.first.split(':').first)
88
- return
89
- end
90
- opts = reqs.last.is_a?(Hash) ? reqs.pop : {}
91
-
92
- unless dep.respond_to?(:name) && dep.respond_to?(:requirement)
93
- dep = Gem::Dependency.new(dep, reqs)
94
- end
95
-
96
- spec = specs.find { |s| s.name == dep.name }
97
-
98
- if spec.nil?
99
-
100
- e = Gem::LoadError.new "#{dep.name} is not part of the bundle. Add it to Gemfile."
101
- e.name = dep.name
102
- if e.respond_to?(:requirement=)
103
- e.requirement = dep.requirement
104
- else
105
- e.version_requirement = dep.requirement
106
- end
107
- raise e
108
- elsif dep !~ spec
109
- e = Gem::LoadError.new "can't activate #{dep}, already activated #{spec.full_name}. " \
110
- "Make sure all dependencies are added to Gemfile."
111
- e.name = dep.name
112
- if e.respond_to?(:requirement=)
113
- e.requirement = dep.requirement
114
- else
115
- e.version_requirement = dep.requirement
116
- end
117
- raise e
118
- end
119
-
120
- true
121
- end
122
-
123
- # === Following hacks are to improve on the generated bin wrappers ===
124
-
125
- # Yeah, talk about a hack
126
- source_index_class = (class << Gem::SourceIndex ; self ; end)
127
- source_index_class.send(:remove_method, :from_gems_in)
128
- source_index_class.send(:define_method, :from_gems_in) do |*args|
129
- source_index = Gem::SourceIndex.new
130
- source_index.spec_dirs = *args
131
- source_index.add_specs(*specs)
132
- source_index
133
- end
134
-
135
- # OMG more hacks
136
- gem_class = (class << Gem ; self ; end)
137
- gem_class.send(:remove_method, :refresh)
138
- gem_class.send(:define_method, :refresh) { }
139
- gem_class.send(:remove_method, :bin_path)
140
- gem_class.send(:define_method, :bin_path) do |name, *args|
141
- exec_name, *reqs = args
142
-
143
- if exec_name == 'bundle'
144
- return ENV['BUNDLE_BIN_PATH']
145
- end
146
-
147
- spec = nil
148
-
149
- if exec_name
150
- spec = specs.find { |s| s.executables.include?(exec_name) }
151
- spec or raise Gem::Exception, "can't find executable #{exec_name}"
152
- else
153
- spec = specs.find { |s| s.name == name }
154
- exec_name = spec.default_executable or raise Gem::Exception, "no default executable for #{spec.full_name}"
155
- end
156
-
157
- gem_bin = File.join(spec.full_gem_path, spec.bindir, exec_name)
158
- gem_from_path_bin = File.join(File.dirname(spec.loaded_from), spec.bindir, exec_name)
159
- File.exist?(gem_bin) ? gem_bin : gem_from_path_bin
160
- end
161
-
162
- Gem.clear_paths
163
- end
164
-
165
71
  extend self
166
72
  end
167
73
  end
@@ -19,7 +19,9 @@ module Bundler
19
19
  @allow_remote = false
20
20
  @allow_cached = false
21
21
 
22
- @caches = [ Bundler.app_cache ] + Gem.path.map{ |p| File.expand_path("#{p}/cache") }
22
+ @caches = [ Bundler.app_cache ]
23
+ @caches << Bundler.rubygems.gem_path.map{|p| File.expand_path("#{p}/cache") }
24
+
23
25
  @spec_fetch_map = {}
24
26
  end
25
27
 
@@ -71,7 +73,7 @@ module Bundler
71
73
  spec, uri = @spec_fetch_map[spec.full_name]
72
74
  if spec
73
75
  path = download_gem_from_uri(spec, uri)
74
- s = Gem::Format.from_file_by_path(path).spec
76
+ s = Bundler.rubygems.spec_from_gem(path)
75
77
  spec.__swap__(s)
76
78
  end
77
79
  end
@@ -86,7 +88,7 @@ module Bundler
86
88
 
87
89
  Bundler.ui.info "Installing #{spec.name} (#{spec.version}) "
88
90
 
89
- install_path = Bundler.requires_sudo? ? Bundler.tmp : Gem.dir
91
+ install_path = Bundler.requires_sudo? ? Bundler.tmp : Bundler.rubygems.gem_dir
90
92
  options = { :install_dir => install_path,
91
93
  :ignore_dependencies => true,
92
94
  :wrappers => true,
@@ -98,16 +100,16 @@ module Bundler
98
100
 
99
101
  # SUDO HAX
100
102
  if Bundler.requires_sudo?
101
- sudo "mkdir -p #{Gem.dir}/gems #{Gem.dir}/specifications"
102
- sudo "cp -R #{Bundler.tmp}/gems/#{spec.full_name} #{Gem.dir}/gems/"
103
- sudo "cp -R #{Bundler.tmp}/specifications/#{spec.full_name}.gemspec #{Gem.dir}/specifications/"
103
+ sudo "mkdir -p #{Bundler.rubygems.gem_dir}/gems #{Bundler.rubygems.gem_dir}/specifications"
104
+ sudo "cp -R #{Bundler.tmp}/gems/#{spec.full_name} #{Bundler.rubygems.gem_dir}/gems/"
105
+ sudo "cp -R #{Bundler.tmp}/specifications/#{spec.full_name}.gemspec #{Bundler.rubygems.gem_dir}/specifications/"
104
106
  spec.executables.each do |exe|
105
- sudo "mkdir -p #{Gem.bindir}"
106
- sudo "cp -R #{Bundler.tmp}/bin/#{exe} #{Gem.bindir}"
107
+ sudo "mkdir -p #{Bundler.rubygems.bindir}"
108
+ sudo "cp -R #{Bundler.tmp}/bin/#{exe} #{Bundler.rubygems.gem_bindir}"
107
109
  end
108
110
  end
109
111
 
110
- spec.loaded_from = "#{Gem.dir}/specifications/#{spec.full_name}.gemspec"
112
+ spec.loaded_from = "#{Bundler.rubygems.gem_dir}/specifications/#{spec.full_name}.gemspec"
111
113
  end
112
114
 
113
115
  def sudo(str)
@@ -160,7 +162,7 @@ module Bundler
160
162
  @installed_specs ||= begin
161
163
  idx = Index.new
162
164
  have_bundler = false
163
- Gem.source_index.to_a.reverse.each do |dont_use_this_var, spec|
165
+ Bundler.rubygems.all_specs.reverse.each do |spec|
164
166
  next if spec.name == 'bundler' && spec.version.to_s != VERSION
165
167
  have_bundler = true if spec.name == 'bundler'
166
168
  spec.source = self
@@ -194,7 +196,7 @@ module Bundler
194
196
  next if gemfile =~ /bundler\-[\d\.]+?\.gem/
195
197
 
196
198
  begin
197
- s ||= Gem::Format.from_file_by_path(gemfile).spec
199
+ s ||= Bundler.rubygems.spec_from_gem(gemfile)
198
200
  rescue Gem::Package::FormatError
199
201
  raise GemspecError, "Could not read gem at #{gemfile}. It may be corrupted."
200
202
  end
@@ -210,7 +212,7 @@ module Bundler
210
212
  def remote_specs(dependencies = nil)
211
213
  @remote_specs ||= begin
212
214
  idx = Index.new
213
- old = Gem.sources
215
+ old = Bundler.rubygems.sources
214
216
 
215
217
  remotes.each do |uri|
216
218
  Bundler.ui.info "Fetching source index for #{uri}"
@@ -232,21 +234,21 @@ module Bundler
232
234
  end
233
235
  idx
234
236
  ensure
235
- Gem.sources = old
237
+ Bundler.rubygems.sources = old
236
238
  end
237
239
  end
238
240
 
239
241
  def download_gem_from_uri(spec, uri)
240
242
  spec.fetch_platform
241
243
 
242
- download_path = Bundler.requires_sudo? ? Bundler.tmp : Gem.dir
243
- gem_path = "#{Gem.dir}/cache/#{spec.full_name}.gem"
244
+ download_path = Bundler.requires_sudo? ? Bundler.tmp : Bundler.rubygems.gem_dir
245
+ gem_path = "#{Bundler.rubygems.gem_dir}/cache/#{spec.full_name}.gem"
244
246
 
245
247
  FileUtils.mkdir_p("#{download_path}/cache")
246
- Gem::RemoteFetcher.fetcher.download(spec, uri, download_path)
248
+ Bundler.rubygems.download_gem(spec, uri, download_path)
247
249
 
248
250
  if Bundler.requires_sudo?
249
- sudo "mkdir -p #{Gem.dir}/cache"
251
+ sudo "mkdir -p #{Bundler.rubygems.gem_dir}/cache"
250
252
  sudo "mv #{Bundler.tmp}/cache/#{spec.full_name}.gem #{gem_path}"
251
253
  end
252
254
 
@@ -308,14 +310,13 @@ module Bundler
308
310
  def eql?(o)
309
311
  o.instance_of?(Path) &&
310
312
  path.expand_path(Bundler.root) == o.path.expand_path(Bundler.root) &&
311
- name == o.name &&
312
313
  version == o.version
313
314
  end
314
315
 
315
316
  alias == eql?
316
317
 
317
318
  def name
318
- File.basename(@path.to_s)
319
+ File.basename(path.expand_path(Bundler.root).to_s)
319
320
  end
320
321
 
321
322
  def load_spec_files
@@ -342,8 +343,9 @@ module Bundler
342
343
  s.summary = "Fake gemspec for #{@name}"
343
344
  s.relative_loaded_from = "#{@name}.gemspec"
344
345
  if expanded_path.join("bin").exist?
345
- binaries = expanded_path.join("bin").children.map{|c| c.basename.to_s }
346
- s.executables = binaries
346
+ binaries = expanded_path.join("bin").children
347
+ binaries.reject!{|p| File.directory?(p) }
348
+ s.executables = binaries.map{|c| c.basename.to_s }
347
349
  end
348
350
  end
349
351
  end
@@ -361,8 +363,8 @@ module Bundler
361
363
  class Installer < Gem::Installer
362
364
  def initialize(spec, options = {})
363
365
  @spec = spec
364
- @bin_dir = Bundler.requires_sudo? ? "#{Bundler.tmp}/bin" : "#{Gem.dir}/bin"
365
- @gem_dir = spec.full_gem_path
366
+ @bin_dir = Bundler.requires_sudo? ? "#{Bundler.tmp}/bin" : "#{Bundler.rubygems.gem_dir}/bin"
367
+ @gem_dir = Bundler.rubygems.path(spec.full_gem_path)
366
368
  @wrappers = options[:wrappers] || true
367
369
  @env_shebang = options[:env_shebang] || true
368
370
  @format_executable = options[:format_executable] || false
@@ -376,9 +378,9 @@ module Bundler
376
378
  end
377
379
  super
378
380
  if Bundler.requires_sudo?
379
- Bundler.mkdir_p "#{Gem.dir}/bin"
381
+ Bundler.mkdir_p "#{Bundler.rubygems.gem_dir}/bin"
380
382
  spec.executables.each do |exe|
381
- Bundler.sudo "cp -R #{Bundler.tmp}/bin/#{exe} #{Gem.dir}/bin/"
383
+ Bundler.sudo "cp -R #{Bundler.tmp}/bin/#{exe} #{Bundler.rubygems.gem_dir}/bin/"
382
384
  end
383
385
  end
384
386
  end
@@ -551,7 +553,9 @@ module Bundler
551
553
  out = %x{git #{command}}
552
554
 
553
555
  if $?.exitstatus != 0
554
- raise GitError, "An error has occurred in git when running `git #{command}`. Cannot complete bundling."
556
+ msg = "Git error: command `git #{command}` in directory #{Dir.pwd} has failed."
557
+ msg << "\nIf this error persists you could try removing the cache directory '#{cache_path}'" if cached?
558
+ raise GitError, msg
555
559
  end
556
560
  out
557
561
  else
@@ -602,7 +606,7 @@ module Bundler
602
606
  return if has_revision_cached?
603
607
  Bundler.ui.info "Updating #{uri}"
604
608
  in_cache do
605
- git %|fetch --force --quiet --tags "#{uri}" refs/heads/*:refs/heads/*|
609
+ git %|fetch --force --quiet --tags "#{uri}" "refs/heads/*:refs/heads/*"|
606
610
  end
607
611
  else
608
612
  Bundler.ui.info "Fetching #{uri}"
@@ -2,5 +2,5 @@ module Bundler
2
2
  # We're doing this because we might write tests that deal
3
3
  # with other versions of bundler and we are unsure how to
4
4
  # handle this better.
5
- VERSION = "1.1.pre.1" unless defined?(::Bundler::VERSION)
5
+ VERSION = "1.1.pre.2" unless defined?(::Bundler::VERSION)
6
6
  end
@@ -60,6 +60,7 @@ update process below under [CONSERVATIVE UPDATING][].
60
60
 
61
61
  * `--deployment`:
62
62
  Switches bundler's defaults into [deployment mode][DEPLOYMENT MODE].
63
+ Do not use this flag on development machines.
63
64
 
64
65
  * `--binstubs[=<directory>]`:
65
66
  Create a directory (defaults to `bin`) containing an executable
@@ -72,6 +73,8 @@ update process below under [CONSERVATIVE UPDATING][].
72
73
 
73
74
  Bundler's defaults are optimized for development. To switch to
74
75
  defaults optimized for deployment, use the `--deployment` flag.
76
+ Do not activate deployment mode on development machines, as it
77
+ will cause in an error when the Gemfile is modified.
75
78
 
76
79
  1. A `Gemfile.lock` is required.
77
80
 
@@ -76,7 +76,7 @@ describe "install with --deployment or --frozen" do
76
76
  G
77
77
 
78
78
  bundle "install --deployment"
79
- out.should include("You have modified your Gemfile")
79
+ out.should include("deployment mode")
80
80
  out.should include("You have added to the Gemfile")
81
81
  out.should include("* rack-obama")
82
82
  out.should_not include("You have deleted from the Gemfile")
@@ -92,7 +92,7 @@ describe "install with --deployment or --frozen" do
92
92
 
93
93
  ENV['BUNDLE_FROZEN'] = '1'
94
94
  bundle "install"
95
- out.should include("You have modified your Gemfile")
95
+ out.should include("deployment mode")
96
96
  out.should include("You have added to the Gemfile")
97
97
  out.should include("* rack-obama")
98
98
  out.should_not include("You have deleted from the Gemfile")
@@ -107,7 +107,7 @@ describe "install with --deployment or --frozen" do
107
107
  G
108
108
 
109
109
  bundle "install --frozen"
110
- out.should include("You have modified your Gemfile")
110
+ out.should include("deployment mode")
111
111
  out.should include("You have added to the Gemfile")
112
112
  out.should include("* rack-obama")
113
113
  out.should_not include("You have deleted from the Gemfile")
@@ -121,7 +121,7 @@ describe "install with --deployment or --frozen" do
121
121
  G
122
122
 
123
123
  bundle "install --deployment"
124
- out.should include("You have modified your Gemfile")
124
+ out.should include("deployment mode")
125
125
  out.should include("You have added to the Gemfile:\n* activesupport\n\n")
126
126
  out.should include("You have deleted from the Gemfile:\n* rack")
127
127
  out.should_not include("You have changed in the Gemfile")
@@ -134,7 +134,7 @@ describe "install with --deployment or --frozen" do
134
134
  G
135
135
 
136
136
  bundle "install --deployment"
137
- out.should include("You have modified your Gemfile")
137
+ out.should include("deployment mode")
138
138
  out.should include("You have added to the Gemfile:\n* source: git://hubz.com (at master)")
139
139
  out.should_not include("You have changed in the Gemfile")
140
140
  end
@@ -153,7 +153,7 @@ describe "install with --deployment or --frozen" do
153
153
  G
154
154
 
155
155
  bundle "install --deployment"
156
- out.should include("You have modified your Gemfile")
156
+ out.should include("deployment mode")
157
157
  out.should include("You have deleted from the Gemfile:\n* source: #{lib_path("rack-1.0")} (at master)")
158
158
  out.should_not include("You have added to the Gemfile")
159
159
  out.should_not include("You have changed in the Gemfile")
@@ -176,7 +176,7 @@ describe "install with --deployment or --frozen" do
176
176
  G
177
177
 
178
178
  bundle "install --deployment"
179
- out.should include("You have modified your Gemfile")
179
+ out.should include("deployment mode")
180
180
  out.should include("You have changed in the Gemfile:\n* rack from `no specified source` to `#{lib_path("rack")} (at master)`")
181
181
  out.should_not include("You have added to the Gemfile")
182
182
  out.should_not include("You have deleted from the Gemfile")
@@ -348,7 +348,7 @@ describe "bundle install with git sources" do
348
348
 
349
349
  bundle :install, :expect_err => true
350
350
 
351
- out.should include("An error has occurred in git")
351
+ out.should include("Git error:")
352
352
  err.should include("fatal")
353
353
  err.should include("omgomg")
354
354
  err.should include("fatal: The remote end hung up unexpectedly")
@@ -15,3 +15,21 @@ describe "bundle install with deprecated features" do
15
15
  end
16
16
 
17
17
  end
18
+
19
+ describe "bundle install to a dead symlink" do
20
+ before do
21
+ in_app_root do
22
+ `ln -s /tmp/idontexist bundle`
23
+ end
24
+ end
25
+
26
+ it "reports the symlink is dead" do
27
+ gemfile <<-G
28
+ source "file://#{gem_repo1}"
29
+ gem "rack"
30
+ G
31
+
32
+ bundle "install --path bundle"
33
+ out.should =~ /invalid symlink/
34
+ end
35
+ end
@@ -141,6 +141,47 @@ describe "bundle install with explicit source paths" do
141
141
  should_be_installed "rack 1.0"
142
142
  end
143
143
 
144
+ it "doesn't automatically unlock dependencies when using the gemspec syntax" do
145
+ build_lib "foo", "1.0", :path => lib_path("foo") do |s|
146
+ s.add_dependency "rack", ">= 1.0"
147
+ end
148
+
149
+ Dir.chdir lib_path("foo")
150
+
151
+ install_gemfile lib_path("foo/Gemfile"), <<-G
152
+ source "file://#{gem_repo1}"
153
+ gemspec
154
+ G
155
+
156
+ build_gem "rack", "1.0.1", :to_system => true
157
+
158
+ bundle "install"
159
+
160
+ should_be_installed "foo 1.0"
161
+ should_be_installed "rack 1.0"
162
+ end
163
+
164
+ it "doesn't automatically unlock dependencies when using the gemspec syntax and the gem has development dependencies" do
165
+ build_lib "foo", "1.0", :path => lib_path("foo") do |s|
166
+ s.add_dependency "rack", ">= 1.0"
167
+ s.add_development_dependency "activesupport"
168
+ end
169
+
170
+ Dir.chdir lib_path("foo")
171
+
172
+ install_gemfile lib_path("foo/Gemfile"), <<-G
173
+ source "file://#{gem_repo1}"
174
+ gemspec
175
+ G
176
+
177
+ build_gem "rack", "1.0.1", :to_system => true
178
+
179
+ bundle "install"
180
+
181
+ should_be_installed "foo 1.0"
182
+ should_be_installed "rack 1.0"
183
+ end
184
+
144
185
  it "raises if there are multiple gemspecs" do
145
186
  build_lib "foo", "1.0", :path => lib_path("foo") do |s|
146
187
  s.write "bar.gemspec"
@@ -182,6 +223,17 @@ describe "bundle install with explicit source paths" do
182
223
  out.should == "1.0"
183
224
  end
184
225
 
226
+ it "handles directories in bin/" do
227
+ build_lib "foo"
228
+ lib_path("foo-1.0").join("foo.gemspec").rmtree
229
+ lib_path("foo-1.0").join("bin/performance").mkpath
230
+
231
+ install_gemfile <<-G
232
+ gem 'foo', '1.0', :path => "#{lib_path('foo-1.0')}"
233
+ G
234
+ err.should == ""
235
+ end
236
+
185
237
  it "removes the .gem file after installing" do
186
238
  build_lib "foo"
187
239