mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Driver/Frontend] Add -print-target-triple
Add a -print-target-triple command line option to the Swift frontend and driver to allow other tools (e.g., SwiftPM) to query the host triple as it is understood by the Swift compiler. This follows the precedent set by Clang. Implements rdar://problem/57434967.
This commit is contained in:
@@ -2122,6 +2122,31 @@ bool Driver::handleImmediateArgs(const ArgList &Args, const ToolChain &TC) {
|
||||
std::end(commandArgs));
|
||||
}
|
||||
|
||||
if (Args.hasArg(options::OPT_print_target_triple)) {
|
||||
SmallVector<const char *, 5> commandLine;
|
||||
commandLine.push_back("-frontend");
|
||||
commandLine.push_back("-print-target-triple");
|
||||
if (const Arg *TargetArg = Args.getLastArg(options::OPT_target)) {
|
||||
commandLine.push_back("-target");
|
||||
commandLine.push_back(TargetArg->getValue());
|
||||
}
|
||||
|
||||
std::string executable = getSwiftProgramPath();
|
||||
|
||||
sys::TaskQueue queue;
|
||||
queue.addTask(executable.c_str(), commandLine);
|
||||
queue.execute(nullptr,
|
||||
[](sys::ProcessId PID, int returnCode,
|
||||
StringRef output, StringRef errors,
|
||||
sys::TaskProcessInformation ProcInfo,
|
||||
void *unused) -> sys::TaskFinishedResponse {
|
||||
llvm::outs() << output;
|
||||
llvm::errs() << errors;
|
||||
return sys::TaskFinishedResponse::ContinueExecution;
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user