From e9bcab6986b064a6584286f6b22fde3177b1694d Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Wed, 21 Sep 2022 22:45:19 +0800 Subject: [PATCH] extend/ENV/std: ignore `fails_with` during `brew test`. The compiler used to a build a formula is typically not needed during the test. This will allow us to get rid of some `:test` dependencies, which were added to prevent `brew` from throwing a `CompilerSelectionError` because the formula declares `fails_with` the default compiler. This also helps us get more accurate results from `brew linkage` in cases of unintended linkage with the compiler used to build. Fixes #11795. --- Library/Homebrew/extend/ENV/std.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index 37d4c7779f..0d75f43489 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -57,7 +57,14 @@ module Stdenv # Os is the default Apple uses for all its stuff so let's trust them define_cflags "-Os #{SAFE_CFLAGS_FLAGS}" - send(compiler) + begin + send(compiler) + rescue CompilerSelectionError => e + # We don't care if our compiler fails to build the formula during `brew test`. + raise e unless testing_formula + + send(DevelopmentTools.default_compiler) + end return unless cc&.match?(GNU_GCC_REGEXP)