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 1/2] 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) From 1d9ee93e6ecdd85eb9c763c83ab7dca3ca3427b6 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Wed, 21 Sep 2022 23:05:00 +0800 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Bo Anderson --- Library/Homebrew/extend/ENV/std.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index 0d75f43489..e1829e32a6 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -59,9 +59,9 @@ module Stdenv begin send(compiler) - rescue CompilerSelectionError => e + rescue CompilerSelectionError # We don't care if our compiler fails to build the formula during `brew test`. - raise e unless testing_formula + raise unless testing_formula send(DevelopmentTools.default_compiler) end