From 16041377235061d9a6fe6683e7be2ce6d825f5ee Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Sun, 22 Sep 2024 11:16:23 -0700 Subject: [PATCH] Fix ENV --- Library/Homebrew/extend/ENV/std.rb | 1 - Library/Homebrew/extend/ENV/super.rb | 1 - .../extend/os/linux/extend/ENV/std.rb | 69 +++++---- .../extend/os/linux/extend/ENV/super.rb | 131 ++++++++++-------- .../Homebrew/extend/os/mac/extend/ENV/std.rb | 3 +- .../extend/os/mac/extend/ENV/super.rb | 3 +- Library/Homebrew/extend/os/mac/keg.rb | 1 + 7 files changed, 112 insertions(+), 97 deletions(-) diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index b0c312c24a86c2..22f5cb4056f96b 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -68,7 +68,6 @@ def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_a gcc_formula = gcc_version_formula(cc) append_path "PATH", gcc_formula.opt_bin.to_s end - alias generic_setup_build_environment setup_build_environment sig { returns(T.nilable(PATH)) } def determine_pkg_config_libdir diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 89f7ecfa5e6548..812ae68bfddb6a 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -119,7 +119,6 @@ def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_a # These flags will also be present: # a - apply fix for apr-1-config path end - alias generic_setup_build_environment setup_build_environment private diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/std.rb b/Library/Homebrew/extend/os/linux/extend/ENV/std.rb index ba2fa12309d4a5..8a249311b83f6f 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/std.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/std.rb @@ -1,36 +1,45 @@ # typed: true # rubocop:todo Sorbet/StrictSigil # frozen_string_literal: true -module Stdenv - sig { - params( - formula: T.nilable(Formula), - cc: T.nilable(String), - build_bottle: T.nilable(T::Boolean), - bottle_arch: T.nilable(String), - testing_formula: T::Boolean, - debug_symbols: T.nilable(T::Boolean), - ).void - } - def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false, - debug_symbols: false) - generic_setup_build_environment(formula:, cc:, build_bottle:, bottle_arch:, - testing_formula:, debug_symbols:) - - prepend_path "CPATH", HOMEBREW_PREFIX/"include" - prepend_path "LIBRARY_PATH", HOMEBREW_PREFIX/"lib" - prepend_path "LD_RUN_PATH", HOMEBREW_PREFIX/"lib" - - return unless @formula - - prepend_path "CPATH", @formula.include - prepend_path "LIBRARY_PATH", @formula.lib - prepend_path "LD_RUN_PATH", @formula.lib - end +module OS + module Linux + module Stdenv + extend T::Helpers + + requires_ancestor { ::Stdenv } + + sig { + params( + formula: T.nilable(Formula), + cc: T.nilable(String), + build_bottle: T.nilable(T::Boolean), + bottle_arch: T.nilable(String), + testing_formula: T::Boolean, + debug_symbols: T.nilable(T::Boolean), + ).void + } + def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, + testing_formula: false, debug_symbols: false) + super + + prepend_path "CPATH", HOMEBREW_PREFIX/"include" + prepend_path "LIBRARY_PATH", HOMEBREW_PREFIX/"lib" + prepend_path "LD_RUN_PATH", HOMEBREW_PREFIX/"lib" - def libxml2 - append "CPPFLAGS", "-I#{Formula["libxml2"].include/"libxml2"}" - rescue FormulaUnavailableError - nil + return unless @formula + + prepend_path "CPATH", @formula.include + prepend_path "LIBRARY_PATH", @formula.lib + prepend_path "LD_RUN_PATH", @formula.lib + end + + def libxml2 + append "CPPFLAGS", "-I#{::Formula["libxml2"].include/"libxml2"}" + rescue FormulaUnavailableError + nil + end + end end end + +Stdenv.prepend(OS::Linux::Stdenv) diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb index f0aa87920edadf..6bc4da2d051bbc 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb @@ -1,73 +1,82 @@ # typed: true # rubocop:todo Sorbet/StrictSigil # frozen_string_literal: true -module Superenv - sig { returns(Pathname) } - def self.shims_path - HOMEBREW_SHIMS_PATH/"linux/super" - end +module OS + module Linux + module Superenv + extend T::Helpers - sig { returns(T.nilable(Pathname)) } - def self.bin - shims_path.realpath - end + requires_ancestor { ::Superenv } - sig { - params( - formula: T.nilable(Formula), - cc: T.nilable(String), - build_bottle: T.nilable(T::Boolean), - bottle_arch: T.nilable(String), - testing_formula: T::Boolean, - debug_symbols: T.nilable(T::Boolean), - ).void - } - def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false, - debug_symbols: false) - generic_setup_build_environment(formula:, cc:, build_bottle:, bottle_arch:, - testing_formula:, debug_symbols:) - self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O2" - self["HOMEBREW_DYNAMIC_LINKER"] = determine_dynamic_linker_path - self["HOMEBREW_RPATH_PATHS"] = determine_rpath_paths(@formula) - self["M4"] = "#{HOMEBREW_PREFIX}/opt/m4/bin/m4" if deps.any? { |d| d.name == "libtool" || d.name == "bison" } - end + sig { returns(Pathname) } + def self.shims_path + HOMEBREW_SHIMS_PATH/"linux/super" + end - def homebrew_extra_paths - paths = generic_homebrew_extra_paths - paths += %w[binutils make].filter_map do |f| - bin = Formulary.factory(f).opt_bin - bin if bin.directory? - rescue FormulaUnavailableError - nil - end - paths - end + sig { returns(T.nilable(Pathname)) } + def self.bin + shims_path.realpath + end - def homebrew_extra_isystem_paths - paths = [] - # Add paths for GCC headers when building against glibc@2.13 because we have to use -nostdinc. - if deps.any? { |d| d.name == "glibc@2.13" } - gcc_include_dir = Utils.safe_popen_read(cc, "--print-file-name=include").chomp - gcc_include_fixed_dir = Utils.safe_popen_read(cc, "--print-file-name=include-fixed").chomp - paths << gcc_include_dir << gcc_include_fixed_dir - end - paths - end + sig { + params( + formula: T.nilable(Formula), + cc: T.nilable(String), + build_bottle: T.nilable(T::Boolean), + bottle_arch: T.nilable(String), + testing_formula: T::Boolean, + debug_symbols: T.nilable(T::Boolean), + ).void + } + def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, + testing_formula: false, debug_symbols: false) + super + self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O2" + self["HOMEBREW_DYNAMIC_LINKER"] = determine_dynamic_linker_path + self["HOMEBREW_RPATH_PATHS"] = determine_rpath_paths(@formula) + self["M4"] = "#{HOMEBREW_PREFIX}/opt/m4/bin/m4" if deps.any? { |d| d.name == "libtool" || d.name == "bison" } + end - def determine_rpath_paths(formula) - PATH.new( - *formula&.lib, - "#{HOMEBREW_PREFIX}/opt/gcc/lib/gcc/current", - PATH.new(run_time_deps.map { |dep| dep.opt_lib.to_s }).existing, - "#{HOMEBREW_PREFIX}/lib", - ) - end + def homebrew_extra_paths + paths = generic_homebrew_extra_paths + paths += %w[binutils make].filter_map do |f| + bin = Formulary.factory(f).opt_bin + bin if bin.directory? + rescue FormulaUnavailableError + nil + end + paths + end + + def homebrew_extra_isystem_paths + paths = [] + # Add paths for GCC headers when building against glibc@2.13 because we have to use -nostdinc. + if deps.any? { |d| d.name == "glibc@2.13" } + gcc_include_dir = Utils.safe_popen_read(cc, "--print-file-name=include").chomp + gcc_include_fixed_dir = Utils.safe_popen_read(cc, "--print-file-name=include-fixed").chomp + paths << gcc_include_dir << gcc_include_fixed_dir + end + paths + end - sig { returns(T.nilable(String)) } - def determine_dynamic_linker_path - path = "#{HOMEBREW_PREFIX}/lib/ld.so" - return unless File.readable? path + def determine_rpath_paths(formula) + PATH.new( + *formula&.lib, + "#{HOMEBREW_PREFIX}/opt/gcc/lib/gcc/current", + PATH.new(run_time_deps.map { |dep| dep.opt_lib.to_s }).existing, + "#{HOMEBREW_PREFIX}/lib", + ) + end - path + sig { returns(T.nilable(String)) } + def determine_dynamic_linker_path + path = "#{HOMEBREW_PREFIX}/lib/ld.so" + return unless File.readable? path + + path + end + end end end + +Superenv.prepend(OS::Linux::Superenv) diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb index 7aec76c23d50bb..90f3dedacc725b 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb @@ -26,8 +26,7 @@ def homebrew_extra_pkg_config_paths } def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false, debug_symbols: false) - generic_setup_build_environment(formula:, cc:, build_bottle:, bottle_arch:, - testing_formula:, debug_symbols:) + super append "LDFLAGS", "-Wl,-headerpad_max_install_names" diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb index eb894c024b167b..921e13707c6a51 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb @@ -108,8 +108,7 @@ def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_a self["M4"] = gm4 end - generic_setup_build_environment(formula:, cc:, build_bottle:, bottle_arch:, - testing_formula:, debug_symbols:) + super # Filter out symbols known not to be defined since GNU Autotools can't # reliably figure this out with Xcode 8 and above. diff --git a/Library/Homebrew/extend/os/mac/keg.rb b/Library/Homebrew/extend/os/mac/keg.rb index 8f5ec2b5f9d1e3..b71aaee900528c 100644 --- a/Library/Homebrew/extend/os/mac/keg.rb +++ b/Library/Homebrew/extend/os/mac/keg.rb @@ -6,6 +6,7 @@ class Keg include SystemCommand::Mixin + # TODO: re-implement these as functions, so that we aren't modifying constants: GENERIC_KEG_LINK_DIRECTORIES = (remove_const :KEG_LINK_DIRECTORIES).freeze KEG_LINK_DIRECTORIES = (GENERIC_KEG_LINK_DIRECTORIES + ["Frameworks"]).freeze GENERIC_MUST_EXIST_SUBDIRECTORIES = (remove_const :MUST_EXIST_SUBDIRECTORIES).freeze