From 27b07776c99dfb4a8a4e6885462786c03e9b0660 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Fri, 9 Jun 2023 22:10:56 +0900 Subject: [PATCH] [rubygems/rubygems] Autoload shellwords when it's needed. https://github.com/rubygems/rubygems/commit/e916ccb2d9 --- lib/rubygems/ext/builder.rb | 7 +++---- lib/rubygems/ext/cargo_builder.rb | 4 ++-- lib/rubygems/ext/rake_builder.rb | 5 +++-- lib/rubygems/shellwords.rb | 3 +++ 4 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 lib/rubygems/shellwords.rb diff --git a/lib/rubygems/ext/builder.rb b/lib/rubygems/ext/builder.rb index c39afc9c9dbd64..242dd0125af2c7 100644 --- a/lib/rubygems/ext/builder.rb +++ b/lib/rubygems/ext/builder.rb @@ -7,6 +7,7 @@ #++ require_relative "../user_interaction" +require_relative "../shellwords" class Gem::Ext::Builder include Gem::UserInteraction @@ -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. @@ -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. diff --git a/lib/rubygems/ext/cargo_builder.rb b/lib/rubygems/ext/cargo_builder.rb index fcead1577bbb6f..0480b4ffdc2bc2 100644 --- a/lib/rubygems/ext/cargo_builder.rb +++ b/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. @@ -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"] diff --git a/lib/rubygems/ext/rake_builder.rb b/lib/rubygems/ext/rake_builder.rb index 2b9a23a23f8acc..0171807b39e744 100644 --- a/lib/rubygems/ext/rake_builder.rb +++ b/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. @@ -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") diff --git a/lib/rubygems/shellwords.rb b/lib/rubygems/shellwords.rb new file mode 100644 index 00000000000000..741dccb3635523 --- /dev/null +++ b/lib/rubygems/shellwords.rb @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +autoload :Shellwords, "shellwords"