Skip to content

Commit 045ce51

Browse files
committed
cmd/go: delete showOutput, formatOutput, and processOutput
This functions have been replaced with Builder.reportCmd. For #62067. Change-Id: Ifeccee720b3da3dc44c49fe11da1eca7b5f46551 Reviewed-on: https://go-review.googlesource.com/c/go/+/529220 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent 7ee9980 commit 045ce51

File tree

1 file changed

+0
-137
lines changed

1 file changed

+0
-137
lines changed

src/cmd/go/internal/work/exec.go

-137
Original file line numberDiff line numberDiff line change
@@ -2379,126 +2379,6 @@ func (e *cmdError) ImportPath() string {
23792379
return e.importPath
23802380
}
23812381

2382-
// showOutput prints "# desc" followed by the given output.
2383-
// The output is expected to contain references to 'dir', usually
2384-
// the source directory for the package that has failed to build.
2385-
// showOutput rewrites mentions of dir with a relative path to dir
2386-
// when the relative path is shorter. This is usually more pleasant.
2387-
// For example, if fmt doesn't compile and we are in src/html,
2388-
// the output is
2389-
//
2390-
// $ go build
2391-
// # fmt
2392-
// ../fmt/print.go:1090: undefined: asdf
2393-
// $
2394-
//
2395-
// instead of
2396-
//
2397-
// $ go build
2398-
// # fmt
2399-
// /usr/gopher/go/src/fmt/print.go:1090: undefined: asdf
2400-
// $
2401-
//
2402-
// showOutput also replaces references to the work directory with $WORK.
2403-
//
2404-
// If a is not nil and a.output is not nil, showOutput appends to that slice instead of
2405-
// printing to b.Print.
2406-
func (b *Builder) showOutput(a *Action, dir, desc, out string) {
2407-
importPath := ""
2408-
if a != nil && a.Package != nil {
2409-
importPath = a.Package.ImportPath
2410-
}
2411-
psErr := formatOutput(b.WorkDir, dir, importPath, desc, out)
2412-
if a != nil && a.output != nil {
2413-
a.output = append(a.output, psErr.prefix...)
2414-
a.output = append(a.output, psErr.suffix...)
2415-
return
2416-
}
2417-
2418-
b.output.Lock()
2419-
defer b.output.Unlock()
2420-
b.Print(psErr.prefix, psErr.suffix)
2421-
}
2422-
2423-
// A prefixSuffixError is an error formatted by formatOutput.
2424-
type prefixSuffixError struct {
2425-
importPath string
2426-
prefix, suffix string
2427-
}
2428-
2429-
func (e *prefixSuffixError) Error() string {
2430-
if e.importPath != "" && !strings.HasPrefix(strings.TrimPrefix(e.prefix, "# "), e.importPath) {
2431-
return fmt.Sprintf("go build %s:\n%s%s", e.importPath, e.prefix, e.suffix)
2432-
}
2433-
return e.prefix + e.suffix
2434-
}
2435-
2436-
func (e *prefixSuffixError) ImportPath() string {
2437-
return e.importPath
2438-
}
2439-
2440-
// formatOutput prints "# desc" followed by the given output.
2441-
// The output is expected to contain references to 'dir', usually
2442-
// the source directory for the package that has failed to build.
2443-
// formatOutput rewrites mentions of dir with a relative path to dir
2444-
// when the relative path is shorter. This is usually more pleasant.
2445-
// For example, if fmt doesn't compile and we are in src/html,
2446-
// the output is
2447-
//
2448-
// $ go build
2449-
// # fmt
2450-
// ../fmt/print.go:1090: undefined: asdf
2451-
// $
2452-
//
2453-
// instead of
2454-
//
2455-
// $ go build
2456-
// # fmt
2457-
// /usr/gopher/go/src/fmt/print.go:1090: undefined: asdf
2458-
// $
2459-
//
2460-
// formatOutput also replaces references to the work directory with $WORK.
2461-
// formatOutput returns the output in a prefix with the description and a
2462-
// suffix with the actual output.
2463-
func formatOutput(workDir, dir, importPath, desc, out string) *prefixSuffixError {
2464-
prefix := "# " + desc
2465-
suffix := "\n" + out
2466-
2467-
suffix = strings.ReplaceAll(suffix, " "+workDir, " $WORK")
2468-
2469-
for {
2470-
// Note that dir starts out long, something like
2471-
// /foo/bar/baz/root/a
2472-
// The target string to be reduced is something like
2473-
// (blah-blah-blah) /foo/bar/baz/root/sibling/whatever.go:blah:blah
2474-
// /foo/bar/baz/root/a doesn't match /foo/bar/baz/root/sibling, but the prefix
2475-
// /foo/bar/baz/root does. And there may be other niblings sharing shorter
2476-
// prefixes, the only way to find them is to look.
2477-
// This doesn't always produce a relative path --
2478-
// /foo is shorter than ../../.., for example.
2479-
//
2480-
if reldir := base.ShortPath(dir); reldir != dir {
2481-
suffix = strings.ReplaceAll(suffix, " "+dir, " "+reldir)
2482-
suffix = strings.ReplaceAll(suffix, "\n"+dir, "\n"+reldir)
2483-
suffix = strings.ReplaceAll(suffix, "\n\t"+dir, "\n\t"+reldir)
2484-
if filepath.Separator == '\\' {
2485-
// Don't know why, sometimes this comes out with slashes, not backslashes.
2486-
wdir := strings.ReplaceAll(dir, "\\", "/")
2487-
suffix = strings.ReplaceAll(suffix, " "+wdir, " "+reldir)
2488-
suffix = strings.ReplaceAll(suffix, "\n"+wdir, "\n"+reldir)
2489-
suffix = strings.ReplaceAll(suffix, "\n\t"+wdir, "\n\t"+reldir)
2490-
}
2491-
}
2492-
dirP := filepath.Dir(dir)
2493-
if dir == dirP {
2494-
break
2495-
}
2496-
dir = dirP
2497-
}
2498-
2499-
return &prefixSuffixError{importPath: importPath, prefix: prefix, suffix: suffix}
2500-
}
2501-
25022382
var cgoLine = lazyregexp.New(`\[[^\[\]]+\.(cgo1|cover)\.go:[0-9]+(:[0-9]+)?\]`)
25032383
var cgoTypeSigRe = lazyregexp.New(`\b_C2?(type|func|var|macro)_\B`)
25042384

@@ -2513,23 +2393,6 @@ func (b *Builder) run(a *Action, dir string, desc string, env []string, cmdargs
25132393
return b.reportCmd(a, nil, desc, dir, out, err)
25142394
}
25152395

2516-
// processOutput prepares the output of runOut to be output to the console.
2517-
func (b *Builder) processOutput(out []byte) string {
2518-
if out[len(out)-1] != '\n' {
2519-
out = append(out, '\n')
2520-
}
2521-
messages := string(out)
2522-
// Fix up output referring to cgo-generated code to be more readable.
2523-
// Replace x.go:19[/tmp/.../x.cgo1.go:18] with x.go:19.
2524-
// Replace *[100]_Ctype_foo with *[100]C.foo.
2525-
// If we're using -x, assume we're debugging and want the full dump, so disable the rewrite.
2526-
if !cfg.BuildX && cgoLine.MatchString(messages) {
2527-
messages = cgoLine.ReplaceAllString(messages, "")
2528-
messages = cgoTypeSigRe.ReplaceAllString(messages, "C.")
2529-
}
2530-
return messages
2531-
}
2532-
25332396
// runOut runs the command given by cmdline in the directory dir.
25342397
// It returns the command output and any errors that occurred.
25352398
// It accumulates execution time in a.

0 commit comments

Comments
 (0)