[clang][deps] Move invocation adjustments from `clang-scan-deps` to `DependencyScanni...
authorJan Svoboda <jan_svoboda@apple.com>
Mon, 14 Jun 2021 10:06:08 +0000 (12:06 +0200)
committerJan Svoboda <jan_svoboda@apple.com>
Mon, 14 Jun 2021 10:23:33 +0000 (12:23 +0200)
commitd8bab69ead22a10dc4cdb2e36f6ea6fdfe774e2e
treeb7f8f018cc83b2f7954bb24dab2df4c76f19e258
parent35fa3e60d1612dcc4f8e233b046423d948ca9a9b
[clang][deps] Move invocation adjustments from `clang-scan-deps` to `DependencyScanning` library

The `clang-scan-deps` tool has some logic that parses and modifies the original Clang command-line. The goal is to setup `DependencyOutputOptions` by injecting `-M -MT <target>` and prevent the creation of output files.

This patch moves the logic into the `DependencyScanning` library, and uses the parsed `CompilerInvocation` instead of the raw command-line. The code simpler and can be used from the C++ API as well.

The `-o /dev/null` arguments are not necessary, since the `DependencyScanning` library only runs a preprocessing action, so there's no way it'll produce an actual object file.

Related: The `-M` argument implies `-w`, which would appear on the command-line of modular dependencies even though it was not on the original TU command line (see D104036).

Some related tests were updated.

Reviewed By: arphaman

Differential Revision: https://reviews.llvm.org/D104030
clang/lib/Tooling/DependencyScanning/DependencyScanningWorker.cpp
clang/test/ClangScanDeps/modules-pch.c
clang/test/ClangScanDeps/modules.cpp
clang/test/ClangScanDeps/regular_cdb.cpp
clang/tools/clang-scan-deps/ClangScanDeps.cpp