[PATCH] D79930: [clangd] Add buildPreamble to TestTU
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue May 26 07:34:10 PDT 2020
kadircet updated this revision to Diff 266202.
kadircet added a comment.
- Rebase
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79930/new/
https://reviews.llvm.org/D79930
Files:
clang-tools-extra/clangd/unittests/PreambleTests.cpp
clang-tools-extra/clangd/unittests/TestTU.cpp
clang-tools-extra/clangd/unittests/TestTU.h
Index: clang-tools-extra/clangd/unittests/TestTU.h
===================================================================
--- clang-tools-extra/clangd/unittests/TestTU.h
+++ clang-tools-extra/clangd/unittests/TestTU.h
@@ -68,6 +68,7 @@
// By default, build() will report Error diagnostics as GTest errors.
// Suppress this behavior by adding an 'error-ok' comment to the code.
ParsedAST build() const;
+ std::shared_ptr<const PreambleData> preamble() const;
ParseInputs inputs() const;
SymbolSlab headerSymbols() const;
RefSlab headerRefs() const;
Index: clang-tools-extra/clangd/unittests/TestTU.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/TestTU.cpp
+++ clang-tools-extra/clangd/unittests/TestTU.cpp
@@ -66,14 +66,24 @@
return Inputs;
}
+std::shared_ptr<const PreambleData> TestTU::preamble() const {
+ auto Inputs = inputs();
+ IgnoreDiagnostics Diags;
+ auto CI = buildCompilerInvocation(Inputs, Diags);
+ assert(CI && "Failed to build compilation invocation.");
+ return clang::clangd::buildPreamble(testPath(Filename), *CI, Inputs,
+ /*StoreInMemory=*/true,
+ /*PreambleCallback=*/nullptr);
+}
+
ParsedAST TestTU::build() const {
auto Inputs = inputs();
StoreDiags Diags;
auto CI = buildCompilerInvocation(Inputs, Diags);
assert(CI && "Failed to build compilation invocation.");
- auto Preamble =
- buildPreamble(testPath(Filename), *CI, Inputs,
- /*StoreInMemory=*/true, /*PreambleCallback=*/nullptr);
+ auto Preamble = clang::clangd::buildPreamble(testPath(Filename), *CI, Inputs,
+ /*StoreInMemory=*/true,
+ /*PreambleCallback=*/nullptr);
auto AST = ParsedAST::build(testPath(Filename), Inputs, std::move(CI),
Diags.take(), Preamble);
if (!AST.hasValue()) {
Index: clang-tools-extra/clangd/unittests/PreambleTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/PreambleTests.cpp
+++ clang-tools-extra/clangd/unittests/PreambleTests.cpp
@@ -36,35 +36,19 @@
return arg.first() == File && arg.second == D;
}
-std::shared_ptr<const PreambleData>
-createPreamble(llvm::StringRef Contents = "") {
- auto TU = TestTU::withCode(Contents);
- // ms-compatibility changes meaning of #import, make sure it is turned off.
- TU.ExtraArgs = {"-fno-ms-compatibility"};
- TU.Filename = "preamble.cpp";
- auto PI = TU.inputs();
- IgnoreDiagnostics Diags;
- auto CI = buildCompilerInvocation(PI, Diags);
- if (!CI) {
- ADD_FAILURE() << "failed to build compiler invocation";
- return nullptr;
- }
- if (auto Preamble = buildPreamble(TU.Filename, *CI, PI, true, nullptr))
- return Preamble;
- ADD_FAILURE() << "failed to build preamble";
- return nullptr;
-}
-
// Builds a preamble for BaselineContents, patches it for ModifiedContents and
// returns the includes in the patch.
IncludeStructure
collectPatchedIncludes(llvm::StringRef ModifiedContents,
llvm::StringRef BaselineContents,
llvm::StringRef MainFileName = "main.cpp") {
- auto BaselinePreamble = createPreamble(BaselineContents);
- // Create the patch.
- auto TU = TestTU::withCode(ModifiedContents);
+ auto TU = TestTU::withCode(BaselineContents);
TU.Filename = MainFileName.str();
+ // ms-compatibility changes meaning of #import, make sure it is turned off.
+ TU.ExtraArgs = {"-fno-ms-compatibility"};
+ auto BaselinePreamble = TU.preamble();
+ // Create the patch.
+ TU = TestTU::withCode(ModifiedContents);
auto PI = TU.inputs();
auto PP = PreamblePatch::create(testPath(TU.Filename), PI, *BaselinePreamble);
// Collect patch contents.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D79930.266202.patch
Type: text/x-patch
Size: 3891 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200526/3327f45b/attachment-0001.bin>
More information about the cfe-commits
mailing list