[clang] [clang][deps] Add `-o` flag to specify output path (PR #88767)

Ben Langmuir via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 15 11:03:10 PDT 2024


================
@@ -864,8 +873,24 @@ int clang_scan_deps_main(int argc, char **argv, const llvm::ToolContext &) {
       });
 
   SharedStream Errs(llvm::errs());
-  // Print out the dependency results to STDOUT by default.
-  SharedStream DependencyOS(llvm::outs());
+
+  std::optional<llvm::raw_fd_ostream> FileOS;
+  llvm::raw_ostream &ThreadUnsafeDependencyOS = [&]() -> llvm::raw_ostream & {
+    if (OutputFileName == "-")
+      return llvm::outs();
+
+    if (OutputFileName == "/dev/null")
+      return llvm::nulls();
+
+    std::error_code EC;
+    FileOS.emplace(OutputFileName, EC);
+    if (EC) {
+      llvm::errs() << llvm::errorCodeToError(EC) << '\n';
----------------
benlangmuir wrote:

Would be good to include the fact it's failing during open and what the path is in this error.  Filesystem errrors can be hard to understand without any context

https://github.com/llvm/llvm-project/pull/88767


More information about the cfe-commits mailing list