diff --git a/Library/Homebrew/build.rb b/Library/Homebrew/build.rb index f448995e099c6763b8cef1c80ed3bb10df867337..ae725d66ed437cab70d382de8b85a9c9c1afbc0d 100644 --- a/Library/Homebrew/build.rb +++ b/Library/Homebrew/build.rb @@ -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) diff --git a/Library/Homebrew/cmd/--env.rb b/Library/Homebrew/cmd/--env.rb index ad97d80d1375eaf7b6ad5a31f639310d6f330b82..7586631754e7b89449a5906c43c77f6d1f166ba1 100644 --- a/Library/Homebrew/cmd/--env.rb +++ b/Library/Homebrew/cmd/--env.rb @@ -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 diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index d63d240a2901765ee9c733d9d56335a870a7ab4c..2b17297200b7c9dce16e94fc6badef3e29bd4c90 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -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 diff --git a/Library/Homebrew/dev-cmd/sh.rb b/Library/Homebrew/dev-cmd/sh.rb index e1f103ec6bb5fc0038b5978cf89ce92adfa66403..e44a617fcca1e39f1050d537d868b3c44921f772 100644 --- a/Library/Homebrew/dev-cmd/sh.rb +++ b/Library/Homebrew/dev-cmd/sh.rb @@ -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 diff --git a/Library/Homebrew/extend/ENV.rb b/Library/Homebrew/extend/ENV.rb index f35099a448ea6fc248b751e032c0162ae6b11f69..29f57569940a7fd3ec2b987d14bd2062e272f70e 100644 --- a/Library/Homebrew/extend/ENV.rb +++ b/Library/Homebrew/extend/ENV.rb @@ -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 diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb index b3bae473d4bbbe7deb5ba84e7e8235e101061f3a..a4ed78a7803a3261dbd8a51f24f617c7c89b7dec 100644 --- a/Library/Homebrew/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/ENV/shared.rb @@ -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 diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index 60231146351a8614c95193808a85552c351c5c03..70e76567373951b6a5faf458cfc960062f3da1d8 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -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" diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 3fc3be8f3b33f5d77009d875b915aadd42099383..ba3015a62fabd302b998a7c77bd0f1080db6752c 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -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 diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/std.rb b/Library/Homebrew/extend/os/linux/extend/ENV/std.rb index ecaafb74a9ced42780097abae8ceb38aad1c2465..585065052e5ca601ef608fbc5b2c0b3d68b93ed1 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/std.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/std.rb @@ -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 diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb index 45a92d6a39306c1d35d72e287f5535bf3706e1e9..965d7a2ce5a85471cdc190ef37e0142367404788 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb @@ -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, ) diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb index b59af01949e41b5cfd723e81351b24a121aba2d7..a83d9f33021ef6a6c2d415370fc0feee9c4d8d16 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/std.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/std.rb @@ -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? diff --git a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb index 424d76c26f0cd2310afad1259725173f573c0bcf..f704e7dd1350ff79b4b29d4905017dcdf0ff29fd 100644 --- a/Library/Homebrew/extend/os/mac/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/mac/extend/ENV/super.rb @@ -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. diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index 0c42c3721aeb71b2463c18d46c04c9328c3faf36..1458370103d3cd8fd9460941587b739727c8c637 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -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 diff --git a/Library/Homebrew/test.rb b/Library/Homebrew/test.rb index 8f91b983e0564aa81e128ea1f071f72135be923f..233c3233836269713570093df4e6ed2e1201a768 100644 --- a/Library/Homebrew/test.rb +++ b/Library/Homebrew/test.rb @@ -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 diff --git a/Library/Homebrew/test/ENV_spec.rb b/Library/Homebrew/test/ENV_spec.rb index 11e6df4196343d950ea5798c4b43174faeef0ffb..9a91960363e295289291531d64205ab9666af355 100644 --- a/Library/Homebrew/test/ENV_spec.rb +++ b/Library/Homebrew/test/ENV_spec.rb @@ -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