From b2539d37fe0ad518f763c4c1663c6bed4b71002e Mon Sep 17 00:00:00 2001 From: botantony Date: Mon, 8 Sep 2025 11:16:27 +0200 Subject: [PATCH] build_options: `typed: strict` Signed-off-by: botantony --- Library/Homebrew/build_options.rb | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/build_options.rb b/Library/Homebrew/build_options.rb index 3dff77598f..d6b4c94c16 100644 --- a/Library/Homebrew/build_options.rb +++ b/Library/Homebrew/build_options.rb @@ -1,11 +1,12 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true # Options for a formula build. class BuildOptions + sig { params(args: Options, options: Options).void } def initialize(args, options) - @args = args - @options = options + @args = T.let(args, Options) + @options = T.let(options, Options) end # True if a {Formula} is being built with a specific option. @@ -29,8 +30,13 @@ class BuildOptions # args << "--with-example1" # end # ``` + sig { params(val: T.any(String, Requirement, Dependency)).returns(T::Boolean) } def with?(val) - option_names = val.respond_to?(:option_names) ? val.option_names : [val] + option_names = if val.is_a?(String) + [val] + else + val.option_names + end option_names.any? do |name| if option_defined? "with-#{name}" @@ -50,11 +56,13 @@ class BuildOptions # ```ruby # args << "--no-spam-plz" if build.without? "spam" # ``` + sig { params(val: T.any(String, Requirement, Dependency)).returns(T::Boolean) } def without?(val) !with?(val) end # True if a {Formula} is being built as a bottle (i.e. binary package). + sig { returns(T::Boolean) } def bottle? include? "build-bottle" end @@ -75,6 +83,7 @@ class BuildOptions # args << "--and-a-cold-beer" if build.with? "cold-beer" # end # ``` + sig { returns(T::Boolean) } def head? include? "HEAD" end @@ -87,29 +96,35 @@ class BuildOptions # ```ruby # args << "--some-feature" if build.stable? # ``` + sig { returns(T::Boolean) } def stable? !head? end # True if the build has any arguments or options specified. + sig { returns(T::Boolean) } def any_args_or_options? !@args.empty? || !@options.empty? end + sig { returns(Options) } def used_options @options & @args end + sig { returns(Options) } def unused_options @options - @args end private + sig { params(name: String).returns(T::Boolean) } def include?(name) @args.include?("--#{name}") end + sig { params(name: String).returns(T::Boolean) } def option_defined?(name) @options.include? name end