1
0
mirror of https://github.com/golang/go synced 2024-11-24 22:57:57 -07:00

cmd/go: allow generate to skip missing files

This change allows go generate to process packages where files may
disappear during code generation. See also #36422.

Updates #36068
This commit is contained in:
Ivan Trubach 2021-04-20 04:01:21 +03:00
parent 3711ea0b5d
commit 4ec27c1540
2 changed files with 40 additions and 0 deletions

View File

@ -201,6 +201,10 @@ func runGenerate(ctx context.Context, cmd *base.Command, args []string) {
func generate(absFile string) bool {
src, err := os.ReadFile(absFile)
if err != nil {
if os.IsNotExist(err) {
// Disappeared during generation - ignore file.
return true
}
log.Fatalf("generate: %s", err)
}

View File

@ -0,0 +1,36 @@
# Install an rm command because some systems don't have it.
env GOBIN=$WORK/tmp/bin
go install rm.go
[plan9] env path=$GOBIN${:}$path
[!plan9] env PATH=$GOBIN${:}$PATH
go generate ./...
-- go.mod --
module genclean
go 1.16
-- a.go --
package genclean
//go:generate rm b.go
-- b.go --
package genclean
-- rm.go --
// +build ignore
package main
import (
"log"
"os"
)
func main() {
if err := os.Remove(os.Args[1]); err != nil {
log.Fatal(err)
}
}