[clang][deps] Make resource directory deduction configurable
authorJan Svoboda <jan_svoboda@apple.com>
Thu, 21 Oct 2021 11:10:18 +0000 (13:10 +0200)
committerJan Svoboda <jan_svoboda@apple.com>
Thu, 21 Oct 2021 12:06:52 +0000 (14:06 +0200)
commitb8b14b682c339c9ab85360d24ba9b888d52fdfbb
treeb70a1844f1f1f613fe09db6d651a7ad21c18331a
parent6c88086ba8046884bb30a72ae1a8bea95e46f022
[clang][deps] Make resource directory deduction configurable

The `clang-scan-deps` CLI tool invokes the compiler with `-print-resource-dir` in case the `-resource-dir` argument is missing from the compilation command line. This is to enable running the tool on compilation databases that use compiler from a different toolchain than `clang-scan-deps` itself. While this doesn't make sense when scanning modular builds (due to the `-cc1` arguments the tool generates), the tool can can be used to efficiently scan for file dependencies of non-modular builds too.

This patch stops deducing the resource directory by invoking the compiler by default. This mode can still be enabled by invoking `clang-scan-deps` with `--resource-dir-recipe invoke-compiler`. The new default is `--resource-dir-recipe modify-compiler-path` which relies on the resource directory deduction taking place in `Driver::Driver` which is based on the compiler path. This makes the default more aligned with the intended usage of the tool while still allowing it to serve other use-cases.

Note that this functionality was also influenced by D108979, where the dependency scanner stopped going through `ClangTool::run`. The function tried to deduce the resource directory based on the current executable path, which might not be what the users expect when invoked from within a shared library.

Depends on D108979.

Reviewed By: dexonsmith

Differential Revision: https://reviews.llvm.org/D108366
clang/test/ClangScanDeps/Inputs/resource_directory/cdb.json.template [new file with mode: 0644]
clang/test/ClangScanDeps/Inputs/resource_directory/compiler [new file with mode: 0755]
clang/test/ClangScanDeps/Inputs/resource_directory/mod.h [new file with mode: 0644]
clang/test/ClangScanDeps/Inputs/resource_directory/module.modulemap [new file with mode: 0644]
clang/test/ClangScanDeps/Inputs/resource_directory/tu.c [new file with mode: 0644]
clang/test/ClangScanDeps/resource_directory.c [new file with mode: 0644]
clang/tools/clang-scan-deps/ClangScanDeps.cpp