Skip to content

Commit

Permalink
*: miscellaneous fixes to allow building with go1.13
Browse files Browse the repository at this point in the history
Disable modules so that `bin/prereqs` and other uses of
`go/build.Import` do not run into a weird permissioning problem with
writing to the modules cache.

Remove unnecessary calls to `flag.Parse()` from tests. Something changed
with the order of initializers and now explicitly calling `flag.Parse()`
in a test causes the flags in the `testing` package to not be registered
which causes the test to fail to run. The explicit call to
`flag.Parse()` wasn't necessary in any case, as the `testing` package
does that automatically.

Release note: None (we're not upgrading to go1.13 yet)
  • Loading branch information
petermattis committed Oct 21, 2019
1 parent 50cd9a7 commit f5009c8
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 13 deletions.
4 changes: 0 additions & 4 deletions pkg/acceptance/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,5 @@ import (
"time"
)

func init() {
flag.Parse()
}

var flagDuration = flag.Duration("d", 5*time.Second, "for duration-limited tests, how long to run them for")
var flagLogDir = flag.String("l", "", "the directory to store log files, relative to the test source")
1 change: 1 addition & 0 deletions pkg/cmd/github-pull-request-make/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"strings"
"time"

_ "github.com/cockroachdb/cockroach/pkg/testutils/buildutil"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/prereqs/prereqs.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ import (
"os"
"path/filepath"
"strings"

_ "github.com/cockroachdb/cockroach/pkg/testutils/buildutil"
)

var buildCtx = func() build.Context {
Expand Down
4 changes: 0 additions & 4 deletions pkg/internal/sqlsmith/sqlsmith_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ var (
flagCheckVec = flag.Bool("check-vec", false, "fail if a generated statement cannot be vectorized")
)

func init() {
flag.Parse()
}

// TestGenerateParse verifies that statements produced by Generate can be
// parsed. This is useful because since we make AST nodes directly we can
// sometimes put them into bad states that the parser would never do.
Expand Down
4 changes: 0 additions & 4 deletions pkg/sql/opt/opbench/opbench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ const rewriteActualFlag = "opbench-rewrite-actual"
var rewriteEstimated = flag.Bool(rewriteEstimatedFlag, false, "re-calculate the estimated costs for each Plan")
var rewriteActual = flag.Bool(rewriteActualFlag, false, "re-measure the runtime for each Plan")

func init() {
flag.Parse()
}

// TODO(justin): we need a system to get consistent re-measurements of all the
// "actual" results. We will probably want some ability to kick off a roachprod
// cluster which will crunch through them all. It's still valuable to be
Expand Down
11 changes: 11 additions & 0 deletions pkg/testutils/buildutil/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,24 @@ package buildutil

import (
"go/build"
"os"
"runtime"
"strings"
"testing"

"github.com/pkg/errors"
)

func init() {
// NB: This is a hack to disable the use of go modules with
// build.Import. This will probably break with a future version of Go, but
// suffices until we move to using go modules. See go/build.Context.importGo
// (https://github.com/golang/go/blob/master/src/go/build/build.go#L999) and
// the logic to skip using `go list` if the env far "GO111MODULE" is set to
// "off".
_ = os.Setenv("GO111MODULE", "off")
}

func short(in string) string {
return strings.Replace(in, "github.com/cockroachdb/cockroach/pkg/", "./pkg/", -1)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/testutils/lint/lint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"testing"

"github.com/cockroachdb/cockroach/pkg/sql/sem/builtins"
_ "github.com/cockroachdb/cockroach/pkg/testutils/buildutil"
"github.com/ghemawat/stream"
"github.com/pkg/errors"
"golang.org/x/tools/go/buildutil"
Expand Down
1 change: 0 additions & 1 deletion pkg/util/timeutil/pgdate/parsing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func init() {
`a postgresql connect string suitable for sql.Open(), `+
`to enable cross-checking during development; for example: `+
`-pgdate.db="database=bob sslmode=disable"`)
flag.Parse()
}

type timeData struct {
Expand Down

0 comments on commit f5009c8

Please sign in to comment.