[memprof] Use LineLocation in a unit test (NFC) (#116917)
[llvm-project.git] / flang / lib / Common / Version.cpp
blobd67255f353dfd771469535e490ed891631ccc0d2
1 //===- Version.cpp - Flang Version Number -------------------*- Fortran -*-===//
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 Flang.
11 //===----------------------------------------------------------------------===//
13 #include "flang/Common/Version.h"
14 #include "llvm/Support/raw_ostream.h"
15 #include <cstdlib>
16 #include <cstring>
18 #include "VCSVersion.inc"
20 namespace Fortran::common {
22 std::string getFlangRepositoryPath() {
23 #if defined(FLANG_REPOSITORY_STRING)
24 return FLANG_REPOSITORY_STRING;
25 #else
26 #ifdef FLANG_REPOSITORY
27 return FLANG_REPOSITORY;
28 #else
29 return "";
30 #endif
31 #endif
34 std::string getLLVMRepositoryPath() {
35 #ifdef LLVM_REPOSITORY
36 return LLVM_REPOSITORY;
37 #else
38 return "";
39 #endif
42 std::string getFlangRevision() {
43 #ifdef FLANG_REVISION
44 return FLANG_REVISION;
45 #else
46 return "";
47 #endif
50 std::string getLLVMRevision() {
51 #ifdef LLVM_REVISION
52 return LLVM_REVISION;
53 #else
54 return "";
55 #endif
58 std::string getFlangFullRepositoryVersion() {
59 std::string buf;
60 llvm::raw_string_ostream OS(buf);
61 std::string Path = getFlangRepositoryPath();
62 std::string Revision = getFlangRevision();
63 if (!Path.empty() || !Revision.empty()) {
64 OS << '(';
65 if (!Path.empty())
66 OS << Path;
67 if (!Revision.empty()) {
68 if (!Path.empty())
69 OS << ' ';
70 OS << Revision;
72 OS << ')';
74 // Support LLVM in a separate repository.
75 std::string LLVMRev = getLLVMRevision();
76 if (!LLVMRev.empty() && LLVMRev != Revision) {
77 OS << " (";
78 std::string LLVMRepo = getLLVMRepositoryPath();
79 if (!LLVMRepo.empty())
80 OS << LLVMRepo << ' ';
81 OS << LLVMRev << ')';
83 return buf;
86 std::string getFlangFullVersion() { return getFlangToolFullVersion("flang"); }
88 std::string getFlangToolFullVersion(llvm::StringRef ToolName) {
89 std::string buf;
90 llvm::raw_string_ostream OS(buf);
91 #ifdef FLANG_VENDOR
92 OS << FLANG_VENDOR;
93 #endif
94 OS << ToolName << " version " FLANG_VERSION_STRING;
96 std::string repo = getFlangFullRepositoryVersion();
97 if (!repo.empty()) {
98 OS << " " << repo;
101 return buf;
104 } // end namespace Fortran::common