bundler 0.9.4 → 0.9.5

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.

data/bin/bundle CHANGED
@@ -1,3 +1,10 @@
1
+ # Check if an older version of bundler is installed
2
+ require 'bundler'
3
+ $:.each do |path|
4
+ if path =~ %r'/bundler-0.(\d+)' && $1.to_i < 9
5
+ abort "Please remove older versions of bundler. This can by running `gem cleanup`."
6
+ end
7
+ end
1
8
  require 'bundler/cli'
2
9
 
3
10
  begin
@@ -4,7 +4,7 @@ require 'yaml'
4
4
  require 'bundler/rubygems-ext'
5
5
 
6
6
  module Bundler
7
- VERSION = "0.9.4"
7
+ VERSION = "0.9.5"
8
8
 
9
9
  autoload :Definition, 'bundler/definition'
10
10
  autoload :Dependency, 'bundler/dependency'
@@ -56,7 +56,7 @@ module Bundler
56
56
 
57
57
  def bundle_path
58
58
  @bundle_path ||= begin
59
- path = settings[:path] || "#{Gem.user_home}/.bundle"
59
+ path = settings[:path] || "#{Gem.user_home}/.bundle/#{Gem.ruby_engine}/#{Gem::ConfigMap[:ruby_version]}"
60
60
  Pathname.new(path).expand_path(root)
61
61
  end
62
62
  end
@@ -96,7 +96,7 @@ module Bundler
96
96
  end
97
97
 
98
98
  def cache
99
- home.join("cache")
99
+ bundle_path.join('cache/bundler')
100
100
  end
101
101
 
102
102
  def root
@@ -114,8 +114,8 @@ module Bundler
114
114
  end
115
115
 
116
116
  def configure_gem_home_and_path
117
- if path = settings[:path]
118
- ENV['GEM_HOME'] = File.expand_path(path, root)
117
+ if settings[:disable_shared_gems]
118
+ ENV['GEM_HOME'] = File.expand_path(bundle_path, root)
119
119
  ENV['GEM_PATH'] = ''
120
120
  else
121
121
  gem_home, gem_path = Gem.dir, Gem.path
@@ -1,6 +1,5 @@
1
1
  $:.unshift File.expand_path('../vendor', __FILE__)
2
2
  require 'thor'
3
- require 'bundler'
4
3
  require 'rubygems/config_file'
5
4
 
6
5
  # Work around a RubyGems bug
@@ -44,18 +43,23 @@ module Bundler
44
43
  end
45
44
 
46
45
  desc "install", "Install the current environment to the system"
47
- method_option :without, :type => :array, :banner => "Exclude gems that are part of the specified named group"
48
- method_option :relock, :type => :boolean, :banner => "Unlock, install the gems, and relock"
46
+ method_option "without", :type => :array, :banner => "Exclude gems that are part of the specified named group."
47
+ method_option "relock", :type => :boolean, :banner => "Unlock, install the gems, and relock."
48
+ method_option "disable-shared-gems", :type => :boolean, :banner => "Do not use any shared gems, such as the system gem repository."
49
49
  def install(path = nil)
50
- remove_lockfiles if options[:relock]
51
-
52
50
  opts = options.dup
53
51
  opts[:without] ||= []
54
52
  opts[:without].map! { |g| g.to_sym }
55
53
 
56
54
  Bundler.settings[:path] = path if path
55
+ Bundler.settings[:disable_shared_gems] = '1' if options["disable-shared-gems"]
56
+
57
+ remove_lockfiles if options[:relock]
57
58
 
58
59
  Installer.install(Bundler.root, Bundler.definition, opts)
60
+ # Ensures that .bundle/environment.rb exists
61
+ # TODO: Figure out a less hackish way to do this
62
+ Bundler.load
59
63
 
60
64
  lock if options[:relock]
61
65
  end
@@ -8,10 +8,13 @@ module Bundler
8
8
  def initialize(name, version, options = {}, &blk)
9
9
  super(name, version)
10
10
 
11
- @groups = Array(options["group"] || :default)
12
- @source = options["source"]
13
- @autorequire = options.include?("require") ? options['require'] || [] : [name]
14
- @autorequire = [@autorequire] unless @autorequire.is_a?(Array)
11
+ @autorequire = nil
12
+ @groups = Array(options["group"] || :default).map { |g| g.to_sym }
13
+ @source = options["source"]
14
+
15
+ if options.key?('require')
16
+ @autorequire = Array(options['require'] || [])
17
+ end
15
18
  end
16
19
  end
17
20
  end
@@ -4,6 +4,13 @@ module Bundler
4
4
  class Runtime < Environment
5
5
  include SharedHelpers
6
6
 
7
+ def initialize(*)
8
+ super
9
+ if locked? # && !rb_lock_file.exist?
10
+ write_rb_lock
11
+ end
12
+ end
13
+
7
14
  def setup(*groups)
8
15
  # Has to happen first
9
16
  clean_load_path
@@ -21,11 +28,20 @@ module Bundler
21
28
  end
22
29
 
23
30
  def require(*groups)
31
+ groups.map! { |g| g.to_sym }
24
32
  groups = [:default] if groups.empty?
25
33
  autorequires = autorequires_for_groups(*groups)
34
+
26
35
  groups.each do |group|
27
- (autorequires[group] || []).each do |path|
28
- Kernel.require(path)
36
+ (autorequires[group] || [[]]).each do |path, explicit|
37
+ if explicit
38
+ Kernel.require(path)
39
+ else
40
+ begin
41
+ Kernel.require(path)
42
+ rescue LoadError
43
+ end
44
+ end
29
45
  end
30
46
  end
31
47
  end
@@ -60,6 +76,7 @@ module Bundler
60
76
  end
61
77
 
62
78
  def specs_for(*groups)
79
+ groups.map! { |g| g.to_sym }
63
80
  if groups.empty?
64
81
  specs
65
82
  else
@@ -75,7 +92,7 @@ module Bundler
75
92
  source_requirements[dep.name] = dep.source.local_specs
76
93
  end
77
94
 
78
- Resolver.resolve(@definition.actual_dependencies, index, source_requirements)
95
+ group_specs(Resolver.resolve(@definition.actual_dependencies, index, source_requirements))
79
96
  end
80
97
  end
81
98
 
@@ -110,11 +127,15 @@ module Bundler
110
127
  specs.map { |s| s.load_paths }.flatten
111
128
  end
112
129
 
130
+ def rb_lock_file
131
+ root.join(".bundle/environment.rb")
132
+ end
133
+
113
134
  def write_rb_lock
114
135
  shared_helpers = File.read(File.expand_path("../shared_helpers.rb", __FILE__))
115
136
  template = File.read(File.expand_path("../templates/environment.erb", __FILE__))
116
137
  erb = ERB.new(template, nil, '-')
117
- File.open("#{root}/.bundle/environment.rb", 'w') do |f|
138
+ File.open(rb_lock_file, 'w') do |f|
118
139
  f.puts erb.result(binding)
119
140
  end
120
141
  end
@@ -138,9 +159,9 @@ module Bundler
138
159
  end
139
160
 
140
161
  details["dependencies"] = @definition.dependencies.inject({}) do |h,d|
141
- h.merge!({d.name => {"version" => d.version_requirements.to_s,
142
- "group" => d.groups,
143
- "require" => d.autorequire}})
162
+ h.merge!({d.name => {"version" => d.version_requirements.to_s, "group" => d.groups} })
163
+ h[d.name]['require'] = d.autorequire if d.autorequire
164
+ h
144
165
  end
145
166
  details
146
167
  end
@@ -149,11 +170,32 @@ module Bundler
149
170
  Digest::SHA1.hexdigest(File.read("#{root}/Gemfile"))
150
171
  end
151
172
 
173
+ def specs_for_lock_file
174
+ specs.map do |spec|
175
+ dep = @definition.dependencies.find { |d| d.name == spec.name }
176
+ hash = {}
177
+ hash[:name] = spec.name
178
+ hash[:version] = spec.version.to_s
179
+ hash[:groups] = spec.groups
180
+ hash[:load_paths] = spec.load_paths
181
+ hash
182
+ end
183
+ end
184
+
152
185
  def autorequires_for_groups(*groups)
186
+ groups.map! { |g| g.to_sym }
153
187
  autorequires = Hash.new { |h,k| h[k] = [] }
154
188
  @definition.dependencies.each do |dep|
155
189
  dep.groups.each do |group|
156
- autorequires[group].concat dep.autorequire
190
+ # If there is no autorequire, then rescue from
191
+ # autorequiring the gems name
192
+ if dep.autorequire
193
+ dep.autorequire.each do |file|
194
+ autorequires[group] << [file, true]
195
+ end
196
+ else
197
+ autorequires[group] << [dep.name, false]
198
+ end
157
199
  end
158
200
  end
159
201
 
@@ -164,24 +206,13 @@ module Bundler
164
206
  end
165
207
  end
166
208
 
167
- def clean_load_path
168
- # handle 1.9 where system gems are always on the load path
169
- if defined?(::Gem)
170
- me = File.expand_path("../../", __FILE__)
171
- $LOAD_PATH.reject! do |p|
172
- p != File.dirname(__FILE__) &&
173
- Gem.path.any? { |gp| p.include?(gp) }
174
- end
175
- $LOAD_PATH.unshift me
176
- $LOAD_PATH.uniq!
177
- end
178
- end
179
-
180
209
  def cripple_rubygems(specs)
181
210
  reverse_rubygems_kernel_mixin
182
211
 
183
212
  executables = specs.map { |s| s.executables }.flatten
184
213
 
214
+ # TODO: This is duplicated a bit too much in environment.erb.
215
+ # Let's figure out how to improve that.
185
216
  ::Kernel.send(:define_method, :gem) do |dep, *reqs|
186
217
  if executables.include? File.basename(caller.first.split(':').first)
187
218
  return
@@ -2,8 +2,6 @@ module Bundler
2
2
  module SharedHelpers
3
3
 
4
4
  def reverse_rubygems_kernel_mixin
5
- require "rubygems"
6
-
7
5
  # Disable rubygems' gem activation system
8
6
  ::Kernel.class_eval do
9
7
  if private_method_defined?(:gem_original_require)
@@ -40,6 +38,19 @@ module Bundler
40
38
  end
41
39
  end
42
40
 
41
+ def clean_load_path
42
+ # handle 1.9 where system gems are always on the load path
43
+ if defined?(::Gem)
44
+ me = File.expand_path("../../", __FILE__)
45
+ $LOAD_PATH.reject! do |p|
46
+ next if File.expand_path(p).include?(me)
47
+ p != File.dirname(__FILE__) &&
48
+ Gem.path.any? { |gp| p.include?(gp) }
49
+ end
50
+ $LOAD_PATH.uniq!
51
+ end
52
+ end
53
+
43
54
  extend self
44
55
  end
45
56
  end
@@ -160,9 +160,10 @@ module Bundler
160
160
  if File.directory?(path)
161
161
  Dir["#{path}/#{@glob}"].each do |file|
162
162
  file = Pathname.new(file)
163
+ relative_path = file.relative_path_from(Pathname.new(path))
163
164
  # Do it in the root of the repo in case they do
164
165
  # assume being in the root
165
- if spec = Dir.chdir(path) { eval(File.read(file)) }
166
+ if spec = Dir.chdir(path) { eval(File.read(relative_path)) }
166
167
  spec = Specification.from_gemspec(spec)
167
168
  spec.loaded_from = file
168
169
  spec.source = self
@@ -313,11 +314,10 @@ module Bundler
313
314
  end
314
315
 
315
316
  def checkout
316
- FileUtils.mkdir_p(path)
317
+ unless File.exist?("#{path}/.git")
318
+ %x(git clone --no-checkout #{cache_path} #{path})
319
+ end
317
320
  Dir.chdir(path) do
318
- unless File.exist?(".git")
319
- %x(git clone --no-checkout #{cache_path} #{path})
320
- end
321
321
  git "fetch --quiet"
322
322
  git "reset --hard #{revision}"
323
323
  end
@@ -1,17 +1,26 @@
1
- require 'digest/sha1'
2
-
3
1
  # DO NOT MODIFY THIS FILE
4
2
 
3
+ require 'digest/sha1'
4
+ require "rubygems"
5
+
5
6
  <%= shared_helpers %>
6
7
 
7
8
  module Bundler
8
- extend SharedHelpers
9
+ LOCKED_BY = '<%= Bundler::VERSION %>'
10
+ FINGERPRINT = <%= gemfile_fingerprint.inspect %>
11
+ SPECS = [
12
+ <% specs_for_lock_file.each do |spec| -%>
13
+ <%= spec.inspect %>,
14
+ <% end -%>
15
+ ]
16
+ AUTOREQUIRES = <%= autorequires_for_groups.inspect %>
9
17
 
10
- reverse_rubygems_kernel_mixin
18
+ extend SharedHelpers
11
19
 
12
- FINGERPRINT = <%= gemfile_fingerprint.inspect %>
13
- LOAD_PATHS = <%= load_paths.inspect %>
14
- AUTOREQUIRES = <%= autorequires_for_groups.inspect %>
20
+ def self.cripple_ruby_gems
21
+ reverse_rubygems_kernel_mixin
22
+ patch_rubygems
23
+ end
15
24
 
16
25
  def self.match_fingerprint
17
26
  print = Digest::SHA1.hexdigest(File.read(File.expand_path('../../Gemfile', __FILE__)))
@@ -22,16 +31,46 @@ module Bundler
22
31
 
23
32
  def self.setup(*groups)
24
33
  match_fingerprint
25
- LOAD_PATHS.each { |path| $LOAD_PATH.unshift path }
34
+ SPECS.each do |spec|
35
+ spec[:load_paths].each { |path| $LOAD_PATH.unshift path }
36
+ end
26
37
  end
27
38
 
28
39
  def self.require(*groups)
29
40
  groups = [:default] if groups.empty?
30
41
  groups.each do |group|
31
- (AUTOREQUIRES[group] || []).each { |file| Kernel.require file }
42
+ (AUTOREQUIRES[group] || []).each do |file, explicit|
43
+ if explicit
44
+ Kernel.require file
45
+ else
46
+ begin
47
+ Kernel.require file
48
+ rescue LoadError
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ def self.patch_rubygems
56
+ specs = SPECS
57
+
58
+ ::Kernel.send(:define_method, :gem) do |dep, *reqs|
59
+ opts = reqs.last.is_a?(Hash) ? reqs.pop : {}
60
+
61
+ dep = dep.name if dep.respond_to?(:name)
62
+ unless specs.any? { |s| s[:name] == dep }
63
+ e = Gem::LoadError.new "#{dep} is not part of the bundle. Add it to Gemfile."
64
+ e.name = dep
65
+ e.version_requirement = reqs
66
+ raise e
67
+ end
68
+
69
+ true
32
70
  end
33
71
  end
34
72
 
35
73
  # Setup bundle when it's required.
74
+ cripple_ruby_gems
36
75
  setup
37
76
  end
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.4
4
+ version: 0.9.5
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-10 00:00:00 -08:00
13
+ date: 2010-02-12 00:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies: []
16
16