xref: /src/contrib/llvm-project/lldb/source/Version/Version.cpp (revision 0eae32dcef82f6f06de6419a0d623d7def0cc8f6)
177fc4c14SDimitry Andric //===-- Version.cpp -------------------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste 
977fc4c14SDimitry Andric #include "lldb/Version/Version.h"
10344a3780SDimitry Andric #include "VCSVersion.inc"
1177fc4c14SDimitry Andric #include "lldb/Version/Version.inc"
12344a3780SDimitry Andric #include "clang/Basic/Version.h"
13f034231aSEd Maste 
GetLLDBVersion()14344a3780SDimitry Andric static const char *GetLLDBVersion() {
1577fc4c14SDimitry Andric #ifdef LLDB_FULL_VERSION_STRING
1677fc4c14SDimitry Andric   return LLDB_FULL_VERSION_STRING;
17344a3780SDimitry Andric #else
1877fc4c14SDimitry Andric   return "lldb version " LLDB_VERSION_STRING;
19344a3780SDimitry Andric #endif
20344a3780SDimitry Andric }
2114f1b3e8SDimitry Andric 
GetLLDBRevision()2214f1b3e8SDimitry Andric static const char *GetLLDBRevision() {
23f034231aSEd Maste #ifdef LLDB_REVISION
24f034231aSEd Maste   return LLDB_REVISION;
25f034231aSEd Maste #else
2677fc4c14SDimitry Andric   return nullptr;
27f034231aSEd Maste #endif
28f034231aSEd Maste }
29f034231aSEd Maste 
GetLLDBRepository()3014f1b3e8SDimitry Andric static const char *GetLLDBRepository() {
31f034231aSEd Maste #ifdef LLDB_REPOSITORY
32f034231aSEd Maste   return LLDB_REPOSITORY;
33f034231aSEd Maste #else
3477fc4c14SDimitry Andric   return nullptr;
35f034231aSEd Maste #endif
36f034231aSEd Maste }
37f034231aSEd Maste 
GetVersion()3814f1b3e8SDimitry Andric const char *lldb_private::GetVersion() {
39f034231aSEd Maste   static std::string g_version_str;
4077fc4c14SDimitry Andric 
4114f1b3e8SDimitry Andric   if (g_version_str.empty()) {
42344a3780SDimitry Andric     const char *lldb_version = GetLLDBVersion();
43f034231aSEd Maste     const char *lldb_repo = GetLLDBRepository();
44f034231aSEd Maste     const char *lldb_rev = GetLLDBRevision();
45344a3780SDimitry Andric     g_version_str += lldb_version;
4614f1b3e8SDimitry Andric     if (lldb_repo || lldb_rev) {
4714f1b3e8SDimitry Andric       g_version_str += " (";
4814f1b3e8SDimitry Andric       if (lldb_repo)
4914f1b3e8SDimitry Andric         g_version_str += lldb_repo;
50cfca06d7SDimitry Andric       if (lldb_repo && lldb_rev)
51cfca06d7SDimitry Andric         g_version_str += " ";
5214f1b3e8SDimitry Andric       if (lldb_rev) {
53f034231aSEd Maste         g_version_str += "revision ";
54f034231aSEd Maste         g_version_str += lldb_rev;
55f034231aSEd Maste       }
5614f1b3e8SDimitry Andric       g_version_str += ")";
5714f1b3e8SDimitry Andric     }
5814f1b3e8SDimitry Andric 
59f034231aSEd Maste     std::string clang_rev(clang::getClangRevision());
6014f1b3e8SDimitry Andric     if (clang_rev.length() > 0) {
6114f1b3e8SDimitry Andric       g_version_str += "\n  clang revision ";
62f034231aSEd Maste       g_version_str += clang_rev;
63f034231aSEd Maste     }
6477fc4c14SDimitry Andric 
65f034231aSEd Maste     std::string llvm_rev(clang::getLLVMRevision());
6614f1b3e8SDimitry Andric     if (llvm_rev.length() > 0) {
6714f1b3e8SDimitry Andric       g_version_str += "\n  llvm revision ";
68f034231aSEd Maste       g_version_str += llvm_rev;
69f034231aSEd Maste     }
70f034231aSEd Maste   }
7177fc4c14SDimitry Andric 
72f034231aSEd Maste   return g_version_str.c_str();
73f034231aSEd Maste }
74