[clang-tools-extra] 0c96a92 - [clangd] Log feature configuration (linux+asan+grpc) of the clangd build
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 30 08:49:54 PDT 2021
Author: Sam McCall
Date: 2021-06-30T17:49:29+02:00
New Revision: 0c96a92d8666b8eb69eb1275aed572f857182d9a
URL: https://github.com/llvm/llvm-project/commit/0c96a92d8666b8eb69eb1275aed572f857182d9a
DIFF: https://github.com/llvm/llvm-project/commit/0c96a92d8666b8eb69eb1275aed572f857182d9a.diff
LOG: [clangd] Log feature configuration (linux+asan+grpc) of the clangd build
Included in logs, --version, remote index queries, and LSP serverInfo.
Differential Revision: https://reviews.llvm.org/D100553
Added:
clang-tools-extra/clangd/Features.cpp
clang-tools-extra/clangd/Features.h
Modified:
clang-tools-extra/clangd/CMakeLists.txt
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/ClangdLSPServer.h
clang-tools-extra/clangd/ConfigCompile.cpp
clang-tools-extra/clangd/Features.inc.in
clang-tools-extra/clangd/index/remote/Client.cpp
clang-tools-extra/clangd/index/remote/server/Server.cpp
clang-tools-extra/clangd/tool/ClangdMain.cpp
clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt
index 671e55e8622d3..b983b71cc90f4 100644
--- a/clang-tools-extra/clangd/CMakeLists.txt
+++ b/clang-tools-extra/clangd/CMakeLists.txt
@@ -64,6 +64,7 @@ add_clang_library(clangDaemon
DumpAST.cpp
ExpectedTypes.cpp
FeatureModule.cpp
+ Features.cpp
FindSymbols.cpp
FindTarget.cpp
FileDistance.cpp
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index f70fd0018cfdf..9214bcbe66bca 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -12,6 +12,7 @@
#include "Diagnostics.h"
#include "DraftStore.h"
#include "DumpAST.h"
+#include "Features.h"
#include "GlobalCompilationDatabase.h"
#include "LSPBinder.h"
#include "Protocol.h"
@@ -24,7 +25,6 @@
#include "support/MemoryTree.h"
#include "support/Trace.h"
#include "clang/AST/ASTContext.h"
-#include "clang/Basic/Version.h"
#include "clang/Tooling/Core/Replacement.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
@@ -620,7 +620,8 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
llvm::json::Object Result{
{{"serverInfo",
llvm::json::Object{{"name", "clangd"},
- {"version", getClangToolFullVersion("clangd")}}},
+ {"version", llvm::formatv("{0} {1}", versionString(),
+ featureString())}}},
{"capabilities", std::move(ServerCaps)}}};
if (Opts.Encoding)
Result["offsetEncoding"] = *Opts.Encoding;
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h
index 8c43d18502875..4c195df6f893c 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.h
+++ b/clang-tools-extra/clangd/ClangdLSPServer.h
@@ -11,7 +11,6 @@
#include "ClangdServer.h"
#include "DraftStore.h"
-#include "Features.inc"
#include "FindSymbols.h"
#include "GlobalCompilationDatabase.h"
#include "LSPBinder.h"
diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp
index 438dd74d866c6..4eaff343b2290 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -28,7 +28,7 @@
#include "ConfigFragment.h"
#include "ConfigProvider.h"
#include "Diagnostics.h"
-#include "Features.inc"
+#include "Features.h"
#include "TidyProvider.h"
#include "support/Logger.h"
#include "support/Path.h"
diff --git a/clang-tools-extra/clangd/Features.cpp b/clang-tools-extra/clangd/Features.cpp
new file mode 100644
index 0000000000000..17f475fc4c22b
--- /dev/null
+++ b/clang-tools-extra/clangd/Features.cpp
@@ -0,0 +1,55 @@
+//===--- Features.cpp - Compile-time configuration ------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "Features.h"
+#include "clang/Basic/Version.h"
+#include "llvm/Support/Compiler.h"
+
+namespace clang {
+namespace clangd {
+
+std::string versionString() { return clang::getClangToolFullVersion("clangd"); }
+
+std::string featureString() {
+ return
+#if defined(_WIN32)
+ "windows"
+#elif defined(__APPLE__)
+ "mac"
+#elif defined(__linux__)
+ "linux"
+#elif defined(LLVM_ON_UNIX)
+ "unix"
+#else
+ "unknown"
+#endif
+
+#ifndef NDEBUG
+ "+debug"
+#endif
+#if LLVM_ADDRESS_SANITIZER_BUILD
+ "+asan"
+#endif
+#if LLVM_THREAD_SANITIZER_BUILD
+ "+tsan"
+#endif
+#if LLVM_MEMORY_SANITIZER_BUILD
+ "+msan"
+#endif
+
+#if CLANGD_ENABLE_REMOTE
+ "+grpc"
+#endif
+#if CLANGD_BUILD_XPC
+ "+xpc"
+#endif
+ ;
+}
+
+} // namespace clangd
+} // namespace clang
diff --git a/clang-tools-extra/clangd/Features.h b/clang-tools-extra/clangd/Features.h
new file mode 100644
index 0000000000000..6fa3618578632
--- /dev/null
+++ b/clang-tools-extra/clangd/Features.h
@@ -0,0 +1,29 @@
+//===--- Features.h - Compile-time configuration ------------------*-C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FEATURES_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FEATURES_H
+#include <string>
+
+// Export constants like CLANGD_BUILD_XPC
+#include "Features.inc"
+
+namespace clang {
+namespace clangd {
+
+// Returns a version string for clangd, e.g. "clangd 10.0.0"
+std::string versionString();
+
+// Returns a string describing the compile-time configuration.
+// e.g. mac+debug+asan+grpc
+std::string featureString();
+
+} // namespace clangd
+} // namespace clang
+
+#endif
diff --git a/clang-tools-extra/clangd/Features.inc.in b/clang-tools-extra/clangd/Features.inc.in
index 5dfde58890b7e..72464d89b830e 100644
--- a/clang-tools-extra/clangd/Features.inc.in
+++ b/clang-tools-extra/clangd/Features.inc.in
@@ -1,3 +1,4 @@
+// IWYU pragma: private, include "Features.h"
#define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMOTE@
#define ENABLE_GRPC_REFLECTION @ENABLE_GRPC_REFLECTION@
diff --git a/clang-tools-extra/clangd/index/remote/Client.cpp b/clang-tools-extra/clangd/index/remote/Client.cpp
index b92c6520f61c0..ac6b7c0c829ff 100644
--- a/clang-tools-extra/clangd/index/remote/Client.cpp
+++ b/clang-tools-extra/clangd/index/remote/Client.cpp
@@ -9,12 +9,12 @@
#include <grpc++/grpc++.h>
#include "Client.h"
+#include "Features.h"
#include "Service.grpc.pb.h"
#include "index/Index.h"
#include "marshalling/Marshalling.h"
#include "support/Logger.h"
#include "support/Trace.h"
-#include "clang/Basic/Version.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Error.h"
@@ -72,7 +72,8 @@ class IndexClient : public clangd::SymbolIndex {
const auto RPCRequest = ProtobufMarshaller->toProtobuf(Request);
SPAN_ATTACH(Tracer, "Request", RPCRequest.DebugString());
grpc::ClientContext Context;
- Context.AddMetadata("version", clang::getClangToolFullVersion("clangd"));
+ Context.AddMetadata("version", versionString());
+ Context.AddMetadata("features", featureString());
std::chrono::system_clock::time_point StartTime =
std::chrono::system_clock::now();
auto Deadline = StartTime + DeadlineWaitingTime;
diff --git a/clang-tools-extra/clangd/index/remote/server/Server.cpp b/clang-tools-extra/clangd/index/remote/server/Server.cpp
index 04ad0b2a1936f..d2f96ba1a1b53 100644
--- a/clang-tools-extra/clangd/index/remote/server/Server.cpp
+++ b/clang-tools-extra/clangd/index/remote/server/Server.cpp
@@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//
-#include "Features.inc"
+#include "Features.h"
#include "Index.pb.h"
#include "MonitoringService.grpc.pb.h"
#include "MonitoringService.pb.h"
diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index 6d70a9cf03f6e..8db52c65061c8 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -10,7 +10,7 @@
#include "CodeComplete.h"
#include "Config.h"
#include "ConfigProvider.h"
-#include "Features.inc"
+#include "Features.h"
#include "PathMapping.h"
#include "Protocol.h"
#include "TidyProvider.h"
@@ -26,7 +26,6 @@
#include "support/Shutdown.h"
#include "support/ThreadsafeFS.h"
#include "support/Trace.h"
-#include "clang/Basic/Version.h"
#include "clang/Format/Format.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallString.h"
@@ -679,7 +678,8 @@ int main(int argc, char *argv[]) {
llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
llvm::sys::SetInterruptFunction(&requestShutdown);
llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) {
- OS << clang::getClangToolFullVersion("clangd") << "\n";
+ OS << versionString() << "\n"
+ << "Features: " << featureString() << "\n";
});
const char *FlagsEnvVar = "CLANGD_FLAGS";
const char *Overview =
@@ -784,7 +784,8 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
StreamLogger Logger(llvm::errs(), LogLevel);
LoggingSession LoggingSession(Logger);
// Write some initial logs before we start doing any real work.
- log("{0}", clang::getClangToolFullVersion("clangd"));
+ log("{0}", versionString());
+ log("Features: {0}", featureString());
log("PID: {0}", llvm::sys::Process::getProcessId());
{
SmallString<128> CWD;
diff --git a/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp b/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
index 381180381f36f..93b85d8c0b5dc 100644
--- a/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp
@@ -9,7 +9,7 @@
#include "Config.h"
#include "ConfigFragment.h"
#include "ConfigTesting.h"
-#include "Features.inc"
+#include "Features.h"
#include "TestFS.h"
#include "clang/Basic/DiagnosticSema.h"
#include "llvm/ADT/None.h"
More information about the cfe-commits
mailing list