Merge pull request #17636 from Homebrew/sorbet-strict-public-apis
This commit is contained in:
commit
1479013710
@ -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.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
|
||||
@ -62,12 +62,14 @@ 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")) &&
|
||||
(build_version = `#{path} --version`[/(?:clang|LLVM) version (\d+\.\d(?:\.\d)?)/, 1])
|
||||
Version.new(build_version)
|
||||
else
|
||||
Version::NULL
|
||||
end, T.nilable(Version)
|
||||
)
|
||||
end
|
||||
|
||||
# Get the Clang build version.
|
||||
@ -75,13 +77,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 +92,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? && (build_version = `#{path} --version`[/clang version (\d+\.\d\.\d)/, 1])
|
||||
Version.new(build_version)
|
||||
else
|
||||
Version::NULL
|
||||
end
|
||||
end
|
||||
end, T.nilable(Version))
|
||||
end
|
||||
|
||||
# Get the GCC version.
|
||||
@ -105,12 +107,12 @@ 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.new(build_version)
|
||||
else
|
||||
Version::NULL
|
||||
end
|
||||
@ -120,8 +122,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) }
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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|
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "system_command"
|
||||
@ -6,11 +6,30 @@ 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.
|
||||
# rubocop:disable Style/MutableConstant
|
||||
UnpackStrategyType = 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
|
||||
|
||||
mixes_in_class_methods(ClassMethods)
|
||||
|
||||
sig { returns(T.nilable(T::Array[UnpackStrategyType])) }
|
||||
def self.strategies
|
||||
@strategies ||= [
|
||||
@strategies ||= T.let([
|
||||
Tar, # Needs to be before Bzip2/Gzip/Xz/Lzma/Zstd.
|
||||
Pax,
|
||||
Gzip,
|
||||
@ -43,10 +62,11 @@ module UnpackStrategy
|
||||
Sit,
|
||||
Rar,
|
||||
Lha,
|
||||
].freeze
|
||||
].freeze, T.nilable(T::Array[UnpackStrategyType]))
|
||||
end
|
||||
private_class_method :strategies
|
||||
|
||||
sig { params(type: Symbol).returns(T.nilable(UnpackStrategyType)) }
|
||||
def self.from_type(type)
|
||||
type = {
|
||||
naked: :uncompressed,
|
||||
@ -61,23 +81,31 @@ module UnpackStrategy
|
||||
end
|
||||
end
|
||||
|
||||
sig { params(extension: String).returns(T.nilable(UnpackStrategyType)) }
|
||||
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) } }
|
||||
return unless strategies
|
||||
|
||||
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(UnpackStrategyType)) }
|
||||
def self.from_magic(path)
|
||||
strategies.find { |s| s.can_extract?(path) }
|
||||
strategies&.find { |s| s.can_extract?(path) }
|
||||
end
|
||||
|
||||
def self.detect(path, prioritize_extension: false, type: nil, ref_type: nil, ref: nil, merge_xattrs: nil)
|
||||
sig {
|
||||
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)
|
||||
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)
|
||||
@ -88,24 +116,31 @@ module UnpackStrategy
|
||||
strategy.new(path, ref_type:, ref:, merge_xattrs:)
|
||||
end
|
||||
|
||||
attr_reader :path, :merge_xattrs
|
||||
sig { returns(Pathname) }
|
||||
attr_reader :path
|
||||
|
||||
def initialize(path, ref_type: nil, ref: nil, merge_xattrs: nil)
|
||||
@path = Pathname(path).expand_path
|
||||
@ref_type = ref_type
|
||||
@ref = ref
|
||||
@merge_xattrs = merge_xattrs
|
||||
sig { returns(T::Boolean) }
|
||||
attr_reader :merge_xattrs
|
||||
|
||||
sig {
|
||||
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 = T.let(ref_type, T.nilable(Symbol))
|
||||
@ref = T.let(ref, T.nilable(String))
|
||||
@merge_xattrs = T.let(merge_xattrs, T::Boolean)
|
||||
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 +166,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 +187,7 @@ module UnpackStrategy
|
||||
end
|
||||
end
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
def dependencies
|
||||
[]
|
||||
end
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
@ -6,18 +6,20 @@ module UnpackStrategy
|
||||
class Air
|
||||
include UnpackStrategy
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[".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 =
|
||||
@ -27,7 +29,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],
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "directory"
|
||||
@ -6,13 +6,14 @@ 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
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
@ -6,18 +6,19 @@ module UnpackStrategy
|
||||
class Bzip2
|
||||
include UnpackStrategy
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[".bz2"]
|
||||
end
|
||||
|
||||
sig { override.params(path: Pathname).returns(T::Boolean) }
|
||||
def self.can_extract?(path)
|
||||
path.magic_number.match?(/\ABZh/n)
|
||||
end
|
||||
|
||||
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"]
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
@ -6,16 +6,17 @@ module UnpackStrategy
|
||||
class Cab
|
||||
include UnpackStrategy
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[".cab"]
|
||||
end
|
||||
|
||||
sig { override.params(path: Pathname).returns(T::Boolean) }
|
||||
def self.can_extract?(path)
|
||||
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],
|
||||
@ -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
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "tar"
|
||||
@ -6,11 +6,12 @@ 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
|
||||
|
||||
sig { override.params(path: Pathname).returns(T::Boolean) }
|
||||
def self.can_extract?(path)
|
||||
path.magic_number.match?(/\A\037\235/n)
|
||||
end
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
@ -6,18 +6,19 @@ module UnpackStrategy
|
||||
class Directory
|
||||
include UnpackStrategy
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[]
|
||||
end
|
||||
|
||||
sig { override.params(path: Pathname).returns(T::Boolean) }
|
||||
def self.can_extract?(path)
|
||||
path.directory?
|
||||
end
|
||||
|
||||
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",
|
||||
|
||||
@ -121,9 +121,15 @@ 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) }
|
||||
sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void }
|
||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||
tries = 3
|
||||
bom = begin
|
||||
@ -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
|
||||
@ -177,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?
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "uncompressed"
|
||||
@ -6,11 +6,12 @@ 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
|
||||
|
||||
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)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "system_command"
|
||||
@ -9,11 +9,12 @@ module UnpackStrategy
|
||||
include UnpackStrategy
|
||||
extend SystemCommand::Mixin
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[]
|
||||
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)
|
||||
|
||||
@ -24,7 +25,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]
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
@ -6,22 +6,24 @@ module UnpackStrategy
|
||||
class GenericUnar
|
||||
include UnpackStrategy
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[]
|
||||
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
|
||||
|
||||
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: [
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
@ -6,18 +6,19 @@ module UnpackStrategy
|
||||
class Gzip
|
||||
include UnpackStrategy
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[".gz"]
|
||||
end
|
||||
|
||||
sig { override.params(path: Pathname).returns(T::Boolean) }
|
||||
def self.can_extract?(path)
|
||||
path.magic_number.match?(/\A\037\213/n)
|
||||
end
|
||||
|
||||
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"]
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "uncompressed"
|
||||
@ -6,11 +6,12 @@ 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
|
||||
|
||||
sig { override.params(path: Pathname).returns(T::Boolean) }
|
||||
def self.can_extract?(path)
|
||||
return false unless Zip.can_extract?(path)
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
@ -6,22 +6,24 @@ module UnpackStrategy
|
||||
class Lha
|
||||
include UnpackStrategy
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[".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
|
||||
|
||||
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],
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "uncompressed"
|
||||
@ -6,11 +6,12 @@ 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
|
||||
|
||||
sig { override.params(path: Pathname).returns(T::Boolean) }
|
||||
def self.can_extract?(path)
|
||||
return false unless Zip.can_extract?(path)
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
@ -6,22 +6,24 @@ module UnpackStrategy
|
||||
class Lzip
|
||||
include UnpackStrategy
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[".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
|
||||
|
||||
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"]
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
@ -6,22 +6,24 @@ module UnpackStrategy
|
||||
class Lzma
|
||||
include UnpackStrategy
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[".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
|
||||
|
||||
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"]
|
||||
|
||||
@ -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],
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "uncompressed"
|
||||
@ -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",
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "uncompressed"
|
||||
@ -6,11 +6,12 @@ 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
|
||||
|
||||
sig { override.params(path: Pathname).returns(T::Boolean) }
|
||||
def self.can_extract?(path)
|
||||
path.magic_number.match?(/\AOTTO/n)
|
||||
end
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
@ -6,22 +6,24 @@ module UnpackStrategy
|
||||
class P7Zip
|
||||
include UnpackStrategy
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[".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
|
||||
|
||||
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}"],
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
@ -6,18 +6,19 @@ module UnpackStrategy
|
||||
class Pax
|
||||
include UnpackStrategy
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[".pax"]
|
||||
end
|
||||
|
||||
sig { override.params(_path: Pathname).returns(T::Boolean) }
|
||||
def self.can_extract?(_path)
|
||||
false
|
||||
end
|
||||
|
||||
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],
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "uncompressed"
|
||||
@ -6,11 +6,12 @@ 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
|
||||
|
||||
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))
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
@ -6,22 +6,24 @@ module UnpackStrategy
|
||||
class Rar
|
||||
include UnpackStrategy
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[".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
|
||||
|
||||
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],
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "generic_unar"
|
||||
@ -6,11 +6,12 @@ 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
|
||||
|
||||
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")
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "generic_unar"
|
||||
@ -6,11 +6,12 @@ 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
|
||||
|
||||
sig { override.params(path: Pathname).returns(T::Boolean) }
|
||||
def self.can_extract?(path)
|
||||
path.magic_number.match?(/\AStuffIt/n)
|
||||
end
|
||||
|
||||
@ -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],
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "system_command"
|
||||
@ -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",
|
||||
@ -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)
|
||||
|
||||
@ -34,7 +35,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)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative "uncompressed"
|
||||
@ -6,11 +6,12 @@ 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
|
||||
|
||||
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) ||
|
||||
|
||||
@ -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),
|
||||
@ -20,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
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
@ -6,18 +6,19 @@ module UnpackStrategy
|
||||
class Xar
|
||||
include UnpackStrategy
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[".xar"]
|
||||
end
|
||||
|
||||
sig { override.params(path: Pathname).returns(T::Boolean) }
|
||||
def self.can_extract?(path)
|
||||
path.magic_number.match?(/\Axar!/n)
|
||||
end
|
||||
|
||||
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],
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
@ -6,22 +6,24 @@ module UnpackStrategy
|
||||
class Xz
|
||||
include UnpackStrategy
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[".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
|
||||
|
||||
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"]
|
||||
|
||||
@ -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
|
||||
@ -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"]
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
# typed: true
|
||||
# typed: strict
|
||||
# frozen_string_literal: true
|
||||
|
||||
module UnpackStrategy
|
||||
@ -6,22 +6,24 @@ module UnpackStrategy
|
||||
class Zstd
|
||||
include UnpackStrategy
|
||||
|
||||
sig { returns(T::Array[String]) }
|
||||
sig { override.returns(T::Array[String]) }
|
||||
def self.extensions
|
||||
[".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
|
||||
|
||||
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"]
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user