1#!/bin/sh
2
3project=github.com/couchbase/query
4top=`go list -f '{{.Dir}}' $project/server/cbq-engine`
5version=`git describe`
6path=server/cbq-engine
7
8top=${top%$path}
9cd $top
10
11DIST=$top/dist
12
13testpkg() {
14    go test $project/test/...
15    go tool vet $top
16}
17
18mkversion() {
19    echo "{\"version\": \"$version\"}" > $DIST/version.json
20}
21
22build() {
23    pkg=$project/server/cbq-engine
24    goflags="-v -ldflags '-X main.VERSION $version'"
25
26    eval env GOARCH=386   GOOS=linux CGO_ENABLED=0 go build $goflags -o $DIST/cbq-engine.lin32 $pkg &
27    #eval env GOARCH=arm   GOOS=linux CGO_ENABLED=0 go build $goflags -o $DIST/cbq-engine.arm $pkg &
28    #eval env GOARCH=arm   GOARM=5 GOOS=linux CGO_ENABLED=0 go build $goflags -o $DIST/cbq-engine.arm5 $pkg &
29    eval env GOARCH=amd64 GOOS=linux CGO_ENABLED=0 go build $goflags -o $DIST/cbq-engine.lin64 $pkg &
30    #eval env GOARCH=amd64 GOOS=freebsd CGO_ENABLED=0 go build $goflags -o $DIST/cbq-engine.fbsd $pkg &&
31    eval env GOARCH=386   GOOS=windows go build $goflags -o $DIST/cbq-engine.win32.exe $pkg &
32    eval env GOARCH=amd64 GOOS=windows go build $goflags -o $DIST/cbq-engine.win64.exe $pkg &
33    eval env GOARCH=amd64 GOOS=darwin go build $goflags -o $DIST/cbq-engine.mac $pkg &
34
35    wait
36}
37
38buildclient() {
39    pkg=$project/shell/cbq
40    goflags="-v -ldflags '-X main.VERSION $version'"
41
42    eval env GOARCH=386   GOOS=linux CGO_ENABLED=0 go build $goflags -o $DIST/cbq.lin32 $pkg &
43    #eval env GOARCH=arm   GOOS=linux CGO_ENABLED=0 go build $goflags -o $DIST/cbq.arm $pkg &
44    #eval env GOARCH=arm   GOARM=5 GOOS=linux CGO_ENABLED=0 go build $goflags -o $DIST/cbq.arm5 $pkg &
45    eval env GOARCH=amd64 GOOS=linux CGO_ENABLED=0 go build $goflags -o $DIST/cbq.lin64 $pkg &
46    #eval env GOARCH=amd64 GOOS=freebsd CGO_ENABLED=0 go build $goflags -o $DIST/cbq.fbsd $pkg &
47    eval env GOARCH=386   GOOS=windows go build $goflags -o $DIST/cbq.win32.exe $pkg &
48    eval env GOARCH=amd64 GOOS=windows go build $goflags -o $DIST/cbq.win64.exe $pkg &
49    eval env GOARCH=amd64 GOOS=darwin go build $goflags -o $DIST/cbq.mac $pkg &
50
51    wait
52}
53
54builddistpackages() {
55
56    mkdir -p $DIST/tutorial_tmp
57    cd tutorial
58    go build
59    cd $top
60    tutorial/tutorial -src tutorial/content/ -dst $DIST/tutorial_tmp/
61
62    # mac build
63    mkdir -p $DIST/stage
64    cp $DIST/README $DIST/stage
65    cp $DIST/license-ce-2013.txt $DIST/stage/LICENSE.txt
66    cp $DIST/start_tutorial.sh $DIST/stage
67    mv $DIST/cbq-engine.mac $DIST/stage/cbq-engine
68    mv $DIST/cbq.mac $DIST/stage/cbq
69    cp -r static/ $DIST/stage/static
70    mkdir -p $DIST/stage/static/tutorial
71    cp -r $DIST/tutorial_tmp/tutorial/content/ $DIST/stage/static/tutorial
72    mkdir -p $DIST/stage/data/default/tutorial
73    unzip tutorial/data/sampledb.zip -d $DIST/stage/data/default/
74    mkdir $DIST/stage/$version
75    mv $DIST/stage/* $DIST/stage/$version
76    cd $DIST/stage
77    zip $DIST/couchbase-query_dev_preview4_x86_64_mac.zip -r .
78    cd $top
79    rm -rf $DIST/stage
80
81    #linux 32
82    mkdir -p $DIST/stage
83    cp $DIST/README $DIST/stage
84    cp $DIST/license-ce-2013.txt $DIST/stage/LICENSE.txt
85    cp $DIST/start_tutorial.sh $DIST/stage
86    mv $DIST/cbq-engine.lin32 $DIST/stage/cbq-engine
87    mv $DIST/cbq.lin32 $DIST/stage/cbq
88    cp -r static/ $DIST/stage/static
89    mkdir -p $DIST/stage/static/tutorial
90    cp -r $DIST/tutorial_tmp/tutorial/content/ $DIST/stage/static/tutorial
91    mkdir -p $DIST/stage/data/default/tutorial
92    unzip tutorial/data/sampledb.zip -d $DIST/stage/data/default/
93    mkdir $DIST/stage/$version
94    mv $DIST/stage/* $DIST/stage/$version
95    cd $DIST/stage
96    tar zcvf $DIST/couchbase-query_dev_preview4_x86_linux.tar.gz .
97    cd $top
98    rm -rf $DIST/stage
99
100    #linux 64
101    mkdir -p $DIST/stage
102    cp $DIST/README $DIST/stage
103    cp $DIST/license-ce-2013.txt $DIST/stage/LICENSE.txt
104    cp $DIST/start_tutorial.sh $DIST/stage
105    mv $DIST/cbq-engine.lin64 $DIST/stage/cbq-engine
106    mv $DIST/cbq.lin64 $DIST/stage/cbq
107    cp -r static/ $DIST/stage/static
108    mkdir -p $DIST/stage/static/tutorial
109    cp -r $DIST/tutorial_tmp/tutorial/content/ $DIST/stage/static/tutorial
110    mkdir -p $DIST/stage/data/default/tutorial
111    unzip tutorial/data/sampledb.zip -d $DIST/stage/data/default/
112    mkdir $DIST/stage/$version
113    mv $DIST/stage/* $DIST/stage/$version
114    cd $DIST/stage
115    tar zcvf $DIST/couchbase-query_dev_preview4_x86_64_linux.tar.gz .
116    cd $top
117    rm -rf $DIST/stage
118
119    #win 32
120    mkdir -p $DIST/stage
121    cp $DIST/README $DIST/stage
122    cp $DIST/license-ce-2013.txt $DIST/stage/LICENSE.txt
123    cp $DIST/start_tutorial.bat $DIST/stage
124    mv $DIST/cbq-engine.win32.exe $DIST/stage/cbq-engine.exe
125    mv $DIST/cbq.win32.exe $DIST/stage/cbq.exe
126    cp -r static/ $DIST/stage/static
127    mkdir -p $DIST/stage/static/tutorial
128    cp -r $DIST/tutorial_tmp/tutorial/content/ $DIST/stage/static/tutorial
129    mkdir -p $DIST/stage/data/default/tutorial
130    unzip tutorial/data/sampledb.zip -d $DIST/stage/data/default/
131    mkdir $DIST/stage/$version
132    mv $DIST/stage/* $DIST/stage/$version
133    cd $DIST/stage
134    zip $DIST/couchbase-query_dev_preview4_x86_win.zip -r .
135    cd $top
136    rm -rf $DIST/stage
137
138    #win 64
139    mkdir -p $DIST/stage
140    cp $DIST/README $DIST/stage
141    cp $DIST/license-ce-2013.txt $DIST/stage/LICENSE.txt
142    cp $DIST/start_tutorial.bat $DIST/stage
143    mv $DIST/cbq-engine.win64.exe $DIST/stage/cbq-engine.exe
144    mv $DIST/cbq.win64.exe $DIST/stage/cbq.exe
145    cp -r static/ $DIST/stage/static
146    mkdir -p $DIST/stage/static/tutorial
147    cp -r $DIST/tutorial_tmp/tutorial/content/ $DIST/stage/static/tutorial
148    mkdir -p $DIST/stage/data/default/tutorial
149    unzip tutorial/data/sampledb.zip -d $DIST/stage/data/default/
150    mkdir $DIST/stage/$version
151    mv $DIST/stage/* $DIST/stage/$version
152    cd $DIST/stage
153    zip $DIST/couchbase-query_dev_preview4_x86_64_win.zip -r .
154    cd $top
155    rm -rf $DIST/stage
156
157    rm -rf $DIST/tutorial_tmp
158
159    
160}
161
162compress() {
163    rm -f $DIST/cbq-engine.*.gz $DIST/cbq.*.gz || true
164
165    for i in $DIST/cbq-engine.* $DIST/cbq.*
166    do
167        gzip -9v $i &
168    done
169
170    wait
171}
172
173benchmark() {
174    go test -test.bench . > $DIST/benchmark.txt
175}
176
177coverage() {
178    for sub in ast misc plan test xpipeline
179    do
180        gocov test $project/$sub | gocov-html > $DIST/cov-$sub.html
181    done
182    cd $top/test
183    gocov test -deps -exclude-goroot > $DIST/integ.json
184    cat $DIST/integ.json | jq '{"Packages": [.Packages[] | if .Name > "github.com/couchbaselabs/tuqtng" and .Name < "github.com/couchbaselabs/tuqtnh" then . else empty end]}' > $DIST/integ2.json
185    cat $DIST/integ2.json |gocov-html > $DIST/integ-cov.html
186    cd $top
187}
188
189upload() {
190    cbfsclient ${cbfsserver:-http://cbfs.hq.couchbase.com:8484/} upload \
191        -ignore=$DIST/.cbfsclient.ignore -delete -v \
192        $DIST/ tuqtng/
193
194    cbfsclient ${cbfsserver:-http://cbfs.hq.couchbase.com:8484/} upload \
195        -ignore=$DIST/.cbfsclient.ignore -delete -v \
196        $DIST/redirect.html tuqtng
197}
198
199testpkg
200mkversion
201build
202buildclient
203builddistpackages
204#compress
205#benchmark
206#coverage
207#upload
208