Mantid
Loading...
Searching...
No Matches
MantidVersion.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7//----------------------------------------------------------------------
8// Includes
9//----------------------------------------------------------------------
10
11/********** PLEASE NOTE! THIS FILE WAS AUTO-GENERATED FROM CMAKE. ***********************/
12/********** Source = MantidVersion.cpp.in *****************************************************/
13
15#include <chrono>
16#include <iostream>
17#include <regex>
18#include <sstream>
19
20namespace Mantid::Kernel {
21
22namespace {
23
27std::chrono::month to_month(const std::string &month) {
28 if (month == "Jan")
29 return std::chrono::January;
30 else if (month == "Feb")
31 return std::chrono::February;
32 else if (month == "Mar")
33 return std::chrono::March;
34 else if (month == "Apr")
35 return std::chrono::April;
36 else if (month == "May")
37 return std::chrono::May;
38 else if (month == "Jun")
39 return std::chrono::June;
40 else if (month == "Jul")
41 return std::chrono::July;
42 else if (month == "Aug")
43 return std::chrono::August;
44 else if (month == "Sep")
45 return std::chrono::September;
46 else if (month == "Oct")
47 return std::chrono::October;
48 else if (month == "Nov")
49 return std::chrono::November;
50 else if (month == "Dec")
51 return std::chrono::December;
52 else // should never get here
53 throw std::runtime_error("Cannot convert \"" + month + "\" to a month object");
54}
55
56Types::Core::DateAndTime create_releaseDateAndTime() {
57 const std::string REVISION_DATE{"Tue, 3 Feb 2026 00:30:06 +0000"};
58
59 Types::Core::DateAndTime release;
60 // cppcheck-suppress knownConditionTrueFalse
61 if (REVISION_DATE == "UNKNOWN") {
62 // something went wrong in VersionNumber.cmake so give the default constructor result
63 } else {
64 // pull apart string into year, month, and day objects
65 // WARNING if the format changes this will break and default DateAndTime is returned
66 std::regex format(R"(^.+,\s+(\d{1,2})\s+(\w{3})\s+(\d{4})\s+(.+)\s*$)");
67 std::smatch matches;
68 if (std::regex_search(REVISION_DATE, matches, format)) {
69 constexpr size_t INDEX_DAY{1};
70 constexpr size_t INDEX_MONTH{2};
71 constexpr size_t INDEX_YEAR{3};
72 constexpr size_t INDEX_TIME{4};
73
74 // day is the next element by whitespace
75 const auto day = std::chrono::day(std::stoi(matches[INDEX_DAY].str()));
76 // then comes 3 character month
77 const auto month = to_month(matches[INDEX_MONTH].str());
78 // then 4 digit year
79 const auto year = std::chrono::year(std::stoi(matches[INDEX_YEAR].str()));
80 // everything past that is time
81 std::string time = matches[INDEX_TIME].str();
82 if (time.empty()) {
83 time = "00:01"; // assume one minute past midnight
84 } else {
85 // remove whitespace that is internal to the time
86 time.erase(find_if(time.begin(), time.end(), isspace));
87 }
88
89 // create a proper chrono from it
90 std::chrono::year_month_day ymd(year, month, day);
91
92 // convert to iso8601 string to get to DateAndTime
93 std::stringstream isostr;
94 isostr << ymd << "T" << time;
95
96 // convert to a proper object
97 release.setFromISO8601(isostr.str());
98 } // otherwise it will remain the default value
99 }
100 return release;
101}
102
103const std::string DOI{"http://dx.doi.org/10.1016/j.nima.2014.07.029"};
104const std::string VERSION_FULL{"6.14.20260127.2059.dev78"};
105const std::string VERSION_SHORT{"6.14"};
106const std::string REVISION_SHORT{"g5ce2ef3fa27"};
107const std::string REVISION_FULL{"5ce2ef3fa273feb1e9f4e5a5d3ed2fd61af7226c"};
108const Types::Core::DateAndTime REVISION_DATE_AND_TIME = create_releaseDateAndTime();
109
110} // namespace
111
117const std::string &MantidVersion::version() { return VERSION_FULL; }
118
119const std::string &MantidVersion::versionShort() { return VERSION_SHORT; }
120
122 return {"6", "14", "20260127.2059", ".dev78"};
123}
124
126 // Convert here in those cases where patch number is of the form "20131022.1356".
127 const unsigned long patchVersion = std::stoul(version.patch);
128 // For major/minor/patch/rc/local releases we point users to a specific release-notes.
129 // For dev and nightly versions we point to the next main release notes.
130 // We assume that the next main release version number will be one minor version higher.
131
132 std::stringstream versionLabel;
133
134 if ((patchVersion < 100 && version.tweak.empty()) || version.tweak[0] == '+' || version.tweak.substr(0, 2) == "rc") {
135 versionLabel << version.major << "." << version.minor;
136 versionLabel << "." << patchVersion;
137 } else {
138 const unsigned long minorVersion = std::stoul(version.minor);
139 versionLabel << version.major << "." << minorVersion + 1 << "." << "0";
140 }
141
142 return versionLabel.str();
143}
144
146 const std::string STEM = "release/v";
147 const std::string END = "/index.html";
148
149 std::stringstream url;
150
151 url << STEM << versionForReleaseNotes(versionInfo()) << END;
152
153 return url.str();
154}
155
156const std::string &MantidVersion::revision() { return REVISION_SHORT; }
157
158const std::string &MantidVersion::revisionFull() { return REVISION_FULL; }
159
160Types::Core::DateAndTime MantidVersion::releaseDateAndTime() {
161 return REVISION_DATE_AND_TIME;
162}
163
165 const std::string GIT_DATE_FMT("%a, %e %b %Y");
166 const auto release = releaseDateAndTime();
167 return release.toFormattedString(GIT_DATE_FMT);
168}
169
170std::string MantidVersion::doi() {
171 const std::string MAIN = "http://dx.doi.org/10.5286/Software/Mantid";
172 // Cast here in those cases where patch number is of the form 20131022.1356.
173 const unsigned int patchVersion = static_cast<unsigned int>(20260127.2059);
174
175 // For major/minor/patch releases we point users to a specific release-notes DOI, for
176 // dev versions we just point to the main DOI. A simple way to see whether or not
177 // we're currently in a dev version is to check if the patch version is larger than
178 // some arbitrarily low value.
179 const std::string tweakVersion(".dev78");
180 // cppcheck-suppress knownConditionTrueFalse
181 if (patchVersion > 100 || !tweakVersion.empty())
182 return MAIN;
183
184 std::stringstream doi;
185 doi << MAIN << 6 << "." << 14;
186
187 // Keep to the convention where we write a version number like "3.0.0" as "3.0".
188 if (patchVersion != 0)
189 doi << "." << patchVersion;
190
191 return doi.str();
192}
193
194const std::string &MantidVersion::paperCitation() { return DOI; }
195
196} // namespace Mantid::Kernel
static const std::string & revision()
The abbreviated SHA-1 of the last commit.
static const std::string & version()
The full version number.
static const VersionInfo versionInfo()
A data structure containing the full version info.
static std::string doi()
The DOI for this release of Mantid.
static Types::Core::DateAndTime releaseDateAndTime()
The DateAndTime of the last commit.
static std::string releaseDate()
The date of the last commit.
static const std::string & paperCitation()
The citation for the Mantid paper.
static std::string releaseNotes()
The url to the most applicable release notes.
static std::string versionForReleaseNotes(const VersionInfo &)
The version of mantid for the release notes url.
static const std::string & versionShort()
The version number of the last full version.
static const std::string & revisionFull()
The full SHA-1 of the last commit.