Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
[DSL] Add support for multi-platform gems with the gemspec method
Browse files Browse the repository at this point in the history
  • Loading branch information
segiddins committed Jul 22, 2016
1 parent 0be0d9a commit 70c029f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
24 changes: 12 additions & 12 deletions lib/bundler/dsl.rb
Expand Up @@ -50,22 +50,22 @@ def eval_gemfile(gemfile, contents = nil)
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

Expand Down
10 changes: 9 additions & 1 deletion lib/bundler/index.rb
Expand Up @@ -67,12 +67,20 @@ def search(query, base = nil)
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)
Expand Down
14 changes: 12 additions & 2 deletions spec/install/gemfile/gemspec_spec.rb
Expand Up @@ -67,7 +67,7 @@

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)
Expand Down Expand Up @@ -196,7 +196,17 @@
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
Expand Down

0 comments on commit 70c029f

Please sign in to comment.