summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/bundler.rb48
-rw-r--r--lib/bundler/cli.rb62
-rw-r--r--lib/bundler/cli/cache.rb2
-rw-r--r--lib/bundler/cli/check.rb6
-rw-r--r--lib/bundler/cli/doctor.rb14
-rw-r--r--lib/bundler/cli/exec.rb7
-rw-r--r--lib/bundler/cli/gem.rb5
-rw-r--r--lib/bundler/cli/install.rb26
-rw-r--r--lib/bundler/cli/list.rb8
-rw-r--r--lib/bundler/cli/lock.rb6
-rw-r--r--lib/bundler/cli/open.rb3
-rw-r--r--lib/bundler/cli/outdated.rb19
-rw-r--r--lib/bundler/cli/remove.rb3
-rw-r--r--lib/bundler/cli/update.rb13
-rw-r--r--lib/bundler/compact_index_client.rb4
-rw-r--r--lib/bundler/current_ruby.rb8
-rw-r--r--lib/bundler/definition.rb244
-rw-r--r--lib/bundler/dsl.rb44
-rw-r--r--lib/bundler/endpoint_specification.rb8
-rw-r--r--lib/bundler/errors.rb2
-rw-r--r--lib/bundler/feature_flag.rb2
-rw-r--r--lib/bundler/fetcher/compact_index.rb2
-rw-r--r--lib/bundler/fetcher/downloader.rb3
-rw-r--r--lib/bundler/fetcher/index.rb1
-rw-r--r--lib/bundler/friendly_errors.rb6
-rw-r--r--lib/bundler/gemdeps.rb29
-rw-r--r--lib/bundler/index.rb9
-rw-r--r--lib/bundler/installer.rb21
-rw-r--r--lib/bundler/installer/gem_installer.rb19
-rw-r--r--lib/bundler/installer/standalone.rb23
-rw-r--r--lib/bundler/lockfile_parser.rb23
-rw-r--r--lib/bundler/man/bundle-add.12
-rw-r--r--lib/bundler/man/bundle-binstubs.12
-rw-r--r--lib/bundler/man/bundle-cache.12
-rw-r--r--lib/bundler/man/bundle-check.12
-rw-r--r--lib/bundler/man/bundle-clean.12
-rw-r--r--lib/bundler/man/bundle-config.113
-rw-r--r--lib/bundler/man/bundle-config.1.ronn15
-rw-r--r--lib/bundler/man/bundle-doctor.12
-rw-r--r--lib/bundler/man/bundle-exec.12
-rw-r--r--lib/bundler/man/bundle-gem.12
-rw-r--r--lib/bundler/man/bundle-info.12
-rw-r--r--lib/bundler/man/bundle-init.12
-rw-r--r--lib/bundler/man/bundle-inject.12
-rw-r--r--lib/bundler/man/bundle-install.14
-rw-r--r--lib/bundler/man/bundle-install.1.ronn4
-rw-r--r--lib/bundler/man/bundle-list.12
-rw-r--r--lib/bundler/man/bundle-lock.12
-rw-r--r--lib/bundler/man/bundle-open.12
-rw-r--r--lib/bundler/man/bundle-outdated.12
-rw-r--r--lib/bundler/man/bundle-platform.12
-rw-r--r--lib/bundler/man/bundle-pristine.12
-rw-r--r--lib/bundler/man/bundle-remove.12
-rw-r--r--lib/bundler/man/bundle-show.12
-rw-r--r--lib/bundler/man/bundle-update.110
-rw-r--r--lib/bundler/man/bundle-update.1.ronn9
-rw-r--r--lib/bundler/man/bundle-viz.12
-rw-r--r--lib/bundler/man/bundle.12
-rw-r--r--lib/bundler/man/gemfile.52
-rw-r--r--lib/bundler/plugin.rb31
-rw-r--r--lib/bundler/plugin/api/source.rb14
-rw-r--r--lib/bundler/plugin/index.rb5
-rw-r--r--lib/bundler/plugin/installer.rb4
-rw-r--r--lib/bundler/psyched_yaml.rb14
-rw-r--r--lib/bundler/resolver.rb103
-rw-r--r--lib/bundler/rubygems_ext.rb34
-rw-r--r--lib/bundler/rubygems_gem_installer.rb6
-rw-r--r--lib/bundler/rubygems_integration.rb19
-rw-r--r--lib/bundler/runtime.rb25
-rw-r--r--lib/bundler/settings.rb46
-rw-r--r--lib/bundler/setup.rb4
-rw-r--r--lib/bundler/shared_helpers.rb7
-rw-r--r--lib/bundler/source.rb15
-rw-r--r--lib/bundler/source/git/git_proxy.rb3
-rw-r--r--lib/bundler/source/rubygems.rb69
-rw-r--r--lib/bundler/source/rubygems_aggregate.rb68
-rw-r--r--lib/bundler/source_list.rb109
-rw-r--r--lib/bundler/source_map.rb58
-rw-r--r--lib/bundler/spec_set.rb59
-rw-r--r--lib/bundler/templates/Executable.bundler12
-rw-r--r--lib/bundler/templates/newgem/github/workflows/main.yml.tt15
-rw-r--r--lib/bundler/templates/newgem/newgem.gemspec.tt6
-rw-r--r--lib/bundler/vendor/connection_pool/lib/connection_pool.rb113
-rw-r--r--lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb66
-rw-r--r--lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb40
-rw-r--r--lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb2
-rw-r--r--lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb57
-rw-r--r--lib/bundler/vendor/uri/lib/uri.rb1
-rw-r--r--lib/bundler/vendor/uri/lib/uri/common.rb97
-rw-r--r--lib/bundler/vendor/uri/lib/uri/ftp.rb1
-rw-r--r--lib/bundler/vendor/uri/lib/uri/generic.rb11
-rw-r--r--lib/bundler/vendor/uri/lib/uri/http.rb1
-rw-r--r--lib/bundler/vendor/uri/lib/uri/https.rb1
-rw-r--r--lib/bundler/vendor/uri/lib/uri/ldap.rb2
-rw-r--r--lib/bundler/vendor/uri/lib/uri/mailto.rb1
-rw-r--r--lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb15
-rw-r--r--lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb13
-rw-r--r--lib/bundler/vendor/uri/lib/uri/version.rb2
-rw-r--r--lib/bundler/vendor/uri/lib/uri/ws.rb84
-rw-r--r--lib/bundler/vendor/uri/lib/uri/wss.rb22
-rw-r--r--lib/bundler/worker.rb23
-rw-r--r--lib/cgi/util.rb11
-rw-r--r--lib/did_you_mean/core_ext/name_error.rb11
-rw-r--r--lib/did_you_mean/spell_checkers/require_path_checker.rb1
-rw-r--r--lib/did_you_mean/version.rb2
-rw-r--r--lib/error_highlight.rb2
-rw-r--r--lib/error_highlight/base.rb461
-rw-r--r--lib/error_highlight/core_ext.rb50
-rw-r--r--lib/error_highlight/error_highlight.gemspec27
-rw-r--r--lib/error_highlight/formatter.rb25
-rw-r--r--lib/error_highlight/version.rb3
-rw-r--r--lib/find.rb4
-rw-r--r--lib/forwardable.rb2
-rw-r--r--lib/getoptlong.rb10
-rw-r--r--lib/getoptlong/getoptlong.gemspec2
-rw-r--r--lib/irb.rb7
-rw-r--r--lib/irb/cmd/help.rb3
-rw-r--r--lib/irb/cmd/info.rb6
-rw-r--r--lib/irb/cmd/ls.rb24
-rw-r--r--lib/irb/cmd/measure.rb3
-rw-r--r--lib/irb/cmd/show_source.rb16
-rw-r--r--lib/irb/completion.rb72
-rw-r--r--lib/irb/context.rb5
-rw-r--r--lib/irb/init.rb21
-rw-r--r--lib/irb/input-method.rb74
-rw-r--r--lib/irb/irb.gemspec2
-rw-r--r--lib/irb/lc/help-message2
-rw-r--r--lib/irb/lc/ja/help-message2
-rw-r--r--lib/irb/ruby-lex.rb83
-rw-r--r--lib/irb/version.rb4
-rw-r--r--lib/irb/workspace.rb3
-rw-r--r--lib/logger/logger.gemspec2
-rw-r--r--lib/mkmf.rb32
-rw-r--r--lib/mutex_m.rb12
-rw-r--r--lib/net/http/generic_request.rb4
-rw-r--r--lib/optparse.rb24
-rw-r--r--lib/ostruct.rb2
-rw-r--r--lib/racc/parser-text.rb2
-rw-r--r--lib/racc/parserfilegenerator.rb44
-rw-r--r--lib/racc/pre-setup13
-rw-r--r--lib/racc/racc.gemspec75
-rw-r--r--lib/racc/rdoc/grammar.en.rdoc219
-rw-r--r--lib/racc/statetransitiontable.rb10
-rw-r--r--lib/rdoc/Rakefile107
-rw-r--r--lib/rdoc/generator/darkfish.rb4
-rw-r--r--lib/rdoc/generator/template/darkfish/_head.rhtml4
-rw-r--r--lib/rdoc/markdown.rb79
-rw-r--r--lib/rdoc/markdown/literals.rb15
-rw-r--r--lib/rdoc/markup/to_html.rb4
-rw-r--r--lib/rdoc/options.rb31
-rw-r--r--lib/rdoc/parser/ruby.rb18
-rw-r--r--lib/rdoc/rd/block_parser.rb2
-rw-r--r--lib/rdoc/rd/inline_parser.rb2
-rw-r--r--lib/rdoc/rdoc.gemspec1
-rw-r--r--lib/rdoc/rdoc.rb33
-rw-r--r--lib/rdoc/ri/driver.rb15
-rw-r--r--lib/rdoc/rubygems_hook.rb4
-rw-r--r--lib/rdoc/text.rb16
-rw-r--r--lib/rdoc/version.rb2
-rw-r--r--lib/readline.gemspec24
-rw-r--r--lib/reline.rb172
-rw-r--r--lib/reline/ansi.rb100
-rw-r--r--lib/reline/config.rb49
-rw-r--r--lib/reline/general_io.rb12
-rw-r--r--lib/reline/key_stroke.rb77
-rw-r--r--lib/reline/line_editor.rb491
-rw-r--r--lib/reline/terminfo.rb126
-rw-r--r--lib/reline/unicode.rb35
-rw-r--r--lib/reline/version.rb2
-rw-r--r--lib/reline/windows.rb214
-rw-r--r--lib/resolv-replace.gemspec2
-rw-r--r--lib/resolv.gemspec2
-rw-r--r--lib/ruby2_keywords.gemspec19
-rw-r--r--lib/rubygems.rb84
-rw-r--r--lib/rubygems/command.rb2
-rw-r--r--lib/rubygems/command_manager.rb6
-rw-r--r--lib/rubygems/commands/build_command.rb8
-rw-r--r--lib/rubygems/commands/cert_command.rb84
-rw-r--r--lib/rubygems/commands/check_command.rb8
-rw-r--r--lib/rubygems/commands/cleanup_command.rb6
-rw-r--r--lib/rubygems/commands/contents_command.rb4
-rw-r--r--lib/rubygems/commands/dependency_command.rb6
-rw-r--r--lib/rubygems/commands/environment_command.rb2
-rw-r--r--lib/rubygems/commands/fetch_command.rb6
-rw-r--r--lib/rubygems/commands/generate_index_command.rb4
-rw-r--r--lib/rubygems/commands/help_command.rb2
-rw-r--r--lib/rubygems/commands/info_command.rb4
-rw-r--r--lib/rubygems/commands/install_command.rb23
-rw-r--r--lib/rubygems/commands/list_command.rb4
-rw-r--r--lib/rubygems/commands/lock_command.rb2
-rw-r--r--lib/rubygems/commands/mirror_command.rb2
-rw-r--r--lib/rubygems/commands/open_command.rb4
-rw-r--r--lib/rubygems/commands/outdated_command.rb8
-rw-r--r--lib/rubygems/commands/owner_command.rb8
-rw-r--r--lib/rubygems/commands/pristine_command.rb10
-rw-r--r--lib/rubygems/commands/push_command.rb8
-rw-r--r--lib/rubygems/commands/query_command.rb6
-rw-r--r--lib/rubygems/commands/rdoc_command.rb6
-rw-r--r--lib/rubygems/commands/search_command.rb4
-rw-r--r--lib/rubygems/commands/server_command.rb6
-rw-r--r--lib/rubygems/commands/setup_command.rb26
-rw-r--r--lib/rubygems/commands/signin_command.rb4
-rw-r--r--lib/rubygems/commands/signout_command.rb2
-rw-r--r--lib/rubygems/commands/sources_command.rb8
-rw-r--r--lib/rubygems/commands/specification_command.rb8
-rw-r--r--lib/rubygems/commands/stale_command.rb2
-rw-r--r--lib/rubygems/commands/uninstall_command.rb6
-rw-r--r--lib/rubygems/commands/unpack_command.rb10
-rw-r--r--lib/rubygems/commands/update_command.rb18
-rw-r--r--lib/rubygems/commands/which_command.rb2
-rw-r--r--lib/rubygems/commands/yank_command.rb8
-rw-r--r--lib/rubygems/config_file.rb10
-rw-r--r--lib/rubygems/core_ext/tcpsocket_init.rb4
-rw-r--r--lib/rubygems/defaults.rb22
-rw-r--r--lib/rubygems/dependency_installer.rb16
-rw-r--r--lib/rubygems/dependency_list.rb2
-rw-r--r--lib/rubygems/deprecate.rb59
-rw-r--r--lib/rubygems/doctor.rb4
-rw-r--r--lib/rubygems/errors.rb3
-rw-r--r--lib/rubygems/exceptions.rb6
-rw-r--r--lib/rubygems/ext/builder.rb1
-rw-r--r--lib/rubygems/ext/ext_conf_builder.rb11
-rw-r--r--lib/rubygems/ext/rake_builder.rb3
-rw-r--r--lib/rubygems/gem_runner.rb6
-rw-r--r--lib/rubygems/gemcutter_utilities.rb20
-rw-r--r--lib/rubygems/indexer.rb4
-rw-r--r--lib/rubygems/install_default_message.rb4
-rw-r--r--lib/rubygems/install_message.rb4
-rw-r--r--lib/rubygems/install_update_options.rb4
-rw-r--r--lib/rubygems/installer.rb31
-rw-r--r--lib/rubygems/local_remote_options.rb2
-rw-r--r--lib/rubygems/mock_gem_ui.rb2
-rw-r--r--lib/rubygems/name_tuple.rb5
-rw-r--r--lib/rubygems/package.rb24
-rw-r--r--lib/rubygems/package/io_source.rb4
-rw-r--r--lib/rubygems/package/tar_reader.rb2
-rw-r--r--lib/rubygems/package_task.rb4
-rw-r--r--lib/rubygems/path_support.rb7
-rw-r--r--lib/rubygems/platform.rb7
-rw-r--r--lib/rubygems/rdoc.rb2
-rw-r--r--lib/rubygems/remote_fetcher.rb37
-rw-r--r--lib/rubygems/request.rb12
-rw-r--r--lib/rubygems/request/connection_pools.rb2
-rw-r--r--lib/rubygems/request/http_pool.rb2
-rw-r--r--lib/rubygems/request_set.rb10
-rw-r--r--lib/rubygems/request_set/lockfile.rb2
-rw-r--r--lib/rubygems/request_set/lockfile/tokenizer.rb2
-rw-r--r--lib/rubygems/requirement.rb25
-rw-r--r--lib/rubygems/resolver.rb62
-rw-r--r--lib/rubygems/resolver/git_specification.rb2
-rw-r--r--lib/rubygems/resolver/installer_set.rb8
-rw-r--r--lib/rubygems/resolver/molinillo.rb2
-rw-r--r--lib/rubygems/resolver/set.rb1
-rw-r--r--lib/rubygems/resolver/specification.rb2
-rw-r--r--lib/rubygems/s3_uri_signer.rb1
-rw-r--r--lib/rubygems/safe_yaml.rb2
-rw-r--r--lib/rubygems/security.rb10
-rw-r--r--lib/rubygems/security/policy.rb2
-rw-r--r--lib/rubygems/security/signer.rb2
-rw-r--r--lib/rubygems/security_option.rb4
-rw-r--r--lib/rubygems/server.rb4
-rw-r--r--lib/rubygems/source.rb12
-rw-r--r--lib/rubygems/spec_fetcher.rb10
-rw-r--r--lib/rubygems/specification.rb38
-rw-r--r--lib/rubygems/specification_policy.rb13
-rw-r--r--lib/rubygems/syck_hack.rb77
-rw-r--r--lib/rubygems/uninstaller.rb58
-rw-r--r--lib/rubygems/uri.rb111
-rw-r--r--lib/rubygems/uri_parser.rb34
-rw-r--r--lib/rubygems/uri_parsing.rb23
-rw-r--r--lib/rubygems/user_interaction.rb6
-rw-r--r--lib/rubygems/util/licenses.rb111
-rw-r--r--lib/rubygems/validator.rb4
-rw-r--r--lib/rubygems/version_option.rb2
-rw-r--r--lib/securerandom.rb2
-rw-r--r--lib/set.rb32
-rw-r--r--lib/set/set.gemspec2
-rw-r--r--lib/tempfile.rb6
-rw-r--r--lib/un.gemspec3
-rw-r--r--lib/un.rb39
-rw-r--r--lib/unicode_normalize/tables.rb36
-rw-r--r--lib/uri.rb3
-rw-r--r--lib/uri/common.rb30
-rw-r--r--lib/uri/file.rb2
-rw-r--r--lib/uri/ftp.rb3
-rw-r--r--lib/uri/http.rb3
-rw-r--r--lib/uri/https.rb3
-rw-r--r--lib/uri/ldap.rb2
-rw-r--r--lib/uri/ldaps.rb3
-rw-r--r--lib/uri/mailto.rb2
-rw-r--r--lib/uri/ws.rb3
-rw-r--r--lib/uri/wss.rb3
292 files changed, 4188 insertions, 2452 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index 9f7f9b2..f2d874b 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -37,7 +37,7 @@ module Bundler
environment_preserver = EnvironmentPreserver.from_env
ORIGINAL_ENV = environment_preserver.restore
environment_preserver.replace_with_backup
- SUDO_MUTEX = Mutex.new
+ SUDO_MUTEX = Thread::Mutex.new
autoload :Definition, File.expand_path("bundler/definition", __dir__)
autoload :Dependency, File.expand_path("bundler/dependency", __dir__)
@@ -69,6 +69,7 @@ module Bundler
autoload :SharedHelpers, File.expand_path("bundler/shared_helpers", __dir__)
autoload :Source, File.expand_path("bundler/source", __dir__)
autoload :SourceList, File.expand_path("bundler/source_list", __dir__)
+ autoload :SourceMap, File.expand_path("bundler/source_map", __dir__)
autoload :SpecSet, File.expand_path("bundler/spec_set", __dir__)
autoload :StubSpecification, File.expand_path("bundler/stub_specification", __dir__)
autoload :UI, File.expand_path("bundler/ui", __dir__)
@@ -235,8 +236,9 @@ module Bundler
end
if warning
- user_home = tmp_home_path(warning)
- Bundler.ui.warn "#{warning}\nBundler will use `#{user_home}' as your home directory temporarily.\n"
+ Bundler.ui.warn "#{warning}\n"
+ user_home = tmp_home_path
+ Bundler.ui.warn "Bundler will use `#{user_home}' as your home directory temporarily.\n"
user_home
else
Pathname.new(home)
@@ -634,15 +636,19 @@ EOF
@rubygems = nil
end
+ def configure_gem_home_and_path(path = bundle_path)
+ configure_gem_path
+ configure_gem_home(path)
+ Bundler.rubygems.clear_paths
+ end
+
private
def eval_yaml_gemspec(path, contents)
require_relative "bundler/psyched_yaml"
- # If the YAML is invalid, Syck raises an ArgumentError, and Psych
- # raises a Psych::SyntaxError. See psyched_yaml.rb for more info.
Gem::Specification.from_yaml(contents)
- rescue YamlLibrarySyntaxError, ArgumentError, Gem::EndOfYAMLException, Gem::Exception
+ rescue ::Psych::SyntaxError, ArgumentError, Gem::EndOfYAMLException, Gem::Exception
eval_gemspec(path, contents)
end
@@ -651,47 +657,29 @@ EOF
rescue ScriptError, StandardError => e
msg = "There was an error while loading `#{path.basename}`: #{e.message}"
- if e.is_a?(LoadError)
- msg += "\nDoes it try to require a relative path? That's been removed in Ruby 1.9"
- end
-
raise GemspecError, Dsl::DSLError.new(msg, path, e.backtrace, contents)
end
- def configure_gem_home_and_path
- configure_gem_path
- configure_gem_home
- bundle_path
- end
-
- def configure_gem_path(env = ENV)
- blank_home = env["GEM_HOME"].nil? || env["GEM_HOME"].empty?
- if !use_system_gems?
+ def configure_gem_path
+ unless use_system_gems?
# this needs to be empty string to cause
# PathSupport.split_gem_path to only load up the
# Bundler --path setting as the GEM_PATH.
- env["GEM_PATH"] = ""
- elsif blank_home
- possibles = [Bundler.rubygems.gem_dir, Bundler.rubygems.gem_path]
- paths = possibles.flatten.compact.uniq.reject(&:empty?)
- env["GEM_PATH"] = paths.join(File::PATH_SEPARATOR)
+ Bundler::SharedHelpers.set_env "GEM_PATH", ""
end
end
- def configure_gem_home
- Bundler::SharedHelpers.set_env "GEM_HOME", File.expand_path(bundle_path, root)
- Bundler.rubygems.clear_paths
+ def configure_gem_home(path)
+ Bundler::SharedHelpers.set_env "GEM_HOME", path.to_s
end
- def tmp_home_path(warning)
+ def tmp_home_path
Kernel.send(:require, "tmpdir")
SharedHelpers.filesystem_access(Dir.tmpdir) do
path = Bundler.tmp
at_exit { Bundler.rm_rf(path) }
path
end
- rescue RuntimeError => e
- raise e.exception("#{warning}\nBundler also failed to create a temporary home directory':\n#{e}")
end
# @param env [Hash]
diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb
index 6562f3a..d5de72e 100644
--- a/lib/bundler/cli.rb
+++ b/lib/bundler/cli.rb
@@ -14,6 +14,7 @@ module Bundler
COMMAND_ALIASES = {
"check" => "c",
"install" => "i",
+ "plugin" => "",
"list" => "ls",
"exec" => ["e", "ex", "exe"],
"cache" => ["package", "pack"],
@@ -72,14 +73,6 @@ module Bundler
Bundler.ui = UI::Shell.new(options)
Bundler.ui.level = "debug" if options["verbose"]
unprinted_warnings.each {|w| Bundler.ui.warn(w) }
-
- if ENV["RUBYGEMS_GEMDEPS"] && !ENV["RUBYGEMS_GEMDEPS"].empty?
- Bundler.ui.warn(
- "The RUBYGEMS_GEMDEPS environment variable is set. This enables RubyGems' " \
- "experimental Gemfile mode, which may conflict with Bundler and cause unexpected errors. " \
- "To remove this warning, unset RUBYGEMS_GEMDEPS.", :wrap => true
- )
- end
end
check_unknown_options!(:except => [:config, :exec])
@@ -191,6 +184,7 @@ module Bundler
method_option "install", :type => :boolean, :banner =>
"Runs 'bundle install' after removing the gems from the Gemfile"
def remove(*gems)
+ SharedHelpers.major_deprecation(2, "The `--install` flag has been deprecated. `bundle install` is triggered by default.") if ARGV.include?("--install")
require_relative "cli/remove"
Remove.new(gems, options).run
end
@@ -308,39 +302,19 @@ module Bundler
end
end
- unless Bundler.feature_flag.bundler_3_mode?
- desc "show GEM [OPTIONS]", "Shows all gems that are part of the bundle, or the path to a given gem"
- long_desc <<-D
- Show lists the names and versions of all gems that are required by your Gemfile.
- Calling show with [GEM] will list the exact location of that gem on your machine.
- D
- method_option "paths", :type => :boolean,
- :banner => "List the paths of all gems that are required by your Gemfile."
- method_option "outdated", :type => :boolean,
- :banner => "Show verbose output including whether gems are outdated."
- def show(gem_name = nil)
- if ARGV[0] == "show"
- rest = ARGV[1..-1]
-
- if flag = rest.find{|arg| ["--verbose", "--outdated"].include?(arg) }
- Bundler::SharedHelpers.major_deprecation(2, "the `#{flag}` flag to `bundle show` was undocumented and will be removed without replacement")
- else
- new_command = rest.find {|arg| !arg.start_with?("--") } ? "info" : "list"
-
- new_arguments = rest.map do |arg|
- next arg if arg != "--paths"
- next "--path" if new_command == "info"
- end
-
- old_argv = ARGV.join(" ")
- new_argv = [new_command, *new_arguments.compact].join(" ")
-
- Bundler::SharedHelpers.major_deprecation(2, "use `bundle #{new_argv}` instead of `bundle #{old_argv}`")
- end
- end
- require_relative "cli/show"
- Show.new(options, gem_name).run
- end
+ desc "show GEM [OPTIONS]", "Shows all gems that are part of the bundle, or the path to a given gem"
+ long_desc <<-D
+ Show lists the names and versions of all gems that are required by your Gemfile.
+ Calling show with [GEM] will list the exact location of that gem on your machine.
+ D
+ method_option "paths", :type => :boolean,
+ :banner => "List the paths of all gems that are required by your Gemfile."
+ method_option "outdated", :type => :boolean,
+ :banner => "Show verbose output including whether gems are outdated."
+ def show(gem_name = nil)
+ SharedHelpers.major_deprecation(2, "the `--outdated` flag to `bundle show` was undocumented and will be removed without replacement") if ARGV.include?("--outdated")
+ require_relative "cli/show"
+ Show.new(options, gem_name).run
end
desc "list", "List all gems in the bundle"
@@ -488,7 +462,7 @@ module Bundler
map aliases_for("cache")
desc "exec [OPTIONS]", "Run the command in context of the bundle"
- method_option :keep_file_descriptors, :type => :boolean, :default => false
+ method_option :keep_file_descriptors, :type => :boolean, :default => true
method_option :gemfile, :type => :string, :required => false
long_desc <<-D
Exec runs a command, providing it access to the gems in the bundle. While using
@@ -496,6 +470,10 @@ module Bundler
into the system wide RubyGems repository.
D
def exec(*args)
+ if ARGV.include?("--no-keep-file-descriptors")
+ SharedHelpers.major_deprecation(2, "The `--no-keep-file-descriptors` has been deprecated. `bundle exec` no longer mess with your file descriptors. Close them in the exec'd script if you need to")
+ end
+
require_relative "cli/exec"
Exec.new(options, args).run
end
diff --git a/lib/bundler/cli/cache.rb b/lib/bundler/cli/cache.rb
index 9cd6133..c8698ed 100644
--- a/lib/bundler/cli/cache.rb
+++ b/lib/bundler/cli/cache.rb
@@ -9,7 +9,7 @@ module Bundler
end
def run
- Bundler.ui.level = "error" if options[:quiet]
+ Bundler.ui.level = "warn" if options[:quiet]
Bundler.settings.set_command_option_if_given :path, options[:path]
Bundler.settings.set_command_option_if_given :cache_path, options["cache-path"]
diff --git a/lib/bundler/cli/check.rb b/lib/bundler/cli/check.rb
index 19c0aae..65c5133 100644
--- a/lib/bundler/cli/check.rb
+++ b/lib/bundler/cli/check.rb
@@ -11,9 +11,11 @@ module Bundler
def run
Bundler.settings.set_command_option_if_given :path, options[:path]
+ definition = Bundler.definition
+ definition.validate_runtime!
+
begin
- definition = Bundler.definition
- definition.validate_runtime!
+ definition.resolve_only_locally!
not_installed = definition.missing_specs
rescue GemNotFound, VersionConflict
Bundler.ui.error "Bundler can't satisfy your Gemfile's dependencies."
diff --git a/lib/bundler/cli/doctor.rb b/lib/bundler/cli/doctor.rb
index 2986ddbc..c28997b 100644
--- a/lib/bundler/cli/doctor.rb
+++ b/lib/bundler/cli/doctor.rb
@@ -61,7 +61,7 @@ module Bundler
end
def run
- Bundler.ui.level = "error" if options[:quiet]
+ Bundler.ui.level = "warn" if options[:quiet]
Bundler.settings.validate!
check!
@@ -100,8 +100,11 @@ module Bundler
files_not_readable_or_writable = []
files_not_rw_and_owned_by_different_user = []
files_not_owned_by_current_user_but_still_rw = []
+ broken_symlinks = []
Find.find(Bundler.bundle_path.to_s).each do |f|
- if !File.writable?(f) || !File.readable?(f)
+ if !File.exist?(f)
+ broken_symlinks << f
+ elsif !File.writable?(f) || !File.readable?(f)
if File.stat(f).uid != Process.uid
files_not_rw_and_owned_by_different_user << f
else
@@ -113,6 +116,13 @@ module Bundler
end
ok = true
+
+ if broken_symlinks.any?
+ Bundler.ui.warn "Broken links exist in the Bundler home. Please report them to the offending gem's upstream repo. These files are:\n - #{broken_symlinks.join("\n - ")}"
+
+ ok = false
+ end
+
if files_not_owned_by_current_user_but_still_rw.any?
Bundler.ui.warn "Files exist in the Bundler home that are owned by another " \
"user, but are still readable/writable. These files are:\n - #{files_not_owned_by_current_user_but_still_rw.join("\n - ")}"
diff --git a/lib/bundler/cli/exec.rb b/lib/bundler/cli/exec.rb
index 318d57f..42b602a 100644
--- a/lib/bundler/cli/exec.rb
+++ b/lib/bundler/cli/exec.rb
@@ -12,12 +12,7 @@ module Bundler
@options = options
@cmd = args.shift
@args = args
-
- if !Bundler.current_ruby.jruby?
- @args << { :close_others => !options.keep_file_descriptors? }
- elsif options.keep_file_descriptors?
- Bundler.ui.warn "Ruby version #{RUBY_VERSION} defaults to keeping non-standard file descriptors on Kernel#exec."
- end
+ @args << { :close_others => !options.keep_file_descriptors? } unless Bundler.current_ruby.jruby?
end
def run
diff --git a/lib/bundler/cli/gem.rb b/lib/bundler/cli/gem.rb
index c9794c4..a034aea 100644
--- a/lib/bundler/cli/gem.rb
+++ b/lib/bundler/cli/gem.rb
@@ -185,14 +185,15 @@ module Bundler
)
end
- if File.exist?(target) && !File.directory?(target)
+ if target.exist? && !target.directory?
Bundler.ui.error "Couldn't create a new gem named `#{gem_name}` because there's an existing file named `#{gem_name}`."
exit Bundler::BundlerError.all_errors[Bundler::GenericSystemCallError]
end
if use_git
Bundler.ui.info "Initializing git repo in #{target}"
- `git init #{target}`
+ require "shellwords"
+ `git init #{target.to_s.shellescape}`
config[:git_default_branch] = File.read("#{target}/.git/HEAD").split("/").last.chomp
end
diff --git a/lib/bundler/cli/install.rb b/lib/bundler/cli/install.rb
index cfbf4be..4c1915f 100644
--- a/lib/bundler/cli/install.rb
+++ b/lib/bundler/cli/install.rb
@@ -8,7 +8,7 @@ module Bundler
end
def run
- Bundler.ui.level = "error" if options[:quiet]
+ Bundler.ui.level = "warn" if options[:quiet]
warn_if_root
@@ -58,7 +58,10 @@ module Bundler
definition.validate_runtime!
installer = Installer.install(Bundler.root, definition, options)
- Bundler.load.cache if Bundler.app_cache.exist? && !options["no-cache"] && !Bundler.frozen_bundle?
+
+ Bundler.settings.temporary(:cache_all_platforms => options[:local] ? false : Bundler.settings[:cache_all_platforms]) do
+ Bundler.load.cache(nil, options[:local]) if Bundler.app_cache.exist? && !options["no-cache"] && !Bundler.frozen_bundle?
+ end
Bundler.ui.confirm "Bundle complete! #{dependencies_count_for(definition)}, #{gems_installed_for(definition)}."
Bundler::CLI::Common.output_without_groups_message(:install)
@@ -80,28 +83,15 @@ module Bundler
end
Bundler::CLI::Common.output_fund_metadata_summary
- rescue GemNotFound, VersionConflict => e
- if options[:local] && Bundler.app_cache.exist?
- Bundler.ui.warn "Some gems seem to be missing from your #{Bundler.settings.app_cache_path} directory."
- end
-
- unless Bundler.definition.has_rubygems_remotes?
- Bundler.ui.warn <<-WARN, :wrap => true
- Your Gemfile has no gem server sources. If you need gems that are \
- not already on your machine, add a line like this to your Gemfile:
- source 'https://rubygems.org'
- WARN
- end
- raise e
- rescue Gem::InvalidSpecificationException => e
+ rescue Gem::InvalidSpecificationException
Bundler.ui.warn "You have one or more invalid gemspecs that need to be fixed."
- raise e
+ raise
end
private
def warn_if_root
- return if Bundler.settings[:silence_root_warning] || Bundler::WINDOWS || !Process.uid.zero?
+ return if Bundler.settings[:silence_root_warning] || Gem.win_platform? || !Process.uid.zero?
Bundler.ui.warn "Don't run Bundler as root. Bundler can ask for sudo " \
"if it is needed, and installing your bundle as root will break this " \
"application for all non-root users on this machine.", :wrap => true
diff --git a/lib/bundler/cli/list.rb b/lib/bundler/cli/list.rb
index 66abd32..f56bf5b 100644
--- a/lib/bundler/cli/list.rb
+++ b/lib/bundler/cli/list.rb
@@ -16,7 +16,13 @@ module Bundler
specs = if @only_group.any? || @without_group.any?
filtered_specs_by_groups
else
- Bundler.load.specs
+ begin
+ Bundler.load.specs
+ rescue GemNotFound => e
+ Bundler.ui.error e.message
+ Bundler.ui.warn "Install missing gems with `bundle install`."
+ exit 1
+ end
end.reject {|s| s.name == "bundler" }.sort_by(&:name)
return Bundler.ui.info "No gems in the Gemfile" if specs.empty?
diff --git a/lib/bundler/cli/lock.rb b/lib/bundler/cli/lock.rb
index 7dd078b..7d613a6 100644
--- a/lib/bundler/cli/lock.rb
+++ b/lib/bundler/cli/lock.rb
@@ -21,9 +21,13 @@ module Bundler
Bundler::Fetcher.disable_endpoint = options["full-index"]
update = options[:update]
+ conservative = options[:conservative]
+
if update.is_a?(Array) # unlocking specific gems
Bundler::CLI::Common.ensure_all_gems_in_lockfile!(update)
- update = { :gems => update, :lock_shared_dependencies => options[:conservative] }
+ update = { :gems => update, :conservative => conservative }
+ elsif update
+ update = { :conservative => conservative } if conservative
end
definition = Bundler.definition(update)
diff --git a/lib/bundler/cli/open.rb b/lib/bundler/cli/open.rb
index df32e2f..ea50434 100644
--- a/lib/bundler/cli/open.rb
+++ b/lib/bundler/cli/open.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require "shellwords"
-
module Bundler
class CLI::Open
attr_reader :options, :name
@@ -19,6 +17,7 @@ module Bundler
else
path = spec.full_gem_path
Dir.chdir(path) do
+ require "shellwords"
command = Shellwords.split(editor) + [path]
Bundler.with_original_env do
system(*command)
diff --git a/lib/bundler/cli/outdated.rb b/lib/bundler/cli/outdated.rb
index e5d9af4..d5183b0 100644
--- a/lib/bundler/cli/outdated.rb
+++ b/lib/bundler/cli/outdated.rb
@@ -146,17 +146,16 @@ module Bundler
end
def retrieve_active_spec(definition, current_spec)
- if strict
- active_spec = definition.find_resolved_spec(current_spec)
- else
- active_specs = definition.find_indexed_specs(current_spec)
- if !current_spec.version.prerelease? && !options[:pre] && active_specs.size > 1
- active_specs.delete_if {|b| b.respond_to?(:version) && b.version.prerelease? }
- end
- active_spec = active_specs.last
- end
+ active_spec = definition.resolve.find_by_name_and_platform(current_spec.name, current_spec.platform)
+ return unless active_spec
- active_spec
+ return active_spec if strict
+
+ active_specs = active_spec.source.specs.search(current_spec.name).select {|spec| spec.match_platform(current_spec.platform) }.sort_by(&:version)
+ if !current_spec.version.prerelease? && !options[:pre] && active_specs.size > 1
+ active_specs.delete_if {|b| b.respond_to?(:version) && b.version.prerelease? }
+ end
+ active_specs.last
end
def print_gems(gems_list)
diff --git a/lib/bundler/cli/remove.rb b/lib/bundler/cli/remove.rb
index cd6a2ce..44a4d89 100644
--- a/lib/bundler/cli/remove.rb
+++ b/lib/bundler/cli/remove.rb
@@ -11,8 +11,7 @@ module Bundler
raise InvalidOption, "Please specify gems to remove." if @gems.empty?
Injector.remove(@gems, {})
-
- Installer.install(Bundler.root, Bundler.definition) if @options["install"]
+ Installer.install(Bundler.root, Bundler.definition)
end
end
end
diff --git a/lib/bundler/cli/update.rb b/lib/bundler/cli/update.rb
index 9469948..1adcaef 100644
--- a/lib/bundler/cli/update.rb
+++ b/lib/bundler/cli/update.rb
@@ -9,7 +9,7 @@ module Bundler
end
def run
- Bundler.ui.level = "error" if options[:quiet]
+ Bundler.ui.level = "warn" if options[:quiet]
Plugin.gemfile_install(Bundler.default_gemfile) if Bundler.feature_flag.plugins?
@@ -27,9 +27,14 @@ module Bundler
raise InvalidOption, "Cannot specify --all along with specific options."
end
+ conservative = options[:conservative]
+
if full_update
- # We're doing a full update
- Bundler.definition(true)
+ if conservative
+ Bundler.definition(:conservative => conservative)
+ else
+ Bundler.definition(true)
+ end
else
unless Bundler.default_lockfile.exist?
raise GemfileLockNotFound, "This Bundle hasn't been installed yet. " \
@@ -43,7 +48,7 @@ module Bundler
end
Bundler.definition(:gems => gems, :sources => sources, :ruby => options[:ruby],
- :lock_shared_dependencies => options[:conservative],
+ :conservative => conservative,
:bundler => options[:bundler])
end
diff --git a/lib/bundler/compact_index_client.rb b/lib/bundler/compact_index_client.rb
index cf67f0e..d5dbeb3 100644
--- a/lib/bundler/compact_index_client.rb
+++ b/lib/bundler/compact_index_client.rb
@@ -5,7 +5,7 @@ require "set"
module Bundler
class CompactIndexClient
- DEBUG_MUTEX = Mutex.new
+ DEBUG_MUTEX = Thread::Mutex.new
def self.debug
return unless ENV["DEBUG_COMPACT_INDEX"]
DEBUG_MUTEX.synchronize { warn("[#{self}] #{yield}") }
@@ -25,7 +25,7 @@ module Bundler
@endpoints = Set.new
@info_checksums_by_name = {}
@parsed_checksums = false
- @mutex = Mutex.new
+ @mutex = Thread::Mutex.new
end
def execution_mode=(block)
diff --git a/lib/bundler/current_ruby.rb b/lib/bundler/current_ruby.rb
index b8c7cad..f84d68e 100644
--- a/lib/bundler/current_ruby.rb
+++ b/lib/bundler/current_ruby.rb
@@ -65,19 +65,19 @@ module Bundler
end
def mswin?
- Bundler::WINDOWS
+ Gem.win_platform?
end
def mswin64?
- Bundler::WINDOWS && Bundler.local_platform != Gem::Platform::RUBY && Bundler.local_platform.os == "mswin64" && Bundler.local_platform.cpu == "x64"
+ Gem.win_platform? && Bundler.local_platform != Gem::Platform::RUBY && Bundler.local_platform.os == "mswin64" && Bundler.local_platform.cpu == "x64"
end
def mingw?
- Bundler::WINDOWS && Bundler.local_platform != Gem::Platform::RUBY && Bundler.local_platform.os == "mingw32" && Bundler.local_platform.cpu != "x64"
+ Gem.win_platform? && Bundler.local_platform != Gem::Platform::RUBY && Bundler.local_platform.os == "mingw32" && Bundler.local_platform.cpu != "x64"
end
def x64_mingw?
- Bundler::WINDOWS && Bundler.local_platform != Gem::Platform::RUBY && Bundler.local_platform.os == "mingw32" && Bundler.local_platform.cpu == "x64"
+ Gem.win_platform? && Bundler.local_platform != Gem::Platform::RUBY && Bundler.local_platform.os == "mingw32" && Bundler.local_platform.cpu == "x64"
end
(KNOWN_MINOR_VERSIONS + KNOWN_MAJOR_VERSIONS).each do |version|
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb
index fc30dd5..2bd1290 100644
--- a/lib/bundler/definition.rb
+++ b/lib/bundler/definition.rb
@@ -61,10 +61,8 @@ module Bundler
@unlocking_bundler = false
@unlocking = unlock
else
- unlock = unlock.dup
@unlocking_bundler = unlock.delete(:bundler)
- unlock.delete_if {|_k, v| Array(v).empty? }
- @unlocking = !unlock.empty?
+ @unlocking = unlock.any? {|_k, v| !Array(v).empty? }
end
@dependencies = dependencies
@@ -111,18 +109,19 @@ module Bundler
@locked_platforms = []
end
- @locked_gem_sources = @locked_sources.select {|s| s.is_a?(Source::Rubygems) }
- @disable_multisource = @locked_gem_sources.all?(&:disable_multisource?)
+ locked_gem_sources = @locked_sources.select {|s| s.is_a?(Source::Rubygems) }
+ @multisource_allowed = locked_gem_sources.size == 1 && locked_gem_sources.first.multiple_remotes? && Bundler.frozen_bundle?
- unless @disable_multisource
- msg = "Your lockfile contains a single rubygems source section with multiple remotes, which is insecure. You should run `bundle update` or generate your lockfile from scratch."
+ if @multisource_allowed
+ unless sources.aggregate_global_source?
+ msg = "Your lockfile contains a single rubygems source section with multiple remotes, which is insecure. Make sure you run `bundle install` in non frozen mode and commit the result to make your lockfile secure."
- Bundler::SharedHelpers.major_deprecation 2, msg
+ Bundler::SharedHelpers.major_deprecation 2, msg
+ end
- @sources.merged_gem_lockfile_sections!
+ @sources.merged_gem_lockfile_sections!(locked_gem_sources.first)
end
- @unlock[:gems] ||= []
@unlock[:sources] ||= []
@unlock[:ruby] ||= if @ruby_version && locked_ruby_version_object
@ruby_version.diff(locked_ruby_version_object)
@@ -135,9 +134,11 @@ module Bundler
@path_changes = converge_paths
@source_changes = converge_sources
- unless @unlock[:lock_shared_dependencies]
- eager_unlock = expand_dependencies(@unlock[:gems], true)
- @unlock[:gems] = @locked_specs.for(eager_unlock, [], false, false, false).map(&:name)
+ if @unlock[:conservative]
+ @unlock[:gems] ||= @dependencies.map(&:name)
+ else
+ eager_unlock = expand_dependencies(@unlock[:gems] || [], true)
+ @unlock[:gems] = @locked_specs.for(eager_unlock, false, false).map(&:name)
end
@dependency_changes = converge_dependencies
@@ -161,8 +162,14 @@ module Bundler
end
end
- def disable_multisource?
- @disable_multisource
+ def multisource_allowed?
+ @multisource_allowed
+ end
+
+ def resolve_only_locally!
+ @remote = false
+ sources.local_only!
+ resolve
end
def resolve_with_cache!
@@ -183,25 +190,7 @@ module Bundler
#
# @return [Bundler::SpecSet]
def specs
- @specs ||= begin
- begin
- specs = resolve.materialize(requested_dependencies)
- rescue GemNotFound => e # Handle yanked gem
- gem_name, gem_version = extract_gem_info(e)
- locked_gem = @locked_specs[gem_name].last
- raise if locked_gem.nil? || locked_gem.version.to_s != gem_version || !@remote
- raise GemNotFound, "Your bundle is locked to #{locked_gem} from #{locked_gem.source}, but that version can " \
- "no longer be found in that source. That means the author of #{locked_gem} has removed it. " \
- "You'll need to update your bundle to a version other than #{locked_gem} that hasn't been " \
- "removed in order to install."
- end
- unless specs["bundler"].any?
- bundler = sources.metadata_source.specs.search(Gem::Dependency.new("bundler", VERSION)).last
- specs["bundler"] = bundler
- end
-
- specs
- end
+ @specs ||= materialize(requested_dependencies)
end
def new_specs
@@ -213,9 +202,7 @@ module Bundler
end
def missing_specs
- missing = []
- resolve.materialize(requested_dependencies, missing)
- missing
+ resolve.materialize(requested_dependencies).missing_specs
end
def missing_specs?
@@ -224,7 +211,6 @@ module Bundler
Bundler.ui.debug "The definition is missing #{missing.map(&:full_name)}"
true
rescue BundlerError => e
- @index = nil
@resolve = nil
@specs = nil
@gem_version_promoter = nil
@@ -234,17 +220,11 @@ module Bundler
end
def requested_specs
- @requested_specs ||= begin
- groups = requested_groups
- groups.map!(&:to_sym)
- specs_for(groups)
- end
+ specs_for(requested_groups)
end
def requested_dependencies
- groups = requested_groups
- groups.map!(&:to_sym)
- dependencies_for(groups)
+ dependencies_for(requested_groups)
end
def current_dependencies
@@ -254,11 +234,13 @@ module Bundler
end
def specs_for(groups)
+ groups = requested_groups if groups.empty?
deps = dependencies_for(groups)
- specs.for(expand_dependencies(deps))
+ materialize(expand_dependencies(deps))
end
def dependencies_for(groups)
+ groups.map!(&:to_sym)
current_dependencies.reject do |d|
(d.groups & groups).empty?
end
@@ -287,54 +269,6 @@ module Bundler
end
end
- def index
- @index ||= Index.build do |idx|
- dependency_names = @dependencies.map(&:name)
-
- sources.all_sources.each do |source|
- source.dependency_names = dependency_names - pinned_spec_names(source)
- idx.add_source source.specs
- dependency_names.concat(source.unmet_deps).uniq!
- end
-
- double_check_for_index(idx, dependency_names)
- end
- end
-
- # Suppose the gem Foo depends on the gem Bar. Foo exists in Source A. Bar has some versions that exist in both
- # sources A and B. At this point, the API request will have found all the versions of Bar in source A,
- # but will not have found any versions of Bar from source B, which is a problem if the requested version
- # of Foo specifically depends on a version of Bar that is only found in source B. This ensures that for
- # each spec we found, we add all possible versions from all sources to the index.
- def double_check_for_index(idx, dependency_names)
- pinned_names = pinned_spec_names
- loop do
- idxcount = idx.size
-
- names = :names # do this so we only have to traverse to get dependency_names from the index once
- unmet_dependency_names = lambda do
- return names unless names == :names
- new_names = sources.all_sources.map(&:dependency_names_to_double_check)
- return names = nil if new_names.compact!
- names = new_names.flatten(1).concat(dependency_names)
- names.uniq!
- names -= pinned_names
- names
- end
-
- sources.all_sources.each do |source|
- source.double_check_for(unmet_dependency_names)
- end
-
- break if idxcount == idx.size
- end
- end
- private :double_check_for_index
-
- def has_rubygems_remotes?
- sources.rubygems_sources.any? {|s| s.remotes.any? }
- end
-
def spec_git_paths
sources.git_sources.map {|s| File.realpath(s.path) if File.exist?(s.path) }.compact
end
@@ -539,20 +473,9 @@ module Bundler
end
end
- def find_resolved_spec(current_spec)
- specs.find_by_name_and_platform(current_spec.name, current_spec.platform)
- end
-
- def find_indexed_specs(current_spec)
- index[current_spec.name].select {|spec| spec.match_platform(current_spec.platform) }.sort_by(&:version)
- end
-
attr_reader :sources
private :sources
- attr_reader :locked_gem_sources
- private :locked_gem_sources
-
def nothing_changed?
!@source_changes && !@dependency_changes && !@new_platform && !@path_changes && !@local_changes && !@locked_specs_incomplete_for_platform
end
@@ -563,6 +486,35 @@ module Bundler
private
+ def materialize(dependencies)
+ specs = resolve.materialize(dependencies)
+ missing_specs = specs.missing_specs
+
+ if missing_specs.any?
+ missing_specs.each do |s|
+ locked_gem = @locked_specs[s.name].last
+ next if locked_gem.nil? || locked_gem.version != s.version || !@remote
+ raise GemNotFound, "Your bundle is locked to #{locked_gem} from #{locked_gem.source}, but that version can " \
+ "no longer be found in that source. That means the author of #{locked_gem} has removed it. " \
+ "You'll need to update your bundle to a version other than #{locked_gem} that hasn't been " \
+ "removed in order to install."
+ end
+
+ raise GemNotFound, "Could not find #{missing_specs.map(&:full_name).join(", ")} in any of the sources"
+ end
+
+ unless specs["bundler"].any?
+ bundler = sources.metadata_source.specs.search(Gem::Dependency.new("bundler", VERSION)).last
+ specs["bundler"] = bundler
+ end
+
+ specs
+ end
+
+ def precompute_source_requirements_for_indirect_dependencies?
+ @remote && sources.non_global_rubygems_sources.all?(&:dependency_api_available?) && !sources.aggregate_global_source?
+ end
+
def current_ruby_platform_locked?
return false unless generic_local_platform == Gem::Platform::RUBY
@@ -676,35 +628,11 @@ module Bundler
end
end
- def converge_rubygems_sources
- return false if disable_multisource?
-
- return false if locked_gem_sources.empty?
-
- # Get the RubyGems remotes from the Gemfile
- actual_remotes = sources.rubygems_remotes
- return false if actual_remotes.empty?
-
- changes = false
-
- # If there is a RubyGems source in both
- locked_gem_sources.each do |locked_gem|
- # Merge the remotes from the Gemfile into the Gemfile.lock
- changes |= locked_gem.replace_remotes(actual_remotes, Bundler.settings[:allow_deployment_source_credential_changes])
- end
-
- changes
- end
-
def converge_sources
- changes = false
-
- changes |= converge_rubygems_sources
-
# Replace the sources from the Gemfile with the sources from the Gemfile.lock,
# if they exist in the Gemfile.lock and are `==`. If you can't find an equivalent
# source in the Gemfile.lock, use the one from the Gemfile.
- changes |= sources.replace_sources!(@locked_sources)
+ changes = sources.replace_sources!(@locked_sources)
sources.all_sources.each do |source|
# If the source is unlockable and the current command allows an unlock of
@@ -789,24 +717,17 @@ module Bundler
end
end
- unlock_source_unlocks_spec = Bundler.feature_flag.unlock_source_unlocks_spec?
-
converged = []
@locked_specs.each do |s|
# Replace the locked dependency's source with the equivalent source from the Gemfile
dep = @dependencies.find {|d| s.satisfies?(d) }
- s.source = (dep && dep.source) || sources.get(s.source)
+ s.source = (dep && dep.source) || sources.get(s.source) unless multisource_allowed?
# Don't add a spec to the list if its source is expired. For example,
# if you change a Git gem to RubyGems.
next if s.source.nil?
next if @unlock[:sources].include?(s.source.name)
- # XXX This is a backwards-compatibility fix to preserve the ability to
- # unlock a single gem by passing its name via `--source`. See issue #3759
- # TODO: delete in Bundler 2
- next if unlock_source_unlocks_spec && @unlock[:sources].include?(s.name)
-
# If the spec is from a path source and it doesn't exist anymore
# then we unlock it.
@@ -818,7 +739,7 @@ module Bundler
# if we won't need the source (according to the lockfile),
# don't error if the path/git source isn't available
next if @locked_specs.
- for(requested_dependencies, [], false, true, false).
+ for(requested_dependencies, false, true).
none? {|locked_spec| locked_spec.source == s.source }
raise
@@ -837,8 +758,8 @@ module Bundler
end
resolve = SpecSet.new(converged)
- @locked_specs_incomplete_for_platform = !resolve.for(expand_dependencies(requested_dependencies & deps), @unlock[:gems], true, true)
- resolve = resolve.for(expand_dependencies(deps, true), @unlock[:gems], false, false, false)
+ @locked_specs_incomplete_for_platform = !resolve.for(expand_dependencies(requested_dependencies & deps), true, true)
+ resolve = SpecSet.new(resolve.for(expand_dependencies(deps, true), false, false).reject{|s| @unlock[:gems].include?(s.name) })
diff = nil
# Now, we unlock any sources that do not have anymore gems pinned to it
@@ -909,26 +830,22 @@ module Bundler
end
def source_requirements
- # Load all specs from remote sources
- index
-
# Record the specs available in each gem's source, so that those
# specs will be available later when the resolver knows where to
# look for that gemspec (or its dependencies)
- source_requirements = { :default => sources.default_source }.merge(dependency_source_requirements)
+ source_requirements = if precompute_source_requirements_for_indirect_dependencies?
+ { :default => sources.default_source }.merge(source_map.all_requirements)
+ else
+ { :default => Source::RubygemsAggregate.new(sources, source_map) }.merge(source_map.direct_requirements)
+ end
metadata_dependencies.each do |dep|
source_requirements[dep.name] = sources.metadata_source
end
- source_requirements[:global] = index unless Bundler.feature_flag.disable_multisource?
- source_requirements[:default_bundler] = source_requirements["bundler"] || source_requirements[:default]
+ source_requirements[:default_bundler] = source_requirements["bundler"] || sources.default_source
source_requirements["bundler"] = sources.metadata_source # needs to come last to override
source_requirements
end
- def pinned_spec_names(skip = nil)
- dependency_source_requirements.reject {|_, source| source == skip }.keys
- end
-
def requested_groups
groups - Bundler.settings[:without] - @optional_groups + Bundler.settings[:with]
end
@@ -946,12 +863,6 @@ module Bundler
current == proposed
end
- def extract_gem_info(error)
- # This method will extract the error message like "Could not find foo-1.2.3 in any of the sources"
- # to an array. The first element will be the gem name (e.g. foo), the second will be the version number.
- error.message.scan(/Could not find (\w+)-(\d+(?:\.\d+)+)/).flatten
- end
-
def compute_requires
dependencies.reduce({}) do |requires, dep|
next requires unless dep.should_include?
@@ -964,14 +875,13 @@ module Bundler
end
def additional_base_requirements_for_resolve
- return [] unless @locked_gems
+ return [] unless @locked_gems && unlocking? && !sources.expired_sources?(@locked_gems.sources)
dependencies_by_name = dependencies.inject({}) {|memo, dep| memo.update(dep.name => dep) }
@locked_gems.specs.reduce({}) do |requirements, locked_spec|
name = locked_spec.name
dependency = dependencies_by_name[name]
- next requirements unless dependency
next requirements if @locked_gems.dependencies[name] != dependency
- next requirements if dependency.source.is_a?(Source::Path)
+ next requirements if dependency && dependency.source.is_a?(Source::Path)
dep = Gem::Dependency.new(name, ">= #{locked_spec.version}")
requirements[name] = DepProxy.get_proxy(dep, locked_spec.platform)
requirements
@@ -984,16 +894,8 @@ module Bundler
Bundler.settings[:allow_deployment_source_credential_changes] && source.equivalent_remotes?(sources.rubygems_remotes)
end
- def dependency_source_requirements
- @dependency_source_requirements ||= begin
- source_requirements = {}
- default = sources.default_source
- dependencies.each do |dep|
- dep_source = dep.source || default
- source_requirements[dep.name] = dep_source
- end
- source_requirements
- end
+ def source_map
+ @source_map ||= SourceMap.new(sources, dependencies)
end
end
end
diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb
index 313d1a9..ed7b3e2 100644
--- a/lib/bundler/dsl.rb
+++ b/lib/bundler/dsl.rb
@@ -24,9 +24,6 @@ module Bundler
def initialize
@source = nil
@sources = SourceList.new
-
- @global_rubygems_sources = []
-
@git_sources = {}
@dependencies = []
@groups = []
@@ -48,7 +45,6 @@ module Bundler
@gemfiles << expanded_gemfile_path
contents ||= Bundler.read_file(@gemfile.to_s)
instance_eval(contents.dup.tap{|x| x.untaint if RUBY_VERSION < "2.7" }, gemfile.to_s, 1)
- check_primary_source_safety
rescue Exception => e # rubocop:disable Lint/RescueException
message = "There was an error " \
"#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \
@@ -107,8 +103,8 @@ module Bundler
if current = @dependencies.find {|d| d.name == dep.name }
deleted_dep = @dependencies.delete(current) if current.type == :development
- if current.requirement != dep.requirement
- unless deleted_dep
+ unless deleted_dep
+ if current.requirement != dep.requirement
return if dep.type == :development
update_prompt = ""
@@ -126,17 +122,14 @@ module Bundler
raise GemfileError, "You cannot specify the same gem twice with different version requirements.\n" \
"You specified: #{current.name} (#{current.requirement}) and #{dep.name} (#{dep.requirement})" \
"#{update_prompt}"
+ else
+ Bundler.ui.warn "Your Gemfile lists the gem #{current.name} (#{current.requirement}) more than once.\n" \
+ "You should probably keep only one of them.\n" \
+ "Remove any duplicate entries and specify the gem only once.\n" \
+ "While it's not a problem now, it could cause errors if you change the version of one of them later."
end
- else
- Bundler.ui.warn "Your Gemfile lists the gem #{current.name} (#{current.requirement}) more than once.\n" \
- "You should probably keep only one of them.\n" \
- "Remove any duplicate entries and specify the gem only once.\n" \
- "While it's not a problem now, it could cause errors if you change the version of one of them later."
- end
-
- if current.source != dep.source
- unless deleted_dep
+ if current.source != dep.source
return if dep.type == :development
raise GemfileError, "You cannot specify the same gem twice coming from different sources.\n" \
"You specified that #{dep.name} (#{dep.requirement}) should come from " \
@@ -168,7 +161,7 @@ module Bundler
elsif block_given?
with_source(@sources.add_rubygems_source("remotes" => source), &blk)
else
- @global_rubygems_sources << source
+ @sources.add_global_rubygems_remote(source)
end
end
@@ -222,6 +215,7 @@ module Bundler
end
def to_definition(lockfile, unlock)
+ check_primary_source_safety
Definition.new(lockfile, @dependencies, @sources, unlock, @ruby_version, @optional_groups, @gemfiles)
end
@@ -453,13 +447,21 @@ repo_name ||= user_name
end
def check_rubygems_source_safety
- @sources.global_rubygems_source = @global_rubygems_sources.shift
- return if @global_rubygems_sources.empty?
-
- @global_rubygems_sources.each do |source|
- @sources.add_rubygems_remote(source)
+ if @sources.implicit_global_source?
+ implicit_global_source_warning
+ elsif @sources.aggregate_global_source?
+ multiple_global_source_warning
end
+ end
+
+ def implicit_global_source_warning
+ Bundler::SharedHelpers.major_deprecation 2, "This Gemfile does not include an explicit global source. " \
+ "Not using an explicit global source may result in a different lockfile being generated depending on " \
+ "the gems you have installed locally before bundler is run. " \
+ "Instead, define a global source in your Gemfile like this: source \"https://rubygems.org\"."
+ end
+ def multiple_global_source_warning
if Bundler.feature_flag.bundler_3_mode?
msg = "This Gemfile contains multiple primary sources. " \
"Each source after the first must include a block to indicate which gems " \
diff --git a/lib/bundler/endpoint_specification.rb b/lib/bundler/endpoint_specification.rb
index 476151a..6cf597b 100644
--- a/lib/bundler/endpoint_specification.rb
+++ b/lib/bundler/endpoint_specification.rb
@@ -3,7 +3,6 @@
module Bundler
# used for Creating Specifications from the Gemcutter Endpoint
class EndpointSpecification < Gem::Specification
- ILLFORMED_MESSAGE = 'Ill-formed requirement ["#<YAML::Syck::DefaultKey'.freeze
include MatchPlatform
attr_reader :name, :version, :platform, :required_rubygems_version, :required_ruby_version, :checksum
@@ -129,13 +128,6 @@ module Bundler
def build_dependency(name, requirements)
Gem::Dependency.new(name, requirements)
- rescue ArgumentError => e
- raise unless e.message.include?(ILLFORMED_MESSAGE)
- puts # we shouldn't print the error message on the "fetching info" status line
- raise GemspecError,
- "Unfortunately, the gem #{name} (#{version}) has an invalid " \
- "gemspec.\nPlease ask the gem author to yank the bad version to fix " \
- "this issue. For more information, see http://bit.ly/syck-defaultkey."
end
end
end
diff --git a/lib/bundler/errors.rb b/lib/bundler/errors.rb
index 11763b4..565aaee 100644
--- a/lib/bundler/errors.rb
+++ b/lib/bundler/errors.rb
@@ -122,7 +122,7 @@ module Bundler
class VirtualProtocolError < BundlerError
def message
- "There was an error relating to virtualization and file access." \
+ "There was an error relating to virtualization and file access. " \
"It is likely that you need to grant access to or mount some file system correctly."
end
diff --git a/lib/bundler/feature_flag.rb b/lib/bundler/feature_flag.rb
index 36c18ea..e441b94 100644
--- a/lib/bundler/feature_flag.rb
+++ b/lib/bundler/feature_flag.rb
@@ -31,7 +31,6 @@ module Bundler
settings_flag(:auto_clean_without_path) { bundler_3_mode? }
settings_flag(:cache_all) { bundler_3_mode? }
settings_flag(:default_install_uses_path) { bundler_3_mode? }
- settings_flag(:disable_multisource) { bundler_3_mode? }
settings_flag(:forget_cli_options) { bundler_3_mode? }
settings_flag(:global_gem_cache) { bundler_3_mode? }
settings_flag(:path_relative_to_cwd) { bundler_3_mode? }
@@ -39,7 +38,6 @@ module Bundler
settings_flag(:print_only_version_number) { bundler_3_mode? }
settings_flag(:setup_makes_kernel_gem_public) { !bundler_3_mode? }
settings_flag(:suppress_install_using_messages) { bundler_3_mode? }
- settings_flag(:unlock_source_unlocks_spec) { !bundler_3_mode? }
settings_flag(:update_requires_all_flag) { bundler_4_mode? }
settings_flag(:use_gem_version_promoter_for_major_updates) { bundler_3_mode? }
diff --git a/lib/bundler/fetcher/compact_index.rb b/lib/bundler/fetcher/compact_index.rb
index 27969d7..aa828af 100644
--- a/lib/bundler/fetcher/compact_index.rb
+++ b/lib/bundler/fetcher/compact_index.rb
@@ -116,7 +116,7 @@ module Bundler
def bundle_worker(func = nil)
@bundle_worker ||= begin
worker_name = "Compact Index (#{display_uri.host})"
- Bundler::Worker.new(Bundler.current_ruby.rbx? ? 1 : 25, worker_name, func)
+ Bundler::Worker.new(Bundler.settings.processor_count, worker_name, func)
end
@bundle_worker.tap do |worker|
worker.instance_variable_set(:@func, func) if func
diff --git a/lib/bundler/fetcher/downloader.rb b/lib/bundler/fetcher/downloader.rb
index 5d30333..f2aad3a 100644
--- a/lib/bundler/fetcher/downloader.rb
+++ b/lib/bundler/fetcher/downloader.rb
@@ -68,8 +68,7 @@ module Bundler
raise CertificateFailureError.new(uri)
rescue *HTTP_ERRORS => e
Bundler.ui.trace e
- case e.message
- when /host down:/, /getaddrinfo: nodename nor servname provided/
+ if e.is_a?(SocketError) || e.message =~ /host down:/
raise NetworkDownError, "Could not reach host #{uri.host}. Check your network " \
"connection and try again."
else
diff --git a/lib/bundler/fetcher/index.rb b/lib/bundler/fetcher/index.rb
index 08b0418..0d14c47 100644
--- a/lib/bundler/fetcher/index.rb
+++ b/lib/bundler/fetcher/index.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require_relative "base"
-require "rubygems/remote_fetcher"
module Bundler
class Fetcher
diff --git a/lib/bundler/friendly_errors.rb b/lib/bundler/friendly_errors.rb
index 5d0bb90..db43e0f 100644
--- a/lib/bundler/friendly_errors.rb
+++ b/lib/bundler/friendly_errors.rb
@@ -49,8 +49,6 @@ module Bundler
"Alternatively, you can increase the amount of memory the JVM is able to use by running Bundler with jruby -J-Xmx1024m -S bundle (JRuby defaults to 500MB)."
else request_issue_report_for(error)
end
- rescue StandardError
- raise error
end
def exit_status(error)
@@ -111,8 +109,8 @@ module Bundler
First, try this link to see if there are any existing issue reports for this error:
#{issues_url(e)}
- If there aren't any reports for this error yet, please create copy and paste the report template above into a new issue. Don't forget to anonymize any private data! The new issue form is located at:
- https://github.com/rubygems/rubygems/issues/new?labels=Bundler
+ If there aren't any reports for this error yet, please copy and paste the report template above into a new issue. Don't forget to anonymize any private data! The new issue form is located at:
+ https://github.com/rubygems/rubygems/issues/new?labels=Bundler&template=bundler-related-issue.md
EOS
end
diff --git a/lib/bundler/gemdeps.rb b/lib/bundler/gemdeps.rb
deleted file mode 100644
index cd4b25d..0000000
--- a/lib/bundler/gemdeps.rb
+++ /dev/null
@@ -1,29 +0,0 @@
-# frozen_string_literal: true
-
-module Bundler
- class Gemdeps
- def initialize(runtime)
- @runtime = runtime
- end
-
- def requested_specs
- @runtime.requested_specs
- end
-
- def specs
- @runtime.specs
- end
-
- def dependencies
- @runtime.dependencies
- end
-
- def current_dependencies
- @runtime.current_dependencies
- end
-
- def requires
- @runtime.requires
- end
- end
-end
diff --git a/lib/bundler/index.rb b/lib/bundler/index.rb
index f945176..8930fca 100644
--- a/lib/bundler/index.rb
+++ b/lib/bundler/index.rb
@@ -122,10 +122,9 @@ module Bundler
names
end
- # returns a list of the dependencies
def unmet_dependency_names
dependency_names.select do |name|
- name != "bundler" && search(name).empty?
+ search(name).empty?
end
end
@@ -196,11 +195,7 @@ module Bundler
if base # allow all platforms when searching from a lockfile
dependency.matches_spec?(spec)
else
- if Gem::Platform.respond_to? :match_spec?
- dependency.matches_spec?(spec) && Gem::Platform.match_spec?(spec)
- else
- dependency.matches_spec?(spec) && Gem::Platform.match(spec.platform)
- end
+ dependency.matches_spec?(spec) && Gem::Platform.match_spec?(spec)
end
end
diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb
index 09c8b1c..49ff177 100644
--- a/lib/bundler/installer.rb
+++ b/lib/bundler/installer.rb
@@ -1,6 +1,5 @@
# frozen_string_literal: true
-require "rubygems/dependency_installer"
require_relative "worker"
require_relative "installer/parallel_installer"
require_relative "installer/standalone"
@@ -135,7 +134,7 @@ module Bundler
next
end
- mode = Bundler::WINDOWS ? "wb:UTF-8" : "w"
+ mode = Gem.win_platform? ? "wb:UTF-8" : "w"
require "erb"
content = if RUBY_VERSION >= "2.6"
ERB.new(template, :trim_mode => "-").result(binding)
@@ -144,7 +143,7 @@ module Bundler
end
File.write(binstub_path, content, :mode => mode, :perm => 0o777 & ~File.umask)
- if Bundler::WINDOWS || options[:all_platforms]
+ if Gem.win_platform? || options[:all_platforms]
prefix = "@ruby -x \"%~f0\" %*\n@exit /b %ERRORLEVEL%\n\n"
File.write("#{binstub_path}.cmd", prefix + content, :mode => mode)
end
@@ -182,7 +181,7 @@ module Bundler
executable_path = Pathname(spec.full_gem_path).join(spec.bindir, executable).relative_path_from(bin_path)
executable_path = executable_path
- mode = Bundler::WINDOWS ? "wb:UTF-8" : "w"
+ mode = Gem.win_platform? ? "wb:UTF-8" : "w"
require "erb"
content = if RUBY_VERSION >= "2.6"
ERB.new(template, :trim_mode => "-").result(binding)
@@ -191,7 +190,7 @@ module Bundler
end
File.write("#{bin_path}/#{executable}", content, :mode => mode, :perm => 0o755)
- if Bundler::WINDOWS || options[:all_platforms]
+ if Gem.win_platform? || options[:all_platforms]
prefix = "@ruby -x \"%~f0\" %*\n@exit /b %ERRORLEVEL%\n\n"
File.write("#{bin_path}/#{executable}.cmd", prefix + content, :mode => mode)
end
@@ -219,17 +218,7 @@ module Bundler
return jobs
end
- # Parallelization has some issues on Windows, so it's not yet the default
- return 1 if Gem.win_platform?
-
- processor_count
- end
-
- def processor_count
- require "etc"
- Etc.nprocessors
- rescue StandardError
- 1
+ Bundler.settings.processor_count
end
def load_plugins
diff --git a/lib/bundler/installer/gem_installer.rb b/lib/bundler/installer/gem_installer.rb
index 507fd18..1df86cc 100644
--- a/lib/bundler/installer/gem_installer.rb
+++ b/lib/bundler/installer/gem_installer.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require "shellwords"
-
module Bundler
class GemInstaller
attr_reader :spec, :standalone, :worker, :force, :installer
@@ -31,34 +29,23 @@ module Bundler
def specific_failure_message(e)
message = "#{e.class}: #{e.message}\n"
- message += " " + e.backtrace.join("\n ") + "\n\n" if Bundler.ui.debug?
+ message += " " + e.backtrace.join("\n ") + "\n\n"
message = message.lines.first + Bundler.ui.add_color(message.lines.drop(1).join, :clear)
message + Bundler.ui.add_color(failure_message, :red)
end
def failure_message
- return install_error_message if spec.source.options["git"]
- "#{install_error_message}\n#{gem_install_message}"
+ install_error_message
end
def install_error_message
"An error occurred while installing #{spec.name} (#{spec.version}), and Bundler cannot continue."
end
- def gem_install_message
- source = spec.source
- return unless source.respond_to?(:remotes)
-
- if source.remotes.size == 1
- "Make sure that `gem install #{spec.name} -v '#{spec.version}' --source '#{source.remotes.first}'` succeeds before bundling."
- else
- "Make sure that `gem install #{spec.name} -v '#{spec.version}'` succeeds before bundling."
- end
- end
-
def spec_settings
# Fetch the build settings, if there are any
if settings = Bundler.settings["build.#{spec.name}"]
+ require "shellwords"
Shellwords.shellsplit(settings)
end
end
diff --git a/lib/bundler/installer/standalone.rb b/lib/bundler/installer/standalone.rb
index 2a3f5cf..e8494b4 100644
--- a/lib/bundler/installer/standalone.rb
+++ b/lib/bundler/installer/standalone.rb
@@ -3,7 +3,7 @@
module Bundler
class Standalone
def initialize(groups, definition)
- @specs = groups.empty? ? definition.requested_specs : definition.specs_for(groups.map(&:to_sym))
+ @specs = definition.specs_for(groups)
end
def generate
@@ -12,12 +12,13 @@ module Bundler
end
File.open File.join(bundler_path, "setup.rb"), "w" do |file|
file.puts "require 'rbconfig'"
- file.puts "ruby_engine = RUBY_ENGINE"
- file.puts "ruby_version = RbConfig::CONFIG[\"ruby_version\"]"
- file.puts "path = File.expand_path('..', __FILE__)"
file.puts reverse_rubygems_kernel_mixin
paths.each do |path|
- file.puts %($:.unshift File.expand_path("\#{path}/#{path}"))
+ if Pathname.new(path).absolute?
+ file.puts %($:.unshift "#{path}")
+ else
+ file.puts %($:.unshift File.expand_path("\#{__dir__}/#{path}"))
+ end
end
end
end
@@ -28,14 +29,14 @@ module Bundler
@specs.map do |spec|
next if spec.name == "bundler"
Array(spec.require_paths).map do |path|
- gem_path(path, spec).sub(version_dir, '#{ruby_engine}/#{ruby_version}')
+ gem_path(path, spec).sub(version_dir, '#{RUBY_ENGINE}/#{RbConfig::CONFIG["ruby_version"]}')
# This is a static string intentionally. It's interpolated at a later time.
end
- end.flatten
+ end.flatten.compact
end
def version_dir
- "#{Bundler::RubyVersion.system.engine}/#{RbConfig::CONFIG["ruby_version"]}"
+ "#{RUBY_ENGINE}/#{RbConfig::CONFIG["ruby_version"]}"
end
def bundler_path
@@ -44,7 +45,11 @@ module Bundler
def gem_path(path, spec)
full_path = Pathname.new(path).absolute? ? path : File.join(spec.full_gem_path, path)
- Pathname.new(full_path).relative_path_from(Bundler.root.join(bundler_path)).to_s
+ if spec.source.instance_of?(Source::Path)
+ full_path
+ else
+ Pathname.new(full_path).relative_path_from(Bundler.root.join(bundler_path)).to_s
+ end
rescue TypeError
error_message = "#{spec.name} #{spec.version} has an invalid gemspec"
raise Gem::InvalidSpecificationException.new(error_message)
diff --git a/lib/bundler/lockfile_parser.rb b/lib/bundler/lockfile_parser.rb
index f87faff..8d0e44d 100644
--- a/lib/bundler/lockfile_parser.rb
+++ b/lib/bundler/lockfile_parser.rb
@@ -1,16 +1,5 @@
# frozen_string_literal: true
-#--
-# Some versions of the Bundler 1.1 RC series introduced corrupted
-# lockfiles. There were two major problems:
-#
-# * multiple copies of the same GIT section appeared in the lockfile
-# * when this happened, those sections got multiple copies of gems
-# in those sections.
-#
-# As a result, Bundler 1.1 contains code that fixes the earlier
-# corruption. We will remove this fix-up code in Bundler 1.2.
-
module Bundler
class LockfileParser
attr_reader :sources, :dependencies, :specs, :platforms, :bundler_version, :ruby_version
@@ -124,12 +113,7 @@ module Bundler
@sources << @current_source
when GIT
@current_source = TYPES[@type].from_lock(@opts)
- # Strip out duplicate GIT sections
- if @sources.include?(@current_source)
- @current_source = @sources.find {|s| s == @current_source }
- else
- @sources << @current_source
- end
+ @sources << @current_source
when GEM
@opts["remotes"] = Array(@opts.delete("remote")).reverse
@current_source = TYPES[@type].from_lock(@opts)
@@ -211,10 +195,9 @@ module Bundler
platform = platform ? Gem::Platform.new(platform) : Gem::Platform::RUBY
@current_spec = LazySpecification.new(name, version, platform)
@current_spec.source = @current_source
+ @current_source.add_dependency_names(name)
- # Avoid introducing multiple copies of the same spec (caused by
- # duplicate GIT sections)
- @specs[@current_spec.identifier] ||= @current_spec
+ @specs[@current_spec.identifier] = @current_spec
elsif spaces.size == 6
version = version.split(",").map(&:strip) if version
dep = Gem::Dependency.new(name, version)
diff --git a/lib/bundler/man/bundle-add.1 b/lib/bundler/man/bundle-add.1
index ffcd63b..0cac84b 100644
--- a/lib/bundler/man/bundle-add.1
+++ b/lib/bundler/man/bundle-add.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-ADD" "1" "April 2021" "" ""
+.TH "BUNDLE\-ADD" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-add\fR \- Add gem to the Gemfile and run bundle install
diff --git a/lib/bundler/man/bundle-binstubs.1 b/lib/bundler/man/bundle-binstubs.1
index 23c371b..017e302 100644
--- a/lib/bundler/man/bundle-binstubs.1
+++ b/lib/bundler/man/bundle-binstubs.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-BINSTUBS" "1" "April 2021" "" ""
+.TH "BUNDLE\-BINSTUBS" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-binstubs\fR \- Install the binstubs of the listed gems
diff --git a/lib/bundler/man/bundle-cache.1 b/lib/bundler/man/bundle-cache.1
index 9bb8011..cfb4b84 100644
--- a/lib/bundler/man/bundle-cache.1
+++ b/lib/bundler/man/bundle-cache.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-CACHE" "1" "April 2021" "" ""
+.TH "BUNDLE\-CACHE" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-cache\fR \- Package your needed \fB\.gem\fR files into your application
diff --git a/lib/bundler/man/bundle-check.1 b/lib/bundler/man/bundle-check.1
index 6696479..bc8f477 100644
--- a/lib/bundler/man/bundle-check.1
+++ b/lib/bundler/man/bundle-check.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-CHECK" "1" "April 2021" "" ""
+.TH "BUNDLE\-CHECK" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-check\fR \- Verifies if dependencies are satisfied by installed gems
diff --git a/lib/bundler/man/bundle-clean.1 b/lib/bundler/man/bundle-clean.1
index 625d87c..814d28e 100644
--- a/lib/bundler/man/bundle-clean.1
+++ b/lib/bundler/man/bundle-clean.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-CLEAN" "1" "April 2021" "" ""
+.TH "BUNDLE\-CLEAN" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-clean\fR \- Cleans up unused gems in your bundler directory
diff --git a/lib/bundler/man/bundle-config.1 b/lib/bundler/man/bundle-config.1
index 81cfaa7..06f2a7b 100644
--- a/lib/bundler/man/bundle-config.1
+++ b/lib/bundler/man/bundle-config.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-CONFIG" "1" "April 2021" "" ""
+.TH "BUNDLE\-CONFIG" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-config\fR \- Set bundler configuration options
@@ -56,9 +56,6 @@ Executing \fBbundle config unset \-\-local <name> <value>\fR will delete the con
.P
Executing bundle with the \fBBUNDLE_IGNORE_CONFIG\fR environment variable set will cause it to ignore all configuration\.
.
-.P
-Executing \fBbundle config set \-\-local disable_multisource true\fR upgrades the warning about the Gemfile containing multiple primary sources to an error\. Executing \fBbundle config unset disable_multisource\fR downgrades this error to a warning\.
-.
.SH "REMEMBERING OPTIONS"
Flags passed to \fBbundle install\fR or the Bundler runtime, such as \fB\-\-path foo\fR or \fB\-\-without production\fR, are remembered between commands and saved to your local application\'s configuration (normally, \fB\./\.bundle/config\fR)\.
.
@@ -184,9 +181,6 @@ The following is a list of all configuration keys and their purpose\. You can le
\fBdisable_local_revision_check\fR (\fBBUNDLE_DISABLE_LOCAL_REVISION_CHECK\fR): Allow Bundler to use a local git override without checking if the revision present in the lockfile is present in the repository\.
.
.IP "\(bu" 4
-\fBdisable_multisource\fR (\fBBUNDLE_DISABLE_MULTISOURCE\fR): When set, Gemfiles containing multiple sources will produce errors instead of warnings\. Use \fBbundle config unset disable_multisource\fR to unset\.
-.
-.IP "\(bu" 4
\fBdisable_shared_gems\fR (\fBBUNDLE_DISABLE_SHARED_GEMS\fR): Stop Bundler from accessing gems installed to RubyGems\' normal location\.
.
.IP "\(bu" 4
@@ -217,7 +211,7 @@ The following is a list of all configuration keys and their purpose\. You can le
\fBinit_gems_rb\fR (\fBBUNDLE_INIT_GEMS_RB\fR): Generate a \fBgems\.rb\fR instead of a \fBGemfile\fR when running \fBbundle init\fR\.
.
.IP "\(bu" 4
-\fBjobs\fR (\fBBUNDLE_JOBS\fR): The number of gems Bundler can install in parallel\. Defaults to 1 on Windows, and to the the number of processors on other platforms\.
+\fBjobs\fR (\fBBUNDLE_JOBS\fR): The number of gems Bundler can install in parallel\. Defaults to the number of available processors\.
.
.IP "\(bu" 4
\fBno_install\fR (\fBBUNDLE_NO_INSTALL\fR): Whether \fBbundle package\fR should skip installing gems\.
@@ -280,9 +274,6 @@ The following is a list of all configuration keys and their purpose\. You can le
\fBtimeout\fR (\fBBUNDLE_TIMEOUT\fR): The seconds allowed before timing out for network requests\. Defaults to \fB10\fR\.
.
.IP "\(bu" 4
-\fBunlock_source_unlocks_spec\fR (\fBBUNDLE_UNLOCK_SOURCE_UNLOCKS_SPEC\fR): Whether running \fBbundle update \-\-source NAME\fR unlocks a gem with the given name\. Defaults to \fBtrue\fR\.
-.
-.IP "\(bu" 4
\fBupdate_requires_all_flag\fR (\fBBUNDLE_UPDATE_REQUIRES_ALL_FLAG\fR): Require passing \fB\-\-all\fR to \fBbundle update\fR when everything should be updated, and disallow passing no options to \fBbundle update\fR\.
.
.IP "\(bu" 4
diff --git a/lib/bundler/man/bundle-config.1.ronn b/lib/bundler/man/bundle-config.1.ronn
index b759939..96374d9 100644
--- a/lib/bundler/man/bundle-config.1.ronn
+++ b/lib/bundler/man/bundle-config.1.ronn
@@ -47,10 +47,6 @@ configuration only from the local application.
Executing bundle with the `BUNDLE_IGNORE_CONFIG` environment variable set will
cause it to ignore all configuration.
-Executing `bundle config set --local disable_multisource true` upgrades the warning about
-the Gemfile containing multiple primary sources to an error. Executing `bundle
-config unset disable_multisource` downgrades this error to a warning.
-
## REMEMBERING OPTIONS
Flags passed to `bundle install` or the Bundler runtime, such as `--path foo` or
@@ -178,10 +174,6 @@ learn more about their operation in [bundle install(1)](bundle-install.1.html).
* `disable_local_revision_check` (`BUNDLE_DISABLE_LOCAL_REVISION_CHECK`):
Allow Bundler to use a local git override without checking if the revision
present in the lockfile is present in the repository.
-* `disable_multisource` (`BUNDLE_DISABLE_MULTISOURCE`):
- When set, Gemfiles containing multiple sources will produce errors
- instead of warnings.
- Use `bundle config unset disable_multisource` to unset.
* `disable_shared_gems` (`BUNDLE_DISABLE_SHARED_GEMS`):
Stop Bundler from accessing gems installed to RubyGems' normal location.
* `disable_version_check` (`BUNDLE_DISABLE_VERSION_CHECK`):
@@ -216,8 +208,8 @@ learn more about their operation in [bundle install(1)](bundle-install.1.html).
* `init_gems_rb` (`BUNDLE_INIT_GEMS_RB`):
Generate a `gems.rb` instead of a `Gemfile` when running `bundle init`.
* `jobs` (`BUNDLE_JOBS`):
- The number of gems Bundler can install in parallel. Defaults to 1 on Windows,
- and to the the number of processors on other platforms.
+ The number of gems Bundler can install in parallel. Defaults to the number of
+ available processors.
* `no_install` (`BUNDLE_NO_INSTALL`):
Whether `bundle package` should skip installing gems.
* `no_prune` (`BUNDLE_NO_PRUNE`):
@@ -268,9 +260,6 @@ learn more about their operation in [bundle install(1)](bundle-install.1.html).
The location where RubyGems installs binstubs. Defaults to `Gem.bindir`.
* `timeout` (`BUNDLE_TIMEOUT`):
The seconds allowed before timing out for network requests. Defaults to `10`.
-* `unlock_source_unlocks_spec` (`BUNDLE_UNLOCK_SOURCE_UNLOCKS_SPEC`):
- Whether running `bundle update --source NAME` unlocks a gem with the given
- name. Defaults to `true`.
* `update_requires_all_flag` (`BUNDLE_UPDATE_REQUIRES_ALL_FLAG`):
Require passing `--all` to `bundle update` when everything should be updated,
and disallow passing no options to `bundle update`.
diff --git a/lib/bundler/man/bundle-doctor.1 b/lib/bundler/man/bundle-doctor.1
index 8e4c47c..5509d31 100644
--- a/lib/bundler/man/bundle-doctor.1
+++ b/lib/bundler/man/bundle-doctor.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-DOCTOR" "1" "April 2021" "" ""
+.TH "BUNDLE\-DOCTOR" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-doctor\fR \- Checks the bundle for common problems
diff --git a/lib/bundler/man/bundle-exec.1 b/lib/bundler/man/bundle-exec.1
index 863b76e..627ba57 100644
--- a/lib/bundler/man/bundle-exec.1
+++ b/lib/bundler/man/bundle-exec.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-EXEC" "1" "April 2021" "" ""
+.TH "BUNDLE\-EXEC" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-exec\fR \- Execute a command in the context of the bundle
diff --git a/lib/bundler/man/bundle-gem.1 b/lib/bundler/man/bundle-gem.1
index ae4e173..0190cef 100644
--- a/lib/bundler/man/bundle-gem.1
+++ b/lib/bundler/man/bundle-gem.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-GEM" "1" "April 2021" "" ""
+.TH "BUNDLE\-GEM" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-gem\fR \- Generate a project skeleton for creating a rubygem
diff --git a/lib/bundler/man/bundle-info.1 b/lib/bundler/man/bundle-info.1
index 168d021..5a1ff77 100644
--- a/lib/bundler/man/bundle-info.1
+++ b/lib/bundler/man/bundle-info.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-INFO" "1" "April 2021" "" ""
+.TH "BUNDLE\-INFO" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-info\fR \- Show information for the given gem in your bundle
diff --git a/lib/bundler/man/bundle-init.1 b/lib/bundler/man/bundle-init.1
index 5d3e61d..7c72947 100644
--- a/lib/bundler/man/bundle-init.1
+++ b/lib/bundler/man/bundle-init.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-INIT" "1" "April 2021" "" ""
+.TH "BUNDLE\-INIT" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-init\fR \- Generates a Gemfile into the current working directory
diff --git a/lib/bundler/man/bundle-inject.1 b/lib/bundler/man/bundle-inject.1
index 37acabf..c281f21 100644
--- a/lib/bundler/man/bundle-inject.1
+++ b/lib/bundler/man/bundle-inject.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-INJECT" "1" "April 2021" "" ""
+.TH "BUNDLE\-INJECT" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-inject\fR \- Add named gem(s) with version requirements to Gemfile
diff --git a/lib/bundler/man/bundle-install.1 b/lib/bundler/man/bundle-install.1
index 2dcb4d3..8b86954 100644
--- a/lib/bundler/man/bundle-install.1
+++ b/lib/bundler/man/bundle-install.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-INSTALL" "1" "April 2021" "" ""
+.TH "BUNDLE\-INSTALL" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-install\fR \- Install the dependencies specified in your Gemfile
@@ -63,7 +63,7 @@ The location of the Gemfile(5) which Bundler should use\. This defaults to a Gem
.
.TP
\fB\-\-jobs=[<number>]\fR, \fB\-j[<number>]\fR
-The maximum number of parallel download and install jobs\. The default is \fB1\fR\.
+The maximum number of parallel download and install jobs\. The default is the number of available processors\.
.
.TP
\fB\-\-local\fR
diff --git a/lib/bundler/man/bundle-install.1.ronn b/lib/bundler/man/bundle-install.1.ronn
index 5ea777f..bec0518 100644
--- a/lib/bundler/man/bundle-install.1.ronn
+++ b/lib/bundler/man/bundle-install.1.ronn
@@ -100,8 +100,8 @@ automatically and that requires `bundler` to silently remember them. Since
to this location.
* `--jobs=[<number>]`, `-j[<number>]`:
- The maximum number of parallel download and install jobs. The default
- is `1`.
+ The maximum number of parallel download and install jobs. The default is the
+ number of available processors.
* `--local`:
Do not attempt to connect to `rubygems.org`. Instead, Bundler will use the
diff --git a/lib/bundler/man/bundle-list.1 b/lib/bundler/man/bundle-list.1
index 7c93b89..48f817e 100644
--- a/lib/bundler/man/bundle-list.1
+++ b/lib/bundler/man/bundle-list.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-LIST" "1" "April 2021" "" ""
+.TH "BUNDLE\-LIST" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-list\fR \- List all the gems in the bundle
diff --git a/lib/bundler/man/bundle-lock.1 b/lib/bundler/man/bundle-lock.1
index a4dfda9..623e764 100644
--- a/lib/bundler/man/bundle-lock.1
+++ b/lib/bundler/man/bundle-lock.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-LOCK" "1" "April 2021" "" ""
+.TH "BUNDLE\-LOCK" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-lock\fR \- Creates / Updates a lockfile without installing
diff --git a/lib/bundler/man/bundle-open.1 b/lib/bundler/man/bundle-open.1
index 0511bc6..d1c5314 100644
--- a/lib/bundler/man/bundle-open.1
+++ b/lib/bundler/man/bundle-open.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-OPEN" "1" "April 2021" "" ""
+.TH "BUNDLE\-OPEN" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-open\fR \- Opens the source directory for a gem in your bundle
diff --git a/lib/bundler/man/bundle-outdated.1 b/lib/bundler/man/bundle-outdated.1
index 268b4b1..d327de4 100644
--- a/lib/bundler/man/bundle-outdated.1
+++ b/lib/bundler/man/bundle-outdated.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-OUTDATED" "1" "April 2021" "" ""
+.TH "BUNDLE\-OUTDATED" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-outdated\fR \- List installed gems with newer versions available
diff --git a/lib/bundler/man/bundle-platform.1 b/lib/bundler/man/bundle-platform.1
index 77638b2..872afb6 100644
--- a/lib/bundler/man/bundle-platform.1
+++ b/lib/bundler/man/bundle-platform.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-PLATFORM" "1" "April 2021" "" ""
+.TH "BUNDLE\-PLATFORM" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-platform\fR \- Displays platform compatibility information
diff --git a/lib/bundler/man/bundle-pristine.1 b/lib/bundler/man/bundle-pristine.1
index 0fcf9fd..8361597 100644
--- a/lib/bundler/man/bundle-pristine.1
+++ b/lib/bundler/man/bundle-pristine.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-PRISTINE" "1" "April 2021" "" ""
+.TH "BUNDLE\-PRISTINE" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-pristine\fR \- Restores installed gems to their pristine condition
diff --git a/lib/bundler/man/bundle-remove.1 b/lib/bundler/man/bundle-remove.1
index ca366b8..548c208 100644
--- a/lib/bundler/man/bundle-remove.1
+++ b/lib/bundler/man/bundle-remove.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-REMOVE" "1" "April 2021" "" ""
+.TH "BUNDLE\-REMOVE" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-remove\fR \- Removes gems from the Gemfile
diff --git a/lib/bundler/man/bundle-show.1 b/lib/bundler/man/bundle-show.1
index e403ae9..8669a8a 100644
--- a/lib/bundler/man/bundle-show.1
+++ b/lib/bundler/man/bundle-show.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-SHOW" "1" "April 2021" "" ""
+.TH "BUNDLE\-SHOW" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-show\fR \- Shows all the gems in your bundle, or the path to a gem
diff --git a/lib/bundler/man/bundle-update.1 b/lib/bundler/man/bundle-update.1
index 5546b51..9df9c05 100644
--- a/lib/bundler/man/bundle-update.1
+++ b/lib/bundler/man/bundle-update.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-UPDATE" "1" "April 2021" "" ""
+.TH "BUNDLE\-UPDATE" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-update\fR \- Update your gems to the latest available versions
@@ -47,7 +47,7 @@ Fall back to using the single\-file index of all gems\.
.
.TP
\fB\-\-jobs=[<number>]\fR, \fB\-j[<number>]\fR
-Specify the number of jobs to run in parallel\. The default is \fB1\fR\.
+Specify the number of jobs to run in parallel\. The default is the number of available processors\.
.
.TP
\fB\-\-retry=[<number>]\fR
@@ -79,7 +79,7 @@ Do not allow any gem to be updated past latest \fB\-\-patch\fR | \fB\-\-minor\fR
.
.TP
\fB\-\-conservative\fR
-Use bundle install conservative update behavior and do not allow shared dependencies to be updated\.
+Use bundle install conservative update behavior and do not allow indirect dependencies to be updated\.
.
.SH "UPDATING ALL GEMS"
If you run \fBbundle update \-\-all\fR, bundler will ignore any previously installed gems and resolve all dependencies again based on the latest versions of all gems available in the sources\.
@@ -208,13 +208,13 @@ In this case, the two gems have their own set of dependencies, but they share \f
In short, by default, when you update a gem using \fBbundle update\fR, bundler will update all dependencies of that gem, including those that are also dependencies of another gem\.
.
.P
-To prevent updating shared dependencies, prior to version 1\.14 the only option was the \fBCONSERVATIVE UPDATING\fR behavior in bundle install(1) \fIbundle\-install\.1\.html\fR:
+To prevent updating indirect dependencies, prior to version 1\.14 the only option was the \fBCONSERVATIVE UPDATING\fR behavior in bundle install(1) \fIbundle\-install\.1\.html\fR:
.
.P
In this scenario, updating the \fBthin\fR version manually in the Gemfile(5), and then running bundle install(1) \fIbundle\-install\.1\.html\fR will only update \fBdaemons\fR and \fBeventmachine\fR, but not \fBrack\fR\. For more information, see the \fBCONSERVATIVE UPDATING\fR section of bundle install(1) \fIbundle\-install\.1\.html\fR\.
.
.P
-Starting with 1\.14, specifying the \fB\-\-conservative\fR option will also prevent shared dependencies from being updated\.
+Starting with 1\.14, specifying the \fB\-\-conservative\fR option will also prevent indirect dependencies from being updated\.
.
.SH "PATCH LEVEL OPTIONS"
Version 1\.14 introduced 4 patch\-level options that will influence how gem versions are resolved\. One of the following options can be used: \fB\-\-patch\fR, \fB\-\-minor\fR or \fB\-\-major\fR\. \fB\-\-strict\fR can be added to further influence resolution\.
diff --git a/lib/bundler/man/bundle-update.1.ronn b/lib/bundler/man/bundle-update.1.ronn
index 397feca..fe500cd 100644
--- a/lib/bundler/man/bundle-update.1.ronn
+++ b/lib/bundler/man/bundle-update.1.ronn
@@ -56,7 +56,8 @@ gem.
Fall back to using the single-file index of all gems.
* `--jobs=[<number>]`, `-j[<number>]`:
- Specify the number of jobs to run in parallel. The default is `1`.
+ Specify the number of jobs to run in parallel. The default is the number of
+ available processors.
* `--retry=[<number>]`:
Retry failed network or git requests for <number> times.
@@ -80,7 +81,7 @@ gem.
Do not allow any gem to be updated past latest `--patch` | `--minor` | `--major`.
* `--conservative`:
- Use bundle install conservative update behavior and do not allow shared dependencies to be updated.
+ Use bundle install conservative update behavior and do not allow indirect dependencies to be updated.
## UPDATING ALL GEMS
@@ -195,7 +196,7 @@ In short, by default, when you update a gem using `bundle update`, bundler will
update all dependencies of that gem, including those that are also dependencies
of another gem.
-To prevent updating shared dependencies, prior to version 1.14 the only option
+To prevent updating indirect dependencies, prior to version 1.14 the only option
was the `CONSERVATIVE UPDATING` behavior in [bundle install(1)](bundle-install.1.html):
In this scenario, updating the `thin` version manually in the Gemfile(5),
@@ -203,7 +204,7 @@ and then running [bundle install(1)](bundle-install.1.html) will only update `da
but not `rack`. For more information, see the `CONSERVATIVE UPDATING` section
of [bundle install(1)](bundle-install.1.html).
-Starting with 1.14, specifying the `--conservative` option will also prevent shared
+Starting with 1.14, specifying the `--conservative` option will also prevent indirect
dependencies from being updated.
## PATCH LEVEL OPTIONS
diff --git a/lib/bundler/man/bundle-viz.1 b/lib/bundler/man/bundle-viz.1
index 645c45b..6603fad 100644
--- a/lib/bundler/man/bundle-viz.1
+++ b/lib/bundler/man/bundle-viz.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE\-VIZ" "1" "April 2021" "" ""
+.TH "BUNDLE\-VIZ" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\-viz\fR \- Generates a visual dependency graph for your Gemfile
diff --git a/lib/bundler/man/bundle.1 b/lib/bundler/man/bundle.1
index 5c1bc96..2fe3072 100644
--- a/lib/bundler/man/bundle.1
+++ b/lib/bundler/man/bundle.1
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "BUNDLE" "1" "April 2021" "" ""
+.TH "BUNDLE" "1" "August 2021" "" ""
.
.SH "NAME"
\fBbundle\fR \- Ruby Dependency Management
diff --git a/lib/bundler/man/gemfile.5 b/lib/bundler/man/gemfile.5
index c23c26a..5ef9154 100644
--- a/lib/bundler/man/gemfile.5
+++ b/lib/bundler/man/gemfile.5
@@ -1,7 +1,7 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
-.TH "GEMFILE" "5" "April 2021" "" ""
+.TH "GEMFILE" "5" "August 2021" "" ""
.
.SH "NAME"
\fBGemfile\fR \- A format for describing gem dependencies for Ruby programs
diff --git a/lib/bundler/plugin.rb b/lib/bundler/plugin.rb
index 023c25b..158c69e 100644
--- a/lib/bundler/plugin.rb
+++ b/lib/bundler/plugin.rb
@@ -13,6 +13,7 @@ module Bundler
class MalformattedPlugin < PluginError; end
class UndefinedCommandError < PluginError; end
class UnknownSourceError < PluginError; end
+ class PluginInstallError < PluginError; end
PLUGIN_FILE_NAME = "plugins.rb".freeze
@@ -38,12 +39,11 @@ module Bundler
specs = Installer.new.install(names, options)
save_plugins names, specs
- rescue PluginError => e
+ rescue PluginError
specs_to_delete = specs.select {|k, _v| names.include?(k) && !index.commands.values.include?(k) }
specs_to_delete.each_value {|spec| Bundler.rm_rf(spec.full_gem_path) }
- names_list = names.map {|name| "`#{name}`" }.join(", ")
- Bundler.ui.error "Failed to install the following plugins: #{names_list}. The underlying error was: #{e.message}.\n #{e.backtrace.join("\n ")}"
+ raise
end
# Uninstalls plugins by the given names
@@ -245,10 +245,11 @@ module Bundler
# @param [Array<String>] names of inferred source plugins that can be ignored
def save_plugins(plugins, specs, optional_plugins = [])
plugins.each do |name|
+ next if index.installed?(name)
+
spec = specs[name]
- validate_plugin! Pathname.new(spec.full_gem_path)
- installed = register_plugin(name, spec, optional_plugins.include?(name))
- Bundler.ui.info "Installed plugin #{name}" if installed
+
+ save_plugin(name, spec, optional_plugins.include?(name))
end
end
@@ -263,6 +264,22 @@ module Bundler
raise MalformattedPlugin, "#{PLUGIN_FILE_NAME} was not found in the plugin." unless plugin_file.file?
end
+ # Validates and registers a plugin.
+ #
+ # @param [String] name the name of the plugin
+ # @param [Specification] spec of installed plugin
+ # @param [Boolean] optional_plugin, removed if there is conflict with any
+ # other plugin (used for default source plugins)
+ #
+ # @raise [PluginInstallError] if validation or registration raises any error
+ def save_plugin(name, spec, optional_plugin = false)
+ validate_plugin! Pathname.new(spec.full_gem_path)
+ installed = register_plugin(name, spec, optional_plugin)
+ Bundler.ui.info "Installed plugin #{name}" if installed
+ rescue PluginError => e
+ raise PluginInstallError, "Failed to install plugin `#{spec.name}`, due to #{e.class} (#{e.message})"
+ end
+
# Runs the plugins.rb file in an isolated namespace, records the plugin
# actions it registers for and then passes the data to index to be stored.
#
@@ -309,6 +326,8 @@ module Bundler
#
# @param [String] name of the plugin
def load_plugin(name)
+ return unless name && !name.empty?
+
# Need to ensure before this that plugin root where the rest of gems
# are installed to be on load path to support plugin deps. Currently not
# done to avoid conflicts
diff --git a/lib/bundler/plugin/api/source.rb b/lib/bundler/plugin/api/source.rb
index d70a16f..f6f4ac4 100644
--- a/lib/bundler/plugin/api/source.rb
+++ b/lib/bundler/plugin/api/source.rb
@@ -244,6 +244,20 @@ module Bundler
specs.unmet_dependency_names
end
+ # Used by definition.
+ #
+ # Note: Do not override if you don't know what you are doing.
+ def spec_names
+ specs.spec_names
+ end
+
+ # Used by definition.
+ #
+ # Note: Do not override if you don't know what you are doing.
+ def add_dependency_names(names)
+ @dependencies |= Array(names)
+ end
+
# Note: Do not override if you don't know what you are doing.
def can_lock?(spec)
spec.source == self
diff --git a/lib/bundler/plugin/index.rb b/lib/bundler/plugin/index.rb
index 819bc60..29d33be 100644
--- a/lib/bundler/plugin/index.rb
+++ b/lib/bundler/plugin/index.rb
@@ -74,7 +74,10 @@ module Bundler
def unregister_plugin(name)
@commands.delete_if {|_, v| v == name }
@sources.delete_if {|_, v| v == name }
- @hooks.each {|_, plugin_names| plugin_names.delete(name) }
+ @hooks.each do |hook, names|
+ names.delete(name)
+ @hooks.delete(hook) if names.empty?
+ end
@plugin_paths.delete(name)
@load_paths.delete(name)
save_index
diff --git a/lib/bundler/plugin/installer.rb b/lib/bundler/plugin/installer.rb
index 980b0e2..d7411ff 100644
--- a/lib/bundler/plugin/installer.rb
+++ b/lib/bundler/plugin/installer.rb
@@ -77,10 +77,12 @@ module Bundler
source_list = SourceList.new
source_list.add_git_source(git_source_options) if git_source_options
- source_list.global_rubygems_source = rubygems_source if rubygems_source
+ Array(rubygems_source).each {|remote| source_list.add_global_rubygems_remote(remote) } if rubygems_source
deps = names.map {|name| Dependency.new name, version }
+ Bundler.configure_gem_home_and_path(Plugin.root)
+
definition = Definition.new(nil, deps, source_list, true)
install_definition(definition)
end
diff --git a/lib/bundler/psyched_yaml.rb b/lib/bundler/psyched_yaml.rb
index 463d52d..3d98930 100644
--- a/lib/bundler/psyched_yaml.rb
+++ b/lib/bundler/psyched_yaml.rb
@@ -1,22 +1,10 @@
# frozen_string_literal: true
-# Psych could be in the stdlib
-# but it's too late if Syck is already loaded
begin
- require "psych" unless defined?(Syck)
+ require "psych"
rescue LoadError
# Apparently Psych wasn't available. Oh well.
end
# At least load the YAML stdlib, whatever that may be
require "yaml" unless defined?(YAML.dump)
-
-module Bundler
- # On encountering invalid YAML,
- # Psych raises Psych::SyntaxError
- if defined?(::Psych::SyntaxError)
- YamlLibrarySyntaxError = ::Psych::SyntaxError
- else # Syck raises ArgumentError
- YamlLibrarySyntaxError = ::ArgumentError
- end
-end
diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb
index 660385c..d26e2fe 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -21,23 +21,19 @@ module Bundler
base = SpecSet.new(base) unless base.is_a?(SpecSet)
resolver = new(source_requirements, base, gem_version_promoter, additional_base_requirements, platforms)
result = resolver.start(requirements)
- SpecSet.new(result).for(requirements.reject{|dep| dep.name.end_with?("\0") })
+ SpecSet.new(SpecSet.new(result).for(requirements.reject{|dep| dep.name.end_with?("\0") }))
end
def initialize(source_requirements, base, gem_version_promoter, additional_base_requirements, platforms)
@source_requirements = source_requirements
-
- @index_requirements = source_requirements.each_with_object({}) do |source_requirement, index_requirements|
- name, source = source_requirement
- index_requirements[name] = name == :global ? source : source.specs
- end
-
@base = base
@resolver = Molinillo::Resolver.new(self, self)
@search_for = {}
@base_dg = Molinillo::DependencyGraph.new
+ aggregate_global_source = @source_requirements[:default].is_a?(Source::RubygemsAggregate)
@base.each do |ls|
dep = Dependency.new(ls.name, ls.version)
+ ls.source = source_for(ls.name) unless aggregate_global_source
@base_dg.add_vertex(ls.name, DepProxy.get_proxy(dep, ls.platform), true)
end
additional_base_requirements.each {|d| @base_dg.add_vertex(d.name, d) }
@@ -45,7 +41,6 @@ module Bundler
@resolving_only_for_ruby = platforms == [Gem::Platform::RUBY]
@gem_version_promoter = gem_version_promoter
@use_gvp = Bundler.feature_flag.use_gem_version_promoter_for_major_updates? || !@gem_version_promoter.major?
- @no_aggregate_global_source = @source_requirements[:global].nil?
end
def start(requirements)
@@ -55,7 +50,6 @@ module Bundler
verify_gemfile_dependencies_are_found!(requirements)
dg = @resolver.resolve(requirements, @base_dg)
dg.
- tap {|resolved| validate_resolved_specs!(resolved) }.
map(&:payload).
reject {|sg| sg.name.end_with?("\0") }.
map(&:to_specs).
@@ -171,16 +165,11 @@ module Bundler
end
def index_for(dependency)
- source = @index_requirements[dependency.name]
- if source
- source
- elsif @no_aggregate_global_source
- Index.build do |idx|
- dependency.all_sources.each {|s| idx.add_source(s.specs) }
- end
- else
- @index_requirements[:global]
- end
+ source_for(dependency.name).specs
+ end
+
+ def source_for(name)
+ @source_requirements[name] || @source_requirements[:default]
end
def results_for(dependency, base)
@@ -211,23 +200,10 @@ module Bundler
dependencies.map(&:dep) == other_dependencies.map(&:dep)
end
- def relevant_sources_for_vertex(vertex)
- if vertex.root?
- [@source_requirements[vertex.name]]
- elsif @no_aggregate_global_source
- vertex.recursive_predecessors.map do |v|
- @source_requirements[v.name]
- end.compact << @source_requirements[:default]
- else
- []
- end
- end
-
def sort_dependencies(dependencies, activated, conflicts)
dependencies.sort_by do |dependency|
name = name_for(dependency)
vertex = activated.vertex_named(name)
- dependency.all_sources = relevant_sources_for_vertex(vertex)
[
@base_dg.vertex_named(name) ? 0 : 1,
vertex.payload ? 0 : 1,
@@ -279,12 +255,6 @@ module Bundler
next if name == "bundler"
next unless search_for(requirement).empty?
- cache_message = begin
- " or in gems cached in #{Bundler.settings.app_cache_path}" if Bundler.app_cache.exist?
- rescue GemfileNotFound
- nil
- end
-
if (base = @base[name]) && !base.empty?
version = base.first.version
message = "You have requested:\n" \
@@ -293,18 +263,17 @@ module Bundler
"Try running `bundle update #{name}`\n\n" \
"If you are updating multiple gems in your Gemfile at once,\n" \
"try passing them all to `bundle update`"
- elsif source = @source_requirements[name]
+ else
+ source = source_for(name)
specs = source.specs.search(name)
versions_with_platforms = specs.map {|s| [s.version, s.platform] }
- message = String.new("Could not find gem '#{SharedHelpers.pretty_dependency(requirement)}' in #{source}#{cache_message}.\n")
- message << if versions_with_platforms.any?
- "The source contains the following versions of '#{name}': #{formatted_versions_with_platforms(versions_with_platforms)}"
- else
- "The source does not contain any versions of '#{name}'"
- end
- else
- message = "Could not find gem '#{SharedHelpers.pretty_dependency(requirement)}' in any of the gem sources " \
- "listed in your Gemfile#{cache_message}."
+ cache_message = begin
+ " or in gems cached in #{Bundler.settings.app_cache_path}" if Bundler.app_cache.exist?
+ rescue GemfileNotFound
+ nil
+ end
+ message = String.new("Could not find gem '#{SharedHelpers.pretty_dependency(requirement)}' in #{source.to_err}#{cache_message}.\n")
+ message << "The source contains the following versions of '#{name}': #{formatted_versions_with_platforms(versions_with_platforms)}" if versions_with_platforms.any?
end
raise GemNotFound, message
end
@@ -369,7 +338,7 @@ module Bundler
if other_bundler_required
o << "\n\n"
- candidate_specs = @index_requirements[:default_bundler].search(conflict_dependency)
+ candidate_specs = source_for(:default_bundler).specs.search(conflict_dependency)
if candidate_specs.any?
target_version = candidate_specs.last.version
new_command = [File.basename($PROGRAM_NAME), "_#{target_version}_", *ARGV].join(" ")
@@ -386,11 +355,7 @@ module Bundler
elsif !conflict.existing
o << "\n"
- relevant_sources = if conflict.requirement.source
- [conflict.requirement.source]
- else
- conflict.requirement.all_sources
- end.compact.map(&:to_s).uniq.sort
+ relevant_source = conflict.requirement.source || source_for(name)
metadata_requirement = name.end_with?("\0")
@@ -403,12 +368,10 @@ module Bundler
end
o << " "
- o << if relevant_sources.empty?
- "in any of the sources.\n"
- elsif metadata_requirement
- "is not available in #{relevant_sources.join(" or ")}"
+ o << if metadata_requirement
+ "is not available in #{relevant_source}"
else
- "in any of the relevant sources:\n #{relevant_sources * "\n "}\n"
+ "in #{relevant_source.to_err}.\n"
end
end
end,
@@ -422,27 +385,5 @@ module Bundler
end
)
end
-
- def validate_resolved_specs!(resolved_specs)
- resolved_specs.each do |v|
- name = v.name
- sources = relevant_sources_for_vertex(v)
- next unless sources.any?
- if default_index = sources.index(@source_requirements[:default])
- sources.delete_at(default_index)
- end
- sources.reject! {|s| s.specs.search(name).empty? }
- sources.uniq!
- next if sources.size <= 1
-
- msg = ["The gem '#{name}' was found in multiple relevant sources."]
- msg.concat sources.map {|s| " * #{s}" }.sort
- msg << "You #{@no_aggregate_global_source ? :must : :should} add this gem to the source block for the source you wish it to be installed from."
- msg = msg.join("\n")
-
- raise SecurityError, msg if @no_aggregate_global_source
- Bundler.ui.warn "Warning: #{msg}"
- end
- end
end
end
diff --git a/lib/bundler/rubygems_ext.rb b/lib/bundler/rubygems_ext.rb
index 2bd2dcb..2613207 100644
--- a/lib/bundler/rubygems_ext.rb
+++ b/lib/bundler/rubygems_ext.rb
@@ -105,7 +105,7 @@ module Gem
end
class Dependency
- attr_accessor :source, :groups, :all_sources
+ attr_accessor :source, :groups
alias_method :eql?, :==
@@ -116,7 +116,7 @@ module Gem
end
def to_yaml_properties
- instance_variables.reject {|p| ["@source", "@groups", "@all_sources"].include?(p.to_s) }
+ instance_variables.reject {|p| ["@source", "@groups"].include?(p.to_s) }
end
def to_lock
@@ -134,6 +134,8 @@ module Gem
class Requirement
module OrderIndependentComparison
def ==(other)
+ return unless Gem::Requirement === other
+
if _requirements_sorted? && other._requirements_sorted?
super
else
@@ -174,20 +176,36 @@ module Gem
end
end
+ require "rubygems/platform"
+
class Platform
JAVA = Gem::Platform.new("java") unless defined?(JAVA)
MSWIN = Gem::Platform.new("mswin32") unless defined?(MSWIN)
MSWIN64 = Gem::Platform.new("mswin64") unless defined?(MSWIN64)
MINGW = Gem::Platform.new("x86-mingw32") unless defined?(MINGW)
X64_MINGW = Gem::Platform.new("x64-mingw32") unless defined?(X64_MINGW)
+ end
- undef_method :hash if method_defined? :hash
- def hash
- @cpu.hash ^ @os.hash ^ @version.hash
- end
+ Platform.singleton_class.module_eval do
+ unless Platform.singleton_methods.include?(:match_spec?)
+ def match_spec?(spec)
+ match_gem?(spec.platform, spec.name)
+ end
- undef_method :eql? if method_defined? :eql?
- alias_method :eql?, :==
+ def match_gem?(platform, gem_name)
+ match_platforms?(platform, Gem.platforms)
+ end
+
+ private
+
+ def match_platforms?(platform, platforms)
+ platforms.any? do |local_platform|
+ platform.nil? ||
+ local_platform == platform ||
+ (local_platform != Gem::Platform::RUBY && local_platform =~ platform)
+ end
+ end
+ end
end
require "rubygems/util"
diff --git a/lib/bundler/rubygems_gem_installer.rb b/lib/bundler/rubygems_gem_installer.rb
index f5f3c53..8890582 100644
--- a/lib/bundler/rubygems_gem_installer.rb
+++ b/lib/bundler/rubygems_gem_installer.rb
@@ -61,7 +61,10 @@ module Bundler
def build_extensions
extension_cache_path = options[:bundler_extension_cache_path]
- return super unless extension_cache_path && extension_dir = spec.extension_dir
+ unless extension_cache_path && extension_dir = spec.extension_dir
+ require "shellwords" # compensate missing require in rubygems before version 3.2.25
+ return super
+ end
extension_dir = Pathname.new(extension_dir)
build_complete = SharedHelpers.filesystem_access(extension_cache_path.join("gem.build_complete"), :read, &:file?)
@@ -71,6 +74,7 @@ module Bundler
FileUtils.cp_r extension_cache_path, spec.extension_dir
end
else
+ require "shellwords" # compensate missing require in rubygems before version 3.2.25
super
if extension_dir.directory? # not made for gems without extensions
SharedHelpers.filesystem_access(extension_cache_path.parent, &:mkpath)
diff --git a/lib/bundler/rubygems_integration.rb b/lib/bundler/rubygems_integration.rb
index d060e21..789797d 100644
--- a/lib/bundler/rubygems_integration.rb
+++ b/lib/bundler/rubygems_integration.rb
@@ -34,10 +34,12 @@ module Bundler
end
def build_args
+ require "rubygems/command"
Gem::Command.build_args
end
def build_args=(args)
+ require "rubygems/command"
Gem::Command.build_args = args
end
@@ -117,7 +119,7 @@ module Bundler
Bundler.ui.error "#{e.class}: #{e.message}"
Bundler.ui.trace e
raise
- rescue YamlLibrarySyntaxError => e
+ rescue ::Psych::SyntaxError => e
raise YamlSyntaxError.new(e, "Your RubyGems configuration, which is " \
"usually located in ~/.gemrc, contains invalid YAML syntax.")
end
@@ -526,13 +528,14 @@ module Bundler
Bundler::Retry.new("download gem from #{uri}").attempts do
fetcher.download(spec, uri, path)
end
+ rescue Gem::RemoteFetcher::FetchError => e
+ raise Bundler::HTTPError, "Could not download gem from #{uri} due to underlying error <#{e.message}>"
end
def gem_remote_fetcher
- require "resolv"
+ require "rubygems/remote_fetcher"
proxy = configuration[:http_proxy]
- dns = Resolv::DNS.new
- Gem::RemoteFetcher.new(proxy, dns)
+ Gem::RemoteFetcher.new(proxy)
end
def gem_from_path(path, policy = nil)
@@ -597,14 +600,6 @@ module Bundler
Gem::Specification.send(:default_stubs, "*.gemspec")
end
end
-
- def use_gemdeps(gemfile)
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path(gemfile)
- require_relative "gemdeps"
- runtime = Bundler.setup
- activated_spec_names = runtime.requested_specs.map(&:to_spec).sort_by(&:name)
- [Gemdeps.new(runtime), activated_spec_names]
- end
end
def self.rubygems
diff --git a/lib/bundler/runtime.rb b/lib/bundler/runtime.rb
index e259b59..fbb8833 100644
--- a/lib/bundler/runtime.rb
+++ b/lib/bundler/runtime.rb
@@ -12,22 +12,16 @@ module Bundler
def setup(*groups)
@definition.ensure_equivalent_gemfile_and_lockfile if Bundler.frozen_bundle?
- groups.map!(&:to_sym)
-
# Has to happen first
clean_load_path
- specs = groups.any? ? @definition.specs_for(groups) : requested_specs
+ specs = @definition.specs_for(groups)
SharedHelpers.set_bundle_environment
Bundler.rubygems.replace_entrypoints(specs)
# Activate the specs
load_paths = specs.map do |spec|
- unless spec.loaded_from
- raise GemNotFound, "#{spec.full_name} is missing. Run `bundle install` to get it."
- end
-
check_for_activated_spec!(spec)
Bundler.rubygems.mark_loaded(spec)
@@ -106,7 +100,7 @@ module Bundler
alias_method :gems, :specs
- def cache(custom_path = nil)
+ def cache(custom_path = nil, local = false)
cache_path = Bundler.app_cache(custom_path)
SharedHelpers.filesystem_access(cache_path) do |p|
FileUtils.mkdir_p(p)
@@ -114,7 +108,20 @@ module Bundler
Bundler.ui.info "Updating files in #{Bundler.settings.app_cache_path}"
- specs_to_cache = Bundler.settings[:cache_all_platforms] ? @definition.resolve.materialized_for_all_platforms : specs
+ specs_to_cache = if Bundler.settings[:cache_all_platforms]
+ @definition.resolve.materialized_for_all_platforms
+ else
+ begin
+ specs
+ rescue GemNotFound
+ if local
+ Bundler.ui.warn "Some gems seem to be missing from your #{Bundler.settings.app_cache_path} directory."
+ end
+
+ raise
+ end
+ end
+
specs_to_cache.each do |spec|
next if spec.name == "bundler"
next if spec.source.is_a?(Source::Gemspec)
diff --git a/lib/bundler/settings.rb b/lib/bundler/settings.rb
index e9155ac..1ced590 100644
--- a/lib/bundler/settings.rb
+++ b/lib/bundler/settings.rb
@@ -20,7 +20,6 @@ module Bundler
disable_exec_load
disable_local_branch_check
disable_local_revision_check
- disable_multisource
disable_shared_gems
disable_version_check
force_ruby_platform
@@ -45,7 +44,6 @@ module Bundler
silence_deprecations
silence_root_warning
suppress_install_using_messages
- unlock_source_unlocks_spec
update_requires_all_flag
use_gem_version_promoter_for_major_updates
].freeze
@@ -210,6 +208,13 @@ module Bundler
locations
end
+ def processor_count
+ require "etc"
+ Etc.nprocessors
+ rescue StandardError
+ 1
+ end
+
# for legacy reasons, in Bundler 2, we do not respect :disable_shared_gems
def path
configs.each do |_level, settings|
@@ -414,7 +419,15 @@ module Bundler
elsif is_credential(key)
"[REDACTED]"
elsif is_userinfo(converted)
- converted.gsub(/:.*$/, ":[REDACTED]")
+ username, pass = converted.split(":", 2)
+
+ if pass == "x-oauth-basic"
+ username = "[REDACTED]"
+ else
+ pass = "[REDACTED]"
+ end
+
+ [username, pass].join(":")
else
converted
end
@@ -423,12 +436,12 @@ module Bundler
def global_config_file
if ENV["BUNDLE_CONFIG"] && !ENV["BUNDLE_CONFIG"].empty?
Pathname.new(ENV["BUNDLE_CONFIG"])
- else
- begin
- Bundler.user_bundle_path("config")
- rescue PermissionError, GenericSystemCallError
- nil
- end
+ elsif ENV["BUNDLE_USER_CONFIG"] && !ENV["BUNDLE_USER_CONFIG"].empty?
+ Pathname.new(ENV["BUNDLE_USER_CONFIG"])
+ elsif ENV["BUNDLE_USER_HOME"] && !ENV["BUNDLE_USER_HOME"].empty?
+ Pathname.new(ENV["BUNDLE_USER_HOME"]).join("config")
+ elsif Bundler.rubygems.user_home && !Bundler.rubygems.user_home.empty?
+ Pathname.new(Bundler.rubygems.user_home).join(".bundle/config")
end
end
@@ -442,7 +455,20 @@ module Bundler
valid_file = file.exist? && !file.size.zero?
return {} unless valid_file
require_relative "yaml_serializer"
- YAMLSerializer.load file.read
+ YAMLSerializer.load(file.read).inject({}) do |config, (k, v)|
+ new_k = k
+
+ if k.include?("-")
+ Bundler.ui.warn "Your #{file} config includes `#{k}`, which contains the dash character (`-`).\n" \
+ "This is deprecated, because configuration through `ENV` should be possible, but `ENV` keys cannot include dashes.\n" \
+ "Please edit #{file} and replace any dashes in configuration keys with a triple underscore (`___`)."
+
+ new_k = k.gsub("-", "___")
+ end
+
+ config[new_k] = v
+ config
+ end
end
end
diff --git a/lib/bundler/setup.rb b/lib/bundler/setup.rb
index 27911dc..32e9b2d 100644
--- a/lib/bundler/setup.rb
+++ b/lib/bundler/setup.rb
@@ -9,10 +9,10 @@ if Bundler::SharedHelpers.in_bundle?
begin
Bundler.ui.silence { Bundler.setup }
rescue Bundler::BundlerError => e
- Bundler.ui.warn "\e[31m#{e.message}\e[0m"
+ Bundler.ui.error e.message
Bundler.ui.warn e.backtrace.join("\n") if ENV["DEBUG"]
if e.is_a?(Bundler::GemNotFound)
- Bundler.ui.warn "\e[33mRun `bundle install` to install missing gems.\e[0m"
+ Bundler.ui.warn "Run `bundle install` to install missing gems."
end
exit e.status_code
end
diff --git a/lib/bundler/shared_helpers.rb b/lib/bundler/shared_helpers.rb
index f43e330..405ade9 100644
--- a/lib/bundler/shared_helpers.rb
+++ b/lib/bundler/shared_helpers.rb
@@ -145,13 +145,6 @@ module Bundler
Bundler.ui.warn message
end
- def trap(signal, override = false, &block)
- prior = Signal.trap(signal) do
- block.call
- prior.call unless override
- end
- end
-
def ensure_same_dependencies(spec, old_deps, new_deps)
new_deps = new_deps.reject {|d| d.type == :development }
old_deps = old_deps.reject {|d| d.type == :development }
diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb
index a3f4b09..434112a 100644
--- a/lib/bundler/source.rb
+++ b/lib/bundler/source.rb
@@ -7,6 +7,7 @@ module Bundler
autoload :Metadata, File.expand_path("source/metadata", __dir__)
autoload :Path, File.expand_path("source/path", __dir__)
autoload :Rubygems, File.expand_path("source/rubygems", __dir__)
+ autoload :RubygemsAggregate, File.expand_path("source/rubygems_aggregate", __dir__)
attr_accessor :dependency_names
@@ -35,10 +36,16 @@ module Bundler
def local!; end
+ def local_only!; end
+
def cached!; end
def remote!; end
+ def add_dependency_names(names)
+ @dependency_names = Array(dependency_names) | Array(names)
+ end
+
# it's possible that gems from one source depend on gems from some
# other source, so now we download gemspecs and iterate over those
# dependencies, looking for gems we don't have info on yet.
@@ -48,6 +55,10 @@ module Bundler
specs.dependency_names
end
+ def spec_names
+ specs.spec_names
+ end
+
def include?(other)
other == self
end
@@ -56,6 +67,10 @@ module Bundler
"#<#{self.class}:0x#{object_id} #{self}>"
end
+ def to_err
+ to_s
+ end
+
def path?
instance_of?(Bundler::Source::Path)
end
diff --git a/lib/bundler/source/git/git_proxy.rb b/lib/bundler/source/git/git_proxy.rb
index ae21770..7555561 100644
--- a/lib/bundler/source/git/git_proxy.rb
+++ b/lib/bundler/source/git/git_proxy.rb
@@ -1,7 +1,5 @@
# frozen_string_literal: true
-require "shellwords"
-
module Bundler
class Source
class Git
@@ -224,6 +222,7 @@ module Bundler
end
def check_allowed(command)
+ require "shellwords"
command_with_no_credentials = URICredentialsFilter.credential_filtered_string("git #{command.shelljoin}", uri)
raise GitNotAllowedError.new(command_with_no_credentials) unless allow?
command_with_no_credentials
diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb
index 2b7cfd5..7f8699b 100644
--- a/lib/bundler/source/rubygems.rb
+++ b/lib/bundler/source/rubygems.rb
@@ -26,6 +26,13 @@ module Bundler
Array(options["remotes"]).reverse_each {|r| add_remote(r) }
end
+ def local_only!
+ @specs = nil
+ @allow_local = true
+ @allow_cached = false
+ @allow_remote = false
+ end
+
def local!
return if @allow_local
@@ -44,6 +51,7 @@ module Bundler
return if @allow_cached
@specs = nil
+ @allow_local = true
@allow_cached = true
end
@@ -61,13 +69,17 @@ module Bundler
o.is_a?(Rubygems) && (o.credless_remotes - credless_remotes).empty?
end
- def disable_multisource?
- @remotes.size <= 1
+ def multiple_remotes?
+ @remotes.size > 1
+ end
+
+ def no_remotes?
+ @remotes.size == 0
end
def can_lock?(spec)
- return super if disable_multisource?
- spec.source.is_a?(Rubygems)
+ return super unless multiple_remotes?
+ include?(spec.source)
end
def options
@@ -86,11 +98,22 @@ module Bundler
out << " specs:\n"
end
+ def to_err
+ if remotes.empty?
+ "locally installed gems"
+ elsif @allow_remote
+ "rubygems repository #{remote_names} or installed locally"
+ elsif @allow_cached
+ "cached gems from rubygems repository #{remote_names} or installed locally"
+ else
+ "locally installed gems"
+ end
+ end
+
def to_s
if remotes.empty?
"locally installed gems"
else
- remote_names = remotes.map(&:to_s).join(", ")
"rubygems repository #{remote_names} or installed locally"
end
end
@@ -121,7 +144,7 @@ module Bundler
end
end
- if (installed?(spec) || Plugin.installed?(spec.name)) && !force
+ if installed?(spec) && !force
print_using_message "Using #{version_message(spec)}"
return nil # no post-install message
end
@@ -246,21 +269,16 @@ module Bundler
other_remotes.map(&method(:remove_auth)) == @remotes.map(&method(:remove_auth))
end
- def replace_remotes(other_remotes, allow_equivalent = false)
- return false if other_remotes == @remotes
-
- equivalent = allow_equivalent && equivalent_remotes?(other_remotes)
-
- @remotes = []
- other_remotes.reverse_each do |r|
- add_remote r.to_s
+ def spec_names
+ if @allow_remote && dependency_api_available?
+ remote_specs.spec_names
+ else
+ []
end
-
- !equivalent
end
def unmet_deps
- if @allow_remote && api_fetchers.any?
+ if @allow_remote && dependency_api_available?
remote_specs.unmet_dependency_names
else
[]
@@ -276,7 +294,7 @@ module Bundler
def double_check_for(unmet_dependency_names)
return unless @allow_remote
- return unless api_fetchers.any?
+ return unless dependency_api_available?
unmet_dependency_names = unmet_dependency_names.call
unless unmet_dependency_names.nil?
@@ -298,19 +316,26 @@ module Bundler
remote_specs.each do |spec|
case spec
when EndpointSpecification, Gem::Specification, StubSpecification, LazySpecification
- names.concat(spec.runtime_dependencies)
+ names.concat(spec.runtime_dependencies.map(&:name))
when RemoteSpecification # from the full index
return nil
else
raise "unhandled spec type (#{spec.inspect})"
end
end
- names.map!(&:name) if names
names
end
+ def dependency_api_available?
+ api_fetchers.any?
+ end
+
protected
+ def remote_names
+ remotes.map(&:to_s).join(", ")
+ end
+
def credless_remotes
remotes.map(&method(:suppress_configured_credentials))
end
@@ -387,10 +412,6 @@ module Bundler
next if gemfile =~ /^bundler\-[\d\.]+?\.gem/
s ||= Bundler.rubygems.spec_from_gem(gemfile)
s.source = self
- if Bundler.rubygems.spec_missing_extensions?(s, false)
- Bundler.ui.debug "Source #{self} is ignoring #{s} because it is missing extensions"
- next
- end
idx << s
end
diff --git a/lib/bundler/source/rubygems_aggregate.rb b/lib/bundler/source/rubygems_aggregate.rb
new file mode 100644
index 0000000..09cf400
--- /dev/null
+++ b/lib/bundler/source/rubygems_aggregate.rb
@@ -0,0 +1,68 @@
+# frozen_string_literal: true
+
+module Bundler
+ class Source
+ class RubygemsAggregate
+ attr_reader :source_map, :sources
+
+ def initialize(sources, source_map)
+ @sources = sources
+ @source_map = source_map
+
+ @index = build_index
+ end
+
+ def specs
+ @index
+ end
+
+ def to_err
+ to_s
+ end
+
+ def to_s
+ "any of the sources"
+ end
+
+ private
+
+ def build_index
+ Index.build do |idx|
+ dependency_names = source_map.pinned_spec_names
+
+ sources.all_sources.each do |source|
+ source.dependency_names = dependency_names - source_map.pinned_spec_names(source)
+ idx.add_source source.specs
+ dependency_names.concat(source.unmet_deps).uniq!
+ end
+
+ double_check_for_index(idx, dependency_names)
+ end
+ end
+
+ # Suppose the gem Foo depends on the gem Bar. Foo exists in Source A. Bar has some versions that exist in both
+ # sources A and B. At this point, the API request will have found all the versions of Bar in source A,
+ # but will not have found any versions of Bar from source B, which is a problem if the requested version
+ # of Foo specifically depends on a version of Bar that is only found in source B. This ensures that for
+ # each spec we found, we add all possible versions from all sources to the index.
+ def double_check_for_index(idx, dependency_names)
+ pinned_names = source_map.pinned_spec_names
+
+ names = :names # do this so we only have to traverse to get dependency_names from the index once
+ unmet_dependency_names = lambda do
+ return names unless names == :names
+ new_names = sources.all_sources.map(&:dependency_names_to_double_check)
+ return names = nil if new_names.compact!
+ names = new_names.flatten(1).concat(dependency_names)
+ names.uniq!
+ names -= pinned_names
+ names
+ end
+
+ sources.all_sources.each do |source|
+ source.double_check_for(unmet_dependency_names)
+ end
+ end
+ end
+ end
+end
diff --git a/lib/bundler/source_list.rb b/lib/bundler/source_list.rb
index 6f5636f..d6310b7 100644
--- a/lib/bundler/source_list.rb
+++ b/lib/bundler/source_list.rb
@@ -21,15 +21,24 @@ module Bundler
@rubygems_sources = []
@metadata_source = Source::Metadata.new
- @disable_multisource = true
+ @merged_gem_lockfile_sections = false
end
- def disable_multisource?
- @disable_multisource
+ def merged_gem_lockfile_sections?
+ @merged_gem_lockfile_sections
end
- def merged_gem_lockfile_sections!
- @disable_multisource = false
+ def merged_gem_lockfile_sections!(replacement_source)
+ @merged_gem_lockfile_sections = true
+ @global_rubygems_source = replacement_source
+ end
+
+ def aggregate_global_source?
+ global_rubygems_source.multiple_remotes?
+ end
+
+ def implicit_global_source?
+ global_rubygems_source.no_remotes?
end
def add_path_source(options = {})
@@ -49,18 +58,17 @@ module Bundler
end
def add_rubygems_source(options = {})
- add_source_to_list Source::Rubygems.new(options), @rubygems_sources
+ new_source = Source::Rubygems.new(options)
+ return @global_rubygems_source if @global_rubygems_source == new_source
+
+ add_source_to_list new_source, @rubygems_sources
end
def add_plugin_source(source, options = {})
add_source_to_list Plugin.source(source).new(options), @plugin_sources
end
- def global_rubygems_source=(uri)
- @global_rubygems_source ||= rubygems_aggregate_class.new("remotes" => uri, "allow_local" => true)
- end
-
- def add_rubygems_remote(uri)
+ def add_global_rubygems_remote(uri)
global_rubygems_source.add_remote(uri)
global_rubygems_source
end
@@ -70,7 +78,11 @@ module Bundler
end
def rubygems_sources
- @rubygems_sources + [global_rubygems_source]
+ non_global_rubygems_sources + [global_rubygems_source]
+ end
+
+ def non_global_rubygems_sources
+ @rubygems_sources
end
def rubygems_remotes
@@ -81,36 +93,51 @@ module Bundler
path_sources + git_sources + plugin_sources + rubygems_sources + [metadata_source]
end
+ def non_default_explicit_sources
+ all_sources - [default_source, metadata_source]
+ end
+
def get(source)
source_list_for(source).find {|s| equal_source?(source, s) || equivalent_source?(source, s) }
end
def lock_sources
- lock_sources = (path_sources + git_sources + plugin_sources).sort_by(&:to_s)
- if disable_multisource?
- lock_sources + rubygems_sources.sort_by(&:to_s).uniq
+ lock_other_sources + lock_rubygems_sources
+ end
+
+ def lock_other_sources
+ (path_sources + git_sources + plugin_sources).sort_by(&:to_s)
+ end
+
+ def lock_rubygems_sources
+ if merged_gem_lockfile_sections?
+ [combine_rubygems_sources]
else
- lock_sources << combine_rubygems_sources
+ rubygems_sources.sort_by(&:to_s)
end
end
# Returns true if there are changes
def replace_sources!(replacement_sources)
- return true if replacement_sources.empty?
+ return false if replacement_sources.empty?
- [path_sources, git_sources, plugin_sources].each do |source_list|
- source_list.map! do |source|
- replacement_sources.find {|s| s == source } || source
- end
- end
+ @rubygems_sources, @path_sources, @git_sources, @plugin_sources = map_sources(replacement_sources)
+ @global_rubygems_source = global_replacement_source(replacement_sources)
- replacement_rubygems = !disable_multisource? &&
- replacement_sources.detect {|s| s.is_a?(Source::Rubygems) }
- @global_rubygems_source = replacement_rubygems if replacement_rubygems
+ different_sources?(lock_sources, replacement_sources)
+ end
+
+ # Returns true if there are changes
+ def expired_sources?(replacement_sources)
+ return false if replacement_sources.empty?
- return true if !equal_sources?(lock_sources, replacement_sources) && !equivalent_sources?(lock_sources, replacement_sources)
+ lock_sources = dup_with_replaced_sources(replacement_sources).lock_sources
+
+ different_sources?(lock_sources, replacement_sources)
+ end
- false
+ def local_only!
+ all_sources.each(&:local_only!)
end
def cached!
@@ -123,6 +150,32 @@ module Bundler
private
+ def dup_with_replaced_sources(replacement_sources)
+ new_source_list = dup
+ new_source_list.replace_sources!(replacement_sources)
+ new_source_list
+ end
+
+ def map_sources(replacement_sources)
+ [@rubygems_sources, @path_sources, @git_sources, @plugin_sources].map do |sources|
+ sources.map do |source|
+ replacement_sources.find {|s| s == source } || source
+ end
+ end
+ end
+
+ def global_replacement_source(replacement_sources)
+ replacement_source = replacement_sources.find {|s| s == global_rubygems_source }
+ return global_rubygems_source unless replacement_source
+
+ replacement_source.local!
+ replacement_source
+ end
+
+ def different_sources?(lock_sources, replacement_sources)
+ !equal_sources?(lock_sources, replacement_sources) && !equivalent_sources?(lock_sources, replacement_sources)
+ end
+
def rubygems_aggregate_class
Source::Rubygems
end
@@ -162,6 +215,8 @@ module Bundler
end
def equal_source?(source, other_source)
+ return source.include?(other_source) if source.is_a?(Source::Rubygems) && other_source.is_a?(Source::Rubygems)
+
source == other_source
end
diff --git a/lib/bundler/source_map.rb b/lib/bundler/source_map.rb
new file mode 100644
index 0000000..a554f26
--- /dev/null
+++ b/lib/bundler/source_map.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+module Bundler
+ class SourceMap
+ attr_reader :sources, :dependencies
+
+ def initialize(sources, dependencies)
+ @sources = sources
+ @dependencies = dependencies
+ end
+
+ def pinned_spec_names(skip = nil)
+ direct_requirements.reject {|_, source| source == skip }.keys
+ end
+
+ def all_requirements
+ requirements = direct_requirements.dup
+
+ unmet_deps = sources.non_default_explicit_sources.map do |source|
+ (source.spec_names - pinned_spec_names).each do |indirect_dependency_name|
+ previous_source = requirements[indirect_dependency_name]
+ if previous_source.nil?
+ requirements[indirect_dependency_name] = source
+ else
+ no_ambiguous_sources = Bundler.feature_flag.bundler_3_mode?
+
+ msg = ["The gem '#{indirect_dependency_name}' was found in multiple relevant sources."]
+ msg.concat [previous_source, source].map {|s| " * #{s}" }.sort
+ msg << "You #{no_ambiguous_sources ? :must : :should} add this gem to the source block for the source you wish it to be installed from."
+ msg = msg.join("\n")
+
+ raise SecurityError, msg if no_ambiguous_sources
+ Bundler.ui.warn "Warning: #{msg}"
+ end
+ end
+
+ source.unmet_deps
+ end
+
+ sources.default_source.add_dependency_names(unmet_deps.flatten - requirements.keys)
+
+ requirements
+ end
+
+ def direct_requirements
+ @direct_requirements ||= begin
+ requirements = {}
+ default = sources.default_source
+ dependencies.each do |dep|
+ dep_source = dep.source || default
+ dep_source.add_dependency_names(dep.name)
+ requirements[dep.name] = dep_source
+ end
+ requirements
+ end
+ end
+ end
+end
diff --git a/lib/bundler/spec_set.rb b/lib/bundler/spec_set.rb
index 67669cd..26d41cb 100644
--- a/lib/bundler/spec_set.rb
+++ b/lib/bundler/spec_set.rb
@@ -11,21 +11,20 @@ module Bundler
@specs = specs
end
- def for(dependencies, skip = [], check = false, match_current_platform = false, raise_on_missing = true)
+ def for(dependencies, check = false, match_current_platform = false)
handled = []
deps = dependencies.dup
specs = []
- skip += ["bundler"]
loop do
break unless dep = deps.shift
- next if handled.include?(dep) || skip.include?(dep.name)
+ next if handled.any?{|d| d.name == dep.name && (match_current_platform || d.__platform == dep.__platform) } || dep.name == "bundler"
handled << dep
specs_for_dep = spec_for_dependency(dep, match_current_platform)
if specs_for_dep.any?
- specs += specs_for_dep
+ match_current_platform ? specs += specs_for_dep : specs |= specs_for_dep
specs_for_dep.first.dependencies.each do |d|
next if d.type == :development
@@ -34,11 +33,6 @@ module Bundler
end
elsif check
return false
- elsif raise_on_missing
- others = lookup[dep.name] if match_current_platform
- message = "Unable to find a spec satisfying #{dep} in the set. Perhaps the lockfile is corrupted?"
- message += " Found #{others.join(", ")} that did not match the current platform." if others && !others.empty?
- raise GemNotFound, message
end
end
@@ -46,11 +40,7 @@ module Bundler
specs << spec
end
- check ? true : SpecSet.new(specs)
- end
-
- def valid_for?(deps)
- self.for(deps, [], true)
+ check ? true : specs
end
def [](key)
@@ -76,52 +66,35 @@ module Bundler
lookup.dup
end
- def materialize(deps, missing_specs = nil)
- materialized = self.for(deps, [], false, true, !missing_specs).to_a
-
- materialized.group_by(&:source).each do |source, specs|
- next unless specs.any?{|s| s.is_a?(LazySpecification) }
-
- source.local!
- names = -> { specs.map(&:name).uniq }
- source.double_check_for(names)
- end
+ def materialize(deps)
+ materialized = self.for(deps, false, true)
materialized.map! do |s|
next s unless s.is_a?(LazySpecification)
- spec = s.__materialize__
- unless spec
- unless missing_specs
- raise GemNotFound, "Could not find #{s.full_name} in any of the sources"
- end
- missing_specs << s
- end
- spec
+ s.source.local!
+ s.__materialize__ || s
end
- SpecSet.new(missing_specs ? materialized.compact : materialized)
+ SpecSet.new(materialized)
end
# Materialize for all the specs in the spec set, regardless of what platform they're for
# This is in contrast to how for does platform filtering (and specifically different from how `materialize` calls `for` only for the current platform)
# @return [Array<Gem::Specification>]
def materialized_for_all_platforms
- @specs.group_by(&:source).each do |source, specs|
- next unless specs.any?{|s| s.is_a?(LazySpecification) }
-
- source.local!
- source.remote!
- names = -> { specs.map(&:name).uniq }
- source.double_check_for(names)
- end
-
@specs.map do |s|
next s unless s.is_a?(LazySpecification)
+ s.source.local!
+ s.source.remote!
spec = s.__materialize__
raise GemNotFound, "Could not find #{s.full_name} in any of the sources" unless spec
spec
end
end
+ def missing_specs
+ @specs.select {|s| s.is_a?(LazySpecification) }
+ end
+
def merge(set)
arr = sorted.dup
set.each do |set_spec|
@@ -199,7 +172,7 @@ module Bundler
def spec_for_dependency(dep, match_current_platform)
specs_for_platforms = lookup[dep.name]
if match_current_platform
- GemHelpers.select_best_platform_match(specs_for_platforms, Bundler.local_platform)
+ GemHelpers.select_best_platform_match(specs_for_platforms.select{|s| Gem::Platform.match_spec?(s) }, Bundler.local_platform)
else
GemHelpers.select_best_platform_match(specs_for_platforms, dep.__platform)
end
diff --git a/lib/bundler/templates/Executable.bundler b/lib/bundler/templates/Executable.bundler
index 69f26bb..8009412 100644
--- a/lib/bundler/templates/Executable.bundler
+++ b/lib/bundler/templates/Executable.bundler
@@ -60,16 +60,16 @@ m = Module.new do
Regexp.last_match(1)
end
- def bundler_version
- @bundler_version ||=
+ def bundler_requirement
+ @bundler_requirement ||=
env_var_version || cli_arg_version ||
- lockfile_version
+ bundler_requirement_for(lockfile_version)
end
- def bundler_requirement
- return "#{Gem::Requirement.default}.a" unless bundler_version
+ def bundler_requirement_for(version)
+ return "#{Gem::Requirement.default}.a" unless version
- bundler_gem_version = Gem::Version.new(bundler_version)
+ bundler_gem_version = Gem::Version.new(version)
requirement = bundler_gem_version.approximate_recommendation
diff --git a/lib/bundler/templates/newgem/github/workflows/main.yml.tt b/lib/bundler/templates/newgem/github/workflows/main.yml.tt
index 6549780..952cd64 100644
--- a/lib/bundler/templates/newgem/github/workflows/main.yml.tt
+++ b/lib/bundler/templates/newgem/github/workflows/main.yml.tt
@@ -1,16 +1,27 @@
name: Ruby
-on: [push,pull_request]
+on:
+ push:
+ branches:
+ - <%= config[:git_default_branch] %>
+
+ pull_request:
jobs:
build:
runs-on: ubuntu-latest
+
+ strategy:
+ matrix:
+ ruby:
+ - <%= RUBY_VERSION %>
+
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
- ruby-version: <%= RUBY_VERSION %>
+ ruby-version: ${{ matrix.ruby }}
bundler-cache: true
- name: Run the default task
run: bundle exec rake
diff --git a/lib/bundler/templates/newgem/newgem.gemspec.tt b/lib/bundler/templates/newgem/newgem.gemspec.tt
index d961d61..e07ec58 100644
--- a/lib/bundler/templates/newgem/newgem.gemspec.tt
+++ b/lib/bundler/templates/newgem/newgem.gemspec.tt
@@ -14,9 +14,9 @@ Gem::Specification.new do |spec|
<%- if config[:mit] -%>
spec.license = "MIT"
<%- end -%>
- spec.required_ruby_version = Gem::Requirement.new(">= <%= config[:required_ruby_version] %>")
+ spec.required_ruby_version = ">= <%= config[:required_ruby_version] %>"
- spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
+ spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject do |f|
- f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
end
end
spec.bindir = "exe"
diff --git a/lib/bundler/vendor/connection_pool/lib/connection_pool.rb b/lib/bundler/vendor/connection_pool/lib/connection_pool.rb
index fbcd26c..984c1c3 100644
--- a/lib/bundler/vendor/connection_pool/lib/connection_pool.rb
+++ b/lib/bundler/vendor/connection_pool/lib/connection_pool.rb
@@ -1,14 +1,18 @@
-require_relative 'connection_pool/version'
-require_relative 'connection_pool/timed_stack'
+require "timeout"
+require_relative "connection_pool/version"
+class Bundler::ConnectionPool
+ class Error < ::RuntimeError; end
+ class PoolShuttingDownError < ::Bundler::ConnectionPool::Error; end
+ class TimeoutError < ::Timeout::Error; end
+end
-# Generic connection pool class for e.g. sharing a limited number of network connections
-# among many threads. Note: Connections are lazily created.
+# Generic connection pool class for sharing a limited number of objects or network connections
+# among many threads. Note: pool elements are lazily created.
#
# Example usage with block (faster):
#
# @pool = Bundler::ConnectionPool.new { Redis.new }
-#
# @pool.with do |redis|
# redis.lpop('my-list') if redis.llen('my-list') > 0
# end
@@ -34,29 +38,23 @@ require_relative 'connection_pool/timed_stack'
class Bundler::ConnectionPool
DEFAULTS = {size: 5, timeout: 5}
- class Error < RuntimeError
- end
-
def self.wrap(options, &block)
Wrapper.new(options, &block)
end
def initialize(options = {}, &block)
- raise ArgumentError, 'Connection pool requires a block' unless block
+ raise ArgumentError, "Connection pool requires a block" unless block
options = DEFAULTS.merge(options)
- @size = options.fetch(:size)
+ @size = Integer(options.fetch(:size))
@timeout = options.fetch(:timeout)
@available = TimedStack.new(@size, &block)
- @key = :"current-#{@available.object_id}"
- @key_count = :"current-#{@available.object_id}-count"
+ @key = :"pool-#{@available.object_id}"
+ @key_count = :"pool-#{@available.object_id}-count"
end
-if Thread.respond_to?(:handle_interrupt)
-
- # MRI
def with(options = {})
Thread.handle_interrupt(Exception => :never) do
conn = checkout(options)
@@ -69,28 +67,15 @@ if Thread.respond_to?(:handle_interrupt)
end
end
end
-
-else
-
- # jruby 1.7.x
- def with(options = {})
- conn = checkout(options)
- begin
- yield conn
- ensure
- checkin
- end
- end
-
-end
+ alias then with
def checkout(options = {})
if ::Thread.current[@key]
- ::Thread.current[@key_count]+= 1
+ ::Thread.current[@key_count] += 1
::Thread.current[@key]
else
- ::Thread.current[@key_count]= 1
- ::Thread.current[@key]= @available.pop(options[:timeout] || @timeout)
+ ::Thread.current[@key_count] = 1
+ ::Thread.current[@key] = @available.pop(options[:timeout] || @timeout)
end
end
@@ -98,64 +83,44 @@ end
if ::Thread.current[@key]
if ::Thread.current[@key_count] == 1
@available.push(::Thread.current[@key])
- ::Thread.current[@key]= nil
+ ::Thread.current[@key] = nil
+ ::Thread.current[@key_count] = nil
else
- ::Thread.current[@key_count]-= 1
+ ::Thread.current[@key_count] -= 1
end
else
- raise Bundler::ConnectionPool::Error, 'no connections are checked out'
+ raise Bundler::ConnectionPool::Error, "no connections are checked out"
end
nil
end
+ ##
+ # Shuts down the Bundler::ConnectionPool by passing each connection to +block+ and
+ # then removing it from the pool. Attempting to checkout a connection after
+ # shutdown will raise +Bundler::ConnectionPool::PoolShuttingDownError+.
+
def shutdown(&block)
@available.shutdown(&block)
end
- # Size of this connection pool
- def size
- @size
+ ##
+ # Reloads the Bundler::ConnectionPool by passing each connection to +block+ and then
+ # removing it the pool. Subsequent checkouts will create new connections as
+ # needed.
+
+ def reload(&block)
+ @available.shutdown(reload: true, &block)
end
+ # Size of this connection pool
+ attr_reader :size
+
# Number of pool entries available for checkout at this instant.
def available
@available.length
end
-
- private
-
- class Wrapper < ::BasicObject
- METHODS = [:with, :pool_shutdown]
-
- def initialize(options = {}, &block)
- @pool = options.fetch(:pool) { ::Bundler::ConnectionPool.new(options, &block) }
- end
-
- def with(&block)
- @pool.with(&block)
- end
-
- def pool_shutdown(&block)
- @pool.shutdown(&block)
- end
-
- def pool_size
- @pool.size
- end
-
- def pool_available
- @pool.available
- end
-
- def respond_to?(id, *args)
- METHODS.include?(id) || with { |c| c.respond_to?(id, *args) }
- end
-
- def method_missing(name, *args, &block)
- with do |connection|
- connection.send(name, *args, &block)
- end
- end
- end
end
+
+require_relative "connection_pool/timed_stack"
+require_relative "connection_pool/wrapper"
diff --git a/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb b/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb
deleted file mode 100644
index 5a9c4a2..0000000
--- a/lib/bundler/vendor/connection_pool/lib/connection_pool/monotonic_time.rb
+++ /dev/null
@@ -1,66 +0,0 @@
-# Global monotonic clock from Concurrent Ruby 1.0.
-# Copyright (c) Jerry D'Antonio -- released under the MIT license.
-# Slightly modified; used with permission.
-# https://github.com/ruby-concurrency/concurrent-ruby
-
-require 'thread'
-
-class Bundler::ConnectionPool
-
- class_definition = Class.new do
-
- if defined?(Process::CLOCK_MONOTONIC)
-
- # @!visibility private
- def get_time
- Process.clock_gettime(Process::CLOCK_MONOTONIC)
- end
-
- elsif defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
-
- # @!visibility private
- def get_time
- java.lang.System.nanoTime() / 1_000_000_000.0
- end
-
- else
-
- # @!visibility private
- def initialize
- @mutex = Mutex.new
- @last_time = Time.now.to_f
- end
-
- # @!visibility private
- def get_time
- @mutex.synchronize do
- now = Time.now.to_f
- if @last_time < now
- @last_time = now
- else # clock has moved back in time
- @last_time += 0.000_001
- end
- end
- end
- end
- end
-
- ##
- # Clock that cannot be set and represents monotonic time since
- # some unspecified starting point.
- #
- # @!visibility private
- GLOBAL_MONOTONIC_CLOCK = class_definition.new
- private_constant :GLOBAL_MONOTONIC_CLOCK
-
- class << self
- ##
- # Returns the current time a tracked by the application monotonic clock.
- #
- # @return [Float] The current monotonic time when `since` not given else
- # the elapsed monotonic time between `since` and the current time
- def monotonic_time
- GLOBAL_MONOTONIC_CLOCK.get_time
- end
- end
-end
diff --git a/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb b/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb
index f3fe1e0..a7b1cf0 100644
--- a/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb
+++ b/lib/bundler/vendor/connection_pool/lib/connection_pool/timed_stack.rb
@@ -1,13 +1,3 @@
-require 'thread'
-require 'timeout'
-require_relative 'monotonic_time'
-
-##
-# Raised when you attempt to retrieve a connection from a pool that has been
-# shut down.
-
-class Bundler::ConnectionPool::PoolShuttingDownError < RuntimeError; end
-
##
# The TimedStack manages a pool of homogeneous connections (or any resource
# you wish to manage). Connections are created lazily up to a given maximum
@@ -25,7 +15,7 @@ class Bundler::ConnectionPool::PoolShuttingDownError < RuntimeError; end
#
# conn = ts.pop
# ts.pop timeout: 5
-# #=> raises Timeout::Error after 5 seconds
+# #=> raises Bundler::ConnectionPool::TimeoutError after 5 seconds
class Bundler::ConnectionPool::TimedStack
attr_reader :max
@@ -39,8 +29,8 @@ class Bundler::ConnectionPool::TimedStack
@created = 0
@que = []
@max = size
- @mutex = Mutex.new
- @resource = ConditionVariable.new
+ @mutex = Thread::Mutex.new
+ @resource = Thread::ConditionVariable.new
@shutdown_block = nil
end
@@ -59,12 +49,12 @@ class Bundler::ConnectionPool::TimedStack
@resource.broadcast
end
end
- alias_method :<<, :push
+ alias << push
##
# Retrieves a connection from the stack. If a connection is available it is
# immediately returned. If no connection is available within the given
- # timeout a Timeout::Error is raised.
+ # timeout a Bundler::ConnectionPool::TimeoutError is raised.
#
# +:timeout+ is the only checked entry in +options+ and is preferred over
# the +timeout+ argument (which will be removed in a future release). Other
@@ -74,7 +64,7 @@ class Bundler::ConnectionPool::TimedStack
options, timeout = timeout, 0.5 if Hash === timeout
timeout = options.fetch :timeout, timeout
- deadline = Bundler::ConnectionPool.monotonic_time + timeout
+ deadline = current_time + timeout
@mutex.synchronize do
loop do
raise Bundler::ConnectionPool::PoolShuttingDownError if @shutdown_block
@@ -83,18 +73,20 @@ class Bundler::ConnectionPool::TimedStack
connection = try_create(options)
return connection if connection
- to_wait = deadline - Bundler::ConnectionPool.monotonic_time
- raise Timeout::Error, "Waited #{timeout} sec" if to_wait <= 0
+ to_wait = deadline - current_time
+ raise Bundler::ConnectionPool::TimeoutError, "Waited #{timeout} sec" if to_wait <= 0
@resource.wait(@mutex, to_wait)
end
end
end
##
- # Shuts down the TimedStack which prevents connections from being checked
- # out. The +block+ is called once for each connection on the stack.
+ # Shuts down the TimedStack by passing each connection to +block+ and then
+ # removing it from the pool. Attempting to checkout a connection after
+ # shutdown will raise +Bundler::ConnectionPool::PoolShuttingDownError+ unless
+ # +:reload+ is +true+.
- def shutdown(&block)
+ def shutdown(reload: false, &block)
raise ArgumentError, "shutdown must receive a block" unless block_given?
@mutex.synchronize do
@@ -102,6 +94,7 @@ class Bundler::ConnectionPool::TimedStack
@resource.broadcast
shutdown_connections
+ @shutdown_block = nil if reload
end
end
@@ -121,6 +114,10 @@ class Bundler::ConnectionPool::TimedStack
private
+ def current_time
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
+ end
+
##
# This is an extension point for TimedStack and is called with a mutex.
#
@@ -149,6 +146,7 @@ class Bundler::ConnectionPool::TimedStack
conn = fetch_connection(options)
@shutdown_block.call(conn)
end
+ @created = 0
end
##
diff --git a/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb b/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb
index b149c0e..56ebf69 100644
--- a/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb
+++ b/lib/bundler/vendor/connection_pool/lib/connection_pool/version.rb
@@ -1,3 +1,3 @@
class Bundler::ConnectionPool
- VERSION = "2.2.2"
+ VERSION = "2.3.0"
end
diff --git a/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb b/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb
new file mode 100644
index 0000000..880170c
--- /dev/null
+++ b/lib/bundler/vendor/connection_pool/lib/connection_pool/wrapper.rb
@@ -0,0 +1,57 @@
+class Bundler::ConnectionPool
+ class Wrapper < ::BasicObject
+ METHODS = [:with, :pool_shutdown, :wrapped_pool]
+
+ def initialize(options = {}, &block)
+ @pool = options.fetch(:pool) { ::Bundler::ConnectionPool.new(options, &block) }
+ end
+
+ def wrapped_pool
+ @pool
+ end
+
+ def with(&block)
+ @pool.with(&block)
+ end
+
+ def pool_shutdown(&block)
+ @pool.shutdown(&block)
+ end
+
+ def pool_size
+ @pool.size
+ end
+
+ def pool_available
+ @pool.available
+ end
+
+ def respond_to?(id, *args)
+ METHODS.include?(id) || with { |c| c.respond_to?(id, *args) }
+ end
+
+ # rubocop:disable Style/MethodMissingSuper
+ # rubocop:disable Style/MissingRespondToMissing
+ if ::RUBY_VERSION >= "3.0.0"
+ def method_missing(name, *args, **kwargs, &block)
+ with do |connection|
+ connection.send(name, *args, **kwargs, &block)
+ end
+ end
+ elsif ::RUBY_VERSION >= "2.7.0"
+ ruby2_keywords def method_missing(name, *args, &block)
+ with do |connection|
+ connection.send(name, *args, &block)
+ end
+ end
+ else
+ def method_missing(name, *args, &block)
+ with do |connection|
+ connection.send(name, *args, &block)
+ end
+ end
+ end
+ # rubocop:enable Style/MethodMissingSuper
+ # rubocop:enable Style/MissingRespondToMissing
+ end
+end
diff --git a/lib/bundler/vendor/uri/lib/uri.rb b/lib/bundler/vendor/uri/lib/uri.rb
index 00c01bd..0e574dd 100644
--- a/lib/bundler/vendor/uri/lib/uri.rb
+++ b/lib/bundler/vendor/uri/lib/uri.rb
@@ -86,7 +86,6 @@
# License::
# Copyright (c) 2001 akira yamada <akira@ruby-lang.org>
# You can redistribute it and/or modify it under the same term as Ruby.
-# Revision:: $Id$
#
module Bundler::URI
diff --git a/lib/bundler/vendor/uri/lib/uri/common.rb b/lib/bundler/vendor/uri/lib/uri/common.rb
index cc1ab86..6539e18 100644
--- a/lib/bundler/vendor/uri/lib/uri/common.rb
+++ b/lib/bundler/vendor/uri/lib/uri/common.rb
@@ -3,7 +3,6 @@
# = uri/common.rb
#
# Author:: Akira Yamada <akira@ruby-lang.org>
-# Revision:: $Id$
# License::
# You can redistribute it and/or modify it under the same term as Ruby.
#
@@ -61,82 +60,6 @@ module Bundler::URI
module_function :make_components_hash
end
- # Module for escaping unsafe characters with codes.
- module Escape
- #
- # == Synopsis
- #
- # Bundler::URI.escape(str [, unsafe])
- #
- # == Args
- #
- # +str+::
- # String to replaces in.
- # +unsafe+::
- # Regexp that matches all symbols that must be replaced with codes.
- # By default uses <tt>UNSAFE</tt>.
- # When this argument is a String, it represents a character set.
- #
- # == Description
- #
- # Escapes the string, replacing all unsafe characters with codes.
- #
- # This method is obsolete and should not be used. Instead, use
- # CGI.escape, Bundler::URI.encode_www_form or Bundler::URI.encode_www_form_component
- # depending on your specific use case.
- #
- # == Usage
- #
- # require 'bundler/vendor/uri/lib/uri'
- #
- # enc_uri = Bundler::URI.escape("http://example.com/?a=\11\15")
- # # => "http://example.com/?a=%09%0D"
- #
- # Bundler::URI.unescape(enc_uri)
- # # => "http://example.com/?a=\t\r"
- #
- # Bundler::URI.escape("@?@!", "!?")
- # # => "@%3F@%21"
- #
- def escape(*arg)
- warn "Bundler::URI.escape is obsolete", uplevel: 1
- DEFAULT_PARSER.escape(*arg)
- end
- alias encode escape
- #
- # == Synopsis
- #
- # Bundler::URI.unescape(str)
- #
- # == Args
- #
- # +str+::
- # String to unescape.
- #
- # == Description
- #
- # This method is obsolete and should not be used. Instead, use
- # CGI.unescape, Bundler::URI.decode_www_form or Bundler::URI.decode_www_form_component
- # depending on your specific use case.
- #
- # == Usage
- #
- # require 'bundler/vendor/uri/lib/uri'
- #
- # enc_uri = Bundler::URI.escape("http://example.com/?a=\11\15")
- # # => "http://example.com/?a=%09%0D"
- #
- # Bundler::URI.unescape(enc_uri)
- # # => "http://example.com/?a=\t\r"
- #
- def unescape(*arg)
- warn "Bundler::URI.unescape is obsolete", uplevel: 1
- DEFAULT_PARSER.unescape(*arg)
- end
- alias decode unescape
- end # module Escape
-
- extend Escape
include REGEXP
@@schemes = {}
@@ -146,6 +69,20 @@ module Bundler::URI
end
#
+ # Construct a Bundler::URI instance, using the scheme to detect the appropriate class
+ # from +Bundler::URI.scheme_list+.
+ #
+ def self.for(scheme, *arguments, default: Generic)
+ if scheme
+ uri_class = @@schemes[scheme.upcase] || default
+ else
+ uri_class = default
+ end
+
+ return uri_class.new(scheme, *arguments)
+ end
+
+ #
# Base class for all Bundler::URI exceptions.
#
class Error < StandardError; end
@@ -315,7 +252,7 @@ module Bundler::URI
#
# Returns a Regexp object which matches to Bundler::URI-like strings.
# The Regexp object returned by this method includes arbitrary
- # number of capture group (parentheses). Never rely on it's number.
+ # number of capture group (parentheses). Never rely on its number.
#
# == Usage
#
@@ -362,7 +299,7 @@ module Bundler::URI
# If +enc+ is given, convert +str+ to the encoding before percent encoding.
#
# This is an implementation of
- # http://www.w3.org/TR/2013/CR-html5-20130806/forms.html#url-encoded-form-data.
+ # https://www.w3.org/TR/2013/CR-html5-20130806/forms.html#url-encoded-form-data.
#
# See Bundler::URI.decode_www_form_component, Bundler::URI.encode_www_form.
def self.encode_www_form_component(str, enc=nil)
@@ -403,7 +340,7 @@ module Bundler::URI
# This method doesn't handle files. When you send a file, use
# multipart/form-data.
#
- # This refers http://url.spec.whatwg.org/#concept-urlencoded-serializer
+ # This refers https://url.spec.whatwg.org/#concept-urlencoded-serializer
#
# Bundler::URI.encode_www_form([["q", "ruby"], ["lang", "en"]])
# #=> "q=ruby&lang=en"
diff --git a/lib/bundler/vendor/uri/lib/uri/ftp.rb b/lib/bundler/vendor/uri/lib/uri/ftp.rb
index ad39f57..2252e40 100644
--- a/lib/bundler/vendor/uri/lib/uri/ftp.rb
+++ b/lib/bundler/vendor/uri/lib/uri/ftp.rb
@@ -3,7 +3,6 @@
#
# Author:: Akira Yamada <akira@ruby-lang.org>
# License:: You can redistribute it and/or modify it under the same term as Ruby.
-# Revision:: $Id$
#
# See Bundler::URI for general documentation
#
diff --git a/lib/bundler/vendor/uri/lib/uri/generic.rb b/lib/bundler/vendor/uri/lib/uri/generic.rb
index 56b09e1..f29ba6c 100644
--- a/lib/bundler/vendor/uri/lib/uri/generic.rb
+++ b/lib/bundler/vendor/uri/lib/uri/generic.rb
@@ -4,7 +4,6 @@
#
# Author:: Akira Yamada <akira@ruby-lang.org>
# License:: You can redistribute it and/or modify it under the same term as Ruby.
-# Revision:: $Id$
#
# See Bundler::URI for general documentation
#
@@ -1098,7 +1097,7 @@ module Bundler::URI
# # => "http://my.example.com/main.rbx?page=1"
#
def merge(oth)
- rel = parser.send(:convert_to_uri, oth)
+ rel = parser.__send__(:convert_to_uri, oth)
if rel.absolute?
#raise BadURIError, "both Bundler::URI are absolute" if absolute?
@@ -1183,7 +1182,7 @@ module Bundler::URI
# :stopdoc:
def route_from0(oth)
- oth = parser.send(:convert_to_uri, oth)
+ oth = parser.__send__(:convert_to_uri, oth)
if self.relative?
raise BadURIError,
"relative Bundler::URI: #{self}"
@@ -1291,7 +1290,7 @@ module Bundler::URI
# #=> #<Bundler::URI::Generic /main.rbx?page=1>
#
def route_to(oth)
- parser.send(:convert_to_uri, oth).route_from(self)
+ parser.__send__(:convert_to_uri, oth).route_from(self)
end
#
@@ -1405,7 +1404,7 @@ module Bundler::URI
# Returns an Array of the components defined from the COMPONENT Array.
def component_ary
component.collect do |x|
- self.send(x)
+ self.__send__(x)
end
end
protected :component_ary
@@ -1430,7 +1429,7 @@ module Bundler::URI
def select(*components)
components.collect do |c|
if component.include?(c)
- self.send(c)
+ self.__send__(c)
else
raise ArgumentError,
"expected of components of #{self.class} (#{self.class.component.join(', ')})"
diff --git a/lib/bundler/vendor/uri/lib/uri/http.rb b/lib/bundler/vendor/uri/lib/uri/http.rb
index b6ca1c5..50d7e42 100644
--- a/lib/bundler/vendor/uri/lib/uri/http.rb
+++ b/lib/bundler/vendor/uri/lib/uri/http.rb
@@ -3,7 +3,6 @@
#
# Author:: Akira Yamada <akira@ruby-lang.org>
# License:: You can redistribute it and/or modify it under the same term as Ruby.
-# Revision:: $Id$
#
# See Bundler::URI for general documentation
#
diff --git a/lib/bundler/vendor/uri/lib/uri/https.rb b/lib/bundler/vendor/uri/lib/uri/https.rb
index 78dc6bf..4fd4e9a 100644
--- a/lib/bundler/vendor/uri/lib/uri/https.rb
+++ b/lib/bundler/vendor/uri/lib/uri/https.rb
@@ -3,7 +3,6 @@
#
# Author:: Akira Yamada <akira@ruby-lang.org>
# License:: You can redistribute it and/or modify it under the same term as Ruby.
-# Revision:: $Id$
#
# See Bundler::URI for general documentation
#
diff --git a/lib/bundler/vendor/uri/lib/uri/ldap.rb b/lib/bundler/vendor/uri/lib/uri/ldap.rb
index b707bed..6e9e191 100644
--- a/lib/bundler/vendor/uri/lib/uri/ldap.rb
+++ b/lib/bundler/vendor/uri/lib/uri/ldap.rb
@@ -7,7 +7,6 @@
# License::
# Bundler::URI::LDAP is copyrighted free software by Takaaki Tateishi and Akira Yamada.
# You can redistribute it and/or modify it under the same term as Ruby.
-# Revision:: $Id$
#
# See Bundler::URI for general documentation
#
@@ -119,6 +118,7 @@ module Bundler::URI
# Private method to cleanup +dn+ from using the +path+ component attribute.
def parse_dn
+ raise InvalidURIError, 'bad LDAP URL' unless @path
@dn = @path[1..-1]
end
private :parse_dn
diff --git a/lib/bundler/vendor/uri/lib/uri/mailto.rb b/lib/bundler/vendor/uri/lib/uri/mailto.rb
index 5b2a476..ff7ab7e 100644
--- a/lib/bundler/vendor/uri/lib/uri/mailto.rb
+++ b/lib/bundler/vendor/uri/lib/uri/mailto.rb
@@ -3,7 +3,6 @@
#
# Author:: Akira Yamada <akira@ruby-lang.org>
# License:: You can redistribute it and/or modify it under the same term as Ruby.
-# Revision:: $Id$
#
# See Bundler::URI for general documentation
#
diff --git a/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb b/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb
index a0d62ed..e48e164 100644
--- a/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb
+++ b/lib/bundler/vendor/uri/lib/uri/rfc2396_parser.rb
@@ -3,7 +3,6 @@
# = uri/common.rb
#
# Author:: Akira Yamada <akira@ruby-lang.org>
-# Revision:: $Id$
# License::
# You can redistribute it and/or modify it under the same term as Ruby.
#
@@ -208,21 +207,9 @@ module Bundler::URI
# #=> #<Bundler::URI::LDAP ldap://ldap.example.com/dc=example?user=john>
#
def parse(uri)
- scheme, userinfo, host, port,
- registry, path, opaque, query, fragment = self.split(uri)
-
- if scheme && Bundler::URI.scheme_list.include?(scheme.upcase)
- Bundler::URI.scheme_list[scheme.upcase].new(scheme, userinfo, host, port,
- registry, path, opaque, query,
- fragment, self)
- else
- Generic.new(scheme, userinfo, host, port,
- registry, path, opaque, query,
- fragment, self)
- end
+ Bundler::URI.for(*self.split(uri), self)
end
-
#
# == Args
#
diff --git a/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb b/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb
index 07ef439..2029cfd 100644
--- a/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb
+++ b/lib/bundler/vendor/uri/lib/uri/rfc3986_parser.rb
@@ -69,18 +69,7 @@ module Bundler::URI
end
def parse(uri) # :nodoc:
- scheme, userinfo, host, port,
- registry, path, opaque, query, fragment = self.split(uri)
- scheme_list = Bundler::URI.scheme_list
- if scheme && scheme_list.include?(uc = scheme.upcase)
- scheme_list[uc].new(scheme, userinfo, host, port,
- registry, path, opaque, query,
- fragment, self)
- else
- Generic.new(scheme, userinfo, host, port,
- registry, path, opaque, query,
- fragment, self)
- end
+ Bundler::URI.for(*self.split(uri), self)
end
diff --git a/lib/bundler/vendor/uri/lib/uri/version.rb b/lib/bundler/vendor/uri/lib/uri/version.rb
index 56177ef..f2bb0eb 100644
--- a/lib/bundler/vendor/uri/lib/uri/version.rb
+++ b/lib/bundler/vendor/uri/lib/uri/version.rb
@@ -1,6 +1,6 @@
module Bundler::URI
# :stopdoc:
- VERSION_CODE = '001000'.freeze
+ VERSION_CODE = '001001'.freeze
VERSION = VERSION_CODE.scan(/../).collect{|n| n.to_i}.join('.').freeze
# :startdoc:
end
diff --git a/lib/bundler/vendor/uri/lib/uri/ws.rb b/lib/bundler/vendor/uri/lib/uri/ws.rb
new file mode 100644
index 0000000..58e08bf
--- /dev/null
+++ b/lib/bundler/vendor/uri/lib/uri/ws.rb
@@ -0,0 +1,84 @@
+# frozen_string_literal: false
+# = uri/ws.rb
+#
+# Author:: Matt Muller <mamuller@amazon.com>
+# License:: You can redistribute it and/or modify it under the same term as Ruby.
+#
+# See Bundler::URI for general documentation
+#
+
+require_relative 'generic'
+
+module Bundler::URI
+
+ #
+ # The syntax of WS URIs is defined in RFC6455 section 3.
+ #
+ # Note that the Ruby Bundler::URI library allows WS URLs containing usernames and
+ # passwords. This is not legal as per the RFC, but used to be
+ # supported in Internet Explorer 5 and 6, before the MS04-004 security
+ # update. See <URL:http://support.microsoft.com/kb/834489>.
+ #
+ class WS < Generic
+ # A Default port of 80 for Bundler::URI::WS.
+ DEFAULT_PORT = 80
+
+ # An Array of the available components for Bundler::URI::WS.
+ COMPONENT = %i[
+ scheme
+ userinfo host port
+ path
+ query
+ ].freeze
+
+ #
+ # == Description
+ #
+ # Creates a new Bundler::URI::WS object from components, with syntax checking.
+ #
+ # The components accepted are userinfo, host, port, path, and query.
+ #
+ # The components should be provided either as an Array, or as a Hash
+ # with keys formed by preceding the component names with a colon.
+ #
+ # If an Array is used, the components must be passed in the
+ # order <code>[userinfo, host, port, path, query]</code>.
+ #
+ # Example:
+ #
+ # uri = Bundler::URI::WS.build(host: 'www.example.com', path: '/foo/bar')
+ #
+ # uri = Bundler::URI::WS.build([nil, "www.example.com", nil, "/path", "query"])
+ #
+ # Currently, if passed userinfo components this method generates
+ # invalid WS URIs as per RFC 1738.
+ #
+ def self.build(args)
+ tmp = Util.make_components_hash(self, args)
+ super(tmp)
+ end
+
+ #
+ # == Description
+ #
+ # Returns the full path for a WS Bundler::URI, as required by Net::HTTP::Get.
+ #
+ # If the Bundler::URI contains a query, the full path is Bundler::URI#path + '?' + Bundler::URI#query.
+ # Otherwise, the path is simply Bundler::URI#path.
+ #
+ # Example:
+ #
+ # uri = Bundler::URI::WS.build(path: '/foo/bar', query: 'test=true')
+ # uri.request_uri # => "/foo/bar?test=true"
+ #
+ def request_uri
+ return unless @path
+
+ url = @query ? "#@path?#@query" : @path.dup
+ url.start_with?(?/.freeze) ? url : ?/ + url
+ end
+ end
+
+ @@schemes['WS'] = WS
+
+end
diff --git a/lib/bundler/vendor/uri/lib/uri/wss.rb b/lib/bundler/vendor/uri/lib/uri/wss.rb
new file mode 100644
index 0000000..3827053
--- /dev/null
+++ b/lib/bundler/vendor/uri/lib/uri/wss.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: false
+# = uri/wss.rb
+#
+# Author:: Matt Muller <mamuller@amazon.com>
+# License:: You can redistribute it and/or modify it under the same term as Ruby.
+#
+# See Bundler::URI for general documentation
+#
+
+require_relative 'ws'
+
+module Bundler::URI
+
+ # The default port for WSS URIs is 443, and the scheme is 'wss:' rather
+ # than 'ws:'. Other than that, WSS URIs are identical to WS URIs;
+ # see Bundler::URI::WS.
+ class WSS < WS
+ # A Default port of 443 for Bundler::URI::WSS
+ DEFAULT_PORT = 443
+ end
+ @@schemes['WSS'] = WSS
+end
diff --git a/lib/bundler/worker.rb b/lib/bundler/worker.rb
index 10139ed..5e4ee21 100644
--- a/lib/bundler/worker.rb
+++ b/lib/bundler/worker.rb
@@ -21,12 +21,12 @@ module Bundler
# @param func [Proc] job to run in inside the worker pool
def initialize(size, name, func)
@name = name
- @request_queue = Queue.new
- @response_queue = Queue.new
+ @request_queue = Thread::Queue.new
+ @response_queue = Thread::Queue.new
@func = func
@size = size
@threads = nil
- SharedHelpers.trap("INT") { abort_threads }
+ @previous_interrupt_handler = nil
end
# Enqueue a request to be executed in the worker pool
@@ -68,13 +68,16 @@ module Bundler
# so as worker threads after retrieving it, shut themselves down
def stop_threads
return unless @threads
+
@threads.each { @request_queue.enq POISON }
@threads.each(&:join)
+
+ remove_interrupt_handler
+
@threads = nil
end
def abort_threads
- return unless @threads
Bundler.ui.debug("\n#{caller.join("\n")}")
@threads.each(&:exit)
exit 1
@@ -94,11 +97,23 @@ module Bundler
end
end.compact
+ add_interrupt_handler unless @threads.empty?
+
return if creation_errors.empty?
message = "Failed to create threads for the #{name} worker: #{creation_errors.map(&:to_s).uniq.join(", ")}"
raise ThreadCreationError, message if @threads.empty?
Bundler.ui.info message
end
+
+ def add_interrupt_handler
+ @previous_interrupt_handler = trap("INT") { abort_threads }
+ end
+
+ def remove_interrupt_handler
+ return unless @previous_interrupt_handler
+
+ trap "INT", @previous_interrupt_handler
+ end
end
end
diff --git a/lib/cgi/util.rb b/lib/cgi/util.rb
index 69a252b..55e61bf 100644
--- a/lib/cgi/util.rb
+++ b/lib/cgi/util.rb
@@ -179,21 +179,12 @@ module CGI::Util
# Synonym for CGI.unescapeElement(str)
alias unescape_element unescapeElement
- # Abbreviated day-of-week names specified by RFC 822
- RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ]
-
- # Abbreviated month names specified by RFC 822
- RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ]
-
# Format a +Time+ object as a String using the format specified by RFC 1123.
#
# CGI.rfc1123_date(Time.now)
# # Sat, 01 Jan 2000 00:00:00 GMT
def rfc1123_date(time)
- t = time.clone.gmtime
- return format("%s, %.2d %s %.4d %.2d:%.2d:%.2d GMT",
- RFC822_DAYS[t.wday], t.day, RFC822_MONTHS[t.month-1], t.year,
- t.hour, t.min, t.sec)
+ time.getgm.strftime("%a, %d %b %Y %T GMT")
end
# Prettify (indent) an HTML string.
diff --git a/lib/did_you_mean/core_ext/name_error.rb b/lib/did_you_mean/core_ext/name_error.rb
index 77dcd52..7e99282 100644
--- a/lib/did_you_mean/core_ext/name_error.rb
+++ b/lib/did_you_mean/core_ext/name_error.rb
@@ -1,14 +1,21 @@
module DidYouMean
module Correctable
+ SKIP_TO_S_FOR_SUPER_LOOKUP = true
+ private_constant :SKIP_TO_S_FOR_SUPER_LOOKUP
+
def original_message
- method(:to_s).super_method.call
+ meth = method(:to_s)
+ while meth.owner.const_defined?(:SKIP_TO_S_FOR_SUPER_LOOKUP)
+ meth = meth.super_method
+ end
+ meth.call
end
def to_s
msg = super.dup
suggestion = DidYouMean.formatter.message_for(corrections)
- msg << suggestion if !msg.end_with?(suggestion)
+ msg << suggestion if !msg.include?(suggestion)
msg
rescue
super
diff --git a/lib/did_you_mean/spell_checkers/require_path_checker.rb b/lib/did_you_mean/spell_checkers/require_path_checker.rb
index aaf877b..e4cdb9f 100644
--- a/lib/did_you_mean/spell_checkers/require_path_checker.rb
+++ b/lib/did_you_mean/spell_checkers/require_path_checker.rb
@@ -2,6 +2,7 @@
require_relative "../spell_checker"
require_relative "../tree_spell_checker"
+require "rbconfig"
module DidYouMean
class RequirePathChecker
diff --git a/lib/did_you_mean/version.rb b/lib/did_you_mean/version.rb
index 9a53a31..8df73e1 100644
--- a/lib/did_you_mean/version.rb
+++ b/lib/did_you_mean/version.rb
@@ -1,3 +1,3 @@
module DidYouMean
- VERSION = "1.5.0"
+ VERSION = "1.6.0-alpha"
end
diff --git a/lib/error_highlight.rb b/lib/error_highlight.rb
new file mode 100644
index 0000000..31db95d
--- /dev/null
+++ b/lib/error_highlight.rb
@@ -0,0 +1,2 @@
+require_relative "error_highlight/base"
+require_relative "error_highlight/core_ext"
diff --git a/lib/error_highlight/base.rb b/lib/error_highlight/base.rb
new file mode 100644
index 0000000..8392979
--- /dev/null
+++ b/lib/error_highlight/base.rb
@@ -0,0 +1,461 @@
+require_relative "version"
+
+module ErrorHighlight
+ # Identify the code fragment that seems associated with a given error
+ #
+ # Arguments:
+ # node: RubyVM::AbstractSyntaxTree::Node (script_lines should be enabled)
+ # point_type: :name | :args
+ # name: The name associated with the NameError/NoMethodError
+ #
+ # Returns:
+ # {
+ # first_lineno: Integer,
+ # first_column: Integer,
+ # last_lineno: Integer,
+ # last_column: Integer,
+ # snippet: String,
+ # } | nil
+ def self.spot(...)
+ Spotter.new(...).spot
+ end
+
+ class Spotter
+ class NonAscii < Exception; end
+ private_constant :NonAscii
+
+ def initialize(node, point_type: :name, name: nil)
+ @node = node
+ @point_type = point_type
+ @name = name
+
+ # Not-implemented-yet options
+ @arg = nil # Specify the index or keyword at which argument caused the TypeError/ArgumentError
+ @multiline = false # Allow multiline spot
+
+ @fetch = -> (lineno, last_lineno = lineno) do
+ snippet = @node.script_lines[lineno - 1 .. last_lineno - 1].join("")
+ snippet += "\n" unless snippet.end_with?("\n")
+
+ # It require some work to support Unicode (or multibyte) characters.
+ # Tentatively, we stop highlighting if the code snippet has non-ascii characters.
+ # See https://github.com/ruby/error_highlight/issues/4
+ raise NonAscii unless snippet.ascii_only?
+
+ snippet
+ end
+ end
+
+ def spot
+ return nil unless @node
+
+ case @node.type
+
+ when :CALL, :QCALL
+ case @point_type
+ when :name
+ spot_call_for_name
+ when :args
+ spot_call_for_args
+ end
+
+ when :ATTRASGN
+ case @point_type
+ when :name
+ spot_attrasgn_for_name
+ when :args
+ spot_attrasgn_for_args
+ end
+
+ when :OPCALL
+ case @point_type
+ when :name
+ spot_opcall_for_name
+ when :args
+ spot_opcall_for_args
+ end
+
+ when :FCALL
+ case @point_type
+ when :name
+ spot_fcall_for_name
+ when :args
+ spot_fcall_for_args
+ end
+
+ when :VCALL
+ spot_vcall
+
+ when :OP_ASGN1
+ case @point_type
+ when :name
+ spot_op_asgn1_for_name
+ when :args
+ spot_op_asgn1_for_args
+ end
+
+ when :OP_ASGN2
+ case @point_type
+ when :name
+ spot_op_asgn2_for_name
+ when :args
+ spot_op_asgn2_for_args
+ end
+
+ when :CONST
+ spot_vcall
+
+ when :COLON2
+ spot_colon2
+
+ when :COLON3
+ spot_vcall
+
+ when :OP_CDECL
+ spot_op_cdecl
+ end
+
+ if @snippet && @beg_column && @end_column && @beg_column < @end_column
+ return {
+ first_lineno: @beg_lineno,
+ first_column: @beg_column,
+ last_lineno: @end_lineno,
+ last_column: @end_column,
+ snippet: @snippet,
+ }
+ else
+ return nil
+ end
+
+ rescue NonAscii
+ nil
+ end
+
+ private
+
+ # Example:
+ # x.foo
+ # ^^^^
+ # x.foo(42)
+ # ^^^^
+ # x&.foo
+ # ^^^^^
+ # x[42]
+ # ^^^^
+ # x += 1
+ # ^
+ def spot_call_for_name
+ nd_recv, mid, nd_args = @node.children
+ lineno = nd_recv.last_lineno
+ lines = @fetch[lineno, @node.last_lineno]
+ if mid == :[] && lines.match(/\G[\s)]*(\[(?:\s*\])?)/, nd_recv.last_column)
+ @beg_column = $~.begin(1)
+ @snippet = lines[/.*\n/]
+ @beg_lineno = @end_lineno = lineno
+ if nd_args
+ if nd_recv.last_lineno == nd_args.last_lineno && @snippet.match(/\s*\]/, nd_args.last_column)
+ @end_column = $~.end(0)
+ end
+ else
+ if lines.match(/\G[\s)]*?\[\s*\]/, nd_recv.last_column)
+ @end_column = $~.end(0)
+ end
+ end
+ elsif lines.match(/\G[\s)]*?(\&?\.)(\s*?)(#{ Regexp.quote(mid) }).*\n/, nd_recv.last_column)
+ lines = $` + $&
+ @beg_column = $~.begin($2.include?("\n") ? 3 : 1)
+ @end_column = $~.end(3)
+ if i = lines[..@beg_column].rindex("\n")
+ @beg_lineno = @end_lineno = lineno + lines[..@beg_column].count("\n")
+ @snippet = lines[i + 1..]
+ @beg_column -= i + 1
+ @end_column -= i + 1
+ else
+ @snippet = lines
+ @beg_lineno = @end_lineno = lineno
+ end
+ elsif mid.to_s =~ /\A\W+\z/ && lines.match(/\G\s*(#{ Regexp.quote(mid) })=.*\n/, nd_recv.last_column)
+ @snippet = $` + $&
+ @beg_column = $~.begin(1)
+ @end_column = $~.end(1)
+ end
+ end
+
+ # Example:
+ # x.foo(42)
+ # ^^
+ # x[42]
+ # ^^
+ # x += 1
+ # ^
+ def spot_call_for_args
+ _nd_recv, _mid, nd_args = @node.children
+ if nd_args && nd_args.first_lineno == nd_args.last_lineno
+ fetch_line(nd_args.first_lineno)
+ @beg_column = nd_args.first_column
+ @end_column = nd_args.last_column
+ end
+ # TODO: support @arg
+ end
+
+ # Example:
+ # x.foo = 1
+ # ^^^^^^
+ # x[42] = 1
+ # ^^^^^^
+ def spot_attrasgn_for_name
+ nd_recv, mid, nd_args = @node.children
+ *nd_args, _nd_last_arg, _nil = nd_args.children
+ fetch_line(nd_recv.last_lineno)
+ if mid == :[]= && @snippet.match(/\G[\s)]*(\[)/, nd_recv.last_column)
+ @beg_column = $~.begin(1)
+ args_last_column = $~.end(0)
+ if nd_args.last && nd_recv.last_lineno == nd_args.last.last_lineno
+ args_last_column = nd_args.last.last_column
+ end
+ if @snippet.match(/[\s)]*\]\s*=/, args_last_column)
+ @end_column = $~.end(0)
+ end
+ elsif @snippet.match(/\G[\s)]*(\.\s*#{ Regexp.quote(mid.to_s.sub(/=\z/, "")) }\s*=)/, nd_recv.last_column)
+ @beg_column = $~.begin(1)
+ @end_column = $~.end(1)
+ end
+ end
+
+ # Example:
+ # x.foo = 1
+ # ^
+ # x[42] = 1
+ # ^^^^^^^
+ # x[] = 1
+ # ^^^^^
+ def spot_attrasgn_for_args
+ nd_recv, mid, nd_args = @node.children
+ fetch_line(nd_recv.last_lineno)
+ if mid == :[]= && @snippet.match(/\G[\s)]*\[/, nd_recv.last_column)
+ @beg_column = $~.end(0)
+ if nd_recv.last_lineno == nd_args.last_lineno
+ @end_column = nd_args.last_column
+ end
+ elsif nd_args && nd_args.first_lineno == nd_args.last_lineno
+ @beg_column = nd_args.first_column
+ @end_column = nd_args.last_column
+ end
+ # TODO: support @arg
+ end
+
+ # Example:
+ # x + 1
+ # ^
+ # +x
+ # ^
+ def spot_opcall_for_name
+ nd_recv, op, nd_arg = @node.children
+ fetch_line(nd_recv.last_lineno)
+ if nd_arg
+ # binary operator
+ if @snippet.match(/\G[\s)]*(#{ Regexp.quote(op) })/, nd_recv.last_column)
+ @beg_column = $~.begin(1)
+ @end_column = $~.end(1)
+ end
+ else
+ # unary operator
+ if @snippet[...nd_recv.first_column].match(/(#{ Regexp.quote(op.to_s.sub(/@\z/, "")) })\s*\(?\s*\z/)
+ @beg_column = $~.begin(1)
+ @end_column = $~.end(1)
+ end
+ end
+ end
+
+ # Example:
+ # x + 1
+ # ^
+ def spot_opcall_for_args
+ _nd_recv, _op, nd_arg = @node.children
+ if nd_arg && nd_arg.first_lineno == nd_arg.last_lineno
+ # binary operator
+ fetch_line(nd_arg.first_lineno)
+ @beg_column = nd_arg.first_column
+ @end_column = nd_arg.last_column
+ end
+ end
+
+ # Example:
+ # foo(42)
+ # ^^^
+ # foo 42
+ # ^^^
+ def spot_fcall_for_name
+ mid, _nd_args = @node.children
+ fetch_line(@node.first_lineno)
+ if @snippet.match(/(#{ Regexp.quote(mid) })/, @node.first_column)
+ @beg_column = $~.begin(1)
+ @end_column = $~.end(1)
+ end
+ end
+
+ # Example:
+ # foo(42)
+ # ^^
+ # foo 42
+ # ^^
+ def spot_fcall_for_args
+ _mid, nd_args = @node.children
+ if nd_args && nd_args.first_lineno == nd_args.last_lineno
+ # binary operator
+ fetch_line(nd_args.first_lineno)
+ @beg_column = nd_args.first_column
+ @end_column = nd_args.last_column
+ end
+ end
+
+ # Example:
+ # foo
+ # ^^^
+ def spot_vcall
+ if @node.first_lineno == @node.last_lineno
+ fetch_line(@node.last_lineno)
+ @beg_column = @node.first_column
+ @end_column = @node.last_column
+ end
+ end
+
+ # Example:
+ # x[1] += 42
+ # ^^^ (for [])
+ # x[1] += 42
+ # ^ (for +)
+ # x[1] += 42
+ # ^^^^^^ (for []=)
+ def spot_op_asgn1_for_name
+ nd_recv, op, nd_args, _nd_rhs = @node.children
+ fetch_line(nd_recv.last_lineno)
+ if @snippet.match(/\G[\s)]*(\[)/, nd_recv.last_column)
+ bracket_beg_column = $~.begin(1)
+ args_last_column = $~.end(0)
+ if nd_args && nd_recv.last_lineno == nd_args.last_lineno
+ args_last_column = nd_args.last_column
+ end
+ if @snippet.match(/\s*\](\s*)(#{ Regexp.quote(op) })=()/, args_last_column)
+ case @name
+ when :[], :[]=
+ @beg_column = bracket_beg_column
+ @end_column = $~.begin(@name == :[] ? 1 : 3)
+ when op
+ @beg_column = $~.begin(2)
+ @end_column = $~.end(2)
+ end
+ end
+ end
+ end
+
+ # Example:
+ # x[1] += 42
+ # ^^^^^^^^
+ def spot_op_asgn1_for_args
+ nd_recv, mid, nd_args, nd_rhs = @node.children
+ fetch_line(nd_recv.last_lineno)
+ if mid == :[]= && @snippet.match(/\G\s*\[/, nd_recv.last_column)
+ @beg_column = $~.end(0)
+ if nd_recv.last_lineno == nd_rhs.last_lineno
+ @end_column = nd_rhs.last_column
+ end
+ elsif nd_args && nd_args.first_lineno == nd_rhs.last_lineno
+ @beg_column = nd_args.first_column
+ @end_column = nd_rhs.last_column
+ end
+ # TODO: support @arg
+ end
+
+ # Example:
+ # x.foo += 42
+ # ^^^ (for foo)
+ # x.foo += 42
+ # ^ (for +)
+ # x.foo += 42
+ # ^^^^^^^ (for foo=)
+ def spot_op_asgn2_for_name
+ nd_recv, _qcall, attr, op, _nd_rhs = @node.children
+ fetch_line(nd_recv.last_lineno)
+ if @snippet.match(/\G[\s)]*(\.)\s*#{ Regexp.quote(attr) }()\s*(#{ Regexp.quote(op) })(=)/, nd_recv.last_column)
+ case @name
+ when attr
+ @beg_column = $~.begin(1)
+ @end_column = $~.begin(2)
+ when op
+ @beg_column = $~.begin(3)
+ @end_column = $~.end(3)
+ when :"#{ attr }="
+ @beg_column = $~.begin(1)
+ @end_column = $~.end(4)
+ end
+ end
+ end
+
+ # Example:
+ # x.foo += 42
+ # ^^
+ def spot_op_asgn2_for_args
+ _nd_recv, _qcall, _attr, _op, nd_rhs = @node.children
+ if nd_rhs.first_lineno == nd_rhs.last_lineno
+ fetch_line(nd_rhs.first_lineno)
+ @beg_column = nd_rhs.first_column
+ @end_column = nd_rhs.last_column
+ end
+ end
+
+ # Example:
+ # Foo::Bar
+ # ^^^^^
+ def spot_colon2
+ nd_parent, const = @node.children
+ if nd_parent.last_lineno == @node.last_lineno
+ fetch_line(nd_parent.last_lineno)
+ @beg_column = nd_parent.last_column
+ @end_column = @node.last_column
+ else
+ @snippet = @fetch[@node.last_lineno]
+ if @snippet[...@node.last_column].match(/#{ Regexp.quote(const) }\z/)
+ @beg_column = $~.begin(0)
+ @end_column = $~.end(0)
+ end
+ end
+ end
+
+ # Example:
+ # Foo::Bar += 1
+ # ^^^^^^^^
+ def spot_op_cdecl
+ nd_lhs, op, _nd_rhs = @node.children
+ *nd_parent_lhs, _const = nd_lhs.children
+ if @name == op
+ @snippet = @fetch[nd_lhs.last_lineno]
+ if @snippet.match(/\G\s*(#{ Regexp.quote(op) })=/, nd_lhs.last_column)
+ @beg_column = $~.begin(1)
+ @end_column = $~.end(1)
+ end
+ else
+ # constant access error
+ @end_column = nd_lhs.last_column
+ if nd_parent_lhs.empty? # example: ::C += 1
+ if nd_lhs.first_lineno == nd_lhs.last_lineno
+ @snippet = @fetch[nd_lhs.last_lineno]
+ @beg_column = nd_lhs.first_column
+ end
+ else # example: Foo::Bar::C += 1
+ if nd_parent_lhs.last.last_lineno == nd_lhs.last_lineno
+ @snippet = @fetch[nd_lhs.last_lineno]
+ @beg_column = nd_parent_lhs.last.last_column
+ end
+ end
+ end
+ end
+
+ def fetch_line(lineno)
+ @beg_lineno = @end_lineno = lineno
+ @snippet = @fetch[lineno]
+ end
+ end
+
+ private_constant :Spotter
+end
diff --git a/lib/error_highlight/core_ext.rb b/lib/error_highlight/core_ext.rb
new file mode 100644
index 0000000..1ae180a
--- /dev/null
+++ b/lib/error_highlight/core_ext.rb
@@ -0,0 +1,50 @@
+require_relative "formatter"
+
+module ErrorHighlight
+ module CoreExt
+ # This is a marker to let `DidYouMean::Correctable#original_message` skip
+ # the following method definition of `to_s`.
+ # See https://github.com/ruby/did_you_mean/pull/152
+ SKIP_TO_S_FOR_SUPER_LOOKUP = true
+ private_constant :SKIP_TO_S_FOR_SUPER_LOOKUP
+
+ def to_s
+ msg = super.dup
+
+ locs = backtrace_locations
+ return msg unless locs
+
+ loc = locs.first
+ begin
+ node = RubyVM::AbstractSyntaxTree.of(loc, keep_script_lines: true)
+ opts = {}
+
+ case self
+ when NoMethodError, NameError
+ opts[:point_type] = :name
+ opts[:name] = name
+ when TypeError, ArgumentError
+ opts[:point_type] = :args
+ end
+
+ spot = ErrorHighlight.spot(node, **opts)
+
+ rescue Errno::ENOENT, SyntaxError
+ end
+
+ if spot
+ points = ErrorHighlight.formatter.message_for(spot)
+ msg << points if !msg.include?(points)
+ end
+
+ msg
+ end
+ end
+
+ NameError.prepend(CoreExt)
+
+ # The extension for TypeError/ArgumentError is temporarily disabled due to many test failures
+
+ #TypeError.prepend(CoreExt)
+ #ArgumentError.prepend(CoreExt)
+end
diff --git a/lib/error_highlight/error_highlight.gemspec b/lib/error_highlight/error_highlight.gemspec
new file mode 100644
index 0000000..b2da18d
--- /dev/null
+++ b/lib/error_highlight/error_highlight.gemspec
@@ -0,0 +1,27 @@
+# coding: utf-8
+lib = File.expand_path('../lib', __FILE__)
+$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
+begin
+ require_relative "lib/error_highlight/version"
+rescue LoadError # Fallback to load version file in ruby core repository
+ require_relative "version"
+end
+
+Gem::Specification.new do |spec|
+ spec.name = "error_highlight"
+ spec.version = ErrorHighlight::VERSION
+ spec.authors = ["Yusuke Endoh"]
+ spec.email = ["mame@ruby-lang.org"]
+
+ spec.summary = 'Shows a one-line code snippet with an underline in the error backtrace'
+ spec.description = 'The gem enhances Exception#message by adding a short explanation where the exception is raised'
+ spec.homepage = "https://github.com/ruby/error_highlight"
+
+ spec.license = "MIT"
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.1.0.dev")
+
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
+ end
+ spec.require_paths = ["lib"]
+end
diff --git a/lib/error_highlight/formatter.rb b/lib/error_highlight/formatter.rb
new file mode 100644
index 0000000..ce687fb
--- /dev/null
+++ b/lib/error_highlight/formatter.rb
@@ -0,0 +1,25 @@
+module ErrorHighlight
+ class DefaultFormatter
+ def message_for(spot)
+ # currently only a one-line code snippet is supported
+ if spot[:first_lineno] == spot[:last_lineno]
+ indent = spot[:snippet][0...spot[:first_column]].gsub(/[^\t]/, " ")
+ marker = indent + "^" * (spot[:last_column] - spot[:first_column])
+
+ "\n\n#{ spot[:snippet] }#{ marker }"
+ else
+ ""
+ end
+ end
+ end
+
+ def self.formatter
+ @@formatter
+ end
+
+ def self.formatter=(formatter)
+ @@formatter = formatter
+ end
+
+ self.formatter = DefaultFormatter.new
+end
diff --git a/lib/error_highlight/version.rb b/lib/error_highlight/version.rb
new file mode 100644
index 0000000..0dda1ba
--- /dev/null
+++ b/lib/error_highlight/version.rb
@@ -0,0 +1,3 @@
+module ErrorHighlight
+ VERSION = "0.2.0"
+end
diff --git a/lib/find.rb b/lib/find.rb
index 3f54cf6..9bee99c 100644
--- a/lib/find.rb
+++ b/lib/find.rb
@@ -49,14 +49,14 @@ module Find
yield file.dup
begin
s = File.lstat(file)
- rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
+ rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG, Errno::EINVAL
raise unless ignore_error
next
end
if s.directory? then
begin
fs = Dir.children(file, encoding: enc)
- rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG
+ rescue Errno::ENOENT, Errno::EACCES, Errno::ENOTDIR, Errno::ELOOP, Errno::ENAMETOOLONG, Errno::EINVAL
raise unless ignore_error
next
end
diff --git a/lib/forwardable.rb b/lib/forwardable.rb
index fb24b8c..c9c4128 100644
--- a/lib/forwardable.rb
+++ b/lib/forwardable.rb
@@ -76,7 +76,7 @@
# def_delegators :@q, :clear, :first, :push, :shift, :size
# end
#
-# q = Queue.new
+# q = Thread::Queue.new
# q.enq 1, 2, 3, 4, 5
# q.push 6
#
diff --git a/lib/getoptlong.rb b/lib/getoptlong.rb
index 53b80ff..d3fff34 100644
--- a/lib/getoptlong.rb
+++ b/lib/getoptlong.rb
@@ -114,7 +114,7 @@ class GetoptLong
class InvalidOption < Error; end
#
- # Set up option processing.
+ # \Set up option processing.
#
# The options to support are passed to new() as an array of arrays.
# Each sub-array contains any number of String option names which carry
@@ -190,7 +190,7 @@ class GetoptLong
end
#
- # Set the handling of the ordering of options and arguments.
+ # \Set the handling of the ordering of options and arguments.
# A RuntimeError is raised if option processing has already started.
#
# The supplied value must be a member of GetoptLong::ORDERINGS. It alters
@@ -267,7 +267,7 @@ class GetoptLong
attr_reader :ordering
#
- # Set options. Takes the same argument as GetoptLong.new.
+ # \Set options. Takes the same argument as GetoptLong.new.
#
# Raises a RuntimeError if option processing has already started.
#
@@ -341,7 +341,7 @@ class GetoptLong
end
#
- # Set/Unset `quiet' mode.
+ # \Set/Unset `quiet' mode.
#
attr_writer :quiet
@@ -383,7 +383,7 @@ class GetoptLong
end
#
- # Set an error (a protected method).
+ # \Set an error (a protected method).
#
def set_error(type, message)
$stderr.print("#{$0}: #{message}\n") if !@quiet
diff --git a/lib/getoptlong/getoptlong.gemspec b/lib/getoptlong/getoptlong.gemspec
index 9ebe3ae..dfe087b 100644
--- a/lib/getoptlong/getoptlong.gemspec
+++ b/lib/getoptlong/getoptlong.gemspec
@@ -26,7 +26,5 @@ Gem::Specification.new do |spec|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z 2>/dev/null`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
- spec.bindir = "exe"
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
end
diff --git a/lib/irb.rb b/lib/irb.rb
index 038d45f..665f67b 100644
--- a/lib/irb.rb
+++ b/lib/irb.rb
@@ -72,6 +72,8 @@ require_relative "irb/easter-egg"
# --nosingleline Don't use singleline editor module
# --colorize Use colorization
# --nocolorize Don't use colorization
+# --autocomplete Use autocompletion
+# --noautocomplete Don't use autocompletion
# --prompt prompt-mode/--prompt-mode prompt-mode
# Switch prompt mode. Pre-defined prompt modes are
# `default', `simple', `xmp' and `inf-ruby'
@@ -114,6 +116,7 @@ require_relative "irb/easter-egg"
# IRB.conf[:USE_SINGLELINE] = nil
# IRB.conf[:USE_COLORIZE] = true
# IRB.conf[:USE_TRACER] = false
+# IRB.conf[:USE_AUTOCOMPLETE] = true
# IRB.conf[:IGNORE_SIGINT] = true
# IRB.conf[:IGNORE_EOF] = false
# IRB.conf[:PROMPT_MODE] = :DEFAULT
@@ -524,7 +527,7 @@ module IRB
@context.io.prompt
end
- @scanner.set_input(@context.io) do
+ @scanner.set_input(@context.io, context: @context) do
signal_status(:IN_INPUT) do
if l = @context.io.gets
print l if @context.verbose?
@@ -666,6 +669,8 @@ module IRB
lines = lines.reverse if order == :bottom
lines.map{ |l| l + "\n" }.join
}
+ # The "<top (required)>" in "(irb)" may be the top level of IRB so imitate the main object.
+ message = message.gsub(/\(irb\):(?<num>\d+):in `<(?<frame>top \(required\))>'/) { "(irb):#{$~[:num]}:in `<main>'" }
puts message
end
print "Maybe IRB bug!\n" if irb_bug
diff --git a/lib/irb/cmd/help.rb b/lib/irb/cmd/help.rb
index 0629479..d82e78f 100644
--- a/lib/irb/cmd/help.rb
+++ b/lib/irb/cmd/help.rb
@@ -17,7 +17,8 @@ module IRB
class Help < Nop
def execute(*names)
require 'rdoc/ri/driver'
- IRB::ExtendCommand::Help.const_set(:Ri, RDoc::RI::Driver.new)
+ opts = RDoc::RI::Driver.process_args([])
+ IRB::ExtendCommand::Help.const_set(:Ri, RDoc::RI::Driver.new(opts))
rescue LoadError, SystemExit
IRB::ExtendCommand::Help.remove_method(:execute)
# raise NoMethodError in ensure
diff --git a/lib/irb/cmd/info.rb b/lib/irb/cmd/info.rb
index d122c88..8ad0c2a 100644
--- a/lib/irb/cmd/info.rb
+++ b/lib/irb/cmd/info.rb
@@ -14,6 +14,12 @@ module IRB
str += "InputMethod: #{IRB.CurrentContext.io.inspect}\n"
str += ".irbrc path: #{IRB.rc_file}\n" if File.exist?(IRB.rc_file)
str += "RUBY_PLATFORM: #{RUBY_PLATFORM}\n"
+ str += "LANG env: #{ENV["LANG"]}\n" if ENV["LANG"] && !ENV["LANG"].empty?
+ str += "LC_ALL env: #{ENV["LC_ALL"]}\n" if ENV["LC_ALL"] && !ENV["LC_ALL"].empty?
+ if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
+ codepage = `chcp`.sub(/.*: (\d+)\n/, '\1')
+ str += "Code page: #{codepage}\n"
+ end
str
end
alias_method :to_s, :inspect
diff --git a/lib/irb/cmd/ls.rb b/lib/irb/cmd/ls.rb
index 8a3c420..cbbf962 100644
--- a/lib/irb/cmd/ls.rb
+++ b/lib/irb/cmd/ls.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true
require "reline"
-require 'set'
require_relative "nop"
require_relative "../color"
@@ -17,32 +16,27 @@ module IRB
klass = (obj.class == Class || obj.class == Module ? obj : obj.class)
o.dump("constants", obj.constants) if obj.respond_to?(:constants)
- dump_singleton_methods(o, klass, obj)
- dump_instance_methods(o, klass)
+ dump_methods(o, klass, obj)
o.dump("instance variables", obj.instance_variables)
o.dump("class variables", klass.class_variables)
o.dump("locals", locals)
end
- def dump_singleton_methods(o, klass, obj)
- maps = class_method_map(obj.singleton_class.ancestors.take_while { |c| c != klass })
+ def dump_methods(o, klass, obj)
+ singleton_class = begin obj.singleton_class; rescue TypeError; nil end
+ maps = class_method_map((singleton_class || klass).ancestors)
maps.each do |mod, methods|
- name = mod == obj.singleton_class ? "#{klass}.methods" : "#{mod}#methods"
+ name = mod == singleton_class ? "#{klass}.methods" : "#{mod}#methods"
o.dump(name, methods)
end
end
- def dump_instance_methods(o, klass)
- maps = class_method_map(klass.ancestors)
- maps.each do |mod, methods|
- o.dump("#{mod}#methods", methods)
- end
- end
-
def class_method_map(classes)
- dumped = Set.new
+ dumped = Array.new
classes.reject { |mod| mod >= Object }.map do |mod|
- methods = mod.public_instance_methods(false).select { |m| dumped.add?(m) }
+ methods = mod.public_instance_methods(false).select do |m|
+ dumped.push(m) unless dumped.include?(m)
+ end
[mod, methods]
end.reverse
end
diff --git a/lib/irb/cmd/measure.rb b/lib/irb/cmd/measure.rb
index 58eaec2..adea540 100644
--- a/lib/irb/cmd/measure.rb
+++ b/lib/irb/cmd/measure.rb
@@ -9,6 +9,9 @@ module IRB
end
def execute(type = nil, arg = nil, &block)
+ # Please check IRB.init_config in lib/irb/init.rb that sets
+ # IRB.conf[:MEASURE_PROC] to register default "measure" methods,
+ # "measure :time" (abbreviated as "measure") and "measure :stackprof".
case type
when :off
IRB.conf[:MEASURE] = nil
diff --git a/lib/irb/cmd/show_source.rb b/lib/irb/cmd/show_source.rb
index 0bd40b7..feff831 100644
--- a/lib/irb/cmd/show_source.rb
+++ b/lib/irb/cmd/show_source.rb
@@ -59,11 +59,21 @@ module IRB
def find_end(file, first_line)
return first_line unless File.exist?(file)
lex = RubyLex.new
+ lines = File.read(file).lines[(first_line - 1)..-1]
+ tokens = RubyLex.ripper_lex_without_warning(lines.join)
+
code = +""
- File.read(file).lines[(first_line - 1)..-1].each_with_index do |line, i|
- _ltype, _indent, continue, code_block_open = lex.check_state(code << line)
+ prev_tokens = []
+
+ # chunk with line number
+ tokens.chunk { |tok| tok[0][0] }.each do |lnum, chunk|
+ code << lines[lnum]
+ prev_tokens.concat chunk
+
+ continue = lex.process_continue(prev_tokens)
+ code_block_open = lex.check_code_block(code, prev_tokens)
if !continue && !code_block_open
- return first_line + i
+ return first_line + lnum
end
end
first_line
diff --git a/lib/irb/completion.rb b/lib/irb/completion.rb
index d1bb821..a8a73cc 100644
--- a/lib/irb/completion.rb
+++ b/lib/irb/completion.rb
@@ -38,16 +38,48 @@ module IRB
BASIC_WORD_BREAK_CHARACTERS = " \t\n`><=;|&{("
- def self.retrieve_files_to_require_from_load_path
- @@files_from_load_path ||= $LOAD_PATH.flat_map { |path|
- begin
- Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: path)
- rescue Errno::ENOENT
- []
+ def self.absolute_path?(p) # TODO Remove this method after 2.6 EOL.
+ if File.respond_to?(:absolute_path?)
+ File.absolute_path?(p)
+ else
+ if File.absolute_path(p) == p
+ true
+ else
+ false
end
- }.uniq.map { |path|
- path.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '')
- }
+ end
+ end
+
+ def self.retrieve_gem_and_system_load_path
+ gem_paths = Gem::Specification.latest_specs(true).map { |s|
+ s.require_paths.map { |p|
+ if absolute_path?(p)
+ p
+ else
+ File.join(s.full_gem_path, p)
+ end
+ }
+ }.flatten if defined?(Gem::Specification)
+ (gem_paths.to_a | $LOAD_PATH).sort
+ end
+
+ def self.retrieve_files_to_require_from_load_path
+ @@files_from_load_path ||=
+ (
+ shortest = []
+ rest = retrieve_gem_and_system_load_path.each_with_object([]) { |path, result|
+ begin
+ names = Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: path)
+ rescue Errno::ENOENT
+ nil
+ end
+ next if names.empty?
+ names.map! { |n| n.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '') }.sort!
+ shortest << names.shift
+ result.concat(names)
+ }
+ shortest.sort! | rest
+ )
end
def self.retrieve_files_to_require_relative_from_current_dir
@@ -160,7 +192,7 @@ module IRB
sym = $1
candidates = Symbol.all_symbols.collect do |s|
":" + s.id2name.encode(Encoding.default_external)
- rescue Encoding::UndefinedConversionError
+ rescue EncodingError
# ignore
end
candidates.grep(/^#{Regexp.quote(sym)}/)
@@ -258,7 +290,7 @@ module IRB
all_gvars.grep(Regexp.new(Regexp.quote(gvar)))
end
- when /^([^."].*)(\.|::)([^.]*)$/
+ when /^([^.:"].*)(\.|::)([^.]*)$/
# variable.func or func.func
receiver = $1
sep = $2
@@ -296,7 +328,8 @@ module IRB
candidates.uniq!
end
if doc_namespace
- "#{rec.class.name}#{sep}#{candidates.find{ |i| i == message }}"
+ rec_class = rec.is_a?(Module) ? rec : rec.class
+ "#{rec_class.name}#{sep}#{candidates.find{ |i| i == message }}"
else
select_message(receiver, message, candidates, sep)
end
@@ -315,12 +348,19 @@ module IRB
end
else
- candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
- candidates |= ReservedWords
-
if doc_namespace
- candidates.find{ |i| i == input }
+ vars = eval("local_variables | instance_variables", bind).collect{|m| m.to_s}
+ perfect_match_var = vars.find{|m| m.to_s == input}
+ if perfect_match_var
+ eval("#{perfect_match_var}.class.name", bind)
+ else
+ candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
+ candidates |= ReservedWords
+ candidates.find{ |i| i == input }
+ end
else
+ candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
+ candidates |= ReservedWords
candidates.grep(/^#{Regexp.quote(input)}/)
end
end
diff --git a/lib/irb/context.rb b/lib/irb/context.rb
index 0d358de..3827bda 100644
--- a/lib/irb/context.rb
+++ b/lib/irb/context.rb
@@ -54,6 +54,7 @@ module IRB
@use_multiline = nil
end
@use_colorize = IRB.conf[:USE_COLORIZE]
+ @use_autocomplete = IRB.conf[:USE_AUTOCOMPLETE]
@verbose = IRB.conf[:VERBOSE]
@io = nil
@@ -185,6 +186,8 @@ module IRB
#
# A copy of the default <code>IRB.conf[:USE_COLORIZE]</code>
attr_reader :use_colorize
+ # A copy of the default <code>IRB.conf[:USE_AUTOCOMPLETE]</code>
+ attr_reader :use_autocomplete
# A copy of the default <code>IRB.conf[:INSPECT_MODE]</code>
attr_reader :inspect_mode
@@ -311,6 +314,8 @@ module IRB
alias use_readline? use_singleline
# Alias for #use_colorize
alias use_colorize? use_colorize
+ # Alias for #use_autocomplete
+ alias use_autocomplete? use_autocomplete
# Alias for #rc
alias rc? rc
alias ignore_sigint? ignore_sigint
diff --git a/lib/irb/init.rb b/lib/irb/init.rb
index 3a5f3de..3c27b4f 100644
--- a/lib/irb/init.rb
+++ b/lib/irb/init.rb
@@ -45,6 +45,7 @@ module IRB # :nodoc:
@CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod)
@CONF[:USE_COLORIZE] = !ENV['NO_COLOR']
+ @CONF[:USE_AUTOCOMPLETE] = true
@CONF[:INSPECT_MODE] = true
@CONF[:USE_TRACER] = false
@CONF[:USE_LOADER] = false
@@ -120,7 +121,11 @@ module IRB # :nodoc:
puts 'processing time: %fs' % (now - time) if IRB.conf[:MEASURE]
result
}
+ # arg can be either a symbol for the mode (:cpu, :wall, ..) or a hash for
+ # a more complete configuration.
+ # See https://github.com/tmm1/stackprof#all-options.
@CONF[:MEASURE_PROC][:STACKPROF] = proc { |context, code, line_no, arg, &block|
+ return block.() unless IRB.conf[:MEASURE]
success = false
begin
require 'stackprof'
@@ -130,10 +135,18 @@ module IRB # :nodoc:
end
if success
result = nil
- stackprof_result = StackProf.run(mode: arg ? arg : :cpu) do
+ arg = { mode: arg || :cpu } unless arg.is_a?(Hash)
+ stackprof_result = StackProf.run(**arg) do
result = block.()
end
- StackProf::Report.new(stackprof_result).print_text if IRB.conf[:MEASURE]
+ case stackprof_result
+ when File
+ puts "StackProf report saved to #{stackprof_result.path}"
+ when Hash
+ StackProf::Report.new(stackprof_result).print_text
+ else
+ puts "Stackprof ran with #{arg.inspect}"
+ end
result
else
block.()
@@ -262,6 +275,10 @@ module IRB # :nodoc:
@CONF[:USE_COLORIZE] = true
when "--nocolorize"
@CONF[:USE_COLORIZE] = false
+ when "--autocomplete"
+ @CONF[:USE_AUTOCOMPLETE] = true
+ when "--noautocomplete"
+ @CONF[:USE_AUTOCOMPLETE] = false
when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/
opt = $1 || argv.shift
prompt_mode = opt.upcase.tr("-", "_").intern
diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb
index 1854567..ea3f31b 100644
--- a/lib/irb/input-method.rb
+++ b/lib/irb/input-method.rb
@@ -14,6 +14,7 @@ require_relative 'magic-file'
require_relative 'completion'
require 'io/console'
require 'reline'
+require 'rdoc'
module IRB
STDIN_FILE_NAME = "(line)" # :nodoc:
@@ -294,6 +295,10 @@ module IRB
end
end
Reline.dig_perfect_match_proc = IRB::InputCompletor::PerfectMatchedProc
+ Reline.autocompletion = IRB.conf[:USE_AUTOCOMPLETE]
+ if IRB.conf[:USE_AUTOCOMPLETE]
+ Reline.add_dialog_proc(:show_doc, SHOW_DOC_DIALOG, Reline::DEFAULT_DIALOG_CONTEXT)
+ end
end
def check_termination(&block)
@@ -308,6 +313,75 @@ module IRB
@auto_indent_proc = block
end
+ SHOW_DOC_DIALOG = ->() {
+ dialog.trap_key = nil
+ alt_d = [
+ [Reline::Key.new(nil, 0xE4, true)], # Normal Alt+d.
+ [195, 164] # The "ä" that appears when Alt+d is pressed on xterm.
+ ]
+ begin
+ require 'rdoc'
+ rescue LoadError
+ return nil
+ end
+
+ if just_cursor_moving and completion_journey_data.nil?
+ return nil
+ end
+ cursor_pos_to_render, result, pointer, autocomplete_dialog = context.pop(4)
+ return nil if result.nil? or pointer.nil? or pointer < 0
+ name = result[pointer]
+ name = IRB::InputCompletor.retrieve_completion_data(name, doc_namespace: true)
+
+ driver = RDoc::RI::Driver.new
+
+ if key.match?(dialog.name)
+ begin
+ driver.display_names([name])
+ rescue RDoc::RI::Driver::NotFoundError
+ end
+ end
+
+ begin
+ name = driver.expand_name(name)
+ rescue RDoc::RI::Driver::NotFoundError
+ return nil
+ rescue
+ return nil # unknown error
+ end
+ doc = nil
+ used_for_class = false
+ if not name =~ /#|\./
+ found, klasses, includes, extends = driver.classes_and_includes_and_extends_for(name)
+ if not found.empty?
+ doc = driver.class_document(name, found, klasses, includes, extends)
+ used_for_class = true
+ end
+ end
+ unless used_for_class
+ doc = RDoc::Markup::Document.new
+ begin
+ driver.add_method(doc, name)
+ rescue RDoc::RI::Driver::NotFoundError
+ doc = nil
+ rescue
+ return nil # unknown error
+ end
+ end
+ return nil if doc.nil?
+ width = 40
+ formatter = RDoc::Markup::ToAnsi.new
+ formatter.width = width
+ dialog.trap_key = alt_d
+ message = 'Press Alt+d to read the full document'
+ contents = [message] + doc.accept(formatter).split("\n")
+
+ x = cursor_pos_to_render.x + autocomplete_dialog.width
+ x = autocomplete_dialog.column - width if x + width >= screen_width
+ y = cursor_pos_to_render.y
+ DialogRenderInfo.new(pos: Reline::CursorPos.new(x, y), contents: contents, width: width, bg_color: '49')
+ }
+
# Reads the next line from this input method.
#
# See IO#gets for more information.
diff --git a/lib/irb/irb.gemspec b/lib/irb/irb.gemspec
index 6cb3df0..cb619b6 100644
--- a/lib/irb/irb.gemspec
+++ b/lib/irb/irb.gemspec
@@ -36,5 +36,5 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = Gem::Requirement.new(">= 2.5")
- spec.add_dependency "reline", ">= 0.2.5"
+ spec.add_dependency "reline", ">= 0.2.8.pre.9"
end
diff --git a/lib/irb/lc/help-message b/lib/irb/lc/help-message
index 9c3ea85..30f4994 100644
--- a/lib/irb/lc/help-message
+++ b/lib/irb/lc/help-message
@@ -30,6 +30,8 @@ Usage: irb.rb [options] [programfile] [arguments]
--nosingleline Don't use singleline editor module
--colorize Use colorization
--nocolorize Don't use colorization
+ --autocomplete Use autocompletion
+ --noautocomplete Don't use autocompletion
--prompt prompt-mode/--prompt-mode prompt-mode
Switch prompt mode. Pre-defined prompt modes are
`default', `simple', `xmp' and `inf-ruby'
diff --git a/lib/irb/lc/ja/help-message b/lib/irb/lc/ja/help-message
index 9794a8e..238535a 100644
--- a/lib/irb/lc/ja/help-message
+++ b/lib/irb/lc/ja/help-message
@@ -29,6 +29,8 @@ Usage: irb.rb [options] [programfile] [arguments]
--nosingleline シングルラインエディタを利用しない.
--colorize 色付けを利用する.
--nocolorize 色付けを利用しない.
+ --autocomplete オートコンプリートを利用する.
+ --noautocomplete オートコンプリートを利用しない.
--prompt prompt-mode/--prompt-mode prompt-mode
プロンプトモードを切替えます. 現在定義されているプ
ロンプトモードは, default, simple, xmp, inf-rubyが
diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb
index 3b3b9b3..f0c056e 100644
--- a/lib/irb/ruby-lex.rb
+++ b/lib/irb/ruby-lex.rb
@@ -30,26 +30,31 @@ class RubyLex
@prompt = nil
end
- def self.compile_with_errors_suppressed(code)
- line_no = 1
+ def self.compile_with_errors_suppressed(code, line_no: 1)
begin
result = yield code, line_no
rescue ArgumentError
+ # Ruby can issue an error for the code if there is an
+ # incomplete magic comment for encoding in it. Force an
+ # expression with a new line before the code in this
+ # case to prevent magic comment handling. To make sure
+ # line numbers in the lexed code remain the same,
+ # decrease the line number by one.
code = ";\n#{code}"
- line_no = 0
+ line_no -= 1
result = yield code, line_no
end
result
end
# io functions
- def set_input(io, p = nil, &block)
+ def set_input(io, p = nil, context: nil, &block)
@io = io
if @io.respond_to?(:check_termination)
@io.check_termination do |code|
if Reline::IOGate.in_pasting?
lex = RubyLex.new
- rest = lex.check_termination_in_prev_line(code)
+ rest = lex.check_termination_in_prev_line(code, context: context)
if rest
Reline.delete_text
rest.bytes.reverse_each do |c|
@@ -61,7 +66,7 @@ class RubyLex
end
else
code.gsub!(/\s*\z/, '').concat("\n")
- ltype, indent, continue, code_block_open = check_state(code)
+ ltype, indent, continue, code_block_open = check_state(code, context: context)
if ltype or indent > 0 or continue or code_block_open
false
else
@@ -74,7 +79,7 @@ class RubyLex
@io.dynamic_prompt do |lines|
lines << '' if lines.empty?
result = []
- tokens = self.class.ripper_lex_without_warning(lines.map{ |l| l + "\n" }.join)
+ tokens = self.class.ripper_lex_without_warning(lines.map{ |l| l + "\n" }.join, context: context)
code = String.new
partial_tokens = []
unprocessed_tokens = []
@@ -86,7 +91,7 @@ class RubyLex
t_str = t[2]
t_str.each_line("\n") do |s|
code << s << "\n"
- ltype, indent, continue, code_block_open = check_state(code, partial_tokens)
+ ltype, indent, continue, code_block_open = check_state(code, partial_tokens, context: context)
result << @prompt.call(ltype, indent, continue || code_block_open, @line_no + line_num_offset)
line_num_offset += 1
end
@@ -96,7 +101,7 @@ class RubyLex
end
end
unless unprocessed_tokens.empty?
- ltype, indent, continue, code_block_open = check_state(code, unprocessed_tokens)
+ ltype, indent, continue, code_block_open = check_state(code, unprocessed_tokens, context: context)
result << @prompt.call(ltype, indent, continue || code_block_open, @line_no + line_num_offset)
end
result
@@ -129,15 +134,25 @@ class RubyLex
:on_param_error
]
- def self.ripper_lex_without_warning(code)
+ def self.ripper_lex_without_warning(code, context: nil)
verbose, $VERBOSE = $VERBOSE, nil
+ if context
+ lvars = context&.workspace&.binding&.local_variables
+ if lvars && !lvars.empty?
+ code = "#{lvars.join('=')}=nil\n#{code}"
+ line_no = 0
+ else
+ line_no = 1
+ end
+ end
tokens = nil
- compile_with_errors_suppressed(code) do |inner_code, line_no|
+ compile_with_errors_suppressed(code, line_no: line_no) do |inner_code, line_no|
lexer = Ripper::Lexer.new(inner_code, '-', line_no)
if lexer.respond_to?(:scan) # Ruby 2.7+
tokens = []
pos_to_index = {}
lexer.scan.each do |t|
+ next if t.pos.first == 0
if pos_to_index.has_key?(t[0])
index = pos_to_index[t[0]]
found_tk = tokens[index]
@@ -182,7 +197,7 @@ class RubyLex
if @io.respond_to?(:auto_indent) and context.auto_indent_mode
@io.auto_indent do |lines, line_index, byte_pointer, is_newline|
if is_newline
- @tokens = self.class.ripper_lex_without_warning(lines[0..line_index].join("\n"))
+ @tokens = self.class.ripper_lex_without_warning(lines[0..line_index].join("\n"), context: context)
prev_spaces = find_prev_spaces(line_index)
depth_difference = check_newline_depth_difference
depth_difference = 0 if depth_difference < 0
@@ -191,8 +206,8 @@ class RubyLex
code = line_index.zero? ? '' : lines[0..(line_index - 1)].map{ |l| l + "\n" }.join
last_line = lines[line_index]&.byteslice(0, byte_pointer)
code += last_line if last_line
- @tokens = self.class.ripper_lex_without_warning(code)
- corresponding_token_depth = check_corresponding_token_depth
+ @tokens = self.class.ripper_lex_without_warning(code, context: context)
+ corresponding_token_depth = check_corresponding_token_depth(lines, line_index)
if corresponding_token_depth
corresponding_token_depth
else
@@ -203,8 +218,8 @@ class RubyLex
end
end
- def check_state(code, tokens = nil)
- tokens = self.class.ripper_lex_without_warning(code) unless tokens
+ def check_state(code, tokens = nil, context: nil)
+ tokens = self.class.ripper_lex_without_warning(code, context: context) unless tokens
ltype = process_literal_type(tokens)
indent = process_nesting_level(tokens)
continue = process_continue(tokens)
@@ -588,7 +603,7 @@ class RubyLex
depth_difference
end
- def check_corresponding_token_depth
+ def check_corresponding_token_depth(lines, line_index)
corresponding_token_depth = nil
is_first_spaces_of_line = true
is_first_printable_of_line = true
@@ -596,6 +611,11 @@ class RubyLex
spaces_at_line_head = 0
open_brace_on_line = 0
in_oneliner_def = nil
+
+ if heredoc_scope?
+ return lines[line_index][/^ */].length
+ end
+
@tokens.each_with_index do |t, index|
# detecting one-liner method definition
if in_oneliner_def.nil?
@@ -693,6 +713,9 @@ class RubyLex
while i < tokens.size
t = tokens[i]
case t[1]
+ when *end_type.last
+ start_token.pop
+ end_type.pop
when :on_tstring_beg
start_token << t
end_type << [:on_tstring_end, :on_label_end]
@@ -700,10 +723,14 @@ class RubyLex
start_token << t
end_type << :on_regexp_end
when :on_symbeg
- acceptable_single_tokens = %i{on_ident on_const on_op on_cvar on_ivar on_gvar on_kw}
- if (i + 1) < tokens.size and acceptable_single_tokens.all?{ |st| tokens[i + 1][1] != st }
- start_token << t
- end_type << :on_tstring_end
+ acceptable_single_tokens = %i{on_ident on_const on_op on_cvar on_ivar on_gvar on_kw on_int on_backtick}
+ if (i + 1) < tokens.size
+ if acceptable_single_tokens.all?{ |st| tokens[i + 1][1] != st }
+ start_token << t
+ end_type << :on_tstring_end
+ else
+ i += 1
+ end
end
when :on_backtick
start_token << t
@@ -714,9 +741,6 @@ class RubyLex
when :on_heredoc_beg
start_token << t
end_type << :on_heredoc_end
- when *end_type.last
- start_token.pop
- end_type.pop
end
i += 1
end
@@ -754,8 +778,8 @@ class RubyLex
end
end
- def check_termination_in_prev_line(code)
- tokens = self.class.ripper_lex_without_warning(code)
+ def check_termination_in_prev_line(code, context: nil)
+ tokens = self.class.ripper_lex_without_warning(code, context: context)
past_first_newline = false
index = tokens.rindex do |t|
# traverse first token before last line
@@ -798,5 +822,12 @@ class RubyLex
end
false
end
+
+ private
+
+ def heredoc_scope?
+ heredoc_tokens = @tokens.select { |t| [:on_heredoc_beg, :on_heredoc_end].include?(t.event) }
+ heredoc_tokens[-1]&.event == :on_heredoc_beg
+ end
end
# :startdoc:
diff --git a/lib/irb/version.rb b/lib/irb/version.rb
index 0014bdd..4bf79e8 100644
--- a/lib/irb/version.rb
+++ b/lib/irb/version.rb
@@ -11,7 +11,7 @@
#
module IRB # :nodoc:
- VERSION = "1.3.5"
+ VERSION = "1.3.8.pre.9"
@RELEASE_VERSION = VERSION
- @LAST_UPDATE_DATE = "2021-04-03"
+ @LAST_UPDATE_DATE = "2021-09-10"
end
diff --git a/lib/irb/workspace.rb b/lib/irb/workspace.rb
index 78d434d..2c4c40f 100644
--- a/lib/irb/workspace.rb
+++ b/lib/irb/workspace.rb
@@ -12,6 +12,7 @@
require "delegate"
+IRB::TOPLEVEL_BINDING = binding
module IRB # :nodoc:
class WorkSpace
# Creates a new workspace.
@@ -57,6 +58,8 @@ EOF
__FILE__,
__LINE__ - 3)
when 4 # binding is a copy of TOPLEVEL_BINDING (default)
+ # Note that this will typically be IRB::TOPLEVEL_BINDING
+ # This is to avoid RubyGems' local variables (see issue #17623)
@binding = TOPLEVEL_BINDING.dup
end
end
diff --git a/lib/logger/logger.gemspec b/lib/logger/logger.gemspec
index cd6d97d..ccd4e70 100644
--- a/lib/logger/logger.gemspec
+++ b/lib/logger/logger.gemspec
@@ -16,8 +16,6 @@ Gem::Specification.new do |spec|
spec.licenses = ["Ruby", "BSD-2-Clause"]
spec.files = Dir.glob("lib/**/*.rb") + ["logger.gemspec"]
- spec.bindir = "exe"
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.required_ruby_version = ">= 2.3.0"
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 1963413..cab9a3f 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -284,7 +284,8 @@ MESSAGE
end
def split_libs(*strs)
- strs.map {|s| s.split(/\s+(?=-|\z)/)}.flatten
+ sep = $mswin ? /\s+/ : /\s+(?=-|\z)/
+ strs.map {|s| s.lstrip.split(sep)}.flatten
end
def merge_libs(*libs)
@@ -770,11 +771,20 @@ int main() {printf("%"PRI_CONFTEST_PREFIX"#{neg ? 'd' : 'u'}\\n", conftest_const
# files.
def try_func(func, libs, headers = nil, opt = "", &b)
headers = cpp_include(headers)
+ prepare = String.new
case func
when /^&/
decltype = proc {|x|"const volatile void *#{x}"}
when /\)$/
- call = func
+ strvars = []
+ call = func.gsub(/""/) {
+ v = "s#{strvars.size + 1}"
+ strvars << v
+ v
+ }
+ unless strvars.empty?
+ prepare << "char " << strvars.map {|v| "#{v}[1024]"}.join(", ") << "; "
+ end
when nil
call = ""
else
@@ -804,18 +814,26 @@ SRC
extern int t(void);
#{MAIN_DOES_NOTHING 't'}
#{"extern void #{call};" if decltype}
-int t(void) { #{call}; return 0; }
+int t(void) { #{prepare}#{call}; return 0; }
SRC
end
# You should use +have_var+ rather than +try_var+.
def try_var(var, headers = nil, opt = "", &b)
headers = cpp_include(headers)
- try_compile(<<"SRC", opt, &b)
+ try_compile(<<"SRC", opt, &b) or
+#{headers}
+/*top*/
+extern int t(void);
+#{MAIN_DOES_NOTHING 't'}
+int t(void) { const volatile void *volatile p; p = &(&#{var})[0]; return !p; }
+SRC
+ try_link(<<"SRC", opt, &b)
#{headers}
/*top*/
extern int t(void);
#{MAIN_DOES_NOTHING 't'}
+extern int #{var};
int t(void) { const volatile void *volatile p; p = &(&#{var})[0]; return !p; }
SRC
end
@@ -2038,7 +2056,7 @@ RUBY = $(ruby#{sep})
ruby_headers = #{headers.join(' ')}
RM = #{config_string('RM', &possible_command) || '$(RUBY) -run -e rm -- -f'}
-RM_RF = #{'$(RUBY) -run -e rm -- -rf'}
+RM_RF = #{config_string('RMALL', &possible_command) || '$(RUBY) -run -e rm -- -rf'}
RMDIRS = #{config_string('RMDIRS', &possible_command) || '$(RUBY) -run -e rmdir -- -p'}
MAKEDIRS = #{config_string('MAKEDIRS', &possible_command) || '@$(RUBY) -run -e mkdir -- -p'}
INSTALL = #{config_string('INSTALL', &possible_command) || '@$(RUBY) -run -e install -- -vp'}
@@ -2497,7 +2515,7 @@ site-install-rb: install-rb
mfile.print "$(ECHO) linking static-library $(@#{rsep})\n\t$(Q) "
mfile.print "$(AR) #{config_string('ARFLAGS') || 'cru '}$@ $(OBJS)"
config_string('RANLIB') do |ranlib|
- mfile.print "\n\t-$(Q)#{ranlib} $(@) 2> /dev/null || true"
+ mfile.print "\n\t-$(Q)#{ranlib} $(@)#{$ignore_error}"
end
end
mfile.print "\n\n"
@@ -2763,7 +2781,7 @@ clean-rb-default::
clean-rb::
clean-so::
clean: clean-so clean-static clean-rb-default clean-rb
-\t\t-$(Q)$(RM) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep}) .*.time
+\t\t-$(Q)$(RM_RF) $(CLEANLIBS#{sep}) $(CLEANOBJS#{sep}) $(CLEANFILES#{sep}) .*.time
distclean-rb-default::
distclean-rb::
diff --git a/lib/mutex_m.rb b/lib/mutex_m.rb
index 18b6256..706d3c1 100644
--- a/lib/mutex_m.rb
+++ b/lib/mutex_m.rb
@@ -73,32 +73,32 @@ module Mutex_m
mu_initialize
end
- # See Mutex#synchronize
+ # See Thread::Mutex#synchronize
def mu_synchronize(&block)
@_mutex.synchronize(&block)
end
- # See Mutex#locked?
+ # See Thread::Mutex#locked?
def mu_locked?
@_mutex.locked?
end
- # See Mutex#try_lock
+ # See Thread::Mutex#try_lock
def mu_try_lock
@_mutex.try_lock
end
- # See Mutex#lock
+ # See Thread::Mutex#lock
def mu_lock
@_mutex.lock
end
- # See Mutex#unlock
+ # See Thread::Mutex#unlock
def mu_unlock
@_mutex.unlock
end
- # See Mutex#sleep
+ # See Thread::Mutex#sleep
def sleep(timeout = nil)
@_mutex.sleep(timeout)
end
diff --git a/lib/net/http/generic_request.rb b/lib/net/http/generic_request.rb
index 0b81243..d6198cd 100644
--- a/lib/net/http/generic_request.rb
+++ b/lib/net/http/generic_request.rb
@@ -202,9 +202,7 @@ class Net::HTTPGenericRequest
IO.copy_stream(f, chunker)
chunker.finish
else
- # copy_stream can sendfile() to sock.io unless we use SSL.
- # If sock.io is an SSLSocket, copy_stream will hit SSL_write()
- IO.copy_stream(f, sock.io)
+ IO.copy_stream(f, sock)
end
end
diff --git a/lib/optparse.rb b/lib/optparse.rb
index 2eedef5..060b134 100644
--- a/lib/optparse.rb
+++ b/lib/optparse.rb
@@ -48,6 +48,10 @@
#
# == OptionParser
#
+# === New to \OptionParser?
+#
+# See the {Tutorial}[./doc/optparse/tutorial_rdoc.html].
+#
# === Introduction
#
# OptionParser is a class for command-line option analysis. It is much more
@@ -415,8 +419,10 @@
#
# === Further documentation
#
-# The above examples should be enough to learn how to use this class. If you
-# have any questions, file a ticket at http://bugs.ruby-lang.org.
+# The above examples, along with the accompanying
+# {Tutorial}[./doc/optparse/tutorial_rdoc.html],
+# should be enough to learn how to use this class.
+# If you have any questions, file a ticket at http://bugs.ruby-lang.org.
#
class OptionParser
OptionParser::Version = "0.1.1"
@@ -547,7 +553,7 @@ class OptionParser
# Parses +arg+ and returns rest of +arg+ and matched portion to the
# argument pattern. Yields when the pattern doesn't match substring.
#
- def parse_arg(arg)
+ def parse_arg(arg) # :nodoc:
pattern or return nil, [arg]
unless m = pattern.match(arg)
yield(InvalidArgument, arg)
@@ -572,7 +578,7 @@ class OptionParser
# conversion. Yields at semi-error condition instead of raising an
# exception.
#
- def conv_arg(arg, val = [])
+ def conv_arg(arg, val = []) # :nodoc:
if conv
val = conv.call(*val)
else
@@ -806,7 +812,7 @@ class OptionParser
# +lopts+:: Long style option list.
# +nlopts+:: Negated long style options list.
#
- def update(sw, sopts, lopts, nsw = nil, nlopts = nil)
+ def update(sw, sopts, lopts, nsw = nil, nlopts = nil) # :nodoc:
sopts.each {|o| @short[o] = sw} if sopts
lopts.each {|o| @long[o] = sw} if lopts
nlopts.each {|o| @long[o] = nsw} if nsw and nlopts
@@ -1300,7 +1306,7 @@ XXX
# +prv+:: Previously specified argument.
# +msg+:: Exception message.
#
- def notwice(obj, prv, msg)
+ def notwice(obj, prv, msg) # :nodoc:
unless !prv or prv == obj
raise(ArgumentError, "argument #{msg} given twice: #{obj}",
ParseError.filter_backtrace(caller(2)))
@@ -1732,7 +1738,7 @@ XXX
# Traverses @stack, sending each element method +id+ with +args+ and
# +block+.
#
- def visit(id, *args, &block)
+ def visit(id, *args, &block) # :nodoc:
@stack.reverse_each do |el|
el.__send__(id, *args, &block)
end
@@ -1743,7 +1749,7 @@ XXX
#
# Searches +key+ in @stack for +id+ hash and returns or yields the result.
#
- def search(id, key)
+ def search(id, key) # :nodoc:
block_given = block_given?
visit(:search, id, key) do |k|
return block_given ? yield(k) : k
@@ -1760,7 +1766,7 @@ XXX
# +icase+:: Search case insensitive if true.
# +pat+:: Optional pattern for completion.
#
- def complete(typ, opt, icase = false, *pat)
+ def complete(typ, opt, icase = false, *pat) # :nodoc:
if pat.empty?
search(typ, opt) {|sw| return [sw, opt]} # exact match or...
end
diff --git a/lib/ostruct.rb b/lib/ostruct.rb
index 1203d10..c03d912 100644
--- a/lib/ostruct.rb
+++ b/lib/ostruct.rb
@@ -308,7 +308,7 @@ class OpenStruct
# Finds and returns the object in nested objects
# that is specified by +name+ and +identifiers+.
# The nested objects may be instances of various classes.
- # See {Dig Methods}[rdoc-ref:doc/dig_methods.rdoc].
+ # See {Dig Methods}[rdoc-ref:dig_methods.rdoc].
#
# Examples:
# require "ostruct"
diff --git a/lib/racc/parser-text.rb b/lib/racc/parser-text.rb
index 7090c6a..4188fa8 100644
--- a/lib/racc/parser-text.rb
+++ b/lib/racc/parser-text.rb
@@ -548,7 +548,7 @@ module Racc
end
# Exit parser.
- # Return value is Symbol_Value_Stack[0].
+ # Return value is +Symbol_Value_Stack[0]+.
def yyaccept
throw :racc_jump, 2
end
diff --git a/lib/racc/parserfilegenerator.rb b/lib/racc/parserfilegenerator.rb
index fb6c209..7131026 100644
--- a/lib/racc/parserfilegenerator.rb
+++ b/lib/racc/parserfilegenerator.rb
@@ -320,50 +320,6 @@ module Racc
end
def integer_list(name, table)
- if table.size > 2000
- serialize_integer_list_compressed name, table
- else
- serialize_integer_list_std name, table
- end
- end
-
- def serialize_integer_list_compressed(name, table)
- # TODO: this can be made a LOT more clean with a simple split/map
- sep = "\n"
- nsep = ",\n"
- buf = String.new
- com = ''
- ncom = ','
- co = com
- @f.print 'clist = ['
- table.each do |i|
- buf << co << i.to_s; co = ncom
- if buf.size > 66
- @f.print sep; sep = nsep
- @f.print "'", buf, "'"
- buf = String.new
- co = com
- end
- end
- unless buf.empty?
- @f.print sep
- @f.print "'", buf, "'"
- end
- line ' ]'
-
- @f.print(<<-End)
- #{name} = arr = ::Array.new(#{table.size}, nil)
- idx = 0
- clist.each do |str|
- str.split(',', -1).each do |i|
- arr[idx] = i.to_i unless i.empty?
- idx += 1
- end
- end
- End
- end
-
- def serialize_integer_list_std(name, table)
sep = ''
line "#{name} = ["
table.each_slice(10) do |ns|
diff --git a/lib/racc/pre-setup b/lib/racc/pre-setup
deleted file mode 100644
index 5027d86..0000000
--- a/lib/racc/pre-setup
+++ /dev/null
@@ -1,13 +0,0 @@
-def generate_parser_text_rb(target)
- return if File.exist?(srcfile(target))
- $stderr.puts "generating #{target}..."
- File.open(target, 'w') {|f|
- f.puts "module Racc"
- f.puts " PARSER_TEXT = <<'__end_of_file__'"
- f.puts File.read(srcfile('parser.rb'))
- f.puts "__end_of_file__"
- f.puts "end"
- }
-end
-
-generate_parser_text_rb 'parser-text.rb'
diff --git a/lib/racc/racc.gemspec b/lib/racc/racc.gemspec
index 5c34589..7ee706f 100644
--- a/lib/racc/racc.gemspec
+++ b/lib/racc/racc.gemspec
@@ -20,14 +20,14 @@ Racc is a LALR(1) parser generator.
DESC
s.authors = ["Minero Aoki", "Aaron Patterson"]
s.email = [nil, "aaron@tenderlovemaking.com"]
- s.homepage = "http://i.loveruby.net/en/projects/racc/"
+ s.homepage = "https://i.loveruby.net/en/projects/racc/"
s.licenses = ["Ruby", "BSD-2-Clause"]
s.executables = ["racc"]
s.files = [
- "COPYING", "ChangeLog",
- "README.ja.rdoc", "README.rdoc", "Rakefile", "TODO", "bin/racc",
+ "COPYING", "ChangeLog", "TODO",
+ "README.ja.rdoc", "README.rdoc", "bin/racc",
"ext/racc/MANIFEST",
- "ext/racc/com/headius/racc/Cparse.java", "ext/racc/cparse/cparse.c",
+ "ext/racc/cparse/cparse.c",
"ext/racc/cparse/extconf.rb",
"lib/racc.rb", "lib/racc/compat.rb",
"lib/racc/debugflags.rb", "lib/racc/exception.rb",
@@ -35,68 +35,19 @@ DESC
"lib/racc/info.rb", "lib/racc/iset.rb",
"lib/racc/logfilegenerator.rb", "lib/racc/parser-text.rb",
"lib/racc/parser.rb", "lib/racc/parserfilegenerator.rb",
- "lib/racc/pre-setup", "lib/racc/sourcetext.rb",
+ "lib/racc/sourcetext.rb",
"lib/racc/state.rb", "lib/racc/statetransitiontable.rb",
- "lib/racc/static.rb", "rdoc/en/NEWS.en.rdoc",
- "rdoc/en/grammar.en.rdoc", "rdoc/ja/NEWS.ja.rdoc",
- "rdoc/ja/command.ja.html", "rdoc/ja/debug.ja.rdoc",
- "rdoc/ja/grammar.ja.rdoc", "rdoc/ja/index.ja.html",
- "rdoc/ja/parser.ja.rdoc", "rdoc/ja/usage.ja.html",
- "sample/array.y", "sample/array2.y", "sample/calc-ja.y",
- "sample/calc.y", "sample/conflict.y", "sample/hash.y",
- "sample/lalr.y", "sample/lists.y", "sample/syntax.y",
- "sample/yyerr.y",
- "test/assets/cadenza.y", "test/assets/cast.y",
- "test/assets/chk.y", "test/assets/conf.y",
- "test/assets/csspool.y", "test/assets/digraph.y",
- "test/assets/echk.y", "test/assets/edtf.y", "test/assets/err.y",
- "test/assets/error_recovery.y", "test/assets/expect.y",
- "test/assets/firstline.y", "test/assets/huia.y",
- "test/assets/ichk.y", "test/assets/intp.y",
- "test/assets/journey.y", "test/assets/liquor.y",
- "test/assets/machete.y", "test/assets/macruby.y",
- "test/assets/mailp.y", "test/assets/mediacloth.y",
- "test/assets/mof.y", "test/assets/namae.y", "test/assets/nasl.y",
- "test/assets/newsyn.y", "test/assets/noend.y",
- "test/assets/nokogiri-css.y", "test/assets/nonass.y",
- "test/assets/normal.y", "test/assets/norule.y",
- "test/assets/nullbug1.y", "test/assets/nullbug2.y",
- "test/assets/opal.y", "test/assets/opt.y",
- "test/assets/percent.y", "test/assets/php_serialization.y",
- "test/assets/recv.y", "test/assets/riml.y",
- "test/assets/rrconf.y", "test/assets/ruby18.y",
- "test/assets/ruby19.y", "test/assets/ruby20.y",
- "test/assets/ruby21.y", "test/assets/ruby22.y",
- "test/assets/scan.y", "test/assets/syntax.y",
- "test/assets/tp_plus.y", "test/assets/twowaysql.y",
- "test/assets/unterm.y", "test/assets/useless.y",
- "test/assets/yyerr.y", "test/bench.y", "test/helper.rb",
- "test/infini.y", "test/regress/cadenza", "test/regress/cast",
- "test/regress/csspool", "test/regress/edtf", "test/regress/huia",
- "test/regress/journey", "test/regress/liquor",
- "test/regress/machete", "test/regress/mediacloth",
- "test/regress/mof", "test/regress/namae", "test/regress/nasl",
- "test/regress/nokogiri-css", "test/regress/opal",
- "test/regress/php_serialization", "test/regress/riml",
- "test/regress/ruby18", "test/regress/ruby22",
- "test/regress/tp_plus", "test/regress/twowaysql",
- "test/scandata/brace", "test/scandata/gvar",
- "test/scandata/normal", "test/scandata/percent",
- "test/scandata/slash", "test/src.intp", "test/start.y",
- "test/test_chk_y.rb", "test/test_grammar_file_parser.rb",
- "test/test_racc_command.rb", "test/test_scan_y.rb",
- "test/testscanner.rb", "web/racc.en.rhtml", "web/racc.ja.rhtml"
+ "lib/racc/static.rb",
+ "doc/en/NEWS.en.rdoc", "doc/en/grammar2.en.rdoc",
+ "doc/en/grammar.en.rdoc", "doc/ja/NEWS.ja.rdoc",
+ "doc/ja/command.ja.html", "doc/ja/debug.ja.rdoc",
+ "doc/ja/grammar.ja.rdoc", "doc/ja/index.ja.html",
+ "doc/ja/parser.ja.rdoc", "doc/ja/usage.ja.html",
]
s.require_paths = ["lib"]
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.required_ruby_version = ">= 2.5"
s.rdoc_options = ["--main", "README.rdoc"]
- s.extra_rdoc_files = [
- "README.ja.rdoc", "README.rdoc",
- "rdoc/en/NEWS.en.rdoc", "rdoc/en/grammar.en.rdoc",
- "rdoc/ja/NEWS.ja.rdoc", "rdoc/ja/debug.ja.rdoc",
- "rdoc/ja/grammar.ja.rdoc", "rdoc/ja/parser.ja.rdoc",
- "README.ja.rdoc", "README.rdoc"
- ]
+ s.extra_rdoc_files = ["README.ja.rdoc", "README.rdoc"]
if RUBY_PLATFORM =~ /java/
s.files << 'lib/racc/cparse-jruby.jar'
diff --git a/lib/racc/rdoc/grammar.en.rdoc b/lib/racc/rdoc/grammar.en.rdoc
deleted file mode 100644
index af10803..0000000
--- a/lib/racc/rdoc/grammar.en.rdoc
+++ /dev/null
@@ -1,219 +0,0 @@
-= Racc Grammar File Reference
-
-== Global Structure
-
-== Class Block and User Code Block
-
-There are two blocks on the toplevel. One is the 'class' block, the other is the 'user code'
-block. The 'user code' block MUST be placed after the 'class' block.
-
-== Comments
-
-You can insert comments about all places. Two styles of comments can be used, Ruby style '#.....' and C style '/\*......*\/'.
-
-== Class Block
-
-The class block is formed like this:
-
- class CLASS_NAME
- [precedence table]
- [token declarations]
- [expected number of S/R conflicts]
- [options]
- [semantic value conversion]
- [start rule]
- rule
- GRAMMARS
-
-CLASS_NAME is a name of the parser class. This is the name of the generating parser
-class.
-
-If CLASS_NAME includes '::', Racc outputs the module clause. For example, writing
-"class M::C" causes the code below to be created:
-
- module M
- class C
- :
- :
- end
- end
-
-== Grammar Block
-
-The grammar block describes grammar which is able to be understood by the parser.
-Syntax is:
-
- (token): (token) (token) (token).... (action)
-
- (token): (token) (token) (token).... (action)
- | (token) (token) (token).... (action)
- | (token) (token) (token).... (action)
-
-(action) is an action which is executed when its (token)s are found.
-(action) is a ruby code block, which is surrounded by braces:
-
- { print val[0]
- puts val[1] }
-
-Note that you cannot use '%' string, here document, '%r' regexp in action.
-
-Actions can be omitted. When it is omitted, '' (empty string) is used.
-
-A return value of action is a value of the left side value ($$). It is the value of the
-result, or the returned value by `return` statement.
-
-Here is an example of the whole grammar block.
-
- rule
- goal: definition rules source { result = val }
-
- definition: /* none */ { result = [] }
- | definition startdesig { result[0] = val[1] }
- | definition
- precrule # this line continues from upper line
- {
- result[1] = val[1]
- }
-
- startdesig: START TOKEN
-
-You can use the following special local variables in action:
-
-* result ($$)
-
-The value of the left-hand side (lhs). A default value is val[0].
-
-* val ($1,$2,$3...)
-
-An array of value of the right-hand side (rhs).
-
-* _values (...$-2,$-1,$0)
-
-A stack of values. DO NOT MODIFY this stack unless you know what you are doing.
-
-== Operator Precedence
-
-This function is equal to '%prec' in yacc.
-To designate this block:
-
- prechigh
- nonassoc '++'
- left '*' '/'
- left '+' '-'
- right '='
- preclow
-
-`right` is yacc's %right, `left` is yacc's %left.
-
-`=` + (symbol) means yacc's %prec:
-
- prechigh
- nonassoc UMINUS
- left '*' '/'
- left '+' '-'
- preclow
-
- rule
- exp: exp '*' exp
- | exp '-' exp
- | '-' exp =UMINUS # equals to "%prec UMINUS"
- :
- :
-
-== expect
-
-Racc has bison's "expect" directive.
-
- # Example
-
- class MyParser
- rule
- expect 3
- :
- :
-
-This directive declares "expected" number of shift/reduce conflicts. If
-"expected" number is equal to real number of conflicts, Racc does not print
-conflict warning message.
-
-== Declaring Tokens
-
-By declaring tokens, you can avoid many meaningless bugs. If declared token
-does not exist or existing token does not decleared, Racc output warnings.
-Declaration syntax is:
-
- token TOKEN_NAME AND_IS_THIS
- ALSO_THIS_IS AGAIN_AND_AGAIN THIS_IS_LAST
-
-== Options
-
-You can write options for Racc command in your Racc file.
-
- options OPTION OPTION ...
-
-Options are:
-
-* omit_action_call
-
-omits empty action call or not.
-
-* result_var
-
-uses local variable "result" or not.
-
-You can use 'no_' prefix to invert their meanings.
-
-== Converting Token Symbol
-
-Token symbols are, as default,
-
- * naked token string in Racc file (TOK, XFILE, this_is_token, ...)
- --> symbol (:TOK, :XFILE, :this_is_token, ...)
- * quoted string (':', '.', '(', ...)
- --> same string (':', '.', '(', ...)
-
-You can change this default by "convert" block.
-Here is an example:
-
- convert
- PLUS 'PlusClass' # We use PlusClass for symbol of `PLUS'
- MIN 'MinusClass' # We use MinusClass for symbol of `MIN'
- end
-
-We can use almost all ruby value can be used by token symbol,
-except 'false' and 'nil'. These cause unexpected parse error.
-
-If you want to use String as token symbol, special care is required.
-For example:
-
- convert
- class '"cls"' # in code, "cls"
- PLUS '"plus\n"' # in code, "plus\n"
- MIN "\"minus#{val}\"" # in code, \"minus#{val}\"
- end
-
-== Start Rule
-
-'%start' in yacc. This changes start rule.
-
- start real_target
-
-== User Code Block
-
-"User Code Block" is a Ruby source code which is copied to output. There are
-three user code blocks, "header" "inner" and "footer".
-
-Format of user code is like this:
-
- ---- header
- ruby statement
- ruby statement
- ruby statement
-
- ---- inner
- ruby statement
- :
- :
-
-If four '-' exist on the line head, Racc treats it as the beginning of the
-user code block. The name of the user code block must be one word.
diff --git a/lib/racc/statetransitiontable.rb b/lib/racc/statetransitiontable.rb
index 4252ba0..4d54287 100644
--- a/lib/racc/statetransitiontable.rb
+++ b/lib/racc/statetransitiontable.rb
@@ -12,12 +12,6 @@
require 'racc/parser'
-unless Object.method_defined?(:funcall)
- class Object
- alias funcall __send__
- end
-end
-
module Racc
StateTransitionTable = Struct.new(:action_table,
@@ -300,9 +294,9 @@ module Racc
c.module_eval "def _reduce_none(vals, vstack) vals[0] end"
@grammar.each do |rule|
if rule.action.empty?
- c.funcall(:alias_method, "_reduce_#{rule.ident}", :_reduce_none)
+ c.alias_method("_reduce_#{rule.ident}", :_reduce_none)
else
- c.funcall(:define_method, "_racc_action_#{rule.ident}", &rule.action.proc)
+ c.define_method("_racc_action_#{rule.ident}", &rule.action.proc)
c.module_eval(<<-End, __FILE__, __LINE__ + 1)
def _reduce_#{rule.ident}(vals, vstack)
_racc_action_#{rule.ident}(*vals)
diff --git a/lib/rdoc/Rakefile b/lib/rdoc/Rakefile
new file mode 100644
index 0000000..278972e
--- /dev/null
+++ b/lib/rdoc/Rakefile
@@ -0,0 +1,107 @@
+$:.unshift File.expand_path 'lib'
+require 'rdoc/task'
+require 'bundler/gem_tasks'
+require 'rake/testtask'
+
+task :docs => :generate
+task :test => [:normal_test, :rubygems_test]
+
+PARSER_FILES = %w[
+ lib/rdoc/rd/block_parser.ry
+ lib/rdoc/rd/inline_parser.ry
+ lib/rdoc/markdown.kpeg
+ lib/rdoc/markdown/literals.kpeg
+]
+
+$rdoc_rakefile = true
+
+task :default => :test
+
+RDoc::Task.new do |doc|
+ doc.main = 'README.rdoc'
+ doc.title = "rdoc #{RDoc::VERSION} Documentation"
+ doc.rdoc_dir = 'html'
+ doc.rdoc_files = FileList.new %w[lib/**/*.rb *.rdoc] - PARSER_FILES
+end
+
+task ghpages: :rdoc do
+ `git checkout gh-pages`
+ require "fileutils"
+ FileUtils.rm_rf "/tmp/html"
+ FileUtils.mv "html", "/tmp"
+ FileUtils.rm_rf "*"
+ FileUtils.cp_r Dir.glob("/tmp/html/*"), "."
+end
+
+Rake::TestTask.new(:normal_test) do |t|
+ t.libs << "test/rdoc"
+ t.verbose = true
+ t.deps = :generate
+ t.test_files = FileList["test/**/test_*.rb"].exclude("test/rdoc/test_rdoc_rubygems_hook.rb")
+end
+
+Rake::TestTask.new(:rubygems_test) do |t|
+ t.libs << "test/rdoc"
+ t.verbose = true
+ t.deps = :generate
+ t.pattern = "test/rdoc/test_rdoc_rubygems_hook.rb"
+end
+
+path = "pkg/#{Bundler::GemHelper.gemspec.full_name}"
+
+package_parser_files = PARSER_FILES.map do |parser_file|
+ name = File.basename(parser_file, File.extname(parser_file))
+ _path = File.dirname(parser_file)
+ package_parser_file = "#{path}/#{name}.rb"
+ parsed_file = "#{_path}/#{name}.rb"
+
+ file package_parser_file => parsed_file # ensure copy runs before racc
+
+ package_parser_file
+end
+
+parsed_files = PARSER_FILES.map do |parser_file|
+ ext = File.extname(parser_file)
+ parsed_file = "#{parser_file.chomp(ext)}.rb"
+
+ file parsed_file => parser_file do |t|
+ puts "Generating #{parsed_file}..."
+ case ext
+ when '.ry' # need racc
+ racc = Gem.bin_path 'racc', 'racc'
+ rb_file = parser_file.gsub(/\.ry\z/, ".rb")
+ ruby "#{racc} -l -o #{rb_file} #{parser_file}"
+ open(rb_file, 'r+') do |f|
+ newtext = "# frozen_string_literal: true\n#{f.read}"
+ f.rewind
+ f.write newtext
+ end
+ when '.kpeg' # need kpeg
+ kpeg = Gem.bin_path 'kpeg', 'kpeg'
+ rb_file = parser_file.gsub(/\.kpeg\z/, ".rb")
+ ruby "#{kpeg} -fsv -o #{rb_file} #{parser_file}"
+ end
+ end
+
+ parsed_file
+end
+
+task "#{path}.gem" => package_parser_files
+desc "Generate all files used racc and kpeg"
+task :generate => parsed_files
+
+task :clean do
+ parsed_files.each do |path|
+ File.delete(path) if File.exist?(path)
+ end
+end
+
+begin
+ require 'rubocop/rake_task'
+rescue LoadError
+else
+ RuboCop::RakeTask.new(:rubocop) do |t|
+ t.options = [*parsed_files]
+ end
+ task :build => [:generate, "rubocop:auto_correct"]
+end
diff --git a/lib/rdoc/generator/darkfish.rb b/lib/rdoc/generator/darkfish.rb
index b46861d..60e0265 100644
--- a/lib/rdoc/generator/darkfish.rb
+++ b/lib/rdoc/generator/darkfish.rb
@@ -220,8 +220,8 @@ class RDoc::Generator::Darkfish
install_rdoc_static_file @template_dir + item, "./#{item}", options
end
- @options.template_stylesheets.each do |stylesheet|
- FileUtils.cp stylesheet, '.', options
+ unless @options.template_stylesheets.empty?
+ FileUtils.cp @options.template_stylesheets, '.', **options
end
Dir[(@template_dir + "{js,images}/**/*").to_s].each do |path|
diff --git a/lib/rdoc/generator/template/darkfish/_head.rhtml b/lib/rdoc/generator/template/darkfish/_head.rhtml
index e61fce1..4f33124 100644
--- a/lib/rdoc/generator/template/darkfish/_head.rhtml
+++ b/lib/rdoc/generator/template/darkfish/_head.rhtml
@@ -15,8 +15,6 @@
<link href="<%= asset_rel_prefix %>/css/fonts.css" rel="stylesheet">
<link href="<%= asset_rel_prefix %>/css/rdoc.css" rel="stylesheet">
-<%- if @options.template_stylesheets.flatten.any? then -%>
-<%- @options.template_stylesheets.flatten.each do |stylesheet| -%>
+<%- @options.template_stylesheets.each do |stylesheet| -%>
<link href="<%= asset_rel_prefix %>/<%= File.basename stylesheet %>" rel="stylesheet">
-<%- end -%>
<%- end -%>
diff --git a/lib/rdoc/markdown.rb b/lib/rdoc/markdown.rb
index 15beaef..3442f76 100644
--- a/lib/rdoc/markdown.rb
+++ b/lib/rdoc/markdown.rb
@@ -344,9 +344,8 @@ class RDoc::Markdown
end
def scan(reg)
- if m = reg.match(@string[@pos..-1])
- width = m.end(0)
- @pos += width
+ if m = reg.match(@string, @pos)
+ @pos = m.end(0)
return true
end
@@ -1060,7 +1059,7 @@ class RDoc::Markdown
self.pos = _save3
break
end
- _tmp = scan(/\A(?-mix:#*)/)
+ _tmp = scan(/\G(?-mix:#*)/)
unless _tmp
self.pos = _save3
break
@@ -1100,7 +1099,7 @@ class RDoc::Markdown
_save = self.pos
while true # sequence
_text_start = self.pos
- _tmp = scan(/\A(?-mix:\#{1,6})/)
+ _tmp = scan(/\G(?-mix:\#{1,6})/)
if _tmp
text = get_text(_text_start)
end
@@ -1165,7 +1164,7 @@ class RDoc::Markdown
self.pos = _save3
break
end
- _tmp = scan(/\A(?-mix:#*)/)
+ _tmp = scan(/\G(?-mix:#*)/)
unless _tmp
self.pos = _save3
break
@@ -1225,7 +1224,7 @@ class RDoc::Markdown
_save = self.pos
while true # sequence
- _tmp = scan(/\A(?-mix:={1,})/)
+ _tmp = scan(/\G(?-mix:={1,})/)
unless _tmp
self.pos = _save
break
@@ -1246,7 +1245,7 @@ class RDoc::Markdown
_save = self.pos
while true # sequence
- _tmp = scan(/\A(?-mix:-{1,})/)
+ _tmp = scan(/\G(?-mix:-{1,})/)
unless _tmp
self.pos = _save
break
@@ -2130,7 +2129,7 @@ class RDoc::Markdown
self.pos = _save
break
end
- _tmp = scan(/\A(?-mix:[+*-])/)
+ _tmp = scan(/\G(?-mix:[+*-])/)
unless _tmp
self.pos = _save
break
@@ -9385,7 +9384,7 @@ class RDoc::Markdown
self.pos = _save7
break
end
- _tmp = scan(/\A(?-mix:[^`\n]*$)/)
+ _tmp = scan(/\G(?-mix:[^`\n]*$)/)
unless _tmp
self.pos = _save7
end
@@ -9476,7 +9475,7 @@ class RDoc::Markdown
self.pos = _save15
break
end
- _tmp = scan(/\A(?-mix:[^`\n]*$)/)
+ _tmp = scan(/\G(?-mix:[^`\n]*$)/)
unless _tmp
self.pos = _save15
end
@@ -9725,7 +9724,7 @@ class RDoc::Markdown
_save3 = self.pos
while true # sequence
- _tmp = scan(/\A(?-mix:_+)/)
+ _tmp = scan(/\G(?-mix:_+)/)
unless _tmp
self.pos = _save3
break
@@ -9755,7 +9754,7 @@ class RDoc::Markdown
_save6 = self.pos
while true # sequence
- _tmp = scan(/\A(?-mix:_+)/)
+ _tmp = scan(/\G(?-mix:_+)/)
unless _tmp
self.pos = _save6
break
@@ -9818,7 +9817,7 @@ class RDoc::Markdown
break
end
_text_start = self.pos
- _tmp = scan(/\A(?-mix:[:\\`|*_{}\[\]()#+.!><-])/)
+ _tmp = scan(/\G(?-mix:[:\\`|*_{}\[\]()#+.!><-])/)
if _tmp
text = get_text(_text_start)
end
@@ -9944,7 +9943,7 @@ class RDoc::Markdown
self.pos = _save5
break
end
- _tmp = scan(/\A(?-mix:={1,}|-{1,})/)
+ _tmp = scan(/\G(?-mix:={1,}|-{1,})/)
unless _tmp
self.pos = _save5
break
@@ -10096,7 +10095,7 @@ class RDoc::Markdown
_save1 = self.pos
while true # sequence
_text_start = self.pos
- _tmp = scan(/\A(?-mix:\*{4,})/)
+ _tmp = scan(/\G(?-mix:\*{4,})/)
if _tmp
text = get_text(_text_start)
end
@@ -10126,7 +10125,7 @@ class RDoc::Markdown
self.pos = _save3
break
end
- _tmp = scan(/\A(?-mix:\*+)/)
+ _tmp = scan(/\G(?-mix:\*+)/)
unless _tmp
self.pos = _save3
break
@@ -10173,7 +10172,7 @@ class RDoc::Markdown
_save1 = self.pos
while true # sequence
_text_start = self.pos
- _tmp = scan(/\A(?-mix:_{4,})/)
+ _tmp = scan(/\G(?-mix:_{4,})/)
if _tmp
text = get_text(_text_start)
end
@@ -10203,7 +10202,7 @@ class RDoc::Markdown
self.pos = _save3
break
end
- _tmp = scan(/\A(?-mix:_+)/)
+ _tmp = scan(/\G(?-mix:_+)/)
unless _tmp
self.pos = _save3
break
@@ -11564,7 +11563,7 @@ class RDoc::Markdown
_save1 = self.pos
while true # sequence
- _tmp = scan(/\A(?-mix:[A-Za-z]+)/)
+ _tmp = scan(/\G(?-mix:[A-Za-z]+)/)
unless _tmp
self.pos = _save1
break
@@ -11689,7 +11688,7 @@ class RDoc::Markdown
_save2 = self.pos
while true # sequence
- _tmp = scan(/\A(?i-mx:[\w+.\/!%~$-]+)/)
+ _tmp = scan(/\G(?i-mx:[\w+.\/!%~$-]+)/)
unless _tmp
self.pos = _save2
break
@@ -12553,7 +12552,7 @@ class RDoc::Markdown
self.pos = _save10
break
end
- _tmp = scan(/\A(?-mix:`+)/)
+ _tmp = scan(/\G(?-mix:`+)/)
unless _tmp
self.pos = _save10
end
@@ -12690,7 +12689,7 @@ class RDoc::Markdown
self.pos = _save24
break
end
- _tmp = scan(/\A(?-mix:`+)/)
+ _tmp = scan(/\G(?-mix:`+)/)
unless _tmp
self.pos = _save24
end
@@ -12867,7 +12866,7 @@ class RDoc::Markdown
self.pos = _save40
break
end
- _tmp = scan(/\A(?-mix:`+)/)
+ _tmp = scan(/\G(?-mix:`+)/)
unless _tmp
self.pos = _save40
end
@@ -13004,7 +13003,7 @@ class RDoc::Markdown
self.pos = _save54
break
end
- _tmp = scan(/\A(?-mix:`+)/)
+ _tmp = scan(/\G(?-mix:`+)/)
unless _tmp
self.pos = _save54
end
@@ -13181,7 +13180,7 @@ class RDoc::Markdown
self.pos = _save70
break
end
- _tmp = scan(/\A(?-mix:`+)/)
+ _tmp = scan(/\G(?-mix:`+)/)
unless _tmp
self.pos = _save70
end
@@ -13318,7 +13317,7 @@ class RDoc::Markdown
self.pos = _save84
break
end
- _tmp = scan(/\A(?-mix:`+)/)
+ _tmp = scan(/\G(?-mix:`+)/)
unless _tmp
self.pos = _save84
end
@@ -13495,7 +13494,7 @@ class RDoc::Markdown
self.pos = _save100
break
end
- _tmp = scan(/\A(?-mix:`+)/)
+ _tmp = scan(/\G(?-mix:`+)/)
unless _tmp
self.pos = _save100
end
@@ -13632,7 +13631,7 @@ class RDoc::Markdown
self.pos = _save114
break
end
- _tmp = scan(/\A(?-mix:`+)/)
+ _tmp = scan(/\G(?-mix:`+)/)
unless _tmp
self.pos = _save114
end
@@ -13809,7 +13808,7 @@ class RDoc::Markdown
self.pos = _save130
break
end
- _tmp = scan(/\A(?-mix:`+)/)
+ _tmp = scan(/\G(?-mix:`+)/)
unless _tmp
self.pos = _save130
end
@@ -13946,7 +13945,7 @@ class RDoc::Markdown
self.pos = _save144
break
end
- _tmp = scan(/\A(?-mix:`+)/)
+ _tmp = scan(/\G(?-mix:`+)/)
unless _tmp
self.pos = _save144
end
@@ -14598,7 +14597,7 @@ class RDoc::Markdown
_save = self.pos
while true # choice
- _tmp = scan(/\A(?-mix:[~*_`&\[\]()<!#\\'"])/)
+ _tmp = scan(/\G(?-mix:[~*_`&\[\]()<!#\\'"])/)
break if _tmp
self.pos = _save
_tmp = _ExtendedSpecialChar()
@@ -14703,13 +14702,13 @@ class RDoc::Markdown
_save = self.pos
while true # sequence
- _tmp = scan(/\A(?i-mx:&#x)/)
+ _tmp = scan(/\G(?i-mx:&#x)/)
unless _tmp
self.pos = _save
break
end
_text_start = self.pos
- _tmp = scan(/\A(?-mix:[0-9a-fA-F]+)/)
+ _tmp = scan(/\G(?-mix:[0-9a-fA-F]+)/)
if _tmp
text = get_text(_text_start)
end
@@ -14745,7 +14744,7 @@ class RDoc::Markdown
break
end
_text_start = self.pos
- _tmp = scan(/\A(?-mix:[0-9]+)/)
+ _tmp = scan(/\G(?-mix:[0-9]+)/)
if _tmp
text = get_text(_text_start)
end
@@ -14781,7 +14780,7 @@ class RDoc::Markdown
break
end
_text_start = self.pos
- _tmp = scan(/\A(?-mix:[A-Za-z0-9]+)/)
+ _tmp = scan(/\G(?-mix:[A-Za-z0-9]+)/)
if _tmp
text = get_text(_text_start)
end
@@ -14813,14 +14812,14 @@ class RDoc::Markdown
# NonindentSpace = / {0,3}/
def _NonindentSpace
- _tmp = scan(/\A(?-mix: {0,3})/)
+ _tmp = scan(/\G(?-mix: {0,3})/)
set_failed_rule :_NonindentSpace unless _tmp
return _tmp
end
# Indent = /\t| /
def _Indent
- _tmp = scan(/\A(?-mix:\t| )/)
+ _tmp = scan(/\G(?-mix:\t| )/)
set_failed_rule :_Indent unless _tmp
return _tmp
end
@@ -15762,7 +15761,7 @@ class RDoc::Markdown
self.pos = _save11
break
end
- _tmp = scan(/\A(?-mix:`+)/)
+ _tmp = scan(/\G(?-mix:`+)/)
unless _tmp
self.pos = _save11
end
@@ -15843,7 +15842,7 @@ class RDoc::Markdown
self.pos = _save19
break
end
- _tmp = scan(/\A(?-mix:`+)/)
+ _tmp = scan(/\G(?-mix:`+)/)
unless _tmp
self.pos = _save19
end
diff --git a/lib/rdoc/markdown/literals.rb b/lib/rdoc/markdown/literals.rb
index 31cd237..943c2d2 100644
--- a/lib/rdoc/markdown/literals.rb
+++ b/lib/rdoc/markdown/literals.rb
@@ -174,9 +174,8 @@ class RDoc::Markdown::Literals
end
def scan(reg)
- if m = reg.match(@string[@pos..-1])
- width = m.end(0)
- @pos += width
+ if m = reg.match(@string, @pos)
+ @pos = m.end(0)
return true
end
@@ -366,14 +365,14 @@ class RDoc::Markdown::Literals
# Alphanumeric = /\p{Word}/
def _Alphanumeric
- _tmp = scan(/\A(?-mix:\p{Word})/)
+ _tmp = scan(/\G(?-mix:\p{Word})/)
set_failed_rule :_Alphanumeric unless _tmp
return _tmp
end
# AlphanumericAscii = /[A-Za-z0-9]/
def _AlphanumericAscii
- _tmp = scan(/\A(?-mix:[A-Za-z0-9])/)
+ _tmp = scan(/\G(?-mix:[A-Za-z0-9])/)
set_failed_rule :_AlphanumericAscii unless _tmp
return _tmp
end
@@ -387,21 +386,21 @@ class RDoc::Markdown::Literals
# Newline = /\n|\r\n?|\p{Zl}|\p{Zp}/
def _Newline
- _tmp = scan(/\A(?-mix:\n|\r\n?|\p{Zl}|\p{Zp})/)
+ _tmp = scan(/\G(?-mix:\n|\r\n?|\p{Zl}|\p{Zp})/)
set_failed_rule :_Newline unless _tmp
return _tmp
end
# NonAlphanumeric = /\p{^Word}/
def _NonAlphanumeric
- _tmp = scan(/\A(?-mix:\p{^Word})/)
+ _tmp = scan(/\G(?-mix:\p{^Word})/)
set_failed_rule :_NonAlphanumeric unless _tmp
return _tmp
end
# Spacechar = /\t|\p{Zs}/
def _Spacechar
- _tmp = scan(/\A(?-mix:\t|\p{Zs})/)
+ _tmp = scan(/\G(?-mix:\t|\p{Zs})/)
set_failed_rule :_Spacechar unless _tmp
return _tmp
end
diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb
index 8ae4dd4..d3bb8af 100644
--- a/lib/rdoc/markup/to_html.rb
+++ b/lib/rdoc/markup/to_html.rb
@@ -357,8 +357,8 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
url =~ /\.(gif|png|jpg|jpeg|bmp)$/ then
"<img src=\"#{url}\" />"
else
- if scheme != 'link' and /\.(?:rb|rdoc|md)\z/i =~ url
- url = url.sub(%r%\A([./]*)(.*)\z%) { "#$1#{$2.tr('.', '_')}.html" }
+ if scheme != 'link' and %r%\A((?!https?:)(?:[^/#]*/)*+)([^/#]+)\.(rb|rdoc|md)(?=\z|#)%i =~ url
+ url = "#$1#{$2.tr('.', '_')}_#$3.html#$'"
end
text = text.sub %r%^#{scheme}:/*%i, ''
diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb
index 13b7ba5..792b473 100644
--- a/lib/rdoc/options.rb
+++ b/lib/rdoc/options.rb
@@ -971,7 +971,7 @@ Usage: #{opt.program_name} [options] [names...]
opt.on("--template-stylesheets=FILES", PathArray,
"Set (or add to) the list of files to",
"include with the html template.") do |value|
- @template_stylesheets << value
+ @template_stylesheets.concat value
end
opt.separator nil
@@ -1282,4 +1282,33 @@ Usage: #{opt.program_name} [options] [names...]
end
end
+ ##
+ # Loads options from .rdoc_options if the file exists, otherwise creates a
+ # new RDoc::Options instance.
+
+ def self.load_options
+ options_file = File.expand_path '.rdoc_options'
+ return RDoc::Options.new unless File.exist? options_file
+
+ RDoc.load_yaml
+
+ begin
+ options = YAML.safe_load File.read('.rdoc_options'), permitted_classes: [RDoc::Options, Symbol]
+ rescue Psych::SyntaxError
+ raise RDoc::Error, "#{options_file} is not a valid rdoc options file"
+ end
+
+ return RDoc::Options.new unless options # Allow empty file.
+
+ raise RDoc::Error, "#{options_file} is not a valid rdoc options file" unless
+ RDoc::Options === options or Hash === options
+
+ if Hash === options
+ # Override the default values with the contents of YAML file.
+ options = RDoc::Options.new options
+ end
+
+ options
+ end
+
end
diff --git a/lib/rdoc/parser/ruby.rb b/lib/rdoc/parser/ruby.rb
index 8d021f3..e546fe2 100644
--- a/lib/rdoc/parser/ruby.rb
+++ b/lib/rdoc/parser/ruby.rb
@@ -1194,6 +1194,22 @@ class RDoc::Parser::Ruby < RDoc::Parser
end
##
+ # Parses an +included+ with a block feature of ActiveSupport::Concern.
+
+ def parse_included_with_activesupport_concern container, comment # :nodoc:
+ skip_tkspace_without_nl
+ tk = get_tk
+ unless tk[:kind] == :on_lbracket || (tk[:kind] == :on_kw && tk[:text] == 'do')
+ unget_tk tk
+ return nil # should be a block
+ end
+
+ parse_statements container
+
+ container
+ end
+
+ ##
# Parses identifiers that can create new methods or change visibility.
#
# Returns true if the comment was not consumed.
@@ -1893,6 +1909,8 @@ class RDoc::Parser::Ruby < RDoc::Parser
parse_extend_or_include RDoc::Include, container, comment
when "extend" then
parse_extend_or_include RDoc::Extend, container, comment
+ when "included" then
+ parse_included_with_activesupport_concern container, comment
end
else
diff --git a/lib/rdoc/rd/block_parser.rb b/lib/rdoc/rd/block_parser.rb
index cf30043..462ba86 100644
--- a/lib/rdoc/rd/block_parser.rb
+++ b/lib/rdoc/rd/block_parser.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
#
# DO NOT MODIFY!!!!
-# This file is automatically generated by Racc 1.5.1
+# This file is automatically generated by Racc 1.5.2
# from Racc grammar file "".
#
diff --git a/lib/rdoc/rd/inline_parser.rb b/lib/rdoc/rd/inline_parser.rb
index 007327b..8f4c2c3 100644
--- a/lib/rdoc/rd/inline_parser.rb
+++ b/lib/rdoc/rd/inline_parser.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
#
# DO NOT MODIFY!!!!
-# This file is automatically generated by Racc 1.5.1
+# This file is automatically generated by Racc 1.5.2
# from Racc grammar file "".
#
diff --git a/lib/rdoc/rdoc.gemspec b/lib/rdoc/rdoc.gemspec
index 75f8534..525a15f 100644
--- a/lib/rdoc/rdoc.gemspec
+++ b/lib/rdoc/rdoc.gemspec
@@ -246,5 +246,4 @@ RDoc includes the +rdoc+ and +ri+ tools for generating and displaying documentat
s.required_rubygems_version = Gem::Requirement.new(">= 2.2")
s.add_dependency 'psych', '>= 4.0.0'
- s.add_development_dependency("gettext")
end
diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb
index 3a3defa..5255e04 100644
--- a/lib/rdoc/rdoc.rb
+++ b/lib/rdoc/rdoc.rb
@@ -14,7 +14,7 @@ require 'time'
# is:
#
# rdoc = RDoc::RDoc.new
-# options = rdoc.load_options # returns an RDoc::Options instance
+# options = RDoc::Options.load_options # returns an RDoc::Options instance
# # set extra options
# rdoc.document options
#
@@ -152,35 +152,6 @@ class RDoc::RDoc
end
##
- # Loads options from .rdoc_options if the file exists, otherwise creates a
- # new RDoc::Options instance.
-
- def load_options
- options_file = File.expand_path '.rdoc_options'
- return RDoc::Options.new unless File.exist? options_file
-
- RDoc.load_yaml
-
- begin
- options = YAML.safe_load File.read('.rdoc_options'), permitted_classes: [RDoc::Options, Symbol]
- rescue Psych::SyntaxError
- raise RDoc::Error, "#{options_file} is not a valid rdoc options file"
- end
-
- return RDoc::Options.new unless options # Allow empty file.
-
- raise RDoc::Error, "#{options_file} is not a valid rdoc options file" unless
- RDoc::Options === options or Hash === options
-
- if Hash === options
- # Override the default values with the contents of YAML file.
- options = RDoc::Options.new options
- end
-
- options
- end
-
- ##
# Create an output dir if it doesn't exist. If it does exist, but doesn't
# contain the flag file <tt>created.rid</tt> then we refuse to use it, as
# we may clobber some manually generated documentation
@@ -471,7 +442,7 @@ The internal error was:
@options = options
@options.finish
else
- @options = load_options
+ @options = RDoc::Options.load_options
@options.parse options
end
diff --git a/lib/rdoc/ri/driver.rb b/lib/rdoc/ri/driver.rb
index a4b70b8..7549a39 100644
--- a/lib/rdoc/ri/driver.rb
+++ b/lib/rdoc/ri/driver.rb
@@ -142,6 +142,8 @@ Where name can be:
gem_name: | gem_name:README | gem_name:History
+ ruby: | ruby:NEWS | ruby:globals
+
All class names may be abbreviated to their minimum unambiguous form.
If a name is ambiguous, all valid options will be listed.
@@ -153,6 +155,10 @@ they're contained in. If the gem name is followed by a ':' all files in the
gem will be shown. The file name extension may be omitted where it is
unambiguous.
+'ruby' can be used as a pseudo gem name to display files from the Ruby
+core documentation. Use 'ruby:' by itself to get a list of all available
+core documentation files.
+
For example:
#{opt.program_name} Fil
@@ -160,6 +166,7 @@ For example:
#{opt.program_name} File.new
#{opt.program_name} zip
#{opt.program_name} rdoc:README
+ #{opt.program_name} ruby:comments
Note that shell quoting or escaping may be required for method names
containing punctuation:
@@ -609,11 +616,11 @@ or the PAGER environment variable.
stores = classes[current]
- break unless stores and not stores.empty?
+ next unless stores and not stores.empty?
- klasses = stores.map do |store|
- store.ancestors[current]
- end.flatten.uniq
+ klasses = stores.flat_map do |store|
+ store.ancestors[current] || []
+ end.uniq
klasses = klasses - seen
diff --git a/lib/rdoc/rubygems_hook.rb b/lib/rdoc/rubygems_hook.rb
index f4aa965..3781ff9 100644
--- a/lib/rdoc/rubygems_hook.rb
+++ b/lib/rdoc/rubygems_hook.rb
@@ -120,7 +120,9 @@ class RDoc::RubygemsHook
options.exclude ||= [] # TODO maybe move to RDoc::Options#finish
options.setup_generator generator
options.op_dir = destination
- options.finish
+ Dir.chdir @spec.full_gem_path do
+ options.finish
+ end
generator = options.generator.new @rdoc.store, options
diff --git a/lib/rdoc/text.rb b/lib/rdoc/text.rb
index c3218fd..0bc4aba 100644
--- a/lib/rdoc/text.rb
+++ b/lib/rdoc/text.rb
@@ -218,10 +218,10 @@ module RDoc::Text
when s.scan(/\.\.\.(\.?)/) then
html << s[1] << encoded[:ellipsis]
after_word = nil
- when s.scan(/\(c\)/) then
+ when s.scan(/\(c\)/i) then
html << encoded[:copyright]
after_word = nil
- when s.scan(/\(r\)/) then
+ when s.scan(/\(r\)/i) then
html << encoded[:trademark]
after_word = nil
when s.scan(/---/) then
@@ -237,10 +237,18 @@ module RDoc::Text
when s.scan(/``/) then # backtick double quote
html << encoded[:open_dquote]
after_word = nil
- when s.scan(/''/) then # tick double quote
+ when s.scan(/(?:&#39;|'){2}/) then # tick double quote
html << encoded[:close_dquote]
after_word = nil
- when s.scan(/'/) then # single quote
+ when s.scan(/`/) then # backtick
+ if insquotes or after_word
+ html << '`'
+ after_word = false
+ else
+ html << encoded[:open_squote]
+ insquotes = true
+ end
+ when s.scan(/&#39;|'/) then # single quote
if insquotes
html << encoded[:close_squote]
insquotes = false
diff --git a/lib/rdoc/version.rb b/lib/rdoc/version.rb
index f6e18f7..a3ef62d 100644
--- a/lib/rdoc/version.rb
+++ b/lib/rdoc/version.rb
@@ -3,6 +3,6 @@ module RDoc
##
# RDoc version you are using
- VERSION = '6.3.1'
+ VERSION = '6.3.2'
end
diff --git a/lib/readline.gemspec b/lib/readline.gemspec
index dddac02..69d7695 100644
--- a/lib/readline.gemspec
+++ b/lib/readline.gemspec
@@ -4,12 +4,12 @@ Gem::Specification.new do |spec|
spec.authors = ['aycabta']
spec.email = ['aycabta@gmail.com']
- spec.summary = %q{It's a loader for "readline".}
+ spec.summary = %q{Loader for "readline".}
spec.description = <<~EOD
- This is just a loader for "readline". If Ruby has "readline-ext" gem that
- is a native extension, this gem will load it first. If Ruby doesn't have
- the "readline-ext" gem this gem will load "reline" that is a compatible
- library with "readline-ext" gem and is implemented by pure Ruby.
+ This is just a loader for "readline". If Ruby has the "readline-ext" gem
+ that is a native extension, this gem will load it. If Ruby does not have
+ the "readline-ext" gem this gem will load "reline", a library that is
+ compatible with the "readline-ext" gem and implemented in pure Ruby.
EOD
spec.homepage = 'https://github.com/ruby/readline'
spec.license = 'Ruby'
@@ -19,17 +19,15 @@ Gem::Specification.new do |spec|
spec.post_install_message = <<~EOM
+---------------------------------------------------------------------------+
- | This is just a loader for "readline". If Ruby has "readline-ext" gem that |
- | is a native extension, this gem will load it first. If Ruby doesn't have |
- | the "readline-ext" gem this gem will load "reline" that is a compatible   |
- | library with "readline-ext" gem and is implemented by pure Ruby.          |
- |                                                                           |
+ | This is just a loader for "readline". If Ruby has the "readline-ext" gem |
+ | that is a native extension, this gem will load it. If Ruby does not have |
+ | the "readline-ext" gem this gem will load "reline", a library that is |
+ | compatible with the "readline-ext" gem and implemented in pure Ruby. |
+ | |
| If you intend to use GNU Readline by `require 'readline'`, please install |
- | "readline-ext" gem.                                                       |
+ | the "readline-ext" gem. |
+---------------------------------------------------------------------------+
EOM
spec.add_runtime_dependency 'reline'
- spec.add_development_dependency 'bundler'
- spec.add_development_dependency 'rake'
end
diff --git a/lib/reline.rb b/lib/reline.rb
index 6fc27ca..9746b35 100644
--- a/lib/reline.rb
+++ b/lib/reline.rb
@@ -7,14 +7,37 @@ require 'reline/key_actor'
require 'reline/key_stroke'
require 'reline/line_editor'
require 'reline/history'
+require 'reline/terminfo'
require 'rbconfig'
module Reline
FILENAME_COMPLETION_PROC = nil
USERNAME_COMPLETION_PROC = nil
- Key = Struct.new('Key', :char, :combined_char, :with_meta)
+ class ConfigEncodingConversionError < StandardError; end
+
+ Key = Struct.new('Key', :char, :combined_char, :with_meta) do
+ def match?(key)
+ if key.instance_of?(Reline::Key)
+ (key.char.nil? or char.nil? or char == key.char) and
+ (key.combined_char.nil? or combined_char.nil? or combined_char == key.combined_char) and
+ (key.with_meta.nil? or with_meta.nil? or with_meta == key.with_meta)
+ elsif key.is_a?(Integer) or key.is_a?(Symbol)
+ if not combined_char.nil? and combined_char == key
+ true
+ elsif combined_char.nil? and not char.nil? and char == key
+ true
+ else
+ false
+ end
+ else
+ false
+ end
+ end
+ alias_method :==, :match?
+ end
CursorPos = Struct.new(:x, :y)
+ DialogRenderInfo = Struct.new(:pos, :contents, :bg_color, :width, :height, :scrollbar, keyword_init: true)
class Core
ATTR_READER_NAMES = %i(
@@ -41,6 +64,7 @@ module Reline
def initialize
self.output = STDOUT
+ @dialog_proc_list = []
yield self
@completion_quote_character = nil
@bracketed_paste_finished = false
@@ -103,6 +127,14 @@ module Reline
@completion_proc = p
end
+ def autocompletion
+ @config.autocompletion
+ end
+
+ def autocompletion=(val)
+ @config.autocompletion = val
+ end
+
def output_modifier_proc=(p)
raise ArgumentError unless p.respond_to?(:call) or p.nil?
@output_modifier_proc = p
@@ -127,6 +159,12 @@ module Reline
@dig_perfect_match_proc = p
end
+ def add_dialog_proc(name_sym, p, context = nil)
+ raise ArgumentError unless p.respond_to?(:call) or p.nil?
+ raise ArgumentError unless name_sym.instance_of?(Symbol)
+ @dialog_proc_list << [name_sym, p, context]
+ end
+
def input=(val)
raise TypeError unless val.respond_to?(:getc) or val.nil?
if val.respond_to?(:getc)
@@ -168,6 +206,46 @@ module Reline
Reline::IOGate.get_screen_size
end
+ Reline::DEFAULT_DIALOG_PROC_AUTOCOMPLETE = ->() {
+ # autocomplete
+ return nil unless config.autocompletion
+ if just_cursor_moving and completion_journey_data.nil?
+ # Auto complete starts only when edited
+ return nil
+ end
+ pre, target, post = retrieve_completion_block(true)
+ if target.nil? or target.empty? or (completion_journey_data&.pointer == -1 and target.size <= 3)
+ return nil
+ end
+ if completion_journey_data and completion_journey_data.list
+ result = completion_journey_data.list.dup
+ result.shift
+ pointer = completion_journey_data.pointer - 1
+ else
+ result = call_completion_proc_with_checking_args(pre, target, post)
+ pointer = nil
+ end
+ if result and result.size == 1 and result[0] == target and pointer != 0
+ result = nil
+ end
+ target_width = Reline::Unicode.calculate_width(target)
+ x = cursor_pos.x - target_width
+ if x < 0
+ x = screen_width + x
+ y = -1
+ else
+ y = 0
+ end
+ cursor_pos_to_render = Reline::CursorPos.new(x, y)
+ if context and context.is_a?(Array)
+ context.clear
+ context.push(cursor_pos_to_render, result, pointer, dialog)
+ end
+ dialog.pointer = pointer
+ DialogRenderInfo.new(pos: cursor_pos_to_render, contents: result, scrollbar: true, height: 15)
+ }
+ Reline::DEFAULT_DIALOG_CONTEXT = Array.new
+
def readmultiline(prompt = '', add_hist = false, &confirm_multiline_termination)
unless confirm_multiline_termination
raise ArgumentError.new('#readmultiline needs block to confirm multiline termination')
@@ -227,6 +305,10 @@ module Reline
line_editor.auto_indent_proc = auto_indent_proc
line_editor.dig_perfect_match_proc = dig_perfect_match_proc
line_editor.pre_input_hook = pre_input_hook
+ @dialog_proc_list.each do |d|
+ name_sym, dialog_proc, context = d
+ line_editor.add_dialog_proc(name_sym, dialog_proc, context)
+ end
unless config.test_mode
config.read
@@ -271,11 +353,12 @@ module Reline
Reline::IOGate.deprep(otio)
end
- # Keystrokes of GNU Readline will timeout it with the specification of
- # "keyseq-timeout" when waiting for the 2nd character after the 1st one.
- # If the 2nd character comes after 1st ESC without timeout it has a
- # meta-property of meta-key to discriminate modified key with meta-key
- # from multibyte characters that come with 8th bit on.
+ # GNU Readline waits for "keyseq-timeout" milliseconds to see if the ESC
+ # is followed by a character, and times out and treats it as a standalone
+ # ESC if the second character does not arrive. If the second character
+ # comes before timed out, it is treated as a modifier key with the
+ # meta-property of meta-key, so that it can be distinguished from
+ # multibyte characters with the 8th bit turned on.
#
# GNU Readline will wait for the 2nd character with "keyseq-timeout"
# milli-seconds but wait forever after 3rd characters.
@@ -299,25 +382,9 @@ module Reline
break
when :matching
if buffer.size == 1
- begin
- succ_c = nil
- Timeout.timeout(keyseq_timeout / 1000.0) {
- succ_c = Reline::IOGate.getc
- }
- rescue Timeout::Error # cancel matching only when first byte
- block.([Reline::Key.new(c, c, false)])
- break
- else
- if key_stroke.match_status(buffer.dup.push(succ_c)) == :unmatched
- if c == "\e".ord
- block.([Reline::Key.new(succ_c, succ_c | 0b10000000, true)])
- else
- block.([Reline::Key.new(c, c, false), Reline::Key.new(succ_c, succ_c, false)])
- end
- break
- else
- Reline::IOGate.ungetc(succ_c)
- end
+ case read_2nd_character_of_key_sequence(keyseq_timeout, buffer, c, block)
+ when :break then break
+ when :next then next
end
end
when :unmatched
@@ -334,6 +401,38 @@ module Reline
end
end
+ private def read_2nd_character_of_key_sequence(keyseq_timeout, buffer, c, block)
+ begin
+ succ_c = nil
+ Timeout.timeout(keyseq_timeout / 1000.0) {
+ succ_c = Reline::IOGate.getc
+ }
+ rescue Timeout::Error # cancel matching only when first byte
+ block.([Reline::Key.new(c, c, false)])
+ return :break
+ else
+ case key_stroke.match_status(buffer.dup.push(succ_c))
+ when :unmatched
+ if c == "\e".ord
+ block.([Reline::Key.new(succ_c, succ_c | 0b10000000, true)])
+ else
+ block.([Reline::Key.new(c, c, false), Reline::Key.new(succ_c, succ_c, false)])
+ end
+ return :break
+ when :matching
+ Reline::IOGate.ungetc(succ_c)
+ return :next
+ when :matched
+ buffer << succ_c
+ expanded = key_stroke.expand(buffer).map{ |expanded_c|
+ Reline::Key.new(expanded_c, expanded_c, false)
+ }
+ block.(expanded)
+ return :break
+ end
+ end
+ end
+
private def read_escaped_key(keyseq_timeout, c, block)
begin
escaped_c = nil
@@ -385,7 +484,7 @@ module Reline
#--------------------------------------------------------
(Core::ATTR_READER_NAMES).each { |name|
- def_single_delegators :core, "#{name}", "#{name}="
+ def_single_delegators :core, :"#{name}", :"#{name}="
}
def_single_delegators :core, :input=, :output=
def_single_delegators :core, :vi_editing_mode, :emacs_editing_mode
@@ -420,6 +519,8 @@ module Reline
def_single_delegators :core, :ambiguous_width
def_single_delegators :core, :last_incremental_search
def_single_delegators :core, :last_incremental_search=
+ def_single_delegators :core, :add_dialog_proc
+ def_single_delegators :core, :autocompletion, :autocompletion=
def_single_delegators :core, :readmultiline
def_instance_delegators self, :readmultiline
@@ -441,6 +542,7 @@ module Reline
core.completer_quote_characters = '"\''
core.filename_quote_characters = ""
core.special_prefixes = ""
+ core.add_dialog_proc(:autocomplete, Reline::DEFAULT_DIALOG_PROC_AUTOCOMPLETE, Reline::DEFAULT_DIALOG_CONTEXT)
}
end
@@ -453,17 +555,25 @@ module Reline
end
end
+require 'reline/general_io'
if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
require 'reline/windows'
if Reline::Windows.msys_tty?
- require 'reline/ansi'
- Reline::IOGate = Reline::ANSI
+ Reline::IOGate = if ENV['TERM'] == 'dumb'
+ Reline::GeneralIO
+ else
+ require 'reline/ansi'
+ Reline::ANSI
+ end
else
Reline::IOGate = Reline::Windows
end
else
- require 'reline/ansi'
- Reline::IOGate = Reline::ANSI
+ Reline::IOGate = if $stdout.isatty
+ require 'reline/ansi'
+ Reline::ANSI
+ else
+ Reline::GeneralIO
+ end
end
Reline::HISTORY = Reline::History.new(Reline.core.config)
-require 'reline/general_io'
diff --git a/lib/reline/ansi.rb b/lib/reline/ansi.rb
index f8e82c1..f34d0b5 100644
--- a/lib/reline/ansi.rb
+++ b/lib/reline/ansi.rb
@@ -1,7 +1,13 @@
require 'io/console'
+require 'io/wait'
require 'timeout'
+require_relative 'terminfo'
class Reline::ANSI
+ if Reline::Terminfo.enabled?
+ Reline::Terminfo.setupterm(0, 2)
+ end
+
def self.encoding
Encoding.default_external
end
@@ -11,6 +17,54 @@ class Reline::ANSI
end
def self.set_default_key_bindings(config)
+ if Reline::Terminfo.enabled?
+ set_default_key_bindings_terminfo(config)
+ else
+ set_default_key_bindings_comprehensive_list(config)
+ end
+ {
+ # extended entries of terminfo
+ [27, 91, 49, 59, 53, 67] => :em_next_word, # Ctrl+→, extended entry
+ [27, 91, 49, 59, 53, 68] => :ed_prev_word, # Ctrl+←, extended entry
+ [27, 91, 49, 59, 51, 67] => :em_next_word, # Meta+→, extended entry
+ [27, 91, 49, 59, 51, 68] => :ed_prev_word, # Meta+←, extended entry
+ }.each_pair do |key, func|
+ config.add_default_key_binding_by_keymap(:emacs, key, func)
+ config.add_default_key_binding_by_keymap(:vi_insert, key, func)
+ config.add_default_key_binding_by_keymap(:vi_command, key, func)
+ end
+ {
+ # default bindings
+ [27, 32] => :em_set_mark, # M-<space>
+ [24, 24] => :em_exchange_mark, # C-x C-x
+ [27, 91, 90] => :completion_journey_up, # S-Tab
+ }.each_pair do |key, func|
+ config.add_default_key_binding_by_keymap(:emacs, key, func)
+ end
+ end
+
+ def self.set_default_key_bindings_terminfo(config)
+ {
+ Reline::Terminfo.tigetstr('khome').bytes => :ed_move_to_beg,
+ Reline::Terminfo.tigetstr('kend').bytes => :ed_move_to_end,
+ Reline::Terminfo.tigetstr('kcuu1').bytes => :ed_prev_history,
+ Reline::Terminfo.tigetstr('kcud1').bytes => :ed_next_history,
+ Reline::Terminfo.tigetstr('kcuf1').bytes => :ed_next_char,
+ Reline::Terminfo.tigetstr('kcub1').bytes => :ed_prev_char,
+ # Escape sequences that omit the move distance and are set to defaults
+ # value 1 may be sometimes sent by pressing the arrow-key.
+ Reline::Terminfo.tigetstr('cuu').sub(/%p1%d/, '').bytes => :ed_prev_history,
+ Reline::Terminfo.tigetstr('cud').sub(/%p1%d/, '').bytes => :ed_next_history,
+ Reline::Terminfo.tigetstr('cuf').sub(/%p1%d/, '').bytes => :ed_next_char,
+ Reline::Terminfo.tigetstr('cub').sub(/%p1%d/, '').bytes => :ed_prev_char,
+ }.each_pair do |key, func|
+ config.add_default_key_binding_by_keymap(:emacs, key, func)
+ config.add_default_key_binding_by_keymap(:vi_insert, key, func)
+ config.add_default_key_binding_by_keymap(:vi_command, key, func)
+ end
+ end
+
+ def self.set_default_key_bindings_comprehensive_list(config)
{
# Console (80x25)
[27, 91, 49, 126] => :ed_move_to_beg, # Home
@@ -41,15 +95,11 @@ class Reline::ANSI
# Arrow keys are the same of KDE
# iTerm2
- [27, 27, 91, 67] => :em_next_word, # Option+→
- [27, 27, 91, 68] => :ed_prev_word, # Option+←
+ [27, 27, 91, 67] => :em_next_word, # Option+→, extended entry
+ [27, 27, 91, 68] => :ed_prev_word, # Option+←, extended entry
[195, 166] => :em_next_word, # Option+f
[195, 162] => :ed_prev_word, # Option+b
- # others
- [27, 91, 49, 59, 53, 67] => :em_next_word, # Ctrl+→
- [27, 91, 49, 59, 53, 68] => :ed_prev_word, # Ctrl+←
-
[27, 79, 65] => :ed_prev_history, # ↑
[27, 79, 66] => :ed_next_history, # ↓
[27, 79, 67] => :ed_next_char, # →
@@ -59,14 +109,6 @@ class Reline::ANSI
config.add_default_key_binding_by_keymap(:vi_insert, key, func)
config.add_default_key_binding_by_keymap(:vi_command, key, func)
end
-
- {
- # others
- [27, 32] => :em_set_mark, # M-<space>
- [24, 24] => :em_exchange_mark, # C-x C-x TODO also add Windows
- }.each_pair do |key, func|
- config.add_default_key_binding_by_keymap(:emacs, key, func)
- end
end
@@input = STDIN
@@ -91,6 +133,8 @@ class Reline::ANSI
rescue Errno::EIO
# Maybe the I/O has been closed.
nil
+ rescue Errno::ENOTTY
+ nil
end
@@in_bracketed_paste_mode = false
@@ -141,12 +185,7 @@ class Reline::ANSI
unless @@buf.empty?
return false
end
- rs, = IO.select([@@input], [], [], 0.00001)
- if rs and rs[0]
- false
- else
- true
- end
+ !@@input.wait_readable(0)
end
def self.ungetc(c)
@@ -155,8 +194,7 @@ class Reline::ANSI
def self.retrieve_keybuffer
begin
- result = select([@@input], [], [], 0.001)
- return if result.nil?
+ return unless @@input.wait_readable(0.001)
str = @@input.read_nonblock(1024)
str.bytes.each do |c|
@@buf.push(c)
@@ -237,6 +275,22 @@ class Reline::ANSI
end
end
+ def self.hide_cursor
+ if Reline::Terminfo.enabled?
+ @@output.write Reline::Terminfo.tigetstr('civis')
+ else
+ # ignored
+ end
+ end
+
+ def self.show_cursor
+ if Reline::Terminfo.enabled?
+ @@output.write Reline::Terminfo.tigetstr('cnorm')
+ else
+ # ignored
+ end
+ end
+
def self.erase_after_cursor
@@output.write "\e[K"
end
@@ -258,8 +312,6 @@ class Reline::ANSI
def self.prep
retrieve_keybuffer
- int_handle = Signal.trap('INT', 'IGNORE')
- Signal.trap('INT', int_handle)
nil
end
diff --git a/lib/reline/config.rb b/lib/reline/config.rb
index 9689c8f..4b2655d 100644
--- a/lib/reline/config.rb
+++ b/lib/reline/config.rb
@@ -50,6 +50,7 @@ class Reline::Config
@additional_key_bindings[:emacs] = {}
@additional_key_bindings[:vi_insert] = {}
@additional_key_bindings[:vi_command] = {}
+ @oneshot_key_bindings = {}
@skip_section = nil
@if_stack = nil
@editing_mode_label = :emacs
@@ -65,6 +66,7 @@ class Reline::Config
@history_size = -1 # unlimited
@keyseq_timeout = 500
@test_mode = false
+ @autocompletion = false
end
def reset
@@ -74,6 +76,7 @@ class Reline::Config
@additional_key_bindings.keys.each do |key|
@additional_key_bindings[key].clear
end
+ @oneshot_key_bindings.clear
reset_default_key_bindings
end
@@ -89,6 +92,14 @@ class Reline::Config
(val.respond_to?(:any?) ? val : [val]).any?(@editing_mode_label)
end
+ def autocompletion=(val)
+ @autocompletion = val
+ end
+
+ def autocompletion
+ @autocompletion
+ end
+
def keymap
@key_actors[@keymap_label]
end
@@ -119,8 +130,12 @@ class Reline::Config
return home_rc_path
end
+ private def default_inputrc_path
+ @default_inputrc_path ||= inputrc_path
+ end
+
def read(file = nil)
- file ||= inputrc_path
+ file ||= default_inputrc_path
begin
if file.respond_to?(:readlines)
lines = file.readlines
@@ -139,8 +154,19 @@ class Reline::Config
end
def key_bindings
- # override @key_actors[@editing_mode_label].default_key_bindings with @additional_key_bindings[@editing_mode_label]
- @key_actors[@editing_mode_label].default_key_bindings.merge(@additional_key_bindings[@editing_mode_label])
+ # The key bindings for each editing mode will be overwritten by the user-defined ones.
+ kb = @key_actors[@editing_mode_label].default_key_bindings.dup
+ kb.merge!(@additional_key_bindings[@editing_mode_label])
+ kb.merge!(@oneshot_key_bindings)
+ kb
+ end
+
+ def add_oneshot_key_binding(keystroke, target)
+ @oneshot_key_bindings[keystroke] = target
+ end
+
+ def reset_oneshot_key_bindings
+ @oneshot_key_bindings.clear
end
def add_default_key_binding_by_keymap(keymap, keystroke, target)
@@ -158,6 +184,16 @@ class Reline::Config
end
def read_lines(lines, file = nil)
+ if not lines.empty? and lines.first.encoding != Reline.encoding_system_needs
+ begin
+ lines = lines.map do |l|
+ l.encode(Reline.encoding_system_needs)
+ rescue Encoding::UndefinedConversionError
+ mes = "The inputrc encoded in #{lines.first.encoding.name} can't be converted to the locale #{Reline.encoding_system_needs.name}."
+ raise Reline::ConfigEncodingConversionError.new(mes)
+ end
+ end
+ end
conditions = [@skip_section, @if_stack]
@skip_section = nil
@if_stack = []
@@ -292,11 +328,8 @@ class Reline::Config
end
def retrieve_string(str)
- if str =~ /\A"(.*)"\z/
- parse_keyseq($1).map(&:chr).join
- else
- parse_keyseq(str).map(&:chr).join
- end
+ str = $1 if str =~ /\A"(.*)"\z/
+ parse_keyseq(str).map { |c| c.chr(Reline.encoding_system_needs) }.join
end
def bind_key(key, func_name)
diff --git a/lib/reline/general_io.rb b/lib/reline/general_io.rb
index 8c8e22d..5df3468 100644
--- a/lib/reline/general_io.rb
+++ b/lib/reline/general_io.rb
@@ -1,12 +1,19 @@
require 'timeout'
class Reline::GeneralIO
- def self.reset
+ def self.reset(encoding: nil)
@@pasting = false
+ @@encoding = encoding
end
def self.encoding
- RUBY_PLATFORM =~ /mswin|mingw/ ? Encoding::UTF_8 : Encoding::default_external
+ if defined?(@@encoding)
+ @@encoding
+ elsif RUBY_PLATFORM =~ /mswin|mingw/
+ Encoding::UTF_8
+ else
+ Encoding::default_external
+ end
end
def self.win?
@@ -17,6 +24,7 @@ class Reline::GeneralIO
end
@@buf = []
+ @@input = STDIN
def self.input=(val)
@@input = val
diff --git a/lib/reline/key_stroke.rb b/lib/reline/key_stroke.rb
index 017e3db..16e5f69 100644
--- a/lib/reline/key_stroke.rb
+++ b/lib/reline/key_stroke.rb
@@ -1,38 +1,87 @@
class Reline::KeyStroke
- using Module.new {
- refine Array do
- def start_with?(other)
- other.size <= size && other == self.take(other.size)
+ def initialize(config)
+ @config = config
+ end
+
+ def compress_meta_key(ary)
+ ary.inject([]) { |result, key|
+ if result.size > 0 and result.last == "\e".ord
+ result[result.size - 1] = Reline::Key.new(key, key | 0b10000000, true)
+ else
+ result << key
end
+ result
+ }
+ end
- def bytes
- self
+ def start_with?(me, other)
+ compressed_me = compress_meta_key(me)
+ compressed_other = compress_meta_key(other)
+ i = 0
+ loop do
+ my_c = compressed_me[i]
+ other_c = compressed_other[i]
+ other_is_last = (i + 1) == compressed_other.size
+ me_is_last = (i + 1) == compressed_me.size
+ if my_c != other_c
+ if other_c == "\e".ord and other_is_last and my_c.is_a?(Reline::Key) and my_c.with_meta
+ return true
+ else
+ return false
+ end
+ elsif other_is_last
+ return true
+ elsif me_is_last
+ return false
end
+ i += 1
end
- }
+ end
- def initialize(config)
- @config = config
+ def equal?(me, other)
+ case me
+ when Array
+ compressed_me = compress_meta_key(me)
+ compressed_other = compress_meta_key(other)
+ compressed_me.size == compressed_other.size and [compressed_me, compressed_other].transpose.all?{ |i| equal?(i[0], i[1]) }
+ when Integer
+ if other.is_a?(Reline::Key)
+ if other.combined_char == "\e".ord
+ false
+ else
+ other.combined_char == me
+ end
+ else
+ me == other
+ end
+ when Reline::Key
+ if other.is_a?(Integer)
+ me.combined_char == other
+ else
+ me == other
+ end
+ end
end
def match_status(input)
key_mapping.keys.select { |lhs|
- lhs.start_with? input
+ start_with?(lhs, input)
}.tap { |it|
- return :matched if it.size == 1 && (it.max_by(&:size)&.size&.== input.size)
- return :matching if it.size == 1 && (it.max_by(&:size)&.size&.!= input.size)
+ return :matched if it.size == 1 && equal?(it[0], input)
+ return :matching if it.size == 1 && !equal?(it[0], input)
return :matched if it.max_by(&:size)&.size&.< input.size
return :matching if it.size > 1
}
key_mapping.keys.select { |lhs|
- input.start_with? lhs
+ start_with?(input, lhs)
}.tap { |it|
return it.size > 0 ? :matched : :unmatched
}
end
def expand(input)
- lhs = key_mapping.keys.select { |item| input.start_with? item }.sort_by(&:size).reverse.first
+ input = compress_meta_key(input)
+ lhs = key_mapping.keys.select { |item| start_with?(input, item) }.sort_by(&:size).last
return input unless lhs
rhs = key_mapping[lhs]
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 7d71e62..c7d6ff4 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -150,7 +150,8 @@ class Reline::LineEditor
@screen_size = Reline::IOGate.get_screen_size
@screen_height = @screen_size.first
reset_variables(prompt, encoding: encoding)
- @old_trap = Signal.trap('SIGINT') {
+ @old_trap = Signal.trap('INT') {
+ clear_dialog
if @scroll_partial_screen
move_cursor_down(@screen_height - (@line_index - @scroll_partial_screen) - 1)
else
@@ -158,9 +159,24 @@ class Reline::LineEditor
end
Reline::IOGate.move_cursor_column(0)
scroll_down(1)
- @old_trap.call if @old_trap.respond_to?(:call) # can also be string, ex: "DEFAULT"
- raise Interrupt
+ case @old_trap
+ when 'DEFAULT', 'SYSTEM_DEFAULT'
+ raise Interrupt
+ when 'IGNORE'
+ # Do nothing
+ when 'EXIT'
+ exit
+ else
+ @old_trap.call
+ end
}
+ begin
+ @old_tstp_trap = Signal.trap('TSTP') {
+ Reline::IOGate.ungetc("\C-z".ord)
+ @old_tstp_trap.call if @old_tstp_trap.respond_to?(:call)
+ }
+ rescue ArgumentError
+ end
Reline::IOGate.set_winch_handler do
@rest_height = (Reline::IOGate.get_screen_size.first - 1) - Reline::IOGate.cursor_pos.y
old_screen_size = @screen_size
@@ -198,10 +214,15 @@ class Reline::LineEditor
@rerender_all = true
end
end
+ @block_elem_width = Reline::Unicode.calculate_width('█')
end
def finalize
- Signal.trap('SIGINT', @old_trap)
+ Signal.trap('INT', @old_trap)
+ begin
+ Signal.trap('TSTP', @old_tstp_trap)
+ rescue ArgumentError
+ end
end
def eof?
@@ -241,6 +262,8 @@ class Reline::LineEditor
@drop_terminate_spaces = false
@in_pasting = false
@auto_indent_proc = nil
+ @dialogs = []
+ @last_key = nil
reset_line
end
@@ -406,10 +429,10 @@ class Reline::LineEditor
Reline::IOGate.erase_after_cursor
end
@output.flush
+ clear_dialog
return
end
new_highest_in_this = calculate_height_by_width(prompt_width + calculate_width(@line.nil? ? '' : @line))
- # FIXME: end of logical line sometimes breaks
rendered = false
if @add_newline_to_end_of_buffer
rerender_added_newline(prompt, prompt_width)
@@ -417,6 +440,7 @@ class Reline::LineEditor
else
if @just_cursor_moving and not @rerender_all
rendered = just_move_cursor
+ render_dialog((prompt_width + @cursor) % @screen_size.last)
@just_cursor_moving = false
return
elsif @previous_line_index or new_highest_in_this != @highest_in_this
@@ -439,18 +463,20 @@ class Reline::LineEditor
new_lines = whole_lines
end
line = modify_lines(new_lines)[@line_index]
+ clear_dialog
prompt, prompt_width, prompt_list = check_multiline_prompt(new_lines, prompt)
render_partial(prompt, prompt_width, line, @first_line_started_from)
move_cursor_down(@highest_in_all - (@first_line_started_from + @highest_in_this - 1) - 1)
scroll_down(1)
Reline::IOGate.move_cursor_column(0)
Reline::IOGate.erase_after_cursor
- elsif not rendered
- unless @in_pasting
+ else
+ if not rendered and not @in_pasting
line = modify_lines(whole_lines)[@line_index]
prompt, prompt_width, prompt_list = check_multiline_prompt(whole_lines, prompt)
render_partial(prompt, prompt_width, line, @first_line_started_from)
end
+ render_dialog((prompt_width + @cursor) % @screen_size.last)
end
@buffer_of_lines[@line_index] = @line
@rest_height = 0 if @scroll_partial_screen
@@ -465,6 +491,392 @@ class Reline::LineEditor
end
end
+ class DialogProcScope
+ def initialize(line_editor, config, proc_to_exec, context)
+ @line_editor = line_editor
+ @config = config
+ @proc_to_exec = proc_to_exec
+ @context = context
+ @cursor_pos = Reline::CursorPos.new
+ end
+
+ def context
+ @context
+ end
+
+ def retrieve_completion_block(set_completion_quote_character = false)
+ @line_editor.retrieve_completion_block(set_completion_quote_character)
+ end
+
+ def call_completion_proc_with_checking_args(pre, target, post)
+ @line_editor.call_completion_proc_with_checking_args(pre, target, post)
+ end
+
+ def set_dialog(dialog)
+ @dialog = dialog
+ end
+
+ def dialog
+ @dialog
+ end
+
+ def set_cursor_pos(col, row)
+ @cursor_pos.x = col
+ @cursor_pos.y = row
+ end
+
+ def set_key(key)
+ @key = key
+ end
+
+ def key
+ @key
+ end
+
+ def cursor_pos
+ @cursor_pos
+ end
+
+ def just_cursor_moving
+ @line_editor.instance_variable_get(:@just_cursor_moving)
+ end
+
+ def screen_width
+ @line_editor.instance_variable_get(:@screen_size).last
+ end
+
+ def completion_journey_data
+ @line_editor.instance_variable_get(:@completion_journey_data)
+ end
+
+ def config
+ @config
+ end
+
+ def call
+ instance_exec(&@proc_to_exec)
+ end
+ end
+
+ class Dialog
+ attr_reader :name, :contents, :width
+ attr_accessor :scroll_top, :scrollbar_pos, :pointer, :column, :vertical_offset, :lines_backup, :trap_key
+
+ def initialize(name, config, proc_scope)
+ @name = name
+ @config = config
+ @proc_scope = proc_scope
+ @width = nil
+ @scroll_top = 0
+ end
+
+ def set_cursor_pos(col, row)
+ @proc_scope.set_cursor_pos(col, row)
+ end
+
+ def width=(v)
+ @width = v
+ end
+
+ def contents=(contents)
+ @contents = contents
+ if contents and @width.nil?
+ @width = contents.map{ |line| Reline::Unicode.calculate_width(line, true) }.max
+ end
+ end
+
+ def call(key)
+ @proc_scope.set_dialog(self)
+ @proc_scope.set_key(key)
+ dialog_render_info = @proc_scope.call
+ if @trap_key
+ if @trap_key.any?{ |i| i.is_a?(Array) } # multiple trap
+ @trap_key.each do |t|
+ @config.add_oneshot_key_binding(t, @name)
+ end
+ elsif @trap_key.is_a?(Array)
+ @config.add_oneshot_key_binding(@trap_key, @name)
+ elsif @trap_key.is_a?(Integer) or @trap_key.is_a?(Reline::Key)
+ @config.add_oneshot_key_binding([@trap_key], @name)
+ end
+ end
+ dialog_render_info
+ end
+ end
+
+ def add_dialog_proc(name, p, context = nil)
+ return if @dialogs.any? { |d| d.name == name }
+ @dialogs << Dialog.new(name, @config, DialogProcScope.new(self, @config, p, context))
+ end
+
+ DIALOG_HEIGHT = 20
+ private def render_dialog(cursor_column)
+ @dialogs.each do |dialog|
+ render_each_dialog(dialog, cursor_column)
+ end
+ end
+
+ private def padding_space_with_escape_sequences(str, width)
+ str + (' ' * (width - calculate_width(str, true)))
+ end
+
+ private def render_each_dialog(dialog, cursor_column)
+ if @in_pasting
+ dialog.contents = nil
+ dialog.trap_key = nil
+ return
+ end
+ dialog.set_cursor_pos(cursor_column, @first_line_started_from + @started_from)
+ dialog_render_info = dialog.call(@last_key)
+ if dialog_render_info.nil? or dialog_render_info.contents.nil? or dialog_render_info.contents.empty?
+ dialog.lines_backup = {
+ lines: modify_lines(whole_lines),
+ line_index: @line_index,
+ first_line_started_from: @first_line_started_from,
+ started_from: @started_from,
+ byte_pointer: @byte_pointer
+ }
+ clear_each_dialog(dialog)
+ dialog.contents = nil
+ dialog.trap_key = nil
+ return
+ end
+ old_dialog = dialog.clone
+ dialog.contents = dialog_render_info.contents
+ pointer = dialog.pointer
+ if dialog_render_info.width
+ dialog.width = dialog_render_info.width
+ else
+ dialog.width = dialog.contents.map { |l| calculate_width(l, true) }.max
+ end
+ height = dialog_render_info.height || DIALOG_HEIGHT
+ height = dialog.contents.size if dialog.contents.size < height
+ if dialog.contents.size > height
+ if dialog.pointer
+ if dialog.pointer < 0
+ dialog.scroll_top = 0
+ elsif (dialog.pointer - dialog.scroll_top) >= (height - 1)
+ dialog.scroll_top = dialog.pointer - (height - 1)
+ elsif (dialog.pointer - dialog.scroll_top) < 0
+ dialog.scroll_top = dialog.pointer
+ end
+ pointer = dialog.pointer - dialog.scroll_top
+ end
+ dialog.contents = dialog.contents[dialog.scroll_top, height]
+ end
+ if dialog_render_info.scrollbar and dialog_render_info.contents.size > height
+ bar_max_height = height * 2
+ moving_distance = (dialog_render_info.contents.size - height) * 2
+ position_ratio = dialog.scroll_top.zero? ? 0.0 : ((dialog.scroll_top * 2).to_f / moving_distance)
+ bar_height = (bar_max_height * ((dialog.contents.size * 2).to_f / (dialog_render_info.contents.size * 2))).floor.to_i
+ dialog.scrollbar_pos = ((bar_max_height - bar_height) * position_ratio).floor.to_i
+ else
+ dialog.scrollbar_pos = nil
+ end
+ upper_space = @first_line_started_from - @started_from
+ lower_space = @highest_in_all - @first_line_started_from - @started_from - 1
+ dialog.column = dialog_render_info.pos.x
+ diff = (dialog.column + dialog.width) - (@screen_size.last - 1)
+ if diff > 0
+ dialog.column -= diff
+ end
+ if (lower_space + @rest_height - dialog_render_info.pos.y) >= height
+ dialog.vertical_offset = dialog_render_info.pos.y + 1
+ elsif upper_space >= height
+ dialog.vertical_offset = dialog_render_info.pos.y - height
+ else
+ if (lower_space + @rest_height - dialog_render_info.pos.y) < height
+ scroll_down(height + dialog_render_info.pos.y)
+ move_cursor_up(height + dialog_render_info.pos.y)
+ end
+ dialog.vertical_offset = dialog_render_info.pos.y + 1
+ end
+ Reline::IOGate.hide_cursor
+ dialog.width += @block_elem_width if dialog.scrollbar_pos
+ reset_dialog(dialog, old_dialog)
+ move_cursor_down(dialog.vertical_offset)
+ Reline::IOGate.move_cursor_column(dialog.column)
+ dialog.contents.each_with_index do |item, i|
+ if i == pointer
+ bg_color = '45'
+ else
+ if dialog_render_info.bg_color
+ bg_color = dialog_render_info.bg_color
+ else
+ bg_color = '46'
+ end
+ end
+ str_width = dialog.width - (dialog.scrollbar_pos.nil? ? 0 : @block_elem_width)
+ str = padding_space_with_escape_sequences(Reline::Unicode.take_range(item, 0, str_width), str_width)
+ @output.write "\e[#{bg_color}m#{str}"
+ if dialog.scrollbar_pos and (dialog.scrollbar_pos != old_dialog.scrollbar_pos or dialog.column != old_dialog.column)
+ @output.write "\e[37m"
+ if dialog.scrollbar_pos <= (i * 2) and (i * 2 + @block_elem_width) < (dialog.scrollbar_pos + bar_height)
+ @output.write '█'
+ elsif dialog.scrollbar_pos <= (i * 2) and (i * 2) < (dialog.scrollbar_pos + bar_height)
+ @output.write '▀'
+ str += ''
+ elsif dialog.scrollbar_pos <= (i * 2 + @block_elem_width) and (i * 2) < (dialog.scrollbar_pos + bar_height)
+ @output.write '▄'
+ else
+ @output.write ' ' * @block_elem_width
+ end
+ end
+ @output.write "\e[0m"
+ Reline::IOGate.move_cursor_column(dialog.column)
+ move_cursor_down(1) if i < (dialog.contents.size - 1)
+ end
+ Reline::IOGate.move_cursor_column(cursor_column)
+ move_cursor_up(dialog.vertical_offset + dialog.contents.size - 1)
+ Reline::IOGate.show_cursor
+ dialog.lines_backup = {
+ lines: modify_lines(whole_lines),
+ line_index: @line_index,
+ first_line_started_from: @first_line_started_from,
+ started_from: @started_from,
+ byte_pointer: @byte_pointer
+ }
+ end
+
+ private def reset_dialog(dialog, old_dialog)
+ return if dialog.lines_backup.nil? or old_dialog.contents.nil?
+ prompt, prompt_width, prompt_list = check_multiline_prompt(dialog.lines_backup[:lines], prompt)
+ visual_lines = []
+ visual_start = nil
+ dialog.lines_backup[:lines].each_with_index { |l, i|
+ pr = prompt_list ? prompt_list[i] : prompt
+ vl, _ = split_by_width(pr + l, @screen_size.last)
+ vl.compact!
+ if i == dialog.lines_backup[:line_index]
+ visual_start = visual_lines.size + dialog.lines_backup[:started_from]
+ end
+ visual_lines.concat(vl)
+ }
+ old_y = dialog.lines_backup[:first_line_started_from] + dialog.lines_backup[:started_from]
+ y = @first_line_started_from + @started_from
+ y_diff = y - old_y
+ if (old_y + old_dialog.vertical_offset) < (y + dialog.vertical_offset)
+ # rerender top
+ move_cursor_down(old_dialog.vertical_offset - y_diff)
+ start = visual_start + old_dialog.vertical_offset
+ line_num = dialog.vertical_offset - old_dialog.vertical_offset
+ line_num.times do |i|
+ Reline::IOGate.move_cursor_column(old_dialog.column)
+ if visual_lines[start + i].nil?
+ s = ' ' * old_dialog.width
+ else
+ s = Reline::Unicode.take_range(visual_lines[start + i], old_dialog.column, old_dialog.width)
+ s = padding_space_with_escape_sequences(s, old_dialog.width)
+ end
+ @output.write "\e[0m#{s}\e[0m"
+ move_cursor_down(1) if i < (line_num - 1)
+ end
+ move_cursor_up(old_dialog.vertical_offset + line_num - 1 - y_diff)
+ end
+ if (old_y + old_dialog.vertical_offset + old_dialog.contents.size) > (y + dialog.vertical_offset + dialog.contents.size)
+ # rerender bottom
+ move_cursor_down(dialog.vertical_offset + dialog.contents.size - y_diff)
+ start = visual_start + dialog.vertical_offset + dialog.contents.size
+ line_num = (old_dialog.vertical_offset + old_dialog.contents.size) - (dialog.vertical_offset + dialog.contents.size)
+ line_num.times do |i|
+ Reline::IOGate.move_cursor_column(old_dialog.column)
+ if visual_lines[start + i].nil?
+ s = ' ' * old_dialog.width
+ else
+ s = Reline::Unicode.take_range(visual_lines[start + i], old_dialog.column, old_dialog.width)
+ s = padding_space_with_escape_sequences(s, old_dialog.width)
+ end
+ @output.write "\e[0m#{s}\e[0m"
+ move_cursor_down(1) if i < (line_num - 1)
+ end
+ move_cursor_up(dialog.vertical_offset + dialog.contents.size + line_num - 1 - y_diff)
+ end
+ if old_dialog.column < dialog.column
+ # rerender left
+ move_cursor_down(old_dialog.vertical_offset - y_diff)
+ width = dialog.column - old_dialog.column
+ start = visual_start + old_dialog.vertical_offset
+ line_num = old_dialog.contents.size
+ line_num.times do |i|
+ Reline::IOGate.move_cursor_column(old_dialog.column)
+ if visual_lines[start + i].nil?
+ s = ' ' * width
+ else
+ s = Reline::Unicode.take_range(visual_lines[start + i], old_dialog.column, width)
+ s = padding_space_with_escape_sequences(s, dialog.width)
+ end
+ @output.write "\e[0m#{s}\e[0m"
+ move_cursor_down(1) if i < (line_num - 1)
+ end
+ move_cursor_up(old_dialog.vertical_offset + line_num - 1 - y_diff)
+ end
+ if (old_dialog.column + old_dialog.width) > (dialog.column + dialog.width)
+ # rerender right
+ move_cursor_down(old_dialog.vertical_offset + y_diff)
+ width = (old_dialog.column + old_dialog.width) - (dialog.column + dialog.width)
+ start = visual_start + old_dialog.vertical_offset
+ line_num = old_dialog.contents.size
+ line_num.times do |i|
+ Reline::IOGate.move_cursor_column(old_dialog.column + dialog.width)
+ if visual_lines[start + i].nil?
+ s = ' ' * width
+ else
+ s = Reline::Unicode.take_range(visual_lines[start + i], old_dialog.column + dialog.width, width)
+ s = padding_space_with_escape_sequences(s, dialog.width)
+ end
+ Reline::IOGate.move_cursor_column(dialog.column + dialog.width)
+ @output.write "\e[0m#{s}\e[0m"
+ move_cursor_down(1) if i < (line_num - 1)
+ end
+ move_cursor_up(old_dialog.vertical_offset + line_num - 1 + y_diff)
+ end
+ Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last)
+ end
+
+ private def clear_dialog
+ @dialogs.each do |dialog|
+ clear_each_dialog(dialog)
+ end
+ end
+
+ private def clear_each_dialog(dialog)
+ dialog.trap_key = nil
+ return unless dialog.contents
+ prompt, prompt_width, prompt_list = check_multiline_prompt(dialog.lines_backup[:lines], prompt)
+ visual_lines = []
+ visual_lines_under_dialog = []
+ visual_start = nil
+ dialog.lines_backup[:lines].each_with_index { |l, i|
+ pr = prompt_list ? prompt_list[i] : prompt
+ vl, _ = split_by_width(pr + l, @screen_size.last)
+ vl.compact!
+ if i == dialog.lines_backup[:line_index]
+ visual_start = visual_lines.size + dialog.lines_backup[:started_from] + dialog.vertical_offset
+ end
+ visual_lines.concat(vl)
+ }
+ visual_lines_under_dialog = visual_lines[visual_start, dialog.contents.size]
+ visual_lines_under_dialog = [] if visual_lines_under_dialog.nil?
+ Reline::IOGate.hide_cursor
+ move_cursor_down(dialog.vertical_offset)
+ dialog_vertical_size = dialog.contents.size
+ dialog_vertical_size.times do |i|
+ if i < visual_lines_under_dialog.size
+ Reline::IOGate.move_cursor_column(dialog.column)
+ str = Reline::Unicode.take_range(visual_lines_under_dialog[i], dialog.column, dialog.width)
+ str = padding_space_with_escape_sequences(str, dialog.width)
+ @output.write "\e[0m#{str}\e[0m"
+ else
+ Reline::IOGate.move_cursor_column(dialog.column)
+ @output.write "\e[0m#{' ' * dialog.width}\e[0m"
+ end
+ move_cursor_down(1) if i < (dialog_vertical_size - 1)
+ end
+ move_cursor_up(dialog_vertical_size - 1 + dialog.vertical_offset)
+ Reline::IOGate.move_cursor_column((prompt_width + @cursor) % @screen_size.last)
+ Reline::IOGate.show_cursor
+ end
+
private def calculate_scroll_partial_screen(highest_in_all, cursor_y)
if @screen_height < highest_in_all
old_scroll_partial_screen = @scroll_partial_screen
@@ -678,7 +1090,6 @@ class Reline::LineEditor
private def render_partial(prompt, prompt_width, line_to_render, this_started_from, with_control: true)
visual_lines, height = split_by_width(line_to_render.nil? ? prompt : prompt + line_to_render, @screen_size.last)
cursor_up_from_last_line = 0
- # TODO: This logic would be sometimes buggy if this logical line isn't the current @line_index.
if @scroll_partial_screen
last_visual_line = this_started_from + (height - 1)
last_screen_line = @scroll_partial_screen + (@screen_height - 1)
@@ -807,7 +1218,7 @@ class Reline::LineEditor
height = render_partial(prompt, prompt_width, line, back, with_control: false)
end
if index < (@buffer_of_lines.size - 1)
- move_cursor_down(height)
+ move_cursor_down(1)
back += height
end
end
@@ -926,6 +1337,16 @@ class Reline::LineEditor
@completion_journey_data = CompletionJourneyData.new(
preposing, postposing,
[target] + list.select{ |item| item.start_with?(target) }, 0)
+ if @completion_journey_data.list.size == 1
+ @completion_journey_data.pointer = 0
+ else
+ case direction
+ when :up
+ @completion_journey_data.pointer = @completion_journey_data.list.size - 1
+ when :down
+ @completion_journey_data.pointer = 1
+ end
+ end
@completion_state = CompletionState::JOURNEY
else
case direction
@@ -940,13 +1361,15 @@ class Reline::LineEditor
@completion_journey_data.pointer = 0
end
end
- completed = @completion_journey_data.list[@completion_journey_data.pointer]
- @line = @completion_journey_data.preposing + completed + @completion_journey_data.postposing
- line_to_pointer = @completion_journey_data.preposing + completed
- @cursor_max = calculate_width(@line)
- @cursor = calculate_width(line_to_pointer)
- @byte_pointer = line_to_pointer.bytesize
end
+ completed = @completion_journey_data.list[@completion_journey_data.pointer]
+ new_line = (@completion_journey_data.preposing + completed + @completion_journey_data.postposing).split("\n")[@line_index]
+ @line = new_line.nil? ? String.new(encoding: @encoding) : new_line
+ line_to_pointer = (@completion_journey_data.preposing + completed).split("\n").last
+ line_to_pointer = String.new(encoding: @encoding) if line_to_pointer.nil?
+ @cursor_max = calculate_width(@line)
+ @cursor = calculate_width(line_to_pointer)
+ @byte_pointer = line_to_pointer.bytesize
end
private def run_for_operators(key, method_symbol, &block)
@@ -1104,6 +1527,13 @@ class Reline::LineEditor
end
def input_key(key)
+ @last_key = key
+ @config.reset_oneshot_key_bindings
+ @dialogs.each do |dialog|
+ if key.char.instance_of?(Symbol) and key.char == dialog.name
+ return
+ end
+ end
@just_cursor_moving = nil
if key.char.nil?
if @first_char
@@ -1121,7 +1551,20 @@ class Reline::LineEditor
if result.is_a?(Array)
completion_occurs = true
process_insert
- complete(result)
+ if @config.autocompletion
+ move_completed_list(result, :down)
+ else
+ complete(result)
+ end
+ end
+ end
+ elsif @config.editing_mode_is?(:emacs, :vi_insert) and key.char == :completion_journey_up
+ if not @config.disable_completion and @config.autocompletion
+ result = call_completion_proc
+ if result.is_a?(Array)
+ completion_occurs = true
+ process_insert
+ move_completed_list(result, :up)
end
end
elsif not @config.disable_completion and @config.editing_mode_is?(:vi_insert) and ["\C-p".ord, "\C-n".ord].include?(key.char)
@@ -1140,6 +1583,7 @@ class Reline::LineEditor
end
unless completion_occurs
@completion_state = CompletionState::NORMAL
+ @completion_journey_data = nil
end
if not @in_pasting and @just_cursor_moving.nil?
if @previous_line_index and @buffer_of_lines[@previous_line_index] == @line
@@ -1159,7 +1603,13 @@ class Reline::LineEditor
def call_completion_proc
result = retrieve_completion_block(true)
- preposing, target, postposing = result
+ pre, target, post = result
+ result = call_completion_proc_with_checking_args(pre, target, post)
+ Reline.core.instance_variable_set(:@completion_quote_character, nil)
+ result
+ end
+
+ def call_completion_proc_with_checking_args(pre, target, post)
if @completion_proc and target
argnum = @completion_proc.parameters.inject(0) { |result, item|
case item.first
@@ -1173,12 +1623,11 @@ class Reline::LineEditor
when 1
result = @completion_proc.(target)
when 2
- result = @completion_proc.(target, preposing)
+ result = @completion_proc.(target, pre)
when 3..Float::INFINITY
- result = @completion_proc.(target, preposing, postposing)
+ result = @completion_proc.(target, pre, post)
end
end
- Reline.core.instance_variable_set(:@completion_quote_character, nil)
result
end
@@ -1960,6 +2409,7 @@ class Reline::LineEditor
arg -= 1
ed_prev_history(key, arg: arg) if arg > 0
end
+ alias_method :previous_history, :ed_prev_history
private def ed_next_history(key, arg: 1)
if @is_multiline and @line_index < (@buffer_of_lines.size - 1)
@@ -2007,6 +2457,7 @@ class Reline::LineEditor
arg -= 1
ed_next_history(key, arg: arg) if arg > 0
end
+ alias_method :next_history, :ed_next_history
private def ed_newline(key)
process_insert(force: true)
diff --git a/lib/reline/terminfo.rb b/lib/reline/terminfo.rb
new file mode 100644
index 0000000..3f32a5a
--- /dev/null
+++ b/lib/reline/terminfo.rb
@@ -0,0 +1,126 @@
+require 'fiddle'
+require 'fiddle/import'
+
+module Reline::Terminfo
+ extend Fiddle::Importer
+
+ class TerminfoError < StandardError; end
+
+ def self.curses_dl_files
+ case RUBY_PLATFORM
+ when /mingw/, /mswin/
+ # aren't supported
+ []
+ when /cygwin/
+ %w[cygncursesw-10.dll cygncurses-10.dll]
+ when /darwin/
+ %w[libncursesw.dylib libcursesw.dylib libncurses.dylib libcurses.dylib]
+ else
+ %w[libncursesw.so libcursesw.so libncurses.so libcurses.so]
+ end
+ end
+
+ @curses_dl = false
+ def self.curses_dl
+ return @curses_dl unless @curses_dl == false
+ if RUBY_VERSION >= '3.0.0'
+ # Gem module isn't defined in test-all of the Ruby repository, and
+ # Fiddle in Ruby 3.0.0 or later supports Fiddle::TYPE_VARIADIC.
+ fiddle_supports_variadic = true
+ elsif Fiddle.const_defined?(:VERSION) and Gem::Version.create(Fiddle::VERSION) >= Gem::Version.create('1.0.1')
+ # Fiddle::TYPE_VARIADIC is supported from Fiddle 1.0.1.
+ fiddle_supports_variadic = true
+ else
+ fiddle_supports_variadic = false
+ end
+ if fiddle_supports_variadic and not Fiddle.const_defined?(:TYPE_VARIADIC)
+ # If the libffi version is not 3.0.5 or higher, there isn't TYPE_VARIADIC.
+ fiddle_supports_variadic = false
+ end
+ if fiddle_supports_variadic
+ curses_dl_files.each do |curses_name|
+ result = Fiddle::Handle.new(curses_name)
+ rescue Fiddle::DLError
+ next
+ else
+ @curses_dl = result
+ break
+ end
+ end
+ @curses_dl = nil if @curses_dl == false
+ @curses_dl
+ end
+end
+
+module Reline::Terminfo
+ dlload curses_dl
+ #extern 'int setupterm(char *term, int fildes, int *errret)'
+ @setupterm = Fiddle::Function.new(curses_dl['setupterm'], [Fiddle::TYPE_VOIDP, Fiddle::TYPE_INT, Fiddle::TYPE_VOIDP], Fiddle::TYPE_INT)
+ #extern 'char *tigetstr(char *capname)'
+ @tigetstr = Fiddle::Function.new(curses_dl['tigetstr'], [Fiddle::TYPE_VOIDP], Fiddle::TYPE_VOIDP)
+ begin
+ #extern 'char *tiparm(const char *str, ...)'
+ @tiparm = Fiddle::Function.new(curses_dl['tiparm'], [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VARIADIC], Fiddle::TYPE_VOIDP)
+ rescue Fiddle::DLError
+ # OpenBSD lacks tiparm
+ #extern 'char *tparm(const char *str, ...)'
+ @tiparm = Fiddle::Function.new(curses_dl['tparm'], [Fiddle::TYPE_VOIDP, Fiddle::TYPE_VARIADIC], Fiddle::TYPE_VOIDP)
+ end
+ # TODO: add int tigetflag(char *capname) and int tigetnum(char *capname)
+
+ def self.setupterm(term, fildes)
+ errret_int = String.new("\x00" * 8, encoding: 'ASCII-8BIT')
+ ret = @setupterm.(term, fildes, errret_int)
+ errret = errret_int.unpack1('i')
+ case ret
+ when 0 # OK
+ 0
+ when -1 # ERR
+ case errret
+ when 1
+ raise TerminfoError.new('The terminal is hardcopy, cannot be used for curses applications.')
+ when 0
+ raise TerminfoError.new('The terminal could not be found, or that it is a generic type, having too little information for curses applications to run.')
+ when -1
+ raise TerminfoError.new('The terminfo database could not be found.')
+ else # unknown
+ -1
+ end
+ else # unknown
+ -2
+ end
+ end
+
+ class StringWithTiparm < String
+ def tiparm(*args) # for method chain
+ Reline::Terminfo.tiparm(self, *args)
+ end
+ end
+
+ def self.tigetstr(capname)
+ capability = @tigetstr.(capname)
+ case capability.to_i
+ when 0, -1
+ raise TerminfoError, "can't find capability: #{capname}"
+ end
+ StringWithTiparm.new(capability.to_s)
+ end
+
+ def self.tiparm(str, *args)
+ new_args = []
+ args.each do |a|
+ new_args << Fiddle::TYPE_INT << a
+ end
+ @tiparm.(str, *new_args).to_s
+ end
+
+ def self.enabled?
+ true
+ end
+end if Reline::Terminfo.curses_dl
+
+module Reline::Terminfo
+ def self.enabled?
+ false
+ end
+end unless Reline::Terminfo.curses_dl
diff --git a/lib/reline/unicode.rb b/lib/reline/unicode.rb
index 7dbe8a1..80cc54a 100644
--- a/lib/reline/unicode.rb
+++ b/lib/reline/unicode.rb
@@ -101,9 +101,9 @@ class Reline::Unicode
def self.get_mbchar_width(mbchar)
ord = mbchar.ord
- if (0x00 <= ord and ord <= 0x1F)
+ if (0x00 <= ord and ord <= 0x1F) # in EscapedPairs
return 2
- elsif (0x20 <= ord and ord <= 0x7E)
+ elsif (0x20 <= ord and ord <= 0x7E) # printable ASCII chars
return 1
end
m = mbchar.encode(Encoding::UTF_8).match(MBCharWidthRE)
@@ -185,6 +185,37 @@ class Reline::Unicode
[lines, height]
end
+ # Take a chunk of a String cut by width with escape sequences.
+ def self.take_range(str, start_col, max_width, encoding = str.encoding)
+ chunk = String.new(encoding: encoding)
+ total_width = 0
+ rest = str.encode(Encoding::UTF_8)
+ in_zero_width = false
+ rest.scan(WIDTH_SCANNER) do |gc|
+ case
+ when gc[NON_PRINTING_START_INDEX]
+ in_zero_width = true
+ when gc[NON_PRINTING_END_INDEX]
+ in_zero_width = false
+ when gc[CSI_REGEXP_INDEX]
+ chunk << gc[CSI_REGEXP_INDEX]
+ when gc[OSC_REGEXP_INDEX]
+ chunk << gc[OSC_REGEXP_INDEX]
+ when gc[GRAPHEME_CLUSTER_INDEX]
+ gc = gc[GRAPHEME_CLUSTER_INDEX]
+ if in_zero_width
+ chunk << gc
+ else
+ mbchar_width = get_mbchar_width(gc)
+ total_width += mbchar_width
+ break if (start_col + max_width) < total_width
+ chunk << gc if start_col < total_width
+ end
+ end
+ end
+ chunk
+ end
+
def self.get_next_mbchar_size(line, byte_pointer)
grapheme = line.byteslice(byte_pointer..-1).grapheme_clusters.first
grapheme ? grapheme.bytesize : 0
diff --git a/lib/reline/version.rb b/lib/reline/version.rb
index 44db465..1c8ef4c 100644
--- a/lib/reline/version.rb
+++ b/lib/reline/version.rb
@@ -1,3 +1,3 @@
module Reline
- VERSION = '0.2.5'
+ VERSION = '0.2.8.pre.9'
end
diff --git a/lib/reline/windows.rb b/lib/reline/windows.rb
index c645458..5bbf1e9 100644
--- a/lib/reline/windows.rb
+++ b/lib/reline/windows.rb
@@ -38,9 +38,18 @@ class Reline::Windows
{
[27, 32] => :em_set_mark, # M-<space>
+ [24, 24] => :em_exchange_mark, # C-x C-x
}.each_pair do |key, func|
config.add_default_key_binding_by_keymap(:emacs, key, func)
end
+
+ # Emulate ANSI key sequence.
+ {
+ [27, 91, 90] => :completion_journey_up, # S-Tab
+ }.each_pair do |key, func|
+ config.add_default_key_binding_by_keymap(:emacs, key, func)
+ config.add_default_key_binding_by_keymap(:vi_insert, key, func)
+ end
end
if defined? JRUBY_VERSION
@@ -85,13 +94,37 @@ class Reline::Windows
end
end
+ VK_RETURN = 0x0D
VK_MENU = 0x12
VK_LMENU = 0xA4
VK_CONTROL = 0x11
VK_SHIFT = 0x10
+ VK_DIVIDE = 0x6F
+
+ KEY_EVENT = 0x01
+ WINDOW_BUFFER_SIZE_EVENT = 0x04
+
+ CAPSLOCK_ON = 0x0080
+ ENHANCED_KEY = 0x0100
+ LEFT_ALT_PRESSED = 0x0002
+ LEFT_CTRL_PRESSED = 0x0008
+ NUMLOCK_ON = 0x0020
+ RIGHT_ALT_PRESSED = 0x0001
+ RIGHT_CTRL_PRESSED = 0x0004
+ SCROLLLOCK_ON = 0x0040
+ SHIFT_PRESSED = 0x0010
+
+ VK_TAB = 0x09
+ VK_END = 0x23
+ VK_HOME = 0x24
+ VK_LEFT = 0x25
+ VK_UP = 0x26
+ VK_RIGHT = 0x27
+ VK_DOWN = 0x28
+ VK_DELETE = 0x2E
+
STD_INPUT_HANDLE = -10
STD_OUTPUT_HANDLE = -11
- WINDOW_BUFFER_SIZE_EVENT = 0x04
FILE_TYPE_PIPE = 0x0003
FILE_NAME_INFO = 2
@@getwch = Win32API.new('msvcrt', '_getwch', [], 'I')
@@ -105,13 +138,15 @@ class Reline::Windows
@@hConsoleHandle = @@GetStdHandle.call(STD_OUTPUT_HANDLE)
@@hConsoleInputHandle = @@GetStdHandle.call(STD_INPUT_HANDLE)
@@GetNumberOfConsoleInputEvents = Win32API.new('kernel32', 'GetNumberOfConsoleInputEvents', ['L', 'P'], 'L')
- @@ReadConsoleInput = Win32API.new('kernel32', 'ReadConsoleInput', ['L', 'P', 'L', 'P'], 'L')
+ @@ReadConsoleInputW = Win32API.new('kernel32', 'ReadConsoleInputW', ['L', 'P', 'L', 'P'], 'L')
@@GetFileType = Win32API.new('kernel32', 'GetFileType', ['L'], 'L')
@@GetFileInformationByHandleEx = Win32API.new('kernel32', 'GetFileInformationByHandleEx', ['L', 'I', 'P', 'L'], 'I')
@@FillConsoleOutputAttribute = Win32API.new('kernel32', 'FillConsoleOutputAttribute', ['L', 'L', 'L', 'L', 'P'], 'L')
+ @@SetConsoleCursorInfo = Win32API.new('kernel32', 'SetConsoleCursorInfo', ['L', 'P'], 'L')
@@GetConsoleMode = Win32API.new('kernel32', 'GetConsoleMode', ['L', 'P'], 'L')
@@SetConsoleMode = Win32API.new('kernel32', 'SetConsoleMode', ['L', 'L'], 'L')
+ @@WaitForSingleObject = Win32API.new('kernel32', 'WaitForSingleObject', ['L', 'L'], 'L')
ENABLE_VIRTUAL_TERMINAL_PROCESSING = 4
private_class_method def self.getconsolemode
@@ -149,7 +184,7 @@ class Reline::Windows
# DWORD FileNameLength;
# WCHAR FileName[1];
# } FILE_NAME_INFO
- len = p_buffer[0, 4].unpack("L")[0]
+ len = p_buffer[0, 4].unpack1("L")
name = p_buffer[4, len].encode(Encoding::UTF_8, Encoding::UTF_16LE, invalid: :replace)
# Check if this could be a MSYS2 pty pipe ('\msys-XXXX-ptyN-XX')
@@ -157,78 +192,76 @@ class Reline::Windows
name =~ /(msys-|cygwin-).*-pty/ ? true : false
end
- def self.getwch
- unless @@input_buf.empty?
- return @@input_buf.shift
- end
- while @@kbhit.call == 0
- sleep(0.001)
- end
- until @@kbhit.call == 0
- ret = @@getwch.call
- if ret == 0 or ret == 0xE0
- @@input_buf << ret
- ret = @@getwch.call
- @@input_buf << ret
- return @@input_buf.shift
- end
- begin
- bytes = ret.chr(Encoding::UTF_8).bytes
- @@input_buf.push(*bytes)
- rescue Encoding::UndefinedConversionError
- @@input_buf << ret
- @@input_buf << @@getwch.call if ret == 224
- end
+ KEY_MAP = [
+ # It's treated as Meta+Enter on Windows.
+ [ { control_keys: :CTRL, virtual_key_code: 0x0D }, "\e\r".bytes ],
+ [ { control_keys: :SHIFT, virtual_key_code: 0x0D }, "\e\r".bytes ],
+
+ # It's treated as Meta+Space on Windows.
+ [ { control_keys: :CTRL, char_code: 0x20 }, "\e ".bytes ],
+
+ # Emulate getwch() key sequences.
+ [ { control_keys: [], virtual_key_code: VK_UP }, [0, 72] ],
+ [ { control_keys: [], virtual_key_code: VK_DOWN }, [0, 80] ],
+ [ { control_keys: [], virtual_key_code: VK_RIGHT }, [0, 77] ],
+ [ { control_keys: [], virtual_key_code: VK_LEFT }, [0, 75] ],
+ [ { control_keys: [], virtual_key_code: VK_DELETE }, [0, 83] ],
+ [ { control_keys: [], virtual_key_code: VK_HOME }, [0, 71] ],
+ [ { control_keys: [], virtual_key_code: VK_END }, [0, 79] ],
+
+ # Emulate ANSI key sequence.
+ [ { control_keys: :SHIFT, virtual_key_code: VK_TAB }, [27, 91, 90] ],
+ ]
+
+ def self.process_key_event(repeat_count, virtual_key_code, virtual_scan_code, char_code, control_key_state)
+
+ key = KeyEventRecord.new(virtual_key_code, char_code, control_key_state)
+
+ match = KEY_MAP.find { |args,| key.matches?(**args) }
+ unless match.nil?
+ @@output_buf.concat(match.last)
+ return
end
- @@input_buf.shift
+
+ # no char, only control keys
+ return if key.char_code == 0 and key.control_keys.any?
+
+ @@output_buf.push("\e".ord) if key.control_keys.include?(:ALT)
+
+ @@output_buf.concat(key.char.bytes)
end
- def self.getc
+ def self.check_input_event
num_of_events = 0.chr * 8
- while @@GetNumberOfConsoleInputEvents.(@@hConsoleInputHandle, num_of_events) != 0 and num_of_events.unpack('L').first > 0
+ while @@output_buf.empty? #or true
+ next if @@WaitForSingleObject.(@@hConsoleInputHandle, 100) != 0 # max 0.1 sec
+ next if @@GetNumberOfConsoleInputEvents.(@@hConsoleInputHandle, num_of_events) == 0 or num_of_events.unpack('L').first == 0
input_record = 0.chr * 18
read_event = 0.chr * 4
- if @@ReadConsoleInput.(@@hConsoleInputHandle, input_record, 1, read_event) != 0
+ if @@ReadConsoleInputW.(@@hConsoleInputHandle, input_record, 1, read_event) != 0
event = input_record[0, 2].unpack('s*').first
- if event == WINDOW_BUFFER_SIZE_EVENT
+ case event
+ when WINDOW_BUFFER_SIZE_EVENT
@@winch_handler.()
+ when KEY_EVENT
+ key_down = input_record[4, 4].unpack('l*').first
+ repeat_count = input_record[8, 2].unpack('s*').first
+ virtual_key_code = input_record[10, 2].unpack('s*').first
+ virtual_scan_code = input_record[12, 2].unpack('s*').first
+ char_code = input_record[14, 2].unpack('S*').first
+ control_key_state = input_record[16, 2].unpack('S*').first
+ is_key_down = key_down.zero? ? false : true
+ if is_key_down
+ process_key_event(repeat_count, virtual_key_code, virtual_scan_code, char_code, control_key_state)
+ end
end
end
end
- unless @@output_buf.empty?
- return @@output_buf.shift
- end
- input = getwch
- meta = (@@GetKeyState.call(VK_LMENU) & 0x80) != 0
- control = (@@GetKeyState.call(VK_CONTROL) & 0x80) != 0
- shift = (@@GetKeyState.call(VK_SHIFT) & 0x80) != 0
- force_enter = !input.instance_of?(Array) && (control or shift) && input == 0x0D
- if force_enter
- # It's treated as Meta+Enter on Windows
- @@output_buf.push("\e".ord)
- @@output_buf.push(input)
- else
- case input
- when 0x00
- meta = false
- @@output_buf.push(input)
- input = getwch
- @@output_buf.push(*input)
- when 0xE0
- @@output_buf.push(input)
- input = getwch
- @@output_buf.push(*input)
- when 0x03
- @@output_buf.push(input)
- else
- @@output_buf.push(input)
- end
- end
- if meta
- "\e".ord
- else
- @@output_buf.shift
- end
+ end
+
+ def self.getc
+ check_input_event
+ @@output_buf.shift
end
def self.ungetc(c)
@@ -325,6 +358,20 @@ class Reline::Windows
raise NotImplementedError
end
+ def self.hide_cursor
+ size = 100
+ visible = 0 # 0 means false
+ cursor_info = [size, visible].pack('Li')
+ @@SetConsoleCursorInfo.call(@@hConsoleHandle, cursor_info)
+ end
+
+ def self.show_cursor
+ size = 100
+ visible = 1 # 1 means true
+ cursor_info = [size, visible].pack('Li')
+ @@SetConsoleCursorInfo.call(@@hConsoleHandle, cursor_info)
+ end
+
def self.set_winch_handler(&handler)
@@winch_handler = handler
end
@@ -337,4 +384,43 @@ class Reline::Windows
def self.deprep(otio)
# do nothing
end
+
+ class KeyEventRecord
+
+ attr_reader :virtual_key_code, :char_code, :control_key_state, :control_keys
+
+ def initialize(virtual_key_code, char_code, control_key_state)
+ @virtual_key_code = virtual_key_code
+ @char_code = char_code
+ @control_key_state = control_key_state
+ @enhanced = control_key_state & ENHANCED_KEY != 0
+
+ (@control_keys = []).tap do |control_keys|
+ # symbols must be sorted to make comparison is easier later on
+ control_keys << :ALT if control_key_state & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED) != 0
+ control_keys << :CTRL if control_key_state & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED) != 0
+ control_keys << :SHIFT if control_key_state & SHIFT_PRESSED != 0
+ end.freeze
+ end
+
+ def char
+ @char_code.chr(Encoding::UTF_8)
+ end
+
+ def enhanced?
+ @enhanced
+ end
+
+ # Verifies if the arguments match with this key event.
+ # Nil arguments are ignored, but at least one must be passed as non-nil.
+ # To verify that no control keys were pressed, pass an empty array: `control_keys: []`.
+ def matches?(control_keys: nil, virtual_key_code: nil, char_code: nil)
+ raise ArgumentError, 'No argument was passed to match key event' if control_keys.nil? && virtual_key_code.nil? && char_code.nil?
+
+ (control_keys.nil? || [*control_keys].sort == @control_keys) &&
+ (virtual_key_code.nil? || @virtual_key_code == virtual_key_code) &&
+ (char_code.nil? || char_code == @char_code)
+ end
+
+ end
end
diff --git a/lib/resolv-replace.gemspec b/lib/resolv-replace.gemspec
index 0dadb19..6bc07db 100644
--- a/lib/resolv-replace.gemspec
+++ b/lib/resolv-replace.gemspec
@@ -16,8 +16,6 @@ Gem::Specification.new do |spec|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
- spec.bindir = "exe"
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_dependency "resolv"
diff --git a/lib/resolv.gemspec b/lib/resolv.gemspec
index 22bdd93..c6a0609 100644
--- a/lib/resolv.gemspec
+++ b/lib/resolv.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = "resolv"
- spec.version = "0.2.0"
+ spec.version = "0.2.1"
spec.authors = ["Tanaka Akira"]
spec.email = ["akr@fsij.org"]
diff --git a/lib/ruby2_keywords.gemspec b/lib/ruby2_keywords.gemspec
index 14c255e..e2cd397 100644
--- a/lib/ruby2_keywords.gemspec
+++ b/lib/ruby2_keywords.gemspec
@@ -1,10 +1,23 @@
+_VERSION = "0.0.5"
+abort "Version must not reach 1" if _VERSION[/\d+/].to_i >= 1
+
Gem::Specification.new do |s|
s.name = "ruby2_keywords"
- s.version = "1.0.0"
+ s.version = _VERSION
s.summary = "Shim library for Module#ruby2_keywords"
s.homepage = "https://github.com/ruby/ruby2_keywords"
s.licenses = ["Ruby", "BSD-2-Clause"]
s.authors = ["Nobuyoshi Nakada"]
- s.require_paths = []
- s.files = []
+ s.require_paths = ["lib"]
+ s.rdoc_options = ["--main", "README.md"]
+ s.extra_rdoc_files = [
+ "LICENSE",
+ "README.md",
+ "ChangeLog",
+ *Dir.glob("#{__dir__}/logs/ChangeLog-*[^~]").map {|path| path[(__dir__.size+1)..-1]},
+ ]
+ s.files = [
+ "lib/ruby2_keywords.rb",
+ ]
+ s.required_ruby_version = '>= 2.0.0'
end
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index 3585def..80708e2 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -12,11 +12,11 @@ module Gem
end
# Must be first since it unloads the prelude from 1.9.2
-require 'rubygems/compatibility'
+require_relative 'rubygems/compatibility'
-require 'rubygems/defaults'
-require 'rubygems/deprecate'
-require 'rubygems/errors'
+require_relative 'rubygems/defaults'
+require_relative 'rubygems/deprecate'
+require_relative 'rubygems/errors'
##
# RubyGems is the Ruby standard for publishing and managing third party
@@ -178,7 +178,7 @@ module Gem
@configuration = nil
@gemdeps = nil
@loaded_specs = {}
- LOADED_SPECS_MUTEX = Mutex.new
+ LOADED_SPECS_MUTEX = Thread::Mutex.new
@path_to_default_spec_map = {}
@platforms = []
@ruby = nil
@@ -249,9 +249,6 @@ module Gem
# you to specify specific gem versions.
def self.bin_path(name, exec_name = nil, *requirements)
- # TODO: fails test_self_bin_path_bin_file_gone_in_latest
- # Gem::Specification.find_by_name(name, *requirements).bin_file exec_name
-
requirements = Gem::Requirement.default if
requirements.empty?
@@ -562,7 +559,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
# => [#<Gem::Specification:0x1013b4528 @name="minitest", ...>]
def self.install(name, version = Gem::Requirement.default, *options)
- require "rubygems/dependency_installer"
+ require_relative "rubygems/dependency_installer"
inst = Gem::DependencyInstaller.new(*options)
inst.install name, version
inst.installed_gems
@@ -628,22 +625,12 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
rescue ::LoadError
# If we can't load psych, that's fine, go on.
else
- # If 'yaml' has already been required, then we have to
- # be sure to switch it over to the newly loaded psych.
- if defined?(YAML::ENGINE) && YAML::ENGINE.yamler != "psych"
- YAML::ENGINE.yamler = "psych"
- end
-
- require 'rubygems/psych_additions'
- require 'rubygems/psych_tree'
+ require_relative 'rubygems/psych_additions'
+ require_relative 'rubygems/psych_tree'
end
require 'yaml'
- require 'rubygems/safe_yaml'
-
- # Now that we're sure some kind of yaml library is loaded, pull
- # in our hack to deal with Syck's DefaultKey ugliness.
- require 'rubygems/syck_hack'
+ require_relative 'rubygems/safe_yaml'
@yaml_loaded = true
end
@@ -1003,7 +990,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
# Lazily loads DefaultUserInteraction and returns the default UI.
def self.ui
- require 'rubygems/user_interaction'
+ require_relative 'rubygems/user_interaction'
Gem::DefaultUserInteraction.ui
end
@@ -1063,7 +1050,9 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
# Find rubygems plugin files in the standard location and load them
def self.load_plugins
- load_plugin_files Gem::Util.glob_files_in_dir("*#{Gem.plugin_suffix_pattern}", plugindir)
+ Gem.path.each do |gem_path|
+ load_plugin_files Gem::Util.glob_files_in_dir("*#{Gem.plugin_suffix_pattern}", plugindir(gem_path))
+ end
end
##
@@ -1121,27 +1110,22 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
end
ENV["BUNDLE_GEMFILE"] ||= File.expand_path(path)
- require 'rubygems/user_interaction'
- Gem::DefaultUserInteraction.use_ui(ui) do
- require "bundler"
- begin
- Bundler.ui.silence do
- @gemdeps = Bundler.setup
+ require_relative 'rubygems/user_interaction'
+ require "bundler"
+ begin
+ Gem::DefaultUserInteraction.use_ui(ui) do
+ begin
+ Bundler.ui.silence do
+ @gemdeps = Bundler.setup
+ end
+ ensure
+ Gem::DefaultUserInteraction.ui.close
end
- ensure
- Gem::DefaultUserInteraction.ui.close
end
- @gemdeps.requested_specs.map(&:to_spec).sort_by(&:name)
- end
-
- rescue => e
- case e
- when Gem::LoadError, Gem::UnsatisfiableDependencyError, (defined?(Bundler::GemNotFound) ? Bundler::GemNotFound : Gem::LoadError)
+ rescue Bundler::BundlerError => e
warn e.message
- warn "You may need to `gem install -g` to install missing gems"
+ warn "You may need to `bundle install` to install missing gems"
warn ""
- else
- raise
end
end
@@ -1338,7 +1322,7 @@ An Array (#{env.inspect}) was passed in from #{caller[3]}
autoload :Version, File.expand_path('rubygems/version', __dir__)
end
-require 'rubygems/exceptions'
+require_relative 'rubygems/exceptions'
# REFACTOR: This should be pulled out into some kind of hacks file.
begin
@@ -1347,6 +1331,14 @@ begin
require 'rubygems/defaults/operating_system'
rescue LoadError
+ # Ignored
+rescue StandardError => e
+ msg = "#{e.message}\n" \
+ "Loading the rubygems/defaults/operating_system.rb file caused an error. " \
+ "This file is owned by your OS, not by rubygems upstream. " \
+ "Please find out which OS package this file belongs to and follow the guidelines from your OS to report " \
+ "the problem and ask for help."
+ raise e.class, msg
end
begin
@@ -1361,8 +1353,6 @@ end
# Loads the default specs.
Gem::Specification.load_defaults
-require 'rubygems/core_ext/kernel_gem'
-require 'rubygems/core_ext/kernel_require'
-require 'rubygems/core_ext/kernel_warn'
-
-Gem.use_gemdeps
+require_relative 'rubygems/core_ext/kernel_gem'
+require_relative 'rubygems/core_ext/kernel_require'
+require_relative 'rubygems/core_ext/kernel_warn'
diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb
index 9f935e6..303f54a 100644
--- a/lib/rubygems/command.rb
+++ b/lib/rubygems/command.rb
@@ -355,6 +355,8 @@ class Gem::Command
def add_option(*opts, &handler) # :yields: value, options
group_name = Symbol === opts.first ? opts.shift : :options
+ raise "Do not pass an empty string in opts" if opts.include?("")
+
@option_groups[group_name] << [opts, handler]
end
diff --git a/lib/rubygems/command_manager.rb b/lib/rubygems/command_manager.rb
index 2409550..39bf8bd 100644
--- a/lib/rubygems/command_manager.rb
+++ b/lib/rubygems/command_manager.rb
@@ -5,9 +5,9 @@
# See LICENSE.txt for permissions.
#++
-require 'rubygems/command'
-require 'rubygems/user_interaction'
-require 'rubygems/text'
+require_relative 'command'
+require_relative 'user_interaction'
+require_relative 'text'
##
# The command manager registers and installs all the individual sub-commands
diff --git a/lib/rubygems/commands/build_command.rb b/lib/rubygems/commands/build_command.rb
index fff5f7c..6d1a057 100644
--- a/lib/rubygems/commands/build_command.rb
+++ b/lib/rubygems/commands/build_command.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/package'
-require 'rubygems/version_option'
+require_relative '../command'
+require_relative '../package'
+require_relative '../version_option'
class Gem::Commands::BuildCommand < Gem::Command
include Gem::VersionOption
@@ -23,7 +23,7 @@ class Gem::Commands::BuildCommand < Gem::Command
options[:output] = value
end
- add_option '-C PATH', '', 'Run as if gem build was started in <PATH> instead of the current working directory.' do |value, options|
+ add_option '-C PATH', 'Run as if gem build was started in <PATH> instead of the current working directory.' do |value, options|
options[:build_path] = value
end
end
diff --git a/lib/rubygems/commands/cert_command.rb b/lib/rubygems/commands/cert_command.rb
index 998df06..bdfeb0b 100644
--- a/lib/rubygems/commands/cert_command.rb
+++ b/lib/rubygems/commands/cert_command.rb
@@ -1,43 +1,15 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/security'
+require_relative '../command'
+require_relative '../security'
class Gem::Commands::CertCommand < Gem::Command
def initialize
super 'cert', 'Manage RubyGems certificates and signing settings',
:add => [], :remove => [], :list => [], :build => [], :sign => []
- OptionParser.accept OpenSSL::X509::Certificate do |certificate_file|
- begin
- certificate = OpenSSL::X509::Certificate.new File.read certificate_file
- rescue Errno::ENOENT
- raise OptionParser::InvalidArgument, "#{certificate_file}: does not exist"
- rescue OpenSSL::X509::CertificateError
- raise OptionParser::InvalidArgument,
- "#{certificate_file}: invalid X509 certificate"
- end
- [certificate, certificate_file]
- end
-
- OptionParser.accept OpenSSL::PKey::RSA do |key_file|
- begin
- passphrase = ENV['GEM_PRIVATE_KEY_PASSPHRASE']
- key = OpenSSL::PKey::RSA.new File.read(key_file), passphrase
- rescue Errno::ENOENT
- raise OptionParser::InvalidArgument, "#{key_file}: does not exist"
- rescue OpenSSL::PKey::RSAError
- raise OptionParser::InvalidArgument, "#{key_file}: invalid RSA key"
- end
-
- raise OptionParser::InvalidArgument,
- "#{key_file}: private key not found" unless key.private?
-
- key
- end
-
- add_option('-a', '--add CERT', OpenSSL::X509::Certificate,
- 'Add a trusted certificate.') do |(cert, _), options|
- options[:add] << cert
+ add_option('-a', '--add CERT',
+ 'Add a trusted certificate.') do |cert_file, options|
+ options[:add] << open_cert(cert_file)
end
add_option('-l', '--list [FILTER]',
@@ -60,15 +32,15 @@ class Gem::Commands::CertCommand < Gem::Command
options[:build] << email_address
end
- add_option('-C', '--certificate CERT', OpenSSL::X509::Certificate,
- 'Signing certificate for --sign') do |(cert, cert_file), options|
- options[:issuer_cert] = cert
+ add_option('-C', '--certificate CERT',
+ 'Signing certificate for --sign') do |cert_file, options|
+ options[:issuer_cert] = open_cert(cert_file)
options[:issuer_cert_file] = cert_file
end
- add_option('-K', '--private-key KEY', OpenSSL::PKey::RSA,
- 'Key for --sign or --build') do |key, options|
- options[:key] = key
+ add_option('-K', '--private-key KEY',
+ 'Key for --sign or --build') do |key_file, options|
+ options[:key] = open_private_key(key_file)
end
add_option('-s', '--sign CERT',
@@ -97,7 +69,39 @@ class Gem::Commands::CertCommand < Gem::Command
say "Added '#{certificate.subject}'"
end
+ def check_openssl
+ return if Gem::HAVE_OPENSSL
+
+ alert_error "OpenSSL library is required for the cert command"
+ terminate_interaction 1
+ end
+
+ def open_cert(certificate_file)
+ check_openssl
+ OpenSSL::X509::Certificate.new File.read certificate_file
+ rescue Errno::ENOENT
+ raise OptionParser::InvalidArgument, "#{certificate_file}: does not exist"
+ rescue OpenSSL::X509::CertificateError
+ raise OptionParser::InvalidArgument,
+ "#{certificate_file}: invalid X509 certificate"
+ end
+
+ def open_private_key(key_file)
+ check_openssl
+ passphrase = ENV['GEM_PRIVATE_KEY_PASSPHRASE']
+ key = OpenSSL::PKey::RSA.new File.read(key_file), passphrase
+ raise OptionParser::InvalidArgument,
+ "#{key_file}: private key not found" unless key.private?
+ key
+ rescue Errno::ENOENT
+ raise OptionParser::InvalidArgument, "#{key_file}: does not exist"
+ rescue OpenSSL::PKey::RSAError
+ raise OptionParser::InvalidArgument, "#{key_file}: invalid RSA key"
+ end
+
def execute
+ check_openssl
+
options[:add].each do |certificate|
add_certificate certificate
end
@@ -311,4 +315,4 @@ For further reading on signing gems see `ri Gem::Security`.
# It's simple, but is all we need
email =~ /\A.+@.+\z/
end
-end if Gem::HAVE_OPENSSL
+end
diff --git a/lib/rubygems/commands/check_command.rb b/lib/rubygems/commands/check_command.rb
index 8b8eda5..3b6b97a 100644
--- a/lib/rubygems/commands/check_command.rb
+++ b/lib/rubygems/commands/check_command.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/version_option'
-require 'rubygems/validator'
-require 'rubygems/doctor'
+require_relative '../command'
+require_relative '../version_option'
+require_relative '../validator'
+require_relative '../doctor'
class Gem::Commands::CheckCommand < Gem::Command
include Gem::VersionOption
diff --git a/lib/rubygems/commands/cleanup_command.rb b/lib/rubygems/commands/cleanup_command.rb
index 662badc..c965085 100644
--- a/lib/rubygems/commands/cleanup_command.rb
+++ b/lib/rubygems/commands/cleanup_command.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/dependency_list'
-require 'rubygems/uninstaller'
+require_relative '../command'
+require_relative '../dependency_list'
+require_relative '../uninstaller'
class Gem::Commands::CleanupCommand < Gem::Command
def initialize
diff --git a/lib/rubygems/commands/contents_command.rb b/lib/rubygems/commands/contents_command.rb
index f17aed6..716022c 100644
--- a/lib/rubygems/commands/contents_command.rb
+++ b/lib/rubygems/commands/contents_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/version_option'
+require_relative '../command'
+require_relative '../version_option'
class Gem::Commands::ContentsCommand < Gem::Command
include Gem::VersionOption
diff --git a/lib/rubygems/commands/dependency_command.rb b/lib/rubygems/commands/dependency_command.rb
index e472d8f..7d21707 100644
--- a/lib/rubygems/commands/dependency_command.rb
+++ b/lib/rubygems/commands/dependency_command.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/local_remote_options'
-require 'rubygems/version_option'
+require_relative '../command'
+require_relative '../local_remote_options'
+require_relative '../version_option'
class Gem::Commands::DependencyCommand < Gem::Command
include Gem::LocalRemoteOptions
diff --git a/lib/rubygems/commands/environment_command.rb b/lib/rubygems/commands/environment_command.rb
index 37429fb..b6eeb62 100644
--- a/lib/rubygems/commands/environment_command.rb
+++ b/lib/rubygems/commands/environment_command.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'rubygems/command'
+require_relative '../command'
class Gem::Commands::EnvironmentCommand < Gem::Command
def initialize
diff --git a/lib/rubygems/commands/fetch_command.rb b/lib/rubygems/commands/fetch_command.rb
index 6a1b346..619f56a 100644
--- a/lib/rubygems/commands/fetch_command.rb
+++ b/lib/rubygems/commands/fetch_command.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/local_remote_options'
-require 'rubygems/version_option'
+require_relative '../command'
+require_relative '../local_remote_options'
+require_relative '../version_option'
class Gem::Commands::FetchCommand < Gem::Command
include Gem::LocalRemoteOptions
diff --git a/lib/rubygems/commands/generate_index_command.rb b/lib/rubygems/commands/generate_index_command.rb
index 93e25ef..87200da 100644
--- a/lib/rubygems/commands/generate_index_command.rb
+++ b/lib/rubygems/commands/generate_index_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/indexer'
+require_relative '../command'
+require_relative '../indexer'
##
# Generates a index files for use as a gem server.
diff --git a/lib/rubygems/commands/help_command.rb b/lib/rubygems/commands/help_command.rb
index 4e8d760..7f3383c 100644
--- a/lib/rubygems/commands/help_command.rb
+++ b/lib/rubygems/commands/help_command.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'rubygems/command'
+require_relative '../command'
class Gem::Commands::HelpCommand < Gem::Command
# :stopdoc:
diff --git a/lib/rubygems/commands/info_command.rb b/lib/rubygems/commands/info_command.rb
index 9ca6ae3..3f2dd4a 100644
--- a/lib/rubygems/commands/info_command.rb
+++ b/lib/rubygems/commands/info_command.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/query_utils'
+require_relative '../command'
+require_relative '../query_utils'
class Gem::Commands::InfoCommand < Gem::Command
include Gem::QueryUtils
diff --git a/lib/rubygems/commands/install_command.rb b/lib/rubygems/commands/install_command.rb
index 4d36c69..adf2cdb 100644
--- a/lib/rubygems/commands/install_command.rb
+++ b/lib/rubygems/commands/install_command.rb
@@ -1,10 +1,10 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/install_update_options'
-require 'rubygems/dependency_installer'
-require 'rubygems/local_remote_options'
-require 'rubygems/validator'
-require 'rubygems/version_option'
+require_relative '../command'
+require_relative '../install_update_options'
+require_relative '../dependency_installer'
+require_relative '../local_remote_options'
+require_relative '../validator'
+require_relative '../version_option'
##
# Gem installer command line tool
@@ -172,7 +172,7 @@ You can use `i` command instead of `install`.
end
def install_from_gemdeps # :nodoc:
- require 'rubygems/request_set'
+ require_relative '../request_set'
rs = Gem::RequestSet.new
specs = rs.install_from_gemdeps options do |req, inst|
@@ -247,11 +247,11 @@ You can use `i` command instead of `install`.
def load_hooks # :nodoc:
if options[:install_as_default]
- require 'rubygems/install_default_message'
+ require_relative '../install_default_message'
else
- require 'rubygems/install_message'
+ require_relative '../install_message'
end
- require 'rubygems/rdoc'
+ require_relative '../rdoc'
end
def show_install_errors(errors) # :nodoc:
@@ -260,7 +260,8 @@ You can use `i` command instead of `install`.
errors.each do |x|
return unless Gem::SourceFetchProblem === x
- msg = "Unable to pull data from '#{x.source.uri}': #{x.error.message}"
+ require_relative "../uri"
+ msg = "Unable to pull data from '#{Gem::Uri.new(x.source.uri).redacted}': #{x.error.message}"
alert_warning msg
end
diff --git a/lib/rubygems/commands/list_command.rb b/lib/rubygems/commands/list_command.rb
index 5c99d3d..dea1111 100644
--- a/lib/rubygems/commands/list_command.rb
+++ b/lib/rubygems/commands/list_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/query_utils'
+require_relative '../command'
+require_relative '../query_utils'
##
# Searches for gems starting with the supplied argument.
diff --git a/lib/rubygems/commands/lock_command.rb b/lib/rubygems/commands/lock_command.rb
index f1dc1ac..cb6229a 100644
--- a/lib/rubygems/commands/lock_command.rb
+++ b/lib/rubygems/commands/lock_command.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'rubygems/command'
+require_relative '../command'
class Gem::Commands::LockCommand < Gem::Command
def initialize
diff --git a/lib/rubygems/commands/mirror_command.rb b/lib/rubygems/commands/mirror_command.rb
index 86671a9..7daa47e 100644
--- a/lib/rubygems/commands/mirror_command.rb
+++ b/lib/rubygems/commands/mirror_command.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'rubygems/command'
+require_relative '../command'
unless defined? Gem::Commands::MirrorCommand
class Gem::Commands::MirrorCommand < Gem::Command
diff --git a/lib/rubygems/commands/open_command.rb b/lib/rubygems/commands/open_command.rb
index 8012a9a..1e616fd 100644
--- a/lib/rubygems/commands/open_command.rb
+++ b/lib/rubygems/commands/open_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/version_option'
+require_relative '../command'
+require_relative '../version_option'
class Gem::Commands::OpenCommand < Gem::Command
include Gem::VersionOption
diff --git a/lib/rubygems/commands/outdated_command.rb b/lib/rubygems/commands/outdated_command.rb
index 3579bfc..162d338 100644
--- a/lib/rubygems/commands/outdated_command.rb
+++ b/lib/rubygems/commands/outdated_command.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/local_remote_options'
-require 'rubygems/spec_fetcher'
-require 'rubygems/version_option'
+require_relative '../command'
+require_relative '../local_remote_options'
+require_relative '../spec_fetcher'
+require_relative '../version_option'
class Gem::Commands::OutdatedCommand < Gem::Command
include Gem::LocalRemoteOptions
diff --git a/lib/rubygems/commands/owner_command.rb b/lib/rubygems/commands/owner_command.rb
index dd49027..0a56652 100644
--- a/lib/rubygems/commands/owner_command.rb
+++ b/lib/rubygems/commands/owner_command.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/local_remote_options'
-require 'rubygems/gemcutter_utilities'
-require 'rubygems/text'
+require_relative '../command'
+require_relative '../local_remote_options'
+require_relative '../gemcutter_utilities'
+require_relative '../text'
class Gem::Commands::OwnerCommand < Gem::Command
include Gem::Text
diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb
index 1431059..41547ce 100644
--- a/lib/rubygems/commands/pristine_command.rb
+++ b/lib/rubygems/commands/pristine_command.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/package'
-require 'rubygems/installer'
-require 'rubygems/version_option'
+require_relative '../command'
+require_relative '../package'
+require_relative '../installer'
+require_relative '../version_option'
class Gem::Commands::PristineCommand < Gem::Command
include Gem::VersionOption
@@ -138,7 +138,7 @@ extensions will be restored.
gem = spec.cache_file
unless File.exist? gem or options[:only_executables] or options[:only_plugins]
- require 'rubygems/remote_fetcher'
+ require_relative '../remote_fetcher'
say "Cached gem for #{spec.full_name} not found, attempting to fetch..."
diff --git a/lib/rubygems/commands/push_command.rb b/lib/rubygems/commands/push_command.rb
index 1a9a193..1864b4b 100644
--- a/lib/rubygems/commands/push_command.rb
+++ b/lib/rubygems/commands/push_command.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/local_remote_options'
-require 'rubygems/gemcutter_utilities'
-require 'rubygems/package'
+require_relative '../command'
+require_relative '../local_remote_options'
+require_relative '../gemcutter_utilities'
+require_relative '../package'
class Gem::Commands::PushCommand < Gem::Command
include Gem::LocalRemoteOptions
diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb
index 789afd6..5896bec 100644
--- a/lib/rubygems/commands/query_command.rb
+++ b/lib/rubygems/commands/query_command.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/query_utils'
-require 'rubygems/deprecate'
+require_relative '../command'
+require_relative '../query_utils'
+require_relative '../deprecate'
class Gem::Commands::QueryCommand < Gem::Command
extend Gem::Deprecate
diff --git a/lib/rubygems/commands/rdoc_command.rb b/lib/rubygems/commands/rdoc_command.rb
index e8c9e84..305c80c 100644
--- a/lib/rubygems/commands/rdoc_command.rb
+++ b/lib/rubygems/commands/rdoc_command.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/version_option'
-require 'rubygems/rdoc'
+require_relative '../command'
+require_relative '../version_option'
+require_relative '../rdoc'
require 'fileutils'
class Gem::Commands::RdocCommand < Gem::Command
diff --git a/lib/rubygems/commands/search_command.rb b/lib/rubygems/commands/search_command.rb
index aeb2119..488d777 100644
--- a/lib/rubygems/commands/search_command.rb
+++ b/lib/rubygems/commands/search_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/query_utils'
+require_relative '../command'
+require_relative '../query_utils'
class Gem::Commands::SearchCommand < Gem::Command
include Gem::QueryUtils
diff --git a/lib/rubygems/commands/server_command.rb b/lib/rubygems/commands/server_command.rb
index 594cf77..f3c08ef 100644
--- a/lib/rubygems/commands/server_command.rb
+++ b/lib/rubygems/commands/server_command.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/server'
-require 'rubygems/deprecate'
+require_relative '../command'
+require_relative '../server'
+require_relative '../deprecate'
class Gem::Commands::ServerCommand < Gem::Command
extend Gem::Deprecate
diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb
index 47e215c..edb3498 100644
--- a/lib/rubygems/commands/setup_command.rb
+++ b/lib/rubygems/commands/setup_command.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'rubygems/command'
+require_relative '../command'
##
# Installs RubyGems itself. This command is ordinarily only available from a
@@ -348,7 +348,7 @@ By default, this RubyGems will install gem as:
rm_rf dir
end
- require 'rubygems/rdoc'
+ require_relative '../rdoc'
fake_spec = Gem::Specification.new 'rubygems', Gem::VERSION
def fake_spec.full_gem_path
@@ -407,7 +407,7 @@ By default, this RubyGems will install gem as:
cp File.join("bundler", bundler_spec.bindir, e), File.join(bundler_bin_dir, e)
end
- require 'rubygems/installer'
+ require_relative '../installer'
Dir.chdir("bundler") do
built_gem = Gem::Package.build(bundler_spec)
@@ -462,20 +462,8 @@ By default, this RubyGems will install gem as:
lib_dir = RbConfig::CONFIG[site_or_vendor]
bin_dir = RbConfig::CONFIG['bindir']
else
- # Apple installed RubyGems into libdir, and RubyGems <= 1.1.0 gets
- # confused about installation location, so switch back to
- # sitelibdir/vendorlibdir.
- if defined?(APPLE_GEM_HOME) and
- # just in case Apple and RubyGems don't get this patched up proper.
- (prefix == RbConfig::CONFIG['libdir'] or
- # this one is important
- prefix == File.join(RbConfig::CONFIG['libdir'], 'ruby'))
- lib_dir = RbConfig::CONFIG[site_or_vendor]
- bin_dir = RbConfig::CONFIG['bindir']
- else
- lib_dir = File.join prefix, 'lib'
- bin_dir = File.join prefix, 'bin'
- end
+ lib_dir = File.join prefix, 'lib'
+ bin_dir = File.join prefix, 'bin'
end
unless install_destdir.empty?
@@ -596,7 +584,7 @@ abort "#{deprecation_message}"
end
def uninstall_old_gemcutter
- require 'rubygems/uninstaller'
+ require_relative '../uninstaller'
ui = Gem::Uninstaller.new('gemcutter', :all => true, :ignore => true,
:version => '< 0.4')
@@ -605,7 +593,7 @@ abort "#{deprecation_message}"
end
def regenerate_binstubs
- require "rubygems/commands/pristine_command"
+ require_relative "pristine_command"
say "Regenerating binstubs"
args = %w[--all --only-executables --silent]
diff --git a/lib/rubygems/commands/signin_command.rb b/lib/rubygems/commands/signin_command.rb
index 2e19c83..23bb2f9 100644
--- a/lib/rubygems/commands/signin_command.rb
+++ b/lib/rubygems/commands/signin_command.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/gemcutter_utilities'
+require_relative '../command'
+require_relative '../gemcutter_utilities'
class Gem::Commands::SigninCommand < Gem::Command
include Gem::GemcutterUtilities
diff --git a/lib/rubygems/commands/signout_command.rb b/lib/rubygems/commands/signout_command.rb
index ebbe746..c9485e0 100644
--- a/lib/rubygems/commands/signout_command.rb
+++ b/lib/rubygems/commands/signout_command.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'rubygems/command'
+require_relative '../command'
class Gem::Commands::SignoutCommand < Gem::Command
def initialize
diff --git a/lib/rubygems/commands/sources_command.rb b/lib/rubygems/commands/sources_command.rb
index f74fb12..9e74f3c 100644
--- a/lib/rubygems/commands/sources_command.rb
+++ b/lib/rubygems/commands/sources_command.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/remote_fetcher'
-require 'rubygems/spec_fetcher'
-require 'rubygems/local_remote_options'
+require_relative '../command'
+require_relative '../remote_fetcher'
+require_relative '../spec_fetcher'
+require_relative '../local_remote_options'
class Gem::Commands::SourcesCommand < Gem::Command
include Gem::LocalRemoteOptions
diff --git a/lib/rubygems/commands/specification_command.rb b/lib/rubygems/commands/specification_command.rb
index 3fddaaa..473b6e7 100644
--- a/lib/rubygems/commands/specification_command.rb
+++ b/lib/rubygems/commands/specification_command.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/local_remote_options'
-require 'rubygems/version_option'
-require 'rubygems/package'
+require_relative '../command'
+require_relative '../local_remote_options'
+require_relative '../version_option'
+require_relative '../package'
class Gem::Commands::SpecificationCommand < Gem::Command
include Gem::LocalRemoteOptions
diff --git a/lib/rubygems/commands/stale_command.rb b/lib/rubygems/commands/stale_command.rb
index badc990..62a9796 100644
--- a/lib/rubygems/commands/stale_command.rb
+++ b/lib/rubygems/commands/stale_command.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'rubygems/command'
+require_relative '../command'
class Gem::Commands::StaleCommand < Gem::Command
def initialize
diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb
index 1540b2f..20781b2 100644
--- a/lib/rubygems/commands/uninstall_command.rb
+++ b/lib/rubygems/commands/uninstall_command.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/version_option'
-require 'rubygems/uninstaller'
+require_relative '../command'
+require_relative '../version_option'
+require_relative '../uninstaller'
require 'fileutils'
##
diff --git a/lib/rubygems/commands/unpack_command.rb b/lib/rubygems/commands/unpack_command.rb
index 8d90d08..3f17083 100644
--- a/lib/rubygems/commands/unpack_command.rb
+++ b/lib/rubygems/commands/unpack_command.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/version_option'
-require 'rubygems/security_option'
-require 'rubygems/remote_fetcher'
-require 'rubygems/package'
+require_relative '../command'
+require_relative '../version_option'
+require_relative '../security_option'
+require_relative '../remote_fetcher'
+require_relative '../package'
# forward-declare
diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb
index 91d93e3..d104488 100644
--- a/lib/rubygems/commands/update_command.rb
+++ b/lib/rubygems/commands/update_command.rb
@@ -1,13 +1,13 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/command_manager'
-require 'rubygems/dependency_installer'
-require 'rubygems/install_update_options'
-require 'rubygems/local_remote_options'
-require 'rubygems/spec_fetcher'
-require 'rubygems/version_option'
-require 'rubygems/install_message' # must come before rdoc for messaging
-require 'rubygems/rdoc'
+require_relative '../command'
+require_relative '../command_manager'
+require_relative '../dependency_installer'
+require_relative '../install_update_options'
+require_relative '../local_remote_options'
+require_relative '../spec_fetcher'
+require_relative '../version_option'
+require_relative '../install_message' # must come before rdoc for messaging
+require_relative '../rdoc'
class Gem::Commands::UpdateCommand < Gem::Command
include Gem::InstallUpdateOptions
diff --git a/lib/rubygems/commands/which_command.rb b/lib/rubygems/commands/which_command.rb
index d42ab18..44e87a2 100644
--- a/lib/rubygems/commands/which_command.rb
+++ b/lib/rubygems/commands/which_command.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'rubygems/command'
+require_relative '../command'
class Gem::Commands::WhichCommand < Gem::Command
def initialize
diff --git a/lib/rubygems/commands/yank_command.rb b/lib/rubygems/commands/yank_command.rb
index a793025..cad78ae 100644
--- a/lib/rubygems/commands/yank_command.rb
+++ b/lib/rubygems/commands/yank_command.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
-require 'rubygems/command'
-require 'rubygems/local_remote_options'
-require 'rubygems/version_option'
-require 'rubygems/gemcutter_utilities'
+require_relative '../command'
+require_relative '../local_remote_options'
+require_relative '../version_option'
+require_relative '../gemcutter_utilities'
class Gem::Commands::YankCommand < Gem::Command
include Gem::LocalRemoteOptions
diff --git a/lib/rubygems/config_file.rb b/lib/rubygems/config_file.rb
index 9dc41a2..60c1d50 100644
--- a/lib/rubygems/config_file.rb
+++ b/lib/rubygems/config_file.rb
@@ -5,7 +5,7 @@
# See LICENSE.txt for permissions.
#++
-require 'rubygems/user_interaction'
+require_relative 'user_interaction'
require 'rbconfig'
##
@@ -320,7 +320,8 @@ if you believe they were disclosed to a third party.
config = load_file(credentials_path).merge(host => api_key)
dirname = File.dirname credentials_path
- Dir.mkdir(dirname) unless File.exist? dirname
+ require 'fileutils'
+ FileUtils.mkdir_p(dirname)
Gem.load_yaml
@@ -457,9 +458,8 @@ if you believe they were disclosed to a third party.
# Writes out this config file, replacing its source.
def write
- unless File.exist?(File.dirname(config_file_name))
- FileUtils.mkdir_p File.dirname(config_file_name)
- end
+ require 'fileutils'
+ FileUtils.mkdir_p File.dirname(config_file_name)
File.open config_file_name, 'w' do |io|
io.write to_yaml
diff --git a/lib/rubygems/core_ext/tcpsocket_init.rb b/lib/rubygems/core_ext/tcpsocket_init.rb
index 3d9740c..2a79b63 100644
--- a/lib/rubygems/core_ext/tcpsocket_init.rb
+++ b/lib/rubygems/core_ext/tcpsocket_init.rb
@@ -11,10 +11,10 @@ module CoreExtensions
IPV4_DELAY_SECONDS = 0.1
def initialize(host, serv, *rest)
- mutex = Mutex.new
+ mutex = Thread::Mutex.new
addrs = []
threads = []
- cond_var = ConditionVariable.new
+ cond_var = Thread::ConditionVariable.new
Addrinfo.foreach(host, serv, nil, :STREAM) do |addr|
Thread.report_on_exception = false if defined? Thread.report_on_exception = ()
diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb
index e95bc06..f29104a 100644
--- a/lib/rubygems/defaults.rb
+++ b/lib/rubygems/defaults.rb
@@ -34,21 +34,7 @@ module Gem
# specified in the environment
def self.default_dir
- path = if defined? RUBY_FRAMEWORK_VERSION
- [
- File.dirname(RbConfig::CONFIG['sitedir']),
- 'Gems',
- RbConfig::CONFIG['ruby_version'],
- ]
- else
- [
- RbConfig::CONFIG['rubylibprefix'],
- 'gems',
- RbConfig::CONFIG['ruby_version'],
- ]
- end
-
- @default_dir ||= File.join(*path)
+ @default_dir ||= File.join(RbConfig::CONFIG['rubylibprefix'], 'gems', RbConfig::CONFIG['ruby_version'])
end
##
@@ -197,11 +183,7 @@ module Gem
# The default directory for binaries
def self.default_bindir
- if defined? RUBY_FRAMEWORK_VERSION # mac framework support
- '/usr/local/bin'
- else # generic install
- RbConfig::CONFIG['bindir']
- end
+ RbConfig::CONFIG['bindir']
end
def self.ruby_engine
diff --git a/lib/rubygems/dependency_installer.rb b/lib/rubygems/dependency_installer.rb
index 400a5de..913bba3 100644
--- a/lib/rubygems/dependency_installer.rb
+++ b/lib/rubygems/dependency_installer.rb
@@ -1,12 +1,12 @@
# frozen_string_literal: true
-require 'rubygems'
-require 'rubygems/dependency_list'
-require 'rubygems/package'
-require 'rubygems/installer'
-require 'rubygems/spec_fetcher'
-require 'rubygems/user_interaction'
-require 'rubygems/available_set'
-require 'rubygems/deprecate'
+require_relative '../rubygems'
+require_relative 'dependency_list'
+require_relative 'package'
+require_relative 'installer'
+require_relative 'spec_fetcher'
+require_relative 'user_interaction'
+require_relative 'available_set'
+require_relative 'deprecate'
##
# Installs a gem along with all its dependencies from local and remote gems.
diff --git a/lib/rubygems/dependency_list.rb b/lib/rubygems/dependency_list.rb
index bcf436c..8f61869 100644
--- a/lib/rubygems/dependency_list.rb
+++ b/lib/rubygems/dependency_list.rb
@@ -6,7 +6,7 @@
#++
require 'tsort'
-require 'rubygems/deprecate'
+require_relative 'deprecate'
##
# Gem::DependencyList is used for installing and uninstalling gems in the
diff --git a/lib/rubygems/deprecate.rb b/lib/rubygems/deprecate.rb
index 8c822cd..5fe0afb 100644
--- a/lib/rubygems/deprecate.rb
+++ b/lib/rubygems/deprecate.rb
@@ -1,23 +1,70 @@
# frozen_string_literal: true
##
-# Provides a single method +deprecate+ to be used to declare when
-# something is going away.
+# Provides 3 methods for declaring when something is going away.
+#
+# +deprecate(name, repl, year, month)+:
+# Indicate something may be removed on/after a certain date.
+#
+# +rubygems_deprecate(name, replacement=:none)+:
+# Indicate something will be removed in the next major RubyGems version,
+# and (optionally) a replacement for it.
+#
+# +rubygems_deprecate_command+:
+# Indicate a RubyGems command (in +lib/rubygems/commands/*.rb+) will be
+# removed in the next RubyGems version.
+#
+# Also provides +skip_during+ for temporarily turning off deprecation warnings.
+# This is intended to be used in the test suite, so deprecation warnings
+# don't cause test failures if you need to make sure stderr is otherwise empty.
+#
+#
+# Example usage of +deprecate+ and +rubygems_deprecate+:
#
# class Legacy
-# def self.klass_method
+# def self.some_class_method
# # ...
# end
#
-# def instance_method
+# def some_instance_method
+# # ...
+# end
+#
+# def some_old_method
# # ...
# end
#
# extend Gem::Deprecate
-# deprecate :instance_method, "X.z", 2011, 4
+# deprecate :some_instance_method, "X.z", 2011, 4
+# rubygems_deprecate :some_old_method, "Modern#some_new_method"
#
# class << self
# extend Gem::Deprecate
-# deprecate :klass_method, :none, 2011, 4
+# deprecate :some_class_method, :none, 2011, 4
+# end
+# end
+#
+#
+# Example usage of +rubygems_deprecate_command+:
+#
+# class Gem::Commands::QueryCommand < Gem::Command
+# extend Gem::Deprecate
+# rubygems_deprecate_command
+#
+# # ...
+# end
+#
+#
+# Example usage of +skip_during+:
+#
+# class TestSomething < Gem::Testcase
+# def test_some_thing_with_deprecations
+# Gem::Deprecate.skip_during do
+# actual_stdout, actual_stderr = capture_output do
+# Gem.something_deprecated
+# end
+# assert_empty actual_stdout
+# assert_equal(expected, actual_stderr)
+# end
# end
# end
diff --git a/lib/rubygems/doctor.rb b/lib/rubygems/doctor.rb
index ef31aed..41bcda9 100644
--- a/lib/rubygems/doctor.rb
+++ b/lib/rubygems/doctor.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'rubygems'
-require 'rubygems/user_interaction'
+require_relative '../rubygems'
+require_relative 'user_interaction'
##
# Cleans up after a partially-failed uninstall or for an invalid
diff --git a/lib/rubygems/errors.rb b/lib/rubygems/errors.rb
index abee206..86f0d1d 100644
--- a/lib/rubygems/errors.rb
+++ b/lib/rubygems/errors.rb
@@ -171,8 +171,7 @@ module Gem
# An English description of the error.
def wordy
- @source.uri.password = 'REDACTED' unless @source.uri.password.nil?
- "Unable to download data from #{@source.uri} - #{@error.message}"
+ "Unable to download data from #{Gem::Uri.new(@source.uri).redacted} - #{@error.message}"
end
##
diff --git a/lib/rubygems/exceptions.rb b/lib/rubygems/exceptions.rb
index 55755dd..f0debb6 100644
--- a/lib/rubygems/exceptions.rb
+++ b/lib/rubygems/exceptions.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require 'rubygems/deprecate'
-require 'rubygems/unknown_command_spell_checker'
+require_relative 'deprecate'
+require_relative 'unknown_command_spell_checker'
##
# Base exception class for RubyGems. All exception raised by RubyGems are a
@@ -225,7 +225,7 @@ class Gem::SystemExitException < SystemExit
def initialize(exit_code)
@exit_code = exit_code
- super "Exiting RubyGems with exit_code #{exit_code}"
+ super exit_code, "Exiting RubyGems with exit_code #{exit_code}"
end
end
diff --git a/lib/rubygems/ext/builder.rb b/lib/rubygems/ext/builder.rb
index 14d5dde..7934309 100644
--- a/lib/rubygems/ext/builder.rb
+++ b/lib/rubygems/ext/builder.rb
@@ -57,6 +57,7 @@ class Gem::Ext::Builder
p(command)
end
results << "current directory: #{dir}"
+ require "shellwords"
results << command.shelljoin
require "open3"
diff --git a/lib/rubygems/ext/ext_conf_builder.rb b/lib/rubygems/ext/ext_conf_builder.rb
index fede270..3ca3463 100644
--- a/lib/rubygems/ext/ext_conf_builder.rb
+++ b/lib/rubygems/ext/ext_conf_builder.rb
@@ -5,8 +5,6 @@
# See LICENSE.txt for permissions.
#++
-require 'shellwords'
-
class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_dir=Dir.pwd)
require 'fileutils'
@@ -23,11 +21,11 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
# spaces do not work.
#
# Details: https://github.com/rubygems/rubygems/issues/977#issuecomment-171544940
- tmp_dest = get_relative_path(tmp_dest, extension_dir)
+ tmp_dest_relative = get_relative_path(tmp_dest.clone, extension_dir)
Tempfile.open %w[siteconf .rb], extension_dir do |siteconf|
siteconf.puts "require 'rbconfig'"
- siteconf.puts "dest_path = #{tmp_dest.dump}"
+ siteconf.puts "dest_path = #{tmp_dest_relative.dump}"
%w[sitearchdir sitelibdir].each do |dir|
siteconf.puts "RbConfig::MAKEFILE_CONFIG['#{dir}'] = dest_path"
siteconf.puts "RbConfig::CONFIG['#{dir}'] = dest_path"
@@ -40,6 +38,7 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
begin
# workaround for https://github.com/oracle/truffleruby/issues/2115
siteconf_path = RUBY_ENGINE == "truffleruby" ? siteconf.path.dup : siteconf.path
+ require "shellwords"
cmd = Gem.ruby.shellsplit << "-I" << File.expand_path("../../..", __FILE__) <<
"-r" << get_relative_path(siteconf_path, extension_dir) << File.basename(extension)
cmd.push(*args)
@@ -63,8 +62,8 @@ class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
make dest_path, results, extension_dir
- if tmp_dest
- full_tmp_dest = File.join(extension_dir, tmp_dest)
+ if tmp_dest_relative
+ full_tmp_dest = File.join(extension_dir, tmp_dest_relative)
# TODO remove in RubyGems 3
if Gem.install_extension_in_lib and lib_dir
diff --git a/lib/rubygems/ext/rake_builder.rb b/lib/rubygems/ext/rake_builder.rb
index 64a6c0e..fed98e7 100644
--- a/lib/rubygems/ext/rake_builder.rb
+++ b/lib/rubygems/ext/rake_builder.rb
@@ -5,8 +5,6 @@
# See LICENSE.txt for permissions.
#++
-require "shellwords"
-
class Gem::Ext::RakeBuilder < Gem::Ext::Builder
def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_dir=Dir.pwd)
if File.basename(extension) =~ /mkrf_conf/i
@@ -16,6 +14,7 @@ class Gem::Ext::RakeBuilder < Gem::Ext::Builder
rake = ENV['rake']
if rake
+ require "shellwords"
rake = rake.shellsplit
else
begin
diff --git a/lib/rubygems/gem_runner.rb b/lib/rubygems/gem_runner.rb
index a366745..55b5a7d 100644
--- a/lib/rubygems/gem_runner.rb
+++ b/lib/rubygems/gem_runner.rb
@@ -5,9 +5,9 @@
# See LICENSE.txt for permissions.
#++
-require 'rubygems'
-require 'rubygems/command_manager'
-require 'rubygems/deprecate'
+require_relative '../rubygems'
+require_relative 'command_manager'
+require_relative 'deprecate'
##
# Load additional plugins from $LOAD_PATH
diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb
index 3687e77..0968e1a 100644
--- a/lib/rubygems/gemcutter_utilities.rb
+++ b/lib/rubygems/gemcutter_utilities.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'rubygems/remote_fetcher'
-require 'rubygems/text'
+require_relative 'remote_fetcher'
+require_relative 'text'
##
# Utility methods for using the RubyGems API.
@@ -31,7 +31,8 @@ module Gem::GemcutterUtilities
def add_otp_option
add_option('--otp CODE',
- 'Digit code for multifactor authentication') do |value, options|
+ 'Digit code for multifactor authentication',
+ 'You can also use the environment variable GEM_HOST_OTP_CODE') do |value, options|
options[:otp] = value
end
end
@@ -52,6 +53,13 @@ module Gem::GemcutterUtilities
end
##
+ # The OTP code from the command options or from the user's configuration.
+
+ def otp
+ options[:otp] || ENV["GEM_HOST_OTP_CODE"]
+ end
+
+ ##
# The host to connect to either from the RUBYGEMS_HOST environment variable
# or from the user's configuration
@@ -126,7 +134,7 @@ module Gem::GemcutterUtilities
response = rubygems_api_request(:put, "api/v1/api_key",
sign_in_host, scope: scope) do |request|
request.basic_auth email, password
- request["OTP"] = options[:otp] if options[:otp]
+ request["OTP"] = otp if otp
request.body = URI.encode_www_form({:api_key => api_key }.merge(update_scope_params))
end
@@ -159,7 +167,7 @@ module Gem::GemcutterUtilities
response = rubygems_api_request(:post, "api/v1/api_key",
sign_in_host, scope: scope) do |request|
request.basic_auth email, password
- request["OTP"] = options[:otp] if options[:otp]
+ request["OTP"] = otp if otp
request.body = URI.encode_www_form({ name: key_name }.merge(scope_params))
end
@@ -224,7 +232,7 @@ module Gem::GemcutterUtilities
request_method = Net::HTTP.const_get method.to_s.capitalize
Gem::RemoteFetcher.fetcher.request(uri, request_method) do |req|
- req["OTP"] = options[:otp] if options[:otp]
+ req["OTP"] = otp if otp
block.call(req)
end
end
diff --git a/lib/rubygems/indexer.rb b/lib/rubygems/indexer.rb
index e595459..6e8dade 100644
--- a/lib/rubygems/indexer.rb
+++ b/lib/rubygems/indexer.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'rubygems'
-require 'rubygems/package'
+require_relative '../rubygems'
+require_relative 'package'
require 'tmpdir'
##
diff --git a/lib/rubygems/install_default_message.rb b/lib/rubygems/install_default_message.rb
index f68fd2f..052ef52 100644
--- a/lib/rubygems/install_default_message.rb
+++ b/lib/rubygems/install_default_message.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'rubygems'
-require 'rubygems/user_interaction'
+require_relative '../rubygems'
+require_relative 'user_interaction'
##
# A post-install hook that displays "Successfully installed
diff --git a/lib/rubygems/install_message.rb b/lib/rubygems/install_message.rb
index 3c13888..861ead3 100644
--- a/lib/rubygems/install_message.rb
+++ b/lib/rubygems/install_message.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require 'rubygems'
-require 'rubygems/user_interaction'
+require_relative '../rubygems'
+require_relative 'user_interaction'
##
# A default post-install hook that displays "Successfully installed
diff --git a/lib/rubygems/install_update_options.rb b/lib/rubygems/install_update_options.rb
index 54a3950..cafa635 100644
--- a/lib/rubygems/install_update_options.rb
+++ b/lib/rubygems/install_update_options.rb
@@ -5,8 +5,8 @@
# See LICENSE.txt for permissions.
#++
-require 'rubygems'
-require 'rubygems/security_option'
+require_relative '../rubygems'
+require_relative 'security_option'
##
# Mixin methods for install and update options for Gem::Commands
diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb
index 7af5105..cf5ed7b 100644
--- a/lib/rubygems/installer.rb
+++ b/lib/rubygems/installer.rb
@@ -5,13 +5,13 @@
# See LICENSE.txt for permissions.
#++
-require 'rubygems/command'
-require 'rubygems/installer_uninstaller_utils'
-require 'rubygems/exceptions'
-require 'rubygems/deprecate'
-require 'rubygems/package'
-require 'rubygems/ext'
-require 'rubygems/user_interaction'
+require_relative 'command'
+require_relative 'installer_uninstaller_utils'
+require_relative 'exceptions'
+require_relative 'deprecate'
+require_relative 'package'
+require_relative 'ext'
+require_relative 'user_interaction'
##
# The installer installs the files contained in the .gem into the Gem.home.
@@ -68,7 +68,7 @@ class Gem::Installer
@path_warning = false
- @install_lock = Mutex.new
+ @install_lock = Thread::Mutex.new
class << self
##
@@ -728,6 +728,10 @@ class Gem::Installer
raise Gem::InstallError, "#{spec} has an invalid extensions"
end
+ if spec.platform.to_s =~ /\R/
+ raise Gem::InstallError, "#{spec.platform} is an invalid platform"
+ end
+
unless spec.specification_version.to_s =~ /\A\d+\z/
raise Gem::InstallError, "#{spec} has an invalid specification_version"
end
@@ -757,7 +761,7 @@ class Gem::Installer
#
require 'rubygems'
-
+#{gemdeps_load(spec.name)}
version = "#{Gem::Requirement.default_prerelease}"
str = ARGV.first
@@ -778,6 +782,15 @@ end
TEXT
end
+ def gemdeps_load(name)
+ return '' if name == "bundler"
+
+ <<-TEXT
+
+Gem.use_gemdeps
+TEXT
+ end
+
##
# return the stub script text used to launch the true Ruby script
diff --git a/lib/rubygems/local_remote_options.rb b/lib/rubygems/local_remote_options.rb
index 2d0509e..8acd98d 100644
--- a/lib/rubygems/local_remote_options.rb
+++ b/lib/rubygems/local_remote_options.rb
@@ -6,7 +6,7 @@
#++
require 'uri'
-require 'rubygems'
+require_relative '../rubygems'
##
# Mixin methods for local and remote Gem::Command options.
diff --git a/lib/rubygems/mock_gem_ui.rb b/lib/rubygems/mock_gem_ui.rb
index ec244fb..914ecb9 100644
--- a/lib/rubygems/mock_gem_ui.rb
+++ b/lib/rubygems/mock_gem_ui.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'rubygems/user_interaction'
+require_relative 'user_interaction'
##
# This Gem::StreamUI subclass records input and output to StringIO for
diff --git a/lib/rubygems/name_tuple.rb b/lib/rubygems/name_tuple.rb
index 3d0afa3..c732d7f 100644
--- a/lib/rubygems/name_tuple.rb
+++ b/lib/rubygems/name_tuple.rb
@@ -89,9 +89,8 @@ class Gem::NameTuple
alias to_s inspect # :nodoc:
def <=>(other)
- [@name, @version, @platform == Gem::Platform::RUBY ? -1 : 1] <=>
- [other.name, other.version,
- other.platform == Gem::Platform::RUBY ? -1 : 1]
+ [@name, @version, Gem::Platform.sort_priority(@platform)] <=>
+ [other.name, other.version, Gem::Platform.sort_priority(other.platform)]
end
include Comparable
diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb
index a4ae3e9..c4b29e4 100644
--- a/lib/rubygems/package.rb
+++ b/lib/rubygems/package.rb
@@ -41,9 +41,9 @@
# #files are the files in the .gem tar file, not the Ruby files in the gem
# #extract_files and #contents automatically call #verify
-require "rubygems"
-require 'rubygems/security'
-require 'rubygems/user_interaction'
+require_relative "../rubygems"
+require_relative 'security'
+require_relative 'user_interaction'
class Gem::Package
include Gem::UserInteraction
@@ -702,12 +702,12 @@ EOM
end
end
-require 'rubygems/package/digest_io'
-require 'rubygems/package/source'
-require 'rubygems/package/file_source'
-require 'rubygems/package/io_source'
-require 'rubygems/package/old'
-require 'rubygems/package/tar_header'
-require 'rubygems/package/tar_reader'
-require 'rubygems/package/tar_reader/entry'
-require 'rubygems/package/tar_writer'
+require_relative 'package/digest_io'
+require_relative 'package/source'
+require_relative 'package/file_source'
+require_relative 'package/io_source'
+require_relative 'package/old'
+require_relative 'package/tar_header'
+require_relative 'package/tar_reader'
+require_relative 'package/tar_reader/entry'
+require_relative 'package/tar_writer'
diff --git a/lib/rubygems/package/io_source.rb b/lib/rubygems/package/io_source.rb
index 7d73831..03d7714 100644
--- a/lib/rubygems/package/io_source.rb
+++ b/lib/rubygems/package/io_source.rb
@@ -32,10 +32,14 @@ class Gem::Package::IOSource < Gem::Package::Source # :nodoc: all
def with_read_io
yield io
+ ensure
+ io.rewind
end
def with_write_io
yield io
+ ensure
+ io.rewind
end
def path
diff --git a/lib/rubygems/package/tar_reader.rb b/lib/rubygems/package/tar_reader.rb
index e7c5620..41121f3 100644
--- a/lib/rubygems/package/tar_reader.rb
+++ b/lib/rubygems/package/tar_reader.rb
@@ -121,4 +121,4 @@ class Gem::Package::TarReader
end
end
-require 'rubygems/package/tar_reader/entry'
+require_relative 'tar_reader/entry'
diff --git a/lib/rubygems/package_task.rb b/lib/rubygems/package_task.rb
index d5a2885..bb48616 100644
--- a/lib/rubygems/package_task.rb
+++ b/lib/rubygems/package_task.rb
@@ -20,8 +20,8 @@
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-require 'rubygems'
-require 'rubygems/package'
+require_relative '../rubygems'
+require_relative 'package'
require 'rake/packagetask'
##
diff --git a/lib/rubygems/path_support.rb b/lib/rubygems/path_support.rb
index 8103caf..d601e65 100644
--- a/lib/rubygems/path_support.rb
+++ b/lib/rubygems/path_support.rb
@@ -72,12 +72,7 @@ class Gem::PathSupport
# Return the default Gem path
def default_path
- gem_path = Gem.default_path + [@home]
-
- if defined?(APPLE_GEM_HOME)
- gem_path << APPLE_GEM_HOME
- end
- gem_path
+ Gem.default_path + [@home]
end
def expand(path)
diff --git a/lib/rubygems/platform.rb b/lib/rubygems/platform.rb
index fd1c0a6..a5e65f9 100644
--- a/lib/rubygems/platform.rb
+++ b/lib/rubygems/platform.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require "rubygems/deprecate"
+require_relative "deprecate"
##
# Available list of platforms for targeting Gem installations.
@@ -40,6 +40,10 @@ class Gem::Platform
match_platforms?(platform, Gem.platforms)
end
+ def self.sort_priority(platform)
+ platform == Gem::Platform::RUBY ? -1 : 1
+ end
+
def self.installable?(spec)
if spec.respond_to? :installable_platform?
spec.installable_platform?
@@ -100,6 +104,7 @@ class Gem::Platform
when /^dotnet([\d.]*)/ then [ 'dotnet', $1 ]
when /linux-?((?!gnu)\w+)?/ then [ 'linux', $1 ]
when /mingw32/ then [ 'mingw32', nil ]
+ when /mingw-?(\w+)?/ then [ 'mingw', $1 ]
when /(mswin\d+)(\_(\d+))?/ then
os, version = $1, $3
@cpu = 'x86' if @cpu.nil? and os =~ /32$/
diff --git a/lib/rubygems/rdoc.rb b/lib/rubygems/rdoc.rb
index c40bb7d..ac5e8f0 100644
--- a/lib/rubygems/rdoc.rb
+++ b/lib/rubygems/rdoc.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'rubygems'
+require_relative '../rubygems'
begin
require 'rdoc/rubygems_hook'
diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb
index e3d4bfb..0724a51 100644
--- a/lib/rubygems/remote_fetcher.rb
+++ b/lib/rubygems/remote_fetcher.rb
@@ -1,12 +1,11 @@
# frozen_string_literal: true
-require 'rubygems'
-require 'rubygems/request'
-require 'rubygems/request/connection_pools'
-require 'rubygems/s3_uri_signer'
-require 'rubygems/uri_formatter'
-require 'rubygems/uri_parsing'
-require 'rubygems/user_interaction'
-require 'resolv'
+require_relative '../rubygems'
+require_relative 'request'
+require_relative 'request/connection_pools'
+require_relative 's3_uri_signer'
+require_relative 'uri_formatter'
+require_relative 'uri'
+require_relative 'user_interaction'
##
# RemoteFetcher handles the details of fetching gems and gem information from
@@ -14,30 +13,24 @@ require 'resolv'
class Gem::RemoteFetcher
include Gem::UserInteraction
- include Gem::UriParsing
##
# A FetchError exception wraps up the various possible IO and HTTP failures
# that could happen while downloading from the internet.
class FetchError < Gem::Exception
- include Gem::UriParsing
-
##
# The URI which was being accessed when the exception happened.
attr_accessor :uri, :original_uri
def initialize(message, uri)
- super message
-
- uri = parse_uri(uri)
-
- @original_uri = uri.dup
+ uri = Gem::Uri.new(uri)
- uri.password = 'REDACTED' if uri.respond_to?(:password) && uri.password
+ super uri.redact_credentials_from(message)
- @uri = uri.to_s
+ @original_uri = uri.to_s
+ @uri = uri.redacted.to_s
end
def to_s # :nodoc:
@@ -88,7 +81,7 @@ class Gem::RemoteFetcher
@proxy = proxy
@pools = {}
- @pool_lock = Mutex.new
+ @pool_lock = Thread::Mutex.new
@cert_files = Gem::Request.get_cert_files
@headers = headers
@@ -133,7 +126,7 @@ class Gem::RemoteFetcher
require "fileutils"
FileUtils.mkdir_p cache_dir rescue nil unless File.exist? cache_dir
- source_uri = parse_uri(source_uri)
+ source_uri = Gem::Uri.new(source_uri)
scheme = source_uri.scheme
@@ -228,7 +221,7 @@ class Gem::RemoteFetcher
unless location = response['Location']
raise FetchError.new("redirecting but no redirect location was given", uri)
end
- location = parse_uri location
+ location = Gem::Uri.new location
if https?(uri) && !https?(location)
raise FetchError.new("redirecting to non-https resource: #{location}", uri)
@@ -246,7 +239,7 @@ class Gem::RemoteFetcher
# Downloads +uri+ and returns it as a String.
def fetch_path(uri, mtime = nil, head = false)
- uri = parse_uri uri
+ uri = Gem::Uri.new uri
unless uri.scheme
raise ArgumentError, "uri scheme is invalid: #{uri.scheme.inspect}"
diff --git a/lib/rubygems/request.rb b/lib/rubygems/request.rb
index 1ed0fbc..72e25e2 100644
--- a/lib/rubygems/request.rb
+++ b/lib/rubygems/request.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
require 'net/http'
-require 'rubygems/user_interaction'
+require_relative 'user_interaction'
class Gem::Request
extend Gem::UserInteraction
@@ -44,7 +44,7 @@ class Gem::Request
end
def self.configure_connection_for_https(connection, cert_files)
- raise Gem::Exception.new('OpenSSl is not available. Install OpenSSL and rebuild Ruby (preferred) or use non-HTTPS sources') unless Gem::HAVE_OPENSSL
+ raise Gem::Exception.new('OpenSSL is not available. Install OpenSSL and rebuild Ruby (preferred) or use non-HTTPS sources') unless Gem::HAVE_OPENSSL
connection.use_ssl = true
connection.verify_mode =
@@ -191,7 +191,7 @@ class Gem::Request
begin
@requests[connection.object_id] += 1
- verbose "#{request.method} #{@uri}"
+ verbose "#{request.method} #{Gem::Uri.new(@uri).redacted}"
file_name = File.basename(@uri.path)
# perform download progress reporter only for gems
@@ -287,6 +287,6 @@ class Gem::Request
end
end
-require 'rubygems/request/http_pool'
-require 'rubygems/request/https_pool'
-require 'rubygems/request/connection_pools'
+require_relative 'request/http_pool'
+require_relative 'request/https_pool'
+require_relative 'request/connection_pools'
diff --git a/lib/rubygems/request/connection_pools.rb b/lib/rubygems/request/connection_pools.rb
index 7f39889..a4c2929 100644
--- a/lib/rubygems/request/connection_pools.rb
+++ b/lib/rubygems/request/connection_pools.rb
@@ -11,7 +11,7 @@ class Gem::Request::ConnectionPools # :nodoc:
@proxy_uri = proxy_uri
@cert_files = cert_files
@pools = {}
- @pool_mutex = Mutex.new
+ @pool_mutex = Thread::Mutex.new
end
def pool_for(uri)
diff --git a/lib/rubygems/request/http_pool.rb b/lib/rubygems/request/http_pool.rb
index 9985bba..f028516 100644
--- a/lib/rubygems/request/http_pool.rb
+++ b/lib/rubygems/request/http_pool.rb
@@ -12,7 +12,7 @@ class Gem::Request::HTTPPool # :nodoc:
@http_args = http_args
@cert_files = cert_files
@proxy_uri = proxy_uri
- @queue = SizedQueue.new 1
+ @queue = Thread::SizedQueue.new 1
@queue << nil
end
diff --git a/lib/rubygems/request_set.rb b/lib/rubygems/request_set.rb
index 5190cfc..9286c54 100644
--- a/lib/rubygems/request_set.rb
+++ b/lib/rubygems/request_set.rb
@@ -151,7 +151,7 @@ class Gem::RequestSet
@prerelease = options[:prerelease]
requests = []
- download_queue = Queue.new
+ download_queue = Thread::Queue.new
# Create a thread-safe list of gems to download
sorted_requests.each do |req|
@@ -303,7 +303,7 @@ class Gem::RequestSet
end
end
- require "rubygems/dependency_installer"
+ require_relative "dependency_installer"
inst = Gem::DependencyInstaller.new options
inst.installed_gems.replace specs
@@ -461,6 +461,6 @@ class Gem::RequestSet
end
end
-require 'rubygems/request_set/gem_dependency_api'
-require 'rubygems/request_set/lockfile'
-require 'rubygems/request_set/lockfile/tokenizer'
+require_relative 'request_set/gem_dependency_api'
+require_relative 'request_set/lockfile'
+require_relative 'request_set/lockfile/tokenizer'
diff --git a/lib/rubygems/request_set/lockfile.rb b/lib/rubygems/request_set/lockfile.rb
index 8f8f142..bec29ef 100644
--- a/lib/rubygems/request_set/lockfile.rb
+++ b/lib/rubygems/request_set/lockfile.rb
@@ -236,4 +236,4 @@ class Gem::RequestSet::Lockfile
end
end
-require 'rubygems/request_set/lockfile/tokenizer'
+require_relative 'lockfile/tokenizer'
diff --git a/lib/rubygems/request_set/lockfile/tokenizer.rb b/lib/rubygems/request_set/lockfile/tokenizer.rb
index 6918e8e..cb8030c 100644
--- a/lib/rubygems/request_set/lockfile/tokenizer.rb
+++ b/lib/rubygems/request_set/lockfile/tokenizer.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'rubygems/request_set/lockfile/parser'
+require_relative 'parser'
class Gem::RequestSet::Lockfile::Tokenizer
Token = Struct.new :type, :value, :column, :line
diff --git a/lib/rubygems/requirement.rb b/lib/rubygems/requirement.rb
index 6721de4..d2e28fa 100644
--- a/lib/rubygems/requirement.rb
+++ b/lib/rubygems/requirement.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require "rubygems/deprecate"
+require_relative "deprecate"
##
# A Requirement is a set of one or more version restrictions. It supports a
@@ -194,24 +194,19 @@ class Gem::Requirement
end
def marshal_dump # :nodoc:
- fix_syck_default_key_in_requirements
-
[@requirements]
end
def marshal_load(array) # :nodoc:
@requirements = array[0]
- fix_syck_default_key_in_requirements
+ raise TypeError, "wrong @requirements" unless Array === @requirements
end
def yaml_initialize(tag, vals) # :nodoc:
vals.each do |ivar, val|
instance_variable_set "@#{ivar}", val
end
-
- Gem.load_yaml
- fix_syck_default_key_in_requirements
end
def init_with(coder) # :nodoc:
@@ -246,8 +241,7 @@ class Gem::Requirement
def satisfied_by?(version)
raise ArgumentError, "Need a Gem::Version: #{version.inspect}" unless
Gem::Version === version
- # #28965: syck has a bug with unquoted '=' YAML.loading as YAML::DefaultKey
- requirements.all? {|op, rv| (OPS[op] || OPS["="]).call version, rv }
+ requirements.all? {|op, rv| OPS[op].call version, rv }
end
alias :=== :satisfied_by?
@@ -289,19 +283,6 @@ class Gem::Requirement
def _tilde_requirements
@_tilde_requirements ||= _sorted_requirements.select {|r| r.first == "~>" }
end
-
- private
-
- def fix_syck_default_key_in_requirements # :nodoc:
- Gem.load_yaml
-
- # Fixup the Syck DefaultKey bug
- @requirements.each do |r|
- if r[0].kind_of? Gem::SyckDefaultKey
- r[0] = "="
- end
- end
- end
end
class Gem::Version
diff --git a/lib/rubygems/resolver.rb b/lib/rubygems/resolver.rb
index 71c35ea..51a11fe 100644
--- a/lib/rubygems/resolver.rb
+++ b/lib/rubygems/resolver.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true
-require 'rubygems/dependency'
-require 'rubygems/exceptions'
-require 'rubygems/util/list'
+require_relative 'dependency'
+require_relative 'exceptions'
+require_relative 'util/list'
##
# Given a set of Gem::Dependency objects as +needed+ and a way to query the
@@ -10,7 +10,7 @@ require 'rubygems/util/list'
# all the requirements.
class Gem::Resolver
- require 'rubygems/resolver/molinillo'
+ require_relative 'resolver/molinillo'
##
# If the DEBUG_RESOLVER environment variable is set then debugging mode is
@@ -318,30 +318,30 @@ class Gem::Resolver
private :amount_constrained
end
-require 'rubygems/resolver/activation_request'
-require 'rubygems/resolver/conflict'
-require 'rubygems/resolver/dependency_request'
-require 'rubygems/resolver/requirement_list'
-require 'rubygems/resolver/stats'
-
-require 'rubygems/resolver/set'
-require 'rubygems/resolver/api_set'
-require 'rubygems/resolver/composed_set'
-require 'rubygems/resolver/best_set'
-require 'rubygems/resolver/current_set'
-require 'rubygems/resolver/git_set'
-require 'rubygems/resolver/index_set'
-require 'rubygems/resolver/installer_set'
-require 'rubygems/resolver/lock_set'
-require 'rubygems/resolver/vendor_set'
-require 'rubygems/resolver/source_set'
-
-require 'rubygems/resolver/specification'
-require 'rubygems/resolver/spec_specification'
-require 'rubygems/resolver/api_specification'
-require 'rubygems/resolver/git_specification'
-require 'rubygems/resolver/index_specification'
-require 'rubygems/resolver/installed_specification'
-require 'rubygems/resolver/local_specification'
-require 'rubygems/resolver/lock_specification'
-require 'rubygems/resolver/vendor_specification'
+require_relative 'resolver/activation_request'
+require_relative 'resolver/conflict'
+require_relative 'resolver/dependency_request'
+require_relative 'resolver/requirement_list'
+require_relative 'resolver/stats'
+
+require_relative 'resolver/set'
+require_relative 'resolver/api_set'
+require_relative 'resolver/composed_set'
+require_relative 'resolver/best_set'
+require_relative 'resolver/current_set'
+require_relative 'resolver/git_set'
+require_relative 'resolver/index_set'
+require_relative 'resolver/installer_set'
+require_relative 'resolver/lock_set'
+require_relative 'resolver/vendor_set'
+require_relative 'resolver/source_set'
+
+require_relative 'resolver/specification'
+require_relative 'resolver/spec_specification'
+require_relative 'resolver/api_specification'
+require_relative 'resolver/git_specification'
+require_relative 'resolver/index_specification'
+require_relative 'resolver/installed_specification'
+require_relative 'resolver/local_specification'
+require_relative 'resolver/lock_specification'
+require_relative 'resolver/vendor_specification'
diff --git a/lib/rubygems/resolver/git_specification.rb b/lib/rubygems/resolver/git_specification.rb
index 555dcff..ee47080 100644
--- a/lib/rubygems/resolver/git_specification.rb
+++ b/lib/rubygems/resolver/git_specification.rb
@@ -21,7 +21,7 @@ class Gem::Resolver::GitSpecification < Gem::Resolver::SpecSpecification
# the executables.
def install(options = {})
- require 'rubygems/installer'
+ require_relative '../installer'
installer = Gem::Installer.for_spec spec, options
diff --git a/lib/rubygems/resolver/installer_set.rb b/lib/rubygems/resolver/installer_set.rb
index 6018131..237bc3f 100644
--- a/lib/rubygems/resolver/installer_set.rb
+++ b/lib/rubygems/resolver/installer_set.rb
@@ -71,17 +71,17 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set
end
found = found.sort_by do |s|
- [s.version, s.platform == Gem::Platform::RUBY ? -1 : 1]
+ [s.version, Gem::Platform.sort_priority(s.platform)]
end
newest = found.last
unless @force
- found_matching_metadata = found.select do |spec|
+ found_matching_metadata = found.reverse.find do |spec|
metadata_satisfied?(spec)
end
- if found_matching_metadata.empty?
+ if found_matching_metadata.nil?
if newest
ensure_required_ruby_version_met(newest.spec)
ensure_required_rubygems_version_met(newest.spec)
@@ -92,7 +92,7 @@ class Gem::Resolver::InstallerSet < Gem::Resolver::Set
raise exc
end
else
- newest = found_matching_metadata.last
+ newest = found_matching_metadata
end
end
diff --git a/lib/rubygems/resolver/molinillo.rb b/lib/rubygems/resolver/molinillo.rb
index 2357f41..12ca740 100644
--- a/lib/rubygems/resolver/molinillo.rb
+++ b/lib/rubygems/resolver/molinillo.rb
@@ -1,2 +1,2 @@
# frozen_string_literal: true
-require 'rubygems/resolver/molinillo/lib/molinillo'
+require_relative 'molinillo/lib/molinillo'
diff --git a/lib/rubygems/resolver/set.rb b/lib/rubygems/resolver/set.rb
index 8046e18..5d8dd51 100644
--- a/lib/rubygems/resolver/set.rb
+++ b/lib/rubygems/resolver/set.rb
@@ -20,7 +20,6 @@ class Gem::Resolver::Set
attr_accessor :prerelease
def initialize # :nodoc:
- require 'uri'
@prerelease = false
@remote = true
@errors = []
diff --git a/lib/rubygems/resolver/specification.rb b/lib/rubygems/resolver/specification.rb
index 8c6fc9a..dfcb7eb 100644
--- a/lib/rubygems/resolver/specification.rb
+++ b/lib/rubygems/resolver/specification.rb
@@ -93,7 +93,7 @@ class Gem::Resolver::Specification
# specification.
def install(options = {})
- require 'rubygems/installer'
+ require_relative '../installer'
gem = download options
diff --git a/lib/rubygems/s3_uri_signer.rb b/lib/rubygems/s3_uri_signer.rb
index f1f9229..bba9afc 100644
--- a/lib/rubygems/s3_uri_signer.rb
+++ b/lib/rubygems/s3_uri_signer.rb
@@ -1,4 +1,3 @@
-require 'base64'
require 'digest'
require 'rubygems/openssl'
diff --git a/lib/rubygems/safe_yaml.rb b/lib/rubygems/safe_yaml.rb
index 29312ad..e905052 100644
--- a/lib/rubygems/safe_yaml.rb
+++ b/lib/rubygems/safe_yaml.rb
@@ -17,8 +17,6 @@ module Gem
Gem::Specification
Gem::Version
Gem::Version::Requirement
- YAML::Syck::DefaultKey
- Syck::DefaultKey
].freeze
PERMITTED_SYMBOLS = %w[
diff --git a/lib/rubygems/security.rb b/lib/rubygems/security.rb
index c80639a..28f7055 100644
--- a/lib/rubygems/security.rb
+++ b/lib/rubygems/security.rb
@@ -5,7 +5,7 @@
# See LICENSE.txt for permissions.
#++
-require 'rubygems/exceptions'
+require_relative 'exceptions'
require_relative 'openssl'
##
@@ -592,9 +592,9 @@ module Gem::Security
end
if Gem::HAVE_OPENSSL
- require 'rubygems/security/policy'
- require 'rubygems/security/policies'
- require 'rubygems/security/trust_dir'
+ require_relative 'security/policy'
+ require_relative 'security/policies'
+ require_relative 'security/trust_dir'
end
-require 'rubygems/security/signer'
+require_relative 'security/signer'
diff --git a/lib/rubygems/security/policy.rb b/lib/rubygems/security/policy.rb
index 7629d64..9683e55 100644
--- a/lib/rubygems/security/policy.rb
+++ b/lib/rubygems/security/policy.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'rubygems/user_interaction'
+require_relative '../user_interaction'
##
# A Gem::Security::Policy object encapsulates the settings for verifying
diff --git a/lib/rubygems/security/signer.rb b/lib/rubygems/security/signer.rb
index 6c85ab0..c5c2c4f 100644
--- a/lib/rubygems/security/signer.rb
+++ b/lib/rubygems/security/signer.rb
@@ -2,7 +2,7 @@
##
# Basic OpenSSL-based package signing class.
-require "rubygems/user_interaction"
+require_relative "../user_interaction"
class Gem::Security::Signer
include Gem::UserInteraction
diff --git a/lib/rubygems/security_option.rb b/lib/rubygems/security_option.rb
index 3403aaa..6c75d6e 100644
--- a/lib/rubygems/security_option.rb
+++ b/lib/rubygems/security_option.rb
@@ -5,7 +5,7 @@
# See LICENSE.txt for permissions.
#++
-require 'rubygems'
+require_relative '../rubygems'
# forward-declare
@@ -20,7 +20,7 @@ end
module Gem::SecurityOption
def add_security_option
OptionParser.accept Gem::Security::Policy do |value|
- require 'rubygems/security'
+ require_relative 'security'
raise OptionParser::InvalidArgument, 'OpenSSL not installed' unless
defined?(Gem::Security::HighSecurity)
diff --git a/lib/rubygems/server.rb b/lib/rubygems/server.rb
index 2c2805f..45be05b 100644
--- a/lib/rubygems/server.rb
+++ b/lib/rubygems/server.rb
@@ -3,8 +3,8 @@ require 'zlib'
require 'erb'
require 'uri'
-require 'rubygems'
-require 'rubygems/rdoc'
+require_relative '../rubygems'
+require_relative 'rdoc'
##
# Gem::Server and allows users to serve gems for consumption by
diff --git a/lib/rubygems/source.rb b/lib/rubygems/source.rb
index 37e03cd..a9d91ed 100644
--- a/lib/rubygems/source.rb
+++ b/lib/rubygems/source.rb
@@ -240,9 +240,9 @@ class Gem::Source
end
end
-require 'rubygems/source/git'
-require 'rubygems/source/installed'
-require 'rubygems/source/specific_file'
-require 'rubygems/source/local'
-require 'rubygems/source/lock'
-require 'rubygems/source/vendor'
+require_relative 'source/git'
+require_relative 'source/installed'
+require_relative 'source/specific_file'
+require_relative 'source/local'
+require_relative 'source/lock'
+require_relative 'source/vendor'
diff --git a/lib/rubygems/spec_fetcher.rb b/lib/rubygems/spec_fetcher.rb
index b2bcadc..68ff605 100644
--- a/lib/rubygems/spec_fetcher.rb
+++ b/lib/rubygems/spec_fetcher.rb
@@ -1,9 +1,9 @@
# frozen_string_literal: true
-require 'rubygems/remote_fetcher'
-require 'rubygems/user_interaction'
-require 'rubygems/errors'
-require 'rubygems/text'
-require 'rubygems/name_tuple'
+require_relative 'remote_fetcher'
+require_relative 'user_interaction'
+require_relative 'errors'
+require_relative 'text'
+require_relative 'name_tuple'
##
# SpecFetcher handles metadata updates from remote gem repositories.
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index 7206c3e..7ed9634 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -6,11 +6,11 @@
# See LICENSE.txt for permissions.
#++
-require 'rubygems/deprecate'
-require 'rubygems/basic_specification'
-require 'rubygems/stub_specification'
-require 'rubygems/specification_policy'
-require 'rubygems/util/list'
+require_relative 'deprecate'
+require_relative 'basic_specification'
+require_relative 'stub_specification'
+require_relative 'specification_policy'
+require_relative 'util/list'
##
# The Specification class contains the information for a gem. Typically
@@ -105,7 +105,7 @@ class Gem::Specification < Gem::BasicSpecification
# rubocop:disable Style/MutableConstant
LOAD_CACHE = {} # :nodoc:
# rubocop:enable Style/MutableConstant
- LOAD_CACHE_MUTEX = Mutex.new
+ LOAD_CACHE_MUTEX = Thread::Mutex.new
private_constant :LOAD_CACHE if defined? private_constant
@@ -855,7 +855,7 @@ class Gem::Specification < Gem::BasicSpecification
next names if names.nonzero?
versions = b.version <=> a.version
next versions if versions.nonzero?
- b.platform == Gem::Platform::RUBY ? -1 : 1
+ Gem::Platform.sort_priority(b.platform)
end
end
@@ -1568,9 +1568,9 @@ class Gem::Specification < Gem::BasicSpecification
unresolved_deps = Gem::Specification.unresolved_deps.dup
Gem::Specification.unresolved_deps.clear
- require 'rubygems/config_file'
- require 'rubygems/ext'
- require 'rubygems/user_interaction'
+ require_relative 'config_file'
+ require_relative 'ext'
+ require_relative 'user_interaction'
ui = Gem::SilentUI.new
Gem::DefaultUserInteraction.use_ui ui do
@@ -1690,12 +1690,6 @@ class Gem::Specification < Gem::BasicSpecification
when String then
if DateTimeFormat =~ date
Time.utc($1.to_i, $2.to_i, $3.to_i)
-
- # Workaround for where the date format output from psych isn't
- # parsed as a Time object by syck and thus comes through as a
- # string.
- elsif /\A(\d{4})-(\d{2})-(\d{2}) \d{2}:\d{2}:\d{2}\.\d+?Z\z/ =~ date
- Time.utc($1.to_i, $2.to_i, $3.to_i)
else
raise(Gem::InvalidSpecificationException,
"invalid date format in specification: #{date.inspect}")
@@ -2339,7 +2333,7 @@ class Gem::Specification < Gem::BasicSpecification
# Returns an object you can use to sort specifications in #sort_by.
def sort_obj
- [@name, @version, @new_platform == Gem::Platform::RUBY ? -1 : 1]
+ [@name, @version, Gem::Platform.sort_priority(@new_platform)]
end
##
@@ -2421,7 +2415,6 @@ class Gem::Specification < Gem::BasicSpecification
# still have their default values are omitted.
def to_ruby
- require_relative 'openssl'
mark_version
result = []
result << "# -*- encoding: utf-8 -*-"
@@ -2455,16 +2448,21 @@ class Gem::Specification < Gem::BasicSpecification
:has_rdoc,
:default_executable,
:metadata,
+ :signing_key,
]
@@attributes.each do |attr_name|
next if handled.include? attr_name
current_value = self.send(attr_name)
if current_value != default_value(attr_name) || self.class.required_attribute?(attr_name)
- result << " s.#{attr_name} = #{ruby_code current_value}" unless defined?(OpenSSL::PKey::RSA) && current_value.is_a?(OpenSSL::PKey::RSA)
+ result << " s.#{attr_name} = #{ruby_code current_value}"
end
end
+ if String === signing_key
+ result << " s.signing_key = #{signing_key.dump}.freeze"
+ end
+
if @installed_by_version
result << nil
result << " s.installed_by_version = \"#{Gem::VERSION}\" if s.respond_to? :installed_by_version"
@@ -2527,7 +2525,7 @@ class Gem::Specification < Gem::BasicSpecification
# back, we have to check again here to make sure that our
# psych code was properly loaded, and load it if not.
unless Gem.const_defined?(:NoAliasYAMLTree)
- require 'rubygems/psych_tree'
+ require_relative 'psych_tree'
end
builder = Gem::NoAliasYAMLTree.create
diff --git a/lib/rubygems/specification_policy.rb b/lib/rubygems/specification_policy.rb
index 2b8b056..c30ec70 100644
--- a/lib/rubygems/specification_policy.rb
+++ b/lib/rubygems/specification_policy.rb
@@ -1,4 +1,4 @@
-require 'rubygems/user_interaction'
+require_relative 'user_interaction'
class Gem::SpecificationPolicy
include Gem::UserInteraction
@@ -124,25 +124,26 @@ class Gem::SpecificationPolicy
end
metadata.each do |key, value|
+ entry = "metadata['#{key}']"
if !key.kind_of?(String)
error "metadata keys must be a String"
end
if key.size > 128
- error "metadata key too large (#{key.size} > 128)"
+ error "metadata key is too large (#{key.size} > 128)"
end
if !value.kind_of?(String)
- error "metadata values must be a String"
+ error "#{entry} value must be a String"
end
if value.size > 1024
- error "metadata value too large (#{value.size} > 1024)"
+ error "#{entry} value is too large (#{value.size} > 1024)"
end
if METADATA_LINK_KEYS.include? key
if value !~ VALID_URI_PATTERN
- error "metadata['#{key}'] has invalid link: #{value.inspect}"
+ error "#{entry} has invalid link: #{value.inspect}"
end
end
end
@@ -380,7 +381,7 @@ http://spdx.org/licenses or '#{Gem::Licenses::NONSTANDARD}' for a nonstandard li
end
LAZY = '"FIxxxXME" or "TOxxxDO"'.gsub(/xxx/, '')
- LAZY_PATTERN = /FI XME|TO DO/x.freeze
+ LAZY_PATTERN = /^FI XME|^TO DO/x.freeze
HOMEPAGE_URI_PATTERN = /\A[a-z][a-z\d+.-]*:/i.freeze
def validate_lazy_metadata
diff --git a/lib/rubygems/syck_hack.rb b/lib/rubygems/syck_hack.rb
deleted file mode 100644
index 051483e..0000000
--- a/lib/rubygems/syck_hack.rb
+++ /dev/null
@@ -1,77 +0,0 @@
-# frozen_string_literal: true
-# :stopdoc:
-
-# Hack to handle syck's DefaultKey bug
-#
-# This file is always loaded AFTER either syck or psych are already
-# loaded. It then looks at what constants are available and creates
-# a consistent view on all rubys.
-#
-# All this is so that there is always a YAML::Syck::DefaultKey
-# class no matter if the full yaml library has loaded or not.
-#
-
-module YAML # :nodoc:
- # In newer 1.9.2, there is a Syck toplevel constant instead of it
- # being underneath YAML. If so, reference it back under YAML as
- # well.
- if defined? ::Syck
- # for tests that change YAML::ENGINE
- # 1.8 does not support the second argument to const_defined?
- remove_const :Syck rescue nil
-
- Syck = ::Syck
-
- # JRuby's "Syck" is called "Yecht"
- elsif defined? YAML::Yecht
- Syck = YAML::Yecht
-
- # Otherwise, if there is no YAML::Syck, then we've got just psych
- # loaded, so lets define a stub for DefaultKey.
- elsif !defined? YAML::Syck
- module Syck
- class DefaultKey # :nodoc:
- end
- end
- end
-
- # Now that we've got something that is always here, define #to_s
- # so when code tries to use this, it at least just shows up like it
- # should.
- module Syck
- class DefaultKey
- remove_method :to_s rescue nil
-
- def to_s
- '='
- end
- end
- end
-
- SyntaxError = Error unless defined? SyntaxError
-end
-
-# Sometime in the 1.9 dev cycle, the Syck constant was moved from under YAML
-# to be a toplevel constant. So gemspecs created under these versions of Syck
-# will have references to Syck::DefaultKey.
-#
-# So we need to be sure that we reference Syck at the toplevel too so that
-# we can always load these kind of gemspecs.
-#
-if !defined?(Syck)
- Syck = YAML::Syck
-end
-
-# Now that we've got Syck setup in all the right places, store
-# a reference to the DefaultKey class inside Gem. We do this so that
-# if later on YAML, etc are redefined, we've still got a consistent
-# place to find the DefaultKey class for comparison.
-
-module Gem
- # for tests that change YAML::ENGINE
- remove_const :SyckDefaultKey if const_defined? :SyckDefaultKey
-
- SyckDefaultKey = YAML::Syck::DefaultKey
-end
-
-# :startdoc:
diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb
index 51ac349..11fb611 100644
--- a/lib/rubygems/uninstaller.rb
+++ b/lib/rubygems/uninstaller.rb
@@ -6,11 +6,11 @@
#++
require 'fileutils'
-require 'rubygems'
-require 'rubygems/installer_uninstaller_utils'
-require 'rubygems/dependency_list'
-require 'rubygems/rdoc'
-require 'rubygems/user_interaction'
+require_relative '../rubygems'
+require_relative 'installer_uninstaller_utils'
+require_relative 'dependency_list'
+require_relative 'rdoc'
+require_relative 'user_interaction'
##
# An Uninstaller.
@@ -70,6 +70,9 @@ class Gem::Uninstaller
# only add user directory if install_dir is not set
@user_install = false
@user_install = options[:user_install] unless options[:install_dir]
+
+ # Optimization: populated during #uninstall
+ @default_specs_matching_uninstall_params = []
end
##
@@ -98,10 +101,8 @@ class Gem::Uninstaller
default_specs, list = list.partition do |spec|
spec.default_gem?
end
-
- default_specs.each do |default_spec|
- say "Gem #{default_spec.full_name} cannot be uninstalled because it is a default gem"
- end
+ warn_cannot_uninstall_default_gems(default_specs - list)
+ @default_specs_matching_uninstall_params = default_specs
list, other_repo_specs = list.partition do |spec|
@gem_home == spec.base_dir or
@@ -261,7 +262,10 @@ class Gem::Uninstaller
safe_delete { FileUtils.rm_r gem }
- Gem::RDoc.new(spec).remove
+ begin
+ Gem::RDoc.new(spec).remove
+ rescue NameError
+ end
gemspec = spec.spec_file
@@ -270,7 +274,7 @@ class Gem::Uninstaller
end
safe_delete { FileUtils.rm_r gemspec }
- say "Successfully uninstalled #{spec.full_name}"
+ announce_deletion_of(spec)
Gem::Specification.reset
end
@@ -356,7 +360,7 @@ class Gem::Uninstaller
# of what it did for us to find rather than trying to recreate
# it again.
if @format_executable
- require 'rubygems/installer'
+ require_relative 'installer'
Gem::Installer.exec_format % File.basename(filename)
else
filename
@@ -373,4 +377,34 @@ class Gem::Uninstaller
raise e
end
+
+ private
+
+ def announce_deletion_of(spec)
+ name = spec.full_name
+ say "Successfully uninstalled #{name}"
+ if default_spec_matches?(spec)
+ say(
+ "There was both a regular copy and a default copy of #{name}. The " \
+ "regular copy was successfully uninstalled, but the default copy " \
+ "was left around because default gems can't be removed."
+ )
+ end
+ end
+
+ # @return true if the specs of any default gems are `==` to the given `spec`.
+ def default_spec_matches?(spec)
+ !default_specs_that_match(spec).empty?
+ end
+
+ # @return [Array] specs of default gems that are `==` to the given `spec`.
+ def default_specs_that_match(spec)
+ @default_specs_matching_uninstall_params.select {|default_spec| spec == default_spec }
+ end
+
+ def warn_cannot_uninstall_default_gems(specs)
+ specs.each do |spec|
+ say "Gem #{spec.full_name} cannot be uninstalled because it is a default gem"
+ end
+ end
end
diff --git a/lib/rubygems/uri.rb b/lib/rubygems/uri.rb
new file mode 100644
index 0000000..ba30fac
--- /dev/null
+++ b/lib/rubygems/uri.rb
@@ -0,0 +1,111 @@
+# frozen_string_literal: true
+
+##
+# The Uri handles rubygems source URIs.
+#
+
+class Gem::Uri
+ def initialize(source_uri)
+ @parsed_uri = parse(source_uri)
+ end
+
+ def redacted
+ return self unless valid_uri?
+
+ if token? || oauth_basic?
+ with_redacted_user
+ elsif password?
+ with_redacted_password
+ else
+ self
+ end
+ end
+
+ def to_s
+ @parsed_uri.to_s
+ end
+
+ def redact_credentials_from(text)
+ return text unless valid_uri? && password?
+
+ text.sub(password, 'REDACTED')
+ end
+
+ def method_missing(method_name, *args, &blk)
+ if @parsed_uri.respond_to?(method_name)
+ @parsed_uri.send(method_name, *args, &blk)
+ else
+ super
+ end
+ end
+
+ def respond_to_missing?(method_name, include_private = false)
+ @parsed_uri.respond_to?(method_name, include_private) || super
+ end
+
+ protected
+
+ # Add a protected reader for the cloned instance to access the original object's parsed uri
+ attr_reader :parsed_uri
+
+ private
+
+ ##
+ # Parses the #uri, raising if it's invalid
+
+ def parse!(uri)
+ require "uri"
+
+ raise URI::InvalidURIError unless uri
+
+ # Always escape URI's to deal with potential spaces and such
+ # It should also be considered that source_uri may already be
+ # a valid URI with escaped characters. e.g. "{DESede}" is encoded
+ # as "%7BDESede%7D". If this is escaped again the percentage
+ # symbols will be escaped.
+ begin
+ URI.parse(uri)
+ rescue URI::InvalidURIError
+ URI.parse(URI::DEFAULT_PARSER.escape(uri))
+ end
+ end
+
+ ##
+ # Parses the #uri, returning the original uri if it's invalid
+
+ def parse(uri)
+ return uri unless uri.is_a?(String)
+
+ parse!(uri)
+ rescue URI::InvalidURIError
+ uri
+ end
+
+ def with_redacted_user
+ clone.tap {|uri| uri.user = 'REDACTED' }
+ end
+
+ def with_redacted_password
+ clone.tap {|uri| uri.password = 'REDACTED' }
+ end
+
+ def valid_uri?
+ !@parsed_uri.is_a?(String)
+ end
+
+ def password?
+ !!password
+ end
+
+ def oauth_basic?
+ password == 'x-oauth-basic'
+ end
+
+ def token?
+ !user.nil? && password.nil?
+ end
+
+ def initialize_copy(original)
+ @parsed_uri = original.parsed_uri.clone
+ end
+end
diff --git a/lib/rubygems/uri_parser.rb b/lib/rubygems/uri_parser.rb
deleted file mode 100644
index f350ede..0000000
--- a/lib/rubygems/uri_parser.rb
+++ /dev/null
@@ -1,34 +0,0 @@
-# frozen_string_literal: true
-
-##
-# The UriParser handles parsing URIs.
-#
-
-class Gem::UriParser
- ##
- # Parses the #uri, raising if it's invalid
-
- def parse!(uri)
- raise URI::InvalidURIError unless uri
-
- # Always escape URI's to deal with potential spaces and such
- # It should also be considered that source_uri may already be
- # a valid URI with escaped characters. e.g. "{DESede}" is encoded
- # as "%7BDESede%7D". If this is escaped again the percentage
- # symbols will be escaped.
- begin
- URI.parse(uri)
- rescue URI::InvalidURIError
- URI.parse(URI::DEFAULT_PARSER.escape(uri))
- end
- end
-
- ##
- # Parses the #uri, returning the original uri if it's invalid
-
- def parse(uri)
- parse!(uri)
- rescue URI::InvalidURIError
- uri
- end
-end
diff --git a/lib/rubygems/uri_parsing.rb b/lib/rubygems/uri_parsing.rb
deleted file mode 100644
index 941d7e0..0000000
--- a/lib/rubygems/uri_parsing.rb
+++ /dev/null
@@ -1,23 +0,0 @@
-# frozen_string_literal: true
-
-require "rubygems/uri_parser"
-
-module Gem::UriParsing
-
- def parse_uri(source_uri)
- return source_uri unless source_uri.is_a?(String)
-
- uri_parser.parse(source_uri)
- end
-
- private :parse_uri
-
- def uri_parser
- require "uri"
-
- Gem::UriParser.new
- end
-
- private :uri_parser
-
-end
diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb
index 27a9957..0ab44fb 100644
--- a/lib/rubygems/user_interaction.rb
+++ b/lib/rubygems/user_interaction.rb
@@ -5,8 +5,8 @@
# See LICENSE.txt for permissions.
#++
-require 'rubygems/deprecate'
-require 'rubygems/text'
+require_relative 'deprecate'
+require_relative 'text'
##
# Module that defines the default UserInteraction. Any class including this
@@ -543,7 +543,7 @@ class Gem::StreamUI
# A progress reporter that behaves nicely with threaded downloading.
class ThreadedDownloadReporter
- MUTEX = Mutex.new
+ MUTEX = Thread::Mutex.new
##
# The current file name being displayed
diff --git a/lib/rubygems/util/licenses.rb b/lib/rubygems/util/licenses.rb
index 29bf310..8de5b11 100644
--- a/lib/rubygems/util/licenses.rb
+++ b/lib/rubygems/util/licenses.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
-require 'rubygems/text'
+require_relative '../text'
class Gem::Licenses
extend Gem::Text
@@ -18,6 +18,8 @@ class Gem::Licenses
AFL-2.1
AFL-3.0
AGPL-1.0
+ AGPL-1.0-only
+ AGPL-1.0-or-later
AGPL-3.0
AGPL-3.0-only
AGPL-3.0-or-later
@@ -25,6 +27,7 @@ class Gem::Licenses
AML
AMPAS
ANTLR-PD
+ ANTLR-PD-fallback
APAFML
APL-1.0
APSL-1.0
@@ -48,29 +51,41 @@ class Gem::Licenses
BSD-2-Clause-FreeBSD
BSD-2-Clause-NetBSD
BSD-2-Clause-Patent
+ BSD-2-Clause-Views
BSD-3-Clause
BSD-3-Clause-Attribution
BSD-3-Clause-Clear
BSD-3-Clause-LBNL
+ BSD-3-Clause-Modification
+ BSD-3-Clause-No-Military-License
BSD-3-Clause-No-Nuclear-License
BSD-3-Clause-No-Nuclear-License-2014
BSD-3-Clause-No-Nuclear-Warranty
+ BSD-3-Clause-Open-MPI
BSD-4-Clause
+ BSD-4-Clause-Shortened
BSD-4-Clause-UC
BSD-Protection
BSD-Source-Code
BSL-1.0
+ BUSL-1.1
Bahyph
Barr
Beerware
BitTorrent-1.0
BitTorrent-1.1
+ BlueOak-1.0.0
Borceux
+ C-UDA-1.0
+ CAL-1.0
+ CAL-1.0-Combined-Work-Exception
CATOSL-1.1
CC-BY-1.0
CC-BY-2.0
CC-BY-2.5
CC-BY-3.0
+ CC-BY-3.0-AT
+ CC-BY-3.0-US
CC-BY-4.0
CC-BY-NC-1.0
CC-BY-NC-2.0
@@ -81,6 +96,7 @@ class Gem::Licenses
CC-BY-NC-ND-2.0
CC-BY-NC-ND-2.5
CC-BY-NC-ND-3.0
+ CC-BY-NC-ND-3.0-IGO
CC-BY-NC-ND-4.0
CC-BY-NC-SA-1.0
CC-BY-NC-SA-2.0
@@ -94,12 +110,17 @@ class Gem::Licenses
CC-BY-ND-4.0
CC-BY-SA-1.0
CC-BY-SA-2.0
+ CC-BY-SA-2.0-UK
+ CC-BY-SA-2.1-JP
CC-BY-SA-2.5
CC-BY-SA-3.0
+ CC-BY-SA-3.0-AT
CC-BY-SA-4.0
+ CC-PDDC
CC0-1.0
CDDL-1.0
CDDL-1.1
+ CDL-1.0
CDLA-Permissive-1.0
CDLA-Sharing-1.0
CECILL-1.0
@@ -108,6 +129,11 @@ class Gem::Licenses
CECILL-2.1
CECILL-B
CECILL-C
+ CERN-OHL-1.1
+ CERN-OHL-1.2
+ CERN-OHL-P-2.0
+ CERN-OHL-S-2.0
+ CERN-OHL-W-2.0
CNRI-Jython
CNRI-Python
CNRI-Python-GPL-Compatible
@@ -123,12 +149,14 @@ class Gem::Licenses
Cube
D-FSL-1.0
DOC
+ DRL-1.0
DSDP
Dotseqn
ECL-1.0
ECL-2.0
EFL-1.0
EFL-2.0
+ EPICS
EPL-1.0
EPL-2.0
EUDatagrid
@@ -144,17 +172,32 @@ class Gem::Licenses
FTL
Fair
Frameworx-1.0
+ FreeBSD-DOC
FreeImage
+ GD
GFDL-1.1
+ GFDL-1.1-invariants-only
+ GFDL-1.1-invariants-or-later
+ GFDL-1.1-no-invariants-only
+ GFDL-1.1-no-invariants-or-later
GFDL-1.1-only
GFDL-1.1-or-later
GFDL-1.2
+ GFDL-1.2-invariants-only
+ GFDL-1.2-invariants-or-later
+ GFDL-1.2-no-invariants-only
+ GFDL-1.2-no-invariants-or-later
GFDL-1.2-only
GFDL-1.2-or-later
GFDL-1.3
+ GFDL-1.3-invariants-only
+ GFDL-1.3-invariants-or-later
+ GFDL-1.3-no-invariants-only
+ GFDL-1.3-no-invariants-or-later
GFDL-1.3-only
GFDL-1.3-or-later
GL2PS
+ GLWTPL
GPL-1.0
GPL-1.0+
GPL-1.0-only
@@ -178,7 +221,10 @@ class Gem::Licenses
Glide
Glulxe
HPND
+ HPND-sell-variant
+ HTMLTIDY
HaskellReport
+ Hippocratic-2.1
IBM-pibs
ICU
IJG
@@ -191,6 +237,7 @@ class Gem::Licenses
Intel
Intel-ACPI
Interbase-1.0
+ JPNIC
JSON
JasPer-2.0
LAL-1.2
@@ -221,11 +268,15 @@ class Gem::Licenses
LiLiQ-R-1.1
LiLiQ-Rplus-1.1
Libpng
+ Linux-OpenIB
MIT
+ MIT-0
MIT-CMU
+ MIT-Modern-Variant
MIT-advertising
MIT-enna
MIT-feh
+ MIT-open-group
MITNFA
MPL-1.0
MPL-1.1
@@ -237,12 +288,18 @@ class Gem::Licenses
MakeIndex
MirOS
Motosoto
+ MulanPSL-1.0
+ MulanPSL-2.0
Multics
Mup
+ NAIST-2003
NASA-1.3
NBPL-1.0
+ NCGL-UK-2.0
NCSA
NGPL
+ NIST-PD
+ NIST-PD-fallback
NLOD-1.0
NLPL
NOSL
@@ -251,6 +308,7 @@ class Gem::Licenses
NPOSL-3.0
NRL
NTP
+ NTP-0
Naumen
Net-SNMP
NetCDF
@@ -258,11 +316,23 @@ class Gem::Licenses
Nokia
Noweb
Nunit
+ O-UDA-1.0
OCCT-PL
OCLC-2.0
+ ODC-By-1.0
ODbL-1.0
OFL-1.0
+ OFL-1.0-RFN
+ OFL-1.0-no-RFN
OFL-1.1
+ OFL-1.1-RFN
+ OFL-1.1-no-RFN
+ OGC-1.0
+ OGDL-Taiwan-1.0
+ OGL-Canada-2.0
+ OGL-UK-1.0
+ OGL-UK-2.0
+ OGL-UK-3.0
OGTSL
OLDAP-1.1
OLDAP-1.2
@@ -292,7 +362,12 @@ class Gem::Licenses
PDDL-1.0
PHP-3.0
PHP-3.01
+ PSF-2.0
+ Parity-6.0.0
+ Parity-7.0.0
Plexus
+ PolyForm-Noncommercial-1.0.0
+ PolyForm-Small-Business-1.0.0
PostgreSQL
Python-2.0
QPL-1.0
@@ -310,15 +385,21 @@ class Gem::Licenses
SGI-B-1.0
SGI-B-1.1
SGI-B-2.0
+ SHL-0.5
+ SHL-0.51
SISSL
SISSL-1.2
SMLNJ
SMPPL
SNIA
SPL-1.0
+ SSH-OpenSSH
+ SSH-short
+ SSPL-1.0
SWL
Saxpath
Sendmail
+ Sendmail-8.23
SimPL-2.0
Sleepycat
Spencer-86
@@ -326,11 +407,15 @@ class Gem::Licenses
Spencer-99
StandardML-NJ
SugarCRM-1.1.3
+ TAPR-OHL-1.0
TCL
TCP-wrappers
TMate
TORQUE-1.1
TOSL
+ TU-Berlin-1.0
+ TU-Berlin-2.0
+ UCL-1.0
UPL-1.0
Unicode-DFS-2015
Unicode-DFS-2016
@@ -360,16 +445,22 @@ class Gem::Licenses
Zimbra-1.3
Zimbra-1.4
Zlib
+ blessing
bzip2-1.0.5
bzip2-1.0.6
+ copyleft-next-0.3.0
+ copyleft-next-0.3.1
curl
diffmark
dvipdfm
eCos-2.0
eGenix
+ etalab-2.0
gSOAP-1.3b
gnuplot
iMatix
+ libpng-2.0
+ libselinux-1.0
libtiff
mpich2
psfrag
@@ -395,12 +486,26 @@ class Gem::Licenses
Font-exception-2.0
GCC-exception-2.0
GCC-exception-3.1
+ GPL-3.0-linking-exception
+ GPL-3.0-linking-source-exception
+ GPL-CC-1.0
+ LGPL-3.0-linking-exception
+ LLVM-exception
LZMA-exception
Libtool-exception
Linux-syscall-note
Nokia-Qt-exception-1.1
OCCT-exception-1.0
+ OCaml-LGPL-linking-exception
+ OpenJDK-assembly-exception-1.0
+ PS-or-PDF-font-exception-20170817
+ Qt-GPL-exception-1.0
+ Qt-LGPL-exception-1.1
Qwt-exception-1.0
+ SHL-2.0
+ SHL-2.1
+ Swift-exception
+ Universal-FOSS-exception-1.0
WxWindows-exception-3.1
eCos-exception-2.0
freertos-exception-2.0
@@ -413,10 +518,10 @@ class Gem::Licenses
REGEXP = %r{
\A
- (
+ (?:
#{Regexp.union(LICENSE_IDENTIFIERS)}
\+?
- (\s WITH \s #{Regexp.union(EXCEPTION_IDENTIFIERS)})?
+ (?:\s WITH \s #{Regexp.union(EXCEPTION_IDENTIFIERS)})?
| #{NONSTANDARD}
)
\Z
diff --git a/lib/rubygems/validator.rb b/lib/rubygems/validator.rb
index 30cdd93..728595e 100644
--- a/lib/rubygems/validator.rb
+++ b/lib/rubygems/validator.rb
@@ -5,8 +5,8 @@
# See LICENSE.txt for permissions.
#++
-require 'rubygems/package'
-require 'rubygems/installer'
+require_relative 'package'
+require_relative 'installer'
##
# Validator performs various gem file and gem database validation
diff --git a/lib/rubygems/version_option.rb b/lib/rubygems/version_option.rb
index be71ef4..eabe4fd 100644
--- a/lib/rubygems/version_option.rb
+++ b/lib/rubygems/version_option.rb
@@ -5,7 +5,7 @@
# See LICENSE.txt for permissions.
#++
-require 'rubygems'
+require_relative '../rubygems'
##
# Mixin methods for --version and --platform Gem::Command options.
diff --git a/lib/securerandom.rb b/lib/securerandom.rb
index 241fde9..323d4af 100644
--- a/lib/securerandom.rb
+++ b/lib/securerandom.rb
@@ -31,7 +31,7 @@
# * uuid
#
# These methods are usable as class methods of SecureRandom such as
-# `SecureRandom.hex`.
+# +SecureRandom.hex+.
#
# === Examples
#
diff --git a/lib/set.rb b/lib/set.rb
index 682cb74..5039930 100644
--- a/lib/set.rb
+++ b/lib/set.rb
@@ -64,9 +64,11 @@
#
# ## What's Here
#
-# First, what's elsewhere. \Set includes the module
-# {Enumerable}[rdoc-ref:Enumerable],
-# which provides dozens of additional methods.
+# First, what's elsewhere. \Class \Set:
+#
+# - Inherits from {class Object}[https://docs.ruby-lang.org/en/master/Object.html#class-Object-label-What-27s+Here].
+# - Includes {module Enumerable}[https://docs.ruby-lang.org/en/master/Enumerable.html#module-Enumerable-label-What-27s+Here],
+# which provides dozens of additional methods.
#
# In particular, class \Set does not have many methods of its own
# for fetching or for iterating.
@@ -468,25 +470,35 @@ class Set
end
end
- # Returns true if the set and the given set have at least one
+ # Returns true if the set and the given enumerable have at least one
# element in common.
#
# Set[1, 2, 3].intersect? Set[4, 5] #=> false
# Set[1, 2, 3].intersect? Set[3, 4] #=> true
+ # Set[1, 2, 3].intersect? 4..5 #=> false
+ # Set[1, 2, 3].intersect? [3, 4] #=> true
def intersect?(set)
- set.is_a?(Set) or raise ArgumentError, "value must be a set"
- if size < set.size
- any? { |o| set.include?(o) }
- else
+ case set
+ when Set
+ if size < set.size
+ any? { |o| set.include?(o) }
+ else
+ set.any? { |o| include?(o) }
+ end
+ when Enumerable
set.any? { |o| include?(o) }
+ else
+ raise ArgumentError, "value must be enumerable"
end
end
- # Returns true if the set and the given set have no element in
- # common. This method is the opposite of `intersect?`.
+ # Returns true if the set and the given enumerable have
+ # no element in common. This method is the opposite of `intersect?`.
#
# Set[1, 2, 3].disjoint? Set[3, 4] #=> false
# Set[1, 2, 3].disjoint? Set[4, 5] #=> true
+ # Set[1, 2, 3].disjoint? [3, 4] #=> false
+ # Set[1, 2, 3].disjoint? 4..5 #=> true
def disjoint?(set)
!intersect?(set)
end
diff --git a/lib/set/set.gemspec b/lib/set/set.gemspec
index 2be9aa9..d14feba 100644
--- a/lib/set/set.gemspec
+++ b/lib/set/set.gemspec
@@ -19,7 +19,5 @@ Gem::Specification.new do |spec|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
- spec.bindir = "exe"
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
end
diff --git a/lib/tempfile.rb b/lib/tempfile.rb
index 1577e45..c1b696c 100644
--- a/lib/tempfile.rb
+++ b/lib/tempfile.rb
@@ -36,9 +36,9 @@ require 'tmpdir'
#
# When a Tempfile object is garbage collected, or when the Ruby interpreter
# exits, its associated temporary file is automatically deleted. This means
-# that's it's unnecessary to explicitly delete a Tempfile after use, though
-# it's good practice to do so: not explicitly deleting unused Tempfiles can
-# potentially leave behind large amounts of tempfiles on the filesystem
+# that it's unnecessary to explicitly delete a Tempfile after use, though
+# it's a good practice to do so: not explicitly deleting unused Tempfiles can
+# potentially leave behind a large number of temp files on the filesystem
# until they're garbage collected. The existence of these temp files can make
# it harder to determine a new Tempfile filename.
#
diff --git a/lib/un.gemspec b/lib/un.gemspec
index 1b89ffa..50032e1 100644
--- a/lib/un.gemspec
+++ b/lib/un.gemspec
@@ -10,6 +10,7 @@ Gem::Specification.new do |spec|
spec.description = spec.summary
spec.homepage = "https://github.com/ruby/un"
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
+ spec.licenses = ["Ruby", "BSD-2-Clause"]
spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = spec.homepage
@@ -18,6 +19,6 @@ Gem::Specification.new do |spec|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
end
spec.bindir = "exe"
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
+ spec.executables = []
spec.require_paths = ["lib"]
end
diff --git a/lib/un.rb b/lib/un.rb
index 3f59e3f..5feac92 100644
--- a/lib/un.rb
+++ b/lib/un.rb
@@ -23,6 +23,7 @@
# ruby -run -e wait_writable -- [OPTION] FILE
# ruby -run -e mkmf -- [OPTION] EXTNAME [OPTION]
# ruby -run -e httpd -- [OPTION] [DocumentRoot]
+# ruby -run -e colorize -- [FILE]
# ruby -run -e help [COMMAND]
require "fileutils"
@@ -346,6 +347,21 @@ def httpd
end
options[:Port] ||= 8080 # HTTP Alternate
options[:DocumentRoot] = argv.shift || '.'
+ s = nil
+ options[:StartCallback] = proc {
+ logger = s.logger
+ logger.info("To access this server, open this URL in a browser:")
+ s.listeners.each do |listener|
+ if options[:SSLEnable]
+ addr = listener.addr
+ addr[3] = "127.0.0.1" if addr[3] == "0.0.0.0"
+ addr[3] = "::1" if addr[3] == "::"
+ logger.info(" https://#{Addrinfo.new(addr).inspect_sockaddr}")
+ else
+ logger.info(" http://#{listener.connect_address.inspect_sockaddr}")
+ end
+ end
+ }
s = WEBrick::HTTPServer.new(options)
shut = proc {s.shutdown}
siglist = %w"TERM QUIT"
@@ -359,6 +375,29 @@ def httpd
end
##
+# Colorize ruby code.
+#
+# ruby -run -e colorize -- [FILE]
+#
+
+def colorize
+ begin
+ require "irb/color"
+ rescue LoadError
+ raise "colorize requires irb 1.1.0 or later"
+ end
+ setup do |argv, |
+ if argv.empty?
+ puts IRB::Color.colorize_code STDIN.read
+ return
+ end
+ argv.each do |file|
+ puts IRB::Color.colorize_code File.read(file)
+ end
+ end
+end
+
+##
# Display help message.
#
# ruby -run -e help [COMMAND]
diff --git a/lib/unicode_normalize/tables.rb b/lib/unicode_normalize/tables.rb
index a36daa8..a7a387d 100644
--- a/lib/unicode_normalize/tables.rb
+++ b/lib/unicode_normalize/tables.rb
@@ -94,6 +94,7 @@ module UnicodeNormalize # :nodoc:
"\u1A75-\u1A7C" \
"\u1A7F" \
"\u1AB0-\u1ABD" \
+ "\u1ABF\u1AC0" \
"\u1B34\u1B35" \
"\u1B44" \
"\u1B6B-\u1B73" \
@@ -122,6 +123,7 @@ module UnicodeNormalize # :nodoc:
"\uA69E\uA69F" \
"\uA6F0\uA6F1" \
"\uA806" \
+ "\uA82C" \
"\uA8C4" \
"\uA8E0-\uA8F1" \
"\uA92B-\uA92D" \
@@ -146,6 +148,7 @@ module UnicodeNormalize # :nodoc:
"\u{10A3F}" \
"\u{10AE5}\u{10AE6}" \
"\u{10D24}-\u{10D27}" \
+ "\u{10EAB}\u{10EAC}" \
"\u{10F46}-\u{10F50}" \
"\u{11046}" \
"\u{1107F}" \
@@ -177,6 +180,9 @@ module UnicodeNormalize # :nodoc:
"\u{116B6}\u{116B7}" \
"\u{1172B}" \
"\u{11839}\u{1183A}" \
+ "\u{11930}" \
+ "\u{1193D}\u{1193E}" \
+ "\u{11943}" \
"\u{119E0}" \
"\u{11A34}" \
"\u{11A47}" \
@@ -187,6 +193,7 @@ module UnicodeNormalize # :nodoc:
"\u{11D97}" \
"\u{16AF0}-\u{16AF4}" \
"\u{16B30}-\u{16B36}" \
+ "\u{16FF0}\u{16FF1}" \
"\u{1BC9E}" \
"\u{1D165}-\u{1D169}" \
"\u{1D16D}-\u{1D172}" \
@@ -434,6 +441,7 @@ module UnicodeNormalize # :nodoc:
"\u{114BB}\u{114BC}" \
"\u{114BE}" \
"\u{115BA}\u{115BB}" \
+ "\u{11938}" \
"\u{1D15E}-\u{1D164}" \
"\u{1D1BB}-\u{1D1C0}" \
"\u{2F800}-\u{2FA1D}" \
@@ -604,6 +612,7 @@ module UnicodeNormalize # :nodoc:
"\u{11347}" \
"\u{114B9}" \
"\u{115B8}\u{115B9}" \
+ "\u{11935}" \
"]?#{accents}+" \
"|#{'' # precomposed Hangul syllables
}" \
@@ -885,6 +894,8 @@ module UnicodeNormalize # :nodoc:
"\u{114BB}\u{114BC}" \
"\u{114BE}" \
"\u{115B8}-\u{115BB}" \
+ "\u{11935}" \
+ "\u{11938}" \
"]?#{accents}+" \
"|#{'' # Hangul syllables with separate trailer
}" \
@@ -1393,6 +1404,7 @@ module UnicodeNormalize # :nodoc:
"\uA770" \
"\uA7F8\uA7F9" \
"\uAB5C-\uAB5F" \
+ "\uAB69" \
"\uFB00-\uFB06" \
"\uFB13-\uFB17" \
"\uFB20-\uFB29" \
@@ -1479,6 +1491,7 @@ module UnicodeNormalize # :nodoc:
"\u{1F210}-\u{1F23B}" \
"\u{1F240}-\u{1F248}" \
"\u{1F250}\u{1F251}" \
+ "\u{1FBF0}-\u{1FBF9}" \
"]"
class_table = {
@@ -1906,6 +1919,8 @@ module UnicodeNormalize # :nodoc:
"\u1ABB"=>230,
"\u1ABC"=>230,
"\u1ABD"=>220,
+ "\u1ABF"=>220,
+ "\u1AC0"=>220,
"\u1B34"=>7,
"\u1B44"=>9,
"\u1B6B"=>230,
@@ -2099,6 +2114,7 @@ module UnicodeNormalize # :nodoc:
"\uA6F0"=>230,
"\uA6F1"=>230,
"\uA806"=>9,
+ "\uA82C"=>9,
"\uA8C4"=>9,
"\uA8E0"=>230,
"\uA8E1"=>230,
@@ -2171,6 +2187,8 @@ module UnicodeNormalize # :nodoc:
"\u{10D25}"=>230,
"\u{10D26}"=>230,
"\u{10D27}"=>230,
+ "\u{10EAB}"=>230,
+ "\u{10EAC}"=>230,
"\u{10F46}"=>220,
"\u{10F47}"=>220,
"\u{10F48}"=>230,
@@ -2226,6 +2244,9 @@ module UnicodeNormalize # :nodoc:
"\u{1172B}"=>9,
"\u{11839}"=>9,
"\u{1183A}"=>7,
+ "\u{1193D}"=>9,
+ "\u{1193E}"=>9,
+ "\u{11943}"=>7,
"\u{119E0}"=>9,
"\u{11A34}"=>9,
"\u{11A47}"=>9,
@@ -2247,6 +2268,8 @@ module UnicodeNormalize # :nodoc:
"\u{16B34}"=>230,
"\u{16B35}"=>230,
"\u{16B36}"=>230,
+ "\u{16FF0}"=>6,
+ "\u{16FF1}"=>6,
"\u{1BC9E}"=>1,
"\u{1D165}"=>216,
"\u{1D166}"=>216,
@@ -3854,6 +3877,7 @@ module UnicodeNormalize # :nodoc:
"\u{114BE}"=>"\u{114B9}\u{114BD}",
"\u{115BA}"=>"\u{115B8}\u{115AF}",
"\u{115BB}"=>"\u{115B9}\u{115AF}",
+ "\u{11938}"=>"\u{11935}\u{11930}",
"\u{1D15E}"=>"\u{1D157}\u{1D165}",
"\u{1D15F}"=>"\u{1D158}\u{1D165}",
"\u{1D160}"=>"\u{1D158}\u{1D165}\u{1D16E}",
@@ -5758,6 +5782,7 @@ module UnicodeNormalize # :nodoc:
"\uAB5D"=>"\uAB37",
"\uAB5E"=>"\u026B",
"\uAB5F"=>"\uAB52",
+ "\uAB69"=>"\u028D",
"\uFB00"=>"ff",
"\uFB01"=>"fi",
"\uFB02"=>"fl",
@@ -8076,6 +8101,16 @@ module UnicodeNormalize # :nodoc:
"\u{1F248}"=>"\u3014\u6557\u3015",
"\u{1F250}"=>"\u5F97",
"\u{1F251}"=>"\u53EF",
+ "\u{1FBF0}"=>"0",
+ "\u{1FBF1}"=>"1",
+ "\u{1FBF2}"=>"2",
+ "\u{1FBF3}"=>"3",
+ "\u{1FBF4}"=>"4",
+ "\u{1FBF5}"=>"5",
+ "\u{1FBF6}"=>"6",
+ "\u{1FBF7}"=>"7",
+ "\u{1FBF8}"=>"8",
+ "\u{1FBF9}"=>"9",
"\u0385"=>" \u0308\u0301",
"\u03D3"=>"\u03A5\u0301",
"\u03D4"=>"\u03A5\u0308",
@@ -9035,5 +9070,6 @@ module UnicodeNormalize # :nodoc:
"\u{114B9}\u{114BD}"=>"\u{114BE}",
"\u{115B8}\u{115AF}"=>"\u{115BA}",
"\u{115B9}\u{115AF}"=>"\u{115BB}",
+ "\u{11935}\u{11930}"=>"\u{11938}",
}.freeze
end
diff --git a/lib/uri.rb b/lib/uri.rb
index 5e820f4..394c156 100644
--- a/lib/uri.rb
+++ b/lib/uri.rb
@@ -30,7 +30,7 @@
# class RSYNC < Generic
# DEFAULT_PORT = 873
# end
-# @@schemes['RSYNC'] = RSYNC
+# register_scheme 'RSYNC', RSYNC
# end
# #=> URI::RSYNC
#
@@ -100,3 +100,4 @@ require_relative 'uri/https'
require_relative 'uri/ldap'
require_relative 'uri/ldaps'
require_relative 'uri/mailto'
+require_relative 'uri/ws'
diff --git a/lib/uri/common.rb b/lib/uri/common.rb
index 915c0e9..26b179a 100644
--- a/lib/uri/common.rb
+++ b/lib/uri/common.rb
@@ -16,6 +16,7 @@ module URI
REGEXP = RFC2396_REGEXP
Parser = RFC2396_Parser
RFC3986_PARSER = RFC3986_Parser.new
+ Ractor.make_shareable(RFC3986_PARSER) if defined?(Ractor)
# URI::Parser.new
DEFAULT_PARSER = Parser.new
@@ -27,6 +28,7 @@ module URI
DEFAULT_PARSER.regexp.each_pair do |sym, str|
const_set(sym, str)
end
+ Ractor.make_shareable(DEFAULT_PARSER) if defined?(Ractor)
module Util # :nodoc:
def make_components_hash(klass, array_hash)
@@ -62,22 +64,37 @@ module URI
include REGEXP
- @@schemes = {}
+ module Schemes
+ end
+ private_constant :Schemes
+
+ def self.register_scheme(scheme, klass)
+ Schemes.const_set(scheme, klass)
+ end
+
# Returns a Hash of the defined schemes.
def self.scheme_list
- @@schemes
+ Schemes.constants.map { |name|
+ [name.to_s.upcase, Schemes.const_get(name)]
+ }.to_h
end
+ INITIAL_SCHEMES = scheme_list
+ private_constant :INITIAL_SCHEMES
+ Ractor.make_shareable(INITIAL_SCHEMES) if defined?(Ractor)
+
#
# Construct a URI instance, using the scheme to detect the appropriate class
# from +URI.scheme_list+.
#
def self.for(scheme, *arguments, default: Generic)
- if scheme
- uri_class = @@schemes[scheme.upcase] || default
- else
- uri_class = default
+ const_name = scheme.to_s.upcase
+
+ uri_class = INITIAL_SCHEMES[const_name]
+ uri_class ||= if /\A[A-Z]\w*\z/.match?(const_name) && Schemes.const_defined?(const_name, false)
+ Schemes.const_get(const_name, false)
end
+ uri_class ||= default
return uri_class.new(scheme, *arguments)
end
@@ -653,6 +670,7 @@ module URI
"utf-16"=>"utf-16le",
"utf-16le"=>"utf-16le",
} # :nodoc:
+ Ractor.make_shareable(WEB_ENCODINGS_) if defined?(Ractor)
# :nodoc:
# return encoding or nil
diff --git a/lib/uri/file.rb b/lib/uri/file.rb
index 561ec70..7671ad6 100644
--- a/lib/uri/file.rb
+++ b/lib/uri/file.rb
@@ -90,5 +90,5 @@ module URI
end
end
- @@schemes['FILE'] = File
+ register_scheme 'FILE', File
end
diff --git a/lib/uri/ftp.rb b/lib/uri/ftp.rb
index fb38481..abad613 100644
--- a/lib/uri/ftp.rb
+++ b/lib/uri/ftp.rb
@@ -262,5 +262,6 @@ module URI
return str
end
end
- @@schemes['FTP'] = FTP
+
+ register_scheme 'FTP', FTP
end
diff --git a/lib/uri/http.rb b/lib/uri/http.rb
index 70cfb2a..6e9c963 100644
--- a/lib/uri/http.rb
+++ b/lib/uri/http.rb
@@ -82,6 +82,5 @@ module URI
end
end
- @@schemes['HTTP'] = HTTP
-
+ register_scheme 'HTTP', HTTP
end
diff --git a/lib/uri/https.rb b/lib/uri/https.rb
index c481b1f..50a5cab 100644
--- a/lib/uri/https.rb
+++ b/lib/uri/https.rb
@@ -18,5 +18,6 @@ module URI
# A Default port of 443 for URI::HTTPS
DEFAULT_PORT = 443
end
- @@schemes['HTTPS'] = HTTPS
+
+ register_scheme 'HTTPS', HTTPS
end
diff --git a/lib/uri/ldap.rb b/lib/uri/ldap.rb
index 14e6163..4544349 100644
--- a/lib/uri/ldap.rb
+++ b/lib/uri/ldap.rb
@@ -257,5 +257,5 @@ module URI
end
end
- @@schemes['LDAP'] = LDAP
+ register_scheme 'LDAP', LDAP
end
diff --git a/lib/uri/ldaps.rb b/lib/uri/ldaps.rb
index 227e7fa..58228f5 100644
--- a/lib/uri/ldaps.rb
+++ b/lib/uri/ldaps.rb
@@ -17,5 +17,6 @@ module URI
# A Default port of 636 for URI::LDAPS
DEFAULT_PORT = 636
end
- @@schemes['LDAPS'] = LDAPS
+
+ register_scheme 'LDAPS', LDAPS
end
diff --git a/lib/uri/mailto.rb b/lib/uri/mailto.rb
index d08c2ae..87cb996 100644
--- a/lib/uri/mailto.rb
+++ b/lib/uri/mailto.rb
@@ -289,5 +289,5 @@ module URI
alias to_rfc822text to_mailtext
end
- @@schemes['MAILTO'] = MailTo
+ register_scheme 'MAILTO', MailTo
end
diff --git a/lib/uri/ws.rb b/lib/uri/ws.rb
index 2bfee59..ff3c554 100644
--- a/lib/uri/ws.rb
+++ b/lib/uri/ws.rb
@@ -79,6 +79,5 @@ module URI
end
end
- @@schemes['WS'] = WS
-
+ register_scheme 'WS', WS
end
diff --git a/lib/uri/wss.rb b/lib/uri/wss.rb
index 1cfa133..7cea9d7 100644
--- a/lib/uri/wss.rb
+++ b/lib/uri/wss.rb
@@ -18,5 +18,6 @@ module URI
# A Default port of 443 for URI::WSS
DEFAULT_PORT = 443
end
- @@schemes['WSS'] = WSS
+
+ register_scheme 'WSS', WSS
end