Pass individual args explicitly to ENV extensions.
This commit is contained in:
parent
fddeceda3c
commit
276c570c16
@ -83,19 +83,29 @@ class Build
|
|||||||
fixopt(dep) unless dep.opt_prefix.directory?
|
fixopt(dep) unless dep.opt_prefix.directory?
|
||||||
end
|
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.keg_only_deps = keg_only_deps
|
||||||
ENV.deps = formula_deps
|
ENV.deps = formula_deps
|
||||||
ENV.run_time_deps = run_time_deps
|
ENV.run_time_deps = run_time_deps
|
||||||
ENV.x11 = reqs.any? { |rq| rq.is_a?(X11Requirement) }
|
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
|
post_superenv_hacks
|
||||||
reqs.each { |req| req.modify_build_environment(args: args) }
|
reqs.each { |req| req.modify_build_environment(args: args) }
|
||||||
deps.each(&:modify_build_environment)
|
deps.each(&:modify_build_environment)
|
||||||
else
|
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) }
|
reqs.each { |req| req.modify_build_environment(args: args) }
|
||||||
deps.each(&:modify_build_environment)
|
deps.each(&:modify_build_environment)
|
||||||
|
|
||||||
|
|||||||
@ -29,9 +29,9 @@ module Homebrew
|
|||||||
def __env
|
def __env
|
||||||
args = __env_args.parse
|
args = __env_args.parse
|
||||||
|
|
||||||
ENV.activate_extensions!(args: args)
|
ENV.activate_extensions!(env: args.env)
|
||||||
ENV.deps = args.formulae if superenv?(args: args)
|
ENV.deps = args.formulae if superenv?(args.env)
|
||||||
ENV.setup_build_environment(args: args)
|
ENV.setup_build_environment
|
||||||
|
|
||||||
shell = if args.plain?
|
shell = if args.plain?
|
||||||
nil
|
nil
|
||||||
|
|||||||
@ -88,8 +88,8 @@ module Homebrew
|
|||||||
git = args.git?
|
git = args.git?
|
||||||
skip_style = args.skip_style? || args.no_named?
|
skip_style = args.skip_style? || args.no_named?
|
||||||
|
|
||||||
ENV.activate_extensions!(args: args)
|
ENV.activate_extensions!
|
||||||
ENV.setup_build_environment(args: args)
|
ENV.setup_build_environment
|
||||||
|
|
||||||
audit_formulae = args.no_named? ? Formula : args.resolved_formulae
|
audit_formulae = args.no_named? ? Formula : args.resolved_formulae
|
||||||
style_files = args.formulae_paths unless skip_style
|
style_files = args.formulae_paths unless skip_style
|
||||||
|
|||||||
@ -29,14 +29,14 @@ module Homebrew
|
|||||||
def sh
|
def sh
|
||||||
args = sh_args.parse
|
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.set_x11_env_if_installed
|
||||||
ENV.deps = Formula.installed.select { |f| f.keg_only? && f.opt_prefix.directory? }
|
ENV.deps = Formula.installed.select { |f| f.keg_only? && f.opt_prefix.directory? }
|
||||||
end
|
end
|
||||||
ENV.setup_build_environment(args: args)
|
ENV.setup_build_environment
|
||||||
if superenv?(args: args)
|
if superenv?(args.env)
|
||||||
# superenv stopped adding brew's bin but generally users will want it
|
# superenv stopped adding brew's bin but generally users will want it
|
||||||
ENV["PATH"] = PATH.new(ENV["PATH"]).insert(1, HOMEBREW_PREFIX/"bin")
|
ENV["PATH"] = PATH.new(ENV["PATH"]).insert(1, HOMEBREW_PREFIX/"bin")
|
||||||
end
|
end
|
||||||
|
|||||||
@ -5,24 +5,24 @@ require "extend/ENV/shared"
|
|||||||
require "extend/ENV/std"
|
require "extend/ENV/std"
|
||||||
require "extend/ENV/super"
|
require "extend/ENV/super"
|
||||||
|
|
||||||
def superenv?(args:)
|
def superenv?(env)
|
||||||
args&.env != "std" && Superenv.bin
|
env != "std" && Superenv.bin
|
||||||
end
|
end
|
||||||
|
|
||||||
module EnvActivation
|
module EnvActivation
|
||||||
def activate_extensions!(args:)
|
def activate_extensions!(env: nil)
|
||||||
if superenv?(args: args)
|
if superenv?(env)
|
||||||
extend(Superenv)
|
extend(Superenv)
|
||||||
else
|
else
|
||||||
extend(Stdenv)
|
extend(Stdenv)
|
||||||
end
|
end
|
||||||
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
|
old_env = to_hash.dup
|
||||||
tmp_env = to_hash.dup.extend(EnvActivation)
|
tmp_env = to_hash.dup.extend(EnvActivation)
|
||||||
tmp_env.activate_extensions!(args: args)
|
tmp_env.activate_extensions!(env: env)
|
||||||
tmp_env.setup_build_environment(args: args)
|
tmp_env.setup_build_environment(cc: cc, build_bottle: build_bottle, bottle_arch: bottle_arch)
|
||||||
replace(tmp_env)
|
replace(tmp_env)
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
|
|||||||
@ -29,9 +29,11 @@ module SharedEnvExtension
|
|||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
# @private
|
# @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
|
@formula = formula
|
||||||
@args = args
|
@cc = cc
|
||||||
|
@build_bottle = build_bottle
|
||||||
|
@bottle_arch = bottle_arch
|
||||||
reset
|
reset
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -163,7 +165,7 @@ module SharedEnvExtension
|
|||||||
# ENV.append_to_cflags "-I ./missing/includes"
|
# ENV.append_to_cflags "-I ./missing/includes"
|
||||||
# end</pre>
|
# end</pre>
|
||||||
def compiler
|
def compiler
|
||||||
@compiler ||= if (cc = @args.cc)
|
@compiler ||= if (cc = @cc)
|
||||||
warn_about_non_apple_gcc($&) if cc =~ GNU_GCC_REGEXP
|
warn_about_non_apple_gcc($&) if cc =~ GNU_GCC_REGEXP
|
||||||
fetch_compiler(cc, "--cc")
|
fetch_compiler(cc, "--cc")
|
||||||
elsif (cc = homebrew_cc)
|
elsif (cc = homebrew_cc)
|
||||||
@ -255,8 +257,8 @@ module SharedEnvExtension
|
|||||||
|
|
||||||
# @private
|
# @private
|
||||||
def effective_arch
|
def effective_arch
|
||||||
if @args&.build_bottle? && @args&.bottle_arch
|
if @build_bottle && @bottle_arch
|
||||||
@args.bottle_arch.to_sym
|
@bottle_arch.to_sym
|
||||||
else
|
else
|
||||||
Hardware.oldest_cpu
|
Hardware.oldest_cpu
|
||||||
end
|
end
|
||||||
|
|||||||
@ -11,8 +11,8 @@ module Stdenv
|
|||||||
SAFE_CFLAGS_FLAGS = "-w -pipe"
|
SAFE_CFLAGS_FLAGS = "-w -pipe"
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
def setup_build_environment(formula = nil, args: nil)
|
def setup_build_environment(**options)
|
||||||
super
|
super(**options)
|
||||||
|
|
||||||
self["HOMEBREW_ENV"] = "std"
|
self["HOMEBREW_ENV"] = "std"
|
||||||
|
|
||||||
|
|||||||
@ -36,8 +36,8 @@ module Superenv
|
|||||||
end
|
end
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
def setup_build_environment(formula = nil, args: nil)
|
def setup_build_environment(**options)
|
||||||
super
|
super(**options)
|
||||||
send(compiler)
|
send(compiler)
|
||||||
|
|
||||||
self["HOMEBREW_ENV"] = "super"
|
self["HOMEBREW_ENV"] = "super"
|
||||||
@ -64,7 +64,7 @@ module Superenv
|
|||||||
self["HOMEBREW_INCLUDE_PATHS"] = determine_include_paths
|
self["HOMEBREW_INCLUDE_PATHS"] = determine_include_paths
|
||||||
self["HOMEBREW_LIBRARY_PATHS"] = determine_library_paths
|
self["HOMEBREW_LIBRARY_PATHS"] = determine_library_paths
|
||||||
self["HOMEBREW_DEPENDENCIES"] = determine_dependencies
|
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
|
# 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
|
# compiler flag stripping. It consists of a string of characters which act
|
||||||
|
|||||||
@ -1,17 +1,18 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Stdenv
|
module Stdenv
|
||||||
def setup_build_environment(formula = nil, args: nil)
|
def setup_build_environment(**options)
|
||||||
generic_setup_build_environment(formula, args: args)
|
generic_setup_build_environment(**options)
|
||||||
|
|
||||||
prepend_path "CPATH", HOMEBREW_PREFIX/"include"
|
prepend_path "CPATH", HOMEBREW_PREFIX/"include"
|
||||||
prepend_path "LIBRARY_PATH", HOMEBREW_PREFIX/"lib"
|
prepend_path "LIBRARY_PATH", HOMEBREW_PREFIX/"lib"
|
||||||
prepend_path "LD_RUN_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 "CPATH", formula.include
|
||||||
prepend_path "LIBRARY_PATH", formula.lib
|
prepend_path "LIBRARY_PATH", @formula.lib
|
||||||
prepend_path "LD_RUN_PATH", formula.lib
|
prepend_path "LD_RUN_PATH", @formula.lib
|
||||||
end
|
end
|
||||||
|
|
||||||
def libxml2
|
def libxml2
|
||||||
|
|||||||
@ -7,11 +7,11 @@ module Superenv
|
|||||||
end
|
end
|
||||||
|
|
||||||
# @private
|
# @private
|
||||||
def setup_build_environment(formula = nil, args: nil)
|
def setup_build_environment(**options)
|
||||||
generic_setup_build_environment(formula, args: args)
|
generic_setup_build_environment(**options)
|
||||||
self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O2"
|
self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O2"
|
||||||
self["HOMEBREW_DYNAMIC_LINKER"] = determine_dynamic_linker_path
|
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
|
end
|
||||||
|
|
||||||
def homebrew_extra_paths
|
def homebrew_extra_paths
|
||||||
@ -27,7 +27,7 @@ module Superenv
|
|||||||
|
|
||||||
def determine_rpath_paths(formula)
|
def determine_rpath_paths(formula)
|
||||||
PATH.new(
|
PATH.new(
|
||||||
formula&.lib,
|
*formula&.lib,
|
||||||
"#{HOMEBREW_PREFIX}/lib",
|
"#{HOMEBREW_PREFIX}/lib",
|
||||||
PATH.new(run_time_deps.map { |dep| dep.opt_lib.to_s }).existing,
|
PATH.new(run_time_deps.map { |dep| dep.opt_lib.to_s }).existing,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -32,8 +32,8 @@ module Stdenv
|
|||||||
append "CFLAGS", "-I#{MacOS::X11.include}" unless MacOS::CLT.installed?
|
append "CFLAGS", "-I#{MacOS::X11.include}" unless MacOS::CLT.installed?
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup_build_environment(formula = nil, args: nil)
|
def setup_build_environment(**options)
|
||||||
generic_setup_build_environment(formula, args: args)
|
generic_setup_build_environment(**options)
|
||||||
|
|
||||||
# sed is strict, and errors out when it encounters files with
|
# sed is strict, and errors out when it encounters files with
|
||||||
# mixed character sets
|
# mixed character sets
|
||||||
@ -41,7 +41,7 @@ module Stdenv
|
|||||||
self["LC_CTYPE"] = "C"
|
self["LC_CTYPE"] = "C"
|
||||||
|
|
||||||
# Add lib and include etc. from the current macosxsdk to compiler flags:
|
# Add lib and include etc. from the current macosxsdk to compiler flags:
|
||||||
macosxsdk(formula: formula)
|
macosxsdk(formula: @formula)
|
||||||
|
|
||||||
return unless MacOS::Xcode.without_clt?
|
return unless MacOS::Xcode.without_clt?
|
||||||
|
|
||||||
|
|||||||
@ -106,7 +106,8 @@ module Superenv
|
|||||||
end
|
end
|
||||||
|
|
||||||
# @private
|
# @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
|
sdk = formula ? MacOS.sdk_for_formula(formula) : MacOS.sdk
|
||||||
if MacOS.sdk_root_needed? || sdk&.source == :xcode
|
if MacOS.sdk_root_needed? || sdk&.source == :xcode
|
||||||
self["HOMEBREW_SDKROOT"] = sdk.path
|
self["HOMEBREW_SDKROOT"] = sdk.path
|
||||||
@ -119,7 +120,7 @@ module Superenv
|
|||||||
self["HOMEBREW_SDKROOT"] = nil
|
self["HOMEBREW_SDKROOT"] = nil
|
||||||
self["HOMEBREW_DEVELOPER_DIR"] = nil
|
self["HOMEBREW_DEVELOPER_DIR"] = nil
|
||||||
end
|
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
|
# Filter out symbols known not to be defined since GNU Autotools can't
|
||||||
# reliably figure this out with Xcode 8 and above.
|
# reliably figure this out with Xcode 8 and above.
|
||||||
|
|||||||
@ -186,7 +186,11 @@ class Requirement
|
|||||||
@satisfied
|
@satisfied
|
||||||
elsif @options[:build_env]
|
elsif @options[:build_env]
|
||||||
require "extend/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
|
else
|
||||||
yield @proc
|
yield @proc
|
||||||
end
|
end
|
||||||
|
|||||||
@ -28,7 +28,7 @@ begin
|
|||||||
formula.extend(Debrew::Formula) if Homebrew.args.debug?
|
formula.extend(Debrew::Formula) if Homebrew.args.debug?
|
||||||
|
|
||||||
ENV.extend(Stdenv)
|
ENV.extend(Stdenv)
|
||||||
ENV.setup_build_environment(formula, args: args)
|
ENV.setup_build_environment(formula: formula)
|
||||||
|
|
||||||
# tests can also return false to indicate failure
|
# tests can also return false to indicate failure
|
||||||
Timeout.timeout TEST_TIMEOUT_SECONDS do
|
Timeout.timeout TEST_TIMEOUT_SECONDS do
|
||||||
|
|||||||
@ -15,12 +15,10 @@ shared_examples EnvActivation do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#with_build_environment" do
|
describe "#with_build_environment" do
|
||||||
let(:args) { Homebrew::CLI::Args.new }
|
|
||||||
|
|
||||||
it "restores the environment" do
|
it "restores the environment" do
|
||||||
before = subject.dup
|
before = subject.dup
|
||||||
|
|
||||||
subject.with_build_environment(args: args) do
|
subject.with_build_environment do
|
||||||
subject["foo"] = "bar"
|
subject["foo"] = "bar"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -32,7 +30,7 @@ shared_examples EnvActivation do
|
|||||||
before = subject.dup
|
before = subject.dup
|
||||||
|
|
||||||
expect {
|
expect {
|
||||||
subject.with_build_environment(args: args) do
|
subject.with_build_environment do
|
||||||
subject["foo"] = "bar"
|
subject["foo"] = "bar"
|
||||||
raise StandardError
|
raise StandardError
|
||||||
end
|
end
|
||||||
@ -43,13 +41,13 @@ shared_examples EnvActivation do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "returns the value of the block" do
|
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
|
end
|
||||||
|
|
||||||
it "does not mutate the interface" do
|
it "does not mutate the interface" do
|
||||||
expected = subject.methods
|
expected = subject.methods
|
||||||
|
|
||||||
subject.with_build_environment(args: args) do
|
subject.with_build_environment do
|
||||||
expect(subject.methods).to eq(expected)
|
expect(subject.methods).to eq(expected)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user