-
Notifications
You must be signed in to change notification settings - Fork 6
/
build.sh
executable file
·132 lines (120 loc) · 2.32 KB
/
build.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh
self=$(cd `dirname $0`; pwd)
export GOPATH=$self
author="[email protected]"
gitbranch=`git status | head -n1 | awk '{print $NF}'`
githash=`git rev-parse HEAD`
githash="$githash@$gitbranch"
buildstamp=`date '+%Y-%m-%d_%I:%M:%S%p'`
build() {
go build -o $self/build/bin/$1 -v -i -ldflags "
-X common.author=$author
-X common.githash=$githash
-X common.buildstamp=$buildstamp" apps/$1
mkdir -p $self/build/etc \
&& cp $self/src/etc/* $self/build/etc/
}
check() {
go tool vet -all --composites=false -shadowstrict $self/src
}
clean() {
rm -rf $self/build
rm -rf $self/pkg
}
gotest() {
pkg=`grep package $1 | awk '{print $NF}'`
path=`find $self/src -name "$pkg"`
pkg=`echo $path | awk -v "b=$self/src/" '{print substr($1, length(b) + 1)}'`
cases=""
for t in `grep "func Test.*(t \*testing\.T)" $1 | awk -F "(" '{print $1}' | awk '{print $2}'`
do
t="^$t$"
if [ -z $cases ]
then
cases=$t
else
cases=$cases"|"$t
fi
done
go test $2 -run "$cases" $pkg
}
gotestdir() {
for i in `find ./ -name "*_test.go" | grep third -v`
do
echo "Testing "$i" ..."
gotest $i
if [ $? -ne 0 ]
then
exit $?
fi
echo
done
}
gotestall() {
for i in `find $self/src -name "*_test.go" | grep third -v`
do
echo "Testing [$i] ..."
gotest $i
if [ $? -ne 0 ]
then
exit $?
fi
echo
done
}
gobuildall() {
allpkgs=`find $self/src -type f | xargs grep "^package " | grep third -vw | awk '{print $NF}' | sort | uniq | grep main -v`
for pkg in $allpkgs
do
gobuildpkg $pkg
done
}
gobuildpkg() {
if [ -z $1 ]
then
pkg=`pwd | awk -F "/" '{print $NF}'`
else
pkg=$1
fi
path=`find $self/src -name "$pkg"`
pkg=`echo $path | awk -v "b=$self/src/" '{print substr($1, length(b) + 1)}'`
echo -n "Build [$pkg] ... "
go build $pkg
if [ $? -eq 0 ]
then
echo "[Success]"
else
echo "[Fail]"
exit $?
fi
}
if [ -z $1 ]
then
build eTunnel
elif [ "x$1" == "xcheck" ]
then
check
elif [ "x$1" == "xclean" ]
then
clean
elif [ "x$1" == "xtest" ]
then
if [ -z $2 ]
then
gotestdir
else
gotest $2 "-v"
fi
elif [ "x$1" == "xbuild" ]
then
gobuildpkg $2
elif [ "x$1" == "xtestall" ]
then
gotestall
elif [ "x$1" == "xbuildall" ]
then
gobuildall
else
echo "unknow parameter [$1]"
exit -1
fi