Skip to content

Commit

Permalink
Vendor tsort into rubygems
Browse files Browse the repository at this point in the history
So that it loads a consistent version of the library and `rubygems` is
never affected by gem activation conflicts related to `tsort`.

Getting CI green required updating one `bundler` spec, because `tsort`
is no longer loaded by `bundle clean` until after `BUNDLE_PATH` has been
changed, so to ensure it is found, it needs to be installed under
`BUNDLE_PATH` as well (which will be different from the global system
path on Bundler 3, meaning installing `tsort` to the global system path
is not enough there). This spec workaround can be removed once we also
vendor `tsort` inside `bundler`.
  • Loading branch information
doodzik authored and deivid-rodriguez committed Oct 27, 2021
1 parent eb16260 commit d326880
Show file tree
Hide file tree
Showing 10 changed files with 501 additions and 6 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ AllCops:
Exclude:
- 'bundler/**/*'
- 'lib/rubygems/resolver/molinillo/**/*'
- 'lib/rubygems/tsort/**/*'
- 'pkg/**/*'
- 'tmp/**/*'
TargetRubyVersion: 2.3
Expand Down
3 changes: 3 additions & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ lib/rubygems/ssl_certs/rubygems.org/GlobalSignRootCA.pem
lib/rubygems/ssl_certs/rubygems.org/GlobalSignRootCA_R3.pem
lib/rubygems/stub_specification.rb
lib/rubygems/text.rb
lib/rubygems/tsort.rb
lib/rubygems/tsort/LICENSE.txt
lib/rubygems/tsort/lib/tsort.rb
lib/rubygems/uninstaller.rb
lib/rubygems/unknown_command_spell_checker.rb
lib/rubygems/uri.rb
Expand Down
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ if File.exist?("util/automatiek.rake")
lib.vendor_lib = "lib/rubygems/resolver/molinillo"
lib.license_path = "LICENSE"
end

desc "Vendor a specific version of tsort"
Automatiek::RakeTask.new("tsort") do |lib|
lib.version = "master"
lib.download = { :github => "https://github.com/ruby/tsort" }
lib.namespace = "TSort"
lib.prefix = "Gem"
lib.vendor_lib = "lib/rubygems/tsort"
lib.license_path = "LICENSE.txt"
end
end

namespace :rubocop do
Expand Down
2 changes: 2 additions & 0 deletions bundler/spec/commands/clean_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ def should_not_have_gems(*gems)
source "#{file_uri_for(gem_repo2)}"
G

realworld_system_gems "tsort --version 0.1.0", :path => default_bundle_path

bundle "clean --force", :env => { "BUNDLER_GEM_DEFAULT_DIR" => system_gem_path.to_s }

expect(out).not_to include("Removing irb")
Expand Down
4 changes: 2 additions & 2 deletions lib/rubygems/dependency_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# See LICENSE.txt for permissions.
#++

require 'tsort'
require_relative 'tsort'
require_relative 'deprecate'

##
Expand All @@ -20,7 +20,7 @@ class Gem::DependencyList
attr_reader :specs

include Enumerable
include TSort
include Gem::TSort

##
# Allows enabling/disabling use of development dependencies
Expand Down
4 changes: 2 additions & 2 deletions lib/rubygems/request_set.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true
require 'tsort'
require_relative 'tsort'

##
# A RequestSet groups a request to activate a set of dependencies.
Expand All @@ -15,7 +15,7 @@
# #=> ["nokogiri-1.6.0", "mini_portile-0.5.1", "pg-0.17.0"]

class Gem::RequestSet
include TSort
include Gem::TSort

##
# Array of gems to install even if already installed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'tsort'
require_relative '../../../../tsort'

require_relative 'dependency_graph/log'
require_relative 'dependency_graph/vertex'
Expand All @@ -17,7 +17,7 @@ def each
vertices.values.each { |v| yield v }
end

include TSort
include Gem::TSort

# @!visibility private
alias tsort_each_node each
Expand Down
3 changes: 3 additions & 0 deletions lib/rubygems/tsort.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

require_relative 'tsort/lib/tsort'
22 changes: 22 additions & 0 deletions lib/rubygems/tsort/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.

0 comments on commit d326880

Please sign in to comment.