diff --git a/Library/Homebrew/os/linux/ld.rb b/Library/Homebrew/os/linux/ld.rb index 3dc85cb23e119..9227792b29920 100644 --- a/Library/Homebrew/os/linux/ld.rb +++ b/Library/Homebrew/os/linux/ld.rb @@ -7,13 +7,18 @@ module Linux module Ld sig { returns(String) } def self.brewed_ld_so_diagnostics + @brewed_ld_so_diagnostics ||= T.let({}, T.nilable(T::Hash[Pathname, String])) + brewed_ld_so = HOMEBREW_PREFIX/"lib/ld.so" return "" unless brewed_ld_so.exist? - ld_so_output = Utils.popen_read(brewed_ld_so, "--list-diagnostics") - return "" unless $CHILD_STATUS.success? + brewed_ld_so_target = brewed_ld_so.readlink + @brewed_ld_so_diagnostics[brewed_ld_so_target] ||= begin + ld_so_output = Utils.popen_read(brewed_ld_so, "--list-diagnostics") + ld_so_output if $CHILD_STATUS.success? + end - ld_so_output + @brewed_ld_so_diagnostics[brewed_ld_so_target].to_s end sig { returns(String) }