forked from baidu/tera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_version.sh
executable file
·66 lines (57 loc) · 2.21 KB
/
build_version.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
# If release a new version, modify these infos
VERSION_INFO="master"
VERSION_ADDR="https://github.com/baidu/tera"
BUILD_DATE_TIME=`date`
BUILD_HOSTNAME=`hostname`
gen_info_template_header ()
{
echo "#include <iostream>"
echo "#include <sstream>"
echo "#include <string>"
echo "#include \"version.h\""
echo "extern const char kGitInfo[] = \"\\"
}
gen_info_template_foot ()
{
echo "\";"
echo "extern const char kBuildType[] = \"debug\";"
echo "extern const char kBuildTime[] = \"$BUILD_DATE_TIME\";"
echo "extern const char kBuilderName[] = \"$USER\";"
echo "extern const char kHostName[] = \"$BUILD_HOSTNAME\";"
echo "extern const char kCompiler[] = __VERSION__;"
}
gen_info_print_template ()
{
echo "std::string SystemVersionInfo() {"
echo " std::stringstream ss;"
echo " ss << \"===== Version Info ===== \" << std::endl;"
echo " ss << \"Version: $VERSION_INFO\" << std::endl;"
echo " ss << \"Address: $VERSION_ADDR\" << std::endl;"
echo " ss << std::endl;"
echo " ss << \"===== Git Info ===== \" << std::endl;"
echo " ss << kGitInfo << std::endl;"
echo " ss << \"===== Build Info ===== \" << std::endl;"
echo " ss << \"Build Type: \" << kBuildType << std::endl;"
echo " ss << \"Build Time: \" << kBuildTime << std::endl;"
echo " ss << \"Builder Name: \" << kBuilderName << std::endl;"
echo " ss << \"Build Host Name: \" << kHostName << std::endl;"
echo " ss << \"Build Compiler: \" << kCompiler << std::endl;"
echo " return ss.str();"
echo "};"
echo "void PrintSystemVersion() {"
echo " std::cout << SystemVersionInfo() << std::endl;"
echo "};"
}
TEMPLATE_HEADER_FILE=template_header.tmp
TEMPLATE_FOOT_FILE=template_foot.tmp
GIT_INFO_FILE=git_info.tmp
VERSION_CPP_FILE=src/version.cc
# generate template file
git log | head -n 6 | sed 's/$/&\\n\\/g' > $GIT_INFO_FILE
gen_info_template_header > $TEMPLATE_HEADER_FILE
gen_info_template_foot > $TEMPLATE_FOOT_FILE
gen_info_print_template >> $TEMPLATE_FOOT_FILE
# generate version cpp
cat $TEMPLATE_HEADER_FILE $GIT_INFO_FILE $TEMPLATE_FOOT_FILE > $VERSION_CPP_FILE
rm -rf $TEMPLATE_HEADER_FILE $GIT_INFO_FILE $TEMPLATE_FOOT_FILE