Merge pull request #20608 from botantony/typed-strict

lock_file simulate_system: `typed: strict`
This commit is contained in:
Mike McQuaid 2025-09-01 13:18:24 +00:00 committed by GitHub
commit 9903f0c1f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 9 deletions

View File

@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "fcntl" require "fcntl"
@ -11,14 +11,15 @@ class LockFile
class OpenFileChangedOnDisk < RuntimeError; end class OpenFileChangedOnDisk < RuntimeError; end
private_constant :OpenFileChangedOnDisk private_constant :OpenFileChangedOnDisk
sig { returns(Pathname) }
attr_reader :path attr_reader :path
sig { params(type: Symbol, locked_path: Pathname).void } sig { params(type: Symbol, locked_path: Pathname).void }
def initialize(type, locked_path) def initialize(type, locked_path)
@locked_path = locked_path @locked_path = locked_path
lock_name = locked_path.basename.to_s lock_name = locked_path.basename.to_s
@path = HOMEBREW_LOCKS/"#{lock_name}.#{type}.lock" @path = T.let(HOMEBREW_LOCKS/"#{lock_name}.#{type}.lock", Pathname)
@lockfile = nil @lockfile = T.let(nil, T.nilable(File))
end end
sig { void } sig { void }
@ -30,7 +31,7 @@ class LockFile
begin begin
lockfile = begin lockfile = begin
path.open(File::RDWR | File::CREAT) File.open(path, File::RDWR | File::CREAT)
rescue Errno::EMFILE rescue Errno::EMFILE
odie "The maximum number of open files on this system has been reached. " \ odie "The maximum number of open files on this system has been reached. " \
"Use `ulimit -n` to increase this limit." "Use `ulimit -n` to increase this limit."
@ -78,7 +79,8 @@ class LockFile
end end
end end
def with_lock sig { params(_block: T.proc.void).void }
def with_lock(&_block)
lock lock
yield yield
ensure ensure

View File

@ -1,4 +1,4 @@
# typed: true # rubocop:todo Sorbet/StrictSigil # typed: strict
# frozen_string_literal: true # frozen_string_literal: true
require "macos_version" require "macos_version"
@ -8,7 +8,11 @@ module Homebrew
# Helper module for simulating different system configurations. # Helper module for simulating different system configurations.
class SimulateSystem class SimulateSystem
class << self class << self
attr_reader :arch, :os sig { returns(T.nilable(Symbol)) }
attr_reader :arch
sig { returns(T.nilable(Symbol)) }
attr_reader :os
sig { returns(T::Hash[Symbol, Symbol]) } sig { returns(T::Hash[Symbol, Symbol]) }
def arch_symbols def arch_symbols
@ -56,14 +60,14 @@ module Homebrew
os_options = [:macos, :linux, *MacOSVersion::SYMBOLS.keys] os_options = [:macos, :linux, *MacOSVersion::SYMBOLS.keys]
raise "Unknown OS: #{new_os}" unless os_options.include?(new_os) raise "Unknown OS: #{new_os}" unless os_options.include?(new_os)
@os = new_os @os = T.let(new_os, T.nilable(Symbol))
end end
sig { params(new_arch: Symbol).void } sig { params(new_arch: Symbol).void }
def arch=(new_arch) def arch=(new_arch)
raise "New arch must be :arm or :intel" unless OnSystem::ARCH_OPTIONS.include?(new_arch) raise "New arch must be :arm or :intel" unless OnSystem::ARCH_OPTIONS.include?(new_arch)
@arch = new_arch @arch = T.let(new_arch, T.nilable(Symbol))
end end
sig { void } sig { void }