2017-01-20 23:10:01 +01:00
|
|
|
// Copyright 2017 Google Inc. All rights reserved.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-08-10 15:01:13 +02:00
|
|
|
"bufio"
|
2017-01-20 23:10:01 +01:00
|
|
|
"context"
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2018-09-01 04:51:35 +02:00
|
|
|
"io"
|
2021-08-24 10:47:13 +02:00
|
|
|
"io/ioutil"
|
2021-08-10 15:01:13 +02:00
|
|
|
"log"
|
2017-01-20 23:10:01 +01:00
|
|
|
"os"
|
2021-08-10 15:01:13 +02:00
|
|
|
"os/exec"
|
2017-01-20 23:10:01 +01:00
|
|
|
"path/filepath"
|
2021-08-11 09:19:27 +02:00
|
|
|
"regexp"
|
2017-01-20 23:10:01 +01:00
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
2017-12-11 23:35:23 +01:00
|
|
|
"syscall"
|
2017-03-30 04:26:09 +02:00
|
|
|
"time"
|
2017-01-20 23:10:01 +01:00
|
|
|
|
|
|
|
"android/soong/ui/logger"
|
2021-08-11 11:10:28 +02:00
|
|
|
"android/soong/ui/signal"
|
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
2018-05-18 01:37:09 +02:00
|
|
|
"android/soong/ui/status"
|
|
|
|
"android/soong/ui/terminal"
|
2016-08-22 00:17:17 +02:00
|
|
|
"android/soong/ui/tracer"
|
2017-11-07 20:23:27 +01:00
|
|
|
"android/soong/zip"
|
2017-01-20 23:10:01 +01:00
|
|
|
)
|
|
|
|
|
2019-12-27 18:54:11 +01:00
|
|
|
var numJobs = flag.Int("j", 0, "number of parallel jobs [0=autodetect]")
|
2017-01-20 23:10:01 +01:00
|
|
|
|
2017-11-07 20:23:27 +01:00
|
|
|
var keepArtifacts = flag.Bool("keep", false, "keep archives of artifacts")
|
2018-09-01 04:51:35 +02:00
|
|
|
var incremental = flag.Bool("incremental", false, "run in incremental mode (saving intermediates)")
|
2017-01-20 23:10:01 +01:00
|
|
|
|
|
|
|
var outDir = flag.String("out", "", "path to store output directories (defaults to tmpdir under $OUT when empty)")
|
2017-05-20 01:39:04 +02:00
|
|
|
var alternateResultDir = flag.Bool("dist", false, "write select results to $DIST_DIR (or <out>/dist when empty)")
|
2017-01-20 23:10:01 +01:00
|
|
|
|
2022-10-26 20:21:55 +02:00
|
|
|
var bazelMode = flag.Bool("bazel-mode", false, "use bazel for analysis of certain modules")
|
|
|
|
var bazelModeStaging = flag.Bool("bazel-mode-staging", false, "use bazel for analysis of certain near-ready modules")
|
|
|
|
|
2017-01-20 23:10:01 +01:00
|
|
|
var onlyConfig = flag.Bool("only-config", false, "Only run product config (not Soong or Kati)")
|
|
|
|
var onlySoong = flag.Bool("only-soong", false, "Only run product config and Soong (not Kati)")
|
|
|
|
|
2017-05-07 20:40:30 +02:00
|
|
|
var buildVariant = flag.String("variant", "eng", "build variant to use")
|
|
|
|
|
2019-12-06 00:22:41 +01:00
|
|
|
var shardCount = flag.Int("shard-count", 1, "split the products into multiple shards (to spread the build onto multiple machines, etc)")
|
|
|
|
var shard = flag.Int("shard", 1, "1-indexed shard to execute")
|
|
|
|
|
2020-12-17 20:29:31 +01:00
|
|
|
var skipProducts multipleStringArg
|
|
|
|
var includeProducts multipleStringArg
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
flag.Var(&skipProducts, "skip-products", "comma-separated list of products to skip (known failures, etc)")
|
|
|
|
flag.Var(&includeProducts, "products", "comma-separated list of products to build")
|
|
|
|
}
|
|
|
|
|
|
|
|
// multipleStringArg is a flag.Value that takes comma separated lists and converts them to a
|
|
|
|
// []string. The argument can be passed multiple times to append more values.
|
|
|
|
type multipleStringArg []string
|
|
|
|
|
|
|
|
func (m *multipleStringArg) String() string {
|
|
|
|
return strings.Join(*m, `, `)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *multipleStringArg) Set(s string) error {
|
|
|
|
*m = append(*m, strings.Split(s, ",")...)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-08-24 10:47:13 +02:00
|
|
|
const errorLeadingLines = 20
|
|
|
|
const errorTrailingLines = 20
|
|
|
|
|
|
|
|
func errMsgFromLog(filename string) string {
|
|
|
|
if filename == "" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
data, err := ioutil.ReadFile(filename)
|
|
|
|
if err != nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
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:]...)
|
|
|
|
}
|
|
|
|
var buf strings.Builder
|
|
|
|
for _, line := range lines {
|
|
|
|
buf.WriteString("> ")
|
|
|
|
buf.WriteString(line)
|
|
|
|
buf.WriteString("\n")
|
|
|
|
}
|
|
|
|
return buf.String()
|
|
|
|
}
|
|
|
|
|
2017-12-11 23:35:23 +01:00
|
|
|
// TODO(b/70370883): This tool uses a lot of open files -- over the default
|
|
|
|
// soft limit of 1024 on some systems. So bump up to the hard limit until I fix
|
|
|
|
// the algorithm.
|
|
|
|
func setMaxFiles(log logger.Logger) {
|
|
|
|
var limits syscall.Rlimit
|
|
|
|
|
|
|
|
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &limits)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Failed to get file limit:", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Verbosef("Current file limits: %d soft, %d hard", limits.Cur, limits.Max)
|
|
|
|
if limits.Cur == limits.Max {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
limits.Cur = limits.Max
|
|
|
|
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limits)
|
|
|
|
if err != nil {
|
|
|
|
log.Println("Failed to increase file limit:", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-26 00:02:45 +02:00
|
|
|
func inList(str string, list []string) bool {
|
|
|
|
for _, other := range list {
|
|
|
|
if str == other {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-09-01 04:51:35 +02:00
|
|
|
func copyFile(from, to string) error {
|
|
|
|
fromFile, err := os.Open(from)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer fromFile.Close()
|
|
|
|
|
|
|
|
toFile, err := os.Create(to)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer toFile.Close()
|
|
|
|
|
|
|
|
_, err = io.Copy(toFile, fromFile)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-09-05 03:09:47 +02:00
|
|
|
type mpContext struct {
|
2021-08-11 11:10:28 +02:00
|
|
|
Logger logger.Logger
|
|
|
|
Status status.ToolStatus
|
2018-09-05 03:09:47 +02:00
|
|
|
|
2021-08-11 11:10:28 +02:00
|
|
|
SoongUi string
|
|
|
|
MainOutDir string
|
|
|
|
MainLogsDir string
|
2018-09-05 03:09:47 +02:00
|
|
|
}
|
|
|
|
|
2021-08-11 09:19:27 +02:00
|
|
|
func findNamedProducts(soongUi string, log logger.Logger) []string {
|
|
|
|
cmd := exec.Command(soongUi, "--dumpvars-mode", "--vars=all_named_products")
|
|
|
|
output, err := cmd.Output()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Cannot determine named products: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
rx := regexp.MustCompile(`^all_named_products='(.*)'$`)
|
|
|
|
match := rx.FindStringSubmatch(strings.TrimSpace(string(output)))
|
|
|
|
return strings.Fields(match[1])
|
|
|
|
}
|
|
|
|
|
|
|
|
// ensureEmptyFileExists ensures that the containing directory exists, and the
|
|
|
|
// specified file exists. If it doesn't exist, it will write an empty file.
|
|
|
|
func ensureEmptyFileExists(file string, log logger.Logger) {
|
|
|
|
if _, err := os.Stat(file); os.IsNotExist(err) {
|
|
|
|
f, err := os.Create(file)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error creating %s: %q\n", file, err)
|
|
|
|
}
|
|
|
|
f.Close()
|
|
|
|
} else if err != nil {
|
|
|
|
log.Fatalf("Error checking %s: %q\n", file, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-24 10:47:13 +02:00
|
|
|
func outDirBase() string {
|
|
|
|
outDirBase := os.Getenv("OUT_DIR")
|
|
|
|
if outDirBase == "" {
|
|
|
|
return "out"
|
|
|
|
} else {
|
|
|
|
return outDirBase
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func distDir(outDir string) string {
|
|
|
|
if distDir := os.Getenv("DIST_DIR"); distDir != "" {
|
|
|
|
return filepath.Clean(distDir)
|
|
|
|
} else {
|
|
|
|
return filepath.Join(outDir, "dist")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-10 22:11:18 +01:00
|
|
|
func forceAnsiOutput() bool {
|
|
|
|
value := os.Getenv("SOONG_UI_ANSI_OUTPUT")
|
|
|
|
return value == "1" || value == "y" || value == "yes" || value == "on" || value == "true"
|
|
|
|
}
|
|
|
|
|
2022-10-26 20:21:55 +02:00
|
|
|
func getBazelArg() string {
|
|
|
|
count := 0
|
|
|
|
str := ""
|
|
|
|
if *bazelMode {
|
|
|
|
count++
|
|
|
|
str = "--bazel-mode"
|
|
|
|
}
|
|
|
|
if *bazelModeStaging {
|
|
|
|
count++
|
|
|
|
str = "--bazel-mode-staging"
|
|
|
|
}
|
|
|
|
|
|
|
|
if count > 1 {
|
|
|
|
// Can't set more than one
|
|
|
|
fmt.Errorf("Only one bazel mode is permitted to be set.")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
return str
|
|
|
|
}
|
|
|
|
|
2017-01-20 23:10:01 +01:00
|
|
|
func main() {
|
2019-06-09 06:48:58 +02:00
|
|
|
stdio := terminal.StdioImpl{}
|
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
2018-05-18 01:37:09 +02:00
|
|
|
|
2021-02-10 22:11:18 +01:00
|
|
|
output := terminal.NewStatusOutput(stdio.Stdout(), "", false, false,
|
|
|
|
forceAnsiOutput())
|
2019-06-10 04:40:08 +02:00
|
|
|
log := logger.New(output)
|
2017-01-20 23:10:01 +01:00
|
|
|
defer log.Cleanup()
|
|
|
|
|
2021-08-24 10:47:13 +02:00
|
|
|
for _, v := range os.Environ() {
|
|
|
|
log.Println("Environment: " + v)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Printf("Argv: %v\n", os.Args)
|
|
|
|
|
2017-01-20 23:10:01 +01:00
|
|
|
flag.Parse()
|
|
|
|
|
2021-08-11 11:10:28 +02:00
|
|
|
_, cancel := context.WithCancel(context.Background())
|
2017-01-20 23:10:01 +01:00
|
|
|
defer cancel()
|
|
|
|
|
2016-08-22 00:17:17 +02:00
|
|
|
trace := tracer.New(log)
|
|
|
|
defer trace.Close()
|
2017-01-20 23:10:01 +01:00
|
|
|
|
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
2018-05-18 01:37:09 +02:00
|
|
|
stat := &status.Status{}
|
|
|
|
defer stat.Finish()
|
2019-06-10 04:40:08 +02:00
|
|
|
stat.AddOutput(output)
|
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
2018-05-18 01:37:09 +02:00
|
|
|
|
2018-07-20 07:57:18 +02:00
|
|
|
var failures failureCount
|
|
|
|
stat.AddOutput(&failures)
|
|
|
|
|
2021-08-11 11:10:28 +02:00
|
|
|
signal.SetupSignals(log, cancel, func() {
|
2016-08-22 00:17:17 +02:00
|
|
|
trace.Close()
|
|
|
|
log.Cleanup()
|
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
2018-05-18 01:37:09 +02:00
|
|
|
stat.Finish()
|
2016-08-22 00:17:17 +02:00
|
|
|
})
|
|
|
|
|
2021-08-10 15:01:13 +02:00
|
|
|
soongUi := "build/soong/soong_ui.bash"
|
|
|
|
|
2021-08-11 09:19:27 +02:00
|
|
|
var outputDir string
|
|
|
|
if *outDir != "" {
|
|
|
|
outputDir = *outDir
|
|
|
|
} else {
|
2018-09-01 04:51:35 +02:00
|
|
|
name := "multiproduct"
|
|
|
|
if !*incremental {
|
|
|
|
name += "-" + time.Now().Format("20060102150405")
|
|
|
|
}
|
2021-08-24 10:47:13 +02:00
|
|
|
outputDir = filepath.Join(outDirBase(), name)
|
2021-08-11 09:19:27 +02:00
|
|
|
}
|
2017-05-20 01:39:04 +02:00
|
|
|
|
2021-08-11 09:19:27 +02:00
|
|
|
log.Println("Output directory:", outputDir)
|
|
|
|
|
|
|
|
// The ninja_build file is used by our buildbots to understand that the output
|
|
|
|
// can be parsed as ninja output.
|
|
|
|
if err := os.MkdirAll(outputDir, 0777); err != nil {
|
|
|
|
log.Fatalf("Failed to create output directory: %v", err)
|
2017-01-20 23:10:01 +01:00
|
|
|
}
|
2021-08-11 09:19:27 +02:00
|
|
|
ensureEmptyFileExists(filepath.Join(outputDir, "ninja_build"), log)
|
2017-01-20 23:10:01 +01:00
|
|
|
|
2021-08-11 09:19:27 +02:00
|
|
|
logsDir := filepath.Join(outputDir, "logs")
|
2017-11-07 20:23:27 +01:00
|
|
|
os.MkdirAll(logsDir, 0777)
|
|
|
|
|
2021-08-11 09:19:27 +02:00
|
|
|
var configLogsDir string
|
|
|
|
if *alternateResultDir {
|
2021-08-24 10:47:13 +02:00
|
|
|
configLogsDir = filepath.Join(distDir(outDirBase()), "logs")
|
2021-08-11 09:19:27 +02:00
|
|
|
} else {
|
|
|
|
configLogsDir = outputDir
|
|
|
|
}
|
2020-12-10 12:32:38 +01:00
|
|
|
|
2021-08-24 10:47:13 +02:00
|
|
|
log.Println("Logs dir: " + configLogsDir)
|
|
|
|
|
2021-08-11 09:19:27 +02:00
|
|
|
os.MkdirAll(configLogsDir, 0777)
|
|
|
|
log.SetOutput(filepath.Join(configLogsDir, "soong.log"))
|
|
|
|
trace.SetOutput(filepath.Join(configLogsDir, "build.trace"))
|
2017-01-20 23:10:01 +01:00
|
|
|
|
2019-12-27 18:54:11 +01:00
|
|
|
var jobs = *numJobs
|
|
|
|
if jobs < 1 {
|
|
|
|
jobs = runtime.NumCPU() / 4
|
|
|
|
|
2021-08-11 09:19:27 +02:00
|
|
|
ramGb := int(detectTotalRAM() / (1024 * 1024 * 1024))
|
2023-01-11 23:19:32 +01:00
|
|
|
if ramJobs := ramGb / 40; ramGb > 0 && jobs > ramJobs {
|
2019-12-27 18:54:11 +01:00
|
|
|
jobs = ramJobs
|
|
|
|
}
|
|
|
|
|
|
|
|
if jobs < 1 {
|
|
|
|
jobs = 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.Verbosef("Using %d parallel jobs", jobs)
|
|
|
|
|
2017-12-11 23:35:23 +01:00
|
|
|
setMaxFiles(log)
|
|
|
|
|
2021-08-11 09:19:27 +02:00
|
|
|
allProducts := findNamedProducts(soongUi, log)
|
2017-10-26 00:02:45 +02:00
|
|
|
var productsList []string
|
|
|
|
|
2020-12-17 20:29:31 +01:00
|
|
|
if len(includeProducts) > 0 {
|
|
|
|
var missingProducts []string
|
|
|
|
for _, product := range includeProducts {
|
2017-10-26 00:02:45 +02:00
|
|
|
if inList(product, allProducts) {
|
|
|
|
productsList = append(productsList, product)
|
|
|
|
} else {
|
|
|
|
missingProducts = append(missingProducts, product)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(missingProducts) > 0 {
|
|
|
|
log.Fatalf("Products don't exist: %s\n", missingProducts)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
productsList = allProducts
|
|
|
|
}
|
2017-10-07 00:05:05 +02:00
|
|
|
|
2018-09-05 03:09:47 +02:00
|
|
|
finalProductsList := make([]string, 0, len(productsList))
|
2017-10-07 00:05:05 +02:00
|
|
|
skipProduct := func(p string) bool {
|
2020-12-17 20:29:31 +01:00
|
|
|
for _, s := range skipProducts {
|
2017-10-07 00:05:05 +02:00
|
|
|
if p == s {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for _, product := range productsList {
|
|
|
|
if !skipProduct(product) {
|
2018-09-05 03:09:47 +02:00
|
|
|
finalProductsList = append(finalProductsList, product)
|
2017-10-07 00:05:05 +02:00
|
|
|
} else {
|
|
|
|
log.Verbose("Skipping: ", product)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-06 00:22:41 +01:00
|
|
|
if *shard < 1 {
|
|
|
|
log.Fatalf("--shard value must be >= 1, not %d\n", *shard)
|
|
|
|
} else if *shardCount < 1 {
|
|
|
|
log.Fatalf("--shard-count value must be >= 1, not %d\n", *shardCount)
|
|
|
|
} else if *shard > *shardCount {
|
|
|
|
log.Fatalf("--shard (%d) must not be greater than --shard-count (%d)\n", *shard,
|
|
|
|
*shardCount)
|
|
|
|
} else if *shardCount > 1 {
|
|
|
|
finalProductsList = splitList(finalProductsList, *shardCount)[*shard-1]
|
|
|
|
}
|
|
|
|
|
2018-09-05 03:09:47 +02:00
|
|
|
log.Verbose("Got product list: ", finalProductsList)
|
2017-01-20 23:10:01 +01:00
|
|
|
|
2021-08-11 09:19:27 +02:00
|
|
|
s := stat.StartTool()
|
2018-09-05 03:09:47 +02:00
|
|
|
s.SetTotalActions(len(finalProductsList))
|
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
2018-05-18 01:37:09 +02:00
|
|
|
|
2018-09-05 03:09:47 +02:00
|
|
|
mpCtx := &mpContext{
|
2021-08-11 11:10:28 +02:00
|
|
|
Logger: log,
|
|
|
|
Status: s,
|
|
|
|
SoongUi: soongUi,
|
|
|
|
MainOutDir: outputDir,
|
|
|
|
MainLogsDir: logsDir,
|
2017-01-20 23:10:01 +01:00
|
|
|
}
|
2018-09-05 03:09:47 +02:00
|
|
|
|
|
|
|
products := make(chan string, len(productsList))
|
2017-01-20 23:10:01 +01:00
|
|
|
go func() {
|
2018-09-05 03:09:47 +02:00
|
|
|
defer close(products)
|
|
|
|
for _, product := range finalProductsList {
|
|
|
|
products <- product
|
|
|
|
}
|
2017-01-20 23:10:01 +01:00
|
|
|
}()
|
|
|
|
|
2018-09-05 03:09:47 +02:00
|
|
|
var wg sync.WaitGroup
|
2019-12-27 18:54:11 +01:00
|
|
|
for i := 0; i < jobs; i++ {
|
2018-09-05 03:09:47 +02:00
|
|
|
wg.Add(1)
|
2023-06-21 23:15:48 +02:00
|
|
|
// To smooth out the spikes in memory usage, skew the
|
|
|
|
// initial starting time of the jobs by a small amount.
|
|
|
|
time.Sleep(15 * time.Second)
|
2017-01-20 23:10:01 +01:00
|
|
|
go func() {
|
2018-09-05 03:09:47 +02:00
|
|
|
defer wg.Done()
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case product := <-products:
|
|
|
|
if product == "" {
|
|
|
|
return
|
2018-09-01 04:51:35 +02:00
|
|
|
}
|
2021-08-11 11:10:28 +02:00
|
|
|
runSoongUiForProduct(mpCtx, product)
|
2018-09-05 03:09:47 +02:00
|
|
|
}
|
2017-01-20 23:10:01 +01:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
2018-09-05 03:09:47 +02:00
|
|
|
wg.Wait()
|
2017-01-20 23:10:01 +01:00
|
|
|
|
2017-11-07 20:23:27 +01:00
|
|
|
if *alternateResultDir {
|
|
|
|
args := zip.ZipArgs{
|
|
|
|
FileArgs: []zip.FileArg{
|
|
|
|
{GlobDir: logsDir, SourcePrefixToStrip: logsDir},
|
|
|
|
},
|
2021-08-24 10:47:13 +02:00
|
|
|
OutputFilePath: filepath.Join(distDir(outDirBase()), "logs.zip"),
|
2017-11-07 20:23:27 +01:00
|
|
|
NumParallelJobs: runtime.NumCPU(),
|
|
|
|
CompressionLevel: 5,
|
|
|
|
}
|
2021-08-24 10:47:13 +02:00
|
|
|
log.Printf("Logs zip: %v\n", args.OutputFilePath)
|
2018-09-28 00:06:19 +02:00
|
|
|
if err := zip.Zip(args); err != nil {
|
2017-11-07 20:23:27 +01:00
|
|
|
log.Fatalf("Error zipping logs: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
2018-05-18 01:37:09 +02:00
|
|
|
s.Finish()
|
2018-07-20 07:57:18 +02:00
|
|
|
|
2022-02-14 21:42:53 +01:00
|
|
|
if failures.count == 1 {
|
2018-07-20 07:57:18 +02:00
|
|
|
log.Fatal("1 failure")
|
2022-02-14 21:42:53 +01:00
|
|
|
} else if failures.count > 1 {
|
|
|
|
log.Fatalf("%d failures %q", failures.count, failures.fails)
|
2018-07-20 07:57:18 +02:00
|
|
|
} else {
|
2019-06-10 04:40:08 +02:00
|
|
|
fmt.Fprintln(output, "Success")
|
2018-07-20 07:57:18 +02:00
|
|
|
}
|
2017-01-20 23:10:01 +01:00
|
|
|
}
|
2018-07-20 07:57:18 +02:00
|
|
|
|
2021-08-10 15:01:13 +02:00
|
|
|
func cleanupAfterProduct(outDir, productZip string) {
|
|
|
|
if *keepArtifacts {
|
|
|
|
args := zip.ZipArgs{
|
|
|
|
FileArgs: []zip.FileArg{
|
|
|
|
{
|
|
|
|
GlobDir: outDir,
|
|
|
|
SourcePrefixToStrip: outDir,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
OutputFilePath: productZip,
|
|
|
|
NumParallelJobs: runtime.NumCPU(),
|
|
|
|
CompressionLevel: 5,
|
|
|
|
}
|
|
|
|
if err := zip.Zip(args); err != nil {
|
|
|
|
log.Fatalf("Error zipping artifacts: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if !*incremental {
|
|
|
|
os.RemoveAll(outDir)
|
|
|
|
}
|
|
|
|
}
|
2018-09-05 03:09:47 +02:00
|
|
|
|
2021-08-11 11:10:28 +02:00
|
|
|
func runSoongUiForProduct(mpctx *mpContext, product string) {
|
|
|
|
outDir := filepath.Join(mpctx.MainOutDir, product)
|
|
|
|
logsDir := filepath.Join(mpctx.MainLogsDir, product)
|
|
|
|
productZip := filepath.Join(mpctx.MainOutDir, product+".zip")
|
2021-08-10 15:01:13 +02:00
|
|
|
consoleLogPath := filepath.Join(logsDir, "std.log")
|
2018-09-05 03:09:47 +02:00
|
|
|
|
|
|
|
if err := os.MkdirAll(outDir, 0777); err != nil {
|
|
|
|
mpctx.Logger.Fatalf("Error creating out directory: %v", err)
|
|
|
|
}
|
|
|
|
if err := os.MkdirAll(logsDir, 0777); err != nil {
|
|
|
|
mpctx.Logger.Fatalf("Error creating log directory: %v", err)
|
|
|
|
}
|
|
|
|
|
2021-08-10 15:01:13 +02:00
|
|
|
consoleLogFile, err := os.Create(consoleLogPath)
|
2018-09-05 03:09:47 +02:00
|
|
|
if err != nil {
|
2021-08-10 15:01:13 +02:00
|
|
|
mpctx.Logger.Fatalf("Error creating console log file: %v", err)
|
2018-09-05 03:09:47 +02:00
|
|
|
}
|
2021-08-10 15:01:13 +02:00
|
|
|
defer consoleLogFile.Close()
|
2018-09-05 03:09:47 +02:00
|
|
|
|
2021-08-10 15:01:13 +02:00
|
|
|
consoleLogWriter := bufio.NewWriter(consoleLogFile)
|
|
|
|
defer consoleLogWriter.Flush()
|
2018-09-05 03:09:47 +02:00
|
|
|
|
2021-08-10 15:01:13 +02:00
|
|
|
args := []string{"--make-mode", "--skip-soong-tests", "--skip-ninja"}
|
|
|
|
|
|
|
|
if !*keepArtifacts {
|
|
|
|
args = append(args, "--empty-ninja-file")
|
2018-09-05 03:09:47 +02:00
|
|
|
}
|
|
|
|
|
2021-08-10 15:01:13 +02:00
|
|
|
if *onlyConfig {
|
|
|
|
args = append(args, "--config-only")
|
|
|
|
} else if *onlySoong {
|
|
|
|
args = append(args, "--soong-only")
|
|
|
|
}
|
2018-09-05 03:09:47 +02:00
|
|
|
|
2022-10-26 20:21:55 +02:00
|
|
|
bazelStr := getBazelArg()
|
|
|
|
if bazelStr != "" {
|
|
|
|
args = append(args, bazelStr)
|
|
|
|
}
|
|
|
|
|
2021-08-11 11:10:28 +02:00
|
|
|
cmd := exec.Command(mpctx.SoongUi, args...)
|
2021-08-10 15:01:13 +02:00
|
|
|
cmd.Stdout = consoleLogWriter
|
|
|
|
cmd.Stderr = consoleLogWriter
|
|
|
|
cmd.Env = append(os.Environ(),
|
|
|
|
"OUT_DIR="+outDir,
|
|
|
|
"TARGET_PRODUCT="+product,
|
|
|
|
"TARGET_BUILD_VARIANT="+*buildVariant,
|
|
|
|
"TARGET_BUILD_TYPE=release",
|
|
|
|
"TARGET_BUILD_APPS=",
|
2023-02-17 20:36:35 +01:00
|
|
|
"TARGET_BUILD_UNBUNDLED=",
|
|
|
|
"USE_RBE=false") // Disabling RBE saves ~10 secs per product
|
2021-06-04 11:09:01 +02:00
|
|
|
|
2021-08-24 10:47:13 +02:00
|
|
|
if *alternateResultDir {
|
|
|
|
cmd.Env = append(cmd.Env,
|
|
|
|
"DIST_DIR="+filepath.Join(distDir(outDirBase()), "products/"+product))
|
|
|
|
}
|
|
|
|
|
2021-08-10 15:01:13 +02:00
|
|
|
action := &status.Action{
|
|
|
|
Description: product,
|
|
|
|
Outputs: []string{product},
|
2018-09-05 03:09:47 +02:00
|
|
|
}
|
|
|
|
|
2021-08-10 15:01:13 +02:00
|
|
|
mpctx.Status.StartAction(action)
|
|
|
|
defer cleanupAfterProduct(outDir, productZip)
|
|
|
|
|
2018-09-05 03:09:47 +02:00
|
|
|
before := time.Now()
|
2021-08-10 15:01:13 +02:00
|
|
|
err = cmd.Run()
|
2018-09-05 03:09:47 +02:00
|
|
|
|
2021-08-10 15:01:13 +02:00
|
|
|
if !*onlyConfig && !*onlySoong {
|
|
|
|
katiBuildNinjaFile := filepath.Join(outDir, "build-"+product+".ninja")
|
|
|
|
if after, err := os.Stat(katiBuildNinjaFile); err == nil && after.ModTime().After(before) {
|
|
|
|
err := copyFile(consoleLogPath, filepath.Join(filepath.Dir(consoleLogPath), "std_full.log"))
|
2018-09-05 03:09:47 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("Error copying log file: %s", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-24 10:47:13 +02:00
|
|
|
var errOutput string
|
|
|
|
if err == nil {
|
|
|
|
errOutput = ""
|
|
|
|
} else {
|
|
|
|
errOutput = errMsgFromLog(consoleLogPath)
|
|
|
|
}
|
|
|
|
|
2018-09-05 03:09:47 +02:00
|
|
|
mpctx.Status.FinishAction(status.ActionResult{
|
|
|
|
Action: action,
|
2021-08-10 15:01:13 +02:00
|
|
|
Error: err,
|
2021-08-24 10:47:13 +02:00
|
|
|
Output: errOutput,
|
2018-09-05 03:09:47 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-02-14 21:42:53 +01:00
|
|
|
type failureCount struct {
|
|
|
|
count int
|
|
|
|
fails []string
|
|
|
|
}
|
2018-07-20 07:57:18 +02:00
|
|
|
|
|
|
|
func (f *failureCount) StartAction(action *status.Action, counts status.Counts) {}
|
|
|
|
|
|
|
|
func (f *failureCount) FinishAction(result status.ActionResult, counts status.Counts) {
|
|
|
|
if result.Error != nil {
|
2022-02-14 21:42:53 +01:00
|
|
|
f.count += 1
|
|
|
|
f.fails = append(f.fails, result.Action.Description)
|
2018-07-20 07:57:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *failureCount) Message(level status.MsgLevel, message string) {
|
|
|
|
if level >= status.ErrorLvl {
|
2022-02-14 21:42:53 +01:00
|
|
|
f.count += 1
|
2018-07-20 07:57:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (f *failureCount) Flush() {}
|
2019-06-10 04:40:08 +02:00
|
|
|
|
|
|
|
func (f *failureCount) Write(p []byte) (int, error) {
|
|
|
|
// discard writes
|
|
|
|
return len(p), nil
|
|
|
|
}
|
2019-12-06 00:22:41 +01:00
|
|
|
|
|
|
|
func splitList(list []string, shardCount int) (ret [][]string) {
|
|
|
|
each := len(list) / shardCount
|
|
|
|
extra := len(list) % shardCount
|
|
|
|
for i := 0; i < shardCount; i++ {
|
|
|
|
count := each
|
|
|
|
if extra > 0 {
|
|
|
|
count += 1
|
|
|
|
extra -= 1
|
|
|
|
}
|
|
|
|
ret = append(ret, list[:count])
|
|
|
|
list = list[count:]
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|