.travis.yml: fix travis CI

Changes made:
* Call autogen.sh before building protobuf.
It's unclear how this worked before, but the README instructions for
protobuf does state to run autogen.sh prior to building and installing.
* Fix downloadArchive to take in a prefix path rather than the number of
prefix directories to skip. The reason for this change is due to a bug
in the Go build system where unexpected directories were being packed.
See https://golang.org/issue/29906
* Explicitly set Travis dist to be "xenial", which comes with Go1.11.
We require Go1.11 for two reasons:
	* The use of t.Helper in integration_test.go
	* Proper understanding of the -mod=vendor flag
	(even if all that flag does is disable modules).
* Add a hack to integration_test.go to periodically output the timestamp
to work around a restriction in Travis where it auto-kills the test
after 10 minutes of no stdout activity.

Change-Id: I114fe2855faeed091c34d79df3d97068be7eccd8
Reviewed-on: https://go-review.googlesource.com/c/164919
Reviewed-by: Herbie Ong <herbie@google.com>
diff --git a/.travis.yml b/.travis.yml
index 0aec6a3..ae7591a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,3 +1,4 @@
+dist: xenial
 script:
   - ./test.bash
 cache:
diff --git a/integration_test.go b/integration_test.go
index 2115ff1..eb1b7a4 100644
--- a/integration_test.go
+++ b/integration_test.go
@@ -2,9 +2,9 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build integration
+// +build ignore
 
-package protobuf
+package main
 
 import (
 	"archive/tar"
@@ -22,6 +22,7 @@
 	"runtime"
 	"strings"
 	"testing"
+	"time"
 )
 
 var (
@@ -119,6 +120,25 @@
 	testDir := filepath.Join(repoRoot, ".cache")
 	check(os.MkdirAll(testDir, 0775))
 
+	// Travis-CI has a hard-coded timeout where it kills the test after
+	// 10 minutes of a lack of activity on stdout.
+	// We work around this restriction by periodically printing the timestamp.
+	ticker := time.NewTicker(5 * time.Minute)
+	done := make(chan struct{})
+	go func() {
+		now := time.Now()
+		for {
+			select {
+			case t := <-ticker.C:
+				fmt.Printf("\tt=%0.fmin\n", t.Sub(now).Minutes())
+			case <-done:
+				return
+			}
+		}
+	}()
+	defer close(done)
+	defer ticker.Stop()
+
 	// Delete the current directory if non-empty,
 	// which only occurs if a dependency failed to initialize properly.
 	var workingDir string
@@ -165,9 +185,10 @@
 	if _, err := os.Stat(workingDir); err != nil {
 		fmt.Printf("download %v\n", filepath.Base(workingDir))
 		url := fmt.Sprintf("https://github.com/google/protobuf/releases/download/v%v/protobuf-all-%v.tar.gz", protobufVersion, protobufVersion)
-		downloadArchive(check, workingDir, url, 1)
+		downloadArchive(check, workingDir, url, "protobuf-"+protobufVersion)
 
 		fmt.Printf("build %v\n", filepath.Base(workingDir))
+		mustRunCommand(t, workingDir, "./autogen.sh")
 		mustRunCommand(t, workingDir, "./configure")
 		mustRunCommand(t, workingDir, "make")
 		mustRunCommand(t, filepath.Join(workingDir, "conformance"), "make")
@@ -184,7 +205,7 @@
 		if _, err := os.Stat(workingDir); err != nil {
 			fmt.Printf("download %v\n", filepath.Base(workingDir))
 			url := fmt.Sprintf("https://dl.google.com/go/go%v.%v-%v.tar.gz", v, runtime.GOOS, runtime.GOARCH)
-			downloadArchive(check, workingDir, url, 1)
+			downloadArchive(check, workingDir, url, "go")
 		}
 		registerBinary("go"+v, filepath.Join(workingDir, "bin", "go"))
 	}
@@ -210,7 +231,7 @@
 	check(os.Setenv("GOPATH", goPath))
 }
 
-func downloadArchive(check func(error), dstPath, srcURL string, skipPrefixes int) {
+func downloadArchive(check func(error), dstPath, srcURL, skipPrefix string) {
 	check(os.RemoveAll(dstPath))
 
 	resp, err := http.Get(srcURL)
@@ -228,7 +249,17 @@
 		}
 		check(err)
 
-		path := strings.Join(strings.Split(h.Name, "/")[skipPrefixes:], "/")
+		// Skip directories or files outside the prefix directory.
+		if len(skipPrefix) > 0 {
+			if !strings.HasPrefix(h.Name, skipPrefix) {
+				continue
+			}
+			if len(h.Name) > len(skipPrefix) && h.Name[len(skipPrefix)] != '/' {
+				continue
+			}
+		}
+
+		path := strings.TrimPrefix(strings.TrimPrefix(h.Name, skipPrefix), "/")
 		path = filepath.Join(dstPath, filepath.FromSlash(path))
 		mode := os.FileMode(h.Mode & 0777)
 		switch h.Typeflag {
diff --git a/regenerate.bash b/regenerate.bash
index 9d35f80..0d99025 100755
--- a/regenerate.bash
+++ b/regenerate.bash
@@ -4,5 +4,5 @@
 # license that can be found in the LICENSE file.
 
 cd "$(git rev-parse --show-toplevel)"
-go test -v -timeout 60m integration_test.go "$@" -regenerate
+go test -v -mod=vendor -timeout=60m integration_test.go "$@" -regenerate
 exit $?
diff --git a/test.bash b/test.bash
index d0aed4b..4d46451 100755
--- a/test.bash
+++ b/test.bash
@@ -4,5 +4,5 @@
 # license that can be found in the LICENSE file.
 
 cd "$(git rev-parse --show-toplevel)"
-go test -v -timeout 60m integration_test.go "$@"
+go test -v -mod=vendor -timeout=60m integration_test.go "$@"
 exit $?