Permalink
Browse files

Load YAML gemspecs

Closes #248
  • Loading branch information...
1 parent 0753a24 commit 4a05eefbec072c8f5cb0e85720d99ca787b1ff54 @joshbuddy joshbuddy committed with indirect Apr 14, 2010
Showing with 44 additions and 5 deletions.
  1. +15 −1 lib/bundler/source.rb
  2. +18 −1 spec/install/gems/simple_case_spec.rb
  3. +11 −3 spec/support/builders.rb
View
@@ -193,7 +193,21 @@ def load_spec_files
Dir["#{path}/#{@glob}"].each do |file|
file = Pathname.new(file)
# Eval the gemspec from its parent directory
- if spec = Dir.chdir(file.dirname) { eval(File.read(file.basename), binding, file.expand_path.to_s) }
+ spec = Dir.chdir(file.dirname) do
+ begin
+ Gem::Specification.from_yaml(file.basename)
+ # Raises ArgumentError if the file is not valid YAML
+ rescue ArgumentError, Gem::EndOfYAMLException, Gem::Exception
+ begin
+ eval(File.read(file.basename), TOPLEVEL_BINDING, file.expand_path.to_s)
+ rescue LoadError
+ raise GemspecError, "There was a LoadError while evaluating #{file.basename}.\n" +
+ "Does it try to require a relative path? That doesn't work in Ruby 1.9."
+ end
+ end
+ end
+
+ if spec
spec = Specification.from_gemspec(spec)
spec.loaded_from = file.to_s
spec.source = self
@@ -343,4 +343,21 @@
out.should include("no activesupport")
end
end
-end
+
+ describe "when a gem has a YAML gemspec" do
+ before :each do
+ build_repo2 do
+ build_gem "yaml_spec", :gemspec => :yaml
+ end
+ end
+
+ it "still installs correctly" do
+ gemfile <<-G
+ source "file://#{gem_repo2}"
+ gem "yaml_spec"
+ G
+ bundle :install
+ err.should be_empty
+ end
+ end
+end
View
@@ -356,7 +356,15 @@ def add_c_extension
def _build(options)
path = options[:path] || _default_path
- @files["#{name}.gemspec"] = @spec.to_ruby unless options[:gemspec] == false
+ case options[:gemspec]
+ when false
+ # do nothing
+ when :yaml
+ @files["#{name}.gemspec"] = @spec.to_yaml
+ else
+ @files["#{name}.gemspec"] = @spec.to_ruby
+ end
+
unless options[:no_default]
@files = _default_files.merge(@files)
end
@@ -429,7 +437,7 @@ def _build(options)
class GemBuilder < LibBuilder
def _build(opts)
- lib_path = super(:path => @context.tmp(".tmp/#{@spec.full_name}"), :no_default => opts[:no_default])
+ lib_path = super(opts.merge(:path => @context.tmp(".tmp/#{@spec.full_name}"), :no_default => opts[:no_default]))
Dir.chdir(lib_path) do
destination = opts[:path] || _default_path
FileUtils.mkdir_p(destination)
@@ -447,4 +455,4 @@ def _default_path
end
end
end
-end
+end

0 comments on commit 4a05eef

Please sign in to comment.