summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Virata-Stone <mjstone@on-site.com>2015-11-18 17:16:19 -0800
committerMike Virata-Stone <mjstone@on-site.com>2015-11-18 17:16:19 -0800
commit4b7a940f668d1884d9266946a48ba55a80c4d513 (patch)
treefa3e167f5a470603d2a425be137741269fbdcdbe
parentf787c664b4645fb44066b140b3b9afee542590c9 (diff)
downloadbundler-4b7a940f668d1884d9266946a48ba55a80c4d513.tar.gz
When loading a gem from a gemspec, restrict to the platforms defined in the gemspec
This fixes #4102
-rw-r--r--lib/bundler/dependency.rb9
-rw-r--r--lib/bundler/dsl.rb2
-rw-r--r--spec/bundler/dsl_spec.rb33
3 files changed, 43 insertions, 1 deletions
diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb
index 660b3355bd..f3e640b676 100644
--- a/lib/bundler/dependency.rb
+++ b/lib/bundler/dependency.rb
@@ -54,6 +54,15 @@ module Bundler
: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)
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb
index d601cc2635..041a55ebd1 100644
--- a/lib/bundler/dsl.rb
+++ b/lib/bundler/dsl.rb
@@ -60,7 +60,7 @@ module Bundler
"#{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|
diff --git a/spec/bundler/dsl_spec.rb b/spec/bundler/dsl_spec.rb
index 4949ad66c4..2397055826 100644
--- a/spec/bundler/dsl_spec.rb
+++ b/spec/bundler/dsl_spec.rb
@@ -145,6 +145,39 @@ describe Bundler::Dsl do
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"