mirror of
https://github.com/golang/go
synced 2024-11-26 19:51:17 -07:00
cmd/go/internal/generate: call modload.InitWorkFile
This is necessary for go generate to enter workspace mode for recognizing package paths in the workspace. Fixes #56098 Change-Id: I25f68de24f4189259353f63194823516e9d3d505 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/559195 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
a64d5be912
commit
b91bad7819
@ -181,6 +181,8 @@ func init() {
|
||||
}
|
||||
|
||||
func runGenerate(ctx context.Context, cmd *base.Command, args []string) {
|
||||
modload.InitWorkfile()
|
||||
|
||||
if generateRunFlag != "" {
|
||||
var err error
|
||||
generateRunRE, err = regexp.Compile(generateRunFlag)
|
||||
|
27
src/cmd/go/testdata/script/generate_workspace.txt
vendored
Normal file
27
src/cmd/go/testdata/script/generate_workspace.txt
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
# This is a regression test for Issue #56098: Go generate
|
||||
# wasn't initializing workspace mode
|
||||
|
||||
[short] skip
|
||||
|
||||
go generate ./mod
|
||||
cmp ./mod/got.txt want.txt
|
||||
|
||||
-- go.work --
|
||||
go 1.22
|
||||
|
||||
use ./mod
|
||||
-- mod/go.mod --
|
||||
module example.com/mod
|
||||
-- mod/gen.go --
|
||||
//go:generate go run gen.go got.txt
|
||||
|
||||
package main
|
||||
|
||||
import "os"
|
||||
|
||||
func main() {
|
||||
outfile := os.Args[1]
|
||||
os.WriteFile(outfile, []byte("Hello World!\n"), 0644)
|
||||
}
|
||||
-- want.txt --
|
||||
Hello World!
|
Loading…
Reference in New Issue
Block a user