| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  | #include "revision_utils.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-18 22:32:27 +00:00
										 |  |  | #include <cstring>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  | #include <QCoreApplication>
 | 
					
						
							|  |  |  | #include <QRegularExpression>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-27 11:40:12 +00:00
										 |  |  | #include "scs_version.h"
 | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   QString revision_extract_number (QString const& s) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     QString revision; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-27 11:40:12 +00:00
										 |  |  |     // try and match a number (hexadecimal allowed)
 | 
					
						
							|  |  |  |     QRegularExpression re {R"(^[$:]\w+: (r?[\da-f]+[^$]*)\$$)"}; | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  |     auto match = re.match (s); | 
					
						
							|  |  |  |     if (match.hasMatch ()) | 
					
						
							|  |  |  |       { | 
					
						
							| 
									
										
										
										
											2018-05-27 11:40:12 +00:00
										 |  |  |         revision = match.captured (1); | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  |       } | 
					
						
							|  |  |  |     return revision; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-27 11:40:12 +00:00
										 |  |  | QString revision (QString const& scs_rev_string) | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  | { | 
					
						
							|  |  |  |   QString result; | 
					
						
							| 
									
										
										
										
											2018-05-27 11:40:12 +00:00
										 |  |  |   auto revision_from_scs = revision_extract_number (scs_rev_string); | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if defined (CMAKE_BUILD)
 | 
					
						
							| 
									
										
										
										
											2020-10-10 13:38:15 +01:00
										 |  |  |   QString scs_info {":Rev: " SCS_VERSION_STR " $"}; | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-27 11:40:12 +00:00
										 |  |  |   auto revision_from_scs_info = revision_extract_number (scs_info); | 
					
						
							|  |  |  |   if (!revision_from_scs_info.isEmpty ()) | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  |     { | 
					
						
							|  |  |  |       // we managed to get the revision number from svn info etc.
 | 
					
						
							| 
									
										
										
										
											2018-05-27 11:40:12 +00:00
										 |  |  |       result = revision_from_scs_info; | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-05-27 11:40:12 +00:00
										 |  |  |   else if (!revision_from_scs.isEmpty ()) | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-22 00:20:42 +00:00
										 |  |  |       // fall back to revision passed in if any
 | 
					
						
							| 
									
										
										
										
											2018-05-27 11:40:12 +00:00
										 |  |  |       result = revision_from_scs; | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       // match anything
 | 
					
						
							|  |  |  |       QRegularExpression re {R"(^[$:]\w+: ([^$]*)\$$)"}; | 
					
						
							| 
									
										
										
										
											2018-05-27 11:40:12 +00:00
										 |  |  |       auto match = re.match (scs_info); | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  |       if (match.hasMatch ()) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           result = match.captured (1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2018-05-27 11:40:12 +00:00
										 |  |  |   if (!revision_from_scs.isEmpty ()) | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2015-02-22 00:20:42 +00:00
										 |  |  |       // not CMake build so all we have is revision passed
 | 
					
						
							| 
									
										
										
										
											2018-05-27 11:40:12 +00:00
										 |  |  |       result = revision_from_scs; | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |   return result.trimmed (); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-24 11:41:05 +00:00
										 |  |  | QString version (bool include_patch) | 
					
						
							| 
									
										
										
										
											2015-02-22 00:20:42 +00:00
										 |  |  | { | 
					
						
							|  |  |  | #if defined (CMAKE_BUILD)
 | 
					
						
							| 
									
										
										
										
											2020-10-10 13:38:15 +01:00
										 |  |  |   QString v {TO_STRING__ (PROJECT_VERSION_MAJOR) "." TO_STRING__ (PROJECT_VERSION_MINOR)}; | 
					
						
							| 
									
										
										
										
											2015-12-24 11:41:05 +00:00
										 |  |  |   if (include_patch) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2020-10-10 13:38:15 +01:00
										 |  |  |       v += "." TO_STRING__ (PROJECT_VERSION_PATCH) + QString {BUILD_TYPE_REVISION}; | 
					
						
							| 
									
										
										
										
											2015-12-24 11:41:05 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-02-22 00:20:42 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  |   QString v {"Not for Release"}; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  |   return v; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  | QString program_title (QString const& revision) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2015-02-23 15:19:41 +00:00
										 |  |  |   QString id {QCoreApplication::applicationName () + "   v" + QCoreApplication::applicationVersion ()}; | 
					
						
							| 
									
										
										
										
											2022-06-19 11:04:49 +02:00
										 |  |  |   return id + " " + revision + "  by K1JT et al."; | 
					
						
							| 
									
										
										
										
											2014-04-13 17:22:12 +00:00
										 |  |  | } |