From bd9c7777e8c8e841a879ed13e21d59444181d0c1 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Thu, 4 Jul 2024 23:46:17 +0100 Subject: [PATCH 01/10] utils/shebang: Convert to Sorbet `typed: strict` --- Library/Homebrew/utils/shebang.rb | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/utils/shebang.rb b/Library/Homebrew/utils/shebang.rb index 3a5d784b1f..93df6425b1 100644 --- a/Library/Homebrew/utils/shebang.rb +++ b/Library/Homebrew/utils/shebang.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module Utils @@ -8,13 +8,20 @@ module Utils # Specification on how to rewrite a given shebang. class RewriteInfo - attr_reader :regex, :max_length, :replacement + sig { returns(Regexp) } + attr_reader :regex + + sig { returns(Integer) } + attr_reader :max_length + + sig { returns(T.any(String, Pathname)) } + attr_reader :replacement sig { params(regex: Regexp, max_length: Integer, replacement: T.any(String, Pathname)).void } def initialize(regex, max_length, replacement) - @regex = regex - @max_length = max_length - @replacement = replacement + @regex = T.let(regex, Regexp) + @max_length = T.let(max_length, Integer) + @replacement = T.let(replacement, T.any(String, Pathname)) end end From fdd7fdd2f64579e3c0b7a3d9280dee2a58eed4e2 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Thu, 4 Jul 2024 23:59:32 +0100 Subject: [PATCH 02/10] formula_assertions: Convert to Sorbet `typed: strict` --- Library/Homebrew/formula_assertions.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/formula_assertions.rb b/Library/Homebrew/formula_assertions.rb index a7d6d0dd77..db3320b62a 100644 --- a/Library/Homebrew/formula_assertions.rb +++ b/Library/Homebrew/formula_assertions.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module Homebrew @@ -10,15 +10,18 @@ module Homebrew require "minitest/assertions" include ::Minitest::Assertions + sig { params(assertions: Integer).returns(Integer) } attr_writer :assertions + sig { returns(Integer) } def assertions - @assertions ||= 0 + @assertions ||= T.let(0, T.nilable(Integer)) end # Returns the output of running cmd and asserts the exit status. # # @api public + sig { params(cmd: String, result: Integer).returns(String) } def shell_output(cmd, result = 0) ohai cmd output = `#{cmd}` @@ -33,6 +36,7 @@ module Homebrew # optionally asserts the exit status. # # @api public + sig { params(cmd: String, input: T.nilable(String), result: T.nilable(Integer)).returns(String) } def pipe_output(cmd, input = nil, result = nil) ohai cmd output = IO.popen(cmd, "w+") do |pipe| From ed4b6d4246a06bdb2062da9d34c2425df2a81282 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Fri, 5 Jul 2024 16:37:34 +0100 Subject: [PATCH 03/10] development_tools: Convert to Sorbet `typed: strict` --- Library/Homebrew/development_tools.rb | 52 +++++++++++++-------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/Library/Homebrew/development_tools.rb b/Library/Homebrew/development_tools.rb index 9d900f5a0f..a0f0fd5c6d 100644 --- a/Library/Homebrew/development_tools.rb +++ b/Library/Homebrew/development_tools.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "version" @@ -16,7 +16,7 @@ class DevelopmentTools # Don't call tools (cc, make, strip, etc.) directly! # Give the name of the binary you look for as a string to this method # in order to get the full path back as a Pathname. - (@locate ||= {}).fetch(tool) do |key| + (@locate ||= T.let({}, T.nilable(T::Hash[T.untyped, T.untyped]))).fetch(tool) do |key| @locate[key] = if File.executable?((path = "/usr/bin/#{tool}")) Pathname.new path # Homebrew GCCs most frequently; much faster to check this before xcrun @@ -62,12 +62,13 @@ class DevelopmentTools # @api public sig { returns(Version) } def clang_version - @clang_version ||= if (path = locate("clang")) && - (build_version = `#{path} --version`[/(?:clang|LLVM) version (\d+\.\d(?:\.\d)?)/, 1]) - Version.new build_version - else - Version::NULL - end + @clang_version ||= T.let( + if (path = locate("clang")) && (bv = `#{path} --version`[/(?:clang|LLVM) version (\d+\.\d(?:\.\d)?)/, 1]) + Version.new(bv) + else + Version::NULL + end, T.nilable(Version) + ) end # Get the Clang build version. @@ -75,13 +76,14 @@ class DevelopmentTools # @api public sig { returns(Version) } def clang_build_version - @clang_build_version ||= if (path = locate("clang")) && - (build_version = `#{path} --version`[ -%r{clang(-| version [^ ]+ \(tags/RELEASE_)(\d{2,})}, 2]) - Version.new build_version - else - Version::NULL - end + @clang_build_version ||= T.let( + if (path = locate("clang")) && + (build_version = `#{path} --version`[%r{clang(-| version [^ ]+ \(tags/RELEASE_)(\d{2,})}, 2]) + Version.new(build_version) + else + Version::NULL + end, T.nilable(Version) + ) end # Get the LLVM Clang build version. @@ -89,15 +91,14 @@ class DevelopmentTools # @api public sig { returns(Version) } def llvm_clang_build_version - @llvm_clang_build_version ||= begin + @llvm_clang_build_version ||= T.let(begin path = Formulary.factory("llvm").opt_prefix/"bin/clang" - if path.executable? && - (build_version = `#{path} --version`[/clang version (\d+\.\d\.\d)/, 1]) - Version.new build_version + if path.executable? && (bv = `#{path} --version`[/clang version (\d+\.\d\.\d)/, 1]) + Version.new(bv) else Version::NULL end - end + end, T.nilable(Version)) end # Get the GCC version. @@ -105,12 +106,11 @@ class DevelopmentTools # @api internal sig { params(cc: String).returns(Version) } def gcc_version(cc) - (@gcc_version ||= {}).fetch(cc) do + (@gcc_version ||= T.let({}, T.nilable(T::Hash[String, Version]))).fetch(cc) do path = HOMEBREW_PREFIX/"opt/#{CompilerSelector.preferred_gcc}/bin"/cc path = locate(cc) unless path.exist? - version = if path && - (build_version = `#{path} --version`[/gcc(?:(?:-\d+(?:\.\d)?)? \(.+\))? (\d+\.\d\.\d)/, 1]) - Version.new build_version + version = if path && (bv = `#{path} --version`[/gcc(?:(?:-\d+(?:\.\d)?)? \(.+\))? (\d+\.\d\.\d)/, 1]) + Version.new(bv) else Version::NULL end @@ -120,8 +120,8 @@ class DevelopmentTools sig { void } def clear_version_cache - @clang_version = @clang_build_version = nil - @gcc_version = {} + @clang_version = @clang_build_version = T.let(nil, T.nilable(Version)) + @gcc_version = T.let({}, T.nilable(T::Hash[String, Version])) end sig { returns(T::Boolean) } From cd1869437d5790fc971926eae5f12d5cb4e86153 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Fri, 5 Jul 2024 17:49:32 +0100 Subject: [PATCH 04/10] unpack_strategy: Convert to Sorbet `typed: strict` --- Library/Homebrew/unpack_strategy.rb | 84 ++++++++++++++++++++++++----- 1 file changed, 70 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index 74e49473cb..44f47999d4 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "system_command" @@ -7,10 +7,47 @@ require "system_command" module UnpackStrategy extend T::Helpers + AnyStrategy = T.type_alias do # rubocop:disable Style/MutableConstant + T.any( + T.class_of(UnpackStrategy::Tar), + T.class_of(UnpackStrategy::Pax), + T.class_of(UnpackStrategy::Gzip), + T.class_of(UnpackStrategy::Dmg), + T.class_of(UnpackStrategy::Lzma), + T.class_of(UnpackStrategy::Xz), + T.class_of(UnpackStrategy::Zstd), + T.class_of(UnpackStrategy::Lzip), + T.class_of(UnpackStrategy::Air), + T.class_of(UnpackStrategy::Jar), + T.class_of(UnpackStrategy::LuaRock), + T.class_of(UnpackStrategy::MicrosoftOfficeXml), + T.class_of(UnpackStrategy::Zip), + T.class_of(UnpackStrategy::Pkg), + T.class_of(UnpackStrategy::Xar), + T.class_of(UnpackStrategy::Ttf), + T.class_of(UnpackStrategy::Otf), + T.class_of(UnpackStrategy::Git), + T.class_of(UnpackStrategy::Mercurial), + T.class_of(UnpackStrategy::Subversion), + T.class_of(UnpackStrategy::Cvs), + T.class_of(UnpackStrategy::SelfExtractingExecutable), + T.class_of(UnpackStrategy::Cab), + T.class_of(UnpackStrategy::Executable), + T.class_of(UnpackStrategy::Bzip2), + T.class_of(UnpackStrategy::Fossil), + T.class_of(UnpackStrategy::Bazaar), + T.class_of(UnpackStrategy::P7Zip), + T.class_of(UnpackStrategy::Sit), + T.class_of(UnpackStrategy::Rar), + T.class_of(UnpackStrategy::Lha), + ) + end + include SystemCommand::Mixin + sig { returns(T.nilable(T::Array[AnyStrategy])) } def self.strategies - @strategies ||= [ + @strategies ||= T.let([ Tar, # Needs to be before Bzip2/Gzip/Xz/Lzma/Zstd. Pax, Gzip, @@ -43,10 +80,11 @@ module UnpackStrategy Sit, Rar, Lha, - ].freeze + ].freeze, T.nilable(T::Array[AnyStrategy])) end private_class_method :strategies + sig { params(type: Symbol).returns(T.nilable(T.any(T.class_of(UnpackStrategy::Uncompressed), AnyStrategy))) } def self.from_type(type) type = { naked: :uncompressed, @@ -61,23 +99,29 @@ module UnpackStrategy end end + sig { params(extension: String).returns(T.nilable(AnyStrategy)) } def self.from_extension(extension) - strategies.sort_by { |s| s.extensions.map(&:length).max || 0 } - .reverse - .find { |s| s.extensions.any? { |ext| extension.end_with?(ext) } } + strategies&.sort_by { |s| s.extensions.map(&:length).max || 0 } + &.reverse + &.find { |s| s.extensions.any? { |ext| extension.end_with?(ext) } } end + sig { params(path: Pathname).returns(T.nilable(AnyStrategy)) } def self.from_magic(path) - strategies.find { |s| s.can_extract?(path) } + strategies&.find { |s| s.can_extract?(path) } end + sig { + params(path: Pathname, prioritize_extension: T::Boolean, type: T.nilable(Symbol), ref_type: T.nilable(String), + ref: T.nilable(String), merge_xattrs: T.nilable(T::Boolean)).returns(T.untyped) + } def self.detect(path, prioritize_extension: false, type: nil, ref_type: nil, ref: nil, merge_xattrs: nil) strategy = from_type(type) if type if prioritize_extension && path.extname.present? strategy ||= from_extension(path.extname) - strategy ||= strategies.select { |s| s < Directory || s == Fossil } - .find { |s| s.can_extract?(path) } + strategy ||= strategies&.select { |s| s < Directory || s == Fossil } + &.find { |s| s.can_extract?(path) } else strategy ||= from_magic(path) strategy ||= from_extension(path.extname) @@ -88,24 +132,32 @@ module UnpackStrategy strategy.new(path, ref_type:, ref:, merge_xattrs:) end - attr_reader :path, :merge_xattrs + sig { returns(Pathname) } + attr_reader :path + sig { returns(T.nilable(T::Boolean)) } + attr_reader :merge_xattrs + + sig { + params(path: T.any(String, Pathname), ref_type: T.nilable(String), ref: T.nilable(String), + merge_xattrs: T.nilable(T::Boolean)).void + } def initialize(path, ref_type: nil, ref: nil, merge_xattrs: nil) - @path = Pathname(path).expand_path + @path = T.let(Pathname(path).expand_path, Pathname) @ref_type = ref_type @ref = ref @merge_xattrs = merge_xattrs end abstract! - sig { abstract.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { abstract.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:); end private :extract_to_dir sig { params( to: T.nilable(Pathname), basename: T.nilable(T.any(String, Pathname)), verbose: T::Boolean, - ).returns(T.untyped) + ).void } def extract(to: nil, basename: nil, verbose: false) basename ||= path.basename @@ -131,7 +183,10 @@ module UnpackStrategy children = tmp_unpack_dir.children if children.size == 1 && !children.fetch(0).directory? - s = UnpackStrategy.detect(children.first, prioritize_extension:) + first_child = children.first + next if first_child.nil? + + s = UnpackStrategy.detect(first_child, prioritize_extension:) s.extract_nestedly(to:, verbose:, prioritize_extension:) @@ -149,6 +204,7 @@ module UnpackStrategy end end + sig { returns(T::Array[String]) } def dependencies [] end From 0a18f77de46431b84be7f9b4d40eedbc1209e272 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Fri, 5 Jul 2024 21:14:03 +0100 Subject: [PATCH 05/10] Apply suggestions from code review --- Library/Homebrew/development_tools.rb | 16 +++++++++------- Library/Homebrew/unpack_strategy.rb | 17 ++++++++++------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/development_tools.rb b/Library/Homebrew/development_tools.rb index a0f0fd5c6d..5a379a04f1 100644 --- a/Library/Homebrew/development_tools.rb +++ b/Library/Homebrew/development_tools.rb @@ -16,7 +16,7 @@ class DevelopmentTools # Don't call tools (cc, make, strip, etc.) directly! # Give the name of the binary you look for as a string to this method # in order to get the full path back as a Pathname. - (@locate ||= T.let({}, T.nilable(T::Hash[T.untyped, T.untyped]))).fetch(tool) do |key| + (@locate ||= T.let({}, T.nilable(T::Hash[T.any(String, Symbol), T.untyped]))).fetch(tool) do |key| @locate[key] = if File.executable?((path = "/usr/bin/#{tool}")) Pathname.new path # Homebrew GCCs most frequently; much faster to check this before xcrun @@ -63,8 +63,9 @@ class DevelopmentTools sig { returns(Version) } def clang_version @clang_version ||= T.let( - if (path = locate("clang")) && (bv = `#{path} --version`[/(?:clang|LLVM) version (\d+\.\d(?:\.\d)?)/, 1]) - Version.new(bv) + if (path = locate("clang")) && + (build_version = `#{path} --version`[/(?:clang|LLVM) version (\d+\.\d(?:\.\d)?)/, 1]) + Version.new(build_version) else Version::NULL end, T.nilable(Version) @@ -93,8 +94,8 @@ class DevelopmentTools def llvm_clang_build_version @llvm_clang_build_version ||= T.let(begin path = Formulary.factory("llvm").opt_prefix/"bin/clang" - if path.executable? && (bv = `#{path} --version`[/clang version (\d+\.\d\.\d)/, 1]) - Version.new(bv) + if path.executable? && (build_version = `#{path} --version`[/clang version (\d+\.\d\.\d)/, 1]) + Version.new(build_version) else Version::NULL end @@ -109,8 +110,9 @@ class DevelopmentTools (@gcc_version ||= T.let({}, T.nilable(T::Hash[String, Version]))).fetch(cc) do path = HOMEBREW_PREFIX/"opt/#{CompilerSelector.preferred_gcc}/bin"/cc path = locate(cc) unless path.exist? - version = if path && (bv = `#{path} --version`[/gcc(?:(?:-\d+(?:\.\d)?)? \(.+\))? (\d+\.\d\.\d)/, 1]) - Version.new(bv) + version = if path && + (build_version = `#{path} --version`[/gcc(?:(?:-\d+(?:\.\d)?)? \(.+\))? (\d+\.\d\.\d)/, 1]) + Version.new(build_version) else Version::NULL end diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index 44f47999d4..a56e76ca58 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -7,6 +7,7 @@ require "system_command" module UnpackStrategy extend T::Helpers + # FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed. AnyStrategy = T.type_alias do # rubocop:disable Style/MutableConstant T.any( T.class_of(UnpackStrategy::Tar), @@ -101,6 +102,8 @@ module UnpackStrategy sig { params(extension: String).returns(T.nilable(AnyStrategy)) } def self.from_extension(extension) + return unless strategies + strategies&.sort_by { |s| s.extensions.map(&:length).max || 0 } &.reverse &.find { |s| s.extensions.any? { |ext| extension.end_with?(ext) } } @@ -113,15 +116,15 @@ module UnpackStrategy sig { params(path: Pathname, prioritize_extension: T::Boolean, type: T.nilable(Symbol), ref_type: T.nilable(String), - ref: T.nilable(String), merge_xattrs: T.nilable(T::Boolean)).returns(T.untyped) + ref: T.nilable(String), merge_xattrs: T::Boolean).returns(T.untyped) } - def self.detect(path, prioritize_extension: false, type: nil, ref_type: nil, ref: nil, merge_xattrs: nil) + def self.detect(path, prioritize_extension: false, type: nil, ref_type: nil, ref: nil, merge_xattrs: false) strategy = from_type(type) if type if prioritize_extension && path.extname.present? strategy ||= from_extension(path.extname) - strategy ||= strategies&.select { |s| s < Directory || s == Fossil } - &.find { |s| s.can_extract?(path) } + + strategy ||= strategies&.find { |s| (s < Directory || s == Fossil) && s.can_extract?(path) } else strategy ||= from_magic(path) strategy ||= from_extension(path.extname) @@ -135,14 +138,14 @@ module UnpackStrategy sig { returns(Pathname) } attr_reader :path - sig { returns(T.nilable(T::Boolean)) } + sig { returns(T::Boolean) } attr_reader :merge_xattrs sig { params(path: T.any(String, Pathname), ref_type: T.nilable(String), ref: T.nilable(String), - merge_xattrs: T.nilable(T::Boolean)).void + merge_xattrs: T::Boolean).void } - def initialize(path, ref_type: nil, ref: nil, merge_xattrs: nil) + def initialize(path, ref_type: nil, ref: nil, merge_xattrs: false) @path = T.let(Pathname(path).expand_path, Pathname) @ref_type = ref_type @ref = ref From 4ebf1116d72deafad63c85cd94c55293f036e253 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Fri, 5 Jul 2024 22:29:41 -0700 Subject: [PATCH 06/10] Introduce UnpackStrategyImpl --- Library/Homebrew/unpack_strategy.rb | 63 +++++++------------ Library/Homebrew/unpack_strategy/air.rb | 2 +- Library/Homebrew/unpack_strategy/bzip2.rb | 2 +- Library/Homebrew/unpack_strategy/cab.rb | 2 +- Library/Homebrew/unpack_strategy/compress.rb | 2 +- Library/Homebrew/unpack_strategy/directory.rb | 2 +- Library/Homebrew/unpack_strategy/dmg.rb | 8 ++- .../Homebrew/unpack_strategy/executable.rb | 2 +- Library/Homebrew/unpack_strategy/fossil.rb | 2 +- .../Homebrew/unpack_strategy/generic_unar.rb | 2 +- Library/Homebrew/unpack_strategy/gzip.rb | 2 +- Library/Homebrew/unpack_strategy/jar.rb | 2 +- Library/Homebrew/unpack_strategy/lha.rb | 2 +- Library/Homebrew/unpack_strategy/lua_rock.rb | 2 +- Library/Homebrew/unpack_strategy/lzip.rb | 2 +- Library/Homebrew/unpack_strategy/lzma.rb | 2 +- .../unpack_strategy/microsoft_office_xml.rb | 2 +- Library/Homebrew/unpack_strategy/otf.rb | 2 +- Library/Homebrew/unpack_strategy/p7zip.rb | 2 +- Library/Homebrew/unpack_strategy/pax.rb | 2 +- Library/Homebrew/unpack_strategy/pkg.rb | 2 +- Library/Homebrew/unpack_strategy/rar.rb | 2 +- .../self_extracting_executable.rb | 2 +- Library/Homebrew/unpack_strategy/sit.rb | 2 +- Library/Homebrew/unpack_strategy/tar.rb | 2 +- Library/Homebrew/unpack_strategy/ttf.rb | 2 +- .../Homebrew/unpack_strategy/uncompressed.rb | 6 ++ Library/Homebrew/unpack_strategy/xar.rb | 2 +- Library/Homebrew/unpack_strategy/xz.rb | 2 +- Library/Homebrew/unpack_strategy/zip.rb | 4 +- Library/Homebrew/unpack_strategy/zstd.rb | 2 +- 31 files changed, 63 insertions(+), 72 deletions(-) diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index a56e76ca58..843a257e2e 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -6,47 +6,27 @@ require "system_command" # Module containing all available strategies for unpacking archives. module UnpackStrategy extend T::Helpers + include SystemCommand::Mixin + abstract! - # FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed. - AnyStrategy = T.type_alias do # rubocop:disable Style/MutableConstant - T.any( - T.class_of(UnpackStrategy::Tar), - T.class_of(UnpackStrategy::Pax), - T.class_of(UnpackStrategy::Gzip), - T.class_of(UnpackStrategy::Dmg), - T.class_of(UnpackStrategy::Lzma), - T.class_of(UnpackStrategy::Xz), - T.class_of(UnpackStrategy::Zstd), - T.class_of(UnpackStrategy::Lzip), - T.class_of(UnpackStrategy::Air), - T.class_of(UnpackStrategy::Jar), - T.class_of(UnpackStrategy::LuaRock), - T.class_of(UnpackStrategy::MicrosoftOfficeXml), - T.class_of(UnpackStrategy::Zip), - T.class_of(UnpackStrategy::Pkg), - T.class_of(UnpackStrategy::Xar), - T.class_of(UnpackStrategy::Ttf), - T.class_of(UnpackStrategy::Otf), - T.class_of(UnpackStrategy::Git), - T.class_of(UnpackStrategy::Mercurial), - T.class_of(UnpackStrategy::Subversion), - T.class_of(UnpackStrategy::Cvs), - T.class_of(UnpackStrategy::SelfExtractingExecutable), - T.class_of(UnpackStrategy::Cab), - T.class_of(UnpackStrategy::Executable), - T.class_of(UnpackStrategy::Bzip2), - T.class_of(UnpackStrategy::Fossil), - T.class_of(UnpackStrategy::Bazaar), - T.class_of(UnpackStrategy::P7Zip), - T.class_of(UnpackStrategy::Sit), - T.class_of(UnpackStrategy::Rar), - T.class_of(UnpackStrategy::Lha), - ) + # rubocop:disable Style/MutableConstant + UnpackStrategyImpl = T.type_alias { T.all(T::Class[UnpackStrategy], UnpackStrategy::ClassMethods) } + # rubocop:enable Style/MutableConstant + + module ClassMethods + extend T::Helpers + abstract! + + sig { abstract.returns(T::Array[String]) } + def extensions; end + + sig { abstract.params(path: Pathname).returns(T::Boolean) } + def can_extract?(path); end end - include SystemCommand::Mixin + mixes_in_class_methods(ClassMethods) - sig { returns(T.nilable(T::Array[AnyStrategy])) } + sig { returns(T.nilable(T::Array[UnpackStrategyImpl])) } def self.strategies @strategies ||= T.let([ Tar, # Needs to be before Bzip2/Gzip/Xz/Lzma/Zstd. @@ -81,11 +61,11 @@ module UnpackStrategy Sit, Rar, Lha, - ].freeze, T.nilable(T::Array[AnyStrategy])) + ].freeze, T.nilable(T::Array[UnpackStrategyImpl])) end private_class_method :strategies - sig { params(type: Symbol).returns(T.nilable(T.any(T.class_of(UnpackStrategy::Uncompressed), AnyStrategy))) } + sig { params(type: Symbol).returns(T.nilable(UnpackStrategyImpl)) } def self.from_type(type) type = { naked: :uncompressed, @@ -100,7 +80,7 @@ module UnpackStrategy end end - sig { params(extension: String).returns(T.nilable(AnyStrategy)) } + sig { params(extension: String).returns(T.nilable(UnpackStrategyImpl)) } def self.from_extension(extension) return unless strategies @@ -109,7 +89,7 @@ module UnpackStrategy &.find { |s| s.extensions.any? { |ext| extension.end_with?(ext) } } end - sig { params(path: Pathname).returns(T.nilable(AnyStrategy)) } + sig { params(path: Pathname).returns(T.nilable(UnpackStrategyImpl)) } def self.from_magic(path) strategies&.find { |s| s.can_extract?(path) } end @@ -152,7 +132,6 @@ module UnpackStrategy @merge_xattrs = merge_xattrs end - abstract! sig { abstract.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:); end private :extract_to_dir diff --git a/Library/Homebrew/unpack_strategy/air.rb b/Library/Homebrew/unpack_strategy/air.rb index c4a6ba601a..26a3c37a1a 100644 --- a/Library/Homebrew/unpack_strategy/air.rb +++ b/Library/Homebrew/unpack_strategy/air.rb @@ -6,7 +6,7 @@ module UnpackStrategy class Air include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".air"] end diff --git a/Library/Homebrew/unpack_strategy/bzip2.rb b/Library/Homebrew/unpack_strategy/bzip2.rb index af1248c466..8eca20c997 100644 --- a/Library/Homebrew/unpack_strategy/bzip2.rb +++ b/Library/Homebrew/unpack_strategy/bzip2.rb @@ -6,7 +6,7 @@ module UnpackStrategy class Bzip2 include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".bz2"] end diff --git a/Library/Homebrew/unpack_strategy/cab.rb b/Library/Homebrew/unpack_strategy/cab.rb index af73d82fdd..26036963a0 100644 --- a/Library/Homebrew/unpack_strategy/cab.rb +++ b/Library/Homebrew/unpack_strategy/cab.rb @@ -6,7 +6,7 @@ module UnpackStrategy class Cab include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".cab"] end diff --git a/Library/Homebrew/unpack_strategy/compress.rb b/Library/Homebrew/unpack_strategy/compress.rb index 0082312214..e2d6ce37f8 100644 --- a/Library/Homebrew/unpack_strategy/compress.rb +++ b/Library/Homebrew/unpack_strategy/compress.rb @@ -6,7 +6,7 @@ require_relative "tar" module UnpackStrategy # Strategy for unpacking compress archives. class Compress < Tar - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".Z"] end diff --git a/Library/Homebrew/unpack_strategy/directory.rb b/Library/Homebrew/unpack_strategy/directory.rb index 90b5ade18e..4df5b09140 100644 --- a/Library/Homebrew/unpack_strategy/directory.rb +++ b/Library/Homebrew/unpack_strategy/directory.rb @@ -6,7 +6,7 @@ module UnpackStrategy class Directory include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [] end diff --git a/Library/Homebrew/unpack_strategy/dmg.rb b/Library/Homebrew/unpack_strategy/dmg.rb index 92c7f8ca49..52036cf8e3 100644 --- a/Library/Homebrew/unpack_strategy/dmg.rb +++ b/Library/Homebrew/unpack_strategy/dmg.rb @@ -121,6 +121,12 @@ module UnpackStrategy end end + sig { override.returns(T::Array[String]) } + def self.extensions = [] + + sig { override.params(_path: Pathname).returns(T::Boolean) } + def self.can_extract?(_path) = false + private sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } @@ -165,7 +171,7 @@ module UnpackStrategy end private_constant :Mount - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".dmg"] end diff --git a/Library/Homebrew/unpack_strategy/executable.rb b/Library/Homebrew/unpack_strategy/executable.rb index 4c5e712da8..86c381ef13 100644 --- a/Library/Homebrew/unpack_strategy/executable.rb +++ b/Library/Homebrew/unpack_strategy/executable.rb @@ -6,7 +6,7 @@ require_relative "uncompressed" module UnpackStrategy # Strategy for unpacking executables. class Executable < Uncompressed - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".sh", ".bash"] end diff --git a/Library/Homebrew/unpack_strategy/fossil.rb b/Library/Homebrew/unpack_strategy/fossil.rb index 1e2dcc00a8..9cf9baf378 100644 --- a/Library/Homebrew/unpack_strategy/fossil.rb +++ b/Library/Homebrew/unpack_strategy/fossil.rb @@ -9,7 +9,7 @@ module UnpackStrategy include UnpackStrategy extend SystemCommand::Mixin - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [] end diff --git a/Library/Homebrew/unpack_strategy/generic_unar.rb b/Library/Homebrew/unpack_strategy/generic_unar.rb index 0aee0ce3ac..eb8f50e2b0 100644 --- a/Library/Homebrew/unpack_strategy/generic_unar.rb +++ b/Library/Homebrew/unpack_strategy/generic_unar.rb @@ -6,7 +6,7 @@ module UnpackStrategy class GenericUnar include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [] end diff --git a/Library/Homebrew/unpack_strategy/gzip.rb b/Library/Homebrew/unpack_strategy/gzip.rb index 2ece0befdc..23801d70ef 100644 --- a/Library/Homebrew/unpack_strategy/gzip.rb +++ b/Library/Homebrew/unpack_strategy/gzip.rb @@ -6,7 +6,7 @@ module UnpackStrategy class Gzip include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".gz"] end diff --git a/Library/Homebrew/unpack_strategy/jar.rb b/Library/Homebrew/unpack_strategy/jar.rb index 892357b48b..8082d8602c 100644 --- a/Library/Homebrew/unpack_strategy/jar.rb +++ b/Library/Homebrew/unpack_strategy/jar.rb @@ -6,7 +6,7 @@ require_relative "uncompressed" module UnpackStrategy # Strategy for unpacking Java archives. class Jar < Uncompressed - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".apk", ".jar"] end diff --git a/Library/Homebrew/unpack_strategy/lha.rb b/Library/Homebrew/unpack_strategy/lha.rb index 1da3021ad7..c161dff98e 100644 --- a/Library/Homebrew/unpack_strategy/lha.rb +++ b/Library/Homebrew/unpack_strategy/lha.rb @@ -6,7 +6,7 @@ module UnpackStrategy class Lha include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".lha", ".lzh"] end diff --git a/Library/Homebrew/unpack_strategy/lua_rock.rb b/Library/Homebrew/unpack_strategy/lua_rock.rb index a01fcd2f88..b054b9f810 100644 --- a/Library/Homebrew/unpack_strategy/lua_rock.rb +++ b/Library/Homebrew/unpack_strategy/lua_rock.rb @@ -6,7 +6,7 @@ require_relative "uncompressed" module UnpackStrategy # Strategy for unpacking LuaRock archives. class LuaRock < Uncompressed - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".rock"] end diff --git a/Library/Homebrew/unpack_strategy/lzip.rb b/Library/Homebrew/unpack_strategy/lzip.rb index 668aa4fdcf..87fe289fb8 100644 --- a/Library/Homebrew/unpack_strategy/lzip.rb +++ b/Library/Homebrew/unpack_strategy/lzip.rb @@ -6,7 +6,7 @@ module UnpackStrategy class Lzip include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".lz"] end diff --git a/Library/Homebrew/unpack_strategy/lzma.rb b/Library/Homebrew/unpack_strategy/lzma.rb index d529e2de4c..f6de6e0b24 100644 --- a/Library/Homebrew/unpack_strategy/lzma.rb +++ b/Library/Homebrew/unpack_strategy/lzma.rb @@ -6,7 +6,7 @@ module UnpackStrategy class Lzma include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".lzma"] end diff --git a/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb b/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb index 2ad2a40644..dfc4c084f4 100644 --- a/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb +++ b/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb @@ -6,7 +6,7 @@ require_relative "uncompressed" module UnpackStrategy # Strategy for unpacking Microsoft Office documents. class MicrosoftOfficeXml < Uncompressed - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [ ".doc", ".docx", diff --git a/Library/Homebrew/unpack_strategy/otf.rb b/Library/Homebrew/unpack_strategy/otf.rb index 7a75f78c4c..b4839b2a61 100644 --- a/Library/Homebrew/unpack_strategy/otf.rb +++ b/Library/Homebrew/unpack_strategy/otf.rb @@ -6,7 +6,7 @@ require_relative "uncompressed" module UnpackStrategy # Strategy for unpacking OpenType fonts. class Otf < Uncompressed - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".otf"] end diff --git a/Library/Homebrew/unpack_strategy/p7zip.rb b/Library/Homebrew/unpack_strategy/p7zip.rb index 19e0154491..063062d02f 100644 --- a/Library/Homebrew/unpack_strategy/p7zip.rb +++ b/Library/Homebrew/unpack_strategy/p7zip.rb @@ -6,7 +6,7 @@ module UnpackStrategy class P7Zip include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".7z"] end diff --git a/Library/Homebrew/unpack_strategy/pax.rb b/Library/Homebrew/unpack_strategy/pax.rb index 9a47b9d1d5..6d77f990c1 100644 --- a/Library/Homebrew/unpack_strategy/pax.rb +++ b/Library/Homebrew/unpack_strategy/pax.rb @@ -6,7 +6,7 @@ module UnpackStrategy class Pax include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".pax"] end diff --git a/Library/Homebrew/unpack_strategy/pkg.rb b/Library/Homebrew/unpack_strategy/pkg.rb index b48a55244b..e4b288b827 100644 --- a/Library/Homebrew/unpack_strategy/pkg.rb +++ b/Library/Homebrew/unpack_strategy/pkg.rb @@ -6,7 +6,7 @@ require_relative "uncompressed" module UnpackStrategy # Strategy for unpacking macOS package installers. class Pkg < Uncompressed - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".pkg", ".mkpg"] end diff --git a/Library/Homebrew/unpack_strategy/rar.rb b/Library/Homebrew/unpack_strategy/rar.rb index 289da9134c..041bcc0798 100644 --- a/Library/Homebrew/unpack_strategy/rar.rb +++ b/Library/Homebrew/unpack_strategy/rar.rb @@ -6,7 +6,7 @@ module UnpackStrategy class Rar include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".rar"] end diff --git a/Library/Homebrew/unpack_strategy/self_extracting_executable.rb b/Library/Homebrew/unpack_strategy/self_extracting_executable.rb index b32cfa825c..078ce77365 100644 --- a/Library/Homebrew/unpack_strategy/self_extracting_executable.rb +++ b/Library/Homebrew/unpack_strategy/self_extracting_executable.rb @@ -6,7 +6,7 @@ require_relative "generic_unar" module UnpackStrategy # Strategy for unpacking self-extracting executables. class SelfExtractingExecutable < GenericUnar - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [] end diff --git a/Library/Homebrew/unpack_strategy/sit.rb b/Library/Homebrew/unpack_strategy/sit.rb index 7d447eaf69..631c446297 100644 --- a/Library/Homebrew/unpack_strategy/sit.rb +++ b/Library/Homebrew/unpack_strategy/sit.rb @@ -6,7 +6,7 @@ require_relative "generic_unar" module UnpackStrategy # Strategy for unpacking Stuffit archives. class Sit < GenericUnar - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".sit"] end diff --git a/Library/Homebrew/unpack_strategy/tar.rb b/Library/Homebrew/unpack_strategy/tar.rb index c3300e7155..5541f96891 100644 --- a/Library/Homebrew/unpack_strategy/tar.rb +++ b/Library/Homebrew/unpack_strategy/tar.rb @@ -9,7 +9,7 @@ module UnpackStrategy include UnpackStrategy extend SystemCommand::Mixin - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [ ".tar", diff --git a/Library/Homebrew/unpack_strategy/ttf.rb b/Library/Homebrew/unpack_strategy/ttf.rb index d741378d29..3c73a6801e 100644 --- a/Library/Homebrew/unpack_strategy/ttf.rb +++ b/Library/Homebrew/unpack_strategy/ttf.rb @@ -6,7 +6,7 @@ require_relative "uncompressed" module UnpackStrategy # Strategy for unpacking TrueType fonts. class Ttf < Uncompressed - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".ttc", ".ttf"] end diff --git a/Library/Homebrew/unpack_strategy/uncompressed.rb b/Library/Homebrew/unpack_strategy/uncompressed.rb index 5d2c3dd511..25c26652c9 100644 --- a/Library/Homebrew/unpack_strategy/uncompressed.rb +++ b/Library/Homebrew/unpack_strategy/uncompressed.rb @@ -6,6 +6,12 @@ module UnpackStrategy class Uncompressed include UnpackStrategy + sig { override.returns(T::Array[String]) } + def self.extensions = [] + + sig { override.params(_path: Pathname).returns(T::Boolean) } + def self.can_extract?(_path) = false + sig { params( to: T.nilable(Pathname), diff --git a/Library/Homebrew/unpack_strategy/xar.rb b/Library/Homebrew/unpack_strategy/xar.rb index f473d35c79..fe5de4e4be 100644 --- a/Library/Homebrew/unpack_strategy/xar.rb +++ b/Library/Homebrew/unpack_strategy/xar.rb @@ -6,7 +6,7 @@ module UnpackStrategy class Xar include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".xar"] end diff --git a/Library/Homebrew/unpack_strategy/xz.rb b/Library/Homebrew/unpack_strategy/xz.rb index 7ac0ceb4e6..2360aa5fe1 100644 --- a/Library/Homebrew/unpack_strategy/xz.rb +++ b/Library/Homebrew/unpack_strategy/xz.rb @@ -6,7 +6,7 @@ module UnpackStrategy class Xz include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".xz"] end diff --git a/Library/Homebrew/unpack_strategy/zip.rb b/Library/Homebrew/unpack_strategy/zip.rb index dc4d6d350b..59da683f35 100644 --- a/Library/Homebrew/unpack_strategy/zip.rb +++ b/Library/Homebrew/unpack_strategy/zip.rb @@ -6,12 +6,12 @@ module UnpackStrategy class Zip include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".zip"] end - sig { params(path: Pathname).returns(T::Boolean) } + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\APK(\003\004|\005\006)/n) end diff --git a/Library/Homebrew/unpack_strategy/zstd.rb b/Library/Homebrew/unpack_strategy/zstd.rb index f8cdacb0ab..ee10cd85f4 100644 --- a/Library/Homebrew/unpack_strategy/zstd.rb +++ b/Library/Homebrew/unpack_strategy/zstd.rb @@ -6,7 +6,7 @@ module UnpackStrategy class Zstd include UnpackStrategy - sig { returns(T::Array[String]) } + sig { override.returns(T::Array[String]) } def self.extensions [".zst"] end From 0076a88541517471afc40aba54047de1e70d9b61 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Sat, 6 Jul 2024 08:10:16 -0700 Subject: [PATCH 07/10] Apply suggested changes --- Library/Homebrew/unpack_strategy.rb | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index 843a257e2e..e4190f10f6 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -9,8 +9,9 @@ module UnpackStrategy include SystemCommand::Mixin abstract! + # FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed. # rubocop:disable Style/MutableConstant - UnpackStrategyImpl = T.type_alias { T.all(T::Class[UnpackStrategy], UnpackStrategy::ClassMethods) } + UnpackStrategyType = T.type_alias { T.all(T::Class[UnpackStrategy], UnpackStrategy::ClassMethods) } # rubocop:enable Style/MutableConstant module ClassMethods @@ -26,7 +27,7 @@ module UnpackStrategy mixes_in_class_methods(ClassMethods) - sig { returns(T.nilable(T::Array[UnpackStrategyImpl])) } + sig { returns(T.nilable(T::Array[UnpackStrategyType])) } def self.strategies @strategies ||= T.let([ Tar, # Needs to be before Bzip2/Gzip/Xz/Lzma/Zstd. @@ -61,11 +62,11 @@ module UnpackStrategy Sit, Rar, Lha, - ].freeze, T.nilable(T::Array[UnpackStrategyImpl])) + ].freeze, T.nilable(T::Array[UnpackStrategyType])) end private_class_method :strategies - sig { params(type: Symbol).returns(T.nilable(UnpackStrategyImpl)) } + sig { params(type: Symbol).returns(T.nilable(UnpackStrategyType)) } def self.from_type(type) type = { naked: :uncompressed, @@ -80,7 +81,7 @@ module UnpackStrategy end end - sig { params(extension: String).returns(T.nilable(UnpackStrategyImpl)) } + sig { params(extension: String).returns(T.nilable(UnpackStrategyType)) } def self.from_extension(extension) return unless strategies @@ -89,7 +90,7 @@ module UnpackStrategy &.find { |s| s.extensions.any? { |ext| extension.end_with?(ext) } } end - sig { params(path: Pathname).returns(T.nilable(UnpackStrategyImpl)) } + sig { params(path: Pathname).returns(T.nilable(UnpackStrategyType)) } def self.from_magic(path) strategies&.find { |s| s.can_extract?(path) } end From 9c6430954b252bacf5e2144a4c8ed11c7077dd19 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Thu, 11 Jul 2024 11:05:42 +0100 Subject: [PATCH 08/10] All the `extract_to_dir`s return `void` now --- Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb | 2 +- Library/Homebrew/unpack_strategy/air.rb | 2 +- Library/Homebrew/unpack_strategy/bazaar.rb | 2 +- Library/Homebrew/unpack_strategy/bzip2.rb | 2 +- Library/Homebrew/unpack_strategy/cab.rb | 2 +- Library/Homebrew/unpack_strategy/directory.rb | 2 +- Library/Homebrew/unpack_strategy/dmg.rb | 4 ++-- Library/Homebrew/unpack_strategy/fossil.rb | 2 +- Library/Homebrew/unpack_strategy/generic_unar.rb | 2 +- Library/Homebrew/unpack_strategy/gzip.rb | 2 +- Library/Homebrew/unpack_strategy/lha.rb | 2 +- Library/Homebrew/unpack_strategy/lzip.rb | 2 +- Library/Homebrew/unpack_strategy/lzma.rb | 2 +- Library/Homebrew/unpack_strategy/p7zip.rb | 2 +- Library/Homebrew/unpack_strategy/pax.rb | 2 +- Library/Homebrew/unpack_strategy/rar.rb | 2 +- Library/Homebrew/unpack_strategy/tar.rb | 2 +- Library/Homebrew/unpack_strategy/uncompressed.rb | 2 +- Library/Homebrew/unpack_strategy/xar.rb | 2 +- Library/Homebrew/unpack_strategy/xz.rb | 2 +- Library/Homebrew/unpack_strategy/zstd.rb | 2 +- 21 files changed, 22 insertions(+), 22 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb index da2ec31692..f220474ddd 100644 --- a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb +++ b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb @@ -8,7 +8,7 @@ module UnpackStrategy module MacOSZipExtension private - sig { params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) with_env(TZ: "UTC") do if merge_xattrs && contains_extended_attributes?(path) diff --git a/Library/Homebrew/unpack_strategy/air.rb b/Library/Homebrew/unpack_strategy/air.rb index 26a3c37a1a..1aeaa830da 100644 --- a/Library/Homebrew/unpack_strategy/air.rb +++ b/Library/Homebrew/unpack_strategy/air.rb @@ -27,7 +27,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! AIR_APPLICATION_INSTALLER, args: ["-silent", "-location", unpack_dir, path], diff --git a/Library/Homebrew/unpack_strategy/bazaar.rb b/Library/Homebrew/unpack_strategy/bazaar.rb index f73902b3aa..b952ba206d 100644 --- a/Library/Homebrew/unpack_strategy/bazaar.rb +++ b/Library/Homebrew/unpack_strategy/bazaar.rb @@ -12,7 +12,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) super diff --git a/Library/Homebrew/unpack_strategy/bzip2.rb b/Library/Homebrew/unpack_strategy/bzip2.rb index 8eca20c997..6225b93388 100644 --- a/Library/Homebrew/unpack_strategy/bzip2.rb +++ b/Library/Homebrew/unpack_strategy/bzip2.rb @@ -17,7 +17,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) FileUtils.cp path, unpack_dir/basename, preserve: true quiet_flags = verbose ? [] : ["-q"] diff --git a/Library/Homebrew/unpack_strategy/cab.rb b/Library/Homebrew/unpack_strategy/cab.rb index 26036963a0..388ceb425c 100644 --- a/Library/Homebrew/unpack_strategy/cab.rb +++ b/Library/Homebrew/unpack_strategy/cab.rb @@ -15,7 +15,7 @@ module UnpackStrategy path.magic_number.match?(/\AMSCF/n) end - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "cabextract", args: ["-d", unpack_dir, "--", path], diff --git a/Library/Homebrew/unpack_strategy/directory.rb b/Library/Homebrew/unpack_strategy/directory.rb index 4df5b09140..50127031da 100644 --- a/Library/Homebrew/unpack_strategy/directory.rb +++ b/Library/Homebrew/unpack_strategy/directory.rb @@ -17,7 +17,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) path.children.each do |child| system_command! "cp", diff --git a/Library/Homebrew/unpack_strategy/dmg.rb b/Library/Homebrew/unpack_strategy/dmg.rb index 52036cf8e3..b63bd439f5 100644 --- a/Library/Homebrew/unpack_strategy/dmg.rb +++ b/Library/Homebrew/unpack_strategy/dmg.rb @@ -129,7 +129,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) tries = 3 bom = begin @@ -183,7 +183,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) mount(verbose:) do |mounts| raise "No mounts found in '#{path}'; perhaps this is a bad disk image?" if mounts.empty? diff --git a/Library/Homebrew/unpack_strategy/fossil.rb b/Library/Homebrew/unpack_strategy/fossil.rb index 9cf9baf378..8517d064f2 100644 --- a/Library/Homebrew/unpack_strategy/fossil.rb +++ b/Library/Homebrew/unpack_strategy/fossil.rb @@ -24,7 +24,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) args = if @ref_type && @ref [@ref] diff --git a/Library/Homebrew/unpack_strategy/generic_unar.rb b/Library/Homebrew/unpack_strategy/generic_unar.rb index eb8f50e2b0..1e3075e947 100644 --- a/Library/Homebrew/unpack_strategy/generic_unar.rb +++ b/Library/Homebrew/unpack_strategy/generic_unar.rb @@ -21,7 +21,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "unar", args: [ diff --git a/Library/Homebrew/unpack_strategy/gzip.rb b/Library/Homebrew/unpack_strategy/gzip.rb index 23801d70ef..70ff74c56e 100644 --- a/Library/Homebrew/unpack_strategy/gzip.rb +++ b/Library/Homebrew/unpack_strategy/gzip.rb @@ -17,7 +17,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) FileUtils.cp path, unpack_dir/basename, preserve: true quiet_flags = verbose ? [] : ["-q"] diff --git a/Library/Homebrew/unpack_strategy/lha.rb b/Library/Homebrew/unpack_strategy/lha.rb index c161dff98e..ece0b4b8cc 100644 --- a/Library/Homebrew/unpack_strategy/lha.rb +++ b/Library/Homebrew/unpack_strategy/lha.rb @@ -21,7 +21,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "lha", args: ["xq2w=#{unpack_dir}", path], diff --git a/Library/Homebrew/unpack_strategy/lzip.rb b/Library/Homebrew/unpack_strategy/lzip.rb index 87fe289fb8..90150a40c6 100644 --- a/Library/Homebrew/unpack_strategy/lzip.rb +++ b/Library/Homebrew/unpack_strategy/lzip.rb @@ -21,7 +21,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) FileUtils.cp path, unpack_dir/basename, preserve: true quiet_flags = verbose ? [] : ["-q"] diff --git a/Library/Homebrew/unpack_strategy/lzma.rb b/Library/Homebrew/unpack_strategy/lzma.rb index f6de6e0b24..5b6ed1c4e8 100644 --- a/Library/Homebrew/unpack_strategy/lzma.rb +++ b/Library/Homebrew/unpack_strategy/lzma.rb @@ -21,7 +21,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) FileUtils.cp path, unpack_dir/basename, preserve: true quiet_flags = verbose ? [] : ["-q"] diff --git a/Library/Homebrew/unpack_strategy/p7zip.rb b/Library/Homebrew/unpack_strategy/p7zip.rb index 063062d02f..69e2c9deab 100644 --- a/Library/Homebrew/unpack_strategy/p7zip.rb +++ b/Library/Homebrew/unpack_strategy/p7zip.rb @@ -21,7 +21,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "7zr", args: ["x", "-y", "-bd", "-bso0", path, "-o#{unpack_dir}"], diff --git a/Library/Homebrew/unpack_strategy/pax.rb b/Library/Homebrew/unpack_strategy/pax.rb index 6d77f990c1..bc5f89c15a 100644 --- a/Library/Homebrew/unpack_strategy/pax.rb +++ b/Library/Homebrew/unpack_strategy/pax.rb @@ -17,7 +17,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "pax", args: ["-rf", path], diff --git a/Library/Homebrew/unpack_strategy/rar.rb b/Library/Homebrew/unpack_strategy/rar.rb index 041bcc0798..06394dbdf4 100644 --- a/Library/Homebrew/unpack_strategy/rar.rb +++ b/Library/Homebrew/unpack_strategy/rar.rb @@ -21,7 +21,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "bsdtar", args: ["x", "-f", path, "-C", unpack_dir], diff --git a/Library/Homebrew/unpack_strategy/tar.rb b/Library/Homebrew/unpack_strategy/tar.rb index 5541f96891..adbf59def5 100644 --- a/Library/Homebrew/unpack_strategy/tar.rb +++ b/Library/Homebrew/unpack_strategy/tar.rb @@ -34,7 +34,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) Dir.mktmpdir("homebrew-tar", HOMEBREW_TEMP) do |tmpdir| tar_path = if DependencyCollector.tar_needs_xz_dependency? && Xz.can_extract?(path) diff --git a/Library/Homebrew/unpack_strategy/uncompressed.rb b/Library/Homebrew/unpack_strategy/uncompressed.rb index 25c26652c9..58e70082e9 100644 --- a/Library/Homebrew/unpack_strategy/uncompressed.rb +++ b/Library/Homebrew/unpack_strategy/uncompressed.rb @@ -26,7 +26,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose: false) FileUtils.cp path, unpack_dir/basename.sub(/^[\da-f]{64}--/, ""), preserve: true, verbose: end diff --git a/Library/Homebrew/unpack_strategy/xar.rb b/Library/Homebrew/unpack_strategy/xar.rb index fe5de4e4be..0d571fa5ac 100644 --- a/Library/Homebrew/unpack_strategy/xar.rb +++ b/Library/Homebrew/unpack_strategy/xar.rb @@ -17,7 +17,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "xar", args: ["-x", "-f", path, "-C", unpack_dir], diff --git a/Library/Homebrew/unpack_strategy/xz.rb b/Library/Homebrew/unpack_strategy/xz.rb index 2360aa5fe1..a9ffc96a65 100644 --- a/Library/Homebrew/unpack_strategy/xz.rb +++ b/Library/Homebrew/unpack_strategy/xz.rb @@ -21,7 +21,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) FileUtils.cp path, unpack_dir/basename, preserve: true quiet_flags = verbose ? [] : ["-q"] diff --git a/Library/Homebrew/unpack_strategy/zstd.rb b/Library/Homebrew/unpack_strategy/zstd.rb index ee10cd85f4..3dfa808f34 100644 --- a/Library/Homebrew/unpack_strategy/zstd.rb +++ b/Library/Homebrew/unpack_strategy/zstd.rb @@ -21,7 +21,7 @@ module UnpackStrategy private - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) FileUtils.cp path, unpack_dir/basename, preserve: true quiet_flags = verbose ? [] : ["-q"] From bffb470c57422a6922afaec41cf5c595b9d8495c Mon Sep 17 00:00:00 2001 From: Issy Long Date: Thu, 11 Jul 2024 19:37:46 +0100 Subject: [PATCH 09/10] unpack_strategy: Fix `ref_type` type (Symbol, not String) - I put a debugger call in the test that was failing. - Running the install command at that debug prompt and lo, the typing bug was staring me in the face: ``` Error: An exception occurred within a child process: TypeError: Parameter 'ref_type': Expected type T.nilable(String), got type Symbol with value :branch Caller: /opt/homebrew/Library/Homebrew/vendor/bundle/ruby/3.3.0/gems/sorbet-runtime-0.5.11471/lib/types/private/methods/call_validation.rb:215 Definition: /opt/homebrew/Library/Homebrew/unpack_strategy.rb:102 (UnpackStrategy.detect) ``` --- Library/Homebrew/unpack_strategy.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index e4190f10f6..b3581c8ad7 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -96,7 +96,7 @@ module UnpackStrategy end sig { - params(path: Pathname, prioritize_extension: T::Boolean, type: T.nilable(Symbol), ref_type: T.nilable(String), + params(path: Pathname, prioritize_extension: T::Boolean, type: T.nilable(Symbol), ref_type: T.nilable(Symbol), ref: T.nilable(String), merge_xattrs: T::Boolean).returns(T.untyped) } def self.detect(path, prioritize_extension: false, type: nil, ref_type: nil, ref: nil, merge_xattrs: false) @@ -123,14 +123,14 @@ module UnpackStrategy attr_reader :merge_xattrs sig { - params(path: T.any(String, Pathname), ref_type: T.nilable(String), ref: T.nilable(String), + params(path: T.any(String, Pathname), ref_type: T.nilable(Symbol), ref: T.nilable(String), merge_xattrs: T::Boolean).void } def initialize(path, ref_type: nil, ref: nil, merge_xattrs: false) @path = T.let(Pathname(path).expand_path, Pathname) - @ref_type = ref_type - @ref = ref - @merge_xattrs = merge_xattrs + @ref_type = T.let(ref_type, T.nilable(Symbol)) + @ref = T.let(ref, T.nilable(String)) + @merge_xattrs = T.let(merge_xattrs, T::Boolean) end sig { abstract.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } From edb8055c7615680c549020a7aeff74f25951c003 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Thu, 11 Jul 2024 19:57:12 +0100 Subject: [PATCH 10/10] unpack_strategy/*: Convert to Sorbet `typed: strict` --- Library/Homebrew/unpack_strategy/air.rb | 6 ++++-- Library/Homebrew/unpack_strategy/bazaar.rb | 5 +++-- Library/Homebrew/unpack_strategy/bzip2.rb | 3 ++- Library/Homebrew/unpack_strategy/cab.rb | 6 ++++-- Library/Homebrew/unpack_strategy/compress.rb | 3 ++- Library/Homebrew/unpack_strategy/cvs.rb | 5 +++-- Library/Homebrew/unpack_strategy/directory.rb | 3 ++- Library/Homebrew/unpack_strategy/executable.rb | 3 ++- Library/Homebrew/unpack_strategy/fossil.rb | 3 ++- Library/Homebrew/unpack_strategy/generic_unar.rb | 6 ++++-- Library/Homebrew/unpack_strategy/git.rb | 5 +++-- Library/Homebrew/unpack_strategy/gzip.rb | 3 ++- Library/Homebrew/unpack_strategy/jar.rb | 3 ++- Library/Homebrew/unpack_strategy/lha.rb | 6 ++++-- Library/Homebrew/unpack_strategy/lua_rock.rb | 3 ++- Library/Homebrew/unpack_strategy/lzip.rb | 6 ++++-- Library/Homebrew/unpack_strategy/lzma.rb | 6 ++++-- Library/Homebrew/unpack_strategy/mercurial.rb | 6 ++++-- Library/Homebrew/unpack_strategy/microsoft_office_xml.rb | 3 ++- Library/Homebrew/unpack_strategy/otf.rb | 3 ++- Library/Homebrew/unpack_strategy/p7zip.rb | 6 ++++-- Library/Homebrew/unpack_strategy/pax.rb | 3 ++- Library/Homebrew/unpack_strategy/pkg.rb | 3 ++- Library/Homebrew/unpack_strategy/rar.rb | 6 ++++-- .../Homebrew/unpack_strategy/self_extracting_executable.rb | 3 ++- Library/Homebrew/unpack_strategy/sit.rb | 3 ++- Library/Homebrew/unpack_strategy/subversion.rb | 6 ++++-- Library/Homebrew/unpack_strategy/tar.rb | 3 ++- Library/Homebrew/unpack_strategy/ttf.rb | 3 ++- Library/Homebrew/unpack_strategy/xar.rb | 3 ++- Library/Homebrew/unpack_strategy/xz.rb | 6 ++++-- Library/Homebrew/unpack_strategy/zip.rb | 1 + Library/Homebrew/unpack_strategy/zstd.rb | 6 ++++-- 33 files changed, 92 insertions(+), 47 deletions(-) diff --git a/Library/Homebrew/unpack_strategy/air.rb b/Library/Homebrew/unpack_strategy/air.rb index 1aeaa830da..6415995419 100644 --- a/Library/Homebrew/unpack_strategy/air.rb +++ b/Library/Homebrew/unpack_strategy/air.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -11,13 +11,15 @@ module UnpackStrategy [".air"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) mime_type = "application/vnd.adobe.air-application-installer-package+zip" path.magic_number.match?(/.{59}#{Regexp.escape(mime_type)}/) end + sig { returns(T.nilable(T::Array[Cask::Cask])) } def dependencies - @dependencies ||= [Cask::CaskLoader.load("adobe-air")] + @dependencies ||= T.let([Cask::CaskLoader.load("adobe-air")], T.nilable(T::Array[Cask::Cask])) end AIR_APPLICATION_INSTALLER = diff --git a/Library/Homebrew/unpack_strategy/bazaar.rb b/Library/Homebrew/unpack_strategy/bazaar.rb index b952ba206d..770cca92aa 100644 --- a/Library/Homebrew/unpack_strategy/bazaar.rb +++ b/Library/Homebrew/unpack_strategy/bazaar.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "directory" @@ -6,8 +6,9 @@ require_relative "directory" module UnpackStrategy # Strategy for unpacking Bazaar archives. class Bazaar < Directory + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) - super && (path/".bzr").directory? + !!(super && (path/".bzr").directory?) end private diff --git a/Library/Homebrew/unpack_strategy/bzip2.rb b/Library/Homebrew/unpack_strategy/bzip2.rb index 6225b93388..12190c6a69 100644 --- a/Library/Homebrew/unpack_strategy/bzip2.rb +++ b/Library/Homebrew/unpack_strategy/bzip2.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -11,6 +11,7 @@ module UnpackStrategy [".bz2"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\ABZh/n) end diff --git a/Library/Homebrew/unpack_strategy/cab.rb b/Library/Homebrew/unpack_strategy/cab.rb index 388ceb425c..a4cc7993a6 100644 --- a/Library/Homebrew/unpack_strategy/cab.rb +++ b/Library/Homebrew/unpack_strategy/cab.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -11,6 +11,7 @@ module UnpackStrategy [".cab"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\AMSCF/n) end @@ -23,8 +24,9 @@ module UnpackStrategy verbose: end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["cabextract"]] + @dependencies ||= T.let([Formula["cabextract"]], T.nilable(T::Array[Formula])) end end end diff --git a/Library/Homebrew/unpack_strategy/compress.rb b/Library/Homebrew/unpack_strategy/compress.rb index e2d6ce37f8..504f31390b 100644 --- a/Library/Homebrew/unpack_strategy/compress.rb +++ b/Library/Homebrew/unpack_strategy/compress.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "tar" @@ -11,6 +11,7 @@ module UnpackStrategy [".Z"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\A\037\235/n) end diff --git a/Library/Homebrew/unpack_strategy/cvs.rb b/Library/Homebrew/unpack_strategy/cvs.rb index af6f0a3a77..7e3c5b018b 100644 --- a/Library/Homebrew/unpack_strategy/cvs.rb +++ b/Library/Homebrew/unpack_strategy/cvs.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "directory" @@ -6,8 +6,9 @@ require_relative "directory" module UnpackStrategy # Strategy for unpacking CVS repositories. class Cvs < Directory + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) - super && (path/"CVS").directory? + !!(super && (path/"CVS").directory?) end end end diff --git a/Library/Homebrew/unpack_strategy/directory.rb b/Library/Homebrew/unpack_strategy/directory.rb index 50127031da..62c76284bd 100644 --- a/Library/Homebrew/unpack_strategy/directory.rb +++ b/Library/Homebrew/unpack_strategy/directory.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -11,6 +11,7 @@ module UnpackStrategy [] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.directory? end diff --git a/Library/Homebrew/unpack_strategy/executable.rb b/Library/Homebrew/unpack_strategy/executable.rb index 86c381ef13..51cf812786 100644 --- a/Library/Homebrew/unpack_strategy/executable.rb +++ b/Library/Homebrew/unpack_strategy/executable.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "uncompressed" @@ -11,6 +11,7 @@ module UnpackStrategy [".sh", ".bash"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\A#!\s*\S+/n) || path.magic_number.match?(/\AMZ/n) diff --git a/Library/Homebrew/unpack_strategy/fossil.rb b/Library/Homebrew/unpack_strategy/fossil.rb index 8517d064f2..8914c05aa8 100644 --- a/Library/Homebrew/unpack_strategy/fossil.rb +++ b/Library/Homebrew/unpack_strategy/fossil.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "system_command" @@ -14,6 +14,7 @@ module UnpackStrategy [] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) return false unless path.magic_number.match?(/\ASQLite format 3\000/n) diff --git a/Library/Homebrew/unpack_strategy/generic_unar.rb b/Library/Homebrew/unpack_strategy/generic_unar.rb index 1e3075e947..ecc6e2c256 100644 --- a/Library/Homebrew/unpack_strategy/generic_unar.rb +++ b/Library/Homebrew/unpack_strategy/generic_unar.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -11,12 +11,14 @@ module UnpackStrategy [] end + sig { override.params(_path: Pathname).returns(T::Boolean) } def self.can_extract?(_path) false end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["unar"]] + @dependencies ||= T.let([Formula["unar"]], T.nilable(T::Array[Formula])) end private diff --git a/Library/Homebrew/unpack_strategy/git.rb b/Library/Homebrew/unpack_strategy/git.rb index ab39f3c4e0..42b906f125 100644 --- a/Library/Homebrew/unpack_strategy/git.rb +++ b/Library/Homebrew/unpack_strategy/git.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "directory" @@ -6,8 +6,9 @@ require_relative "directory" module UnpackStrategy # Strategy for unpacking Git repositories. class Git < Directory + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) - super && (path/".git").directory? + !!(super && (path/".git").directory?) end end end diff --git a/Library/Homebrew/unpack_strategy/gzip.rb b/Library/Homebrew/unpack_strategy/gzip.rb index 70ff74c56e..b525cc6d0b 100644 --- a/Library/Homebrew/unpack_strategy/gzip.rb +++ b/Library/Homebrew/unpack_strategy/gzip.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -11,6 +11,7 @@ module UnpackStrategy [".gz"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\A\037\213/n) end diff --git a/Library/Homebrew/unpack_strategy/jar.rb b/Library/Homebrew/unpack_strategy/jar.rb index 8082d8602c..0be166bbaa 100644 --- a/Library/Homebrew/unpack_strategy/jar.rb +++ b/Library/Homebrew/unpack_strategy/jar.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "uncompressed" @@ -11,6 +11,7 @@ module UnpackStrategy [".apk", ".jar"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) return false unless Zip.can_extract?(path) diff --git a/Library/Homebrew/unpack_strategy/lha.rb b/Library/Homebrew/unpack_strategy/lha.rb index ece0b4b8cc..0fdb49ed55 100644 --- a/Library/Homebrew/unpack_strategy/lha.rb +++ b/Library/Homebrew/unpack_strategy/lha.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -11,12 +11,14 @@ module UnpackStrategy [".lha", ".lzh"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\A..-(lh0|lh1|lz4|lz5|lzs|lh\\40|lhd|lh2|lh3|lh4|lh5)-/n) end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["lha"]] + @dependencies ||= T.let([Formula["lha"]], T.nilable(T::Array[Formula])) end private diff --git a/Library/Homebrew/unpack_strategy/lua_rock.rb b/Library/Homebrew/unpack_strategy/lua_rock.rb index b054b9f810..f806364a0f 100644 --- a/Library/Homebrew/unpack_strategy/lua_rock.rb +++ b/Library/Homebrew/unpack_strategy/lua_rock.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "uncompressed" @@ -11,6 +11,7 @@ module UnpackStrategy [".rock"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) return false unless Zip.can_extract?(path) diff --git a/Library/Homebrew/unpack_strategy/lzip.rb b/Library/Homebrew/unpack_strategy/lzip.rb index 90150a40c6..710f3684db 100644 --- a/Library/Homebrew/unpack_strategy/lzip.rb +++ b/Library/Homebrew/unpack_strategy/lzip.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -11,12 +11,14 @@ module UnpackStrategy [".lz"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\ALZIP/n) end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["lzip"]] + @dependencies ||= T.let([Formula["lzip"]], T.nilable(T::Array[Formula])) end private diff --git a/Library/Homebrew/unpack_strategy/lzma.rb b/Library/Homebrew/unpack_strategy/lzma.rb index 5b6ed1c4e8..d1b6710c42 100644 --- a/Library/Homebrew/unpack_strategy/lzma.rb +++ b/Library/Homebrew/unpack_strategy/lzma.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -11,12 +11,14 @@ module UnpackStrategy [".lzma"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\A\]\000\000\200\000/n) end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["xz"]] + @dependencies ||= T.let([Formula["xz"]], T.nilable(T::Array[Formula])) end private diff --git a/Library/Homebrew/unpack_strategy/mercurial.rb b/Library/Homebrew/unpack_strategy/mercurial.rb index c4a77d4d0d..146f686c9c 100644 --- a/Library/Homebrew/unpack_strategy/mercurial.rb +++ b/Library/Homebrew/unpack_strategy/mercurial.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "directory" @@ -6,12 +6,14 @@ require_relative "directory" module UnpackStrategy # Strategy for unpacking Mercurial repositories. class Mercurial < Directory + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) - super && (path/".hg").directory? + !!(super && (path/".hg").directory?) end private + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "hg", args: ["--cwd", path, "archive", "--subrepos", "-y", "-t", "files", unpack_dir], diff --git a/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb b/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb index dfc4c084f4..cb54b9b1f7 100644 --- a/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb +++ b/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "uncompressed" @@ -15,6 +15,7 @@ module UnpackStrategy ] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) return false unless Zip.can_extract?(path) diff --git a/Library/Homebrew/unpack_strategy/otf.rb b/Library/Homebrew/unpack_strategy/otf.rb index b4839b2a61..da593812a5 100644 --- a/Library/Homebrew/unpack_strategy/otf.rb +++ b/Library/Homebrew/unpack_strategy/otf.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "uncompressed" @@ -11,6 +11,7 @@ module UnpackStrategy [".otf"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\AOTTO/n) end diff --git a/Library/Homebrew/unpack_strategy/p7zip.rb b/Library/Homebrew/unpack_strategy/p7zip.rb index 69e2c9deab..44a8c4b986 100644 --- a/Library/Homebrew/unpack_strategy/p7zip.rb +++ b/Library/Homebrew/unpack_strategy/p7zip.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -11,12 +11,14 @@ module UnpackStrategy [".7z"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\A7z\xBC\xAF\x27\x1C/n) end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["p7zip"]] + @dependencies ||= T.let([Formula["p7zip"]], T.nilable(T::Array[Formula])) end private diff --git a/Library/Homebrew/unpack_strategy/pax.rb b/Library/Homebrew/unpack_strategy/pax.rb index bc5f89c15a..9cbc799c23 100644 --- a/Library/Homebrew/unpack_strategy/pax.rb +++ b/Library/Homebrew/unpack_strategy/pax.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -11,6 +11,7 @@ module UnpackStrategy [".pax"] end + sig { override.params(_path: Pathname).returns(T::Boolean) } def self.can_extract?(_path) false end diff --git a/Library/Homebrew/unpack_strategy/pkg.rb b/Library/Homebrew/unpack_strategy/pkg.rb index e4b288b827..585edfbea9 100644 --- a/Library/Homebrew/unpack_strategy/pkg.rb +++ b/Library/Homebrew/unpack_strategy/pkg.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "uncompressed" @@ -11,6 +11,7 @@ module UnpackStrategy [".pkg", ".mkpg"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.extname.match?(/\A.m?pkg\Z/) && (path.directory? || path.magic_number.match?(/\Axar!/n)) diff --git a/Library/Homebrew/unpack_strategy/rar.rb b/Library/Homebrew/unpack_strategy/rar.rb index 06394dbdf4..7d8109d654 100644 --- a/Library/Homebrew/unpack_strategy/rar.rb +++ b/Library/Homebrew/unpack_strategy/rar.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -11,12 +11,14 @@ module UnpackStrategy [".rar"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\ARar!/n) end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["libarchive"]] + @dependencies ||= T.let([Formula["libarchive"]], T.nilable(T::Array[Formula])) end private diff --git a/Library/Homebrew/unpack_strategy/self_extracting_executable.rb b/Library/Homebrew/unpack_strategy/self_extracting_executable.rb index 078ce77365..58bad3be74 100644 --- a/Library/Homebrew/unpack_strategy/self_extracting_executable.rb +++ b/Library/Homebrew/unpack_strategy/self_extracting_executable.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "generic_unar" @@ -11,6 +11,7 @@ module UnpackStrategy [] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\AMZ/n) && path.file_type.include?("self-extracting archive") diff --git a/Library/Homebrew/unpack_strategy/sit.rb b/Library/Homebrew/unpack_strategy/sit.rb index 631c446297..82c48e6d19 100644 --- a/Library/Homebrew/unpack_strategy/sit.rb +++ b/Library/Homebrew/unpack_strategy/sit.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "generic_unar" @@ -11,6 +11,7 @@ module UnpackStrategy [".sit"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\AStuffIt/n) end diff --git a/Library/Homebrew/unpack_strategy/subversion.rb b/Library/Homebrew/unpack_strategy/subversion.rb index 7ba74fa5e0..81c037d73e 100644 --- a/Library/Homebrew/unpack_strategy/subversion.rb +++ b/Library/Homebrew/unpack_strategy/subversion.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "directory" @@ -6,12 +6,14 @@ require_relative "directory" module UnpackStrategy # Strategy for unpacking Subversion repositories. class Subversion < Directory + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) - super && (path/".svn").directory? + !!(super && (path/".svn").directory?) end private + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void } def extract_to_dir(unpack_dir, basename:, verbose:) system_command! "svn", args: ["export", "--force", ".", unpack_dir], diff --git a/Library/Homebrew/unpack_strategy/tar.rb b/Library/Homebrew/unpack_strategy/tar.rb index adbf59def5..ae3ff08cd2 100644 --- a/Library/Homebrew/unpack_strategy/tar.rb +++ b/Library/Homebrew/unpack_strategy/tar.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require "system_command" @@ -22,6 +22,7 @@ module UnpackStrategy ] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) return true if path.magic_number.match?(/\A.{257}ustar/n) diff --git a/Library/Homebrew/unpack_strategy/ttf.rb b/Library/Homebrew/unpack_strategy/ttf.rb index 3c73a6801e..c240f93679 100644 --- a/Library/Homebrew/unpack_strategy/ttf.rb +++ b/Library/Homebrew/unpack_strategy/ttf.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true require_relative "uncompressed" @@ -11,6 +11,7 @@ module UnpackStrategy [".ttc", ".ttf"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) # TrueType Font path.magic_number.match?(/\A\000\001\000\000\000/n) || diff --git a/Library/Homebrew/unpack_strategy/xar.rb b/Library/Homebrew/unpack_strategy/xar.rb index 0d571fa5ac..d6562f8d22 100644 --- a/Library/Homebrew/unpack_strategy/xar.rb +++ b/Library/Homebrew/unpack_strategy/xar.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -11,6 +11,7 @@ module UnpackStrategy [".xar"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\Axar!/n) end diff --git a/Library/Homebrew/unpack_strategy/xz.rb b/Library/Homebrew/unpack_strategy/xz.rb index a9ffc96a65..2e155c687b 100644 --- a/Library/Homebrew/unpack_strategy/xz.rb +++ b/Library/Homebrew/unpack_strategy/xz.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -11,12 +11,14 @@ module UnpackStrategy [".xz"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\A\xFD7zXZ\x00/n) end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["xz"]] + @dependencies ||= T.let([Formula["xz"]], T.nilable(T::Array[Formula])) end private diff --git a/Library/Homebrew/unpack_strategy/zip.rb b/Library/Homebrew/unpack_strategy/zip.rb index 59da683f35..28e413e00a 100644 --- a/Library/Homebrew/unpack_strategy/zip.rb +++ b/Library/Homebrew/unpack_strategy/zip.rb @@ -23,6 +23,7 @@ module UnpackStrategy .returns(SystemCommand::Result) } def extract_to_dir(unpack_dir, basename:, verbose:) + odebug "in unpack_strategy, zip, extract_to_dir, verbose: #{verbose.inspect}" unzip = if which("unzip").blank? begin Formula["unzip"] diff --git a/Library/Homebrew/unpack_strategy/zstd.rb b/Library/Homebrew/unpack_strategy/zstd.rb index 3dfa808f34..475b0ca518 100644 --- a/Library/Homebrew/unpack_strategy/zstd.rb +++ b/Library/Homebrew/unpack_strategy/zstd.rb @@ -1,4 +1,4 @@ -# typed: true +# typed: strict # frozen_string_literal: true module UnpackStrategy @@ -11,12 +11,14 @@ module UnpackStrategy [".zst"] end + sig { override.params(path: Pathname).returns(T::Boolean) } def self.can_extract?(path) path.magic_number.match?(/\x28\xB5\x2F\xFD/n) end + sig { returns(T.nilable(T::Array[Formula])) } def dependencies - @dependencies ||= [Formula["zstd"]] + @dependencies ||= T.let([Formula["zstd"]], T.nilable(T::Array[Formula])) end private