diff options
Diffstat (limited to 'libgo/go/go/build/build.go')
-rw-r--r-- | libgo/go/go/build/build.go | 28 |
1 files changed, 9 insertions, 19 deletions
diff --git a/libgo/go/go/build/build.go b/libgo/go/go/build/build.go index f19f3d4a589..1e91e6eb08b 100644 --- a/libgo/go/go/build/build.go +++ b/libgo/go/go/build/build.go @@ -791,7 +791,7 @@ Found: } // package was not found - return p, fmt.Errorf("cannot find package %q in:\n\t%s", path, p.Dir) + return p, fmt.Errorf("cannot find package %q in:\n\t%s", p.ImportPath, p.Dir) } if mode&FindOnly != 0 { @@ -896,7 +896,7 @@ Found: isTest := strings.HasSuffix(name, "_test.go") isXTest := false - if isTest && strings.HasSuffix(pkg, "_test") { + if isTest && strings.HasSuffix(pkg, "_test") && p.Name != pkg { isXTest = true pkg = pkg[:len(pkg)-len("_test")] } @@ -1260,19 +1260,14 @@ func findImportComment(data []byte) (s string, line int) { var comment []byte switch { case bytes.HasPrefix(data, slashSlash): - i := bytes.Index(data, newline) - if i < 0 { - i = len(data) - } - comment = data[2:i] + comment, _, _ = bytes.Cut(data[2:], newline) case bytes.HasPrefix(data, slashStar): - data = data[2:] - i := bytes.Index(data, starSlash) - if i < 0 { + var ok bool + comment, _, ok = bytes.Cut(data[2:], starSlash) + if !ok { // malformed comment return "", 0 } - comment = data[:i] if bytes.Contains(comment, newline) { return "", 0 } @@ -1656,12 +1651,10 @@ func (ctxt *Context) saveCgo(filename string, di *Package, cg *ast.CommentGroup) } // Split at colon. - line = strings.TrimSpace(line[4:]) - i := strings.Index(line, ":") - if i < 0 { + line, argstr, ok := strings.Cut(strings.TrimSpace(line[4:]), ":") + if !ok { return fmt.Errorf("%s: invalid #cgo line: %s", filename, orig) } - line, argstr := line[:i], line[i+1:] // Parse GOOS/GOARCH stuff. f := strings.Fields(line) @@ -1687,7 +1680,6 @@ func (ctxt *Context) saveCgo(filename string, di *Package, cg *ast.CommentGroup) if err != nil { return fmt.Errorf("%s: invalid #cgo line: %s", filename, orig) } - var ok bool for i, arg := range args { if arg, ok = expandSrcDir(arg, di.Dir); !ok { return fmt.Errorf("%s: malformed #cgo argument: %s", filename, arg) @@ -1946,9 +1938,7 @@ func (ctxt *Context) matchTag(name string, allTags map[string]bool) bool { // if GOOS=illumos, then files with GOOS=solaris are also matched. // if GOOS=ios, then files with GOOS=darwin are also matched. func (ctxt *Context) goodOSArchFile(name string, allTags map[string]bool) bool { - if dot := strings.Index(name, "."); dot != -1 { - name = name[:dot] - } + name, _, _ = strings.Cut(name, ".") // Before Go 1.4, a file called "linux.go" would be equivalent to having a // build tag "linux" in that file. For Go 1.4 and beyond, we require this |