Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Library/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ Layout/EndAlignment:
Layout/SpaceAroundOperators:
Enabled: false

# Auto-correct is broken (https://github.com/rubocop-hq/rubocop/issues/6300).
Layout/EmptyLineAfterGuardClause:
Enabled: false

# Auto-correct is broken (https://github.com/rubocop-hq/rubocop/issues/6258)
# and layout is not configurable (https://github.com/rubocop-hq/rubocop/issues/6254).
Layout/RescueEnsureAlignment:
Expand Down
3 changes: 1 addition & 2 deletions Library/.rubocop_shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ Style/CollectionMethods:
Style/FormatStringToken:
EnforcedStyle: template

# This often leads to lines longer than the maximum line length.
# https://github.com/rubocop-hq/rubocop/issues/6149
# This shouldn't be enabled until LineLength is lower.
Style/IfUnlessModifier:
Enabled: false

Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ Style/GuardClause:
Style/HashSyntax:
EnforcedStyle: ruby19_no_mixed_keys

# LineLength is low enough here to re-enable it.
Style/IfUnlessModifier:
Enabled: true

# so many of these in formulae but none in here
Style/TrailingBodyOnMethodDefinition:
Enabled: true
18 changes: 9 additions & 9 deletions Library/Homebrew/brew.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
unless ENV["HOMEBREW_BREW_FILE"]
raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!"
end
raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" unless ENV["HOMEBREW_BREW_FILE"]

std_trap = trap("INT") { exit! 130 } # no backtrace thanks

Expand All @@ -10,6 +8,12 @@
raise "Homebrew must be run under Ruby 2.3! You're running #{RUBY_VERSION}."
end

# Load Bundler first of all if it's needed to avoid Gem version conflicts.
if ENV["HOMEBREW_INSTALL_BUNDLER_GEMS_FIRST"]
require_relative "utils/gems"
Homebrew.install_bundler_gems!
end

# Also define here so we can rescue regardless of location.
class MissingEnvironmentVariables < RuntimeError; end

Expand Down Expand Up @@ -92,9 +96,7 @@ class MissingEnvironmentVariables < RuntimeError; end
# `Homebrew.help` never returns, except for external/unknown commands.
end

if ENV["HOMEBREW_BUILD_FROM_SOURCE"]
odisabled("HOMEBREW_BUILD_FROM_SOURCE", "--build-from-source")
end
odisabled("HOMEBREW_BUILD_FROM_SOURCE", "--build-from-source") if ENV["HOMEBREW_BUILD_FROM_SOURCE"]

if internal_cmd
Homebrew.send cmd.to_s.tr("-", "_").downcase
Expand All @@ -113,9 +115,7 @@ class MissingEnvironmentVariables < RuntimeError; end

brew_uid = HOMEBREW_BREW_FILE.stat.uid
tap_commands = []
if Process.uid.zero? && !brew_uid.zero?
tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}]
end
tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] if Process.uid.zero? && !brew_uid.zero?
# Unset HOMEBREW_HELP to avoid confusing the tap
ENV.delete("HOMEBREW_HELP") if help_flag
tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{possible_tap}]
Expand Down
5 changes: 5 additions & 0 deletions Library/Homebrew/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,11 @@ then
esac
fi

if [[ "$HOMEBREW_COMMAND" = "audit" || "$HOMEBREW_COMMAND" = "style" ]]
then
export HOMEBREW_INSTALL_BUNDLER_GEMS_FIRST="1"
fi

# Set HOMEBREW_DEV_CMD_RUN for users who have run a development command.
# This makes them behave like HOMEBREW_DEVELOPERs for brew update.
if [[ -z "$HOMEBREW_DEVELOPER" ]]
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/cache_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def delete(key)
# Closes the underlying database (if it is created and open).
def close_if_open!
return unless @db

cache_path.dirname.mkpath
cache_path.atomic_write(JSON.dump(@db))
end
Expand All @@ -55,6 +56,7 @@ def created?
# @return [Time]
def mtime
return unless created?

cache_path.mtime
end

Expand Down
5 changes: 2 additions & 3 deletions Library/Homebrew/cask/artifact/abstract_uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def uninstall_quit(*bundle_ids, command: nil, **_)
Timeout.timeout(10) do
Kernel.loop do
next unless quit(bundle_id).success?

if running_processes(bundle_id).empty?
puts "Application '#{bundle_id}' quit successfully."
break
Expand Down Expand Up @@ -179,9 +180,7 @@ def quit(bundle_id)
# :signal should come after :quit so it can be used as a backup when :quit fails
def uninstall_signal(*signals, command: nil, **_)
signals.each do |pair|
unless pair.size == 2
raise CaskInvalidError.new(cask, "Each #{stanza} :signal must consist of 2 elements.")
end
raise CaskInvalidError.new(cask, "Each #{stanza} :signal must consist of 2 elements.") unless pair.size == 2

signal, bundle_id = pair
ohai "Signalling '#{signal}' to application ID '#{bundle_id}'"
Expand Down
4 changes: 1 addition & 3 deletions Library/Homebrew/cask/artifact/artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ def self.english_name
def self.from_args(cask, *args)
source_string, target_hash = args

if source_string.nil?
raise CaskInvalidError.new(cask.token, "no source given for #{english_name}")
end
raise CaskInvalidError.new(cask.token, "no source given for #{english_name}") if source_string.nil?

unless target_hash.is_a?(Hash)
raise CaskInvalidError.new(cask.token, "target required for #{english_name} '#{source_string}'")
Expand Down
4 changes: 1 addition & 3 deletions Library/Homebrew/cask/artifact/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ def install_phase(command: nil, **_)
cask.staged_path.join(path)
end

if absolute_path.exist? && !absolute_path.executable?
FileUtils.chmod "+x", absolute_path
end
FileUtils.chmod "+x", absolute_path if absolute_path.exist? && !absolute_path.executable?

executable = if absolute_path.exist?
absolute_path
Expand Down
4 changes: 1 addition & 3 deletions Library/Homebrew/cask/artifact/pkg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ def run_installer(command: nil, verbose: false, **_options)
"-target", "/"
]
args << "-verboseR" if verbose
if stanza_options.fetch(:allow_untrusted, false)
args << "-allowUntrusted"
end
args << "-allowUntrusted" if stanza_options.fetch(:allow_untrusted, false)
with_choices_file do |choices_path|
args << "-applyChoiceChangesXML" << choices_path if choices_path
env = {
Expand Down
4 changes: 1 addition & 3 deletions Library/Homebrew/cask/artifact/stage_only.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ module Cask
module Artifact
class StageOnly < AbstractArtifact
def self.from_args(cask, *args)
if args != [true]
raise CaskInvalidError.new(cask.token, "'stage_only' takes only a single argument: true")
end
raise CaskInvalidError.new(cask.token, "'stage_only' takes only a single argument: true") if args != [true]

new(cask)
end
Expand Down
9 changes: 3 additions & 6 deletions Library/Homebrew/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,14 @@ def check_single_uninstall_zap
k.directives.key?(:uninstall_preflight)
end

if count > 1
add_warning "only a single uninstall_preflight stanza is allowed"
end
add_warning "only a single uninstall_preflight stanza is allowed" if count > 1

count = cask.artifacts.count do |k|
k.is_a?(Artifact::PostflightBlock) &&
k.directives.key?(:uninstall_postflight)
end

if count > 1
add_warning "only a single uninstall_postflight stanza is allowed"
end
add_warning "only a single uninstall_postflight stanza is allowed" if count > 1

return unless cask.artifacts.count { |k| k.is_a?(Artifact::Zap) } > 1

Expand Down Expand Up @@ -296,6 +292,7 @@ def check_download

def check_https_availability
return unless download

if !cask.url.blank? && !cask.url.using
check_url_for_https_availability(cask.url, user_agents: [cask.url.user_agent])
end
Expand Down
16 changes: 4 additions & 12 deletions Library/Homebrew/cask/cask_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ def load

begin
instance_eval(content, path).tap do |cask|
unless cask.is_a?(Cask)
raise CaskUnreadableError.new(token, "'#{path}' does not contain a cask.")
end
raise CaskUnreadableError.new(token, "'#{path}' does not contain a cask.") unless cask.is_a?(Cask)
end
rescue NameError, ArgumentError, ScriptError => e
raise CaskUnreadableError.new(token, e.message)
Expand All @@ -70,9 +68,7 @@ def load
private

def cask(header_token, **options, &block)
if token != header_token
raise CaskTokenMismatchError.new(token, header_token)
end
raise CaskTokenMismatchError.new(token, header_token) if token != header_token

super(header_token, **options, sourcefile_path: path, &block)
end
Expand Down Expand Up @@ -192,9 +188,7 @@ def self.for(ref)
return loader_class.new(ref) if loader_class.can_load?(ref)
end

if FromTapPathLoader.can_load?(default_path(ref))
return FromTapPathLoader.new(default_path(ref))
end
return FromTapPathLoader.new(default_path(ref)) if FromTapPathLoader.can_load?(default_path(ref))

case (possible_tap_casks = tap_paths(ref)).count
when 1
Expand All @@ -209,9 +203,7 @@ def self.for(ref)
end

possible_installed_cask = Cask.new(ref)
if possible_installed_cask.installed?
return FromPathLoader.new(possible_installed_cask.installed_caskfile)
end
return FromPathLoader.new(possible_installed_cask.installed_caskfile) if possible_installed_cask.installed?

NullLoader.new(ref)
end
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/cask/cmd/automerge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def run
end

return if failed.empty?

$stderr.puts
raise CaskError, "Failed merging the following PRs:\n#{failed.join("\n")}"
end
Expand Down Expand Up @@ -90,8 +91,10 @@ def check_diff(pr)

def diff_is_single_cask(diff)
return false unless diff.files.count == 1

file = diff.files.first
return false unless file.a_path == file.b_path

file.a_path.match?(%r{\ACasks/[^/]+\.rb\Z})
end

Expand Down
4 changes: 1 addition & 3 deletions Library/Homebrew/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ def language_eval

return @language = nil if @language_blocks.nil? || @language_blocks.empty?

if @language_blocks.default.nil?
raise CaskInvalidError.new(cask, "No default language specified.")
end
raise CaskInvalidError.new(cask, "No default language specified.") if @language_blocks.default.nil?

locales = MacOS.languages
.map do |language|
Expand Down
12 changes: 3 additions & 9 deletions Library/Homebrew/cask/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,7 @@ def install

old_config = @cask.config

if @cask.installed? && !force? && !reinstall? && !upgrade?
raise CaskAlreadyInstalledError, @cask
end
raise CaskAlreadyInstalledError, @cask if @cask.installed? && !force? && !reinstall? && !upgrade?

check_conflicts

Expand All @@ -100,9 +98,7 @@ def install

install_artifacts

unless @cask.tap&.private?
::Utils::Analytics.report_event("cask_install", @cask.token)
end
::Utils::Analytics.report_event("cask_install", @cask.token) unless @cask.tap&.private?

puts summary
end
Expand All @@ -113,9 +109,7 @@ def check_conflicts
@cask.conflicts_with[:cask].each do |conflicting_cask|
begin
conflicting_cask = CaskLoader.load(conflicting_cask)
if conflicting_cask.installed?
raise CaskConflictError.new(@cask, conflicting_cask)
end
raise CaskConflictError.new(@cask, conflicting_cask) if conflicting_cask.installed?
rescue CaskUnavailableError
next # Ignore conflicting Casks that do not exist.
end
Expand Down
12 changes: 3 additions & 9 deletions Library/Homebrew/cask/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ def metadata_master_container_path
def metadata_versioned_path(version: self.version)
cask_version = (version || :unknown).to_s

if cask_version.empty?
raise CaskError, "Cannot create metadata path with empty version."
end
raise CaskError, "Cannot create metadata path with empty version." if cask_version.empty?

metadata_master_container_path.join(cask_version)
end

def metadata_timestamped_path(version: self.version, timestamp: :latest, create: false)
if create && timestamp == :latest
raise CaskError, "Cannot create metadata path when timestamp is :latest."
end
raise CaskError, "Cannot create metadata path when timestamp is :latest." if create && timestamp == :latest

path = if timestamp == :latest
Pathname.glob(metadata_versioned_path(version: version).join("*")).max
Expand All @@ -37,9 +33,7 @@ def metadata_timestamped_path(version: self.version, timestamp: :latest, create:
end

def metadata_subdir(leaf, version: self.version, timestamp: :latest, create: false)
if create && timestamp == :latest
raise CaskError, "Cannot create metadata subdir when timestamp is :latest."
end
raise CaskError, "Cannot create metadata subdir when timestamp is :latest." if create && timestamp == :latest

unless leaf.respond_to?(:empty?) && !leaf.empty?
raise CaskError, "Cannot create metadata subdir for empty leaf."
Expand Down
16 changes: 4 additions & 12 deletions Library/Homebrew/caveats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,8 @@ def keg_only_text(skip_reason: false)

If you need to have #{f.name} first in your PATH run:
EOS
if f.bin.directory?
s << " #{Utils::Shell.prepend_path_in_profile(f.opt_bin.to_s)}\n"
end
if f.sbin.directory?
s << " #{Utils::Shell.prepend_path_in_profile(f.opt_sbin.to_s)}\n"
end
s << " #{Utils::Shell.prepend_path_in_profile(f.opt_bin.to_s)}\n" if f.bin.directory?
s << " #{Utils::Shell.prepend_path_in_profile(f.opt_sbin.to_s)}\n" if f.sbin.directory?
end

if f.lib.directory? || f.include.directory?
Expand All @@ -61,13 +57,9 @@ def keg_only_text(skip_reason: false)
For compilers to find #{f.name} you may need to set:
EOS

if f.lib.directory?
s << " #{Utils::Shell.export_value("LDFLAGS", "-L#{f.opt_lib}")}\n"
end
s << " #{Utils::Shell.export_value("LDFLAGS", "-L#{f.opt_lib}")}\n" if f.lib.directory?

if f.include.directory?
s << " #{Utils::Shell.export_value("CPPFLAGS", "-I#{f.opt_include}")}\n"
end
s << " #{Utils::Shell.export_value("CPPFLAGS", "-I#{f.opt_include}")}\n" if f.include.directory?

if which("pkg-config", ENV["HOMEBREW_PATH"]) &&
((f.lib/"pkgconfig").directory? || (f.share/"pkgconfig").directory?)
Expand Down
8 changes: 2 additions & 6 deletions Library/Homebrew/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ def clean

# Get rid of any info 'dir' files, so they don't conflict at the link stage
info_dir_file = @f.info + "dir"
if info_dir_file.file? && !@f.skip_clean?(info_dir_file)
observe_file_removal info_dir_file
end
observe_file_removal info_dir_file if info_dir_file.file? && !@f.skip_clean?(info_dir_file)

prune
end
Expand Down Expand Up @@ -111,9 +109,7 @@ def clean_dir(d)
end
if ARGV.debug?
old_perms = path.stat.mode & 0777
if perms != old_perms
puts "Fixing #{path} permissions from #{old_perms.to_s(8)} to #{perms.to_s(8)}"
end
puts "Fixing #{path} permissions from #{old_perms.to_s(8)} to #{perms.to_s(8)}" if perms != old_perms
end
path.chmod perms
end
Expand Down
Loading