summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rodríguez <deivid.rodriguez@riseup.net>2019-03-28 19:29:03 +0100
committerDavid Rodríguez <deivid.rodriguez@riseup.net>2019-04-12 10:13:17 +0200
commitc25f1d2380b4701d7c3896b62ef3997cedcf1b23 (patch)
tree49304d96aec05941bc29e87983e98b773c652325
parent1f77be49b98c4ef4bbbe5013003e091de02d4b90 (diff)
downloadbundler-c25f1d2380b4701d7c3896b62ef3997cedcf1b23.tar.gz
Add warning about conflicting executables
-rw-r--r--lib/bundler/rubygems_integration.rb22
-rw-r--r--spec/install/binstubs_spec.rb13
2 files changed, 25 insertions, 10 deletions
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb
index 42466fe03e..120ed1017c 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -442,14 +442,10 @@ module Bundler
raise ArgumentError, "you must supply exec_name" unless exec_name
spec_with_name = specs_by_name[gem_name]
- spec =
- if spec_with_name && spec_with_name.executables.include?(exec_name)
- spec_with_name
- else
- specs.find {|s| s.executables.include?(exec_name) }
- end
+ matching_specs_by_exec_name = specs.select {|s| s.executables.include?(exec_name) }
+ spec = matching_specs_by_exec_name.delete(spec_with_name)
- unless spec
+ unless spec || !matching_specs_by_exec_name.empty?
message = "can't find executable #{exec_name} for gem #{gem_name}"
if spec_with_name.nil?
message += ". #{gem_name} is not currently included in the bundle, " \
@@ -458,12 +454,22 @@ module Bundler
raise Gem::Exception, message
end
- unless spec.name == gem_name
+ unless spec
+ spec = matching_specs_by_exec_name.shift
warn \
"Bundler is using a binstub that was created for a different gem (#{spec.name}).\n" \
"You should run `bundle binstub #{gem_name}` " \
"to work around a system/bundle conflict."
end
+
+ unless matching_specs_by_exec_name.empty?
+ conflicting_names = matching_specs_by_exec_name.map(&:name).join(", ")
+ warn \
+ "The `#{exec_name}` executable in the `#{spec.name}` gem is being loaded, but it's also present in other gems (#{conflicting_names}).\n" \
+ "If you meant to run the executable for another gem, make sure you use a project specific binstub (`bundle binstub <gem_name>`).\n" \
+ "If you plan to actually use _both_ conflicting executables, generate binstubs for both and disambiguate their names."
+ end
+
spec
end
diff --git a/spec/install/binstubs_spec.rb b/spec/install/binstubs_spec.rb
index f04d3fe654..24c5aea6c3 100644
--- a/spec/install/binstubs_spec.rb
+++ b/spec/install/binstubs_spec.rb
@@ -35,9 +35,18 @@ RSpec.describe "bundle install", :bundler => "< 3" do
G
end
- it "loads the correct spec's executable" do
+ it "warns about the situation" do
gembin("rackup")
- expect(out).to eq("1.2")
+
+ expect(last_command.stderr).to include(
+ "The `rackup` executable in the `fake` gem is being loaded, but it's also present in other gems (rack).\n" \
+ "If you meant to run the executable for another gem, make sure you use a project specific binstub (`bundle binstub <gem_name>`).\n" \
+ "If you plan to actually use _both_ conflicting executables, generate binstubs for both and disambiguate their names."
+ ).or include(
+ "The `rackup` executable in the `rack` gem is being loaded, but it's also present in other gems (fake).\n" \
+ "If you meant to run the executable for another gem, make sure you use a project specific binstub (`bundle binstub <gem_name>`).\n" \
+ "If you plan to actually use _both_ conflicting executables, generate binstubs for both and disambiguate their names."
+ )
end
end
end