1
0
mirror of https://github.com/golang/go synced 2024-11-22 13:14:55 -07:00

cmd/go: print the package containing the unmatched embed patterns

Fixes #49534

Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Change-Id: Ia95868ecc1c3dc9715c0fdc7ab1f30348fffaef5
Reviewed-on: https://go-review.googlesource.com/c/go/+/540017
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Quan Tong 2023-11-06 12:01:13 +07:00 committed by Gopher Robot
parent db67824361
commit aa9d2de559
2 changed files with 36 additions and 19 deletions

View File

@ -324,7 +324,13 @@ func vendorPkg(vdir, pkg string) {
}
embeds, err := load.ResolveEmbed(bp.Dir, embedPatterns)
if err != nil {
base.Fatal(err)
format := "go: resolving embeds in %s: %v\n"
if vendorE {
fmt.Fprintf(os.Stderr, format, pkg, err)
} else {
base.Errorf(format, pkg, err)
}
return
}
for _, embed := range embeds {
embedDst := filepath.Join(dst, embed)
@ -333,23 +339,30 @@ func vendorPkg(vdir, pkg string) {
}
// Copy the file as is done by copyDir below.
r, err := os.Open(filepath.Join(src, embed))
err := func() error {
r, err := os.Open(filepath.Join(src, embed))
if err != nil {
return err
}
if err := os.MkdirAll(filepath.Dir(embedDst), 0777); err != nil {
return err
}
w, err := os.Create(embedDst)
if err != nil {
return err
}
if _, err := io.Copy(w, r); err != nil {
return err
}
r.Close()
return w.Close()
}()
if err != nil {
base.Fatal(err)
}
if err := os.MkdirAll(filepath.Dir(embedDst), 0777); err != nil {
base.Fatal(err)
}
w, err := os.Create(embedDst)
if err != nil {
base.Fatal(err)
}
if _, err := io.Copy(w, r); err != nil {
base.Fatal(err)
}
r.Close()
if err := w.Close(); err != nil {
base.Fatal(err)
if vendorE {
fmt.Fprintf(os.Stderr, "go: %v\n", err)
} else {
base.Error(err)
}
}
}
}

View File

@ -6,11 +6,15 @@ cmp vendor/example.com/a/subdir/test/xtest/embed.txt a/subdir/test/xtest/embed.t
cd broken_no_matching_files
! go mod vendor
stderr 'go: pattern foo.txt: no matching files found'
stderr '^go: resolving embeds in example.com/brokendep: pattern foo.txt: no matching files found$'
go mod vendor -e
stderr '^go: resolving embeds in example.com/brokendep: pattern foo.txt: no matching files found$'
cd ../broken_bad_pattern
! go mod vendor
stderr 'go: pattern ../foo.txt: invalid pattern syntax'
stderr '^go: resolving embeds in example.com/brokendep: pattern ../foo.txt: invalid pattern syntax$'
go mod vendor -e
stderr '^go: resolving embeds in example.com/brokendep: pattern ../foo.txt: invalid pattern syntax$'
cd ../embed_go122
go mod vendor