From 0ebacc111eb99a9f88516364bd855b5e1c947691 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 5 May 2022 10:13:48 -0400 Subject: [PATCH] internal: remove pre-go1.12 conditionally compiled files Change-Id: I496ad24654990341eae9508587e950abde05b540 Reviewed-on: https://go-review.googlesource.com/c/tools/+/404334 Reviewed-by: Robert Findley Reviewed-by: Bryan Mills Run-TryBot: Alan Donovan --- internal/span/token.go | 2 +- internal/span/token111.go | 40 --------------------------------- internal/span/token112.go | 17 -------------- internal/testenv/testenv.go | 18 +++++++++++---- internal/testenv/testenv_112.go | 28 ----------------------- 5 files changed, 15 insertions(+), 90 deletions(-) delete mode 100644 internal/span/token111.go delete mode 100644 internal/span/token112.go delete mode 100644 internal/testenv/testenv_112.go diff --git a/internal/span/token.go b/internal/span/token.go index 6f8b9b570c..3fd22199d1 100644 --- a/internal/span/token.go +++ b/internal/span/token.go @@ -183,7 +183,7 @@ func (l *FileConverter) ToOffset(line, col int) (int, error) { // at the end of the file, allowing for a trailing eol return l.file.Size(), nil } - pos := lineStart(l.file, line) + pos := l.file.LineStart(line) if !pos.IsValid() { return -1, fmt.Errorf("line is not in file") } diff --git a/internal/span/token111.go b/internal/span/token111.go deleted file mode 100644 index c41e94b8fb..0000000000 --- a/internal/span/token111.go +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build !go1.12 -// +build !go1.12 - -package span - -import ( - "go/token" -) - -// lineStart is the pre-Go 1.12 version of (*token.File).LineStart. For Go -// versions <= 1.11, we borrow logic from the analysisutil package. -// TODO(rstambler): Delete this file when we no longer support Go 1.11. -func lineStart(f *token.File, line int) token.Pos { - // Use binary search to find the start offset of this line. - - min := 0 // inclusive - max := f.Size() // exclusive - for { - offset := (min + max) / 2 - pos := f.Pos(offset) - posn := f.Position(pos) - if posn.Line == line { - return pos - (token.Pos(posn.Column) - 1) - } - - if min+1 >= max { - return token.NoPos - } - - if posn.Line < line { - min = offset - } else { - max = offset - } - } -} diff --git a/internal/span/token112.go b/internal/span/token112.go deleted file mode 100644 index 4c4dea1708..0000000000 --- a/internal/span/token112.go +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build go1.12 -// +build go1.12 - -package span - -import ( - "go/token" -) - -// TODO(rstambler): Delete this file when we no longer support Go 1.11. -func lineStart(f *token.File, line int) token.Pos { - return f.LineStart(line) -} diff --git a/internal/testenv/testenv.go b/internal/testenv/testenv.go index 1d0cc3c08b..bfadb44be6 100644 --- a/internal/testenv/testenv.go +++ b/internal/testenv/testenv.go @@ -13,6 +13,7 @@ import ( "io/ioutil" "os" "runtime" + "runtime/debug" "strings" "sync" "time" @@ -32,10 +33,19 @@ type helperer interface { // packageMainIsDevel reports whether the module containing package main // is a development version (if module information is available). -// -// Builds in GOPATH mode and builds that lack module information are assumed to -// be development versions. -var packageMainIsDevel = func() bool { return true } +func packageMainIsDevel() bool { + info, ok := debug.ReadBuildInfo() + if !ok { + // Most test binaries currently lack build info, but this should become more + // permissive once https://golang.org/issue/33976 is fixed. + return true + } + + // Note: info.Main.Version describes the version of the module containing + // package main, not the version of “the main module”. + // See https://golang.org/issue/33975. + return info.Main.Version == "(devel)" +} var checkGoGoroot struct { once sync.Once diff --git a/internal/testenv/testenv_112.go b/internal/testenv/testenv_112.go deleted file mode 100644 index 4b6e57d682..0000000000 --- a/internal/testenv/testenv_112.go +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2019 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -//go:build go1.12 -// +build go1.12 - -package testenv - -import "runtime/debug" - -func packageMainIsDevelModule() bool { - info, ok := debug.ReadBuildInfo() - if !ok { - // Most test binaries currently lack build info, but this should become more - // permissive once https://golang.org/issue/33976 is fixed. - return true - } - - // Note: info.Main.Version describes the version of the module containing - // package main, not the version of “the main module”. - // See https://golang.org/issue/33975. - return info.Main.Version == "(devel)" -} - -func init() { - packageMainIsDevel = packageMainIsDevelModule -}