go/buildutil: ExpandPatterns: ignore a trailing slash in a pattern
Previously, a trailing slash would cause "foo/" to be treated as the name of a package, with comical results. Fixed golang/go#14584 Change-Id: I660f8a079bbd63d3645812e516a9264c8e080e61 Reviewed-on: https://go-review.googlesource.com/30452 Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
27f88d9b7a
commit
03663480fa
|
@ -137,6 +137,9 @@ func allPackages(ctxt *build.Context, root string, ch chan<- item) {
|
|||
//
|
||||
// encoding/... -encoding/xml
|
||||
//
|
||||
// A trailing slash in a pattern is ignored. (Path components of Go
|
||||
// package names are separated by slash, not the platform's path separator.)
|
||||
//
|
||||
func ExpandPatterns(ctxt *build.Context, patterns []string) map[string]bool {
|
||||
// TODO(adonovan): support other features of 'go list':
|
||||
// - "std"/"cmd"/"all" meta-packages
|
||||
|
@ -187,7 +190,7 @@ func ExpandPatterns(ctxt *build.Context, patterns []string) map[string]bool {
|
|||
}
|
||||
} else {
|
||||
// single package
|
||||
doPkg(arg, neg)
|
||||
doPkg(strings.TrimSuffix(arg, "/"), neg)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,8 @@ func TestExpandPatterns(t *testing.T) {
|
|||
{"...", "encoding encoding/hex encoding/json encoding/xml fmt"},
|
||||
{"encoding/... -encoding/xml", "encoding encoding/hex encoding/json"},
|
||||
{"... -encoding/...", "fmt"},
|
||||
{"encoding", "encoding"},
|
||||
{"encoding/", "encoding"},
|
||||
} {
|
||||
var pkgs []string
|
||||
for pkg := range buildutil.ExpandPatterns(ctxt, strings.Fields(test.patterns)) {
|
||||
|
|
Loading…
Reference in New Issue