Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sorbet: Migrate dev-cmd files from typed: true to typed: strict #17606

Merged
merged 24 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
34caeb7
dev-cmd/unbottled: Bump to Sorbet `typed: strict`
issyl0 Jun 30, 2024
c57cd4b
dev-cmd/contributions: Bump to Sorbet `typed: strict`
issyl0 Jun 30, 2024
1b517a9
dev-cmd/irb: Bump to Sorbet `typed: strict`
issyl0 Jun 30, 2024
57ba220
dev-cmd/update-sponsors: Bump to Sorbet `typed: strict`
issyl0 Jun 30, 2024
69cf1df
dev-cmd/livecheck: Bump to Sorbet `typed: strict`
issyl0 Jun 30, 2024
3b28e90
dev-cmd/tap-new: Bump to Sorbet `typed: strict`
issyl0 Jun 30, 2024
944790a
dev-cmd/generate-cask-api: Bump to Sorbet `typed: strict`
issyl0 Jun 30, 2024
3bf6a01
dev-cmd/generate-formula-api: Bump to Sorbet `typed: strict`
issyl0 Jun 30, 2024
0837f7c
dev-cmd/test: Bump to Sorbet `typed: strict`
issyl0 Jun 30, 2024
d5af469
dev-cmd/tests: Bump to Sorbet `typed: strict`
issyl0 Jun 30, 2024
6b995ad
dev-cmd/pr-upload: Bump to Sorbet `typed: strict`
issyl0 Jun 30, 2024
8587f4b
dev-cmd/bump-formula-pr: Bump to Sorbet `typed: strict`
issyl0 Jul 1, 2024
b181739
dev-cmd/pr-pull: Bump to Sorbet `typed: strict`
issyl0 Jul 1, 2024
9e0a749
dev-cmd/extract: Can't be `typed: strict` because of `undef` usage
issyl0 Jul 1, 2024
f854a9f
dev-cmd/audit: Bump to Sorbet `typed: strict`
issyl0 Jul 1, 2024
8360218
Run `brew style` on all the new Sorbet sigs
issyl0 Jul 1, 2024
3b695c6
dev-cmd/bottle: Bump to Sorbet `typed: strict`
issyl0 Jul 1, 2024
9130dd1
dev-cmd/contributions: Tighten up type sigs
issyl0 Jul 1, 2024
b9b065a
dev-cmd/bottle: Fix type errors (strings, symbols, either, none) than…
issyl0 Jul 1, 2024
1db0834
dev-cmd/bottle: The `cellar_parameter_needed?` method returns always …
issyl0 Jul 2, 2024
3d09094
Fewer `T.must`s
issyl0 Jul 2, 2024
9baf50a
Get rid of even more `T.must`s
issyl0 Jul 3, 2024
b6f142f
Fewer `T.must`s
issyl0 Jul 3, 2024
4b83521
dev_cmd/irb: Straight away `require "formula"`
issyl0 Jul 3, 2024
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: 3 additions & 1 deletion Library/Homebrew/dev-cmd/audit.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "abstract_command"
Expand Down Expand Up @@ -329,6 +329,7 @@ def run

private

sig { params(results: T::Hash[[Symbol, Pathname], T::Array[T::Hash[Symbol, T.untyped]]]).void }
def print_problems(results)
results.each do |(name, path), problems|
problem_lines = format_problem_lines(problems)
Expand All @@ -343,6 +344,7 @@ def print_problems(results)
end
end

sig { params(problems: T::Array[T::Hash[Symbol, T.untyped]]).returns(T::Array[String]) }
def format_problem_lines(problems)
problems.map do |problem|
status = " #{Formatter.success("[corrected]")}" if problem.fetch(:corrected)
Expand Down
46 changes: 37 additions & 9 deletions Library/Homebrew/dev-cmd/bottle.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "abstract_command"
Expand All @@ -20,7 +20,7 @@
class Bottle < AbstractCommand
include FileUtils

BOTTLE_ERB = <<-EOS.freeze
BOTTLE_ERB = T.let(<<-EOS.freeze, String)
bottle do
<% if [HOMEBREW_BOTTLE_DEFAULT_DOMAIN.to_s,
"#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}/bottles"].exclude?(root_url) %>
Expand All @@ -39,9 +39,9 @@

MAXIMUM_STRING_MATCHES = 100

ALLOWABLE_HOMEBREW_REPOSITORY_LINKS = [
ALLOWABLE_HOMEBREW_REPOSITORY_LINKS = T.let([
%r{#{Regexp.escape(HOMEBREW_LIBRARY)}/Homebrew/os/(mac|linux)/pkgconfig},
].freeze
].freeze, T::Array[Regexp])

cmd_args do
description <<~EOS
Expand Down Expand Up @@ -110,6 +110,10 @@
end
end

sig {
params(tag: Symbol, digest: T.any(Checksum, String), cellar: T.nilable(T.any(String, Symbol)),
tag_column: Integer, digest_column: Integer).returns(String)
}
def generate_sha256_line(tag, digest, cellar, tag_column, digest_column)
line = "sha256 "
tag_column += line.length
Expand All @@ -125,6 +129,7 @@
%Q(#{line}"#{digest}")
end

sig { params(bottle: BottleSpecification, root_url_using: T.nilable(String)).returns(String) }
def bottle_output(bottle, root_url_using)
cellars = bottle.checksums.filter_map do |checksum|
cellar = checksum["cellar"]
Expand Down Expand Up @@ -153,12 +158,14 @@
erb.result(erb_binding).gsub(/^\s*$\n/, "")
end

sig { params(filenames: T::Array[String]).returns(T::Array[T::Hash[String, T.untyped]]) }
def parse_json_files(filenames)
filenames.map do |filename|
JSON.parse(File.read(filename))
end
end

sig { params(json_files: T::Array[T::Hash[String, T.untyped]]).returns(T::Hash[String, T.untyped]) }
def merge_json_files(json_files)
json_files.reduce({}) do |hash, json_file|
json_file.each_value do |json_hash|
Expand All @@ -172,6 +179,10 @@
end
end

sig {
params(old_keys: T::Array[String], old_bottle_spec: BottleSpecification,
new_bottle_hash: T::Hash[String, T.untyped]).returns(T::Array[T::Array[String]])
}
def merge_bottle_spec(old_keys, old_bottle_spec, new_bottle_hash)
mismatches = []
checksums = []
Expand Down Expand Up @@ -214,16 +225,20 @@

private

sig {
params(string: String, keg: Keg, ignores: T::Array[String],
formula_and_runtime_deps_names: T.nilable(T::Array[String])).returns(T::Boolean)
}
def keg_contain?(string, keg, ignores, formula_and_runtime_deps_names = nil)
@put_string_exists_header, @put_filenames = nil

print_filename = lambda do |str, filename|
unless @put_string_exists_header
opoo "String '#{str}' still exists in these files:"
@put_string_exists_header = true
@put_string_exists_header = T.let(true, T.nilable(T::Boolean))

Check warning on line 238 in Library/Homebrew/dev-cmd/bottle.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/bottle.rb#L238

Added line #L238 was not covered by tests
end

@put_filenames ||= []
@put_filenames ||= T.let([], T.nilable(T::Array[T.any(String, Pathname)]))

Check warning on line 241 in Library/Homebrew/dev-cmd/bottle.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/bottle.rb#L241

Added line #L241 was not covered by tests

return false if @put_filenames.include?(filename)

Expand Down Expand Up @@ -265,6 +280,7 @@
keg_contain_absolute_symlink_starting_with?(string, keg) || result
end

sig { params(string: String, keg: Keg).returns(T::Boolean) }
def keg_contain_absolute_symlink_starting_with?(string, keg)
absolute_symlinks_start_with_string = []
keg.find do |pn|
Expand All @@ -283,6 +299,7 @@
!absolute_symlinks_start_with_string.empty?
end

sig { params(cellar: T.nilable(T.any(String, Symbol))).returns(T::Boolean) }
def cellar_parameter_needed?(cellar)
default_cellars = [
Homebrew::DEFAULT_MACOS_CELLAR,
Expand All @@ -292,6 +309,7 @@
cellar.present? && default_cellars.exclude?(cellar)
end

sig { returns(T.nilable(T::Boolean)) }
def sudo_purge
return unless ENV["HOMEBREW_BOTTLE_SUDO_PURGE"]

Expand Down Expand Up @@ -354,6 +372,7 @@
[gnu_tar(gnu_tar_formula), reproducible_gnutar_args(mtime)].freeze
end

sig { params(formula: T.untyped).returns(T::Array[T.untyped]) }
def formula_ignores(formula)
ignores = []
cellar_regex = Regexp.escape(HOMEBREW_CELLAR)
Expand Down Expand Up @@ -384,6 +403,7 @@
ignores.compact
end

sig { params(formula: Formula).void }
def bottle_formula(formula)
local_bottle_json = args.json? && formula.local_bottle_path.present?

Expand Down Expand Up @@ -453,6 +473,8 @@

if local_bottle_json
bottle_path = formula.local_bottle_path
return if bottle_path.blank?

local_filename = bottle_path.basename.to_s

tab_path = Utils::Bottles.receipt_path(bottle_path)
Expand All @@ -471,6 +493,7 @@
else
tar_filename = filename.to_s.sub(/.gz$/, "")
tar_path = Pathname.pwd/tar_filename
return if tar_path.blank?

keg = Keg.new(formula.prefix)
end
Expand Down Expand Up @@ -681,6 +704,7 @@
json_path.write(JSON.pretty_generate(json))
end

sig { returns(T::Hash[String, T.untyped]) }
def merge
bottles_hash = merge_json_files(parse_json_files(args.named))

Expand Down Expand Up @@ -750,7 +774,7 @@
end
end

all_bottle_hash = T.let(nil, T.nilable(Hash))
all_bottle_hash = T.let(nil, T.nilable(T::Hash[String, T.untyped]))
bottle_hash["bottle"]["tags"].each do |tag, tag_hash|
filename = ::Bottle::Filename.new(
formula_name,
Expand Down Expand Up @@ -801,7 +825,7 @@
checksums = old_checksums(formula, formula_ast, bottle_hash)
update_or_add = checksums.nil? ? "add" : "update"

checksums&.each(&bottle.method(:sha256))
checksums&.each { |checksum| bottle.sha256(checksum) }
output = bottle_output(bottle, args.root_url_using)
puts output

Expand Down Expand Up @@ -835,8 +859,12 @@
end
end

sig {
params(formula: Formula, formula_ast: Utils::AST::FormulaAST,
bottle_hash: T::Hash[String, T.untyped]).returns(T.nilable(T::Array[String]))
}
def old_checksums(formula, formula_ast, bottle_hash)
bottle_node = formula_ast.bottle_block
bottle_node = T.cast(formula_ast.bottle_block, T.nilable(RuboCop::AST::BlockNode))
return if bottle_node.nil?
return [] unless args.keep_old?

Expand Down
Loading