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. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "flang/Common/Version.h" 14 #include "llvm/Support/raw_ostream.h" 15 #include <cstdlib> 16 #include <cstring> 17 18 #include "VCSVersion.inc" 19 20 namespace Fortran::common { 21 getFlangRepositoryPath()22std::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 32 } 33 getLLVMRepositoryPath()34std::string getLLVMRepositoryPath() { 35 #ifdef LLVM_REPOSITORY 36 return LLVM_REPOSITORY; 37 #else 38 return ""; 39 #endif 40 } 41 getFlangRevision()42std::string getFlangRevision() { 43 #ifdef FLANG_REVISION 44 return FLANG_REVISION; 45 #else 46 return ""; 47 #endif 48 } 49 getLLVMRevision()50std::string getLLVMRevision() { 51 #ifdef LLVM_REVISION 52 return LLVM_REVISION; 53 #else 54 return ""; 55 #endif 56 } 57 getFlangFullRepositoryVersion()58std::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; 71 } 72 OS << ')'; 73 } 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 << ')'; 82 } 83 return buf; 84 } 85 getFlangFullVersion()86std::string getFlangFullVersion() { return getFlangToolFullVersion("flang"); } 87 getFlangToolFullVersion(llvm::StringRef ToolName)88std::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; 95 96 std::string repo = getFlangFullRepositoryVersion(); 97 if (!repo.empty()) { 98 OS << " " << repo; 99 } 100 101 return buf; 102 } 103 104 } // end namespace Fortran::common 105