aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2018-05-17 16:37:09 -0700
committerDan Willemsen <dwillemsen@google.com>2018-07-12 14:15:31 -0700
commitb82471ad6dfec4790b2d86e49525dadc3fc06416 (patch)
treebca7e73da63c7506bbc3c967468034a351aaad94 /cmd
parent5e48b1d183a8333528f529c7e677c4ab644f8caf (diff)
downloadbuild_soong-b82471ad6dfec4790b2d86e49525dadc3fc06416.tar.gz
build_soong-b82471ad6dfec4790b2d86e49525dadc3fc06416.tar.bz2
build_soong-b82471ad6dfec4790b2d86e49525dadc3fc06416.zip
Add a unified status reporting UI
This adds a new status package that merges the running of "actions" (ninja calls them edges) of multiple tools into one view of the current state, and gives that to a number of different outputs. For inputs: Kati's output parser has been rewritten (and moved) to map onto the StartAction/FinishAction API. A byproduct of this is that the build servers should be able to extract errors from Kati better, since they look like the errors that Ninja used to write. Ninja is no longer directly connected to the terminal, but its output is read via the protobuf frontend API, so it's just another tool whose output becomes merged together. multiproduct_kati loses its custom status routines, and uses the common one instead. For outputs: The primary output is the ui/terminal.Status type, which along with ui/terminal.Writer now controls everything about the terminal output. Today, this doesn't really change any behaviors, but having all terminal output going through here allows a more complicated (multi-line / full window) status display in the future. The tracer acts as an output of the status package, tracing all the action start / finish events. This replaces reading the .ninja_log file, so it now properly handles multiple output files from a single action. A new rotated log file (out/error.log, or out/dist/logs/error.log) just contains a description of all of the errors that happened during the current build. Another new compressed and rotated log file (out/verbose.log.gz, or out/dist/logs/verbose.log.gz) contains the full verbose (showcommands) log of every execution run by the build. Since this is now written on every build, the showcommands argument is now ignored -- if you want to get the commands run, look at the log file after the build. Test: m Test: <built-in tests> Test: NINJA_ARGS="-t list" m Test: check the build.trace.gz Test: check the new log files Change-Id: If1d8994890d43ef68f65aa10ddd8e6e06dc7013a
Diffstat (limited to 'cmd')
-rw-r--r--cmd/multiproduct_kati/Android.bp1
-rw-r--r--cmd/multiproduct_kati/main.go166
-rw-r--r--cmd/soong_ui/Android.bp1
-rw-r--r--cmd/soong_ui/main.go49
4 files changed, 102 insertions, 115 deletions
diff --git a/cmd/multiproduct_kati/Android.bp b/cmd/multiproduct_kati/Android.bp
index 04a58023..13b3679e 100644
--- a/cmd/multiproduct_kati/Android.bp
+++ b/cmd/multiproduct_kati/Android.bp
@@ -17,6 +17,7 @@ blueprint_go_binary {
deps: [
"soong-ui-build",
"soong-ui-logger",
+ "soong-ui-terminal",
"soong-ui-tracer",
"soong-zip",
],
diff --git a/cmd/multiproduct_kati/main.go b/cmd/multiproduct_kati/main.go
index ab829638..237d384c 100644
--- a/cmd/multiproduct_kati/main.go
+++ b/cmd/multiproduct_kati/main.go
@@ -29,6 +29,8 @@ import (
"android/soong/ui/build"
"android/soong/ui/logger"
+ "android/soong/ui/status"
+ "android/soong/ui/terminal"
"android/soong/ui/tracer"
"android/soong/zip"
)
@@ -66,98 +68,34 @@ type Product struct {
ctx build.Context
config build.Config
logFile string
+ action *status.Action
}
-type Status struct {
- cur int
- total int
- failed int
-
- ctx build.Context
- haveBlankLine bool
- smartTerminal bool
-
- lock sync.Mutex
-}
-
-func NewStatus(ctx build.Context) *Status {
- return &Status{
- ctx: ctx,
- haveBlankLine: true,
- smartTerminal: ctx.IsTerminal(),
+func errMsgFromLog(filename string) string {
+ if filename == "" {
+ return ""
}
-}
-
-func (s *Status) SetTotal(total int) {
- s.total = total
-}
-
-func (s *Status) Fail(product string, err error, logFile string) {
- s.Finish(product)
-
- s.lock.Lock()
- defer s.lock.Unlock()
- if s.smartTerminal && !s.haveBlankLine {
- fmt.Fprintln(s.ctx.Stdout())
- s.haveBlankLine = true
- }
-
- s.failed++
- fmt.Fprintln(s.ctx.Stderr(), "FAILED:", product)
- s.ctx.Verboseln("FAILED:", product)
-
- if logFile != "" {
- data, err := ioutil.ReadFile(logFile)
- if err == nil {
- lines := strings.Split(strings.TrimSpace(string(data)), "\n")
- if len(lines) > errorLeadingLines+errorTrailingLines+1 {
- lines[errorLeadingLines] = fmt.Sprintf("... skipping %d lines ...",
- len(lines)-errorLeadingLines-errorTrailingLines)
-
- lines = append(lines[:errorLeadingLines+1],
- lines[len(lines)-errorTrailingLines:]...)
- }
- for _, line := range lines {
- fmt.Fprintln(s.ctx.Stderr(), "> ", line)
- s.ctx.Verboseln(line)
- }
- }
+ data, err := ioutil.ReadFile(filename)
+ if err != nil {
+ return ""
}
- s.ctx.Print(err)
-}
-
-func (s *Status) Finish(product string) {
- s.lock.Lock()
- defer s.lock.Unlock()
-
- s.cur++
- line := fmt.Sprintf("[%d/%d] %s", s.cur, s.total, product)
+ lines := strings.Split(strings.TrimSpace(string(data)), "\n")
+ if len(lines) > errorLeadingLines+errorTrailingLines+1 {
+ lines[errorLeadingLines] = fmt.Sprintf("... skipping %d lines ...",
+ len(lines)-errorLeadingLines-errorTrailingLines)
- if s.smartTerminal {
- if max, ok := s.ctx.TermWidth(); ok {
- if len(line) > max {
- line = line[:max]
- }
- }
-
- fmt.Fprint(s.ctx.Stdout(), "\r", line, "\x1b[K")
- s.haveBlankLine = false
- } else {
- s.ctx.Println(line)
+ lines = append(lines[:errorLeadingLines+1],
+ lines[len(lines)-errorTrailingLines:]...)
}
-}
-
-func (s *Status) Finished() int {
- s.lock.Lock()
- defer s.lock.Unlock()
-
- if !s.haveBlankLine {
- fmt.Fprintln(s.ctx.Stdout())
- s.haveBlankLine = true
+ var buf strings.Builder
+ for _, line := range lines {
+ buf.WriteString("> ")
+ buf.WriteString(line)
+ buf.WriteString("\n")
}
- return s.failed
+ return buf.String()
}
// TODO(b/70370883): This tool uses a lot of open files -- over the default
@@ -194,6 +132,9 @@ func inList(str string, list []string) bool {
}
func main() {
+ writer := terminal.NewWriter(terminal.StdioImpl{})
+ defer writer.Finish()
+
log := logger.New(os.Stderr)
defer log.Cleanup()
@@ -205,20 +146,24 @@ func main() {
trace := tracer.New(log)
defer trace.Close()
+ stat := &status.Status{}
+ defer stat.Finish()
+ stat.AddOutput(terminal.NewStatusOutput(writer, ""))
+
build.SetupSignals(log, cancel, func() {
trace.Close()
log.Cleanup()
+ stat.Finish()
})
buildCtx := build.Context{&build.ContextImpl{
- Context: ctx,
- Logger: log,
- Tracer: trace,
- StdioInterface: build.StdioImpl{},
+ Context: ctx,
+ Logger: log,
+ Tracer: trace,
+ Writer: writer,
+ Status: stat,
}}
- status := NewStatus(buildCtx)
-
config := build.NewConfig(buildCtx)
if *outDir == "" {
name := "multiproduct-" + time.Now().Format("20060102150405")
@@ -303,7 +248,8 @@ func main() {
log.Verbose("Got product list: ", products)
- status.SetTotal(len(products))
+ s := buildCtx.Status.StartTool()
+ s.SetTotalActions(len(products))
var wg sync.WaitGroup
productConfigs := make(chan Product, len(products))
@@ -315,8 +261,18 @@ func main() {
var stdLog string
defer wg.Done()
+
+ action := &status.Action{
+ Description: product,
+ Outputs: []string{product},
+ }
+ s.StartAction(action)
defer logger.Recover(func(err error) {
- status.Fail(product, err, stdLog)
+ s.FinishAction(status.ActionResult{
+ Action: action,
+ Error: err,
+ Output: errMsgFromLog(stdLog),
+ })
})
productOutDir := filepath.Join(config.OutDir(), product)
@@ -339,12 +295,14 @@ func main() {
productLog.SetOutput(filepath.Join(productLogDir, "soong.log"))
productCtx := build.Context{&build.ContextImpl{
- Context: ctx,
- Logger: productLog,
- Tracer: trace,
- StdioInterface: build.NewCustomStdio(nil, f, f),
- Thread: trace.NewThread(product),
+ Context: ctx,
+ Logger: productLog,
+ Tracer: trace,
+ Writer: terminal.NewWriter(terminal.NewCustomStdio(nil, f, f)),
+ Thread: trace.NewThread(product),
+ Status: &status.Status{},
}}
+ productCtx.Status.AddOutput(terminal.NewStatusOutput(productCtx.Writer, ""))
productConfig := build.NewConfig(productCtx)
productConfig.Environment().Set("OUT_DIR", productOutDir)
@@ -352,7 +310,7 @@ func main() {
productConfig.Lunch(productCtx, product, *buildVariant)
build.Build(productCtx, productConfig, build.BuildProductConfig)
- productConfigs <- Product{productCtx, productConfig, stdLog}
+ productConfigs <- Product{productCtx, productConfig, stdLog, action}
}(product)
}
go func() {
@@ -369,7 +327,11 @@ func main() {
for product := range productConfigs {
func() {
defer logger.Recover(func(err error) {
- status.Fail(product.config.TargetProduct(), err, product.logFile)
+ s.FinishAction(status.ActionResult{
+ Action: product.action,
+ Error: err,
+ Output: errMsgFromLog(product.logFile),
+ })
})
defer func() {
@@ -400,7 +362,9 @@ func main() {
}
}
build.Build(product.ctx, product.config, buildWhat)
- status.Finish(product.config.TargetProduct())
+ s.FinishAction(status.ActionResult{
+ Action: product.action,
+ })
}()
}
}()
@@ -421,7 +385,5 @@ func main() {
}
}
- if count := status.Finished(); count > 0 {
- log.Fatalln(count, "products failed")
- }
+ s.Finish()
}
diff --git a/cmd/soong_ui/Android.bp b/cmd/soong_ui/Android.bp
index f09e42ed..4e57bef3 100644
--- a/cmd/soong_ui/Android.bp
+++ b/cmd/soong_ui/Android.bp
@@ -17,6 +17,7 @@ blueprint_go_binary {
deps: [
"soong-ui-build",
"soong-ui-logger",
+ "soong-ui-terminal",
"soong-ui-tracer",
],
srcs: [
diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go
index 2ca7ebfa..e2f25b8f 100644
--- a/cmd/soong_ui/main.go
+++ b/cmd/soong_ui/main.go
@@ -26,6 +26,8 @@ import (
"android/soong/ui/build"
"android/soong/ui/logger"
+ "android/soong/ui/status"
+ "android/soong/ui/terminal"
"android/soong/ui/tracer"
)
@@ -44,7 +46,10 @@ func inList(s string, list []string) bool {
}
func main() {
- log := logger.New(os.Stderr)
+ writer := terminal.NewWriter(terminal.StdioImpl{})
+ defer writer.Finish()
+
+ log := logger.New(writer)
defer log.Cleanup()
if len(os.Args) < 2 || !(inList("--make-mode", os.Args) ||
@@ -60,16 +65,23 @@ func main() {
trace := tracer.New(log)
defer trace.Close()
+ stat := &status.Status{}
+ defer stat.Finish()
+ stat.AddOutput(terminal.NewStatusOutput(writer, os.Getenv("NINJA_STATUS")))
+ stat.AddOutput(trace.StatusTracer())
+
build.SetupSignals(log, cancel, func() {
trace.Close()
log.Cleanup()
+ stat.Finish()
})
buildCtx := build.Context{&build.ContextImpl{
- Context: ctx,
- Logger: log,
- Tracer: trace,
- StdioInterface: build.StdioImpl{},
+ Context: ctx,
+ Logger: log,
+ Tracer: trace,
+ Writer: writer,
+ Status: stat,
}}
var config build.Config
if os.Args[1] == "--dumpvars-mode" || os.Args[1] == "--dumpvar-mode" {
@@ -78,19 +90,19 @@ func main() {
config = build.NewConfig(buildCtx, os.Args[1:]...)
}
- log.SetVerbose(config.IsVerbose())
build.SetupOutDir(buildCtx, config)
+ logsDir := config.OutDir()
if config.Dist() {
- logsDir := filepath.Join(config.DistDir(), "logs")
- os.MkdirAll(logsDir, 0777)
- log.SetOutput(filepath.Join(logsDir, "soong.log"))
- trace.SetOutput(filepath.Join(logsDir, "build.trace"))
- } else {
- log.SetOutput(filepath.Join(config.OutDir(), "soong.log"))
- trace.SetOutput(filepath.Join(config.OutDir(), "build.trace"))
+ logsDir = filepath.Join(config.DistDir(), "logs")
}
+ os.MkdirAll(logsDir, 0777)
+ log.SetOutput(filepath.Join(logsDir, "soong.log"))
+ trace.SetOutput(filepath.Join(logsDir, "build.trace"))
+ stat.AddOutput(status.NewVerboseLog(log, filepath.Join(logsDir, "verbose.log")))
+ stat.AddOutput(status.NewErrorLog(log, filepath.Join(logsDir, "error.log")))
+
if start, ok := os.LookupEnv("TRACE_BEGIN_SOONG"); ok {
if !strings.HasSuffix(start, "N") {
if start_time, err := strconv.ParseUint(start, 10, 64); err == nil {
@@ -114,6 +126,17 @@ func main() {
} else if os.Args[1] == "--dumpvars-mode" {
dumpVars(buildCtx, config, os.Args[2:])
} else {
+ if config.IsVerbose() {
+ writer.Print("! The argument `showcommands` is no longer supported.")
+ writer.Print("! Instead, the verbose log is always written to a compressed file in the output dir:")
+ writer.Print("!")
+ writer.Print(fmt.Sprintf("! gzip -cd %s/verbose.log.gz | less -R", logsDir))
+ writer.Print("!")
+ writer.Print("! Older versions are saved in verbose.log.#.gz files")
+ writer.Print("")
+ time.Sleep(5 * time.Second)
+ }
+
toBuild := build.BuildAll
if config.Checkbuild() {
toBuild |= build.RunBuildTests