2012-02-16 21:48:24 -07:00
|
|
|
# Copyright 2012 The Go Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
# These function names are also known to
|
|
|
|
# (and are the plan for transitioning to) run.go.
|
|
|
|
|
2013-01-02 13:31:49 -07:00
|
|
|
# helper (not known to run.go)
|
|
|
|
# group file list by packages and return list of packages
|
|
|
|
# each package is a comma-separated list of go files.
|
|
|
|
pkgs() {
|
|
|
|
pkglist=$(grep -h '^package ' $* | awk '{print $2}' | sort -u)
|
|
|
|
for p in $pkglist
|
|
|
|
do
|
|
|
|
echo $(grep -l "^package $p\$" $*) | tr ' ' ,
|
|
|
|
done | sort
|
|
|
|
}
|
|
|
|
|
2013-08-13 10:25:41 -06:00
|
|
|
_match() {
|
|
|
|
case $1 in
|
|
|
|
*,*)
|
|
|
|
#echo >&2 "match comma separated $1"
|
|
|
|
first=$(echo $1 | sed 's/,.*//')
|
|
|
|
rest=$(echo $1 | sed 's/[^,]*,//')
|
|
|
|
if _match $first && _match $rest; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
return 1
|
|
|
|
;;
|
|
|
|
'!'*)
|
|
|
|
#echo >&2 "match negation $1"
|
|
|
|
neg=$(echo $1 | sed 's/^!//')
|
|
|
|
if _match $neg; then
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
$GOARCH|$GOOS)
|
|
|
|
#echo >&2 "match GOARCH or GOOS $1"
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2013-01-28 13:29:45 -07:00
|
|
|
# +build aborts execution if the supplied tags don't match,
|
|
|
|
# i.e. none of the tags (x or !x) matches GOARCH or GOOS.
|
|
|
|
+build() {
|
|
|
|
if (( $# == 0 )); then
|
|
|
|
return
|
|
|
|
fi
|
2013-08-13 10:25:41 -06:00
|
|
|
m=0
|
2013-01-28 13:29:45 -07:00
|
|
|
for tag; do
|
2013-08-13 10:25:41 -06:00
|
|
|
if _match $tag; then
|
|
|
|
m=1
|
|
|
|
fi
|
2013-01-28 13:29:45 -07:00
|
|
|
done
|
2013-08-13 10:25:41 -06:00
|
|
|
if [ $m = 0 ]; then
|
|
|
|
#echo >&2 no match
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
unset m
|
2013-01-28 13:29:45 -07:00
|
|
|
}
|
|
|
|
|
2012-02-16 21:48:24 -07:00
|
|
|
compile() {
|
|
|
|
$G $D/$F.go
|
|
|
|
}
|
|
|
|
|
2012-07-30 13:12:05 -06:00
|
|
|
compiledir() {
|
2013-01-02 13:31:49 -07:00
|
|
|
for pkg in $(pkgs $D/$F.dir/*.go)
|
2012-07-30 13:12:05 -06:00
|
|
|
do
|
2013-01-02 13:31:49 -07:00
|
|
|
$G -I . $(echo $pkg | tr , ' ') || return 1
|
2012-07-30 13:12:05 -06:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2012-10-06 01:23:31 -06:00
|
|
|
errorcheckdir() {
|
|
|
|
lastzero=""
|
|
|
|
if [ "$1" = "-0" ]; then
|
|
|
|
lastzero="-0"
|
|
|
|
fi
|
2013-01-02 13:31:49 -07:00
|
|
|
pkgs=$(pkgs $D/$F.dir/*.go)
|
|
|
|
for pkg in $pkgs.last
|
2012-10-06 01:23:31 -06:00
|
|
|
do
|
|
|
|
zero="-0"
|
2013-01-02 13:31:49 -07:00
|
|
|
case $pkg in
|
|
|
|
*.last)
|
|
|
|
pkg=$(echo $pkg |sed 's/\.last$//')
|
2012-10-06 01:23:31 -06:00
|
|
|
zero=$lastzero
|
2013-01-02 13:31:49 -07:00
|
|
|
esac
|
|
|
|
errchk $zero $G -D . -I . -e $(echo $pkg | tr , ' ')
|
2012-10-06 01:23:31 -06:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
rundir() {
|
|
|
|
lastfile=""
|
2013-01-02 13:31:49 -07:00
|
|
|
for pkg in $(pkgs $D/$F.dir/*.go)
|
2012-10-06 01:23:31 -06:00
|
|
|
do
|
2013-01-02 13:31:49 -07:00
|
|
|
name=$(echo $pkg | sed 's/\.go.*//; s/.*\///')
|
|
|
|
$G -D . -I . -e $(echo $pkg | tr , ' ') || return 1
|
2012-10-06 01:23:31 -06:00
|
|
|
lastfile=$name
|
|
|
|
done
|
2013-01-02 13:31:49 -07:00
|
|
|
$L -o $A.out -L . $lastfile.$A
|
2012-10-06 01:23:31 -06:00
|
|
|
./$A.out
|
|
|
|
}
|
|
|
|
|
|
|
|
rundircmpout() {
|
|
|
|
lastfile=""
|
2013-01-02 13:31:49 -07:00
|
|
|
for pkg in $(pkgs $D/$F.dir/*.go)
|
2012-10-06 01:23:31 -06:00
|
|
|
do
|
2013-01-02 13:31:49 -07:00
|
|
|
name=$(echo $pkg | sed 's/\.go.*//; s/.*\///')
|
|
|
|
$G -D . -I . -e $(echo $pkg | tr , ' ') || return 1
|
2012-10-06 01:23:31 -06:00
|
|
|
lastfile=$name
|
|
|
|
done
|
2013-01-02 13:31:49 -07:00
|
|
|
$L -o $A.out -L . $lastfile.$A
|
2012-10-07 15:14:20 -06:00
|
|
|
./$A.out 2>&1 | cmp - $D/$F.out
|
2012-10-06 01:23:31 -06:00
|
|
|
}
|
|
|
|
|
2012-02-16 21:48:24 -07:00
|
|
|
build() {
|
|
|
|
$G $D/$F.go && $L $F.$A
|
|
|
|
}
|
|
|
|
|
2012-04-20 09:45:43 -06:00
|
|
|
runoutput() {
|
2012-11-07 13:33:54 -07:00
|
|
|
go run "$D/$F.go" "$@" > tmp.go
|
2012-04-20 09:45:43 -06:00
|
|
|
go run tmp.go
|
|
|
|
}
|
|
|
|
|
2012-02-16 21:48:24 -07:00
|
|
|
run() {
|
2012-03-06 23:54:39 -07:00
|
|
|
gofiles=""
|
|
|
|
ingo=true
|
|
|
|
while $ingo; do
|
|
|
|
case "$1" in
|
|
|
|
*.go)
|
|
|
|
gofiles="$gofiles $1"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
ingo=false
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2012-03-07 12:16:58 -07:00
|
|
|
$G $D/$F.go $gofiles && $L $F.$A && ./$A.out "$@"
|
2012-02-16 21:48:24 -07:00
|
|
|
}
|
|
|
|
|
2012-02-23 19:17:26 -07:00
|
|
|
cmpout() {
|
|
|
|
$G $D/$F.go && $L $F.$A && ./$A.out 2>&1 | cmp - $D/$F.out
|
|
|
|
}
|
|
|
|
|
2012-02-16 21:48:24 -07:00
|
|
|
errorcheck() {
|
2012-09-23 11:16:14 -06:00
|
|
|
zero=""
|
|
|
|
if [ "$1" = "-0" ]; then
|
|
|
|
zero="-0"
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
errchk $zero $G -e $* $D/$F.go
|
2012-02-16 21:48:24 -07:00
|
|
|
}
|
2012-03-21 12:14:44 -06:00
|
|
|
|
2012-11-07 13:33:54 -07:00
|
|
|
errorcheckoutput() {
|
|
|
|
zero=""
|
|
|
|
if [ "$1" = "-0" ]; then
|
|
|
|
zero="-0"
|
|
|
|
shift
|
|
|
|
fi
|
|
|
|
go run "$D/$F.go" "$@" > tmp.go
|
|
|
|
errchk $zero $G -e tmp.go
|
|
|
|
}
|
|
|
|
|
2012-03-21 12:14:44 -06:00
|
|
|
skip() {
|
|
|
|
true
|
|
|
|
}
|