From 78065c57810214a7944d4849880fb5b67d3a5e38 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:54:59 +0800 Subject: [PATCH] env_config: deprecate setting boolean vars to falsy values The way we handle boolean environment variables is a bit unfortunate. For example, setting `HOMEBREW_EVAL_ALL=false` actually enables `HOMEBREW_EVAL_ALL`. Let's fix this by deprecating setting boolean environment variables to common false-y values (`false`, `0`, `nil`, `no`, and `off`) so that we can later ignore these false-y values when reading boolean environment variables. --- Library/Homebrew/env_config.rb | 13 ++++++++++++- Library/Homebrew/test/github_runner_matrix_spec.rb | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index 63445e6dbe..bb185001b3 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -515,7 +515,18 @@ module Homebrew if hash[:boolean] define_method(method_name) do - ENV[env].present? + env_value = ENV.fetch(env, nil) + + falsy_values = %w[false no off nil 0] + if falsy_values.include?(env_value&.downcase) + odeprecated "#{env}=#{env_value}", <<~EOS + If you wish to enable #{env}, #{env}=1 + If you wish to disable #{env}, #{env}= + EOS + end + + # TODO: Uncomment the remaining part of the line below after the deprecation/disable cycle. + env_value.present? # && !falsy_values.include(env_value.downcase) end elsif hash[:default].present? define_method(method_name) do diff --git a/Library/Homebrew/test/github_runner_matrix_spec.rb b/Library/Homebrew/test/github_runner_matrix_spec.rb index 24f6e6221b..d314f3522b 100644 --- a/Library/Homebrew/test/github_runner_matrix_spec.rb +++ b/Library/Homebrew/test/github_runner_matrix_spec.rb @@ -9,6 +9,10 @@ RSpec.describe GitHubRunnerMatrix do allow(ENV).to receive(:fetch).with("HOMEBREW_MACOS_LONG_TIMEOUT", "false").and_return("false") allow(ENV).to receive(:fetch).with("HOMEBREW_MACOS_BUILD_ON_GITHUB_RUNNER", "false").and_return("false") allow(ENV).to receive(:fetch).with("GITHUB_RUN_ID").and_return("12345") + allow(ENV).to receive(:fetch).with("HOMEBREW_NO_INSTALL_FROM_API", nil).and_call_original + allow(ENV).to receive(:fetch).with("HOMEBREW_EVAL_ALL", nil).and_call_original + allow(ENV).to receive(:fetch).with("HOMEBREW_SIMULATE_MACOS_ON_LINUX", nil).and_call_original + allow(ENV).to receive(:fetch).with("HOMEBREW_FORBID_PACKAGES_FROM_PATHS", nil).and_call_original end let(:newest_supported_macos) do