Merge "Apply kati output rewriting to dumpvars"
This commit is contained in:
@@ -103,6 +103,13 @@ func (c ContextImpl) IsTerminal() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c ContextImpl) IsErrTerminal() bool {
|
||||||
|
if term, ok := os.LookupEnv("TERM"); ok {
|
||||||
|
return term != "dumb" && isTerminal(c.Stderr())
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (c ContextImpl) TermWidth() (int, bool) {
|
func (c ContextImpl) TermWidth() (int, bool) {
|
||||||
return termWidth(c.Stdout())
|
return termWidth(c.Stdout())
|
||||||
}
|
}
|
||||||
|
@@ -42,6 +42,7 @@ func dumpMakeVars(ctx Context, config Config, goals, vars []string, write_soong_
|
|||||||
config.PrebuiltBuildTool("ckati"),
|
config.PrebuiltBuildTool("ckati"),
|
||||||
"-f", "build/make/core/config.mk",
|
"-f", "build/make/core/config.mk",
|
||||||
"--color_warnings",
|
"--color_warnings",
|
||||||
|
"--kati_stats",
|
||||||
"dump-many-vars",
|
"dump-many-vars",
|
||||||
"MAKECMDGOALS="+strings.Join(goals, " "))
|
"MAKECMDGOALS="+strings.Join(goals, " "))
|
||||||
cmd.Environment.Set("CALLED_FROM_SETUP", "true")
|
cmd.Environment.Set("CALLED_FROM_SETUP", "true")
|
||||||
@@ -51,15 +52,19 @@ func dumpMakeVars(ctx Context, config Config, goals, vars []string, write_soong_
|
|||||||
}
|
}
|
||||||
cmd.Environment.Set("DUMP_MANY_VARS", strings.Join(vars, " "))
|
cmd.Environment.Set("DUMP_MANY_VARS", strings.Join(vars, " "))
|
||||||
cmd.Sandbox = dumpvarsSandbox
|
cmd.Sandbox = dumpvarsSandbox
|
||||||
// TODO: error out when Stderr contains any content
|
output := bytes.Buffer{}
|
||||||
cmd.Stderr = ctx.Stderr()
|
cmd.Stdout = &output
|
||||||
output, err := cmd.Output()
|
pipe, err := cmd.StderrPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
ctx.Fatalln("Error getting output pipe for ckati:", err)
|
||||||
}
|
}
|
||||||
|
cmd.StartOrFatal()
|
||||||
|
// TODO: error out when Stderr contains any content
|
||||||
|
katiRewriteOutput(ctx, pipe)
|
||||||
|
cmd.WaitOrFatal()
|
||||||
|
|
||||||
ret := make(map[string]string, len(vars))
|
ret := make(map[string]string, len(vars))
|
||||||
for _, line := range strings.Split(string(output), "\n") {
|
for _, line := range strings.Split(output.String(), "\n") {
|
||||||
if len(line) == 0 {
|
if len(line) == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@@ -115,6 +115,7 @@ var katiLogRe = regexp.MustCompile(`^\*kati\*: `)
|
|||||||
func katiRewriteOutput(ctx Context, pipe io.ReadCloser) {
|
func katiRewriteOutput(ctx Context, pipe io.ReadCloser) {
|
||||||
haveBlankLine := true
|
haveBlankLine := true
|
||||||
smartTerminal := ctx.IsTerminal()
|
smartTerminal := ctx.IsTerminal()
|
||||||
|
errSmartTerminal := ctx.IsErrTerminal()
|
||||||
|
|
||||||
scanner := bufio.NewScanner(pipe)
|
scanner := bufio.NewScanner(pipe)
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
@@ -155,7 +156,7 @@ func katiRewriteOutput(ctx Context, pipe io.ReadCloser) {
|
|||||||
// that message instead of overwriting it.
|
// that message instead of overwriting it.
|
||||||
fmt.Fprintln(ctx.Stdout())
|
fmt.Fprintln(ctx.Stdout())
|
||||||
haveBlankLine = true
|
haveBlankLine = true
|
||||||
} else if !smartTerminal {
|
} else if !errSmartTerminal {
|
||||||
// Most editors display these as garbage, so strip them out.
|
// Most editors display these as garbage, so strip them out.
|
||||||
line = string(stripAnsiEscapes([]byte(line)))
|
line = string(stripAnsiEscapes([]byte(line)))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user