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

Commit

Permalink
When loading a gem from a gemspec, restrict to the platforms defined …
Browse files Browse the repository at this point in the history
…in the gemspec

This fixes #4102
  • Loading branch information
smellsblue committed Nov 19, 2015
1 parent f787c66 commit 4b7a940
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/bundler/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ class Dependency < Gem::Dependency
:x64_mingw_23 => Gem::Platform::X64_MINGW
}.freeze

REVERSE_PLATFORM_MAP = {}.tap do |reverse_platform_map|
PLATFORM_MAP.each do |key, value|
reverse_platform_map[value] ||= []
reverse_platform_map[value] << key
end

reverse_platform_map.each {|_, platforms| platforms.freeze }
end.freeze

def initialize(name, version, options = {}, &blk)
type = options["type"] || :runtime
super(name, version, type)
Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def gemspec(opts = nil)
"#{file}. Make sure you can build the gem, then try again"
end

gem spec.name, :path => path, :glob => glob
gem spec.name, :path => path, :glob => glob, :platforms => Bundler::Dependency::REVERSE_PLATFORM_MAP[spec.platform]

group(development_group) do
spec.development_dependencies.each do |dep|
Expand Down
33 changes: 33 additions & 0 deletions spec/bundler/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,39 @@
end
end

describe "#gemspec" do
let(:spec) do
Gem::Specification.new do |gem|
gem.name = "example"
gem.platform = platform
end
end

before do
allow(Dir).to receive(:[]).and_return(["spec_path"])
allow(Bundler).to receive(:load_gemspec).with("spec_path").and_return(spec)
allow(Bundler).to receive(:default_gemfile).and_return(Pathname.new("./Gemfile"))
end

context "with a ruby platform" do
let(:platform) { "ruby" }

it "keeps track of the ruby platforms in the dependency" do
subject.gemspec
expect(subject.dependencies.last.platforms).to eq(Bundler::Dependency::REVERSE_PLATFORM_MAP[Gem::Platform::RUBY])
end
end

context "with a jruby platform" do
let(:platform) { "java" }

it "keeps track of the jruby platforms in the dependency" do
subject.gemspec
expect(subject.dependencies.last.platforms).to eq(Bundler::Dependency::REVERSE_PLATFORM_MAP[Gem::Platform::JAVA])
end
end
end

context "can bundle groups of gems with" do
# git "https://github.com/rails/rails.git" do
# gem "railties"
Expand Down

0 comments on commit 4b7a940

Please sign in to comment.