Commit eda49f33 authored by Russ Cox's avatar Russ Cox

new included Make.pkg for handwritten package makefiles.

gobuild is obsolete; don't build it (will delete eventually).

revised gotest for whole-package compilation.

R=r
DELTA=102  (68 added, 6 deleted, 28 changed)
OCL=33067
CL=33098
parent 3b864e41
# Copyright 2009 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.
package: _obj/$(TARG).a
testpackage: _test/$(TARG).a
dir=$(shell echo $(TARG) | sed 's|[^/]*$$||')
pkgdir=$(GOROOT)/pkg/$(GOOS)_$(GOARCH)
coverage:
gotest
6cov -g $(shell pwd) | grep -v '_test\.go:'
clean:
rm -rf *.[$(OS)] *.a [$(OS)].out _obj _test _testmain.go
test:
gotest
nuke: clean
rm -f $(pkgdir)/$(TARG).a
testpackage-clean:
rm -f _test/$(TARG).a _gotest_.$O
install: package
test -d $(GOROOT)/pkg && mkdir -p $(pkgdir)/$(dir)
cp _obj/$(TARG).a $(pkgdir)/$(TARG).a
_go_.$O: $(GOFILES)
$(GC) -o $@ $(GOFILES)
_gotest_.$O: $(GOFILES) $(GOTESTFILES)
$(GC) -o $@ $(GOFILES) $(GOTESTFILES)
%.$O: %.c
$(CC) $*.c
%.$O: %.s
$(AS) $*.s
%.$O: $(HFILES)
_obj/$(TARG).a: _go_.$O $(OFILES)
mkdir -p _obj/$(dir)
rm -f _obj/$(TARG).a
gopack grc $@ _go_.$O $(OFILES)
_test/$(TARG).a: _gotest_.$O $(OFILES)
mkdir -p _test/$(dir)
rm -f _test/$(TARG).a
gopack grc $@ _gotest_.$O $(OFILES)
importpath:
@echo $(TARG)
...@@ -19,8 +19,8 @@ fi ...@@ -19,8 +19,8 @@ fi
# Allow overrides # Allow overrides
GC=${_GC:-$GC} GC=${_GC:-$GC}
GL=${GL:-$LD} GL=${GL:-$LD}
GC="$GC -I _obj" GC="$GC -I _test"
GL="$GL -L _obj" GL="$GL -L _test"
export GC GL export GC GL
gofiles="" gofiles=""
...@@ -42,7 +42,7 @@ done ...@@ -42,7 +42,7 @@ done
case "x$gofiles" in case "x$gofiles" in
x) x)
gofiles=$(ls *_test.go 2>/dev/null) gofiles=$(echo -n $(ls *_test.go *_test.pb.go 2>/dev/null))
esac esac
case "x$gofiles" in case "x$gofiles" in
...@@ -51,53 +51,62 @@ x) ...@@ -51,53 +51,62 @@ x)
exit 1 exit 1
esac esac
ofiles=$(echo $gofiles | sed 's/\.go/.'$O'/g')
files=$(echo $gofiles | sed 's/\.go//g')
# Run any commands given in sources, like # Run any commands given in sources, like
# // gotest: $GC foo.go # // gotest: $GC foo.go
# to build any test-only dependencies. # to build any test-only dependencies.
sed -n 's/^\/\/ gotest: //p' $gofiles | sh sed -n 's/^\/\/ gotest: //p' $gofiles | sh
# Split $gofiles into external gofiles (those in *_test packages)
# and internal ones (those in the main package).
xgofiles=$(echo $(grep '^package[ ]' $gofiles /dev/null | grep ':.*_test' | sed 's/:.*//'))
gofiles=$(echo $(grep '^package[ ]' $gofiles /dev/null | grep -v ':.*_test' | sed 's/:.*//'))
# External $O file
xofile=""
havex=false
if [ "x$xgofiles" != "x" ]; then
xofile="_xtest_.$O"
havex=true
fi
set -e set -e
for i in $gofiles make testpackage-clean
do make testpackage "GOTESTFILES=$gofiles"
$GC $i if $havex; then
done $GC -o $xofile $xgofiles
fi
# They all compile; now generate the code to call them. # They all compile; now generate the code to call them.
trap "rm -f _testmain.go _testmain.$O" 0 1 2 3 14 15 #trap "rm -f _testmain.go _testmain.$O" 0 1 2 3 14 15
importpath=$(make importpath)
{ {
# package spec # package spec
echo 'package main' echo 'package main'
echo echo
# imports # imports
for i in $files echo 'import "'$importpath'"'
do if $havex; then
echo 'import "./'$i'"' echo 'import "./_xtest_"'
done fi
echo 'import "testing"' echo 'import "testing"'
# test array # test array
echo echo
echo 'var tests = []testing.Test {' echo 'var tests = []testing.Test {'
for ofile in $ofiles
do
# test functions are named TestFoo # test functions are named TestFoo
# the grep -v eliminates methods and other special names # the grep -v eliminates methods and other special names
# that have multiple dots. # that have multiple dots.
pattern='Test([^a-z].*)?' pattern='Test([^a-z].*)?'
tests=$(6nm -s $ofile | egrep ' T .*·'$pattern'$' | grep -v '·.*[.·]' | sed 's/.* //; s/·/./') tests=$(6nm -s _test/$importpath.a $xofile | egrep ' T .*·'$pattern'$' | grep -v '·.*[.·]' | sed 's/.* //; s/·/./')
if [ "x$tests" = x ]; then if [ "x$tests" = x ]; then
echo 'gotest: warning: no tests matching '$pattern' in '$ofile 1>&2 echo 'gotest: warning: no tests matching '$pattern in _test/$importpath.a $xofile 1>&2
else else
for i in $tests for i in $tests
do do
echo ' testing.Test{ "'$i'", '$i' },' echo ' testing.Test{ "'$i'", '$i' },'
done done
fi fi
done
echo '}' echo '}'
# body # body
echo echo
...@@ -107,5 +116,5 @@ trap "rm -f _testmain.go _testmain.$O" 0 1 2 3 14 15 ...@@ -107,5 +116,5 @@ trap "rm -f _testmain.go _testmain.$O" 0 1 2 3 14 15
}>_testmain.go }>_testmain.go
$GC _testmain.go $GC _testmain.go
$GL _testmain.$O $GL _testmain.$O _test/$importpath.a $xofile
./$O.out "$@" ./$O.out "$@"
...@@ -19,7 +19,7 @@ rm -f $GOBIN/quietgcc ...@@ -19,7 +19,7 @@ rm -f $GOBIN/quietgcc
cp quietgcc.bash $GOBIN/quietgcc cp quietgcc.bash $GOBIN/quietgcc
chmod +x $GOBIN/quietgcc chmod +x $GOBIN/quietgcc
for i in lib9 libbio libmach_amd64 libregexp cmd pkg cmd/ebnflint cmd/gobuild cmd/godoc cmd/gofmt for i in lib9 libbio libmach_amd64 libregexp cmd pkg cmd/ebnflint cmd/godoc cmd/gofmt
do do
# The ( ) here are to preserve the current directory # The ( ) here are to preserve the current directory
# for the next round despite the cd $i below. # for the next round despite the cd $i below.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment