mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
build_environment: add proper types to dump() and fix inreplace error
This commit is contained in:
parent
4a623e0a25
commit
2de6958a36
@ -55,22 +55,23 @@ class BuildEnvironment
|
||||
].freeze
|
||||
private_constant :KEYS
|
||||
|
||||
sig { params(env: T.untyped).returns(T::Array[String]) }
|
||||
sig { params(env: T::Hash[String, T.nilable(T.any(String, Pathname))]).returns(T::Array[String]) }
|
||||
def self.keys(env)
|
||||
KEYS & env.keys
|
||||
end
|
||||
|
||||
sig { params(env: T.untyped, f: IO).void }
|
||||
sig { params(env: T::Hash[String, T.nilable(T.any(String, Pathname))], f: IO).void }
|
||||
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|
|
||||
value = env.fetch(key)
|
||||
|
||||
s = +"#{key}: #{value}"
|
||||
case key
|
||||
when "CC", "CXX", "LD"
|
||||
s << " => #{Pathname.new(value).realpath}" if File.symlink?(value)
|
||||
s << " => #{Pathname.new(value).realpath}" if value.present? && File.symlink?(value)
|
||||
end
|
||||
s.freeze
|
||||
f.puts s
|
||||
|
@ -51,7 +51,7 @@ module Homebrew
|
||||
if shell.nil?
|
||||
BuildEnvironment.dump ENV
|
||||
else
|
||||
BuildEnvironment.keys(ENV).each do |key|
|
||||
BuildEnvironment.keys(ENV.to_h).each do |key|
|
||||
puts Utils::Shell.export_value(key, ENV.fetch(key), shell)
|
||||
end
|
||||
end
|
||||
|
@ -466,9 +466,19 @@ end
|
||||
|
||||
# Raised when an error occurs during a formula build.
|
||||
class BuildError < RuntimeError
|
||||
extend T::Sig
|
||||
|
||||
attr_reader :cmd, :args, :env
|
||||
attr_accessor :formula, :options
|
||||
|
||||
sig {
|
||||
params(
|
||||
formula: T.nilable(Formula),
|
||||
cmd: T.any(String, Pathname),
|
||||
args: T::Array[T.any(String, Pathname, Integer)],
|
||||
env: T::Hash[String, T.untyped],
|
||||
).void
|
||||
}
|
||||
def initialize(formula, cmd, args, env)
|
||||
@formula = formula
|
||||
@cmd = cmd
|
||||
@ -478,10 +488,12 @@ class BuildError < RuntimeError
|
||||
super "Failed executing: #{cmd} #{pretty_args}".strip
|
||||
end
|
||||
|
||||
sig { returns(T::Array[T.untyped]) }
|
||||
def issues
|
||||
@issues ||= fetch_issues
|
||||
end
|
||||
|
||||
sig { returns(T::Array[T.untyped]) }
|
||||
def fetch_issues
|
||||
GitHub.issues_for_formula(formula.name, tap: formula.tap, state: "open")
|
||||
rescue GitHub::API::RateLimitExceededError => e
|
||||
@ -489,6 +501,7 @@ class BuildError < RuntimeError
|
||||
[]
|
||||
end
|
||||
|
||||
sig { params(verbose: T::Boolean).void }
|
||||
def dump(verbose: false)
|
||||
puts
|
||||
|
||||
|
@ -2219,7 +2219,7 @@ class Formula
|
||||
def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter
|
||||
super(paths, before, after, audit_result)
|
||||
rescue Utils::Inreplace::Error
|
||||
raise BuildError.new(self, "inreplace", paths, nil)
|
||||
raise BuildError.new(self, "inreplace", paths, {})
|
||||
end
|
||||
|
||||
protected
|
||||
|
Loading…
x
Reference in New Issue
Block a user