Skip to content

Commit

Permalink
please_go: remove Go <= 1.19 coverage generation code (#291)
Browse files Browse the repository at this point in the history
Go 1.20 made breaking changes to the way in which coverage is computed.
This required the `coverageredesign` GOEXPERIMENT to be enabled when
using go-rules with Go 1.20 onwards.

Go 1.19 has now been EOL for almost a year, and the `coveragedesign`
GOEXPERIMENT will be removed from Go shortly, having been the default
for around 18 months. Remove the following features from please_go that
supported the Go <= 1.19 method of computing coverage:

* The `covervars` command, which is no longer necessary with
  `coverageredesign`.
* The generation of Go <= 1.19-compatible test main files with the
  `testmain` command.
  • Loading branch information
chrisnovakovic authored Aug 27, 2024
1 parent c356931 commit f0ce150
Show file tree
Hide file tree
Showing 11 changed files with 6 additions and 416 deletions.
2 changes: 0 additions & 2 deletions tools/please_go/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ go_binary(
deps = [
"//third_party/go:flags",
"//tools/please_go/cover",
"//tools/please_go/covervars",
"//tools/please_go/embed",
"//tools/please_go/filter",
"//tools/please_go/generate",
Expand Down Expand Up @@ -38,7 +37,6 @@ genrule(
visibility = ["PUBLIC"],
deps = [
"//tools/please_go/cover:srcs",
"//tools/please_go/covervars:srcs",
"//tools/please_go/embed:srcs",
"//tools/please_go/filter:srcs",
"//tools/please_go/generate:srcs",
Expand Down
15 changes: 0 additions & 15 deletions tools/please_go/covervars/BUILD

This file was deleted.

25 changes: 0 additions & 25 deletions tools/please_go/covervars/cover_vars.go

This file was deleted.

11 changes: 0 additions & 11 deletions tools/please_go/please_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/peterebden/go-cli-init/v5/flags"

"github.com/please-build/go-rules/tools/please_go/cover"
"github.com/please-build/go-rules/tools/please_go/covervars"
"github.com/please-build/go-rules/tools/please_go/embed"
"github.com/please-build/go-rules/tools/please_go/filter"
"github.com/please-build/go-rules/tools/please_go/generate"
Expand Down Expand Up @@ -52,12 +51,6 @@ var opts = struct {
Sources []string `positional-arg-name:"sources" description:"Test source files" required:"true"`
} `positional-args:"true" required:"true"`
} `command:"testmain" alias:"t" description:"Generates a go main package to run the tests in a package."`
CoverVars struct {
ImportPath string `short:"i" long:"import_path" description:"The import path for the source files"`
Args struct {
Sources []string `positional-arg-name:"sources" description:"Source files to generate embed config for"`
} `positional-args:"true"`
} `command:"covervars" description:"Generates coverage variable config for a set of go src files"`
Cover struct {
GoTool string `short:"g" long:"go" default:"go" env:"TOOLS_GO" description:"Go binary to run"`
CoverTool string `short:"t" long:"go_cover" env:"TOOLS_COVER" description:"Go coverage tool to run"`
Expand Down Expand Up @@ -170,10 +163,6 @@ var subCommands = map[string]func() int{
}
return 0
},
"covervars": func() int {
covervars.GenCoverVars(os.Stdout, opts.CoverVars.ImportPath, opts.CoverVars.Args.Sources)
return 0
},
"filter": func() int {
filter.Filter(opts.Filter.Tags, opts.Filter.Args.Sources)
return 0
Expand Down
13 changes: 0 additions & 13 deletions tools/please_go/test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ filegroup(
go_library(
name = "test",
srcs = [
"find_cover_vars.go",
"gotest.go",
"write_test_main.go",
],
Expand All @@ -19,18 +18,6 @@ go_library(
],
)

go_test(
name = "find_cover_vars_test",
srcs = ["find_cover_vars_test.go"],
data = [
"test_data",
],
deps = [
":test",
"//third_party/go:testify",
],
)

go_test(
name = "write_test_main_test",
srcs = ["write_test_main_test.go"],
Expand Down
94 changes: 0 additions & 94 deletions tools/please_go/test/find_cover_vars.go

This file was deleted.

45 changes: 0 additions & 45 deletions tools/please_go/test/find_cover_vars_test.go

This file was deleted.

19 changes: 1 addition & 18 deletions tools/please_go/test/gotest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,11 @@ package test

import (
"log"

"github.com/please-build/go-rules/tools/please_go/install/toolchain"
)

// PleaseGoTest will generate the test main for the provided sources
func PleaseGoTest(goTool, dir, testPackage, output string, sources, exclude []string, isBenchmark, external bool) {
tc := toolchain.Toolchain{GoTool: goTool}
minor, err := tc.GoMinorVersion()
if err != nil {
log.Fatalf("Failed to determine Go version: %s", err)
}
if minor >= 20 {
if err := WriteTestMain(testPackage, sources, output, dir != "", nil, isBenchmark, true, true); err != nil {
log.Fatalf("Error writing test main: %s", err)
}
return
}
coverVars, err := FindCoverVars(dir, testPackage, external, exclude)
if err != nil {
log.Fatalf("Error scanning for coverage: %s", err)
}
if err := WriteTestMain(testPackage, sources, output, dir != "", coverVars, isBenchmark, minor >= 18, false); err != nil {
if err := WriteTestMain(testPackage, sources, output, dir != "", isBenchmark, true); err != nil {
log.Fatalf("Error writing test main: %s", err)
}
}
21 changes: 0 additions & 21 deletions tools/please_go/test/test_data/test/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,6 @@ func TestReadCopiedPkgdef(t *testing.T) {
assert.Equal(t, coverageVars, vars)
}

func TestFindCoverVars(t *testing.T) {
vars, err := FindCoverVars("src/build/go/test_data", []string{"src/build/go/test_data/x"})
assert.NoError(t, err)
assert.Equal(t, coverageVars, vars)
}

func TestFindCoverVarsFailsGracefully(t *testing.T) {
_, err := FindCoverVars("wibble", []string{})
assert.Error(t, err)
}

func TestFindCoverVarsReturnsNothingForEmptyPath(t *testing.T) {
vars, err := FindCoverVars("", []string{})
assert.NoError(t, err)
assert.Equal(t, 0, len(vars))
}

func readPkgdef(name string) ([]string, error) {
return nil, nil
}

func FindCoverVars(filename string, vars []string) ([]string, error) {
return nil, nil
}
Loading

0 comments on commit f0ce150

Please sign in to comment.