Add --clang-sanity-check.

Does a simple index test to verify expected libclang API behavior.
This commit is contained in:
Jacob Dufault 2017-12-01 09:45:44 -08:00
parent 2a2794da23
commit 066166ba40
3 changed files with 60 additions and 0 deletions

View File

@ -3227,6 +3227,11 @@ int main(int argc, char** argv) {
bool print_help = true; bool print_help = true;
if (HasOption(options, "--clang-sanity-check")) {
print_help = false;
ClangSanityCheck();
}
if (HasOption(options, "--log-stdin-stdout-to-stderr")) if (HasOption(options, "--log-stdin-stdout-to-stderr"))
g_log_stdin_stdout_to_stderr = true; g_log_stdin_stdout_to_stderr = true;
@ -3272,6 +3277,9 @@ int main(int argc, char** argv) {
Print stdin and stdout messages to stderr. This is a aid for Print stdin and stdout messages to stderr. This is a aid for
developing new language clients, as it makes it easier to developing new language clients, as it makes it easier to
figure out how the client is interacting with cquery. figure out how the client is interacting with cquery.
--clang-sanity-check
Run a simple index test. Verifies basic clang functionality.
Needs to be executed from the cquery root checkout directory.
Configuration: Configuration:
When opening up a directory, cquery will look for a compile_commands.json When opening up a directory, cquery will look for a compile_commands.json

View File

@ -1716,3 +1716,53 @@ void IndexInit() {
clang_enableStackTraces(); clang_enableStackTraces();
clang_toggleCrashRecovery(1); clang_toggleCrashRecovery(1);
} }
void ClangSanityCheck() {
std::vector<const char*> args = {"clang", "tests/vars/class_member.cc"};
unsigned opts = 0;
CXIndex index = clang_createIndex(0, 1);
CXTranslationUnit tu;
clang_parseTranslationUnit2FullArgv(index, nullptr, args.data(), args.size(),
nullptr, 0, opts, &tu);
assert(tu);
IndexerCallbacks callback = {0};
callback.abortQuery = [](CXClientData client_data, void* reserved) {
return 0;
};
callback.diagnostic = [](CXClientData client_data,
CXDiagnosticSet diagnostics, void* reserved) {};
callback.enteredMainFile = [](CXClientData client_data, CXFile mainFile,
void* reserved) -> CXIdxClientFile {
return nullptr;
};
callback.ppIncludedFile =
[](CXClientData client_data,
const CXIdxIncludedFileInfo* file) -> CXIdxClientFile {
return nullptr;
};
callback.importedASTFile =
[](CXClientData client_data,
const CXIdxImportedASTFileInfo*) -> CXIdxClientASTFile {
return nullptr;
};
callback.startedTranslationUnit = [](CXClientData client_data,
void* reserved) -> CXIdxClientContainer {
return nullptr;
};
callback.indexDeclaration = [](CXClientData client_data,
const CXIdxDeclInfo* decl) {};
callback.indexEntityReference = [](CXClientData client_data,
const CXIdxEntityRefInfo* ref) {};
const unsigned kIndexOpts = 0;
CXIndexAction index_action = clang_IndexAction_create(index);
int index_param = 0;
clang_toggleCrashRecovery(0);
clang_indexTranslationUnit(index_action, &index_param, &callback,
sizeof(IndexerCallbacks), kIndexOpts, tu);
clang_IndexAction_dispose(index_action);
clang_disposeTranslationUnit(tu);
clang_disposeIndex(index);
}

View File

@ -555,3 +555,5 @@ std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
const std::vector<CXUnsavedFile>& file_contents); const std::vector<CXUnsavedFile>& file_contents);
void IndexInit(); void IndexInit();
void ClangSanityCheck();