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{"Thu, 24 Sep 2026 15:49:33 +0100"};
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{"https://doi.org/10.1016/j.nima.2014.07.029"};
104const std::string VERSION_FULL{"0.0.0"};
105const std::string VERSION_SHORT{"0.0"};
106const std::string REVISION_SHORT{"gd918b07b"};
107const std::string REVISION_FULL{"d918b07b02c04ff17c2d0ba9f91279caf2f35820"};
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 {"0", "0", "0", ""};
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
129 // A development/nightly version has either a .dev suffix or date-based patch.
130 const bool isDevelopmentVersion = version.tweak.starts_with(".dev") || patchVersion > 100;
131
132 // Released versions and release candidates point to their own release notes.
133 if (!isDevelopmentVersion) {
134 std::stringstream versionLabel;
135 versionLabel << version.major << "." << version.minor << "." << patchVersion;
136 return versionLabel.str();
137 }
138
139 // Development and nightly versions point to the next release's notes.
140 // Normally this is the next minor version, except when the next release is a major version.
141 if (version.major == "6" && version.minor == "16") {
142 // The next release after 6.16 is 7.0, rather than 6.17.
143 return "7.0.0";
144 }
145
146 const unsigned long minorVersion = std::stoul(version.minor);
147 std::stringstream nextMinorVersionLabel;
148 nextMinorVersionLabel << version.major << "." << minorVersion + 1 << ".0";
149
150 return nextMinorVersionLabel.str();
151}
152
154 const std::string STEM = "release/v";
155 const std::string END = "/index.html";
156
157 std::stringstream url;
158
159 url << STEM << versionForReleaseNotes(versionInfo()) << END;
160
161 return url.str();
162}
163
164const std::string &MantidVersion::revision() { return REVISION_SHORT; }
165
166const std::string &MantidVersion::revisionFull() { return REVISION_FULL; }
167
168Types::Core::DateAndTime MantidVersion::releaseDateAndTime() {
169 return REVISION_DATE_AND_TIME;
170}
171
173 const std::string GIT_DATE_FMT("%a, %e %b %Y");
174 const auto release = releaseDateAndTime();
175 return release.toFormattedString(GIT_DATE_FMT);
176}
177
178std::string MantidVersion::doi() {
179 const std::string MAIN = "https://doi.org/10.5286/Software/Mantid";
180 // Cast here in those cases where patch number is of the form 20131022.1356.
181 const unsigned int patchVersion = static_cast<unsigned int>(0);
182
183 // For major/minor/patch releases we point users to a specific release-notes DOI, for
184 // dev versions we just point to the main DOI. A simple way to see whether or not
185 // we're currently in a dev version is to check if the patch version is larger than
186 // some arbitrarily low value.
187 const std::string tweakVersion("");
188 // cppcheck-suppress knownConditionTrueFalse
189 if (patchVersion > 100 || !tweakVersion.empty())
190 return MAIN;
191
192 std::stringstream doi;
193 doi << MAIN << 0 << "." << 0;
194
195 // Keep to the convention where we write a version number like "3.0.0" as "3.0".
196 if (patchVersion != 0)
197 doi << "." << patchVersion;
198
199 return doi.str();
200}
201
202const std::string &MantidVersion::paperCitation() { return DOI; }
203
204} // 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.