Skip to content

Commit

Permalink
[rubygems/rubygems] Autoload shellwords when it's needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix authored and matzbot committed Jun 13, 2023
1 parent c74f42a commit 27b0777
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
7 changes: 3 additions & 4 deletions lib/rubygems/ext/builder.rb
Expand Up @@ -7,6 +7,7 @@
#++

require_relative "../user_interaction"
require_relative "../shellwords"

class Gem::Ext::Builder
include Gem::UserInteraction
Expand Down Expand Up @@ -55,9 +56,8 @@ def self.make(dest_path, results, make_dir = Dir.pwd, sitedir = nil, targets = [
end

def self.ruby
require "shellwords"
# Gem.ruby is quoted if it contains whitespace
cmd = Gem.ruby.shellsplit
cmd = Shellwords.split(Gem.ruby)

# This load_path is only needed when running rubygems test without a proper installation.
# Prepending it in a normal installation will cause problem with order of $LOAD_PATH.
Expand All @@ -82,8 +82,7 @@ def self.run(command, results, command_name = nil, dir = Dir.pwd, env = {})
p(command)
end
results << "current directory: #{dir}"
require "shellwords"
results << command.shelljoin
results << Shellwords.join(command)

require "open3"
# Set $SOURCE_DATE_EPOCH for the subprocess.
Expand Down
4 changes: 2 additions & 2 deletions lib/rubygems/ext/cargo_builder.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require_relative "../shellwords"

# This class is used by rubygems to build Rust extensions. It is a thin-wrapper
# over the `cargo rustc` command which takes care of building Rust code in a way
# that Ruby can use.
Expand Down Expand Up @@ -73,8 +75,6 @@ def build_env
end

def cargo_command(cargo_toml, dest_path, args = [], crate_name = nil)
require "shellwords"

cmd = []
cmd += [cargo, "rustc"]
cmd += ["--crate-type", "cdylib"]
Expand Down
5 changes: 3 additions & 2 deletions lib/rubygems/ext/rake_builder.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require_relative "../shellwords"

#--
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
# All rights reserved.
Expand All @@ -15,8 +17,7 @@ def self.build(extension, dest_path, results, args=[], lib_dir=nil, extension_di
rake = ENV["rake"]

if rake
require "shellwords"
rake = rake.shellsplit
rake = Shellwords.split(rake)
else
begin
rake = ruby << "-rrubygems" << Gem.bin_path("rake", "rake")
Expand Down
3 changes: 3 additions & 0 deletions lib/rubygems/shellwords.rb
@@ -0,0 +1,3 @@
# frozen_string_literal: true

autoload :Shellwords, "shellwords"

0 comments on commit 27b0777

Please sign in to comment.