mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Refactor and document BuildEnvironment
.
This commit is contained in:
parent
535e7dc836
commit
b5363025a6
@ -1,5 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Settings for the build environment.
|
||||
#
|
||||
# @api private
|
||||
class BuildEnvironment
|
||||
def initialize(*settings)
|
||||
@settings = Set.new(*settings)
|
||||
@ -23,19 +26,15 @@ class BuildEnvironment
|
||||
@settings.include? :userpaths
|
||||
end
|
||||
|
||||
# DSL for specifying build environment settings.
|
||||
module DSL
|
||||
def env(*settings)
|
||||
@env ||= BuildEnvironment.new
|
||||
@env.merge(settings)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
module Homebrew
|
||||
module_function
|
||||
|
||||
def build_env_keys(env)
|
||||
%w[
|
||||
KEYS = %w[
|
||||
CC CXX LD OBJC OBJCXX
|
||||
HOMEBREW_CC HOMEBREW_CXX
|
||||
CFLAGS CXXFLAGS CPPFLAGS LDFLAGS SDKROOT MAKEFLAGS
|
||||
@ -47,11 +46,15 @@ module Homebrew
|
||||
MAKE GIT CPP
|
||||
ACLOCAL_PATH PATH CPATH
|
||||
LD_LIBRARY_PATH LD_RUN_PATH LD_PRELOAD LIBRARY_PATH
|
||||
].select { |key| env.key?(key) }
|
||||
].freeze
|
||||
private_constant :KEYS
|
||||
|
||||
def self.keys(env)
|
||||
KEYS & env.keys
|
||||
end
|
||||
|
||||
def dump_build_env(env, f = $stdout)
|
||||
keys = build_env_keys(env)
|
||||
def self.dump(env, f = $stdout)
|
||||
keys = self.keys(env)
|
||||
keys -= %w[CC CXX OBJC OBJCXX] if env["CC"] == env["HOMEBREW_CC"]
|
||||
|
||||
keys.each do |key|
|
||||
|
@ -43,9 +43,9 @@ module Homebrew
|
||||
Utils::Shell.from_path(args.shell)
|
||||
end
|
||||
|
||||
env_keys = build_env_keys(ENV)
|
||||
env_keys = BuildEnvironment.keys(ENV)
|
||||
if shell.nil?
|
||||
dump_build_env ENV
|
||||
BuildEnvironment.dump ENV
|
||||
else
|
||||
env_keys.each do |key|
|
||||
puts Utils::Shell.export_value(key, ENV[key], shell)
|
||||
|
@ -369,7 +369,7 @@ class BuildError < RuntimeError
|
||||
ohai "Configuration"
|
||||
SystemConfig.dump_verbose_config
|
||||
ohai "ENV"
|
||||
Homebrew.dump_build_env(env)
|
||||
BuildEnvironment.dump env
|
||||
puts
|
||||
onoe "#{formula.full_name} #{formula.version} did not build"
|
||||
unless (logs = Dir["#{formula.logs}/*"]).empty?
|
||||
|
@ -2020,7 +2020,7 @@ class Formula
|
||||
|
||||
SystemConfig.dump_verbose_config(log)
|
||||
log.puts
|
||||
Homebrew.dump_build_env(env, log)
|
||||
BuildEnvironment.dump env, log
|
||||
|
||||
raise BuildError.new(self, cmd, args, env)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user