Skip to content

Commit dfd9562

Browse files
dmitshurcodebien
authored andcommitted
dashboard, cmd/coordinator: add controls to skip subrepo dirs in GOPATH mode
This change adds controls to the dashboard package that makes it possible to skip certain directories in subrepos from being tested in GOPATH mode. It uses this control mechanism to skip the gopls directory in x/tools from being tested in GOPATH mode. That directory and everything inside is developed with support for module mode only. All other packages in x/tools continue to be supported both in module and GOPATH modes for the current and previous releases, as per release policy¹. ¹ https://golang.org/doc/devel/release.html#policy Fixes golang/go#34190 Change-Id: Icdb4d0e1419f69c84c9a3f9a33727a09a35599f4 Reviewed-on: https://go-review.googlesource.com/c/build/+/194397 Run-TryBot: Dmitri Shuralyov <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 03e07c0 commit dfd9562

File tree

3 files changed

+98
-4
lines changed

3 files changed

+98
-4
lines changed

cmd/coordinator/coordinator.go

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,6 +2372,12 @@ func (st *buildStatus) runSubrepoTests() (remoteErr, err error) {
23722372
return nil, fmt.Errorf("failed to determine go env GOMOD value: %v", err)
23732373
}
23742374

2375+
// patterns defines import path patterns to provide to 'go test'.
2376+
// The starting default value is "golang.org/x/{repo}/...".
2377+
patterns := []string{
2378+
importPathOfRepo(st.SubName) + "/...",
2379+
}
2380+
23752381
// The next large step diverges into two code paths,
23762382
// one for module mode and another for GOPATH mode.
23772383
//
@@ -2419,7 +2425,7 @@ func (st *buildStatus) runSubrepoTests() (remoteErr, err error) {
24192425
return nil, fmt.Errorf("exec go list on buildlet: %v", err)
24202426
}
24212427
if rErr != nil {
2422-
fmt.Fprintf(st, "go list error:\n%s", &buf)
2428+
fmt.Fprintf(st, "go list error: %v\noutput:\n%s", rErr, &buf)
24232429
return rErr, nil
24242430
}
24252431
for _, p := range strings.Fields(buf.String()) {
@@ -2469,7 +2475,35 @@ func (st *buildStatus) runSubrepoTests() (remoteErr, err error) {
24692475
}
24702476
}
24712477

2472-
// TODO(dmitshur): Allow dashboard to filter out directories to test. See golang.org/issue/34190.
2478+
// The dashboard offers control over what packages to test in GOPATH mode.
2479+
// Compute a list of packages by calling 'go list'. See golang.org/issue/34190.
2480+
{
2481+
repoPath := importPathOfRepo(st.SubName)
2482+
var buf bytes.Buffer
2483+
sp := st.CreateSpan("listing_subrepo_packages", st.SubName)
2484+
rErr, err := st.bc.Exec(path.Join("go", "bin", "go"), buildlet.ExecOpts{
2485+
Output: &buf,
2486+
Dir: "gopath/src/" + repoPath,
2487+
ExtraEnv: append(st.conf.Env(), "GOROOT="+goroot, "GOPATH="+gopath),
2488+
Path: []string{"$WORKDIR/go/bin", "$PATH"},
2489+
Args: []string{"list", repoPath + "/..."},
2490+
})
2491+
sp.Done(firstNonNil(err, rErr))
2492+
if err != nil {
2493+
return nil, fmt.Errorf("exec go list on buildlet: %v", err)
2494+
}
2495+
if rErr != nil {
2496+
fmt.Fprintf(st, "go list error: %v\noutput:\n%s", rErr, &buf)
2497+
return rErr, nil
2498+
}
2499+
patterns = nil
2500+
for _, importPath := range strings.Fields(buf.String()) {
2501+
if !st.conf.ShouldTestPackageInGOPATHMode(importPath) {
2502+
continue
2503+
}
2504+
patterns = append(patterns, importPath)
2505+
}
2506+
}
24732507
}
24742508

24752509
// TODO(dmitshur): For some subrepos, test in both modes. See golang.org/issue/30233.
@@ -2491,7 +2525,7 @@ func (st *buildStatus) runSubrepoTests() (remoteErr, err error) {
24912525
if st.conf.IsRace() {
24922526
args = append(args, "-race")
24932527
}
2494-
args = append(args, importPathOfRepo(st.SubName)+"/...")
2528+
args = append(args, patterns...)
24952529

24962530
return st.bc.Exec(path.Join("go", "bin", "go"), buildlet.ExecOpts{
24972531
Debug: true, // make buildlet print extra debug in output for failures
@@ -2527,6 +2561,16 @@ func (st *buildStatus) goMod(importPath, goroot, gopath string) (string, error)
25272561
return env.GoMod, err
25282562
}
25292563

2564+
// firstNonNil returns the first non-nil error, or nil otherwise.
2565+
func firstNonNil(errs ...error) error {
2566+
for _, e := range errs {
2567+
if e != nil {
2568+
return e
2569+
}
2570+
}
2571+
return nil
2572+
}
2573+
25302574
// moduleProxy returns the GOPROXY environment value to use for module-enabled
25312575
// tests.
25322576
//

dashboard/builders.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,30 @@ func (c *BuildConfig) ModulesEnv(repo string) (env []string) {
733733
case "oauth2", "build", "perf", "website":
734734
env = append(env, "GO111MODULE=on")
735735
}
736-
return
736+
return env
737+
}
738+
739+
// ShouldTestPackageInGOPATHMode is used to control whether the package
740+
// with the specified import path should be tested in GOPATH mode.
741+
//
742+
// When running tests for all golang.org/* repositories in GOPATH mode,
743+
// this method is called repeatedly with the full import path of each
744+
// package that is found and is being considered for testing in GOPATH
745+
// mode. It's not used and has no effect on import paths in the main
746+
// "go" repository. It has no effect on tests done in module mode.
747+
//
748+
// When considering making changes here, keep the release policy in mind:
749+
//
750+
// https://golang.org/doc/devel/release.html#policy
751+
//
752+
func (*BuildConfig) ShouldTestPackageInGOPATHMode(importPath string) bool {
753+
if importPath == "golang.org/x/tools/gopls" ||
754+
strings.HasPrefix(importPath, "golang.org/x/tools/gopls/") {
755+
// Don't test golang.org/x/tools/gopls/... in GOPATH mode.
756+
return false
757+
}
758+
// Test everything else in GOPATH mode as usual.
759+
return true
737760
}
738761

739762
func (c *BuildConfig) IsReverse() bool { return c.hostConf().IsReverse }

dashboard/builders_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,30 @@ func TestShouldRunDistTest(t *testing.T) {
595595
}
596596
}
597597
}
598+
599+
func TestShouldTestPackageInGOPATHMode(t *testing.T) {
600+
// This function doesn't change behavior depending on the builder
601+
// at this time, so just use a common one.
602+
bc, ok := Builders["linux-amd64"]
603+
if !ok {
604+
t.Fatal("unknown builder")
605+
}
606+
607+
tests := []struct {
608+
importPath string
609+
want bool
610+
}{
611+
{"golang.org/x/image/bmp", true},
612+
{"golang.org/x/tools/go/ast/astutil", true},
613+
{"golang.org/x/tools/go/packages", true},
614+
{"golang.org/x/tools", true}, // Three isn't a package there, but if there was, it should be tested.
615+
{"golang.org/x/tools/gopls", false},
616+
{"golang.org/x/tools/gopls/internal/foobar", false},
617+
}
618+
for _, tt := range tests {
619+
got := bc.ShouldTestPackageInGOPATHMode(tt.importPath)
620+
if got != tt.want {
621+
t.Errorf("ShouldTestPackageInGOPATHMode(%q) = %v; want %v", tt.importPath, got, tt.want)
622+
}
623+
}
624+
}

0 commit comments

Comments
 (0)