-
Notifications
You must be signed in to change notification settings - Fork 21
/
build.sh
executable file
·180 lines (164 loc) · 4.66 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
VER=0.3.2
GOVER=$(go version | cut -d' ' -f3 | cut -d'.' -f2)
GIT_ID=$(git rev-parse HEAD | cut -c1-7)
GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true)
BUILD_TIME=$(date '+%Y-%m-%d-%H:%M:%S')
GREEN="\033[33;32m"
RESET="\033[m"
INSTALL="no"
GCDEBUG="no"
RACE="no"
BENCHCMP="no"
BUILDALL="no"
BENCHALL="no"
FASTHTTP="no"
QA="no"
GOSTATUS="no"
VALIDATE="no"
TARGET="gk"
PREFIX=$GOPATH
show_line_of_code() {
find . -name '*.go' | xargs wc -l | sort -n | tail -1
#git ls-files | grep '.go$' | xargs wc -l | sort -n | tail -1
}
check_gofmt() {
GOFMT_LINES=`gofmt -l . | grep -v bindata.go | wc -l | xargs`
test $GOFMT_LINES -eq 0 || echo "gofmt needs to be run, ${GOFMT_LINES} files have issues"
}
validate() {
echo "validating..."
check_gofmt
if [ $GOVER -gt 4 ]; then
go test -race -cover $(go list ./... | grep -v '/bench' | grep -v '/demo' | grep -v '/misc' | grep -v '/client') -ldflags "-X github.com/funkygao/gafka.BuildId=${GIT_ID}${GIT_DIRTY} -w"
else
go test -race -cover $(go list ./... | grep -v '/bench' | grep -v '/demo' | grep -v '/misc' | grep -v '/client') -ldflags "-X github.com/funkygao/gafka.BuildId ${GIT_ID}${GIT_DIRTY} -w"
fi
}
show_usage() {
echo -e "build tool for gafka components"
echo -e "`printf %-18s "Usage: $0"` [-h] help"
echo -e "`printf %-18s ` [-a] build all executables"
echo -e "`printf %-18s ` [-b] benchmark all dependent pkgs"
echo -e "`printf %-18s ` [-c] benchmark compare current repo with last commit"
echo -e "`printf %-18s ` [-f] enable fasthttp pub"
echo -e "`printf %-18s ` [-g] enable gc compile output"
echo -e "`printf %-18s ` [-i] install"
echo -e "`printf %-18s ` [-l] display line of code"
echo -e "`printf %-18s ` [-p] install prefix path"
echo -e "`printf %-18s ` [-q] quality assurance of code"
echo -e "`printf %-18s ` [-r] enable data race detection"
echo -e "`printf %-18s ` [-s] gostatus checks dependent pkg status"
echo -e "`printf %-18s ` [-v] validate"
echo -e "`printf %-18s ` -t <target> `ls -Cm cmd`"
}
args=`getopt abcvqfgrhislt:p: $*`
[ $? != 0 ] && echo "hs" && show_usage && exit 1
set -- $args
for i
do
case "$i" in
-a):
BUILDALL="yes"; shift
;;
-b):
BENCHALL="yes"; shift
;;
-c):
BENCHCMP="yes"; shift
;;
-f):
FASTHTTP="yes"; shift
;;
-g):
GCDEBUG="yes"; shift
;;
-r):
RACE="yes"; shift
;;
-q)
QA="yes"; shift
;;
-h):
show_usage; exit 0
;;
-s)
GOSTATUS="yes"; shift
;;
-i)
INSTALL="yes"; shift
;;
-l)
show_line_of_code; exit 0
;;
-v)
VALIDATE="yes"; shift
;;
-p)
PREFIX=$2; shift 2
;;
-t)
TARGET=$2; shift 2
;;
esac
done
BUILD_FLAGS=''
if [ $RACE == "yes" ]; then
BUILD_FLAGS="$BUILD_FLAGS -race"
fi
if [ $GCDEBUG == "yes" ]; then
BUILD_FLAGS="$BUILD_FLAGS -gcflags '-m=1'"
fi
if [ $FASTHTTP == "yes" ]; then
BUILD_FLAGS="$BUILD_FLAGS -tags fasthttp"
fi
if [ $VALIDATE == "yes" ]; then
validate
exit
fi
if [ $GOSTATUS == "yes" ]; then
gostatus all
exit
fi
if [ $BUILDALL == "yes" ]; then
for target in `ls cmd`; do
$0 -it $target
done
exit
fi
if [ $BENCHALL == "yes" ]; then
for target in `go list github.com/funkygao/gafka/cmd/kateway/... | grep -v '/bench' | grep -v '/demo'`; do
echo "benchmarking $target"
go test -v -run=XXX -benchmem -cpu=1,4,8,16 -test.bench=".*" $target
done
exit
fi
if [ $BENCHCMP == "yes" ]; then
for target in `go list github.com/funkygao/gafka/cmd/kateway/... | grep -v '/bench' | grep -v '/demo' | grep -v misc`; do
echo -e "${GREEN}benchcmp-vcs $target${RESET}"
benchcmp-vcs $target
done
exit
fi
echo "compiling $TARGET"
cd cmd/$TARGET
check_gofmt
if [ $QA == "yes" ]; then
go vet ./...
go install github.com/golang/lint/golint
golint ./...
exit $?
fi
go generate ./...
if [ $GOVER -gt 4 ]; then
go build $BUILD_FLAGS -ldflags "-X github.com/funkygao/gafka.BuiltAt=$BUILD_TIME -X github.com/funkygao/gafka.Version=$VER -X github.com/funkygao/gafka.BuildId=${GIT_ID}${GIT_DIRTY} -w"
else
go build $BUILD_FLAGS -ldflags "-X github.com/funkygao/gafka.BuiltAt $BUILD_TIME -X github.com/funkygao/gafka.Version $VER -X github.com/funkygao/gafka.BuildId ${GIT_ID}${GIT_DIRTY} -w"
fi
if [ $INSTALL == "yes" ]; then
install -m 755 $TARGET $PREFIX/bin
fi
#---------
# show ver
#---------
./$TARGET -version