1 //===- lib/Common/Version.cpp - LLD Version Number ---------------*- 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 // This file defines several version-related utility functions for LLD.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "lld/Common/Version.h"
14 
15 using namespace llvm;
16 
17 // Returns an SVN repository path, which is usually "trunk".
18 static std::string getRepositoryPath() {
19   StringRef S = LLD_REPOSITORY_STRING;
20   size_t Pos = S.find("lld/");
21   if (Pos != StringRef::npos)
22     return S.substr(Pos + 4);
23   return S;
24 }
25 
26 // Returns an SVN repository name, e.g., " (trunk 284614)"
27 // or an empty string if no repository info is available.
28 static std::string getRepository() {
29   std::string Repo = getRepositoryPath();
30   std::string Rev = LLD_REVISION_STRING;
31 
32   if (Repo.empty() && Rev.empty())
33     return "";
34   if (!Repo.empty() && !Rev.empty())
35     return " (" + Repo + " " + Rev + ")";
36   return " (" + Repo + Rev + ")";
37 }
38 
39 // Returns a version string, e.g., "LLD 4.0 (lld/trunk 284614)".
40 std::string lld::getLLDVersion() {
41   return "LLD " + std::string(LLD_VERSION_STRING) + getRepository();
42 }
43