xref: /llvm-project/lldb/source/Version/Version.cpp (revision 58473d84e0c7796de5dcfd3153e5d5cc8ad034b3)
1ccf1469aSJonas Devlieghere //===-- Version.cpp -------------------------------------------------------===//
2ccf1469aSJonas Devlieghere //
3ccf1469aSJonas Devlieghere // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4ccf1469aSJonas Devlieghere // See https://llvm.org/LICENSE.txt for license information.
5ccf1469aSJonas Devlieghere // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6ccf1469aSJonas Devlieghere //
7ccf1469aSJonas Devlieghere //===----------------------------------------------------------------------===//
8ccf1469aSJonas Devlieghere 
9ccf1469aSJonas Devlieghere #include "lldb/Version/Version.h"
10ccf1469aSJonas Devlieghere #include "VCSVersion.inc"
11ccf1469aSJonas Devlieghere #include "lldb/Version/Version.inc"
12ccf1469aSJonas Devlieghere #include "clang/Basic/Version.h"
13ccf1469aSJonas Devlieghere 
GetLLDBVersion()14ccf1469aSJonas Devlieghere static const char *GetLLDBVersion() {
15ccf1469aSJonas Devlieghere #ifdef LLDB_FULL_VERSION_STRING
16ccf1469aSJonas Devlieghere   return LLDB_FULL_VERSION_STRING;
17ccf1469aSJonas Devlieghere #else
18*58473d84SJonas Devlieghere   return "lldb version " LLDB_VERSION_STRING;
19ccf1469aSJonas Devlieghere #endif
20ccf1469aSJonas Devlieghere }
21ccf1469aSJonas Devlieghere 
GetLLDBRevision()22ccf1469aSJonas Devlieghere static const char *GetLLDBRevision() {
23ccf1469aSJonas Devlieghere #ifdef LLDB_REVISION
24ccf1469aSJonas Devlieghere   return LLDB_REVISION;
25ccf1469aSJonas Devlieghere #else
26ccf1469aSJonas Devlieghere   return nullptr;
27ccf1469aSJonas Devlieghere #endif
28ccf1469aSJonas Devlieghere }
29ccf1469aSJonas Devlieghere 
GetLLDBRepository()30ccf1469aSJonas Devlieghere static const char *GetLLDBRepository() {
31ccf1469aSJonas Devlieghere #ifdef LLDB_REPOSITORY
32ccf1469aSJonas Devlieghere   return LLDB_REPOSITORY;
33ccf1469aSJonas Devlieghere #else
34ccf1469aSJonas Devlieghere   return nullptr;
35ccf1469aSJonas Devlieghere #endif
36ccf1469aSJonas Devlieghere }
37ccf1469aSJonas Devlieghere 
GetVersion()38ccf1469aSJonas Devlieghere const char *lldb_private::GetVersion() {
39ccf1469aSJonas Devlieghere   static std::string g_version_str;
40ccf1469aSJonas Devlieghere 
41ccf1469aSJonas Devlieghere   if (g_version_str.empty()) {
42ccf1469aSJonas Devlieghere     const char *lldb_version = GetLLDBVersion();
43ccf1469aSJonas Devlieghere     const char *lldb_repo = GetLLDBRepository();
44ccf1469aSJonas Devlieghere     const char *lldb_rev = GetLLDBRevision();
45ccf1469aSJonas Devlieghere     g_version_str += lldb_version;
46ccf1469aSJonas Devlieghere     if (lldb_repo || lldb_rev) {
47ccf1469aSJonas Devlieghere       g_version_str += " (";
48ccf1469aSJonas Devlieghere       if (lldb_repo)
49ccf1469aSJonas Devlieghere         g_version_str += lldb_repo;
50ccf1469aSJonas Devlieghere       if (lldb_repo && lldb_rev)
51ccf1469aSJonas Devlieghere         g_version_str += " ";
52ccf1469aSJonas Devlieghere       if (lldb_rev) {
53ccf1469aSJonas Devlieghere         g_version_str += "revision ";
54ccf1469aSJonas Devlieghere         g_version_str += lldb_rev;
55ccf1469aSJonas Devlieghere       }
56ccf1469aSJonas Devlieghere       g_version_str += ")";
57ccf1469aSJonas Devlieghere     }
58ccf1469aSJonas Devlieghere 
59ccf1469aSJonas Devlieghere     std::string clang_rev(clang::getClangRevision());
60ccf1469aSJonas Devlieghere     if (clang_rev.length() > 0) {
61ccf1469aSJonas Devlieghere       g_version_str += "\n  clang revision ";
62ccf1469aSJonas Devlieghere       g_version_str += clang_rev;
63ccf1469aSJonas Devlieghere     }
64ccf1469aSJonas Devlieghere 
65ccf1469aSJonas Devlieghere     std::string llvm_rev(clang::getLLVMRevision());
66ccf1469aSJonas Devlieghere     if (llvm_rev.length() > 0) {
67ccf1469aSJonas Devlieghere       g_version_str += "\n  llvm revision ";
68ccf1469aSJonas Devlieghere       g_version_str += llvm_rev;
69ccf1469aSJonas Devlieghere     }
70ccf1469aSJonas Devlieghere   }
71ccf1469aSJonas Devlieghere 
72ccf1469aSJonas Devlieghere   return g_version_str.c_str();
73ccf1469aSJonas Devlieghere }
74