rm popen sigs

This commit is contained in:
Douglas Eichelberger 2023-03-30 17:14:04 -07:00
parent a20d28f343
commit 4f5fc770f6
10 changed files with 21 additions and 67 deletions

View File

@ -130,7 +130,7 @@ module Homebrew
new_tag = Utils.popen_read( new_tag = Utils.popen_read(
"git", "-C", HOMEBREW_REPOSITORY, "tag", "--list", "--sort=-version:refname", "*.*" "git", "-C", HOMEBREW_REPOSITORY, "tag", "--list", "--sort=-version:refname", "*.*"
).lines.fetch(0).chomp ).lines.first.chomp
Settings.write "latesttag", new_tag if new_tag != old_tag Settings.write "latesttag", new_tag if new_tag != old_tag
@ -286,8 +286,6 @@ module Homebrew
puts puts
new_major_version, new_minor_version, new_patch_version = new_tag.split(".").map(&:to_i) new_major_version, new_minor_version, new_patch_version = new_tag.split(".").map(&:to_i)
raise "Invalid new tag: #{new_tag}" if !new_major_version || !new_minor_version || !new_patch_version
old_major_version, old_minor_version = (old_tag.split(".")[0, 2]).map(&:to_i) if old_tag.present? old_major_version, old_minor_version = (old_tag.split(".")[0, 2]).map(&:to_i) if old_tag.present?
if old_tag.blank? || new_major_version > old_major_version \ if old_tag.blank? || new_major_version > old_major_version \
|| new_minor_version > old_minor_version || new_minor_version > old_minor_version

View File

@ -234,13 +234,13 @@ module Homebrew
"--reverse", "#{original_commit}..HEAD").lines.map(&:strip) "--reverse", "#{original_commit}..HEAD").lines.map(&:strip)
# Generate a bidirectional mapping of commits <=> formula/cask files. # Generate a bidirectional mapping of commits <=> formula/cask files.
files_to_commits = T.let({}, T::Hash[String, T::Array[String]]) files_to_commits = {}
commits_to_files = commits.to_h do |commit| commits_to_files = commits.to_h do |commit|
files = Utils.safe_popen_read("git", "-C", tap.path, "diff-tree", "--diff-filter=AMD", files = Utils.safe_popen_read("git", "-C", tap.path, "diff-tree", "--diff-filter=AMD",
"-r", "--name-only", "#{commit}^", commit).lines.map(&:strip) "-r", "--name-only", "#{commit}^", commit).lines.map(&:strip)
files.each do |file| files.each do |file|
files_to_commits[file] ||= [] files_to_commits[file] ||= []
files_to_commits.fetch(file) << commit files_to_commits[file] << commit
tap_file = tap.path/file tap_file = tap.path/file
if (tap_file.dirname == tap.formula_dir || tap_file.dirname == tap.cask_dir) && if (tap_file.dirname == tap.formula_dir || tap_file.dirname == tap.cask_dir) &&
File.extname(file) == ".rb" File.extname(file) == ".rb"
@ -266,14 +266,14 @@ module Homebrew
next if processed_commits.include? commit next if processed_commits.include? commit
files = commits_to_files[commit] files = commits_to_files[commit]
if files.length == 1 && files_to_commits.fetch(files.first).length == 1 if files.length == 1 && files_to_commits[files.first].length == 1
# If there's a 1:1 mapping of commits to files, just cherry pick and (maybe) reword. # If there's a 1:1 mapping of commits to files, just cherry pick and (maybe) reword.
reword_package_commit(commit, files.first, path: tap.path, reason: reason, verbose: verbose, resolve: resolve) reword_package_commit(commit, files.first, path: tap.path, reason: reason, verbose: verbose, resolve: resolve)
processed_commits << commit processed_commits << commit
elsif files.length == 1 && files_to_commits.fetch(files.first).length > 1 elsif files.length == 1 && files_to_commits[files.first].length > 1
# If multiple commits modify a single file, squash them down into a single commit. # If multiple commits modify a single file, squash them down into a single commit.
file = files.first file = files.first
commits = files_to_commits.fetch(file) commits = files_to_commits[file]
squash_package_commits(commits, file, path: tap.path, reason: reason, verbose: verbose, resolve: resolve) squash_package_commits(commits, file, path: tap.path, reason: reason, verbose: verbose, resolve: resolve)
processed_commits += commits processed_commits += commits
else else
@ -336,7 +336,7 @@ module Homebrew
rescue FormulaUnavailableError rescue FormulaUnavailableError
nil nil
end end
end end.compact
casks = Utils.popen_read("git", "-C", tap.path, "diff-tree", casks = Utils.popen_read("git", "-C", tap.path, "diff-tree",
"-r", "--name-only", "--diff-filter=AM", "-r", "--name-only", "--diff-filter=AM",
original_commit, "HEAD", "--", tap.cask_dir) original_commit, "HEAD", "--", tap.cask_dir)
@ -351,7 +351,7 @@ module Homebrew
nil nil
end end
end.compact end.compact
T.must(formulae).compact + casks formulae + casks
end end
def self.download_artifact(url, dir, pull_request) def self.download_artifact(url, dir, pull_request)

View File

@ -40,11 +40,8 @@ module Superenv
paths = [] paths = []
# Add paths for GCC headers when building against glibc@2.13 because we have to use -nostdinc. # Add paths for GCC headers when building against glibc@2.13 because we have to use -nostdinc.
if deps.any? { |d| d.name == "glibc@2.13" } if deps.any? { |d| d.name == "glibc@2.13" }
env_cc = cc gcc_include_dir = Utils.safe_popen_read(cc, "--print-file-name=include").chomp
raise "No CC compiler found in ENV" if env_cc.nil? gcc_include_fixed_dir = Utils.safe_popen_read(cc, "--print-file-name=include-fixed").chomp
gcc_include_dir = Utils.safe_popen_read(env_cc, "--print-file-name=include").chomp
gcc_include_fixed_dir = Utils.safe_popen_read(env_cc, "--print-file-name=include-fixed").chomp
paths << gcc_include_dir << gcc_include_fixed_dir paths << gcc_include_dir << gcc_include_fixed_dir
end end
paths paths

View File

@ -338,7 +338,7 @@ class Keg
# Some binaries contain strings with lists of files # Some binaries contain strings with lists of files
# e.g. `/usr/local/lib/foo:/usr/local/share/foo:/usr/lib/foo` # e.g. `/usr/local/lib/foo:/usr/local/share/foo:/usr/lib/foo`
# Each item in the list should be checked separately # Each item in the list should be checked separately
T.must(match).split(":").each do |sub_match| match.split(":").each do |sub_match|
# Not all items in the list may be matches # Not all items in the list may be matches
next unless sub_match.match? path_regex next unless sub_match.match? path_regex
next if linked_libraries.include? sub_match # Don't bother reporting a string if it was found by otool next if linked_libraries.include? sub_match # Don't bother reporting a string if it was found by otool

View File

@ -34,7 +34,7 @@ module Language
output = Utils.popen_read("npm", "pack", "--ignore-scripts") output = Utils.popen_read("npm", "pack", "--ignore-scripts")
raise "npm failed to pack #{Dir.pwd}" if !$CHILD_STATUS.exitstatus.zero? || output.lines.empty? raise "npm failed to pack #{Dir.pwd}" if !$CHILD_STATUS.exitstatus.zero? || output.lines.empty?
output.lines.fetch(-1).chomp output.lines.last.chomp
end end
def self.setup_npm_environment def self.setup_npm_environment

View File

@ -179,7 +179,7 @@ module Homebrew
return return
end end
commit_message = T.must(commit_message).reject(&:empty?).join("\n ") commit_message = commit_message.reject(&:empty?).join("\n ")
commit_message.sub!(/ \(#(\d+)\)$/, " (#{tap.issues_url}/\\1)") commit_message.sub!(/ \(#(\d+)\)$/, " (#{tap.issues_url}/\\1)")
commit_message.gsub!(/(Closes|Fixes) #(\d+)/, "\\1 #{tap.issues_url}/\\2") commit_message.gsub!(/(Closes|Fixes) #(\d+)/, "\\1 #{tap.issues_url}/\\2")

View File

@ -14,7 +14,7 @@ module OS
def os_version def os_version
if which("lsb_release") if which("lsb_release")
lsb_info = Utils.popen_read("lsb_release", "-a") lsb_info = Utils.popen_read("lsb_release", "-a")
description = T.must(lsb_info[/^Description:\s*(.*)$/, 1]).force_encoding("UTF-8") description = lsb_info[/^Description:\s*(.*)$/, 1].force_encoding("UTF-8")
codename = lsb_info[/^Codename:\s*(.*)$/, 1] codename = lsb_info[/^Codename:\s*(.*)$/, 1]
if codename.blank? || (codename == "n/a") if codename.blank? || (codename == "n/a")
description description

View File

@ -131,7 +131,7 @@ module ELFShim
return if needed.empty? return if needed.empty?
ldd = DevelopmentTools.locate "ldd" ldd = DevelopmentTools.locate "ldd"
ldd_output = Utils.popen_read(T.must(ldd), path.expand_path.to_s).split("\n") ldd_output = Utils.popen_read(ldd, path.expand_path.to_s).split("\n")
return unless $CHILD_STATUS.success? return unless $CHILD_STATUS.success?
ldd_paths = ldd_output.map do |line| ldd_paths = ldd_output.map do |line|

View File

@ -161,8 +161,7 @@ module OS
# Xcode.prefix is pretty smart, so let's look inside to find the sdk # Xcode.prefix is pretty smart, so let's look inside to find the sdk
sdk_prefix = "#{Xcode.prefix}/Platforms/MacOSX.platform/Developer/SDKs" sdk_prefix = "#{Xcode.prefix}/Platforms/MacOSX.platform/Developer/SDKs"
# Finally query Xcode itself (this is slow, so check it last) # Finally query Xcode itself (this is slow, so check it last)
sdk_platform_path = Utils.popen_read(T.must(DevelopmentTools.locate("xcrun")), sdk_platform_path = Utils.popen_read(DevelopmentTools.locate("xcrun"), "--show-sdk-platform-path").chomp
"--show-sdk-platform-path").chomp
sdk_prefix = File.join(sdk_platform_path, "Developer", "SDKs") unless File.directory? sdk_prefix sdk_prefix = File.join(sdk_platform_path, "Developer", "SDKs") unless File.directory? sdk_prefix
sdk_prefix sdk_prefix

View File

@ -1,20 +1,10 @@
# typed: strict # typed: true
# frozen_string_literal: true # frozen_string_literal: true
module Utils module Utils
extend T::Sig
IO_DEFAULT_BUFFER_SIZE = 4096 IO_DEFAULT_BUFFER_SIZE = 4096
private_constant :IO_DEFAULT_BUFFER_SIZE private_constant :IO_DEFAULT_BUFFER_SIZE
sig {
params(
args: T.any(Pathname, String, T::Hash[String, String]),
safe: T::Boolean,
options: T.untyped,
block: T.nilable(T.proc.params(io: IO).void),
).returns(T.nilable(String))
}
def self.popen_read(*args, safe: false, **options, &block) def self.popen_read(*args, safe: false, **options, &block)
output = popen(args, "rb", options, &block) output = popen(args, "rb", options, &block)
return output if !safe || $CHILD_STATUS.success? return output if !safe || $CHILD_STATUS.success?
@ -22,26 +12,11 @@ module Utils
raise ErrorDuringExecution.new(args, status: $CHILD_STATUS, output: [[:stdout, output]]) raise ErrorDuringExecution.new(args, status: $CHILD_STATUS, output: [[:stdout, output]])
end end
sig {
params(
args: T.any(Pathname, String, T::Hash[String, String]),
options: T.untyped,
block: T.nilable(T.proc.params(io: IO).void),
).returns(T.nilable(String))
}
def self.safe_popen_read(*args, **options, &block) def self.safe_popen_read(*args, **options, &block)
popen_read(*args, safe: true, **options, &block) popen_read(*args, safe: true, **options, &block)
end end
sig { def self.popen_write(*args, safe: false, **options)
params(
args: T.any(Pathname, String, T::Hash[String, String]),
safe: T::Boolean,
options: T.untyped,
_block: T.proc.params(io: IO).void,
).returns(T.nilable(String))
}
def self.popen_write(*args, safe: false, **options, &_block)
output = "" output = ""
popen(args, "w+b", options) do |pipe| popen(args, "w+b", options) do |pipe|
# Before we yield to the block, capture as much output as we can # Before we yield to the block, capture as much output as we can
@ -56,7 +31,7 @@ module Utils
pipe.wait_readable pipe.wait_readable
# Capture the rest of the output # Capture the rest of the output
output += T.must(pipe.read) output += pipe.read
output.freeze output.freeze
end end
return output if !safe || $CHILD_STATUS.success? return output if !safe || $CHILD_STATUS.success?
@ -64,29 +39,14 @@ module Utils
raise ErrorDuringExecution.new(args, status: $CHILD_STATUS, output: [[:stdout, output]]) raise ErrorDuringExecution.new(args, status: $CHILD_STATUS, output: [[:stdout, output]])
end end
sig {
params(
args: T.any(Pathname, String, T::Hash[String, String]),
options: T.untyped,
block: T.nilable(T.proc.params(io: IO).void),
).returns(T.nilable(String))
}
def self.safe_popen_write(*args, **options, &block) def self.safe_popen_write(*args, **options, &block)
popen_write(*args, safe: true, **options, &block) popen_write(*args, safe: true, **options, &block)
end end
sig { def self.popen(args, mode, options = {})
params(
args: T::Array[T.any(Pathname, String, T::Hash[String, String])],
mode: String,
options: T::Hash[Symbol, T.untyped],
block: T.nilable(T.proc.params(io: IO).void),
).returns(T.nilable(String))
}
def self.popen(args, mode, options = {}, &block)
IO.popen("-", mode) do |pipe| IO.popen("-", mode) do |pipe|
if pipe if pipe
return pipe.read unless block return pipe.read unless block_given?
yield pipe yield pipe
else else