defer os.RemoveAll(dir)
dst := filepath.Join(dir, strings.TrimSuffix(files[0], ".go"))
- args := []string{"build", "-gcflags=-L -e", "-o=" + dst} // TODO(gri) no need for -gcflags=-L if go tool is adjusted
+ args := []string{"build", "-gcflags=-e", "-o=" + dst}
for _, file := range files {
args = append(args, path(file))
}
// Compile Go.
objpkg := objdir + "_pkg_.a"
ofile, out, err := BuildToolchain.gc(b, a, objpkg, icfg.Bytes(), embedcfg, symabis, len(sfiles) > 0, pgoProfile, gofiles)
+ if len(out) > 0 && (p.UsesCgo() || p.UsesSwig()) && !cfg.BuildX {
+ // Fix up output referring to cgo-generated code to be more readable.
+ // Replace *[100]_Ctype_foo with *[100]C.foo.
+ // If we're using -x, assume we're debugging and want the full dump, so disable the rewrite.
+ out = cgoTypeSigRe.ReplaceAll(out, []byte("C."))
+ }
if err := sh.reportCmd("", "", out, err); err != nil {
return err
}
return nil
}
+var cgoTypeSigRe = lazyregexp.New(`\b_C2?(type|func|var|macro)_\B`)
+
func (b *Builder) checkDirectives(a *Action) error {
var msg []byte
p := a.Package
"cmd/internal/pathcache"
"errors"
"fmt"
- "internal/lazyregexp"
"io"
"io/fs"
"os"
dir = dirP
}
- // Fix up output referring to cgo-generated code to be more readable.
- // Replace x.go:19[/tmp/.../x.cgo1.go:18] with x.go:19.
- // Replace *[100]_Ctype_foo with *[100]C.foo.
- // If we're using -x, assume we're debugging and want the full dump, so disable the rewrite.
- if !cfg.BuildX && cgoLine.MatchString(out) {
- out = cgoLine.ReplaceAllString(out, "")
- out = cgoTypeSigRe.ReplaceAllString(out, "C.")
- }
-
// Usually desc is already p.Desc(), but if not, signal cmdError.Error to
// add a line explicitly mentioning the import path.
needsPath := importPath != "" && p != nil && desc != p.Desc()
return e.importPath
}
-var cgoLine = lazyregexp.New(`\[[^\[\]]+\.(cgo1|cover)\.go:[0-9]+(:[0-9]+)?\]`)
-var cgoTypeSigRe = lazyregexp.New(`\b_C2?(type|func|var|macro)_\B`)
-
// run runs the command given by cmdline in the directory dir.
// If the command fails, run prints information about the failure
// and returns a non-nil error.
return r.re().FindStringSubmatchIndex(s)
}
+func (r *Regexp) ReplaceAll(src, repl []byte) []byte {
+ return r.re().ReplaceAll(src, repl)
+}
+
func (r *Regexp) ReplaceAllString(src, repl string) string {
return r.re().ReplaceAllString(src, repl)
}