summaryrefslogtreecommitdiff
path: root/lib
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 /lib
parent0be0d9a186110be65c59099c7633a83feeaa6cf9 (diff)
downloadbundler-70c029f3fa24826aa99eb4fcc87b9901b8d667b9.tar.gz
[DSL] Add support for multi-platform gems with the `gemspec` method
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler/dsl.rb24
-rw-r--r--lib/bundler/index.rb10
2 files changed, 21 insertions, 13 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)