Skip to content

Commit

Permalink
Fix ENV
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Oct 5, 2024
1 parent 0d5b56a commit f4a6dce
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 97 deletions.
1 change: 0 additions & 1 deletion Library/Homebrew/extend/ENV/std.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion Library/Homebrew/extend/ENV/super.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
69 changes: 39 additions & 30 deletions Library/Homebrew/extend/os/linux/extend/ENV/std.rb
Original file line number Diff line number Diff line change
@@ -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

Check warning on line 33 in Library/Homebrew/extend/os/linux/extend/ENV/std.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/std.rb#L31-L33

Added lines #L31 - L33 were not covered by tests
end

def libxml2
append "CPPFLAGS", "-I#{::Formula["libxml2"].include/"libxml2"}"

Check warning on line 37 in Library/Homebrew/extend/os/linux/extend/ENV/std.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/std.rb#L37

Added line #L37 was not covered by tests
rescue FormulaUnavailableError
nil

Check warning on line 39 in Library/Homebrew/extend/os/linux/extend/ENV/std.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/std.rb#L39

Added line #L39 was not covered by tests
end
end
end
end

Stdenv.prepend(OS::Linux::Stdenv)
131 changes: 70 additions & 61 deletions Library/Homebrew/extend/os/linux/extend/ENV/super.rb
Original file line number Diff line number Diff line change
@@ -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"

Check warning on line 13 in Library/Homebrew/extend/os/linux/extend/ENV/super.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L13

Added line #L13 was not covered by tests
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

Check warning on line 18 in Library/Homebrew/extend/os/linux/extend/ENV/super.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L18

Added line #L18 was not covered by tests
end

def homebrew_extra_isystem_paths
paths = []
# Add paths for GCC headers when building against [email protected] because we have to use -nostdinc.
if deps.any? { |d| d.name == "[email protected]" }
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(

Check warning on line 22 in Library/Homebrew/extend/os/linux/extend/ENV/super.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L22

Added line #L22 was not covered by tests
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)

Check warning on line 36 in Library/Homebrew/extend/os/linux/extend/ENV/super.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L33-L36

Added lines #L33 - L36 were not covered by tests
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

Check warning on line 43 in Library/Homebrew/extend/os/linux/extend/ENV/super.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L41-L43

Added lines #L41 - L43 were not covered by tests
bin if bin.directory?
rescue FormulaUnavailableError
nil

Check warning on line 46 in Library/Homebrew/extend/os/linux/extend/ENV/super.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L46

Added line #L46 was not covered by tests
end
paths

Check warning on line 48 in Library/Homebrew/extend/os/linux/extend/ENV/super.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L48

Added line #L48 was not covered by tests
end

def homebrew_extra_isystem_paths
paths = []

Check warning on line 52 in Library/Homebrew/extend/os/linux/extend/ENV/super.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L52

Added line #L52 was not covered by tests
# Add paths for GCC headers when building against [email protected] because we have to use -nostdinc.
if deps.any? { |d| d.name == "[email protected]" }
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

Check warning on line 57 in Library/Homebrew/extend/os/linux/extend/ENV/super.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L56-L57

Added lines #L56 - L57 were not covered by tests
end
paths

Check warning on line 59 in Library/Homebrew/extend/os/linux/extend/ENV/super.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L59

Added line #L59 was not covered by tests
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(

Check warning on line 63 in Library/Homebrew/extend/os/linux/extend/ENV/super.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L63

Added line #L63 was not covered by tests
*formula&.lib,
"#{HOMEBREW_PREFIX}/opt/gcc/lib/gcc/current",
PATH.new(run_time_deps.map { |dep| dep.opt_lib.to_s }).existing,

Check warning on line 66 in Library/Homebrew/extend/os/linux/extend/ENV/super.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L66

Added line #L66 was not covered by tests
"#{HOMEBREW_PREFIX}/lib",
)
end

path
sig { returns(T.nilable(String)) }
def determine_dynamic_linker_path
path = "#{HOMEBREW_PREFIX}/lib/ld.so"

Check warning on line 73 in Library/Homebrew/extend/os/linux/extend/ENV/super.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L73

Added line #L73 was not covered by tests
return unless File.readable? path

path

Check warning on line 76 in Library/Homebrew/extend/os/linux/extend/ENV/super.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/extend/ENV/super.rb#L76

Added line #L76 was not covered by tests
end
end
end
end

Superenv.prepend(OS::Linux::Superenv)
3 changes: 1 addition & 2 deletions Library/Homebrew/extend/os/mac/extend/ENV/std.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 29 in Library/Homebrew/extend/os/mac/extend/ENV/std.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/mac/extend/ENV/std.rb#L29

Added line #L29 was not covered by tests

append "LDFLAGS", "-Wl,-headerpad_max_install_names"

Check warning on line 31 in Library/Homebrew/extend/os/mac/extend/ENV/std.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/mac/extend/ENV/std.rb#L31

Added line #L31 was not covered by tests

Expand Down
3 changes: 1 addition & 2 deletions Library/Homebrew/extend/os/mac/extend/ENV/super.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/extend/os/mac/keg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f4a6dce

Please sign in to comment.