Merge pull request #18430 from Homebrew/files-strict-type

completions formula_pin: `typed: strict`, cxxstdlib: `typed: strong`
This commit is contained in:
Mike McQuaid 2024-09-27 17:12:54 +01:00 committed by GitHub
commit 7156fb7d3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 14 deletions

View File

@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "utils/link" require "utils/link"
@ -16,8 +16,8 @@ module Homebrew
keyword_init: true, keyword_init: true,
) )
COMPLETIONS_DIR = (HOMEBREW_REPOSITORY/"completions").freeze COMPLETIONS_DIR = T.let((HOMEBREW_REPOSITORY/"completions").freeze, Pathname)
TEMPLATE_DIR = (HOMEBREW_LIBRARY_PATH/"completions").freeze TEMPLATE_DIR = T.let((HOMEBREW_LIBRARY_PATH/"completions").freeze, Pathname)
SHELLS = %w[bash fish zsh].freeze SHELLS = %w[bash fish zsh].freeze
COMPLETIONS_EXCLUSION_LIST = %w[ COMPLETIONS_EXCLUSION_LIST = %w[
@ -26,7 +26,7 @@ module Homebrew
update-report update-report
].freeze ].freeze
BASH_NAMED_ARGS_COMPLETION_FUNCTION_MAPPING = { BASH_NAMED_ARGS_COMPLETION_FUNCTION_MAPPING = T.let({
formula: "__brew_complete_formulae", formula: "__brew_complete_formulae",
installed_formula: "__brew_complete_installed_formulae", installed_formula: "__brew_complete_installed_formulae",
outdated_formula: "__brew_complete_outdated_formulae", outdated_formula: "__brew_complete_outdated_formulae",
@ -38,9 +38,9 @@ module Homebrew
command: "__brew_complete_commands", command: "__brew_complete_commands",
diagnostic_check: '__brewcomp "${__HOMEBREW_DOCTOR_CHECKS=$(brew doctor --list-checks)}"', diagnostic_check: '__brewcomp "${__HOMEBREW_DOCTOR_CHECKS=$(brew doctor --list-checks)}"',
file: "__brew_complete_files", file: "__brew_complete_files",
}.freeze }.freeze, T::Hash[Symbol, String])
ZSH_NAMED_ARGS_COMPLETION_FUNCTION_MAPPING = { ZSH_NAMED_ARGS_COMPLETION_FUNCTION_MAPPING = T.let({
formula: "__brew_formulae", formula: "__brew_formulae",
installed_formula: "__brew_installed_formulae", installed_formula: "__brew_installed_formulae",
outdated_formula: "__brew_outdated_formulae", outdated_formula: "__brew_outdated_formulae",
@ -52,9 +52,9 @@ module Homebrew
command: "__brew_commands", command: "__brew_commands",
diagnostic_check: "__brew_diagnostic_checks", diagnostic_check: "__brew_diagnostic_checks",
file: "__brew_formulae_or_ruby_files", file: "__brew_formulae_or_ruby_files",
}.freeze }.freeze, T::Hash[Symbol, String])
FISH_NAMED_ARGS_COMPLETION_FUNCTION_MAPPING = { FISH_NAMED_ARGS_COMPLETION_FUNCTION_MAPPING = T.let({
formula: "__fish_brew_suggest_formulae_all", formula: "__fish_brew_suggest_formulae_all",
installed_formula: "__fish_brew_suggest_formulae_installed", installed_formula: "__fish_brew_suggest_formulae_installed",
outdated_formula: "__fish_brew_suggest_formulae_outdated", outdated_formula: "__fish_brew_suggest_formulae_outdated",
@ -65,7 +65,7 @@ module Homebrew
installed_tap: "__fish_brew_suggest_taps_installed", installed_tap: "__fish_brew_suggest_taps_installed",
command: "__fish_brew_suggest_commands", command: "__fish_brew_suggest_commands",
diagnostic_check: "__fish_brew_suggest_diagnostic_checks", diagnostic_check: "__fish_brew_suggest_diagnostic_checks",
}.freeze }.freeze, T::Hash[Symbol, String])
sig { void } sig { void }
def self.link! def self.link!
@ -264,6 +264,7 @@ module Homebrew
COMPLETION COMPLETION
end end
sig { params(command: String, option: String).returns(String) }
def self.generate_zsh_option_exclusions(command, option) def self.generate_zsh_option_exclusions(command, option)
conflicts = Commands.option_conflicts(command, option.gsub(/^--/, "")) conflicts = Commands.option_conflicts(command, option.gsub(/^--/, ""))
return "" unless conflicts.presence return "" unless conflicts.presence

View File

@ -1,23 +1,30 @@
# typed: true # rubocop:todo Sorbet/StrictSigil # typed: strong
# frozen_string_literal: true # frozen_string_literal: true
require "compilers" require "compilers"
# Combination of C++ standard library and compiler. # Combination of C++ standard library and compiler.
class CxxStdlib class CxxStdlib
sig { params(type: T.nilable(Symbol), compiler: T.any(Symbol, String)).returns(CxxStdlib) }
def self.create(type, compiler) def self.create(type, compiler)
raise ArgumentError, "Invalid C++ stdlib type: #{type}" if type && [:libstdcxx, :libcxx].exclude?(type) raise ArgumentError, "Invalid C++ stdlib type: #{type}" if type && [:libstdcxx, :libcxx].exclude?(type)
CxxStdlib.new(type, compiler) CxxStdlib.new(type, compiler)
end end
attr_reader :type, :compiler sig { returns(T.nilable(Symbol)) }
attr_reader :type
sig { returns(Symbol) }
attr_reader :compiler
sig { params(type: T.nilable(Symbol), compiler: T.any(Symbol, String)).void }
def initialize(type, compiler) def initialize(type, compiler)
@type = type @type = type
@compiler = compiler.to_sym @compiler = T.let(compiler.to_sym, Symbol)
end end
sig { returns(String) }
def type_string def type_string
type.to_s.gsub(/cxx$/, "c++") type.to_s.gsub(/cxx$/, "c++")
end end

View File

@ -1,24 +1,28 @@
# typed: true # rubocop:todo Sorbet/StrictSigil # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "keg" require "keg"
# Helper functions for pinning a formula. # Helper functions for pinning a formula.
class FormulaPin class FormulaPin
sig { params(formula: Formula).void }
def initialize(formula) def initialize(formula)
@formula = formula @formula = formula
end end
sig { returns(Pathname) }
def path def path
HOMEBREW_PINNED_KEGS/@formula.name HOMEBREW_PINNED_KEGS/@formula.name
end end
sig { params(version: PkgVersion).void }
def pin_at(version) def pin_at(version)
HOMEBREW_PINNED_KEGS.mkpath HOMEBREW_PINNED_KEGS.mkpath
version_path = @formula.rack/version version_path = @formula.rack/version.to_s
path.make_relative_symlink(version_path) if !pinned? && version_path.exist? path.make_relative_symlink(version_path) if !pinned? && version_path.exist?
end end
sig { void }
def pin def pin
latest_keg = @formula.installed_kegs.max_by(&:scheme_and_version) latest_keg = @formula.installed_kegs.max_by(&:scheme_and_version)
return if latest_keg.nil? return if latest_keg.nil?
@ -26,19 +30,23 @@ class FormulaPin
pin_at(latest_keg.version) pin_at(latest_keg.version)
end end
sig { void }
def unpin def unpin
path.unlink if pinned? path.unlink if pinned?
HOMEBREW_PINNED_KEGS.rmdir_if_possible HOMEBREW_PINNED_KEGS.rmdir_if_possible
end end
sig { returns(T::Boolean) }
def pinned? def pinned?
path.symlink? path.symlink?
end end
sig { returns(T::Boolean) }
def pinnable? def pinnable?
!@formula.installed_prefixes.empty? !@formula.installed_prefixes.empty?
end end
sig { returns(T.nilable(PkgVersion)) }
def pinned_version def pinned_version
Keg.new(path.resolved_path).version if pinned? Keg.new(path.resolved_path).version if pinned?
end end