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