Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the hmaptool support response file #2601

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tools/hmaptool/BinaryHeaderMapTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,23 @@ struct BinaryHeaderMapTool {
var arguments = arguments
var output: URL?

// If the first argument starts with @, treat it as a response file.
// Since this is an internal tool, it's safe to just check the first argument.
if let arg = arguments.first, arg.hasPrefix("@") {
// Remove @ prefix to get file path
let filePath = String(arg.dropFirst())

guard FileManager.default.fileExists(atPath: filePath) else {
fatalError("The response file doesn't exist: \(filePath)")
}

guard let fileContents = try? String(contentsOfFile: filePath, encoding: .utf8) else {
fatalError("The response file cannot be read: \(filePath)")
}

arguments = fileContents.components(separatedBy: .newlines)
}

if let outputIndex = arguments.firstIndex(of: "--output") {
guard outputIndex + 1 < arguments.count else {
fatalError("Missing output path after --output")
Expand Down