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

Commit

Permalink
Allow bundle viz to work with dependencies satisfied by prereleases.
Browse files Browse the repository at this point in the history
Suppose a Gemfile specifies a dependency, `foo`:

  foo

Let's say `foo` requires a certain `bar`:

  foo
    bar (>= 0.5)

If this dependency happens to be satisfied by a prerelease `bar`, e.g.,
0.6.pre, then `bundle viz` will error.

The cause of this error is that `Bundler::Graph#_populate_relations`
executes

  child_dependencies = dependency.to_spec.runtime_dependencies.to_set

and if `dependency` (here, `bar`), is a prerelease, then
`dependency.to_spec` will be `nil` on Rubygems 2.4.0 and higher because
of changes to `#to_spec`.

By forcing `dependency.prerelease = true`, then `to_spec` won't ignore
the prerelease `bar` dependency, which prevents `dependency.to_spec` to
from being `nil`.

This should address GitHub issues 3621 and 3217.
  • Loading branch information
aprescott authored and indirect committed May 12, 2015
1 parent 62987f8 commit e3e9f4a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Rakefile
Expand Up @@ -114,8 +114,10 @@ namespace :spec do
system "sudo sed -i 's/1000::/1000:Travis:/g' /etc/passwd"
# Strip secure_path so that RVM paths transmit through sudo -E
system "sudo sed -i '/secure_path/d' /etc/sudoers"
# Install groff for the ronn gem
# Install groff so ronn can generate man/help pages
sh "sudo apt-get install groff -y"
# Install graphviz so that the viz specs can run
sh "sudo apt-get install graphviz -y 2>&1 | tail -n 2"
if RUBY_VERSION < '1.9'
# Downgrade Rubygems on 1.8 so Ronn can be required
# https://github.com/rubygems/rubygems/issues/784
Expand Down
3 changes: 3 additions & 0 deletions lib/bundler/graph.rb
Expand Up @@ -36,6 +36,9 @@ def _populate_relations
else
tmp = Set.new
parent_dependencies.each do |dependency|
# if the dependency is a prerelease, allow to_spec to be non-nil
dependency.prerelease = true

child_dependencies = dependency.to_spec.runtime_dependencies.to_set
@relations[dependency.name] += child_dependencies.map(&:name).to_set
tmp += child_dependencies
Expand Down
34 changes: 34 additions & 0 deletions spec/commands/viz_spec.rb
@@ -0,0 +1,34 @@
require "spec_helper"

describe "bundle viz", :if => Bundler.which("dot") do
let(:graphviz_lib) do
graphviz_glob = base_system_gems.join("gems/ruby-graphviz*/lib")
Dir[graphviz_glob].first
end

it "graphs gems from the Gemfile" do
install_gemfile <<-G
source "file://#{gem_repo1}"
gem "rack"
gem "rack-obama"
G

bundle "viz", :env => {"RUBYOPT" => "-I #{graphviz_lib}"}
expect(out).to include("gem_graph.png")
end

it "graphs gems that are prereleases" do
update_repo(gem_repo1) do
build_gem "rack", "1.3.pre"
end

install_gemfile <<-G
source "file://#{gem_repo1}"
gem "rack", "= 1.3.pre"
gem "rack-obama"
G

bundle "viz", :env => {"RUBYOPT" => "-I #{graphviz_lib}"}
expect(out).to include("gem_graph.png")
end
end
4 changes: 3 additions & 1 deletion spec/support/rubygems_ext.rb
Expand Up @@ -12,14 +12,16 @@ def self.setup

unless File.exist?("#{Path.base_system_gems}")
FileUtils.mkdir_p(Path.base_system_gems)
puts "fetching fakeweb, artifice, sinatra, rake, rack, and builder for the tests to use..."
puts "installing gems for the tests to use..."
`gem install fakeweb artifice --no-rdoc --no-ri`
`gem install sinatra --version 1.2.7 --no-rdoc --no-ri`
# Rake version has to be consistent for tests to pass
`gem install rake --version 10.0.2 --no-rdoc --no-ri`
# 3.0.0 breaks 1.9.2 specs
`gem install builder --version 2.1.2 --no-rdoc --no-ri`
`gem install rack --no-rdoc --no-ri`
# ruby-graphviz is used by the viz tests
`gem install ruby-graphviz --no-rdoc --no-ri`
end

ENV['HOME'] = Path.home.to_s
Expand Down

0 comments on commit e3e9f4a

Please sign in to comment.