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
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# Settings for the build environment.
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
class BuildEnvironment
|
class BuildEnvironment
|
||||||
def initialize(*settings)
|
def initialize(*settings)
|
||||||
@settings = Set.new(*settings)
|
@settings = Set.new(*settings)
|
||||||
@ -23,19 +26,15 @@ class BuildEnvironment
|
|||||||
@settings.include? :userpaths
|
@settings.include? :userpaths
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# DSL for specifying build environment settings.
|
||||||
module DSL
|
module DSL
|
||||||
def env(*settings)
|
def env(*settings)
|
||||||
@env ||= BuildEnvironment.new
|
@env ||= BuildEnvironment.new
|
||||||
@env.merge(settings)
|
@env.merge(settings)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
module Homebrew
|
KEYS = %w[
|
||||||
module_function
|
|
||||||
|
|
||||||
def build_env_keys(env)
|
|
||||||
%w[
|
|
||||||
CC CXX LD OBJC OBJCXX
|
CC CXX LD OBJC OBJCXX
|
||||||
HOMEBREW_CC HOMEBREW_CXX
|
HOMEBREW_CC HOMEBREW_CXX
|
||||||
CFLAGS CXXFLAGS CPPFLAGS LDFLAGS SDKROOT MAKEFLAGS
|
CFLAGS CXXFLAGS CPPFLAGS LDFLAGS SDKROOT MAKEFLAGS
|
||||||
@ -47,11 +46,15 @@ module Homebrew
|
|||||||
MAKE GIT CPP
|
MAKE GIT CPP
|
||||||
ACLOCAL_PATH PATH CPATH
|
ACLOCAL_PATH PATH CPATH
|
||||||
LD_LIBRARY_PATH LD_RUN_PATH LD_PRELOAD LIBRARY_PATH
|
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
|
end
|
||||||
|
|
||||||
def dump_build_env(env, f = $stdout)
|
def self.dump(env, f = $stdout)
|
||||||
keys = build_env_keys(env)
|
keys = self.keys(env)
|
||||||
keys -= %w[CC CXX OBJC OBJCXX] if env["CC"] == env["HOMEBREW_CC"]
|
keys -= %w[CC CXX OBJC OBJCXX] if env["CC"] == env["HOMEBREW_CC"]
|
||||||
|
|
||||||
keys.each do |key|
|
keys.each do |key|
|
||||||
|
@ -43,9 +43,9 @@ module Homebrew
|
|||||||
Utils::Shell.from_path(args.shell)
|
Utils::Shell.from_path(args.shell)
|
||||||
end
|
end
|
||||||
|
|
||||||
env_keys = build_env_keys(ENV)
|
env_keys = BuildEnvironment.keys(ENV)
|
||||||
if shell.nil?
|
if shell.nil?
|
||||||
dump_build_env ENV
|
BuildEnvironment.dump ENV
|
||||||
else
|
else
|
||||||
env_keys.each do |key|
|
env_keys.each do |key|
|
||||||
puts Utils::Shell.export_value(key, ENV[key], shell)
|
puts Utils::Shell.export_value(key, ENV[key], shell)
|
||||||
|
@ -369,7 +369,7 @@ class BuildError < RuntimeError
|
|||||||
ohai "Configuration"
|
ohai "Configuration"
|
||||||
SystemConfig.dump_verbose_config
|
SystemConfig.dump_verbose_config
|
||||||
ohai "ENV"
|
ohai "ENV"
|
||||||
Homebrew.dump_build_env(env)
|
BuildEnvironment.dump env
|
||||||
puts
|
puts
|
||||||
onoe "#{formula.full_name} #{formula.version} did not build"
|
onoe "#{formula.full_name} #{formula.version} did not build"
|
||||||
unless (logs = Dir["#{formula.logs}/*"]).empty?
|
unless (logs = Dir["#{formula.logs}/*"]).empty?
|
||||||
|
@ -2020,7 +2020,7 @@ class Formula
|
|||||||
|
|
||||||
SystemConfig.dump_verbose_config(log)
|
SystemConfig.dump_verbose_config(log)
|
||||||
log.puts
|
log.puts
|
||||||
Homebrew.dump_build_env(env, log)
|
BuildEnvironment.dump env, log
|
||||||
|
|
||||||
raise BuildError.new(self, cmd, args, env)
|
raise BuildError.new(self, cmd, args, env)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user