From eec2130ea274839bdbd7a9727b622b11b092d2bf Mon Sep 17 00:00:00 2001
From: Ian Lance Taylor <iant@golang.org>
Date: Wed, 14 Jun 2017 19:26:21 +0000
Subject: [PATCH] Makefile.am (libgosrcdir): Define.

	* Makefile.am (libgosrcdir): Define.
	(check-head, check-gccgo, check-go-tool): New targets.
	(CHECK_ENV): Define.
	(check): New target.
	(mostlyclean-local): New target.
	* Makefile.in: Rebuild.

From-SVN: r249203
---
 gotools/ChangeLog   |   9 ++++
 gotools/Makefile.am |  89 ++++++++++++++++++++++++++++++++++++++-
 gotools/Makefile.in | 100 +++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 192 insertions(+), 6 deletions(-)

diff --git a/gotools/ChangeLog b/gotools/ChangeLog
index d0390985bbe9..8f9507561827 100644
--- a/gotools/ChangeLog
+++ b/gotools/ChangeLog
@@ -1,3 +1,12 @@
+2017-06-14  Ian Lance Taylor  <iant@golang.org>
+
+	* Makefile.am (libgosrcdir): Define.
+	(check-head, check-gccgo, check-go-tool): New targets.
+	(CHECK_ENV): Define.
+	(check): New target.
+	(mostlyclean-local): New target.
+	* Makefile.in: Rebuild.
+
 2017-06-13  Ian Lance Taylor  <iant@golang.org>
 
 	PR go/80964
diff --git a/gotools/Makefile.am b/gotools/Makefile.am
index ccadbd25a883..bde5e432531b 100644
--- a/gotools/Makefile.am
+++ b/gotools/Makefile.am
@@ -42,7 +42,8 @@ AM_GOCFLAGS = -I $(libgodir)
 AM_LDFLAGS = -L $(libgodir) -L $(libgodir)/.libs
 GOLINK = $(GOCOMPILER) $(GOCFLAGS) $(AM_GOCFLAGS) $(LDFLAGS) $(AM_LDFLAGS) -o $@
 
-cmdsrcdir = $(srcdir)/../libgo/go/cmd
+libgosrcdir = $(srcdir)/../libgo/go
+cmdsrcdir = $(libgosrcdir)/cmd
 
 go_cmd_go_files = \
 	$(cmdsrcdir)/go/alldocs.go \
@@ -131,6 +132,89 @@ install-exec-local: cgo$(EXEEXT)
 uninstall-local:
 	rm -f $(DESTDIR)$(libexecsubdir)/cgo$(exeext)
 
+# Run tests using the go tool, and frob the output to look like that
+# generated by DejaGNU.  The main output of this is two files:
+# gotools.sum and gotools.log.
+
+# check-head starts generating the log files in DejaGNU format.  This
+# is a separate target so that the date is approximately when we start
+# running the tests.
+check-head:
+	@echo "Test Run By $${USER} on `date`" > gotools.head
+	@echo "Native configuration is $(host_triplet)" >> gotools.head
+	@echo >> gotools.head
+	@echo "		=== gotools tests ===" >> gotools.head
+	@echo >> gotools.head
+
+# check-gccgo is a little shell script that executes gccgo with the
+# options to pick up the newly built libgo.
+check-gccgo: Makefile
+	rm -f $@
+	echo "#!/bin/sh" > $@
+	abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
+	echo "$(GOCOMPILE)" '"$$@"' "-I $${abs_libgodir} -L $${abs_libgodir} -L $${abs_libgodir}/.libs" >> $@
+	chmod +x $@
+
+# CHECK_ENV sets up the environment to run the newly built go tool.
+CHECK_ENV = \
+	PATH=`echo $(abs_builddir):$${PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
+	export PATH; \
+	GCCGO="$(abs_builddir)/check-gccgo"; \
+	export GCCGO; \
+	GCCGOTOOLDIR="$(abs_builddir)"; \
+	export GCCGOTOOLDIR; \
+	GO_TESTING_GOTOOLS=yes; \
+	export GO_TESTING_GOTOOLS; \
+	abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
+	LD_LIBRARY_PATH=`echo $${abs_libgodir}/.libs:$${LD_LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
+	export LD_LIBRARY_PATH;
+
+# check-go-tools runs `go test cmd/go` in our environment.
+check-go-tool: go$(EXEEXT) check-head check-gccgo
+	rm -rf check-go-dir
+	$(MKDIR_P) check-go-dir/src/cmd/go
+	cp $(cmdsrcdir)/go/*.go check-go-dir/src/cmd/go/
+	cp $(libgodir)/zstdpkglist.go check-go-dir/src/cmd/go/
+	cp zdefaultcc.go check-go-dir/src/cmd/go/
+	cp -r $(cmdsrcdir)/go/testdata check-go-dir/src/cmd/go/
+	$(CHECK_ENV) \
+	GOPATH=`cd check-go-dir && $(PWD_COMMAND)`; \
+	export GOPATH; \
+	(cd check-go-dir/src/cmd/go && $(abs_builddir)/go$(EXEEXT) test -test.short -test.v) >& cmd_go-testlog || true
+	grep '^--- ' cmd_go-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'
+
+# The check targets runs the tests and assembles the output files.
+check: check-head check-go-tool
+	mv gotools.head gotools.sum
+	cp gotools.sum gotools.log
+	for file in cmd_go-testlog; do \
+	  testname=`echo $${file} | sed -e 's/-testlog//' -e 's|_|/|'`; \
+	  echo "Running $${testname}" >> gotools.sum; \
+	  echo "Running $${testname}" >> gotools.log; \
+	  sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' < $${file} >> gotools.log; \
+	  grep '^--- ' $${file} | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' -e 's/SKIP/UNTESTED/' >> gotools.sum; \
+	done
+	@echo >> gotools.sum
+	@echo "		=== gotools Summary ===" >> gotools.sum
+	pass=`grep -c '^PASS' gotools.sum`; \
+	if test "$${pass}" -ne "0"; then \
+	  echo "# of expected passes		$${pass}" >> gotools.sum; \
+	fi
+	fail=`grep -c '^FAIL' gotools.sum`; \
+	if test "$${fail}" -ne "0"; then \
+	  echo "# of unexpected failures	$${fail}" >> gotools.sum; \
+	fi
+	untested=`grep -c '^UNTESTED' gotools.sum`; \
+	if test "$${untested}" -ne "0"; then \
+	  echo "# of untested testcases		$${untested}" >> gotools.sum; \
+	fi
+	echo `echo $(GOC_FOR_TARGET) | sed -e 's/ .*//'`  `$(GOC_FOR_TARGET) -v 2>&1 | grep " version" | sed -n -e 's/.* \(version.*$$\)/\1/p'` >> gotools.sum
+	echo >> gotools.log
+	echo "runtest completed at `date`" >> gotools.log
+	if grep '^FAIL' gotools.sum >/dev/null 2>&1; then exit 1; fi
+
+.PHONY: check check-head check-go-tool
+
 else
 
 # For a non-native build we have to build the programs using a
@@ -140,3 +224,6 @@ else
 # the go/build package.  Figure this out later.
 
 endif
+
+mostlyclean-local:
+	rm -rf check-go-dir
diff --git a/gotools/Makefile.in b/gotools/Makefile.in
index 941a82336ac5..9e42330c8be9 100644
--- a/gotools/Makefile.in
+++ b/gotools/Makefile.in
@@ -261,7 +261,8 @@ GOCOMPILE = $(GOCOMPILER) $(GOCFLAGS)
 AM_GOCFLAGS = -I $(libgodir)
 AM_LDFLAGS = -L $(libgodir) -L $(libgodir)/.libs
 GOLINK = $(GOCOMPILER) $(GOCFLAGS) $(AM_GOCFLAGS) $(LDFLAGS) $(AM_LDFLAGS) -o $@
-cmdsrcdir = $(srcdir)/../libgo/go/cmd
+libgosrcdir = $(srcdir)/../libgo/go
+cmdsrcdir = $(libgosrcdir)/cmd
 go_cmd_go_files = \
 	$(cmdsrcdir)/go/alldocs.go \
 	$(cmdsrcdir)/go/bug.go \
@@ -319,6 +320,21 @@ MOSTLYCLEANFILES = zdefaultcc.go s-zdefaultcc
 @NATIVE_TRUE@bin_PROGRAMS = go$(EXEEXT) gofmt$(EXEEXT)
 @NATIVE_TRUE@noinst_PROGRAMS = cgo$(EXEEXT)
 @NATIVE_TRUE@man_MANS = go.1 gofmt.1
+
+# CHECK_ENV sets up the environment to run the newly built go tool.
+@NATIVE_TRUE@CHECK_ENV = \
+@NATIVE_TRUE@	PATH=`echo $(abs_builddir):$${PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
+@NATIVE_TRUE@	export PATH; \
+@NATIVE_TRUE@	GCCGO="$(abs_builddir)/check-gccgo"; \
+@NATIVE_TRUE@	export GCCGO; \
+@NATIVE_TRUE@	GCCGOTOOLDIR="$(abs_builddir)"; \
+@NATIVE_TRUE@	export GCCGOTOOLDIR; \
+@NATIVE_TRUE@	GO_TESTING_GOTOOLS=yes; \
+@NATIVE_TRUE@	export GO_TESTING_GOTOOLS; \
+@NATIVE_TRUE@	abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
+@NATIVE_TRUE@	LD_LIBRARY_PATH=`echo $${abs_libgodir}/.libs:$${LD_LIBRARY_PATH} | sed 's,::*,:,g;s,^:*,,;s,:*$$,,'`; \
+@NATIVE_TRUE@	export LD_LIBRARY_PATH;
+
 all: all-am
 
 .SUFFIXES:
@@ -629,7 +645,8 @@ maintainer-clean-am: distclean-am maintainer-clean-generic
 
 mostlyclean: mostlyclean-am
 
-mostlyclean-am: mostlyclean-compile mostlyclean-generic
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+	mostlyclean-local
 
 pdf: pdf-am
 
@@ -655,9 +672,10 @@ uninstall-man: uninstall-man1
 	install-man install-man1 install-pdf install-pdf-am install-ps \
 	install-ps-am install-strip installcheck installcheck-am \
 	installdirs maintainer-clean maintainer-clean-generic \
-	mostlyclean mostlyclean-compile mostlyclean-generic pdf pdf-am \
-	ps ps-am tags uninstall uninstall-am uninstall-binPROGRAMS \
-	uninstall-local uninstall-man uninstall-man1
+	mostlyclean mostlyclean-compile mostlyclean-generic \
+	mostlyclean-local pdf pdf-am ps ps-am tags uninstall \
+	uninstall-am uninstall-binPROGRAMS uninstall-local \
+	uninstall-man uninstall-man1
 
 
 zdefaultcc.go: s-zdefaultcc; @true
@@ -685,12 +703,84 @@ s-zdefaultcc: Makefile
 @NATIVE_TRUE@uninstall-local:
 @NATIVE_TRUE@	rm -f $(DESTDIR)$(libexecsubdir)/cgo$(exeext)
 
+# Run tests using the go tool, and frob the output to look like that
+# generated by DejaGNU.  The main output of this is two files:
+# gotools.sum and gotools.log.
+
+# check-head starts generating the log files in DejaGNU format.  This
+# is a separate target so that the date is approximately when we start
+# running the tests.
+@NATIVE_TRUE@check-head:
+@NATIVE_TRUE@	@echo "Test Run By $${USER} on `date`" > gotools.head
+@NATIVE_TRUE@	@echo "Native configuration is $(host_triplet)" >> gotools.head
+@NATIVE_TRUE@	@echo >> gotools.head
+@NATIVE_TRUE@	@echo "		=== gotools tests ===" >> gotools.head
+@NATIVE_TRUE@	@echo >> gotools.head
+
+# check-gccgo is a little shell script that executes gccgo with the
+# options to pick up the newly built libgo.
+@NATIVE_TRUE@check-gccgo: Makefile
+@NATIVE_TRUE@	rm -f $@
+@NATIVE_TRUE@	echo "#!/bin/sh" > $@
+@NATIVE_TRUE@	abs_libgodir=`cd $(libgodir) && $(PWD_COMMAND)`; \
+@NATIVE_TRUE@	echo "$(GOCOMPILE)" '"$$@"' "-I $${abs_libgodir} -L $${abs_libgodir} -L $${abs_libgodir}/.libs" >> $@
+@NATIVE_TRUE@	chmod +x $@
+
+# check-go-tools runs `go test cmd/go` in our environment.
+@NATIVE_TRUE@check-go-tool: go$(EXEEXT) check-head check-gccgo
+@NATIVE_TRUE@	rm -rf check-go-dir
+@NATIVE_TRUE@	$(MKDIR_P) check-go-dir/src/cmd/go
+@NATIVE_TRUE@	cp $(cmdsrcdir)/go/*.go check-go-dir/src/cmd/go/
+@NATIVE_TRUE@	cp $(libgodir)/zstdpkglist.go check-go-dir/src/cmd/go/
+@NATIVE_TRUE@	cp zdefaultcc.go check-go-dir/src/cmd/go/
+@NATIVE_TRUE@	cp -r $(cmdsrcdir)/go/testdata check-go-dir/src/cmd/go/
+@NATIVE_TRUE@	$(CHECK_ENV) \
+@NATIVE_TRUE@	GOPATH=`cd check-go-dir && $(PWD_COMMAND)`; \
+@NATIVE_TRUE@	export GOPATH; \
+@NATIVE_TRUE@	(cd check-go-dir/src/cmd/go && $(abs_builddir)/go$(EXEEXT) test -test.short -test.v) >& cmd_go-testlog || true
+@NATIVE_TRUE@	grep '^--- ' cmd_go-testlog | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/'
+
+# The check targets runs the tests and assembles the output files.
+@NATIVE_TRUE@check: check-head check-go-tool
+@NATIVE_TRUE@	mv gotools.head gotools.sum
+@NATIVE_TRUE@	cp gotools.sum gotools.log
+@NATIVE_TRUE@	for file in cmd_go-testlog; do \
+@NATIVE_TRUE@	  testname=`echo $${file} | sed -e 's/-testlog//' -e 's|_|/|'`; \
+@NATIVE_TRUE@	  echo "Running $${testname}" >> gotools.sum; \
+@NATIVE_TRUE@	  echo "Running $${testname}" >> gotools.log; \
+@NATIVE_TRUE@	  sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' < $${file} >> gotools.log; \
+@NATIVE_TRUE@	  grep '^--- ' $${file} | sed -e 's/^--- \(.*\) ([^)]*)$$/\1/' -e 's/SKIP/UNTESTED/' >> gotools.sum; \
+@NATIVE_TRUE@	done
+@NATIVE_TRUE@	@echo >> gotools.sum
+@NATIVE_TRUE@	@echo "		=== gotools Summary ===" >> gotools.sum
+@NATIVE_TRUE@	pass=`grep -c '^PASS' gotools.sum`; \
+@NATIVE_TRUE@	if test "$${pass}" -ne "0"; then \
+@NATIVE_TRUE@	  echo "# of expected passes		$${pass}" >> gotools.sum; \
+@NATIVE_TRUE@	fi
+@NATIVE_TRUE@	fail=`grep -c '^FAIL' gotools.sum`; \
+@NATIVE_TRUE@	if test "$${fail}" -ne "0"; then \
+@NATIVE_TRUE@	  echo "# of unexpected failures	$${fail}" >> gotools.sum; \
+@NATIVE_TRUE@	fi
+@NATIVE_TRUE@	untested=`grep -c '^UNTESTED' gotools.sum`; \
+@NATIVE_TRUE@	if test "$${untested}" -ne "0"; then \
+@NATIVE_TRUE@	  echo "# of untested testcases		$${untested}" >> gotools.sum; \
+@NATIVE_TRUE@	fi
+@NATIVE_TRUE@	echo `echo $(GOC_FOR_TARGET) | sed -e 's/ .*//'`  `$(GOC_FOR_TARGET) -v 2>&1 | grep " version" | sed -n -e 's/.* \(version.*$$\)/\1/p'` >> gotools.sum
+@NATIVE_TRUE@	echo >> gotools.log
+@NATIVE_TRUE@	echo "runtest completed at `date`" >> gotools.log
+@NATIVE_TRUE@	if grep '^FAIL' gotools.sum >/dev/null 2>&1; then exit 1; fi
+
+@NATIVE_TRUE@.PHONY: check check-head check-go-tool
+
 # For a non-native build we have to build the programs using a
 # previously built host (or build -> host) Go compiler.  We should
 # only do this if such a compiler is available.  We also need to get
 # the right values for GOARCH and GOOS in the default build context in
 # the go/build package.  Figure this out later.
 
+mostlyclean-local:
+	rm -rf check-go-dir
+
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
-- 
GitLab