Pass individual args explicitly to ENV extensions.

This commit is contained in:
Markus Reiter 2020-07-28 02:04:50 +02:00
parent fddeceda3c
commit 276c570c16
15 changed files with 68 additions and 52 deletions

View File

@ -83,19 +83,29 @@ class Build
fixopt(dep) unless dep.opt_prefix.directory?
end
ENV.activate_extensions!(args: args)
ENV.activate_extensions!(env: args.env)
if superenv?(args: args)
if superenv?(args.env)
ENV.keg_only_deps = keg_only_deps
ENV.deps = formula_deps
ENV.run_time_deps = run_time_deps
ENV.x11 = reqs.any? { |rq| rq.is_a?(X11Requirement) }
ENV.setup_build_environment(formula, args: args)
ENV.setup_build_environment(
formula: formula,
cc: args.cc,
build_bottle: args.build_bottle?,
bottle_arch: args.bottle_arch,
)
post_superenv_hacks
reqs.each { |req| req.modify_build_environment(args: args) }
deps.each(&:modify_build_environment)
else
ENV.setup_build_environment(formula, args: args)
ENV.setup_build_environment(
formula: formula,
cc: args.cc,
build_bottle: args.build_bottle?,
bottle_arch: args.bottle_arch,
)
reqs.each { |req| req.modify_build_environment(args: args) }
deps.each(&:modify_build_environment)

View File

@ -29,9 +29,9 @@ module Homebrew
def __env
args = __env_args.parse
ENV.activate_extensions!(args: args)
ENV.deps = args.formulae if superenv?(args: args)
ENV.setup_build_environment(args: args)
ENV.activate_extensions!(env: args.env)
ENV.deps = args.formulae if superenv?(args.env)
ENV.setup_build_environment
shell = if args.plain?
nil

View File

@ -88,8 +88,8 @@ module Homebrew
git = args.git?
skip_style = args.skip_style? || args.no_named?
ENV.activate_extensions!(args: args)
ENV.setup_build_environment(args: args)
ENV.activate_extensions!
ENV.setup_build_environment
audit_formulae = args.no_named? ? Formula : args.resolved_formulae
style_files = args.formulae_paths unless skip_style

View File

@ -29,14 +29,14 @@ module Homebrew
def sh
args = sh_args.parse
ENV.activate_extensions!(args: args)
ENV.activate_extensions!(env: args.env)
if superenv?(args: args)
if superenv?(args.env)
ENV.set_x11_env_if_installed
ENV.deps = Formula.installed.select { |f| f.keg_only? && f.opt_prefix.directory? }
end
ENV.setup_build_environment(args: args)
if superenv?(args: args)
ENV.setup_build_environment
if superenv?(args.env)
# superenv stopped adding brew's bin but generally users will want it
ENV["PATH"] = PATH.new(ENV["PATH"]).insert(1, HOMEBREW_PREFIX/"bin")
end

View File

@ -5,24 +5,24 @@ require "extend/ENV/shared"
require "extend/ENV/std"
require "extend/ENV/super"
def superenv?(args:)
args&.env != "std" && Superenv.bin
def superenv?(env)
env != "std" && Superenv.bin
end
module EnvActivation
def activate_extensions!(args:)
if superenv?(args: args)
def activate_extensions!(env: nil)
if superenv?(env)
extend(Superenv)
else
extend(Stdenv)
end
end
def with_build_environment(args:)
def with_build_environment(env: nil, cc: nil, build_bottle: false, bottle_arch: nil)
old_env = to_hash.dup
tmp_env = to_hash.dup.extend(EnvActivation)
tmp_env.activate_extensions!(args: args)
tmp_env.setup_build_environment(args: args)
tmp_env.activate_extensions!(env: env)
tmp_env.setup_build_environment(cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch)
replace(tmp_env)
yield
ensure

View File

@ -29,9 +29,11 @@ module SharedEnvExtension
].freeze
# @private
def setup_build_environment(formula = nil, args: nil)
def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil)
@formula = formula
@args = args
@cc = cc
@build_bottle = build_bottle
@bottle_arch = bottle_arch
reset
end
@ -163,7 +165,7 @@ module SharedEnvExtension
# ENV.append_to_cflags "-I ./missing/includes"
# end</pre>
def compiler
@compiler ||= if (cc = @args.cc)
@compiler ||= if (cc = @cc)
warn_about_non_apple_gcc($&) if cc =~ GNU_GCC_REGEXP
fetch_compiler(cc, "--cc")
elsif (cc = homebrew_cc)
@ -255,8 +257,8 @@ module SharedEnvExtension
# @private
def effective_arch
if @args&.build_bottle? && @args&.bottle_arch
@args.bottle_arch.to_sym
if @build_bottle && @bottle_arch
@bottle_arch.to_sym
else
Hardware.oldest_cpu
end

View File

@ -11,8 +11,8 @@ module Stdenv
SAFE_CFLAGS_FLAGS = "-w -pipe"
# @private
def setup_build_environment(formula = nil, args: nil)
super
def setup_build_environment(**options)
super(**options)
self["HOMEBREW_ENV"] = "std"

View File

@ -36,8 +36,8 @@ module Superenv
end
# @private
def setup_build_environment(formula = nil, args: nil)
super
def setup_build_environment(**options)
super(**options)
send(compiler)
self["HOMEBREW_ENV"] = "super"
@ -64,7 +64,7 @@ module Superenv
self["HOMEBREW_INCLUDE_PATHS"] = determine_include_paths
self["HOMEBREW_LIBRARY_PATHS"] = determine_library_paths
self["HOMEBREW_DEPENDENCIES"] = determine_dependencies
self["HOMEBREW_FORMULA_PREFIX"] = formula.prefix unless formula.nil?
self["HOMEBREW_FORMULA_PREFIX"] = @formula.prefix unless @formula.nil?
# 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

View File

@ -1,17 +1,18 @@
# frozen_string_literal: true
module Stdenv
def setup_build_environment(formula = nil, args: nil)
generic_setup_build_environment(formula, args: args)
def setup_build_environment(**options)
generic_setup_build_environment(**options)
prepend_path "CPATH", HOMEBREW_PREFIX/"include"
prepend_path "LIBRARY_PATH", HOMEBREW_PREFIX/"lib"
prepend_path "LD_RUN_PATH", HOMEBREW_PREFIX/"lib"
return unless formula
return unless @formula
prepend_path "CPATH", formula.include
prepend_path "LIBRARY_PATH", formula.lib
prepend_path "LD_RUN_PATH", formula.lib
prepend_path "LIBRARY_PATH", @formula.lib
prepend_path "LD_RUN_PATH", @formula.lib
end
def libxml2

View File

@ -7,11 +7,11 @@ module Superenv
end
# @private
def setup_build_environment(formula = nil, args: nil)
generic_setup_build_environment(formula, args: args)
def setup_build_environment(**options)
generic_setup_build_environment(**options)
self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O2"
self["HOMEBREW_DYNAMIC_LINKER"] = determine_dynamic_linker_path
self["HOMEBREW_RPATH_PATHS"] = determine_rpath_paths(formula)
self["HOMEBREW_RPATH_PATHS"] = determine_rpath_paths(@formula)
end
def homebrew_extra_paths
@ -27,7 +27,7 @@ module Superenv
def determine_rpath_paths(formula)
PATH.new(
formula&.lib,
*formula&.lib,
"#{HOMEBREW_PREFIX}/lib",
PATH.new(run_time_deps.map { |dep| dep.opt_lib.to_s }).existing,
)

View File

@ -32,8 +32,8 @@ module Stdenv
append "CFLAGS", "-I#{MacOS::X11.include}" unless MacOS::CLT.installed?
end
def setup_build_environment(formula = nil, args: nil)
generic_setup_build_environment(formula, args: args)
def setup_build_environment(**options)
generic_setup_build_environment(**options)
# sed is strict, and errors out when it encounters files with
# mixed character sets
@ -41,7 +41,7 @@ module Stdenv
self["LC_CTYPE"] = "C"
# Add lib and include etc. from the current macosxsdk to compiler flags:
macosxsdk(formula: formula)
macosxsdk(formula: @formula)
return unless MacOS::Xcode.without_clt?

View File

@ -106,7 +106,8 @@ module Superenv
end
# @private
def setup_build_environment(formula = nil, args: nil)
def setup_build_environment(**options)
formula = options[:formula]
sdk = formula ? MacOS.sdk_for_formula(formula) : MacOS.sdk
if MacOS.sdk_root_needed? || sdk&.source == :xcode
self["HOMEBREW_SDKROOT"] = sdk.path
@ -119,7 +120,7 @@ module Superenv
self["HOMEBREW_SDKROOT"] = nil
self["HOMEBREW_DEVELOPER_DIR"] = nil
end
generic_setup_build_environment(formula, args: args)
generic_setup_build_environment(**options)
# Filter out symbols known not to be defined since GNU Autotools can't
# reliably figure this out with Xcode 8 and above.

View File

@ -186,7 +186,11 @@ class Requirement
@satisfied
elsif @options[:build_env]
require "extend/ENV"
ENV.with_build_environment(args: args) { yield @proc }
ENV.with_build_environment(
env: args.env, cc: args.cc, build_bottle: args.build_bottle?, bottle_arch: args.bottle_arch,
) do
yield @proc
end
else
yield @proc
end

View File

@ -28,7 +28,7 @@ begin
formula.extend(Debrew::Formula) if Homebrew.args.debug?
ENV.extend(Stdenv)
ENV.setup_build_environment(formula, args: args)
ENV.setup_build_environment(formula: formula)
# tests can also return false to indicate failure
Timeout.timeout TEST_TIMEOUT_SECONDS do

View File

@ -15,12 +15,10 @@ shared_examples EnvActivation do
end
describe "#with_build_environment" do
let(:args) { Homebrew::CLI::Args.new }
it "restores the environment" do
before = subject.dup
subject.with_build_environment(args: args) do
subject.with_build_environment do
subject["foo"] = "bar"
end
@ -32,7 +30,7 @@ shared_examples EnvActivation do
before = subject.dup
expect {
subject.with_build_environment(args: args) do
subject.with_build_environment do
subject["foo"] = "bar"
raise StandardError
end
@ -43,13 +41,13 @@ shared_examples EnvActivation do
end
it "returns the value of the block" do
expect(subject.with_build_environment(args: args) { 1 }).to eq(1)
expect(subject.with_build_environment { 1 }).to eq(1)
end
it "does not mutate the interface" do
expected = subject.methods
subject.with_build_environment(args: args) do
subject.with_build_environment do
expect(subject.methods).to eq(expected)
end