Skip to content

Commit a20c0d0

Browse files
committed
Build identification strings
All client version information is moved to version.cpp, which optionally (-DHAVE_BUILD_INFO) includes build.h. build.h is automatically generated on supporting platforms via contrib/genbuild.sh, using git describe. The git export-subst attribute is used to put the commit id statically in version.cpp inside generated archives, and this value is used if no build.h is present. The gitian descriptors are modified to use git archive instead of a copy, to create the src/ directory in the output. This way, src/src/version.cpp will contain the static commit id. To prevent gitian builds from getting the "-dirty" marker in their git-describe generated identifiers, no touching of files or running sed on the makefile is performed anymore. This does not seem to influence determinism.
1 parent 138d08c commit a20c0d0

20 files changed

+193
-31
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/version.cpp export-subst

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
src/*.exe
22
src/bitcoin
33
src/bitcoind
4+
src/build.h
45
.*.swp
56
*.*~*
67
*.bak

bitcoin-qt.pro

+10
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ contains(BITCOIN_NEED_QT_PLUGINS, 1) {
8080
# do not enable this on windows, as it will result in a non-working executable!
8181
}
8282

83+
# regenerate src/build.h
84+
!windows || contains(USE_BUILD_INFO, 1) {
85+
genbuild.commands = share/genbuild.sh src/build.h
86+
genbuild.target = src/build.h
87+
"src/version.cpp".depends += src/build.h
88+
QMAKE_EXTRA_TARGETS += genbuild
89+
DEFINES += HAVE_BUILD_INFO
90+
}
91+
8392
# disable quite some warnings because bitcoin core "sins" a lot
8493
QMAKE_CXXFLAGS_WARN_ON = -fdiagnostics-show-option -Wall -Wno-strict-aliasing -Wno-invalid-offsetof -Wno-unused-variable -Wno-unused-parameter -Wno-sign-compare -Wno-char-subscripts -Wno-unused-value -Wno-sequence-point -Wno-parentheses -Wno-unknown-pragmas -Wno-switch
8594

@@ -161,6 +170,7 @@ SOURCES += src/qt/bitcoin.cpp src/qt/bitcoingui.cpp \
161170
src/qt/aboutdialog.cpp \
162171
src/qt/editaddressdialog.cpp \
163172
src/qt/bitcoinaddressvalidator.cpp \
173+
src/version.cpp \
164174
src/util.cpp \
165175
src/netbase.cpp \
166176
src/key.cpp \

contrib/gitian-descriptors/gitian-win32.yml

+12-7
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,30 @@ script: |
4545
#
4646
cd bitcoin
4747
mkdir -p $OUTDIR/src
48-
cp -a . $OUTDIR/src
49-
rm -rf $OUTDIR/src/.git
48+
git archive HEAD | tar -x -C $OUTDIR/src
5049
cp $OUTDIR/src/doc/README_windows.txt $OUTDIR/readme.txt
5150
cp $OUTDIR/src/COPYING $OUTDIR/license.txt
5251
export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1
5352
export FAKETIME=$REFERENCE_DATETIME
5453
export TZ=UTC
55-
$HOME/qt/src/bin/qmake -spec unsupported/win32-g++-cross MINIUPNPC_LIB_PATH=$HOME/build/miniupnpc MINIUPNPC_INCLUDE_PATH=$HOME/build/ BDB_LIB_PATH=$HOME/build/db-4.8.30.NC/build_unix BDB_INCLUDE_PATH=$HOME/build/db-4.8.30.NC/build_unix BOOST_LIB_PATH=$HOME/build/boost_1_47_0/stage/lib BOOST_INCLUDE_PATH=$HOME/build/boost_1_47_0 BOOST_LIB_SUFFIX=-mt-s BOOST_THREAD_LIB_SUFFIX=_win32-mt-s OPENSSL_LIB_PATH=$HOME/build/openssl-1.0.0e OPENSSL_INCLUDE_PATH=$HOME/build/openssl-1.0.0e/include QRENCODE_LIB_PATH=$HOME/build/qrencode-3.2.0/.libs QRENCODE_INCLUDE_PATH=$HOME/build/qrencode-3.2.0 USE_QRCODE=1 INCLUDEPATH=$HOME/build DEFINES=BOOST_THREAD_USE_LIB BITCOIN_NEED_QT_PLUGINS=1 QMAKE_LRELEASE=lrelease QMAKE_CXXFLAGS=-frandom-seed=bitcoin QMAKE_LFLAGS=-frandom-seed=bitcoin
54+
$HOME/qt/src/bin/qmake -spec unsupported/win32-g++-cross MINIUPNPC_LIB_PATH=$HOME/build/miniupnpc MINIUPNPC_INCLUDE_PATH=$HOME/build/ BDB_LIB_PATH=$HOME/build/db-4.8.30.NC/build_unix BDB_INCLUDE_PATH=$HOME/build/db-4.8.30.NC/build_unix BOOST_LIB_PATH=$HOME/build/boost_1_47_0/stage/lib BOOST_INCLUDE_PATH=$HOME/build/boost_1_47_0 BOOST_LIB_SUFFIX=-mt-s BOOST_THREAD_LIB_SUFFIX=_win32-mt-s OPENSSL_LIB_PATH=$HOME/build/openssl-1.0.0e OPENSSL_INCLUDE_PATH=$HOME/build/openssl-1.0.0e/include QRENCODE_LIB_PATH=$HOME/build/qrencode-3.2.0/.libs QRENCODE_INCLUDE_PATH=$HOME/build/qrencode-3.2.0 USE_QRCODE=1 INCLUDEPATH=$HOME/build DEFINES=BOOST_THREAD_USE_LIB BITCOIN_NEED_QT_PLUGINS=1 QMAKE_LRELEASE=lrelease QMAKE_CXXFLAGS=-frandom-seed=bitcoin QMAKE_LFLAGS=-frandom-seed=bitcoin USE_BUILD_INFO=1
5655
make $MAKEOPTS
5756
cp release/bitcoin-qt.exe $OUTDIR/
5857
#
5958
cd src
60-
sed 's/$(DEBUGFLAGS)/-frandom-seed=bitcoin/' -i makefile.linux-mingw
6159
export LD_PRELOAD=/usr/lib/faketime/libfaketime.so.1
6260
export FAKETIME=$REFERENCE_DATETIME
6361
export TZ=UTC
64-
make -f makefile.linux-mingw $MAKEOPTS DEPSDIR=$HOME/build bitcoind.exe USE_UPNP=0
62+
make -f makefile.linux-mingw $MAKEOPTS DEPSDIR=$HOME/build bitcoind.exe USE_UPNP=0 DEBUGFLAGS="-frandom-seed=bitcoin"
6563
i586-mingw32msvc-strip bitcoind.exe
66-
makensis ../share/setup.nsi
67-
cp ../share/bitcoin-*-win32-setup.exe $OUTDIR/
6864
mkdir $OUTDIR/daemon
6965
cp bitcoind.exe $OUTDIR/daemon
66+
cd ..
67+
mkdir nsis
68+
git archive HEAD | tar -x -C nsis
69+
cd nsis/src
70+
mkdir ../release
71+
cp ../../release/* ../release/
72+
cp ../../src/*.exe .
73+
makensis ../share/setup.nsi
74+
cp ../share/bitcoin-*-win32-setup.exe $OUTDIR/

contrib/gitian-descriptors/gitian.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ script: |
4242
#
4343
cd bitcoin
4444
mkdir -p $OUTDIR/src
45-
cp -a . $OUTDIR/src
46-
rm -rf $OUTDIR/src/.git
45+
git archive HEAD | tar -x -C $OUTDIR/src
4746
cp $OUTDIR/src/doc/README $OUTDIR
4847
cp $OUTDIR/src/COPYING $OUTDIR
4948
cd src
50-
sed 's/$(DEBUGFLAGS)//' -i makefile.unix
51-
make -f makefile.unix STATIC=1 OPENSSL_INCLUDE_PATH="$INSTDIR/include" OPENSSL_LIB_PATH="$INSTDIR/lib" $MAKEOPTS bitcoind USE_UPNP=0
49+
make -f makefile.unix STATIC=1 OPENSSL_INCLUDE_PATH="$INSTDIR/include" OPENSSL_LIB_PATH="$INSTDIR/lib" $MAKEOPTS bitcoind USE_UPNP=0 DEBUGFLAGS=
5250
mkdir -p $OUTDIR/bin/$GBUILD_BITS
5351
install -s bitcoind $OUTDIR/bin/$GBUILD_BITS
5452
cd ..

doc/release-process.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
* update (commit) version in sources
44
bitcoin-qt.pro
5-
src/main.h (CLIENT_VERSION : PROTOCOL_VERSION in serialize.h is updated only on protocol changes)
5+
src/version.cpp
66
share/setup.nsi
77
doc/README*
88

share/genbuild.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
3+
if [ $# -gt 0 ]; then
4+
FILE="$1"
5+
shift
6+
if [ -f "$FILE" ]; then
7+
INFO="$(head -n 1 "$FILE")"
8+
fi
9+
else
10+
echo "Usage: $0 <filename>"
11+
exit 1
12+
fi
13+
14+
if [ -e "$(which git)" ]; then
15+
# clean 'dirty' status of touched files that haven't been modified
16+
git diff >/dev/null 2>/dev/null
17+
18+
# get a string like "v0.6.0-66-g59887e8-dirty"
19+
DESC="$(git describe --dirty 2>/dev/null)"
20+
21+
# get a string like "2012-04-10 16:27:19 +0200"
22+
TIME="$(git log -n 1 --format="%ci")"
23+
fi
24+
25+
if [ -n "$DESC" ]; then
26+
NEWINFO="#define BUILD_DESC \"$DESC\""
27+
else
28+
NEWINFO="// No build information available"
29+
fi
30+
31+
# only update build.h if necessary
32+
if [ "$INFO" != "$NEWINFO" ]; then
33+
echo "$NEWINFO" >"$FILE"
34+
echo "#define BUILD_DATE \"$TIME\"" >>"$FILE"
35+
fi

src/init.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ bool AppInit2(int argc, char* argv[])
307307
if (!fDebug && !pszSetDataDir[0])
308308
ShrinkDebugFile();
309309
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
310-
printf("Bitcoin version %s\n", FormatFullVersion().c_str());
310+
printf("Bitcoin version %s (%s)\n", FormatFullVersion().c_str(), CLIENT_DATE.c_str());
311311
printf("Default data directory %s\n", GetDefaultDataDir().c_str());
312312

313313
if (GetBoolArg("-loadblockindextest"))

src/main.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ using namespace boost;
1818
// Global state
1919
//
2020

21-
// Name of client reported in the 'version' message. Report the same name
22-
// for both bitcoind and bitcoin-qt, to make it harder for attackers to
23-
// target servers or GUI users specifically.
24-
const std::string CLIENT_NAME("Satoshi");
25-
2621
CCriticalSection cs_setpwalletRegistered;
2722
set<CWallet*> setpwalletRegistered;
2823

src/main.h

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "key.h"
1111
#include "script.h"
1212
#include "db.h"
13+
#include "version.h"
1314

1415
#ifdef WIN32
1516
#include <io.h> /* for _commit */
@@ -30,10 +31,6 @@ class CInv;
3031
class CRequestTracker;
3132
class CNode;
3233

33-
static const int CLIENT_VERSION = 60099;
34-
static const bool VERSION_IS_BETA = true;
35-
extern const std::string CLIENT_NAME;
36-
3734
static const unsigned int MAX_BLOCK_SIZE = 1000000;
3835
static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/2;
3936
static const int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;

src/makefile.linux-mingw

+9-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ LIBS += -l mingwthrd -l kernel32 -l user32 -l gdi32 -l comdlg32 -l winspool -l w
4343
HEADERS = $(wildcard *.h)
4444

4545
OBJS= \
46+
obj/version.o \
4647
obj/checkpoints.o \
4748
obj/netbase.o \
4849
obj/addrman.o \
@@ -64,10 +65,14 @@ OBJS= \
6465

6566
all: bitcoind.exe
6667

68+
build.h: FORCE
69+
@../share/genbuild.sh build.h
70+
DEFS += -DHAVE_BUILD_INFO
71+
6772
obj/%.o: %.cpp $(HEADERS)
6873
i586-mingw32msvc-g++ -c $(CFLAGS) -o $@ $<
6974

70-
bitcoind.exe: $(OBJS:obj/%=obj/%)
75+
bitcoind.exe: build.h $(OBJS:obj/%=obj/%)
7176
i586-mingw32msvc-g++ $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
7277

7378

@@ -85,3 +90,6 @@ clean:
8590
-rm -f headers.h.gch
8691
-rm -f bitcoind.exe
8792
-rm -f test_bitcoin.exe
93+
-rm -f src/build.h
94+
95+
FORCE:

src/makefile.mingw

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ LIBS += -l kernel32 -l user32 -l gdi32 -l comdlg32 -l winspool -l winmm -l shell
4141
HEADERS = $(wildcard *.h)
4242

4343
OBJS= \
44+
obj/version.o \
4445
obj/checkpoints.o \
4546
obj/netbase.o \
4647
obj/addrman.o \
@@ -82,3 +83,4 @@ clean:
8283
-del /Q obj\test\*
8384
-del /Q test\*.o
8485
-del /Q headers.h.gch
86+
-del /Q build.h

src/makefile.osx

+9-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ CFLAGS += -Wextra -Wno-sign-compare -Wno-char-subscripts -Wno-invalid-offsetof -
6565
$(DEBUGFLAGS) $(DEFS) $(INCLUDEPATHS)
6666

6767
OBJS= \
68+
obj/version.o \
6869
obj/checkpoints.o \
6970
obj/netbase.o \
7071
obj/addrman.o \
@@ -99,14 +100,18 @@ all: bitcoind
99100
-include obj/*.P
100101
-include obj-test/*.P
101102

103+
build.h: FORCE
104+
@../share/genbuild.sh build.h
105+
DEFS += -DHAVE_BUILD_INFO
106+
102107
obj/%.o: %.cpp
103108
$(CXX) -c $(CFLAGS) -MMD -o $@ $<
104109
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
105110
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
106111
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
107112
rm -f $(@:%.o=%.d)
108113

109-
bitcoind: $(OBJS:obj/%=obj/%)
114+
bitcoind: build.h $(OBJS:obj/%=obj/%)
110115
$(CXX) $(CFLAGS) -o $@ $(LIBPATHS) $^ $(LIBS)
111116

112117
TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
@@ -127,3 +132,6 @@ clean:
127132
-rm -f obj-test/*.o
128133
-rm -f obj/*.P
129134
-rm -f obj-test/*.P
135+
-rm -f src/build.h
136+
137+
FORCE:

src/makefile.unix

+9-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ xCXXFLAGS=-pthread -Wextra -Wno-sign-compare -Wno-char-subscripts -Wno-invalid-o
8585
$(DEBUGFLAGS) $(DEFS) $(HARDENING) $(CXXFLAGS)
8686

8787
OBJS= \
88+
obj/version.o \
8889
obj/checkpoints.o \
8990
obj/netbase.o \
9091
obj/addrman.o \
@@ -111,14 +112,18 @@ all: bitcoind
111112
-include obj/*.P
112113
-include obj-test/*.P
113114

115+
build.h: FORCE
116+
@../share/genbuild.sh build.h
117+
DEFS += -DHAVE_BUILD_INFO
118+
114119
obj/%.o: %.cpp
115120
$(CXX) -c $(xCXXFLAGS) -MMD -o $@ $<
116121
@cp $(@:%.o=%.d) $(@:%.o=%.P); \
117122
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
118123
-e '/^$$/ d' -e 's/$$/ :/' < $(@:%.o=%.d) >> $(@:%.o=%.P); \
119124
rm -f $(@:%.o=%.d)
120125

121-
bitcoind: $(OBJS:obj/%=obj/%)
126+
bitcoind: build.h $(OBJS:obj/%=obj/%)
122127
$(CXX) $(xCXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
123128

124129
TESTOBJS := $(patsubst test/%.cpp,obj-test/%.o,$(wildcard test/*.cpp))
@@ -139,3 +144,6 @@ clean:
139144
-rm -f obj-test/*.o
140145
-rm -f obj/*.P
141146
-rm -f obj-test/*.P
147+
-rm -f src/build.h
148+
149+
FORCE:

src/qt/aboutdialog.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "ui_aboutdialog.h"
33
#include "clientmodel.h"
44

5+
#include "version.h"
6+
57
AboutDialog::AboutDialog(QWidget *parent) :
68
QDialog(parent),
79
ui(new Ui::AboutDialog)

src/qt/clientmodel.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,8 @@ QString ClientModel::formatFullVersion() const
8888
{
8989
return QString::fromStdString(FormatFullVersion());
9090
}
91+
92+
QString ClientModel::formatBuildDate() const
93+
{
94+
return QString::fromStdString(CLIENT_DATE);
95+
}

src/qt/clientmodel.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ClientModel : public QObject
3737
QString getStatusBarWarnings() const;
3838

3939
QString formatFullVersion() const;
40+
QString formatBuildDate() const;
4041

4142
private:
4243
OptionsModel *optionsModel;

src/util.cpp

+1-6
Original file line numberDiff line numberDiff line change
@@ -1061,12 +1061,7 @@ string FormatVersion(int nVersion)
10611061

10621062
string FormatFullVersion()
10631063
{
1064-
string s = FormatVersion(CLIENT_VERSION);
1065-
if (VERSION_IS_BETA) {
1066-
s += "-";
1067-
s += _("beta");
1068-
}
1069-
return s;
1064+
return CLIENT_BUILD;
10701065
}
10711066

10721067
// Format the subversion field according to BIP 14 spec (https://en.bitcoin.it/wiki/BIP_0014)

0 commit comments

Comments
 (0)