Skip to content

Commit fc895d7

Browse files
committed
Merge #18616: refactor: Cleanup clientversion.cpp
c269e61 Drop unused GIT_COMMIT_DATE macro (Hennadii Stepanov) 8f9f4ba refactor: Remove duplicated code (Hennadii Stepanov) 35f1189 build: Rename BUILD_* macros and the code self-descriptive (Hennadii Stepanov) dc1fba9 scripted-diff: Rename share/genbuild.sh macros to more meaningful ones (Hennadii Stepanov) 1e06bb6 Drop unused CLIENT_VERSION_SUFFIX macro (Hennadii Stepanov) Pull request description: This PR: - removes unused macros and duplicated code - renames macros in a way, that makes the code self-descriptive. ACKs for top commit: dongcarl: Yup! ACK c269e61 Tree-SHA512: c469f6269b578ccfae33d960e317eca8efaf27d49638f4c3830948c11b12ef728494d7e18c31e4a410945b7d83af5b246c7b83661b4eca17cf41ee4c4583649b
2 parents 5d18c0a + c269e61 commit fc895d7

File tree

2 files changed

+28
-53
lines changed

2 files changed

+28
-53
lines changed

share/genbuild.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@ else
1818
exit 1
1919
fi
2020

21-
DESC=""
22-
SUFFIX=""
21+
GIT_TAG=""
22+
GIT_COMMIT=""
2323
if [ "${BITCOIN_GENBUILD_NO_GIT}" != "1" ] && [ -e "$(command -v git)" ] && [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then
2424
# clean 'dirty' status of touched files that haven't been modified
2525
git diff >/dev/null 2>/dev/null
2626

2727
# if latest commit is tagged and not dirty, then override using the tag name
2828
RAWDESC=$(git describe --abbrev=0 2>/dev/null)
2929
if [ "$(git rev-parse HEAD)" = "$(git rev-list -1 $RAWDESC 2>/dev/null)" ]; then
30-
git diff-index --quiet HEAD -- && DESC=$RAWDESC
30+
git diff-index --quiet HEAD -- && GIT_TAG=$RAWDESC
3131
fi
3232

3333
# otherwise generate suffix from git, i.e. string like "59887e8-dirty"
34-
SUFFIX=$(git rev-parse --short HEAD)
35-
git diff-index --quiet HEAD -- || SUFFIX="$SUFFIX-dirty"
34+
GIT_COMMIT=$(git rev-parse --short HEAD)
35+
git diff-index --quiet HEAD -- || GIT_COMMIT="$GIT_COMMIT-dirty"
3636
fi
3737

38-
if [ -n "$DESC" ]; then
39-
NEWINFO="#define BUILD_DESC \"$DESC\""
40-
elif [ -n "$SUFFIX" ]; then
41-
NEWINFO="#define BUILD_SUFFIX $SUFFIX"
38+
if [ -n "$GIT_TAG" ]; then
39+
NEWINFO="#define BUILD_GIT_TAG \"$GIT_TAG\""
40+
elif [ -n "$GIT_COMMIT" ]; then
41+
NEWINFO="#define BUILD_GIT_COMMIT \"$GIT_COMMIT\""
4242
else
4343
NEWINFO="// No build information available"
4444
fi

src/clientversion.cpp

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,59 +14,34 @@
1414
*/
1515
const std::string CLIENT_NAME("Satoshi");
1616

17-
/**
18-
* Client version number
19-
*/
20-
#define CLIENT_VERSION_SUFFIX ""
21-
22-
23-
/**
24-
* The following part of the code determines the CLIENT_BUILD variable.
25-
* Several mechanisms are used for this:
26-
* * first, if HAVE_BUILD_INFO is defined, include build.h, a file that is
27-
* generated by the build environment, possibly containing the output
28-
* of git-describe in a macro called BUILD_DESC
29-
* * secondly, if this is an exported version of the code, GIT_ARCHIVE will
30-
* be defined (automatically using the export-subst git attribute), and
31-
* GIT_COMMIT will contain the commit id.
32-
* * then, three options exist for determining CLIENT_BUILD:
33-
* * if BUILD_DESC is defined, use that literally (output of git-describe)
34-
* * if not, but GIT_COMMIT is defined, use v[maj].[min].[rev].[build]-g[commit]
35-
* * otherwise, use v[maj].[min].[rev].[build]-unk
36-
* finally CLIENT_VERSION_SUFFIX is added
37-
*/
3817

39-
//! First, include build.h if requested
4018
#ifdef HAVE_BUILD_INFO
4119
#include <obj/build.h>
20+
// The <obj/build.h>, which is generated by the build environment (share/genbuild.sh),
21+
// could contain only one line of the following:
22+
// - "#define BUILD_GIT_TAG ...", if the top commit is tagged
23+
// - "#define BUILD_GIT_COMMIT ...", if the top commit is not tagged
24+
// - "// No build information available", if proper git information is not available
4225
#endif
4326

44-
//! git will put "#define GIT_ARCHIVE 1" on the next line inside archives. $Format:%n#define GIT_ARCHIVE 1$
45-
#ifdef GIT_ARCHIVE
46-
#define GIT_COMMIT_ID "$Format:%H$"
47-
#define GIT_COMMIT_DATE "$Format:%cD$"
48-
#endif
49-
50-
#define BUILD_DESC_WITH_SUFFIX(maj, min, rev, build, suffix) \
51-
"v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-" DO_STRINGIZE(suffix)
52-
53-
#define BUILD_DESC_FROM_COMMIT(maj, min, rev, build, commit) \
54-
"v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-g" commit
27+
//! git will put "#define GIT_COMMIT_ID ..." on the next line inside archives. $Format:%n#define GIT_COMMIT_ID "%H"$
5528

56-
#define BUILD_DESC_FROM_UNKNOWN(maj, min, rev, build) \
57-
"v" DO_STRINGIZE(maj) "." DO_STRINGIZE(min) "." DO_STRINGIZE(rev) "." DO_STRINGIZE(build) "-unk"
58-
59-
#ifndef BUILD_DESC
60-
#ifdef BUILD_SUFFIX
61-
#define BUILD_DESC BUILD_DESC_WITH_SUFFIX(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, BUILD_SUFFIX)
62-
#elif defined(GIT_COMMIT_ID)
63-
#define BUILD_DESC BUILD_DESC_FROM_COMMIT(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD, GIT_COMMIT_ID)
29+
#ifdef BUILD_GIT_TAG
30+
#define BUILD_DESC BUILD_GIT_TAG
31+
#define BUILD_SUFFIX ""
6432
#else
65-
#define BUILD_DESC BUILD_DESC_FROM_UNKNOWN(CLIENT_VERSION_MAJOR, CLIENT_VERSION_MINOR, CLIENT_VERSION_REVISION, CLIENT_VERSION_BUILD)
66-
#endif
33+
#define BUILD_DESC "v" STRINGIZE(CLIENT_VERSION_MAJOR) "." STRINGIZE(CLIENT_VERSION_MINOR) \
34+
"." STRINGIZE(CLIENT_VERSION_REVISION) "." STRINGIZE(CLIENT_VERSION_BUILD)
35+
#ifdef BUILD_GIT_COMMIT
36+
#define BUILD_SUFFIX "-" BUILD_GIT_COMMIT
37+
#elif defined(GIT_COMMIT_ID)
38+
#define BUILD_SUFFIX "-g" GIT_COMMIT_ID
39+
#else
40+
#define BUILD_SUFFIX "-unk"
41+
#endif
6742
#endif
6843

69-
const std::string CLIENT_BUILD(BUILD_DESC CLIENT_VERSION_SUFFIX);
44+
const std::string CLIENT_BUILD(BUILD_DESC BUILD_SUFFIX);
7045

7146
static std::string FormatVersion(int nVersion)
7247
{

0 commit comments

Comments
 (0)