]> Cypherpunks repositories - gostls13.git/commit
go/build, cmd/go: use ast.ParseDirective for go:embed
authorAustin Clements <austin@google.com>
Thu, 11 Sep 2025 20:17:45 +0000 (16:17 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 21 Oct 2025 21:49:13 +0000 (14:49 -0700)
commit29d43df8ab212910487345c354491b67780798cf
treedffa6bf28040f00971c5d280d4473eaa45703b84
parent4e695dd6346e5c7f7e94f54ed177ef96249d2294
go/build, cmd/go: use ast.ParseDirective for go:embed

Currently, "//go:embed" directives are read by bespoke parsers in
go/build and cmd/go/internal/modindex. Replace these bespoke parsers
with scanner.Scanner for finding these directives and
ast.ParseDirective for parsing them.

It's not clear why we had a bespoke parser just for finding
"//go:embed" directives in the first place. We have a bespoke parser
for reading imports in order to avoid having to read the entire source
file into memory, but if we're parsing embeds, we wind up reading the
entire source file into memory anyway. Using scanner.Scanner instead
eliminates some truly confusing code.

This also demonstrates that ast.ParseDirective as proposed in #68021
achieves useful API coverage.

Updates #68021.

Change-Id: Ieb68738121dcff605a6a704a8045ddd2ff35df35
Reviewed-on: https://go-review.googlesource.com/c/go/+/704836
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Austin Clements <austin@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
src/cmd/go/internal/modindex/build_read.go
src/go/build/read.go