[clang-tools-extra] e2559e5 - [clangd] Add platform triple (host & target) to version info
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 27 05:26:51 PDT 2021
Author: Sam McCall
Date: 2021-07-27T14:25:17+02:00
New Revision: e2559e5dc62445a92a9a5344db79f78f735e1e61
URL: https://github.com/llvm/llvm-project/commit/e2559e5dc62445a92a9a5344db79f78f735e1e61
DIFF: https://github.com/llvm/llvm-project/commit/e2559e5dc62445a92a9a5344db79f78f735e1e61.diff
LOG: [clangd] Add platform triple (host & target) to version info
Useful in logs to understand issues around some platforms we don't have much
experience with (e.g. m1, mingw)
Differential Revision: https://reviews.llvm.org/D105681
Added:
Modified:
clang-tools-extra/clangd/ClangdLSPServer.cpp
clang-tools-extra/clangd/Features.cpp
clang-tools-extra/clangd/Features.h
clang-tools-extra/clangd/index/remote/Client.cpp
clang-tools-extra/clangd/tool/ClangdMain.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/ClangdLSPServer.cpp b/clang-tools-extra/clangd/ClangdLSPServer.cpp
index 9214bcbe66bca..90d6e1159750a 100644
--- a/clang-tools-extra/clangd/ClangdLSPServer.cpp
+++ b/clang-tools-extra/clangd/ClangdLSPServer.cpp
@@ -619,9 +619,10 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
llvm::json::Object Result{
{{"serverInfo",
- llvm::json::Object{{"name", "clangd"},
- {"version", llvm::formatv("{0} {1}", versionString(),
- featureString())}}},
+ llvm::json::Object{
+ {"name", "clangd"},
+ {"version", llvm::formatv("{0} {1} {2}", versionString(),
+ featureString(), platformString())}}},
{"capabilities", std::move(ServerCaps)}}};
if (Opts.Encoding)
Result["offsetEncoding"] = *Opts.Encoding;
diff --git a/clang-tools-extra/clangd/Features.cpp b/clang-tools-extra/clangd/Features.cpp
index 4ec03ea84bfb4..d7fba42a3408c 100644
--- a/clang-tools-extra/clangd/Features.cpp
+++ b/clang-tools-extra/clangd/Features.cpp
@@ -9,12 +9,26 @@
#include "Features.h"
#include "clang/Basic/Version.h"
#include "llvm/Support/Compiler.h"
+#include "llvm/Support/Host.h"
namespace clang {
namespace clangd {
std::string versionString() { return clang::getClangToolFullVersion("clangd"); }
+std::string platformString() {
+ static std::string PlatformString = []() {
+ std::string Host = llvm::sys::getProcessTriple();
+ std::string Target = llvm::sys::getDefaultTargetTriple();
+ if (Host != Target) {
+ Host += "; target=";
+ Host += Target;
+ }
+ return Host;
+ }();
+ return PlatformString;
+}
+
std::string featureString() {
return
#if defined(_WIN32)
diff --git a/clang-tools-extra/clangd/Features.h b/clang-tools-extra/clangd/Features.h
index 6fa3618578632..1723eb37b3bc1 100644
--- a/clang-tools-extra/clangd/Features.h
+++ b/clang-tools-extra/clangd/Features.h
@@ -19,6 +19,10 @@ namespace clangd {
// Returns a version string for clangd, e.g. "clangd 10.0.0"
std::string versionString();
+// Returns the platform triple for clangd, e.g. "x86_64-pc-linux-gnu"
+// May include both the host and target triple if they
diff er.
+std::string platformString();
+
// Returns a string describing the compile-time configuration.
// e.g. mac+debug+asan+grpc
std::string featureString();
diff --git a/clang-tools-extra/clangd/index/remote/Client.cpp b/clang-tools-extra/clangd/index/remote/Client.cpp
index ac6b7c0c829ff..8db2287654600 100644
--- a/clang-tools-extra/clangd/index/remote/Client.cpp
+++ b/clang-tools-extra/clangd/index/remote/Client.cpp
@@ -74,6 +74,7 @@ class IndexClient : public clangd::SymbolIndex {
grpc::ClientContext Context;
Context.AddMetadata("version", versionString());
Context.AddMetadata("features", featureString());
+ Context.AddMetadata("platform", platformString());
std::chrono::system_clock::time_point StartTime =
std::chrono::system_clock::now();
auto Deadline = StartTime + DeadlineWaitingTime;
diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index 8db52c65061c8..c40f98f5a4eeb 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -679,7 +679,8 @@ int main(int argc, char *argv[]) {
llvm::sys::SetInterruptFunction(&requestShutdown);
llvm::cl::SetVersionPrinter([](llvm::raw_ostream &OS) {
OS << versionString() << "\n"
- << "Features: " << featureString() << "\n";
+ << "Features: " << featureString() << "\n"
+ << "Platform: " << platformString() << "\n";
});
const char *FlagsEnvVar = "CLANGD_FLAGS";
const char *Overview =
More information about the cfe-commits
mailing list