-
Notifications
You must be signed in to change notification settings - Fork 552
/
build_version.sh
executable file
·54 lines (46 loc) · 1.83 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
#!/usr/bin/env bash
BUILD_DATE_TIME=`date`
BUILD_HOSTNAME=`hostname`
BUILD_GCC_VERSION=`gcc --version | head -n 1`
gen_info_template_header ()
{
echo "// Generated by the build_version.sh. DO NOT EDIT!"
echo " "
echo "#include <iostream>"
echo "#include \"version.h\""
echo "const char kGitInfo[] = \"\\"
}
gen_info_template_foot ()
{
echo "\";"
echo "const char kBuildTime[] = \"$BUILD_DATE_TIME\";"
echo "const char kBuilderName[] = \"$USER\";"
echo "const char kHostName[] = \"$BUILD_HOSTNAME\";"
}
gen_info_print_template ()
{
echo "void PrintSystemVersion() {"
echo " std::cout << \"Baidu File System v\" << kMajorVersion << \".\" << kMinorVersion << \".\" << kRevision << std::endl;"
echo " std::cout << \"===== Git Info ===== \" << std::endl;"
echo " std::cout << kGitInfo << std::endl;"
echo " std::cout << \"===== Build Info ===== \" << std::endl;"
echo " std::cout << \"Build Time: \" << kBuildTime << std::endl;"
echo " std::cout << \"Builder Name: \" << kBuilderName << std::endl;"
echo " std::cout << \"Build Host Name: \" << kHostName << std::endl;"
echo " std::cout << \"Build Compiler: \" << kCompiler << std::endl;"
echo " std::cout << 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 remote -v | sed 's/$/&\\n\\/g' > $GIT_INFO_FILE
git log | head -n 3 | 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