A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
version.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Lawrence Livermore National Laboratory
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Mathew Bielejeski <bielejeski1@llnl.gov>
7 */
8
9#ifndef BUILD_VERSION_H_
10#define BUILD_VERSION_H_
11
12#include "int64x64.h"
13
14#include <string>
15
16/**
17 * \file
18 * \ingroup buildversion
19 * class ns3::Version definition
20 */
21
22namespace ns3
23{
24
25/**
26 * \ingroup core
27 * \defgroup buildversion Build version reporting
28 *
29 * Version information is pulled from the local git repository during the build
30 * process. If a git repository is not found, the build system will search for
31 * a file named version.cache under the src/core directory. The version.cache
32 * file must contain key/value pairs in the format key=value with one entry per
33 * line. The build system will use the data pulled from the git repository, or
34 * loaded from the version.cache file, to generate the file version-defines.h
35 *
36 * The build will fail if a local git repository is not present and
37 * a version.cache file can not be found.
38 */
39
40/**
41 * \ingroup buildversion
42 *
43 * Helper class providing functions to access various parts of the version
44 * string, as well as functions for composing short and long variants of the
45 * version string.
46 *
47 * See CommandLine::PrintVersion() for an example on how to
48 * use Version to output a version string. command-line-example has been updated
49 * to include CommandLine::PrintVersion() in its output
50 *
51 * build-version-example.cc illustrates using each of these functions.
52 *
53 * Below is a partial view of a git branch:
54 *
55 * \note Square nodes represent tags
56 * \note Circle nodes represent commits
57 *
58 * \dot
59 * digraph {
60 * vt [label="ns-3.32", shape="box"]
61 * t [label="mytag", shape="box"]
62 * h [label="HEAD", shape="box"]
63 * c1 [label="6ad7f05"]
64 * c2 [label="05fc891"]
65 * c3 [label="bd9ffac"]
66 * c4 [label="70fa23b"]
67 *
68 * h -> c1 -> c2 -> c3 -> c4
69 * t -> c2
70 * vt -> c4
71 * }
72 * \enddot
73 *
74 * Here are the values that will be assigned based on this example branch:
75 *
76 * | Component | Value | Notes |
77 * |--------------------|----------|-------|
78 * | VersionTag | ns-3.32 | |
79 * | ClosestAncestorTag | mytag | |
80 * | Major | 3 | |
81 * | Minor | 32 | |
82 * | Patch | 0 | This version tag does not have a patch field |
83 * | ReleaseCandidate | "" | This version tag does not have a release candidate field |
84 * | TagDistance | 1 | |
85 * | CommitHash | g6ad7f05 | g at front of hash indicates a git hash |
86 * | DirtyWorkingTree | Variable | Depends on status of git working and stage areas |
87 * | BuildProfile | Variable | Depends on the value of --build-profile option of ns3 configure
88 * |
89 */
91{
92 public:
93 /**
94 * Returns the ns-3 version tag of the closest ancestor commit.
95 *
96 * The format of the tag is
97 * \verbatim ns3-<major>.<minor>[.patch] \endverbatim
98 *
99 * The patch field is optional and may not be present. The value of
100 * patch defaults to 0 if the tag does not have a patch field.
101 *
102 * \return ns-3 version tag
103 */
104 static std::string VersionTag();
105
106 /**
107 * Returns the closest tag that is attached to a commit that is an ancestor
108 * of the current branch head.
109 *
110 * The value returned by this function may be the same as VersionTag()
111 * if the ns-3 version tag is the closest ancestor tag.
112 *
113 * \return Closest tag attached to an ancestor of the current commit
114 */
115 static std::string ClosestAncestorTag();
116
117 /**
118 * Major component of the build version
119 *
120 * The format of the build version string is
121 * \verbatim ns-<major>.<minor>[.patch][-RC<digit>] \endverbatim
122 *
123 * The major component is the number before the first period
124 *
125 * \return The major component of the build version
126 */
127 static uint32_t Major();
128
129 /**
130 * Minor component of the build version
131 *
132 * The format of the build version string is
133 * \verbatim ns-<major>.<minor>[.patch][-RC<digit>] \endverbatim
134 *
135 * The minor component is the number after the first period
136 *
137 * \return The minor component of the build version
138 */
139 static uint32_t Minor();
140
141 /**
142 * Patch component of the build version
143 *
144 * A build version with a patch component will have the format
145 * \verbatim ns-<major>.<minor>.<patch> \endverbatim
146 *
147 * The patch component is the number after the second period
148 *
149 * \return The patch component of the build version or 0 if the build version
150 * does not have a patch component
151 */
152 static uint32_t Patch();
153
154 /**
155 * Release candidate component of the build version
156 *
157 * A build version with a release candidate will have the format
158 * \verbatim ns-<major>.<minor>[.patch]-RC<digit> \endverbatim
159 *
160 * The string returned by this function will have the format RC<digit>
161 *
162 * \return The release candidate component of the build version or an empty
163 * string if the build version does not have a release candidate component
164 */
165 static std::string ReleaseCandidate();
166
167 /**
168 * The number of commits between the current
169 * commit and the tag returned by ClosestAncestorTag().
170 *
171 * \return The number of commits made since the last tagged commit
172 */
173 static uint32_t TagDistance();
174
175 /**
176 * Indicates whether there were uncommitted changes during the build
177 *
178 * \return \c true if the working tree had uncommitted changes.
179 */
180 static bool DirtyWorkingTree();
181
182 /**
183 * Hash of the most recent commit
184 *
185 * The hash component is the id of the most recent commit.
186 * The returned value is a hexadecimal string with enough data to
187 * uniquely identify the commit.
188 *
189 * The first character of the string is a letter indicating the type
190 * of repository that was in use: g=git
191 *
192 * Example of hash output: g6bfb0c9
193 *
194 * \return hexadecimal representation of the most recent commit id
195 */
196 static std::string CommitHash();
197
198 /**
199 * Indicates the type of build that was performed (debug/release/optimized).
200 *
201 * This information is set by the --build-profile option of ns3 configure
202 *
203 * \return String containing the type of build
204 */
205 static std::string BuildProfile();
206
207 /**
208 * Constructs a string containing the ns-3 major and minor version components,
209 * and indication of additional commits or dirty status.
210 *
211 * The format of the constructed string is
212 * \verbatim ns-<major>.<minor>[.patch][-rc]<flags> \endverbatim
213 *
214 * * [patch] is included when Patch() > 0.
215 * * [-rc] is included when ReleaseCandidate() contains a non-empty string
216 * * \c flags will contain `+` when TagDistance() > 0
217 * * \c flags will contain `*` when DirtyWorkingTree() == true.
218 *
219 * [flags] will contain none, one, or both characters depending on the state
220 * of the branch
221 *
222 * \return String containing the ns-3 major and minor components and flags.
223 */
224 static std::string ShortVersion();
225
226 /**
227 * Constructs a string containing the most recent tag and status flags.
228 *
229 * In the case where closest-ancestor-tag == version-tag, the output of this
230 * function will be the same as ShortVersion()
231 *
232 * The format of the constructed string is `<closest-ancestor-tag>[flags]`.
233 *
234 * * \c flags will contain `+` when TagDistance() > 0
235 * * \c flags will contain `*` when DirtyWorkingTree() == true.
236 *
237 * [flags] will contain none, one, or both characters depending on the state
238 * of the branch
239 *
240 * \return String containing the closest ancestor tag and flags.
241 */
242 static std::string BuildSummary();
243
244 /**
245 * Constructs a string containing all of the build details
246 *
247 * The format of the constructed string is
248 * \verbatim
249 * ns-<major>.<minor>[.patch][-rc][-closest-tag]-<tag-distance>@<hash>[-dirty]-<build-profile>
250 * \endverbatim
251 *
252 * [patch], [rc], [closest-tag], and [dirty] will only be present under certain circumstances:
253 * * [patch] is included when Patch() > 0
254 * * [rc] is included when ReleaseCandidate() is not an empty string
255 * * [closest-tag] is included when ClosestTag() != VersionTag()
256 * * [dirty] is included when DirtyWorkingTree() is \c true
257 *
258 * \return String containing full version
259 */
260 static std::string LongVersion();
261
262}; // class Version
263
264} // namespace ns3
265
266#endif
Helper class providing functions to access various parts of the version string, as well as functions ...
Definition version.h:91
static uint32_t Patch()
Patch component of the build version.
Definition version.cc:49
static std::string CommitHash()
Hash of the most recent commit.
Definition version.cc:73
static uint32_t Major()
Major component of the build version.
Definition version.cc:37
static uint32_t TagDistance()
The number of commits between the current commit and the tag returned by ClosestAncestorTag().
Definition version.cc:61
static std::string BuildProfile()
Indicates the type of build that was performed (debug/release/optimized).
Definition version.cc:79
static std::string ReleaseCandidate()
Release candidate component of the build version.
Definition version.cc:55
static uint32_t Minor()
Minor component of the build version.
Definition version.cc:43
static std::string BuildSummary()
Constructs a string containing the most recent tag and status flags.
Definition version.cc:104
static bool DirtyWorkingTree()
Indicates whether there were uncommitted changes during the build.
Definition version.cc:67
static std::string ShortVersion()
Constructs a string containing the ns-3 major and minor version components, and indication of additio...
Definition version.cc:85
static std::string LongVersion()
Constructs a string containing all of the build details.
Definition version.cc:122
static std::string VersionTag()
Returns the ns-3 version tag of the closest ancestor commit.
Definition version.cc:25
static std::string ClosestAncestorTag()
Returns the closest tag that is attached to a commit that is an ancestor of the current branch head.
Definition version.cc:31
Declaration of the ns3::int64x64_t type and associated operators.
Every class exported by the ns3 library is enclosed in the ns3 namespace.