[clang] Infer compilation directory in driver
When building with -fdebug-compilation-dir/-fcoverige-compilation-dir, infer the compilation directory in clang driver, rather than try to fallback to VFS current working directory lookup during CodeGen. This allows compilation directory to be used as it is passed via cc1 flag and the value can be empty to remove dependency on CWD if needed. Reviewers: adrian-prantl, dwblaikie Reviewed By: adrian-prantl, dwblaikie Pull Request: https://github.com/llvm/llvm-project/pull/150112
This commit is contained in:
parent
91e0055c7c
commit
441f5b0e36
@ -226,17 +226,19 @@ static bool ShouldEnableAutolink(const ArgList &Args, const ToolChain &TC,
|
|||||||
static const char *addDebugCompDirArg(const ArgList &Args,
|
static const char *addDebugCompDirArg(const ArgList &Args,
|
||||||
ArgStringList &CmdArgs,
|
ArgStringList &CmdArgs,
|
||||||
const llvm::vfs::FileSystem &VFS) {
|
const llvm::vfs::FileSystem &VFS) {
|
||||||
|
std::string DebugCompDir;
|
||||||
if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
|
if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
|
||||||
options::OPT_fdebug_compilation_dir_EQ)) {
|
options::OPT_fdebug_compilation_dir_EQ))
|
||||||
if (A->getOption().matches(options::OPT_ffile_compilation_dir_EQ))
|
DebugCompDir = A->getValue();
|
||||||
CmdArgs.push_back(Args.MakeArgString(Twine("-fdebug-compilation-dir=") +
|
|
||||||
A->getValue()));
|
if (DebugCompDir.empty()) {
|
||||||
|
if (llvm::ErrorOr<std::string> CWD = VFS.getCurrentWorkingDirectory())
|
||||||
|
DebugCompDir = std::move(*CWD);
|
||||||
else
|
else
|
||||||
A->render(Args, CmdArgs);
|
return nullptr;
|
||||||
} else if (llvm::ErrorOr<std::string> CWD =
|
|
||||||
VFS.getCurrentWorkingDirectory()) {
|
|
||||||
CmdArgs.push_back(Args.MakeArgString("-fdebug-compilation-dir=" + *CWD));
|
|
||||||
}
|
}
|
||||||
|
CmdArgs.push_back(
|
||||||
|
Args.MakeArgString("-fdebug-compilation-dir=" + DebugCompDir));
|
||||||
StringRef Path(CmdArgs.back());
|
StringRef Path(CmdArgs.back());
|
||||||
return Path.substr(Path.find('=') + 1).data();
|
return Path.substr(Path.find('=') + 1).data();
|
||||||
}
|
}
|
||||||
@ -525,17 +527,17 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
|
|||||||
CmdArgs.push_back("-fcoverage-mcdc");
|
CmdArgs.push_back("-fcoverage-mcdc");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
StringRef CoverageCompDir;
|
||||||
if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
|
if (Arg *A = Args.getLastArg(options::OPT_ffile_compilation_dir_EQ,
|
||||||
options::OPT_fcoverage_compilation_dir_EQ)) {
|
options::OPT_fcoverage_compilation_dir_EQ))
|
||||||
if (A->getOption().matches(options::OPT_ffile_compilation_dir_EQ))
|
CoverageCompDir = A->getValue();
|
||||||
CmdArgs.push_back(Args.MakeArgString(
|
if (CoverageCompDir.empty()) {
|
||||||
Twine("-fcoverage-compilation-dir=") + A->getValue()));
|
if (auto CWD = D.getVFS().getCurrentWorkingDirectory())
|
||||||
else
|
CmdArgs.push_back(
|
||||||
A->render(Args, CmdArgs);
|
Args.MakeArgString(Twine("-fcoverage-compilation-dir=") + *CWD));
|
||||||
} else if (llvm::ErrorOr<std::string> CWD =
|
} else
|
||||||
D.getVFS().getCurrentWorkingDirectory()) {
|
CmdArgs.push_back(Args.MakeArgString(Twine("-fcoverage-compilation-dir=") +
|
||||||
CmdArgs.push_back(Args.MakeArgString("-fcoverage-compilation-dir=" + *CWD));
|
CoverageCompDir));
|
||||||
}
|
|
||||||
|
|
||||||
if (Args.hasArg(options::OPT_fprofile_exclude_files_EQ)) {
|
if (Args.hasArg(options::OPT_fprofile_exclude_files_EQ)) {
|
||||||
auto *Arg = Args.getLastArg(options::OPT_fprofile_exclude_files_EQ);
|
auto *Arg = Args.getLastArg(options::OPT_fprofile_exclude_files_EQ);
|
||||||
|
@ -8,3 +8,8 @@
|
|||||||
// RUN: %clang -### -integrated-as -ffile-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefixes=CHECK-DEBUG-COMPILATION-DIR %s
|
// RUN: %clang -### -integrated-as -ffile-compilation-dir=. -x assembler %s 2>&1 | FileCheck -check-prefixes=CHECK-DEBUG-COMPILATION-DIR %s
|
||||||
// CHECK-DEBUG-COMPILATION-DIR: "-fdebug-compilation-dir=."
|
// CHECK-DEBUG-COMPILATION-DIR: "-fdebug-compilation-dir=."
|
||||||
// CHECK-DEBUG-COMPILATION-DIR-NOT: "-ffile-compilation-dir=."
|
// CHECK-DEBUG-COMPILATION-DIR-NOT: "-ffile-compilation-dir=."
|
||||||
|
|
||||||
|
// RUN: %clang -### -S %s -working-directory %S 2>&1 | FileCheck -check-prefix=CHECK-CWD %s
|
||||||
|
// RUN: cd %S
|
||||||
|
// RUN: %clang -### -S %s 2>&1 | FileCheck -check-prefix=CHECK-CWD %s
|
||||||
|
// CHECK-CWD: -fdebug-compilation-dir={{.*}}Driver
|
||||||
|
Loading…
x
Reference in New Issue
Block a user