mirror of
https://github.com/Homebrew/brew.git
synced 2026-08-12 22:29:27 +04:00
- `brew readall`: validate tap formulae and casks across forked workers (combination loop inside each worker so the `on_system` cache keeps its per-file locality) and syntax-check Ruby files in-process with `RubyVM::InstructionSequence.compile_file` and a `Warning` buffer instead of spawning `ruby -c -w` per file. - `brew style`: run shellcheck+shfmt and actionlint on background threads with buffered output while RuboCop runs on the main thread, chunk shellcheck across CPU cores and pass `--parallel` to RuboCop with `--fix` (supported since RuboCop 1.41). - Resolve linter executables before spawning threads so they cannot race to install formulae. - `Readall.valid_aliases?`: use a single glob and `Set` lookup rather than one glob per alias. - Fix an `end` indentation warning in `cask/cask.rb` that made `brew readall --syntax` fail. - Hyperfine benchmarks (18-core Mac, mean of 2 runs, warm RuboCop cache for style runs, all exit codes 0): - `brew readall homebrew/core`: 34.36s -> 4.71s (7.3x faster) - `brew readall homebrew/cask`: 40.69s -> 5.17s (7.9x faster) - `brew style homebrew/core` (warm): 2.93s -> 2.20s - `brew style homebrew/cask` (warm): 2.37s -> 2.18s - `brew style` on Homebrew/brew itself: 13.2s -> 7.8s - `brew readall --syntax`: 18.2s -> 0.5s - Tap style runs are RuboCop-bound so barely change; the larger style win is on Homebrew/brew where all four linters run. CI runners with fewer cores should expect roughly 3-4x on readall.
60 lines
1.7 KiB
Ruby
60 lines
1.7 KiB
Ruby
# typed: strict
|
|
# frozen_string_literal: true
|
|
|
|
require "utils/output"
|
|
|
|
module OS
|
|
module Mac
|
|
module Readall
|
|
module ClassMethods
|
|
extend T::Helpers
|
|
include ::Utils::Output::Mixin
|
|
|
|
requires_ancestor { Kernel }
|
|
|
|
sig {
|
|
params(
|
|
tap: ::Tap,
|
|
os_name: T.nilable(Symbol),
|
|
arch: T.nilable(Symbol),
|
|
files: T.nilable(T::Array[::Pathname]),
|
|
).returns(T::Boolean)
|
|
}
|
|
def valid_casks?(tap, os_name: nil, arch: ::Hardware::CPU.type, files: nil)
|
|
return super if os_name == :linux
|
|
|
|
current_macos_version = if os_name.is_a?(Symbol)
|
|
MacOSVersion.from_symbol(os_name)
|
|
else
|
|
MacOS.version
|
|
end
|
|
|
|
success = T.let(true, T::Boolean)
|
|
(files || tap.cask_files).each do |file|
|
|
cask = ::Cask::CaskLoader.load(file)
|
|
|
|
# Fine to have missing URLs for unsupported macOS
|
|
macos_req = cask.depends_on.macos
|
|
next if macos_req&.version && Array(macos_req.version).none? do |macos_version|
|
|
current_macos_version.compare(macos_req.comparator, macos_version)
|
|
end
|
|
|
|
raise "Missing URL" if cask.url.nil?
|
|
rescue Interrupt
|
|
raise
|
|
# Handle all possible exceptions reading Casks.
|
|
rescue Exception => e # rubocop:disable Lint/RescueException
|
|
os_and_arch = "macOS #{current_macos_version} on #{arch}"
|
|
onoe "Invalid cask (#{os_and_arch}): #{file}"
|
|
$stderr.puts e
|
|
success = false
|
|
end
|
|
success
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
Readall.singleton_class.prepend(OS::Mac::Readall::ClassMethods)
|