[PATCH] D158496: [WIP][clang][modules] module build daemon initial commit

2023-08-30 Thread Connor Sughrue via Phabricator via cfe-commits
cpsughrue added a comment.

In D158496#4618653 , @dblaikie wrote:

> (probably worth linking to the RFC/etc 
> (https://discourse.llvm.org/t/rfc-modules-build-daemon-build-system-agnostic-support-for-explicitly-built-modules/71524/47)
>  from the patch description/commit message)

I agree




Comment at: clang/tools/driver/cc1_main.cpp:49
 #include 
+#include 
 

Can be removed


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158496/new/

https://reviews.llvm.org/D158496

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D158496: [WIP][clang][modules] module build daemon initial commit

2023-08-30 Thread Connor Sughrue via Phabricator via cfe-commits
cpsughrue updated this revision to Diff 554583.
cpsughrue added a comment.

Remove unnecessary header files


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158496/new/

https://reviews.llvm.org/D158496

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/include/clang/Tooling/ModuleBuildDaemon/Protocol.h
  clang/include/clang/Tooling/ModuleBuildDaemon/SocketMsgSupport.h
  clang/include/clang/Tooling/ModuleBuildDaemon/SocketSupport.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/ModuleBuildDaemon/CMakeLists.txt
  clang/lib/Tooling/ModuleBuildDaemon/Protocol.cpp
  clang/lib/Tooling/ModuleBuildDaemon/SocketMsgSupport.cpp
  clang/lib/Tooling/ModuleBuildDaemon/SocketSupport.cpp
  clang/test/Driver/unknown-arg.c
  clang/tools/driver/CMakeLists.txt
  clang/tools/driver/cc1_main.cpp
  clang/tools/driver/cc1modbuildd_main.cpp
  clang/tools/driver/driver.cpp

Index: clang/tools/driver/driver.cpp
===
--- clang/tools/driver/driver.cpp
+++ clang/tools/driver/driver.cpp
@@ -213,6 +213,9 @@
 extern int cc1gen_reproducer_main(ArrayRef Argv,
   const char *Argv0, void *MainAddr,
   const llvm::ToolContext &);
+#if LLVM_ON_UNIX
+extern int cc1modbuildd_main(ArrayRef Argv);
+#endif
 
 static void insertTargetAndModeArgs(const ParsedClangName ,
 SmallVectorImpl ,
@@ -369,9 +372,15 @@
   if (Tool == "-cc1gen-reproducer")
 return cc1gen_reproducer_main(ArrayRef(ArgV).slice(2), ArgV[0],
   GetExecutablePathVP, ToolContext);
-  // Reject unknown tools.
-  llvm::errs() << "error: unknown integrated tool '" << Tool << "'. "
-   << "Valid tools include '-cc1' and '-cc1as'.\n";
+#if LLVM_ON_UNIX
+  if (Tool == "-cc1modbuildd")
+return cc1modbuildd_main(ArrayRef(ArgV).slice(2));
+#endif
+
+  // Reject unknown tools
+  llvm::errs()
+  << "error: unknown integrated tool '" << Tool << "'. "
+  << "Valid tools include '-cc1', '-cc1as', and '-cc1gen-reproducer'.\n";
   return 1;
 }
 
Index: clang/tools/driver/cc1modbuildd_main.cpp
===
--- /dev/null
+++ clang/tools/driver/cc1modbuildd_main.cpp
@@ -0,0 +1,361 @@
+//===--- cc1modbuildd_main.cpp - Clang CC1 Module Build Daemon ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/DiagnosticCategories.h"
+#include "clang/Basic/DiagnosticFrontend.h"
+#include "clang/Frontend/TextDiagnosticBuffer.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
+#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
+#include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
+#include "clang/Tooling/ModuleBuildDaemon/Protocol.h"
+#include "clang/Tooling/ModuleBuildDaemon/SocketMsgSupport.h"
+#include "clang/Tooling/ModuleBuildDaemon/SocketSupport.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Config/llvm-config.h"
+#include "llvm/Support/ThreadPool.h"
+#include "llvm/Support/Threading.h"
+#include "llvm/Support/YAMLParser.h"
+#include "llvm/Support/YAMLTraits.h"
+
+// TODO: Make portable
+#if LLVM_ON_UNIX
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace llvm;
+using namespace clang;
+using namespace tooling::dependencies;
+
+namespace {
+class ModuleBuildDaemonServer {
+public:
+  SmallString<128> BasePath;
+  SmallString<128> SocketPath;
+  SmallString<128> PidPath;
+
+  ModuleBuildDaemonServer(SmallString<128> Path, ArrayRef Argv)
+  : BasePath(Path), SocketPath(Path),
+Diags(constructDiagnosticsEngine(Argv)) {
+llvm::sys::path::append(SocketPath, SOCKET_FILE_NAME);
+
+if (find(Argv, StringRef("-Rmodule-build-daemon")) != Argv.end())
+  Diags.setSeverityForGroup(diag::Flavor::Remark,
+diag::Group::ModuleBuildDaemon,
+diag::Severity::Remark);
+  }
+
+  ~ModuleBuildDaemonServer() { Shutdown(SIGTERM); }
+
+  int Fork();
+  int Launch();
+  int Listen();
+  static llvm::Error Service(int Client);
+
+  void Shutdown(int signal) {
+unlink(SocketPath.c_str());
+shutdown(ListenSocketFD, SHUT_RD);
+close(ListenSocketFD);
+exit(EXIT_SUCCESS);
+  }
+
+private:
+  // Initializes and returns DiagnosticsEngine
+  static DiagnosticsEngine
+ 

[PATCH] D158496: [WIP][clang][modules] module build daemon initial commit

2023-08-30 Thread Connor Sughrue via Phabricator via cfe-commits
cpsughrue updated this revision to Diff 554582.
cpsughrue edited the summary of this revision.
cpsughrue added a comment.

Addressed feedback:

- Renamed ub_outs() to unbuff_outs()
- Fixed spelling errors
- Added daemon response to handshake request from clang invocation
- Replaced 10 sec sleep with backoff strategy when checking if the daemon has 
finished initializing
- In daemon response to REGISTER, added updated cc1 command line, which 
replaces the clang invocation argv


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158496/new/

https://reviews.llvm.org/D158496

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Basic/DiagnosticGroups.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/include/clang/Tooling/ModuleBuildDaemon/Protocol.h
  clang/include/clang/Tooling/ModuleBuildDaemon/SocketMsgSupport.h
  clang/include/clang/Tooling/ModuleBuildDaemon/SocketSupport.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/ModuleBuildDaemon/CMakeLists.txt
  clang/lib/Tooling/ModuleBuildDaemon/Protocol.cpp
  clang/lib/Tooling/ModuleBuildDaemon/SocketMsgSupport.cpp
  clang/lib/Tooling/ModuleBuildDaemon/SocketSupport.cpp
  clang/test/Driver/unknown-arg.c
  clang/tools/driver/CMakeLists.txt
  clang/tools/driver/cc1_main.cpp
  clang/tools/driver/cc1modbuildd_main.cpp
  clang/tools/driver/driver.cpp

Index: clang/tools/driver/driver.cpp
===
--- clang/tools/driver/driver.cpp
+++ clang/tools/driver/driver.cpp
@@ -213,6 +213,9 @@
 extern int cc1gen_reproducer_main(ArrayRef Argv,
   const char *Argv0, void *MainAddr,
   const llvm::ToolContext &);
+#if LLVM_ON_UNIX
+extern int cc1modbuildd_main(ArrayRef Argv);
+#endif
 
 static void insertTargetAndModeArgs(const ParsedClangName ,
 SmallVectorImpl ,
@@ -369,9 +372,15 @@
   if (Tool == "-cc1gen-reproducer")
 return cc1gen_reproducer_main(ArrayRef(ArgV).slice(2), ArgV[0],
   GetExecutablePathVP, ToolContext);
-  // Reject unknown tools.
-  llvm::errs() << "error: unknown integrated tool '" << Tool << "'. "
-   << "Valid tools include '-cc1' and '-cc1as'.\n";
+#if LLVM_ON_UNIX
+  if (Tool == "-cc1modbuildd")
+return cc1modbuildd_main(ArrayRef(ArgV).slice(2));
+#endif
+
+  // Reject unknown tools
+  llvm::errs()
+  << "error: unknown integrated tool '" << Tool << "'. "
+  << "Valid tools include '-cc1', '-cc1as', and '-cc1gen-reproducer'.\n";
   return 1;
 }
 
Index: clang/tools/driver/cc1modbuildd_main.cpp
===
--- /dev/null
+++ clang/tools/driver/cc1modbuildd_main.cpp
@@ -0,0 +1,361 @@
+//===--- cc1modbuildd_main.cpp - Clang CC1 Module Build Daemon ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Basic/DiagnosticCategories.h"
+#include "clang/Basic/DiagnosticFrontend.h"
+#include "clang/Frontend/TextDiagnosticBuffer.h"
+#include "clang/Frontend/TextDiagnosticPrinter.h"
+#include "clang/Tooling/DependencyScanning/DependencyScanningService.h"
+#include "clang/Tooling/DependencyScanning/DependencyScanningTool.h"
+#include "clang/Tooling/DependencyScanning/ModuleDepCollector.h"
+#include "clang/Tooling/ModuleBuildDaemon/Protocol.h"
+#include "clang/Tooling/ModuleBuildDaemon/SocketMsgSupport.h"
+#include "clang/Tooling/ModuleBuildDaemon/SocketSupport.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Config/llvm-config.h"
+#include "llvm/Support/ThreadPool.h"
+#include "llvm/Support/Threading.h"
+#include "llvm/Support/YAMLParser.h"
+#include "llvm/Support/YAMLTraits.h"
+
+// TODO: Make portable
+#if LLVM_ON_UNIX
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace llvm;
+using namespace clang;
+using namespace tooling::dependencies;
+
+namespace {
+class ModuleBuildDaemonServer {
+public:
+  SmallString<128> BasePath;
+  SmallString<128> SocketPath;
+  SmallString<128> PidPath;
+
+  ModuleBuildDaemonServer(SmallString<128> Path, ArrayRef Argv)
+  : BasePath(Path), SocketPath(Path),
+Diags(constructDiagnosticsEngine(Argv)) {
+llvm::sys::path::append(SocketPath, SOCKET_FILE_NAME);
+
+if (find(Argv, StringRef("-Rmodule-build-daemon")) != Argv.end())
+  Diags.setSeverityForGroup(diag::Flavor::Remark,
+diag::Group::ModuleBuildDaemon,
+diag::Severity::Remark);
+  }
+
+  

[PATCH] D158496: [WIP][clang][modules] module build daemon initial commit

2023-08-22 Thread Connor Sughrue via Phabricator via cfe-commits
cpsughrue created this revision.
cpsughrue added reviewers: jansvoboda11, Bigcheese.
Herald added a project: All.
cpsughrue requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Initial commit for module build daemon. The title will be updated soon to 
remove the [WIP] tag once I am done writing tests.

The goal of the commit: A source file that doesn't depend on any modules can 
connect to the daemon, get scanned, find that there are no modules, then resume 
building. If there are any modules in the dependency graph have the daemon emit 
a warning that dependencies were detected but that the daemon cannot yet build 
modules or update the cc1 command line.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158496

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Frontend/FrontendOptions.h
  clang/include/clang/Tooling/ModuleBuildDaemon/Protocol.h
  clang/include/clang/Tooling/ModuleBuildDaemon/SocketSupport.h
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Tooling/CMakeLists.txt
  clang/lib/Tooling/ModuleBuildDaemon/CMakeLists.txt
  clang/lib/Tooling/ModuleBuildDaemon/Protocol.cpp
  clang/lib/Tooling/ModuleBuildDaemon/SocketSupport.cpp
  clang/tools/driver/CMakeLists.txt
  clang/tools/driver/cc1_main.cpp
  clang/tools/driver/cc1modbuildd_main.cpp
  clang/tools/driver/driver.cpp

Index: clang/tools/driver/driver.cpp
===
--- clang/tools/driver/driver.cpp
+++ clang/tools/driver/driver.cpp
@@ -213,6 +213,9 @@
 extern int cc1gen_reproducer_main(ArrayRef Argv,
   const char *Argv0, void *MainAddr,
   const llvm::ToolContext &);
+#if LLVM_ON_UNIX
+extern int cc1modbuildd_main(ArrayRef Argv);
+#endif
 
 static void insertTargetAndModeArgs(const ParsedClangName ,
 SmallVectorImpl ,
@@ -369,9 +372,20 @@
   if (Tool == "-cc1gen-reproducer")
 return cc1gen_reproducer_main(ArrayRef(ArgV).slice(2), ArgV[0],
   GetExecutablePathVP, ToolContext);
-  // Reject unknown tools.
+#if LLVM_ON_UNIX
+  if (Tool == "-cc1modbuildd")
+return cc1modbuildd_main(ArrayRef(ArgV).slice(2));
+
+  // FIXME: Once cc1modbuildd becomes portable unify llvm::errs messages
   llvm::errs() << "error: unknown integrated tool '" << Tool << "'. "
-   << "Valid tools include '-cc1' and '-cc1as'.\n";
+   << "Valid tools include '-cc1', '-cc1as', '-cc1gen-reproducer', "
+   << "and '-cc1modbuildd'.\n";
+#else
+  // Reject unknown tools
+  llvm::errs()
+  << "error: unknown integrated tool '" << Tool << "'. "
+  << "Valid tools include '-cc1', '-cc1as', and '-cc1gen-reproducer'.\n";
+#endif
   return 1;
 }
 
Index: clang/tools/driver/cc1modbuildd_main.cpp
===
--- /dev/null
+++ clang/tools/driver/cc1modbuildd_main.cpp
@@ -0,0 +1,265 @@
+//===--- cc1modbuildd_main.cpp - Clang CC1 Module Build Daemon ===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/Tooling/ModuleBuildDaemon/Protocol.h"
+#include "clang/Tooling/ModuleBuildDaemon/SocketSupport.h"
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Config/llvm-config.h"
+#include "llvm/Support/ThreadPool.h"
+#include "llvm/Support/Threading.h"
+#include "llvm/Support/YAMLParser.h"
+#include "llvm/Support/YAMLTraits.h"
+
+// TODO: Make portable
+#if LLVM_ON_UNIX
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+using namespace llvm;
+using namespace clang;
+
+namespace {
+class ModuleBuildDaemonServer {
+public:
+  SmallString<128> BasePath;
+  SmallString<128> SocketPath;
+  SmallString<128> PidPath;
+
+  ModuleBuildDaemonServer(SmallString<128> Path)
+  : BasePath(Path), SocketPath(Path) {
+llvm::sys::path::append(SocketPath, SOCKET_FILE_NAME);
+  }
+
+  ~ModuleBuildDaemonServer() { Shutdown(SIGTERM); }
+
+  int Fork();
+  int Launch();
+  int Listen();
+  static llvm::Error Service(int Client);
+
+  void Shutdown(int signal) {
+unlink(SocketPath.c_str());
+shutdown(ListenSocketFD, SHUT_RD);
+close(ListenSocketFD);
+exit(EXIT_SUCCESS);
+  }
+
+private:
+  pid_t Pid = -1;
+  int ListenSocketFD = -1;
+};
+
+// Required to handle SIGTERM by calling Shutdown
+ModuleBuildDaemonServer *DaemonPtr = nullptr;
+void HandleSignal(int signal) {
+  if (DaemonPtr != nullptr) {
+DaemonPtr->Shutdown(signal);
+  }
+}
+} // namespace
+
+// Forks and detaches process, creating module build daemon
+int 

[PATCH] D156234: [clang][deps] add support for dependency scanning with cc1 command line

2023-08-03 Thread Connor Sughrue via Phabricator via cfe-commits
cpsughrue updated this revision to Diff 546861.
cpsughrue added a comment.

Fixing failed test on Windows CI


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156234/new/

https://reviews.llvm.org/D156234

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/test/ClangScanDeps/modules-cc1.cpp

Index: clang/test/ClangScanDeps/modules-cc1.cpp
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-cc1.cpp
@@ -0,0 +1,29 @@
+// Check that clang-scan-deps works with cc1 command lines
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+
+//--- modules_cc1.cpp
+#include "header.h"
+
+//--- header.h
+
+//--- module.modulemap
+module header1 { header "header.h" }
+
+//--- cdb.json.template
+[{
+  "file": "DIR/modules_cc1.cpp",
+  "directory": "DIR",
+  "command": "clang -cc1 DIR/modules_cc1.cpp -fimplicit-module-maps -o modules_cc1.o"
+}]
+
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -j 1 -mode preprocess-dependency-directives > %t/result
+// RUN: cat %t/result | sed 's:\?:/:g' | FileCheck %s -DPREFIX=%/t
+
+// CHECK: modules_cc1.o:
+// CHECK-NEXT: [[PREFIX]]/modules_cc1.cpp
+// CHECK-NEXT: [[PREFIX]]/module.modulemap
+// CHECK-NEXT: [[PREFIX]]/header.h
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -385,6 +385,9 @@
   if (!Compilation)
 return false;
 
+  if (Compilation->containsError())
+return false;
+
   for (const driver::Command  : Compilation->getJobs()) {
 if (!Callback(Job))
   return false;
@@ -392,6 +395,26 @@
   return true;
 }
 
+static bool createAndRunToolInvocation(
+std::vector CommandLine, DependencyScanningAction ,
+FileManager ,
+std::shared_ptr ,
+DiagnosticsEngine , DependencyConsumer ) {
+
+  // Save executable path before providing CommandLine to ToolInvocation
+  std::string Executable = CommandLine[0];
+  ToolInvocation Invocation(std::move(CommandLine), , ,
+PCHContainerOps);
+  Invocation.setDiagnosticConsumer(Diags.getClient());
+  Invocation.setDiagnosticOptions(());
+  if (!Invocation.run())
+return false;
+
+  std::vector Args = Action.takeLastCC1Arguments();
+  Consumer.handleBuildCommand({std::move(Executable), std::move(Args)});
+  return true;
+}
+
 bool DependencyScanningWorker::computeDependencies(
 StringRef WorkingDirectory, const std::vector ,
 DependencyConsumer , DependencyActionController ,
@@ -454,37 +477,37 @@
   DependencyScanningAction Action(WorkingDirectory, Consumer, Controller, DepFS,
   Format, OptimizeArgs, EagerLoadModules,
   DisableFree, ModuleName);
-  bool Success = forEachDriverJob(
-  FinalCommandLine, *Diags, *FileMgr, [&](const driver::Command ) {
-if (StringRef(Cmd.getCreator().getName()) != "clang") {
-  // Non-clang command. Just pass through to the dependency
-  // consumer.
-  Consumer.handleBuildCommand(
-  {Cmd.getExecutable(),
-   {Cmd.getArguments().begin(), Cmd.getArguments().end()}});
-  return true;
-}
-
-std::vector Argv;
-Argv.push_back(Cmd.getExecutable());
-Argv.insert(Argv.end(), Cmd.getArguments().begin(),
-Cmd.getArguments().end());
-
-// Create an invocation that uses the underlying file
-// system to ensure that any file system requests that
-// are made by the driver do not go through the
-// dependency scanning filesystem.
-ToolInvocation Invocation(std::move(Argv), , &*FileMgr,
-  PCHContainerOps);
-Invocation.setDiagnosticConsumer(Diags->getClient());
-Invocation.setDiagnosticOptions(>getDiagnosticOptions());
-if (!Invocation.run())
-  return false;
-
-std::vector Args = Action.takeLastCC1Arguments();
-Consumer.handleBuildCommand({Cmd.getExecutable(), std::move(Args)});
-return true;
-  });
+
+  bool Success = false;
+  if (FinalCommandLine[1] == "-cc1") {
+Success = createAndRunToolInvocation(FinalCommandLine, Action, *FileMgr,
+ PCHContainerOps, *Diags, Consumer);
+  } else {
+Success = forEachDriverJob(
+FinalCommandLine, *Diags, *FileMgr, [&](const driver::Command ) {
+  if (StringRef(Cmd.getCreator().getName()) != "clang") {
+// Non-clang command. Just pass through to the dependency
+// consumer.
+Consumer.handleBuildCommand(
+{Cmd.getExecutable(),
+ {Cmd.getArguments().begin(), 

[PATCH] D156234: [clang][deps] add support for dependency scanning with cc1 command line

2023-08-01 Thread Connor Sughrue via Phabricator via cfe-commits
cpsughrue updated this revision to Diff 546182.
cpsughrue added a comment.

Update llvm-lit test to use split-file


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156234/new/

https://reviews.llvm.org/D156234

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/test/ClangScanDeps/modules-cc1.cpp

Index: clang/test/ClangScanDeps/modules-cc1.cpp
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-cc1.cpp
@@ -0,0 +1,29 @@
+// Check that clang-scan-deps works with cc1 command lines
+
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+
+
+//--- modules_cc1.cpp
+#include "header.h"
+
+//--- header.h
+
+//--- module.modulemap
+module header1 { header "header.h" }
+
+//--- cdb.json.template
+[{
+  "file": "DIR/modules_cc1.cpp",
+  "directory": "DIR",
+  "command": "clang -cc1 DIR/modules_cc1.cpp -fimplicit-module-maps -o modules_cc1.o"
+}]
+
+// RUN: sed "s|DIR|%/t|g" %t/cdb.json.template > %t/cdb.json
+// RUN: clang-scan-deps -compilation-database %t/cdb.json -j 1 -mode preprocess-dependency-directives | \
+// RUN:   FileCheck %s -DPREFIX=%t
+
+// CHECK: modules_cc1.o:
+// CHECK-NEXT: [[PREFIX]]/modules_cc1.cpp
+// CHECK-NEXT: [[PREFIX]]/module.modulemap
+// CHECK-NEXT: [[PREFIX]]/header.h
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -385,6 +385,9 @@
   if (!Compilation)
 return false;
 
+  if (Compilation->containsError())
+return false;
+
   for (const driver::Command  : Compilation->getJobs()) {
 if (!Callback(Job))
   return false;
@@ -392,6 +395,26 @@
   return true;
 }
 
+static bool createAndRunToolInvocation(
+std::vector CommandLine, DependencyScanningAction ,
+FileManager ,
+std::shared_ptr ,
+DiagnosticsEngine , DependencyConsumer ) {
+
+  // Save executable path before providing CommandLine to ToolInvocation
+  std::string Executable = CommandLine[0];
+  ToolInvocation Invocation(std::move(CommandLine), , ,
+PCHContainerOps);
+  Invocation.setDiagnosticConsumer(Diags.getClient());
+  Invocation.setDiagnosticOptions(());
+  if (!Invocation.run())
+return false;
+
+  std::vector Args = Action.takeLastCC1Arguments();
+  Consumer.handleBuildCommand({std::move(Executable), std::move(Args)});
+  return true;
+}
+
 bool DependencyScanningWorker::computeDependencies(
 StringRef WorkingDirectory, const std::vector ,
 DependencyConsumer , DependencyActionController ,
@@ -454,37 +477,37 @@
   DependencyScanningAction Action(WorkingDirectory, Consumer, Controller, DepFS,
   Format, OptimizeArgs, EagerLoadModules,
   DisableFree, ModuleName);
-  bool Success = forEachDriverJob(
-  FinalCommandLine, *Diags, *FileMgr, [&](const driver::Command ) {
-if (StringRef(Cmd.getCreator().getName()) != "clang") {
-  // Non-clang command. Just pass through to the dependency
-  // consumer.
-  Consumer.handleBuildCommand(
-  {Cmd.getExecutable(),
-   {Cmd.getArguments().begin(), Cmd.getArguments().end()}});
-  return true;
-}
-
-std::vector Argv;
-Argv.push_back(Cmd.getExecutable());
-Argv.insert(Argv.end(), Cmd.getArguments().begin(),
-Cmd.getArguments().end());
-
-// Create an invocation that uses the underlying file
-// system to ensure that any file system requests that
-// are made by the driver do not go through the
-// dependency scanning filesystem.
-ToolInvocation Invocation(std::move(Argv), , &*FileMgr,
-  PCHContainerOps);
-Invocation.setDiagnosticConsumer(Diags->getClient());
-Invocation.setDiagnosticOptions(>getDiagnosticOptions());
-if (!Invocation.run())
-  return false;
-
-std::vector Args = Action.takeLastCC1Arguments();
-Consumer.handleBuildCommand({Cmd.getExecutable(), std::move(Args)});
-return true;
-  });
+
+  bool Success = false;
+  if (FinalCommandLine[1] == "-cc1") {
+Success = createAndRunToolInvocation(FinalCommandLine, Action, *FileMgr,
+ PCHContainerOps, *Diags, Consumer);
+  } else {
+Success = forEachDriverJob(
+FinalCommandLine, *Diags, *FileMgr, [&](const driver::Command ) {
+  if (StringRef(Cmd.getCreator().getName()) != "clang") {
+// Non-clang command. Just pass through to the dependency
+// consumer.
+Consumer.handleBuildCommand(
+{Cmd.getExecutable(),
+ {Cmd.getArguments().begin(), Cmd.getArguments().end()}});
+return true;
+ 

[PATCH] D156234: [clang][deps] add support for dependency scanning with cc1 command line

2023-08-01 Thread Connor Sughrue via Phabricator via cfe-commits
cpsughrue added inline comments.



Comment at: 
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp:482
+  bool Success = false;
+  if (FinalCommandLine[1] == "-cc1") {
+Success = createAndRunToolInvocation(FinalCommandLine, Action, *FileMgr,

Bigcheese wrote:
> jansvoboda11 wrote:
> > cpsughrue wrote:
> > > Is there a good way to validate cc1 command lines?
> > I think that happens in `ToolInvocation::run()` that's called by 
> > `createAndRunToolInvocation`. Are you seeing cases where we don't emit a 
> > diagnostic for an invalid `-cc1` command line?
> Not really, you just have to parse it. Was there a particular reason you 
> wanted to validate here?
@jansvoboda11 You're right, `ToolInvocation::run()` fails if there are any 
issues when the function creates the compiler invocation - I missed that. I've 
not seen any cases where diagnostics aren't outputted.



Comment at: 
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp:482
+  bool Success = false;
+  if (FinalCommandLine[1] == "-cc1") {
+Success = createAndRunToolInvocation(FinalCommandLine, Action, *FileMgr,

cpsughrue wrote:
> Bigcheese wrote:
> > jansvoboda11 wrote:
> > > cpsughrue wrote:
> > > > Is there a good way to validate cc1 command lines?
> > > I think that happens in `ToolInvocation::run()` that's called by 
> > > `createAndRunToolInvocation`. Are you seeing cases where we don't emit a 
> > > diagnostic for an invalid `-cc1` command line?
> > Not really, you just have to parse it. Was there a particular reason you 
> > wanted to validate here?
> @jansvoboda11 You're right, `ToolInvocation::run()` fails if there are any 
> issues when the function creates the compiler invocation - I missed that. 
> I've not seen any cases where diagnostics aren't outputted.
@Bigcheese No, I just wanted to make sure some sort of validation was happening 
and missed the work being done in `ToolInvocation::run()`.



Comment at: clang/test/ClangScanDeps/Inputs/modules_cc1_cdb.json:1
+[
+{

jansvoboda11 wrote:
> I assume this was cargo-culted from 
> `clang/test/ClangScanDeps/Inputs/modules_cdb.json`. I don't think we need 
> multiple entries here and lots of the flags are unnecessary for just testing 
> out `-cc1` command lines work. I suggest having just one minimal `-cc1` 
> command line here.
That is an accurate assumption. Are you good with the following command line 
`clang -cc1 DIR/modules_cdb_input.cpp -IInputs -fimplicit-module-maps -o 
modules_cdb_input.o`?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156234/new/

https://reviews.llvm.org/D156234

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156234: [clang][deps] add support for dependency scanning with cc1 command line

2023-08-01 Thread Connor Sughrue via Phabricator via cfe-commits
cpsughrue added inline comments.



Comment at: 
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp:482
+  bool Success = false;
+  if (FinalCommandLine[1] == "-cc1") {
+Success = createAndRunToolInvocation(FinalCommandLine, Action, *FileMgr,

Is there a good way to validate cc1 command lines?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156234/new/

https://reviews.llvm.org/D156234

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D156234: [clang][deps] add support for dependency scanning with cc1 command line

2023-07-31 Thread Connor Sughrue via Phabricator via cfe-commits
cpsughrue updated this revision to Diff 545910.
cpsughrue retitled this revision from "[clang][deps] provide support for cc1 
command line scanning" to "[clang][deps] add support for dependency scanning 
with cc1 command line".
cpsughrue edited the summary of this revision.
cpsughrue added a comment.

Added llvm-lit test for commit and removed previously created unit test


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156234/new/

https://reviews.llvm.org/D156234

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/test/ClangScanDeps/Inputs/modules_cc1_cdb.json
  clang/test/ClangScanDeps/modules-cc1.cpp

Index: clang/test/ClangScanDeps/modules-cc1.cpp
===
--- /dev/null
+++ clang/test/ClangScanDeps/modules-cc1.cpp
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t.dir
+// RUN: rm -rf %t.cdb
+// RUN: rm -rf %t_clangcl.cdb
+// RUN: rm -rf %t.module-cache
+// RUN: rm -rf %t.module-cache_clangcl
+// RUN: mkdir -p %t.dir
+// RUN: cp %s %t.dir/modules_cdb_input.cpp
+// RUN: cp %s %t.dir/modules_cdb_input2.cpp
+// RUN: mkdir %t.dir/Inputs
+// RUN: cp %S/Inputs/header.h %t.dir/Inputs/header.h
+// RUN: cp %S/Inputs/header2.h %t.dir/Inputs/header2.h
+// RUN: cp %S/Inputs/module.modulemap %t.dir/Inputs/module.modulemap
+// RUN: sed -e "s|DIR|%/t.dir|g" %S/Inputs/modules_cc1_cdb.json > %t.cdb
+//
+// RUN: clang-scan-deps -compilation-database %t.cdb -j 1 -mode preprocess-dependency-directives | \
+// RUN:   FileCheck --check-prefixes=CHECK1,CHECK2,CHECK2NO %s
+//
+// The output order is non-deterministic when using more than one thread,
+// so check the output using two runs. Note that the 'NOT' check is not used
+// as it might fail if the results for `modules_cdb_input.cpp` are reported before
+// `modules_cdb_input2.cpp`.
+//
+// RUN: clang-scan-deps -compilation-database %t.cdb -j 2 -mode preprocess-dependency-directives | \
+// RUN:   FileCheck --check-prefix=CHECK1 %s
+// RUN: clang-scan-deps -compilation-database %t.cdb -j 2 -mode preprocess | \
+// RUN:   FileCheck --check-prefix=CHECK1 %s
+// RUN: clang-scan-deps -compilation-database %t.cdb -j 2 -mode preprocess-dependency-directives | \
+// RUN:   FileCheck --check-prefix=CHECK2 %s
+// RUN: clang-scan-deps -compilation-database %t.cdb -j 2 -mode preprocess | \
+// RUN:   FileCheck --check-prefix=CHECK2 %s
+
+#include "header.h"
+
+// CHECK1: modules_cdb_input2.o:
+// CHECK1-NEXT: modules_cdb_input2.cpp
+// CHECK1-NEXT: Inputs{{/|\\}}module.modulemap
+// CHECK1-NEXT: Inputs{{/|\\}}header2.h
+// CHECK1: Inputs{{/|\\}}header.h
+
+// CHECK2: {{(modules_cdb_input)|(a)|(b)}}.o:
+// CHECK2-NEXT: modules_cdb_input.cpp
+// CHECK2-NEXT: Inputs{{/|\\}}module.modulemap
+// CHECK2-NEXT: Inputs{{/|\\}}header.h
+// CHECK2NO-NOT: header2
\ No newline at end of file
Index: clang/test/ClangScanDeps/Inputs/modules_cc1_cdb.json
===
--- /dev/null
+++ clang/test/ClangScanDeps/Inputs/modules_cc1_cdb.json
@@ -0,0 +1,22 @@
+[
+{
+  "directory": "DIR",
+  "command": "clang -cc1 -E DIR/modules_cdb_input2.cpp -IInputs -D INCLUDE_HEADER2 -fmodules -MT modules_cdb_input2.o -dependency-file DIR/modules_cdb2.d -fmodules-cache-path=DIR/module-cache -fcoverage-compilation-dir=DIR -fimplicit-module-maps -fmodules-validate-system-headers",
+  "file": "DIR/modules_cdb_input2.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang -cc1 -E DIR/modules_cdb_input.cpp -IInputs -fmodules -fmodules-cache-path=DIR/module-cache -fcoverage-compilation-dir=DIR -fdebug-compilation-dir=DIR -fimplicit-module-maps -fmodules-validate-system-headers",
+  "file": "DIR/modules_cdb_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang -cc1 -E DIR/modules_cdb_input.cpp -IInputs -fmodules -fmodules-cache-path=DIR/module-cache -fcoverage-compilation-dir=DIR -fdebug-compilation-dir=DIR -fimplicit-module-maps -fmodules-validate-system-headers -o a.o",
+  "file": "DIR/modules_cdb_input.cpp"
+},
+{
+  "directory": "DIR",
+  "command": "clang -cc1 -E DIR/modules_cdb_input.cpp -IInputs -fmodules -fmodules-cache-path=DIR/module-cache -fcoverage-compilation-dir=DIR -fdebug-compilation-dir=DIR -fimplicit-module-maps -fmodules-validate-system-headers -o b.o",
+  "file": "DIR/modules_cdb_input.cpp"
+}
+]
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -385,6 +385,9 @@
   if (!Compilation)
 return false;
 
+  if (Compilation->containsError())
+return false;
+
   for (const driver::Command  : Compilation->getJobs()) {
 if (!Callback(Job))
   return false;
@@ -392,6 +395,26 @@
   return true;
 }
 
+static bool createAndRunToolInvocation(
+std::vector CommandLine, DependencyScanningAction ,
+FileManager ,
+

[PATCH] D156234: [clang][deps] provide support for cc1 command line scanning

2023-07-25 Thread Connor Sughrue via Phabricator via cfe-commits
cpsughrue updated this revision to Diff 544127.
cpsughrue edited the summary of this revision.
cpsughrue added a comment.

Fixed formatting issues


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156234/new/

https://reviews.llvm.org/D156234

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/unittests/Tooling/DependencyScannerTest.cpp

Index: clang/unittests/Tooling/DependencyScannerTest.cpp
===
--- clang/unittests/Tooling/DependencyScannerTest.cpp
+++ clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -240,6 +240,36 @@
 "test.cpp.o: /root/test.cpp /root/header.h\n");
 }
 
+TEST(DependencyScanner, ScanDepsWithCC1) {
+  std::vector CommandLine = {
+  "clang","-cc1", "-triple",   "x86_64-apple-macosx10.7", "-x", "c++",
+  "test.cpp", "-o",   "test.cpp.o"};
+  StringRef CWD = "/root";
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->setCurrentWorkingDirectory(CWD);
+  auto Sept = llvm::sys::path::get_separator();
+  std::string HeaderPath =
+  std::string(llvm::formatv("{0}root{0}header.h", Sept));
+  std::string TestPath = std::string(llvm::formatv("{0}root{0}test.cpp", Sept));
+
+  VFS->addFile(HeaderPath, 0, llvm::MemoryBuffer::getMemBuffer("\n"));
+  VFS->addFile(TestPath, 0,
+   llvm::MemoryBuffer::getMemBuffer("#include \"header.h\"\n"));
+
+  DependencyScanningService Service(ScanningMode::DependencyDirectivesScan,
+ScanningOutputFormat::Make);
+  DependencyScanningTool ScanTool(Service, VFS);
+
+  std::string DepFile;
+  ASSERT_THAT_ERROR(
+  ScanTool.getDependencyFile(CommandLine, CWD).moveInto(DepFile),
+  llvm::Succeeded());
+  using llvm::sys::path::convert_to_slash;
+  EXPECT_EQ(convert_to_slash(DepFile),
+"test.cpp.o: /root/test.cpp /root/header.h\n");
+}
+
 TEST(DependencyScanner, ScanDepsWithModuleLookup) {
   std::vector CommandLine = {
   "clang",
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -385,6 +385,9 @@
   if (!Compilation)
 return false;
 
+  if (Compilation->containsError())
+return false;
+
   for (const driver::Command  : Compilation->getJobs()) {
 if (!Callback(Job))
   return false;
@@ -392,6 +395,26 @@
   return true;
 }
 
+static bool createAndRunToolInvocation(
+std::vector CommandLine, DependencyScanningAction ,
+FileManager ,
+std::shared_ptr ,
+DiagnosticsEngine , DependencyConsumer ) {
+
+  // Save executable path before providing CommandLine to ToolInvocation
+  std::string Executable = CommandLine[0];
+  ToolInvocation Invocation(std::move(CommandLine), , ,
+PCHContainerOps);
+  Invocation.setDiagnosticConsumer(Diags.getClient());
+  Invocation.setDiagnosticOptions(());
+  if (!Invocation.run())
+return false;
+
+  std::vector Args = Action.takeLastCC1Arguments();
+  Consumer.handleBuildCommand({Executable, std::move(Args)});
+  return true;
+}
+
 bool DependencyScanningWorker::computeDependencies(
 StringRef WorkingDirectory, const std::vector ,
 DependencyConsumer , DependencyActionController ,
@@ -454,37 +477,37 @@
   DependencyScanningAction Action(WorkingDirectory, Consumer, Controller, DepFS,
   Format, OptimizeArgs, EagerLoadModules,
   DisableFree, ModuleName);
-  bool Success = forEachDriverJob(
-  FinalCommandLine, *Diags, *FileMgr, [&](const driver::Command ) {
-if (StringRef(Cmd.getCreator().getName()) != "clang") {
-  // Non-clang command. Just pass through to the dependency
-  // consumer.
-  Consumer.handleBuildCommand(
-  {Cmd.getExecutable(),
-   {Cmd.getArguments().begin(), Cmd.getArguments().end()}});
-  return true;
-}
-
-std::vector Argv;
-Argv.push_back(Cmd.getExecutable());
-Argv.insert(Argv.end(), Cmd.getArguments().begin(),
-Cmd.getArguments().end());
-
-// Create an invocation that uses the underlying file
-// system to ensure that any file system requests that
-// are made by the driver do not go through the
-// dependency scanning filesystem.
-ToolInvocation Invocation(std::move(Argv), , &*FileMgr,
-  PCHContainerOps);
-Invocation.setDiagnosticConsumer(Diags->getClient());
-Invocation.setDiagnosticOptions(>getDiagnosticOptions());
-if (!Invocation.run())
-  return false;
-
-std::vector Args = Action.takeLastCC1Arguments();
-Consumer.handleBuildCommand({Cmd.getExecutable(), std::move(Args)});
-return true;
-  });
+

[PATCH] D156234: [clang][deps] provide support for cc1 command line scanning

2023-07-25 Thread Connor Sughrue via Phabricator via cfe-commits
cpsughrue created this revision.
cpsughrue added reviewers: Bigcheese, jansvoboda11.
Herald added a project: All.
cpsughrue requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Allow users to run a dependency scan with a cc1 command line in addition to a 
driver command line. The scan was being carried out with a cc1 command line, 
but `DependencyScanningWorker::computeDependencies` assumed that the user 
always provided a driver command line. Now 
`DependencyScanningWorker::computeDependencies` can handle the case where the 
user provides a cc1 command line.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D156234

Files:
  clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
  clang/unittests/Tooling/DependencyScannerTest.cpp

Index: clang/unittests/Tooling/DependencyScannerTest.cpp
===
--- clang/unittests/Tooling/DependencyScannerTest.cpp
+++ clang/unittests/Tooling/DependencyScannerTest.cpp
@@ -240,6 +240,42 @@
 "test.cpp.o: /root/test.cpp /root/header.h\n");
 }
 
+TEST(DependencyScanner, ScanDepsWithCC1) {
+  std::vector CommandLine = {"clang",
+  "-cc1", 
+  "-triple",   
+  "x86_64-apple-macosx10.7", 
+  "-x", 
+  "c++",
+  "test.cpp", 
+  "-o",   
+  "test.cpp.o"};
+  StringRef CWD = "/root";
+
+  auto VFS = new llvm::vfs::InMemoryFileSystem();
+  VFS->setCurrentWorkingDirectory(CWD);
+  auto Sept = llvm::sys::path::get_separator();
+  std::string HeaderPath =
+  std::string(llvm::formatv("{0}root{0}header.h", Sept));
+  std::string TestPath = std::string(llvm::formatv("{0}root{0}test.cpp", Sept));
+
+  VFS->addFile(HeaderPath, 0, llvm::MemoryBuffer::getMemBuffer("\n"));
+  VFS->addFile(TestPath, 0,
+   llvm::MemoryBuffer::getMemBuffer("#include \"header.h\"\n"));
+
+  DependencyScanningService Service(ScanningMode::DependencyDirectivesScan,
+ScanningOutputFormat::Make);
+  DependencyScanningTool ScanTool(Service, VFS);
+
+  std::string DepFile;
+  ASSERT_THAT_ERROR(
+  ScanTool.getDependencyFile(CommandLine, CWD).moveInto(DepFile),
+  llvm::Succeeded());
+  using llvm::sys::path::convert_to_slash;
+  EXPECT_EQ(convert_to_slash(DepFile),
+"test.cpp.o: /root/test.cpp /root/header.h\n");
+}
+
 TEST(DependencyScanner, ScanDepsWithModuleLookup) {
   std::vector CommandLine = {
   "clang",
Index: clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
===
--- clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
+++ clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
@@ -385,6 +385,9 @@
   if (!Compilation)
 return false;
 
+  if (Compilation->containsError())
+return false;
+
   for (const driver::Command  : Compilation->getJobs()) {
 if (!Callback(Job))
   return false;
@@ -392,6 +395,26 @@
   return true;
 }
 
+static bool createAndRunToolInvocation(
+std::vector CommandLine, DependencyScanningAction ,
+FileManager ,
+std::shared_ptr ,
+DiagnosticsEngine , DependencyConsumer ) {
+
+  // Save executable path before providing CommandLine to ToolInvocation
+  std::string Executable = CommandLine[0];
+  ToolInvocation Invocation(std::move(CommandLine), , ,
+PCHContainerOps);
+  Invocation.setDiagnosticConsumer(Diags.getClient());
+  Invocation.setDiagnosticOptions(());
+  if (!Invocation.run())
+return false;
+
+  std::vector Args = Action.takeLastCC1Arguments();
+  Consumer.handleBuildCommand({Executable, std::move(Args)});
+  return true;
+}
+
 bool DependencyScanningWorker::computeDependencies(
 StringRef WorkingDirectory, const std::vector ,
 DependencyConsumer , DependencyActionController ,
@@ -454,37 +477,37 @@
   DependencyScanningAction Action(WorkingDirectory, Consumer, Controller, DepFS,
   Format, OptimizeArgs, EagerLoadModules,
   DisableFree, ModuleName);
-  bool Success = forEachDriverJob(
-  FinalCommandLine, *Diags, *FileMgr, [&](const driver::Command ) {
-if (StringRef(Cmd.getCreator().getName()) != "clang") {
-  // Non-clang command. Just pass through to the dependency
-  // consumer.
-  Consumer.handleBuildCommand(
-  {Cmd.getExecutable(),
-   {Cmd.getArguments().begin(), Cmd.getArguments().end()}});
-  return true;
-}
-
-std::vector Argv;
-Argv.push_back(Cmd.getExecutable());
-Argv.insert(Argv.end(),