diff --git a/clang-tools-extra/clangd/CMakeLists.txt b/clang-tools-extra/clangd/CMakeLists.txt --- a/clang-tools-extra/clangd/CMakeLists.txt +++ b/clang-tools-extra/clangd/CMakeLists.txt @@ -64,6 +64,7 @@ DumpAST.cpp ExpectedTypes.cpp FeatureModule.cpp + Features.cpp FindSymbols.cpp FindTarget.cpp FileDistance.cpp diff --git a/clang-tools-extra/clangd/ClangdLSPServer.h b/clang-tools-extra/clangd/ClangdLSPServer.h --- 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/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp --- 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 @@ 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/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp --- 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.h b/clang-tools-extra/clangd/Features.h new file mode 100644 --- /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 + +// 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.cpp b/clang-tools-extra/clangd/Features.cpp new file mode 100644 --- /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.inc.in b/clang-tools-extra/clangd/Features.inc.in --- 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 --- a/clang-tools-extra/clangd/index/remote/Client.cpp +++ b/clang-tools-extra/clangd/index/remote/Client.cpp @@ -9,12 +9,12 @@ #include #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 @@ 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 --- 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 --- 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 @@ 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 @@ 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 --- 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"