forked from dshills/gofhir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·46 lines (41 loc) · 1.13 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
#!/bin/bash
ROOT=$GOPATH/src/github.com/dshills/gofhir
WATCHFILE=$1
FPATH=$(dirname "${WATCHFILE}")
FNAME=$(basename "${WATCHFILE}")
EXT=${FNAME##*.}
function build {
BASEDIR=$1
cd ${BASEDIR}
go test && go vet && go install
}
function watch {
# fswatch
# -0 output nul seperator
# -1 run just once
# -r run recursive
# xargs
# -0 expect null sperator
# -n 1 grab only the first arg
# -I execute for each input line
# {} replaced with args from fswatch
# watch for file changes recursivly quit after first one is found and rerun the script
fswatch -r ${ROOT} | xargs -n1 -I{} ${ROOT}/build.sh {}
}
if [ "${WATCHFILE}" == "" ]; then
watch
else
# Take action depending on the file type
# Doing seperate builds if not in the main folder
# allows code being worked on to be compiled even if
# it is not used by the main application and as such would not be
# compiled by simply doing go install in the root directory.
# go install ./... works but test and vet get run on the vendor directory
if [ "${EXT}" == "go" ]; then
if [ "${FPATH}" == "${ROOT}" ]; then
build ${FPATH}
else
build ${FPATH} && build ${ROOT}
fi
fi
fi