| 1 |
From: "Dr. Tobias Quathamer" <[email protected]> |
| 2 |
Date: Mon, 23 Feb 2026 21:32:04 +0100 |
| 3 |
Subject: Add local copy of x/tools/go/expect |
| 4 |
|
| 5 |
go-tools imports golang.org/x/tools/go/expect, a long-deprecated package |
| 6 |
that upstream only keeps around for the sake of analysistest. It was |
| 7 |
removed from golang.org/x/tools and therefore is not shipped by Debian's |
| 8 |
golang-golang-x-tools-dev, so the build fails to resolve the import. |
| 9 |
|
| 10 |
Copy internal/xtools-internal/expect to a new top-level golang-x-tools/ |
| 11 |
directory, which debian/rules rewrites the import path to. Because the |
| 12 |
copy is created from the upstream tree rather than maintained by hand, it |
| 13 |
has to be regenerated whenever upstream changes the expect API, which |
| 14 |
happened for 2026.2.1 where MatchBefore, parse and ExtractGo switched |
| 15 |
from taking a *token.File to taking a *token.FileSet. |
| 16 |
|
| 17 |
Not forwarding this upstream: the import path rewrite is specific to how |
| 18 |
Debian builds this package, and upstream has no reason to drop support |
| 19 |
for the deprecated x/tools/go/expect package. |
| 20 |
|
| 21 |
Forwarded: not-needed |
| 22 |
Last-Update: 2026-09-30 |
| 23 |
--- |
| 24 |
.../xtools-internal => golang-x-tools}/expect/expect.go | 5 +++-- |
| 25 |
.../xtools-internal => golang-x-tools}/expect/extract.go | 15 +++++++-------- |
| 26 |
2 files changed, 10 insertions(+), 10 deletions(-) |
| 27 |
copy {internal/xtools-internal => golang-x-tools}/expect/expect.go (95%) |
| 28 |
copy {internal/xtools-internal => golang-x-tools}/expect/extract.go (95%) |
| 29 |
|
| 30 |
diff --git a/internal/xtools-internal/expect/expect.go b/golang-x-tools/expect/expect.go |
| 31 |
similarity index 95% |
| 32 |
copy from internal/xtools-internal/expect/expect.go |
| 33 |
copy to golang-x-tools/expect/expect.go |
| 34 |
index 273f048..69875cd 100644 |
| 35 |
--- a/internal/xtools-internal/expect/expect.go |
| 36 |
+++ b/golang-x-tools/expect/expect.go |
| 37 |
@@ -79,14 +79,15 @@ type Note struct { |
| 38 |
type ReadFile func(filename string) ([]byte, error) |
| 39 |
|
| 40 |
// MatchBefore attempts to match a pattern in the line before the supplied pos. |
| 41 |
-// It uses the token.File and the ReadFile to work out the contents of the line |
| 42 |
+// It uses the FileSet and the ReadFile to work out the contents of the line |
| 43 |
// that end is part of, and then matches the pattern against the content of the |
| 44 |
// start of that line up to the supplied position. |
| 45 |
// The pattern may be either a simple string, []byte or a *regexp.Regexp. |
| 46 |
// MatchBefore returns the range of the line that matched the pattern, and |
| 47 |
// invalid positions if there was no match, or an error if the line could not be |
| 48 |
// found. |
| 49 |
-func MatchBefore(f *token.File, readFile ReadFile, end token.Pos, pattern any) (token.Pos, token.Pos, error) { |
| 50 |
+func MatchBefore(fset *token.FileSet, readFile ReadFile, end token.Pos, pattern any) (token.Pos, token.Pos, error) { |
| 51 |
+ f := fset.File(end) |
| 52 |
content, err := readFile(f.Name()) |
| 53 |
if err != nil { |
| 54 |
return token.NoPos, token.NoPos, fmt.Errorf("invalid file: %v", err) |
| 55 |
diff --git a/internal/xtools-internal/expect/extract.go b/golang-x-tools/expect/extract.go |
| 56 |
similarity index 95% |
| 57 |
copy from internal/xtools-internal/expect/extract.go |
| 58 |
copy to golang-x-tools/expect/extract.go |
| 59 |
index 69173e2..0c86273 100644 |
| 60 |
--- a/internal/xtools-internal/expect/extract.go |
| 61 |
+++ b/golang-x-tools/expect/extract.go |
| 62 |
@@ -62,7 +62,7 @@ func Parse(fset *token.FileSet, filename string, content []byte) ([]*Note, error |
| 63 |
if text == "" { |
| 64 |
continue |
| 65 |
} |
| 66 |
- parsed, err := parse(file, pos+token.Pos(adjust), text) |
| 67 |
+ parsed, err := parse(fset, pos+token.Pos(adjust), text) |
| 68 |
if err != nil { |
| 69 |
return nil, err |
| 70 |
} |
| 71 |
@@ -80,7 +80,7 @@ func Parse(fset *token.FileSet, filename string, content []byte) ([]*Note, error |
| 72 |
if file == nil { |
| 73 |
return nil, err |
| 74 |
} |
| 75 |
- return ExtractGo(fset.File(file.Pos()), file) |
| 76 |
+ return ExtractGo(fset, file) |
| 77 |
|
| 78 |
case ".mod": |
| 79 |
file, err := modfile.Parse(filename, content, nil) |
| 80 |
@@ -143,8 +143,7 @@ func extractModWork(fset *token.FileSet, exprs []modfile.Expr) ([]*Note, error) |
| 81 |
if text == "" { |
| 82 |
continue |
| 83 |
} |
| 84 |
- pos := token.Pos(int(cmt.Start.Byte) + adjust) |
| 85 |
- parsed, err := parse(fset.File(pos), pos, text) |
| 86 |
+ parsed, err := parse(fset, token.Pos(int(cmt.Start.Byte)+adjust), text) |
| 87 |
if err != nil { |
| 88 |
return nil, err |
| 89 |
} |
| 90 |
@@ -159,7 +158,7 @@ func extractModWork(fset *token.FileSet, exprs []modfile.Expr) ([]*Note, error) |
| 91 |
// sequence of notes. |
| 92 |
// See the package documentation for details about the syntax of those |
| 93 |
// notes. |
| 94 |
-func ExtractGo(tokFile *token.File, file *ast.File) ([]*Note, error) { |
| 95 |
+func ExtractGo(fset *token.FileSet, file *ast.File) ([]*Note, error) { |
| 96 |
var notes []*Note |
| 97 |
for _, g := range file.Comments { |
| 98 |
for _, c := range g.List { |
| 99 |
@@ -167,7 +166,7 @@ func ExtractGo(tokFile *token.File, file *ast.File) ([]*Note, error) { |
| 100 |
if text == "" { |
| 101 |
continue |
| 102 |
} |
| 103 |
- parsed, err := parse(tokFile, token.Pos(int(c.Pos())+adjust), text) |
| 104 |
+ parsed, err := parse(fset, token.Pos(int(c.Pos())+adjust), text) |
| 105 |
if err != nil { |
| 106 |
return nil, err |
| 107 |
} |
| 108 |
@@ -264,11 +263,11 @@ func (t *tokens) Errorf(msg string, args ...any) { |
| 109 |
t.err = fmt.Errorf(msg, args...) |
| 110 |
} |
| 111 |
|
| 112 |
-func parse(tokFile *token.File, base token.Pos, text string) ([]*Note, error) { |
| 113 |
+func parse(fset *token.FileSet, base token.Pos, text string) ([]*Note, error) { |
| 114 |
t := new(tokens).Init(base, text) |
| 115 |
notes := parseComment(t) |
| 116 |
if t.err != nil { |
| 117 |
- return nil, fmt.Errorf("%v: %s", tokFile.Position(t.Pos()), t.err) |
| 118 |
+ return nil, fmt.Errorf("%v: %s", fset.Position(t.Pos()), t.err) |
| 119 |
} |
| 120 |
return notes, nil |
| 121 |
} |