[clang-tools-extra] r365132 - [clangd] Query driver reads stderr and passes driver as first argument
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 4 04:34:23 PDT 2019
Author: kadircet
Date: Thu Jul 4 04:34:23 2019
New Revision: 365132
URL: http://llvm.org/viewvc/llvm-project?rev=365132&view=rev
Log:
[clangd] Query driver reads stderr and passes driver as first argument
Summary:
gcc invokes cc1 through a path deduced from argv[0] therefore it must
be correctly set.
Also it prints the search path to stderr not stdout, this also applies to clang.
Reviewers: sammccall
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D64196
Modified:
clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
clang-tools-extra/trunk/clangd/test/system-include-extractor.test
Modified: clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp?rev=365132&r1=365131&r2=365132&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/QueryDriverDatabase.cpp Thu Jul 4 04:34:23 2019
@@ -102,20 +102,19 @@ std::vector<std::string> extractSystemIn
return {};
}
- llvm::SmallString<128> OutputPath;
- auto EC = llvm::sys::fs::createTemporaryFile("system-includes", "clangd",
- OutputPath);
- if (EC) {
+ llvm::SmallString<128> StdErrPath;
+ if (auto EC = llvm::sys::fs::createTemporaryFile("system-includes", "clangd",
+ StdErrPath)) {
elog("System include extraction: failed to create temporary file with "
"error {0}",
EC.message());
return {};
}
auto CleanUp = llvm::make_scope_exit(
- [&OutputPath]() { llvm::sys::fs::remove(OutputPath); });
+ [&StdErrPath]() { llvm::sys::fs::remove(StdErrPath); });
llvm::Optional<llvm::StringRef> Redirects[] = {
- {""}, llvm::StringRef(OutputPath), {""}};
+ {""}, {""}, llvm::StringRef(StdErrPath)};
auto Type = driver::types::lookupTypeForExtension(Ext);
if (Type == driver::types::TY_INVALID) {
@@ -123,22 +122,21 @@ std::vector<std::string> extractSystemIn
return {};
}
// Should we also preserve flags like "-sysroot", "-nostdinc" ?
- const llvm::StringRef Args[] = {"-E", "-x", driver::types::getTypeName(Type),
- "-", "-v"};
+ const llvm::StringRef Args[] = {
+ Driver, "-E", "-x", driver::types::getTypeName(Type), "-", "-v"};
- int RC =
- llvm::sys::ExecuteAndWait(Driver, Args, /*Env=*/llvm::None, Redirects);
- if (RC) {
+ if (int RC = llvm::sys::ExecuteAndWait(Driver, Args, /*Env=*/llvm::None,
+ Redirects)) {
elog("System include extraction: driver execution failed with return code: "
"{0}",
llvm::to_string(RC));
return {};
}
- auto BufOrError = llvm::MemoryBuffer::getFile(OutputPath);
+ auto BufOrError = llvm::MemoryBuffer::getFile(StdErrPath);
if (!BufOrError) {
elog("System include extraction: failed to read {0} with error {1}",
- OutputPath, BufOrError.getError().message());
+ StdErrPath, BufOrError.getError().message());
return {};
}
Modified: clang-tools-extra/trunk/clangd/test/system-include-extractor.test
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/system-include-extractor.test?rev=365132&r1=365131&r2=365132&view=diff
==============================================================================
--- clang-tools-extra/trunk/clangd/test/system-include-extractor.test (original)
+++ clang-tools-extra/trunk/clangd/test/system-include-extractor.test Thu Jul 4 04:34:23 2019
@@ -3,11 +3,12 @@
# Generate a mock-driver that will print %temp_dir%/my/dir and
# %temp_dir%/my/dir2 as include search paths.
# RUN: echo '#!/bin/bash' >> %t.dir/my_driver.sh
-# RUN: echo 'echo line to ignore' >> %t.dir/my_driver.sh
-# RUN: echo 'echo \#include \<...\> search starts here:' >> %t.dir/my_driver.sh
-# RUN: echo 'echo %t.dir/my/dir/' >> %t.dir/my_driver.sh
-# RUN: echo 'echo %t.dir/my/dir2/' >> %t.dir/my_driver.sh
-# RUN: echo 'echo End of search list.' >> %t.dir/my_driver.sh
+# RUN: echo '[ "$0" = "%t.dir/my_driver.sh" ] || exit' >> %t.dir/my_driver.sh
+# RUN: echo 'echo line to ignore >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo \#include \<...\> search starts here: >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo %t.dir/my/dir/ >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo %t.dir/my/dir2/ >&2' >> %t.dir/my_driver.sh
+# RUN: echo 'echo End of search list. >&2' >> %t.dir/my_driver.sh
# RUN: chmod +x %t.dir/my_driver.sh
# Create header files my/dir/a.h and my/dir2/b.h
More information about the cfe-commits
mailing list