From eb7c3e52a0b9b732a5bab09def0df296051e5539 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Fri, 26 Jan 2024 17:33:55 -0800 Subject: [PATCH] Require SystemInclude only where needed --- Library/Homebrew/cask/artifact/abstract_uninstall.rb | 3 +++ Library/Homebrew/cask/audit.rb | 1 + Library/Homebrew/cask/quarantine.rb | 3 +++ Library/Homebrew/diagnostic.rb | 3 +++ Library/Homebrew/download_strategy.rb | 2 ++ Library/Homebrew/extend/os/mac/keg.rb | 4 ++++ Library/Homebrew/extend/pathname.rb | 2 ++ Library/Homebrew/github_packages.rb | 2 ++ Library/Homebrew/global.rb | 1 - Library/Homebrew/livecheck/strategy/git.rb | 3 +++ Library/Homebrew/os/mac/sdk.rb | 3 +++ Library/Homebrew/readall.rb | 2 ++ Library/Homebrew/style.rb | 3 +++ Library/Homebrew/system_command.rb | 5 +---- Library/Homebrew/test/system_command_spec.rb | 6 ++++-- Library/Homebrew/unpack_strategy/dmg.rb | 4 ++++ Library/Homebrew/unversioned_cask_checker.rb | 3 +++ Library/Homebrew/utils/curl.rb | 4 ++++ Library/Homebrew/utils/curl.rbi | 1 - Library/Homebrew/utils/git.rb | 4 ++++ Library/Homebrew/utils/github.rb | 2 +- Library/Homebrew/utils/github/api.rb | 3 +++ Library/Homebrew/utils/tar.rb | 2 ++ 23 files changed, 57 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index a08431eb93409..61af5bd458468 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -7,6 +7,7 @@ require "cask/artifact/abstract_artifact" require "cask/pkg" require "extend/hash/keys" +require "system_command" module Cask module Artifact @@ -14,6 +15,8 @@ module Artifact # # @api private class AbstractUninstall < AbstractArtifact + include SystemCommand::Mixin + ORDERED_DIRECTIVES = [ :early_script, :launchctl, diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index 85f6df62f31a5..51846d807730f 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -17,6 +17,7 @@ module Cask # # @api private class Audit + include SystemCommand::Mixin include ::Utils::Curl extend Attrable diff --git a/Library/Homebrew/cask/quarantine.rb b/Library/Homebrew/cask/quarantine.rb index 446f42e3f327c..a93525bd74c09 100644 --- a/Library/Homebrew/cask/quarantine.rb +++ b/Library/Homebrew/cask/quarantine.rb @@ -3,12 +3,15 @@ require "development_tools" require "cask/exceptions" +require "system_command" module Cask # Helper module for quarantining files. # # @api private module Quarantine + extend SystemCommand::Mixin + QUARANTINE_ATTRIBUTE = "com.apple.quarantine" QUARANTINE_SCRIPT = (HOMEBREW_LIBRARY_PATH/"cask/utils/quarantine.swift").freeze diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 99630fe1f7412..b039069da96d0 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -11,6 +11,7 @@ require "system_config" require "cask/caskroom" require "cask/quarantine" +require "system_command" module Homebrew # Module containing diagnostic checks. @@ -48,6 +49,8 @@ def self.checks(type, fatal: true) # Diagnostic checks. class Checks + include SystemCommand::Mixin + def initialize(verbose: true) @verbose = verbose end diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index f96eb0274e4bb..cb364c2441f8b 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -7,6 +7,7 @@ require "lazy_object" require "cgi" require "lock_file" +require "system_command" # Need to define this before requiring Mechanize to avoid: # uninitialized constant Mechanize @@ -28,6 +29,7 @@ class AbstractDownloadStrategy extend Forwardable include FileUtils include Context + include SystemCommand::Mixin # Extension for bottle downloads. # diff --git a/Library/Homebrew/extend/os/mac/keg.rb b/Library/Homebrew/extend/os/mac/keg.rb index 788f548f0e831..097e58f65e6da 100644 --- a/Library/Homebrew/extend/os/mac/keg.rb +++ b/Library/Homebrew/extend/os/mac/keg.rb @@ -1,7 +1,11 @@ # typed: true # frozen_string_literal: true +require "system_command" + class Keg + include SystemCommand::Mixin + GENERIC_KEG_LINK_DIRECTORIES = (remove_const :KEG_LINK_DIRECTORIES).freeze KEG_LINK_DIRECTORIES = (GENERIC_KEG_LINK_DIRECTORIES + ["Frameworks"]).freeze GENERIC_MUST_EXIST_SUBDIRECTORIES = (remove_const :MUST_EXIST_SUBDIRECTORIES).freeze diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index c836d26ddf80f..5f363c088d194 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -5,6 +5,7 @@ require "resource" require "metafiles" require "extend/file/atomic" +require "system_command" module DiskUsageExtension sig { returns(Integer) } @@ -77,6 +78,7 @@ def compute_disk_usage # Homebrew extends Ruby's `Pathname` to make our code more readable. # @see https://ruby-doc.org/stdlib-2.6.3/libdoc/pathname/rdoc/Pathname.html Ruby's Pathname API class Pathname + include SystemCommand::Mixin include DiskUsageExtension # Moves a file from the original location to the {Pathname}'s. diff --git a/Library/Homebrew/github_packages.rb b/Library/Homebrew/github_packages.rb index 75c8b62604410..b54ae151378d7 100644 --- a/Library/Homebrew/github_packages.rb +++ b/Library/Homebrew/github_packages.rb @@ -5,12 +5,14 @@ require "json" require "zlib" require "extend/hash/keys" +require "system_command" # GitHub Packages client. # # @api private class GitHubPackages include Context + include SystemCommand::Mixin URL_DOMAIN = "ghcr.io" URL_PREFIX = "https://#{URL_DOMAIN}/v2/".freeze diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 0a04c785cde9a..3abfdf0f86bc6 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -137,7 +137,6 @@ def auto_update_command? nil end.compact.freeze -require "system_command" require "exceptions" require "utils" diff --git a/Library/Homebrew/livecheck/strategy/git.rb b/Library/Homebrew/livecheck/strategy/git.rb index 77dc3d2587dff..8414baca23951 100644 --- a/Library/Homebrew/livecheck/strategy/git.rb +++ b/Library/Homebrew/livecheck/strategy/git.rb @@ -2,6 +2,7 @@ # frozen_string_literal: true require "open3" +require "system_command" module Homebrew module Livecheck @@ -24,6 +25,8 @@ module Strategy # # @api public class Git + extend SystemCommand::Mixin + # The priority of the strategy on an informal scale of 1 to 10 (from # lowest to highest). PRIORITY = 8 diff --git a/Library/Homebrew/os/mac/sdk.rb b/Library/Homebrew/os/mac/sdk.rb index 23c0e52202222..44d5dd7df4b6c 100644 --- a/Library/Homebrew/os/mac/sdk.rb +++ b/Library/Homebrew/os/mac/sdk.rb @@ -1,6 +1,8 @@ # typed: true # frozen_string_literal: true +require "system_command" + module OS module Mac # Class representing a macOS SDK. @@ -32,6 +34,7 @@ def initialize(version, path, source) # @api private class BaseSDKLocator extend T::Helpers + include SystemCommand::Mixin abstract! diff --git a/Library/Homebrew/readall.rb b/Library/Homebrew/readall.rb index 93f2b4ecbc87b..91407529aaa01 100644 --- a/Library/Homebrew/readall.rb +++ b/Library/Homebrew/readall.rb @@ -3,6 +3,7 @@ require "formula" require "cask/cask_loader" +require "system_command" # Helper module for validating syntax in taps. # @@ -10,6 +11,7 @@ module Readall class << self include Cachable + include SystemCommand::Mixin # TODO: remove this once the `MacOS` module is undefined on Linux MACOS_MODULE_REGEX = /\b(MacOS|OS::Mac)(\.|::)\b/ diff --git a/Library/Homebrew/style.rb b/Library/Homebrew/style.rb index 6c8240c0f58f1..d5e63ffda464c 100644 --- a/Library/Homebrew/style.rb +++ b/Library/Homebrew/style.rb @@ -3,12 +3,15 @@ require "shellwords" require "source_location" +require "system_command" module Homebrew # Helper module for running RuboCop. # # @api private module Style + extend SystemCommand::Mixin + # Checks style for a list of files, printing simple RuboCop output. # Returns true if violations were found, false otherwise. def self.check_style_and_print(files, **options) diff --git a/Library/Homebrew/system_command.rb b/Library/Homebrew/system_command.rb index 4d91367dfd1b7..d9935d007d41c 100644 --- a/Library/Homebrew/system_command.rb +++ b/Library/Homebrew/system_command.rb @@ -6,6 +6,7 @@ require "plist" require "shellwords" +require "context" require "extend/io" require "utils/timer" @@ -405,7 +406,3 @@ def warn_plist_garbage(garbage) private :warn_plist_garbage end end - -# Make `system_command` available everywhere. -# FIXME: Include this explicitly only where it is needed. -include SystemCommand::Mixin # rubocop:disable Style/MixinUsage diff --git a/Library/Homebrew/test/system_command_spec.rb b/Library/Homebrew/test/system_command_spec.rb index 232d4d84a633e..8c4b9e8fd5280 100644 --- a/Library/Homebrew/test/system_command_spec.rb +++ b/Library/Homebrew/test/system_command_spec.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "system_command" + describe SystemCommand do describe "#initialize" do subject(:command) do @@ -284,7 +286,7 @@ it 'does not format `stderr` when it starts with \r' do expect do - system_command \ + Class.new.extend(SystemCommand::Mixin).system_command \ "bash", args: [ "-c", @@ -308,7 +310,7 @@ end it "does not interpret the executable as a shell line" do - expect(system_command(executable)).to be_a_success + expect(Class.new.extend(SystemCommand::Mixin).system_command(executable)).to be_a_success end end diff --git a/Library/Homebrew/unpack_strategy/dmg.rb b/Library/Homebrew/unpack_strategy/dmg.rb index 21cc3326f7ceb..7d96dd67c50d3 100644 --- a/Library/Homebrew/unpack_strategy/dmg.rb +++ b/Library/Homebrew/unpack_strategy/dmg.rb @@ -2,14 +2,18 @@ # frozen_string_literal: true require "tempfile" +require "system_command" module UnpackStrategy # Strategy for unpacking disk images. class Dmg + extend SystemCommand::Mixin include UnpackStrategy # Helper module for listing the contents of a volume mounted from a disk image. module Bom + extend SystemCommand::Mixin + DMG_METADATA = Set.new(%w[ .background .com.apple.timemachine.donotpresent diff --git a/Library/Homebrew/unversioned_cask_checker.rb b/Library/Homebrew/unversioned_cask_checker.rb index 842181365ee69..3a56ddc33d495 100644 --- a/Library/Homebrew/unversioned_cask_checker.rb +++ b/Library/Homebrew/unversioned_cask_checker.rb @@ -4,6 +4,7 @@ require "bundle_version" require "cask/cask" require "cask/installer" +require "system_command" module Homebrew # Check unversioned casks for updates by extracting their @@ -11,6 +12,8 @@ module Homebrew # # @api private class UnversionedCaskChecker + include SystemCommand::Mixin + sig { returns(Cask::Cask) } attr_reader :cask diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 47110f623755f..ffd1d0ff055a3 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -4,12 +4,16 @@ require "open3" require "utils/timer" +require "system_command" module Utils # Helper function for interacting with `curl`. # # @api private module Curl + include SystemCommand::Mixin + extend SystemCommand::Mixin + # This regex is used to extract the part of an ETag within quotation marks, # ignoring any leading weak validator indicator (`W/`). This simplifies # ETag comparison in `#curl_check_http_content`. diff --git a/Library/Homebrew/utils/curl.rbi b/Library/Homebrew/utils/curl.rbi index e69d89d750476..0f6a0b720568e 100644 --- a/Library/Homebrew/utils/curl.rbi +++ b/Library/Homebrew/utils/curl.rbi @@ -2,5 +2,4 @@ module Utils::Curl include Kernel - requires_ancestor { SystemCommand::Mixin } end diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb index 2e42b7024d5ec..bb55c7ec9f5dd 100644 --- a/Library/Homebrew/utils/git.rb +++ b/Library/Homebrew/utils/git.rb @@ -1,12 +1,16 @@ # typed: true # frozen_string_literal: true +require "system_command" + module Utils # Helper functions for querying Git information. # # @see GitRepository # @api private module Git + extend SystemCommand::Mixin + def self.available? version.present? end diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 4fef5cf74af78..d2527f130cfd2 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -11,7 +11,7 @@ # # @api private module GitHub - include SystemCommand::Mixin + extend SystemCommand::Mixin def self.check_runs(repo: nil, commit: nil, pull_request: nil) if pull_request diff --git a/Library/Homebrew/utils/github/api.rb b/Library/Homebrew/utils/github/api.rb index 07a38e22f5883..bff224f126cf0 100644 --- a/Library/Homebrew/utils/github/api.rb +++ b/Library/Homebrew/utils/github/api.rb @@ -1,6 +1,7 @@ # typed: true # frozen_string_literal: true +require "system_command" require "tempfile" require "utils/shell" require "utils/formatter" @@ -32,6 +33,8 @@ def self.pat_blurb(scopes = ALL_SCOPES) # # @api private module API + extend SystemCommand::Mixin + # Generic API error. class Error < RuntimeError attr_reader :github_message diff --git a/Library/Homebrew/utils/tar.rb b/Library/Homebrew/utils/tar.rb index cb0ff5fbcadb6..ab7b411f5eb61 100644 --- a/Library/Homebrew/utils/tar.rb +++ b/Library/Homebrew/utils/tar.rb @@ -9,6 +9,8 @@ module Utils # @api private module Tar class << self + include SystemCommand::Mixin + TAR_FILE_EXTENSIONS = %w[.tar .tb2 .tbz .tbz2 .tgz .tlz .txz .tZ].freeze def available?