summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-07-22 15:38:13 -0400
committerSamuel Giddins <segiddins@segiddins.me>2016-07-22 15:38:13 -0400
commit70c029f3fa24826aa99eb4fcc87b9901b8d667b9 (patch)
tree97d68ad65a2bddd73ed8187507d1f1e87eca4d0f
parent0be0d9a186110be65c59099c7633a83feeaa6cf9 (diff)
downloadbundler-70c029f3fa24826aa99eb4fcc87b9901b8d667b9.tar.gz
[DSL] Add support for multi-platform gems with the `gemspec` method
-rw-r--r--lib/bundler/dsl.rb24
-rw-r--r--lib/bundler/index.rb10
-rw-r--r--spec/install/gemfile/gemspec_spec.rb14
3 files changed, 33 insertions, 15 deletions
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb
index bbb091e3ba..91c791c73b 100644
--- a/lib/bundler/dsl.rb
+++ b/lib/bundler/dsl.rb
@@ -50,22 +50,22 @@ module Bundler
end
def gemspec(opts = nil)
- path = opts && opts[:path] || "."
- glob = opts && opts[:glob]
- name = opts && opts[:name] || "{,*}"
- development_group = opts && opts[:development_group] || :development
+ opts ||= {}
+ path = opts[:path] || "."
+ glob = opts[:glob]
+ name = opts[:name]
+ development_group = opts[:development_group] || :development
expanded_path = gemfile_root.join(path)
- gemspecs = Dir[File.join(expanded_path, "#{name}.gemspec")]
+ gemspecs = Dir[File.join(expanded_path, "{,*}.gemspec")].map {|g| Bundler.load_gemspec(g) }.compact
+ gemspecs.select! {|s| s.name == name } if name
+ Index.sort_specs(gemspecs)
+ specs_by_name_and_version = gemspecs.group_by {|s| [s.name, s.version] }
- case gemspecs.size
+ case specs_by_name_and_version.size
when 1
- spec = Bundler.load_gemspec(gemspecs.first)
-
- unless spec
- raise InvalidOption, "There was an error loading the gemspec at " \
- "#{file}. Make sure you can build the gem, then try again"
- end
+ specs = specs_by_name_and_version.values.first
+ spec = specs.find {|s| s.match_platform(Gem::Platform.local) } || specs.first
@gemspecs << spec
diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb
index f0ee411df8..4529c57279 100644
--- a/lib/bundler/index.rb
+++ b/lib/bundler/index.rb
@@ -67,12 +67,20 @@ module Bundler
end
end
- results.sort_by do |s|
+ sort_specs(results)
+ end
+
+ def self.sort_specs(specs)
+ specs.sort_by do |s|
platform_string = s.platform.to_s
[s.version, platform_string == RUBY ? NULL : platform_string]
end
end
+ def sort_specs(specs)
+ self.class.sort_specs(specs)
+ end
+
def local_search(query, base = nil)
case query
when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification then search_by_spec(query)
diff --git a/spec/install/gemfile/gemspec_spec.rb b/spec/install/gemfile/gemspec_spec.rb
index f601a7ded8..454dbcf8c2 100644
--- a/spec/install/gemfile/gemspec_spec.rb
+++ b/spec/install/gemfile/gemspec_spec.rb
@@ -67,7 +67,7 @@ describe "bundle install from an existing gemspec" do
it "should raise if there are too many gemspecs available" do
build_lib("foo", :path => tmp.join("foo")) do |s|
- s.write("foo2.gemspec", "")
+ s.write("foo2.gemspec", build_spec("foo", "4.0").first.to_ruby)
end
error = install_gemfile(<<-G, :expect_err => true)
@@ -196,7 +196,17 @@ describe "bundle install from an existing gemspec" do
before do
build_lib("foo", :path => tmp.join("foo")) do |s|
s.add_dependency "rack", "=1.0.0"
- s.platform = platform if explicit_platform
+ end
+
+ if explicit_platform
+ create_file(
+ tmp.join("foo", "foo-#{platform}.gemspec"),
+ build_spec("foo", "1.0", platform) do
+ dep "rack", "=1.0.0"
+ @spec.authors = "authors"
+ @spec.summary = "summary"
+ end.first.to_ruby
+ )
end
gemfile <<-G