Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support gemification of pathname #4992

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bc9ac8d
SharedHelpers.pwd doesn't need to return a Pathname
deivid-rodriguez Oct 17, 2021
fa9fd3b
Don't activate the `pathname` gem from binstubs
deivid-rodriguez Oct 18, 2021
3b4a380
The `tmp` test helper already joins internally
deivid-rodriguez Oct 18, 2021
a7c7b9b
The `bundled_app` helper method already joins internally
deivid-rodriguez Oct 18, 2021
56607cb
The `home` helper method already joins internally
deivid-rodriguez Oct 18, 2021
e68620d
The `default_bundle_path` helper method already joins internally
deivid-rodriguez Oct 18, 2021
1d108c1
The `system_gem_path` helper method already joins internally
deivid-rodriguez Oct 18, 2021
6d7f7a0
We should be checking raised exception, not status code here
deivid-rodriguez Aug 5, 2021
e0cafef
These method should be returning a string
deivid-rodriguez Aug 5, 2021
bfabc6c
Check not having load system features also for successful runs
deivid-rodriguez Aug 5, 2021
91eca89
Normalize `Pathname` instantiations
deivid-rodriguez Oct 18, 2021
235e52e
Prefer `Pathname#parent` for simplicity
deivid-rodriguez Oct 18, 2021
6100a5d
Simplify check for ruby-core setup
deivid-rodriguez Oct 18, 2021
1d382ad
Respect `GEM_COMMAND` in non ruby-core mode
deivid-rodriguez Oct 18, 2021
0984a25
Reuse `git` helper when possible
deivid-rodriguez Oct 18, 2021
247146a
Stop depending on `pathname` for subprocess launching
deivid-rodriguez Oct 18, 2021
3b3af0e
No need to instantiate here
deivid-rodriguez Oct 19, 2021
81828eb
Use `Pathname#sub` for consistency
deivid-rodriguez Oct 19, 2021
4d2c059
Tweak assertion to give better error when it fails
deivid-rodriguez Oct 19, 2021
f39c4de
Make rubygems source caches consistently use strings
deivid-rodriguez Oct 19, 2021
668a971
Simplify unwritable files finding
deivid-rodriguez Oct 19, 2021
d290d10
Support using the `pathname` gem in the Gemfile
deivid-rodriguez Oct 19, 2021
f62cad4
Backfill the rest of the `Pathname` API
deivid-rodriguez Nov 18, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb
bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/connection.rb
bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/pool.rb
bundler/lib/bundler/vendor/net-http-persistent/lib/net/http/persistent/timed_stack_multi.rb
bundler/lib/bundler/vendor/pathname/LICENSE.txt
bundler/lib/bundler/vendor/pathname/lib/pathname.rb
bundler/lib/bundler/vendor/thor/LICENSE.md
bundler/lib/bundler/vendor/thor/lib/thor.rb
bundler/lib/bundler/vendor/thor/lib/thor/actions.rb
Expand Down Expand Up @@ -310,6 +312,7 @@ bundler/lib/bundler/vendor/uri/lib/uri/ws.rb
bundler/lib/bundler/vendor/uri/lib/uri/wss.rb
bundler/lib/bundler/vendored_fileutils.rb
bundler/lib/bundler/vendored_molinillo.rb
bundler/lib/bundler/vendored_pathname.rb
bundler/lib/bundler/vendored_persistent.rb
bundler/lib/bundler/vendored_thor.rb
bundler/lib/bundler/vendored_tmpdir.rb
Expand Down
12 changes: 12 additions & 0 deletions bundler/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@ Automatiek::RakeTask.new("tmpdir") do |lib|
end
end

# We currently include the following changes over the official version:
# * Replace the C-extension with a pure ruby implementation.
# * Add back ruby 2.3 support.
Automatiek::RakeTask.new("pathname") do |lib|
lib.version = "v0.2.0"
lib.download = { :github => "https://github.com/ruby/pathname" }
lib.namespace = "Pathname"
lib.prefix = "Bundler"
lib.vendor_lib = "lib/bundler/vendor/pathname"
lib.license_path = "LICENSE.txt"
end

# We currently include the following changes over the official version:
# * Avoid requiring the optional `net-http-pipeline` dependency, so that its version can be selected by end users.
# * Workaround for incorrect `Process.getrlimit` on JRuby + Windows.
Expand Down
16 changes: 10 additions & 6 deletions bundler/lib/bundler.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require_relative "bundler/vendored_fileutils"
require "pathname"
require_relative "bundler/vendored_pathname"
require "rbconfig"

require_relative "bundler/errors"
Expand Down Expand Up @@ -93,7 +93,7 @@ def ui=(ui)

# Returns absolute path of where gems are installed on the filesystem.
def bundle_path
@bundle_path ||= Pathname.new(configured_bundle_path.path).expand_path(root)
@bundle_path ||= Bundler::Pathname.new(configured_bundle_path.path).expand_path(root)
end

def configured_bundle_path
Expand All @@ -104,7 +104,7 @@ def configured_bundle_path
def bin_path
@bin_path ||= begin
path = settings[:bin] || "bin"
path = Pathname.new(path).expand_path(root).expand_path
path = Bundler::Pathname.new(path).expand_path(root).expand_path
SharedHelpers.filesystem_access(path) {|p| FileUtils.mkdir_p(p) }
path
end
Expand Down Expand Up @@ -287,7 +287,7 @@ def root
rescue GemfileNotFound
bundle_dir = default_bundle_dir
raise GemfileNotFound, "Could not locate Gemfile or .bundle/ directory" unless bundle_dir
Pathname.new(File.expand_path("..", bundle_dir))
bundle_dir.parent
end
end

Expand Down Expand Up @@ -455,6 +455,10 @@ def default_lockfile
SharedHelpers.default_lockfile
end

def relative_path_to_lockfile
default_lockfile.relative_path_from(SharedHelpers.pwd)
end

def default_bundle_dir
SharedHelpers.default_bundle_dir
end
Expand Down Expand Up @@ -492,11 +496,11 @@ def requires_sudo?
bin_dir = bin_dir.parent until bin_dir.exist?

# if any directory is not writable, we need sudo
files = [path, bin_dir] | Dir[bundle_path.join("build_info/*").to_s] | Dir[bundle_path.join("*").to_s]
files = [path.to_s, bin_dir.to_s] | Dir[bundle_path.join("build_info/*").to_s] | Dir[bundle_path.join("*").to_s]
unwritable_files = files.reject {|f| File.writable?(f) }
sudo_needed = !unwritable_files.empty?
if sudo_needed
Bundler.ui.warn "Following files may not be writable, so sudo is needed:\n #{unwritable_files.map(&:to_s).sort.join("\n ")}"
Bundler.ui.warn "Following files may not be writable, so sudo is needed:\n #{unwritable_files.sort.join("\n ")}"
end
end

Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/cli/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def run
Bundler.ui.warn "Install missing gems with `bundle install`"
exit 1
elsif !Bundler.default_lockfile.file? && Bundler.frozen_bundle?
Bundler.ui.error "This bundle has been frozen, but there is no #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} present"
Bundler.ui.error "This bundle has been frozen, but there is no #{Bundler.relative_path_to_lockfile} present"
exit 1
else
Bundler.load.lock(:preserve_unknown_sections => true) unless options[:"dry-run"]
Expand Down
20 changes: 9 additions & 11 deletions bundler/lib/bundler/cli/gem.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "pathname"

module Bundler
class CLI
Bundler.require_thor_actions
Expand All @@ -26,7 +24,7 @@ def initialize(options, gem_name, thor)
thor.destination_root = nil

@name = @gem_name
@target = SharedHelpers.pwd.join(gem_name)
@target = File.expand_path(gem_name)

validate_ext_name if options[:ext]
end
Expand Down Expand Up @@ -185,28 +183,28 @@ def run
)
end

if target.exist? && !target.directory?
if File.exist?(target) && !File.directory?(target)
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}"
require "shellwords"
`git init #{target.to_s.shellescape}`
`git init #{target.shellescape}`

config[:git_default_branch] = File.read("#{target}/.git/HEAD").split("/").last.chomp
end

templates.each do |src, dst|
destination = target.join(dst)
destination = File.join(target, dst)
thor.template("newgem/#{src}", destination, config)
end

executables.each do |file|
path = target.join(file)
executable = (path.stat.mode | 0o111)
path.chmod(executable)
path = File.join(target, file)
executable = (File.stat(path).mode | 0o111)
File.chmod(executable, path)
end

if use_git
Expand All @@ -216,7 +214,7 @@ def run
end

# Open gemspec in editor
open_editor(options["edit"], target.join("#{name}.gemspec")) if options[:edit]
open_editor(options["edit"], File.join(target, "#{name}.gemspec")) if options[:edit]

Bundler.ui.info "Gem '#{name}' was successfully created. " \
"For more information on making a RubyGem visit https://bundler.io/guides/creating_gem.html"
Expand All @@ -225,7 +223,7 @@ def run
private

def resolve_name(name)
SharedHelpers.pwd.join(name).basename.to_s
File.basename(File.expand_path(name))
end

def ask_and_set(key, header, message)
Expand Down
4 changes: 2 additions & 2 deletions bundler/lib/bundler/cli/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def run
flag = "--deployment flag" if options[:deployment]
flag ||= "--frozen flag" if options[:frozen]
flag ||= "deployment setting"
raise ProductionError, "The #{flag} requires a #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}. Please make " \
"sure you have checked your #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} into version control " \
raise ProductionError, "The #{flag} requires a #{Bundler.relative_path_to_lockfile}. Please make " \
"sure you have checked your #{Bundler.relative_path_to_lockfile} into version control " \
"before deploying."
end

Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/compact_index_client.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "pathname"
require_relative "vendored_pathname"
require "set"

module Bundler
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def ensure_equivalent_gemfile_and_lockfile(explicit_flag = false)
msg = String.new
msg << "You are trying to install in deployment mode after changing\n" \
"your Gemfile. Run `bundle install` elsewhere and add the\n" \
"updated #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} to version control."
"updated #{Bundler.relative_path_to_lockfile} to version control."

unless explicit_flag
suggested_command = if Bundler.settings.locations("frozen").keys.&([:global, :local]).any?
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def self.report(options = {})
out << "```ruby\n" << read_file(gemfile).chomp << "\n```\n"
end

out << "\n### #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}\n\n"
out << "\n### #{Bundler.relative_path_to_lockfile}\n\n"
out << "```\n" << read_file(Bundler.default_lockfile).chomp << "\n```\n"
end

Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/gem_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def gemspec(&block)
attr_writer :tag_prefix

def initialize(base = nil, name = nil)
@base = File.expand_path(base || SharedHelpers.pwd)
@base = base ? File.expand_path(base) : SharedHelpers.pwd
gemspecs = name ? [File.join(@base, "#{name}.gemspec")] : Gem::Util.glob_files_in_dir("{,*}.gemspec", @base)
raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1
@spec_path = gemspecs.first
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/inline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def gemfile(install = false, options = {}, &gemfile)
bundler_module = class << Bundler; self; end
bundler_module.send(:remove_method, :root)
def Bundler.root
Bundler::SharedHelpers.pwd.expand_path
Bundler::Pathname.new(Bundler::SharedHelpers.pwd)
end
old_gemfile = ENV["BUNDLE_GEMFILE"]
Bundler::SharedHelpers.set_env "BUNDLE_GEMFILE", "Gemfile"
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def generate_standalone_bundler_executable_stubs(spec, options = {})

spec.executables.each do |executable|
next if executable == "bundle"
executable_path = Pathname(spec.full_gem_path).join(spec.bindir, executable).relative_path_from(bin_path)
executable_path = Pathname.new(spec.full_gem_path).join(spec.bindir, executable).relative_path_from(bin_path)
executable_path = executable_path

mode = Gem.win_platform? ? "wb:UTF-8" : "w"
Expand Down
6 changes: 3 additions & 3 deletions bundler/lib/bundler/lockfile_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def initialize(lockfile)
@specs = {}

if lockfile.match(/<<<<<<<|=======|>>>>>>>|\|\|\|\|\|\|\|/)
raise LockfileError, "Your #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)} contains merge conflicts.\n" \
"Run `git checkout HEAD -- #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}` first to get a clean lock."
raise LockfileError, "Your #{Bundler.relative_path_to_lockfile} contains merge conflicts.\n" \
"Run `git checkout HEAD -- #{Bundler.relative_path_to_lockfile}` first to get a clean lock."
end

lockfile.split(/(?:\r?\n)+/).each do |line|
Expand All @@ -80,7 +80,7 @@ def initialize(lockfile)
warn_for_outdated_bundler_version
rescue ArgumentError => e
Bundler.ui.debug(e)
raise LockfileError, "Your lockfile is unreadable. Run `rm #{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}` " \
raise LockfileError, "Your lockfile is unreadable. Run `rm #{Bundler.relative_path_to_lockfile}` " \
"and then `bundle install` to generate a new lockfile."
end

Expand Down
4 changes: 2 additions & 2 deletions bundler/lib/bundler/rubygems_ext.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "pathname"
require_relative "vendored_pathname"

require "rubygems/specification"

Expand Down Expand Up @@ -29,7 +29,7 @@ def full_gem_path
# gems at that time, this method could be called inside another require,
# thus raising with that constant being undefined. Better to check a method
if source.respond_to?(:path) || (source.respond_to?(:bundler_plugin_api_source?) && source.bundler_plugin_api_source?)
Pathname.new(loaded_from).dirname.expand_path(source.root).to_s.tap{|x| x.untaint if RUBY_VERSION < "2.7" }
Bundler::Pathname.new(loaded_from).dirname.expand_path(source.root).to_s.tap{|x| x.untaint if RUBY_VERSION < "2.7" }
else
rg_full_gem_path
end
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def base_path
def base_path_relative_to_pwd
base_path = Pathname.new(self.base_path)
expanded_base_path = base_path.expand_path(Bundler.root)
relative_path = expanded_base_path.relative_path_from(Pathname.pwd)
relative_path = expanded_base_path.relative_path_from(SharedHelpers.pwd)
if relative_path.to_s.start_with?("..")
relative_path = base_path if base_path.absolute?
else
Expand Down
4 changes: 2 additions & 2 deletions bundler/lib/bundler/settings/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def self.validate!(key, value, settings)
path = path.expand_path

root = begin
Bundler.root
Bundler.root.to_s
rescue GemfileNotFound
Pathname.pwd.expand_path
SharedHelpers.pwd
end

path = begin
Expand Down
8 changes: 4 additions & 4 deletions bundler/lib/bundler/shared_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "pathname"
require_relative "vendored_pathname"
require "rbconfig"

require_relative "version"
Expand All @@ -26,8 +26,8 @@ def default_lockfile
gemfile = default_gemfile

case gemfile.basename.to_s
when "gems.rb" then Pathname.new(gemfile.sub(/.rb$/, ".locked"))
else Pathname.new("#{gemfile}.lock")
when "gems.rb" then gemfile.sub(/.rb$/, ".locked")
else gemfile.sub(/$/, ".lock")
end.tap{|x| x.untaint if RUBY_VERSION < "2.7" }
end

Expand Down Expand Up @@ -55,7 +55,7 @@ def chdir(dir, &blk)

def pwd
Bundler.rubygems.ext_lock.synchronize do
Pathname.pwd
Dir.pwd
end
end

Expand Down
4 changes: 2 additions & 2 deletions bundler/lib/bundler/source/git/git_proxy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def initialize(command, path, extra_info = nil)
msg = String.new
msg << "Git error: command `#{command}` in directory #{path} has failed."
msg << "\n#{extra_info}" if extra_info
msg << "\nIf this error persists you could try removing the cache directory '#{path}'" if path.exist?
msg << "\nIf this error persists you could try removing the cache directory '#{path}'" if File.exist?(path)
super msg
end
end
Expand Down Expand Up @@ -169,7 +169,7 @@ def git(*command, dir: nil)

filtered_out = URICredentialsFilter.credential_filtered_string(out, uri)

raise GitCommandError.new(command_with_no_credentials, dir || SharedHelpers.pwd, filtered_out) unless status.success?
raise GitCommandError.new(command_with_no_credentials, dir ? dir.to_s : SharedHelpers.pwd, filtered_out) unless status.success?

filtered_out
end
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/source/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def default_cache_path_for(dir)
end

def cache_path
Bundler.app_cache
Bundler.app_cache.to_s
end

private
Expand Down
6 changes: 2 additions & 4 deletions bundler/lib/bundler/templates/Executable
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
# this file is here to facilitate running it.
#

require "pathname"
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../<%= relative_gemfile_path %>",
Pathname.new(__FILE__).realpath)
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("<%= relative_gemfile_path %>", __dir__)

bundle_binstub = File.expand_path("../bundle", __FILE__)
bundle_binstub = File.expand_path("bundle", __dir__)

if File.file?(bundle_binstub)
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
Expand Down
6 changes: 2 additions & 4 deletions bundler/lib/bundler/templates/Executable.standalone
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
# this file is here to facilitate running it.
#

require "pathname"
path = Pathname.new(__FILE__)
$:.unshift File.expand_path "../<%= standalone_path %>", path.realpath
$:.unshift File.expand_path "<%= standalone_path %>", __dir__

require "bundler/setup"
load File.expand_path "../<%= executable_path %>", path.realpath
load File.expand_path "<%= executable_path %>", __dir__