diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index 5ee369389a..aef1cc3df4 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -79,10 +79,11 @@ class Build ENV.deps = formula_deps ENV.run_time_deps = run_time_deps ENV.setup_build_environment( - formula: formula, - cc: args.cc, - build_bottle: args.build_bottle?, - bottle_arch: args.bottle_arch, + formula: formula, + cc: args.cc, + build_bottle: args.build_bottle?, + bottle_arch: args.bottle_arch, + debug_symbols: args.debug_symbols?, ) reqs.each do |req| req.modify_build_environment( @@ -96,6 +97,7 @@ class Build cc: args.cc, build_bottle: args.build_bottle?, bottle_arch: args.bottle_arch, + debug_symbols: args.debug_symbols?, ) reqs.each do |req| req.modify_build_environment( diff --git a/Library/Homebrew/extend/ENV.rb b/Library/Homebrew/extend/ENV.rb index 12ef1af60d..40bb592a87 100644 --- a/Library/Homebrew/extend/ENV.rb +++ b/Library/Homebrew/extend/ENV.rb @@ -40,12 +40,22 @@ module EnvActivation _block: T.proc.returns(T.untyped), ).returns(T.untyped) } - def with_build_environment(env: nil, cc: nil, build_bottle: false, bottle_arch: nil, &_block) + def with_build_environment( + env: nil, + cc: nil, + build_bottle: false, + bottle_arch: nil, + debug_symbols: false, + &_block + ) old_env = to_hash.dup tmp_env = to_hash.dup.extend(EnvActivation) T.cast(tmp_env, EnvActivation).activate_extensions!(env: env) T.cast(tmp_env, T.any(Superenv, Stdenv)) - .setup_build_environment(cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch) + .setup_build_environment( + cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch, + debug_symbols: debug_symbols, + ) replace(tmp_env) begin diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb index bccd15aaf5..f31400733c 100644 --- a/Library/Homebrew/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/ENV/shared.rb @@ -40,13 +40,22 @@ module SharedEnvExtension 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) + def setup_build_environment( + formula: nil, + cc: nil, + build_bottle: false, + bottle_arch: nil, + testing_formula: false, + debug_symbols: false + ) @formula = formula @cc = cc @build_bottle = build_bottle @bottle_arch = bottle_arch + @debug_symbols = debug_symbols reset end private :setup_build_environment @@ -315,9 +324,6 @@ module SharedEnvExtension sig { void } def permit_arch_flags; end - sig { void } - def debug_symbols; end - # @private sig { params(cc: T.any(Symbol, String)).returns(T::Boolean) } def compiler_any_clang?(cc = compiler) diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index ba4caa1a80..fb3cc6d570 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -23,7 +23,14 @@ module Stdenv testing_formula: T::Boolean, ).void } - def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false) + def setup_build_environment( + formula: nil, + cc: nil, + build_bottle: false, + bottle_arch: nil, + testing_formula: false, + debug_symbols: false + ) super self["HOMEBREW_ENV"] = "std" diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index c199714866..3ddaaad7e6 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -57,7 +57,14 @@ module Superenv testing_formula: T::Boolean, ).void } - def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false) + def setup_build_environment( + formula: nil, + cc: nil, + build_bottle: false, + bottle_arch: nil, + testing_formula: false, + debug_symbols: false + ) super send(compiler) @@ -87,6 +94,8 @@ module Superenv self["HOMEBREW_DEPENDENCIES"] = determine_dependencies self["HOMEBREW_FORMULA_PREFIX"] = @formula.prefix unless @formula.nil? + set_debug_symbols if debug_symbols + # The HOMEBREW_CCCFG ENV variable is used by the ENV/cc tool to control # compiler flag stripping. It consists of a string of characters which act # as flags. Some of these flags are mutually exclusive. @@ -283,9 +292,7 @@ module Superenv sig { returns(String) } def determine_cccfg - # TODO: temporarily hard code symbol generation - # "" - "D" + "" end public @@ -335,8 +342,7 @@ module Superenv end sig { void } - def debug_symbols - # TODO: how do I get this method called? + def set_debug_symbols append_to_cccfg "D" if OS.mac? end diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/std.rb b/Library/Homebrew/extend/os/linux/extend/ENV/std.rb index 76d564cd59..73bc4e2a91 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/std.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/std.rb @@ -2,10 +2,18 @@ # frozen_string_literal: true module Stdenv - def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false) + 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: formula, cc: cc, build_bottle: build_bottle, - bottle_arch: bottle_arch, testing_formula: testing_formula + bottle_arch: bottle_arch, testing_formula: testing_formula, + debug_symbols: debug_symbols, ) prepend_path "CPATH", HOMEBREW_PREFIX/"include" diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb index bbfc418214..074f842099 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb @@ -15,10 +15,18 @@ module Superenv end # @private - def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false) + 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: formula, cc: cc, build_bottle: build_bottle, - bottle_arch: bottle_arch, testing_formula: testing_formula + bottle_arch: bottle_arch, testing_formula: testing_formula, + debug_symbols: debug_symbols, ) self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O2" self["HOMEBREW_DYNAMIC_LINKER"] = determine_dynamic_linker_path diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/shared.rb b/Library/Homebrew/extend/os/mac/extend/ENV/shared.rb index a690791acc..7db7a5f8fd 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/shared.rb @@ -4,10 +4,18 @@ module SharedEnvExtension extend T::Sig - def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false) + def setup_build_environment( + formula: nil, + cc: nil, + build_bottle: false, + bottle_arch: nil, + testing_formula: false, + debug_symbols: false + ) generic_shared_setup_build_environment( formula: formula, cc: cc, build_bottle: build_bottle, - bottle_arch: bottle_arch, testing_formula: testing_formula + bottle_arch: bottle_arch, testing_formula: testing_formula, + debug_symbols: debug_symbols, ) # Normalise the system Perl version used, where multiple may be available diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb index d40fcec500..7368ec4696 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb @@ -10,10 +10,18 @@ module Stdenv ["#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}"] end - def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false) + 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: formula, cc: cc, build_bottle: build_bottle, - bottle_arch: bottle_arch, testing_formula: testing_formula + bottle_arch: bottle_arch, testing_formula: testing_formula, + debug_symbols: debug_symbols, ) 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 c05535a800..258970240e 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb @@ -85,7 +85,14 @@ module Superenv end # @private - def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false) + def setup_build_environment( + formula: nil, + cc: nil, + build_bottle: false, + bottle_arch: nil, + testing_formula: false, + debug_symbols: false + ) sdk = formula ? MacOS.sdk_for_formula(formula) : MacOS.sdk is_xcode_sdk = sdk&.source == :xcode @@ -102,7 +109,8 @@ module Superenv generic_setup_build_environment( formula: formula, cc: cc, build_bottle: build_bottle, - bottle_arch: bottle_arch, testing_formula: testing_formula + bottle_arch: bottle_arch, testing_formula: testing_formula, + debug_symbols: debug_symbols, ) # Filter out symbols known not to be defined since GNU Autotools can't