From: "Dr. Tobias Quathamer" Date: Mon, 23 Feb 2026 21:32:04 +0100 Subject: Add local copy of x/tools/go/expect go-tools imports golang.org/x/tools/go/expect, a long-deprecated package that upstream only keeps around for the sake of analysistest. It was removed from golang.org/x/tools and therefore is not shipped by Debian's golang-golang-x-tools-dev, so the build fails to resolve the import. Copy internal/xtools-internal/expect to a new top-level golang-x-tools/ directory, which debian/rules rewrites the import path to. Because the copy is created from the upstream tree rather than maintained by hand, it has to be regenerated whenever upstream changes the expect API, which happened for 2026.2.1 where MatchBefore, parse and ExtractGo switched from taking a *token.File to taking a *token.FileSet. Not forwarding this upstream: the import path rewrite is specific to how Debian builds this package, and upstream has no reason to drop support for the deprecated x/tools/go/expect package. Forwarded: not-needed Last-Update: 2026-09-30 --- .../xtools-internal => golang-x-tools}/expect/expect.go | 5 +++-- .../xtools-internal => golang-x-tools}/expect/extract.go | 15 +++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) copy {internal/xtools-internal => golang-x-tools}/expect/expect.go (95%) copy {internal/xtools-internal => golang-x-tools}/expect/extract.go (95%) diff --git a/internal/xtools-internal/expect/expect.go b/golang-x-tools/expect/expect.go similarity index 95% copy from internal/xtools-internal/expect/expect.go copy to golang-x-tools/expect/expect.go index 273f048..69875cd 100644 --- a/internal/xtools-internal/expect/expect.go +++ b/golang-x-tools/expect/expect.go @@ -79,14 +79,15 @@ type Note struct { type ReadFile func(filename string) ([]byte, error) // MatchBefore attempts to match a pattern in the line before the supplied pos. -// It uses the token.File and the ReadFile to work out the contents of the line +// It uses the FileSet and the ReadFile to work out the contents of the line // that end is part of, and then matches the pattern against the content of the // start of that line up to the supplied position. // The pattern may be either a simple string, []byte or a *regexp.Regexp. // MatchBefore returns the range of the line that matched the pattern, and // invalid positions if there was no match, or an error if the line could not be // found. -func MatchBefore(f *token.File, readFile ReadFile, end token.Pos, pattern any) (token.Pos, token.Pos, error) { +func MatchBefore(fset *token.FileSet, readFile ReadFile, end token.Pos, pattern any) (token.Pos, token.Pos, error) { + f := fset.File(end) content, err := readFile(f.Name()) if err != nil { return token.NoPos, token.NoPos, fmt.Errorf("invalid file: %v", err) diff --git a/internal/xtools-internal/expect/extract.go b/golang-x-tools/expect/extract.go similarity index 95% copy from internal/xtools-internal/expect/extract.go copy to golang-x-tools/expect/extract.go index 69173e2..0c86273 100644 --- a/internal/xtools-internal/expect/extract.go +++ b/golang-x-tools/expect/extract.go @@ -62,7 +62,7 @@ func Parse(fset *token.FileSet, filename string, content []byte) ([]*Note, error if text == "" { continue } - parsed, err := parse(file, pos+token.Pos(adjust), text) + parsed, err := parse(fset, pos+token.Pos(adjust), text) if err != nil { return nil, err } @@ -80,7 +80,7 @@ func Parse(fset *token.FileSet, filename string, content []byte) ([]*Note, error if file == nil { return nil, err } - return ExtractGo(fset.File(file.Pos()), file) + return ExtractGo(fset, file) case ".mod": file, err := modfile.Parse(filename, content, nil) @@ -143,8 +143,7 @@ func extractModWork(fset *token.FileSet, exprs []modfile.Expr) ([]*Note, error) if text == "" { continue } - pos := token.Pos(int(cmt.Start.Byte) + adjust) - parsed, err := parse(fset.File(pos), pos, text) + parsed, err := parse(fset, token.Pos(int(cmt.Start.Byte)+adjust), text) if err != nil { return nil, err } @@ -159,7 +158,7 @@ func extractModWork(fset *token.FileSet, exprs []modfile.Expr) ([]*Note, error) // sequence of notes. // See the package documentation for details about the syntax of those // notes. -func ExtractGo(tokFile *token.File, file *ast.File) ([]*Note, error) { +func ExtractGo(fset *token.FileSet, file *ast.File) ([]*Note, error) { var notes []*Note for _, g := range file.Comments { for _, c := range g.List { @@ -167,7 +166,7 @@ func ExtractGo(tokFile *token.File, file *ast.File) ([]*Note, error) { if text == "" { continue } - parsed, err := parse(tokFile, token.Pos(int(c.Pos())+adjust), text) + parsed, err := parse(fset, token.Pos(int(c.Pos())+adjust), text) if err != nil { return nil, err } @@ -264,11 +263,11 @@ func (t *tokens) Errorf(msg string, args ...any) { t.err = fmt.Errorf(msg, args...) } -func parse(tokFile *token.File, base token.Pos, text string) ([]*Note, error) { +func parse(fset *token.FileSet, base token.Pos, text string) ([]*Note, error) { t := new(tokens).Init(base, text) notes := parseComment(t) if t.err != nil { - return nil, fmt.Errorf("%v: %s", tokFile.Position(t.Pos()), t.err) + return nil, fmt.Errorf("%v: %s", fset.Position(t.Pos()), t.err) } return notes, nil }