cmd/coordinator: fix trybots for the "dl" repo

Don't assume that all repos have import path starting with "golang.org/x/".
Add a new func instead.

But in one place (finding GOPATH deps), just hard-code the old
behavior of only looking for golang.org/x/ deps. That code will be
deleted soonish anyway, so no point cleaning it up.

Fixes golang/go#30852

Change-Id: Ic657549832da71d3915439875e456f323cf5ebdf
Reviewed-on: https://go-review.googlesource.com/c/build/+/170417
Reviewed-by: Bryan C. Mills <bcmills@google.com>
diff --git a/cmd/coordinator/coordinator.go b/cmd/coordinator/coordinator.go
index 6d6816b..86d0014 100644
--- a/cmd/coordinator/coordinator.go
+++ b/cmd/coordinator/coordinator.go
@@ -67,8 +67,6 @@
 )
 
 const (
-	subrepoPrefix = "golang.org/x/"
-
 	// eventDone is a build event name meaning the build was
 	// completed (either successfully or with remote errors).
 	// Notably, it is NOT included for network/communication
@@ -2347,7 +2345,7 @@
 	// findDeps uses 'go list' on the checked out repo to find its
 	// dependencies, and adds any not-yet-fetched deps to toFetched.
 	findDeps := func(repo string) (rErr, err error) {
-		repoPath := subrepoPrefix + repo
+		repoPath := importPathOfRepo(repo)
 		var buf bytes.Buffer
 		rErr, err = st.bc.Exec(path.Join("go", "bin", "go"), buildlet.ExecOpts{
 			Output:   &buf,
@@ -2363,10 +2361,10 @@
 			return rErr, nil
 		}
 		for _, p := range strings.Fields(buf.String()) {
-			if !strings.HasPrefix(p, subrepoPrefix) || strings.HasPrefix(p, repoPath) {
+			if !strings.HasPrefix(p, "golang.org/x/") || strings.HasPrefix(p, repoPath) {
 				continue
 			}
-			repo = strings.TrimPrefix(p, subrepoPrefix)
+			repo = strings.TrimPrefix(p, "golang.org/x/")
 			if i := strings.Index(repo, "/"); i >= 0 {
 				repo = repo[:i]
 			}
@@ -2428,7 +2426,7 @@
 	if st.conf.IsRace() {
 		args = append(args, "-race")
 	}
-	args = append(args, subrepoPrefix+st.SubName+"/...")
+	args = append(args, importPathOfRepo(st.SubName)+"/...")
 
 	return st.bc.Exec(path.Join("go", "bin", "go"), buildlet.ExecOpts{
 		Debug:    true, // make buildlet print extra debug in output for failures
@@ -3353,3 +3351,18 @@
 	}
 	return fmt.Sprintf("%x", buf)[:n]
 }
+
+// importPathOfRepo returns the Go import path corresponding to the
+// root of the given repo (Gerrit project). Because it's a Go import
+// path, it always has forward slashes and no trailing slash.
+//
+// For example:
+//   "net"    -> "golang.org/x/net"
+//   "crypto" -> "golang.org/x/crypto"
+//   "dl"     -> "golang.org/dl"
+func importPathOfRepo(repo string) string {
+	if repo == "dl" {
+		return "golang.org/dl"
+	}
+	return "golang.org/x/" + repo
+}
diff --git a/cmd/coordinator/dash.go b/cmd/coordinator/dash.go
index ba91a79..b1555cc 100644
--- a/cmd/coordinator/dash.go
+++ b/cmd/coordinator/dash.go
@@ -105,7 +105,7 @@
 		"RunTime":     runTime,
 	}
 	if br.IsSubrepo() {
-		req["PackagePath"] = subrepoPrefix + br.SubName
+		req["PackagePath"] = importPathOfRepo(br.SubName)
 		req["Hash"] = br.SubRev
 		req["GoHash"] = br.Rev
 	}