diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 56f2a5d58a..ca162a051c 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -1102,6 +1102,9 @@ then fi unset SUDO +# Remove internal variables +unset HOMEBREW_INTERNAL_ALLOW_PACKAGES_FROM_PATHS + if [[ -n "${HOMEBREW_BASH_COMMAND}" ]] then # source rather than executing directly to ensure the entire file is read into diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index de47babe8c..0cfdd8d5e6 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -227,7 +227,10 @@ class Build end begin - ENV.delete("HOMEBREW_FORBID_PACKAGES_FROM_PATHS") + # Undocumented opt-out for internal use. + # We need to allow formulae from paths here due to how we pass them through. + ENV["HOMEBREW_INTERNAL_ALLOW_PACKAGES_FROM_PATHS"] = "1" + args = Homebrew::Cmd::InstallCmd.new.args Context.current = args.context diff --git a/Library/Homebrew/env_config.rb b/Library/Homebrew/env_config.rb index 74679b02fd..df1ea287a7 100644 --- a/Library/Homebrew/env_config.rb +++ b/Library/Homebrew/env_config.rb @@ -632,6 +632,9 @@ module Homebrew sig { returns(T::Boolean) } def forbid_packages_from_paths? + # Undocumented opt-out for internal use. + return false if ENV["HOMEBREW_INTERNAL_ALLOW_PACKAGES_FROM_PATHS"].present? + return true if ENV["HOMEBREW_FORBID_PACKAGES_FROM_PATHS"].present? # Provide an opt-out for tests and developers. diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 1d30222bd5..92570e4e03 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -619,17 +619,21 @@ module Formulary if Homebrew::EnvConfig.forbid_packages_from_paths? path_realpath = path.realpath.to_s path_string = path.to_s - if !path_realpath.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/", "#{HOMEBREW_CACHE}/") && - (path_string.include?("/") || path_string.end_with?(".rb")) - raise <<~WARNING - Rejecting formula at #{path_string} because it's not in a tap. - Homebrew requires formulae to be in a tap. + unless path_realpath.start_with?("#{HOMEBREW_CELLAR}/", "#{HOMEBREW_LIBRARY}/Taps/", "#{HOMEBREW_CACHE}/") + if path_string.include?("./") || path_string.end_with?(".rb") || path_string.count("/") != 2 + raise <<~WARNING + Rejecting formula at #{path_string} because it's not in a tap. + Homebrew requires formulae to be in a tap. - To create a tap, run e.g. - brew tap-new / - To create a formula in a tap run e.g. - brew create --tap=/ - WARNING + To create a tap, run e.g. + brew tap-new / + To create a formula in a tap run e.g. + brew create --tap=/ + WARNING + elsif path_string.count("/") == 2 + # Looks like a tap, let's quietly return but not error. + return + end end end diff --git a/Library/Homebrew/postinstall.rb b/Library/Homebrew/postinstall.rb index cde5b8b676..f69d270de3 100644 --- a/Library/Homebrew/postinstall.rb +++ b/Library/Homebrew/postinstall.rb @@ -14,7 +14,10 @@ require "cmd/postinstall" require "json/add/exception" begin - ENV.delete("HOMEBREW_FORBID_PACKAGES_FROM_PATHS") + # Undocumented opt-out for internal use. + # We need to allow formulae from paths here due to how we pass them through. + ENV["HOMEBREW_INTERNAL_ALLOW_PACKAGES_FROM_PATHS"] = "1" + args = Homebrew::Cmd::Postinstall.new.args error_pipe = Utils::UNIXSocketExt.open(ENV.fetch("HOMEBREW_ERROR_PIPE"), &:recv_io) error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC) @@ -29,7 +32,7 @@ begin formula.run_post_install # Handle all possible exceptions. rescue Exception => e # rubocop:disable Lint/RescueException - error_pipe.puts e.to_json - error_pipe.close + error_pipe&.puts e.to_json + error_pipe&.close exit! 1 end diff --git a/Library/Homebrew/test.rb b/Library/Homebrew/test.rb index 338e4d7d9b..1f2b1c8956 100644 --- a/Library/Homebrew/test.rb +++ b/Library/Homebrew/test.rb @@ -19,7 +19,10 @@ require "json/add/exception" DEFAULT_TEST_TIMEOUT_SECONDS = 5 * 60 begin - ENV.delete("HOMEBREW_FORBID_PACKAGES_FROM_PATHS") + # Undocumented opt-out for internal use. + # We need to allow formulae from paths here due to how we pass them through. + ENV["HOMEBREW_INTERNAL_ALLOW_PACKAGES_FROM_PATHS"] = "1" + args = Homebrew::DevCmd::Test.new.args Context.current = args.context @@ -55,8 +58,8 @@ begin end # Any exceptions during the test run are reported. rescue Exception => e # rubocop:disable Lint/RescueException - error_pipe.puts e.to_json - error_pipe.close + error_pipe&.puts e.to_json + error_pipe&.close ensure pid = Process.pid.to_s if which("pgrep") && which("pkill") && system("pgrep", "-P", pid, out: File::NULL)