From ab22e8bc4e9ecb3cbe59c09eae5d8b496e2612b7 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Mon, 23 Sep 2024 21:00:58 +0800 Subject: [PATCH] env_config: infer HOMEBREW_FORBID_PACKAGES_FROM_PATHS from HOMEBREW_DEVELOPER If `HOMEBREW_DEVELOPER` is not set, then let's make `HOMEBREW_FORBID_PACKAGES_FROM_PATHS` default to true. I used a custom implementation here because we don't currently support setting defaults for booleans. (See calls to `define_method` below.) Closes #18371. --- Library/Homebrew/env_config.rb | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index 63445e6dbe2c9..77a8bd3cce95e 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -219,9 +219,11 @@ module EnvConfig "formula if it or any of its dependencies is in a tap on this list.", }, HOMEBREW_FORBID_PACKAGES_FROM_PATHS: { - description: "If set, Homebrew will refuse to read formulae or casks provided from file paths, " \ - "e.g. `brew install ./package.rb`.", - boolean: true, + description: "If set, Homebrew will refuse to read formulae or casks provided from file paths, " \ + "e.g. `brew install ./package.rb`.", + boolean: true, + default_text: "Enabled unless `HOMEBREW_DEVELOPER` is set.", + default: -> { !developer? }, }, HOMEBREW_FORCE_BREWED_CA_CERTIFICATES: { description: "If set, always use a Homebrew-installed `ca-certificates` rather than the system version. " \ @@ -504,6 +506,7 @@ def env_method_name(env, hash) CUSTOM_IMPLEMENTATIONS = T.let(Set.new([ :HOMEBREW_MAKE_JOBS, :HOMEBREW_CASK_OPTS, + :HOMEBREW_FORBID_PACKAGES_FROM_PATHS, ]).freeze, T::Set[Symbol]) ENVS.each do |env, hash| @@ -528,6 +531,15 @@ def env_method_name(env, hash) end end + sig { returns(T::Boolean) } + def forbid_packages_from_paths? + return true if ENV["HOMEBREW_FORBID_PACKAGES_FROM_PATHS"].present? + + ENVS.fetch(:HOMEBREW_FORBID_PACKAGES_FROM_PATHS) + .fetch(:default) + .call + end + # Needs a custom implementation. sig { returns(String) } def make_jobs