Skip to content

Commit

Permalink
Require SystemInclude only where needed
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Jan 31, 2024
1 parent 34ff696 commit eb7c3e5
Show file tree
Hide file tree
Showing 23 changed files with 57 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Library/Homebrew/cask/artifact/abstract_uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
require "cask/artifact/abstract_artifact"
require "cask/pkg"
require "extend/hash/keys"
require "system_command"

module Cask
module Artifact
# Abstract superclass for uninstall artifacts.
#
# @api private
class AbstractUninstall < AbstractArtifact
include SystemCommand::Mixin

ORDERED_DIRECTIVES = [
:early_script,
:launchctl,
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Cask
#
# @api private
class Audit
include SystemCommand::Mixin
include ::Utils::Curl
extend Attrable

Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/cask/quarantine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
require "system_config"
require "cask/caskroom"
require "cask/quarantine"
require "system_command"

module Homebrew
# Module containing diagnostic checks.
Expand Down Expand Up @@ -48,6 +49,8 @@ def self.checks(type, fatal: true)

# Diagnostic checks.
class Checks
include SystemCommand::Mixin

def initialize(verbose: true)
@verbose = verbose
end
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,6 +29,7 @@ class AbstractDownloadStrategy
extend Forwardable
include FileUtils
include Context
include SystemCommand::Mixin

# Extension for bottle downloads.
#
Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/extend/os/mac/keg.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/extend/pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require "resource"
require "metafiles"
require "extend/file/atomic"
require "system_command"

module DiskUsageExtension
sig { returns(Integer) }
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/github_packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Library/Homebrew/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def auto_update_command?
nil
end.compact.freeze

require "system_command"
require "exceptions"
require "utils"

Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/livecheck/strategy/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# frozen_string_literal: true

require "open3"
require "system_command"

module Homebrew
module Livecheck
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/os/mac/sdk.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# typed: true
# frozen_string_literal: true

require "system_command"

module OS
module Mac
# Class representing a macOS SDK.
Expand Down Expand Up @@ -32,6 +34,7 @@ def initialize(version, path, source)
# @api private
class BaseSDKLocator
extend T::Helpers
include SystemCommand::Mixin

abstract!

Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/readall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

require "formula"
require "cask/cask_loader"
require "system_command"

# Helper module for validating syntax in taps.
#
# @api private
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/
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions Library/Homebrew/system_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require "plist"
require "shellwords"

require "context"
require "extend/io"
require "utils/timer"

Expand Down Expand Up @@ -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
6 changes: 4 additions & 2 deletions Library/Homebrew/test/system_command_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "system_command"

describe SystemCommand do
describe "#initialize" do
subject(:command) do
Expand Down Expand Up @@ -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",
Expand All @@ -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

Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/unpack_strategy/dmg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/unversioned_cask_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
require "bundle_version"
require "cask/cask"
require "cask/installer"
require "system_command"

module Homebrew
# Check unversioned casks for updates by extracting their
# contents and guessing the version from contained files.
#
# @api private
class UnversionedCaskChecker
include SystemCommand::Mixin

sig { returns(Cask::Cask) }
attr_reader :cask

Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/utils/curl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
1 change: 0 additions & 1 deletion Library/Homebrew/utils/curl.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

module Utils::Curl
include Kernel
requires_ancestor { SystemCommand::Mixin }
end
4 changes: 4 additions & 0 deletions Library/Homebrew/utils/git.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/utils/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/utils/github/api.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# typed: true
# frozen_string_literal: true

require "system_command"
require "tempfile"
require "utils/shell"
require "utils/formatter"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/utils/tar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down

0 comments on commit eb7c3e5

Please sign in to comment.