Skip to content

Commit 0c96a92

Browse files
committed
[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
1 parent bb41f85 commit 0c96a92

File tree

11 files changed

+100
-12
lines changed

11 files changed

+100
-12
lines changed

clang-tools-extra/clangd/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ add_clang_library(clangDaemon
6464
DumpAST.cpp
6565
ExpectedTypes.cpp
6666
FeatureModule.cpp
67+
Features.cpp
6768
FindSymbols.cpp
6869
FindTarget.cpp
6970
FileDistance.cpp

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "Diagnostics.h"
1313
#include "DraftStore.h"
1414
#include "DumpAST.h"
15+
#include "Features.h"
1516
#include "GlobalCompilationDatabase.h"
1617
#include "LSPBinder.h"
1718
#include "Protocol.h"
@@ -24,7 +25,6 @@
2425
#include "support/MemoryTree.h"
2526
#include "support/Trace.h"
2627
#include "clang/AST/ASTContext.h"
27-
#include "clang/Basic/Version.h"
2828
#include "clang/Tooling/Core/Replacement.h"
2929
#include "llvm/ADT/ArrayRef.h"
3030
#include "llvm/ADT/Optional.h"
@@ -620,7 +620,8 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
620620
llvm::json::Object Result{
621621
{{"serverInfo",
622622
llvm::json::Object{{"name", "clangd"},
623-
{"version", getClangToolFullVersion("clangd")}}},
623+
{"version", llvm::formatv("{0} {1}", versionString(),
624+
featureString())}}},
624625
{"capabilities", std::move(ServerCaps)}}};
625626
if (Opts.Encoding)
626627
Result["offsetEncoding"] = *Opts.Encoding;

clang-tools-extra/clangd/ClangdLSPServer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "ClangdServer.h"
1313
#include "DraftStore.h"
14-
#include "Features.inc"
1514
#include "FindSymbols.h"
1615
#include "GlobalCompilationDatabase.h"
1716
#include "LSPBinder.h"

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#include "ConfigFragment.h"
2929
#include "ConfigProvider.h"
3030
#include "Diagnostics.h"
31-
#include "Features.inc"
31+
#include "Features.h"
3232
#include "TidyProvider.h"
3333
#include "support/Logger.h"
3434
#include "support/Path.h"

clang-tools-extra/clangd/Features.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//===--- Features.cpp - Compile-time configuration ------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "Features.h"
10+
#include "clang/Basic/Version.h"
11+
#include "llvm/Support/Compiler.h"
12+
13+
namespace clang {
14+
namespace clangd {
15+
16+
std::string versionString() { return clang::getClangToolFullVersion("clangd"); }
17+
18+
std::string featureString() {
19+
return
20+
#if defined(_WIN32)
21+
"windows"
22+
#elif defined(__APPLE__)
23+
"mac"
24+
#elif defined(__linux__)
25+
"linux"
26+
#elif defined(LLVM_ON_UNIX)
27+
"unix"
28+
#else
29+
"unknown"
30+
#endif
31+
32+
#ifndef NDEBUG
33+
"+debug"
34+
#endif
35+
#if LLVM_ADDRESS_SANITIZER_BUILD
36+
"+asan"
37+
#endif
38+
#if LLVM_THREAD_SANITIZER_BUILD
39+
"+tsan"
40+
#endif
41+
#if LLVM_MEMORY_SANITIZER_BUILD
42+
"+msan"
43+
#endif
44+
45+
#if CLANGD_ENABLE_REMOTE
46+
"+grpc"
47+
#endif
48+
#if CLANGD_BUILD_XPC
49+
"+xpc"
50+
#endif
51+
;
52+
}
53+
54+
} // namespace clangd
55+
} // namespace clang

clang-tools-extra/clangd/Features.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===--- Features.h - Compile-time configuration ------------------*-C++-*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_FEATURES_H
10+
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_FEATURES_H
11+
#include <string>
12+
13+
// Export constants like CLANGD_BUILD_XPC
14+
#include "Features.inc"
15+
16+
namespace clang {
17+
namespace clangd {
18+
19+
// Returns a version string for clangd, e.g. "clangd 10.0.0"
20+
std::string versionString();
21+
22+
// Returns a string describing the compile-time configuration.
23+
// e.g. mac+debug+asan+grpc
24+
std::string featureString();
25+
26+
} // namespace clangd
27+
} // namespace clang
28+
29+
#endif

clang-tools-extra/clangd/Features.inc.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// IWYU pragma: private, include "Features.h"
12
#define CLANGD_BUILD_XPC @CLANGD_BUILD_XPC@
23
#define CLANGD_ENABLE_REMOTE @CLANGD_ENABLE_REMOTE@
34
#define ENABLE_GRPC_REFLECTION @ENABLE_GRPC_REFLECTION@

clang-tools-extra/clangd/index/remote/Client.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
#include <grpc++/grpc++.h>
1010

1111
#include "Client.h"
12+
#include "Features.h"
1213
#include "Service.grpc.pb.h"
1314
#include "index/Index.h"
1415
#include "marshalling/Marshalling.h"
1516
#include "support/Logger.h"
1617
#include "support/Trace.h"
17-
#include "clang/Basic/Version.h"
1818
#include "llvm/ADT/SmallString.h"
1919
#include "llvm/ADT/StringRef.h"
2020
#include "llvm/Support/Error.h"
@@ -72,7 +72,8 @@ class IndexClient : public clangd::SymbolIndex {
7272
const auto RPCRequest = ProtobufMarshaller->toProtobuf(Request);
7373
SPAN_ATTACH(Tracer, "Request", RPCRequest.DebugString());
7474
grpc::ClientContext Context;
75-
Context.AddMetadata("version", clang::getClangToolFullVersion("clangd"));
75+
Context.AddMetadata("version", versionString());
76+
Context.AddMetadata("features", featureString());
7677
std::chrono::system_clock::time_point StartTime =
7778
std::chrono::system_clock::now();
7879
auto Deadline = StartTime + DeadlineWaitingTime;

clang-tools-extra/clangd/index/remote/server/Server.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "Features.inc"
9+
#include "Features.h"
1010
#include "Index.pb.h"
1111
#include "MonitoringService.grpc.pb.h"
1212
#include "MonitoringService.pb.h"

clang-tools-extra/clangd/tool/ClangdMain.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "CodeComplete.h"
1111
#include "Config.h"
1212
#include "ConfigProvider.h"
13-
#include "Features.inc"
13+
#include "Features.h"
1414
#include "PathMapping.h"
1515
#include "Protocol.h"
1616
#include "TidyProvider.h"
@@ -26,7 +26,6 @@
2626
#include "support/Shutdown.h"
2727
#include "support/ThreadsafeFS.h"
2828
#include "support/Trace.h"
29-
#include "clang/Basic/Version.h"
3029
#include "clang/Format/Format.h"
3130
#include "llvm/ADT/Optional.h"
3231
#include "llvm/ADT/SmallString.h"
@@ -679,7 +678,8 @@ int main(int argc, char *argv[]) {
679678
llvm::sys::PrintStackTraceOnErrorSignal(argv[0]);
680679
llvm::sys::SetInterruptFunction(&requestShutdown);
681680
llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) {
682-
OS << clang::getClangToolFullVersion("clangd") << "\n";
681+
OS << versionString() << "\n"
682+
<< "Features: " << featureString() << "\n";
683683
});
684684
const char *FlagsEnvVar = "CLANGD_FLAGS";
685685
const char *Overview =
@@ -784,7 +784,8 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
784784
StreamLogger Logger(llvm::errs(), LogLevel);
785785
LoggingSession LoggingSession(Logger);
786786
// Write some initial logs before we start doing any real work.
787-
log("{0}", clang::getClangToolFullVersion("clangd"));
787+
log("{0}", versionString());
788+
log("Features: {0}", featureString());
788789
log("PID: {0}", llvm::sys::Process::getProcessId());
789790
{
790791
SmallString<128> CWD;

clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "Config.h"
1010
#include "ConfigFragment.h"
1111
#include "ConfigTesting.h"
12-
#include "Features.inc"
12+
#include "Features.h"
1313
#include "TestFS.h"
1414
#include "clang/Basic/DiagnosticSema.h"
1515
#include "llvm/ADT/None.h"

0 commit comments

Comments
 (0)