Merge "Add --bazel-exit-code parameter to soong_ui."
This commit is contained in:
@@ -94,7 +94,7 @@ var commands = []command{
|
|||||||
}, {
|
}, {
|
||||||
flag: "--upload-metrics-only",
|
flag: "--upload-metrics-only",
|
||||||
description: "upload metrics without building anything",
|
description: "upload metrics without building anything",
|
||||||
config: uploadOnlyConfig,
|
config: build.UploadOnlyConfig,
|
||||||
stdio: stdio,
|
stdio: stdio,
|
||||||
// Upload-only mode mostly skips to the metrics-uploading phase of soong_ui.
|
// Upload-only mode mostly skips to the metrics-uploading phase of soong_ui.
|
||||||
// However, this invocation marks the true "end of the build", and thus we
|
// However, this invocation marks the true "end of the build", and thus we
|
||||||
@@ -451,14 +451,6 @@ func dumpVarConfig(ctx build.Context, args ...string) build.Config {
|
|||||||
return build.NewConfig(ctx)
|
return build.NewConfig(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// uploadOnlyConfig explicitly requires no arguments.
|
|
||||||
func uploadOnlyConfig(ctx build.Context, args ...string) build.Config {
|
|
||||||
if len(args) > 0 {
|
|
||||||
fmt.Printf("--upload-only does not require arguments.")
|
|
||||||
}
|
|
||||||
return build.UploadOnlyConfig(ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func buildActionConfig(ctx build.Context, args ...string) build.Config {
|
func buildActionConfig(ctx build.Context, args ...string) build.Config {
|
||||||
flags := flag.NewFlagSet("build-mode", flag.ContinueOnError)
|
flags := flag.NewFlagSet("build-mode", flag.ContinueOnError)
|
||||||
flags.SetOutput(ctx.Writer)
|
flags.SetOutput(ctx.Writer)
|
||||||
@@ -710,7 +702,7 @@ func updateTotalRealTime(ctx build.Context, config build.Config, args []string)
|
|||||||
}
|
}
|
||||||
met := ctx.ContextImpl.Metrics
|
met := ctx.ContextImpl.Metrics
|
||||||
|
|
||||||
err = met.UpdateTotalRealTime(data)
|
err = met.UpdateTotalRealTimeAndNonZeroExit(data, config.BazelExitCode())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Fatal(err)
|
ctx.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@@ -89,7 +89,8 @@ type configImpl struct {
|
|||||||
skipMetricsUpload bool
|
skipMetricsUpload bool
|
||||||
buildStartedTime int64 // For metrics-upload-only - manually specify a build-started time
|
buildStartedTime int64 // For metrics-upload-only - manually specify a build-started time
|
||||||
buildFromTextStub bool
|
buildFromTextStub bool
|
||||||
ensureAllowlistIntegrity bool // For CI builds - make sure modules are mixed-built
|
ensureAllowlistIntegrity bool // For CI builds - make sure modules are mixed-built
|
||||||
|
bazelExitCode int32 // For b-runs - necessary for updating NonZeroExit
|
||||||
|
|
||||||
// From the product config
|
// From the product config
|
||||||
katiArgs []string
|
katiArgs []string
|
||||||
@@ -298,11 +299,12 @@ func defaultBazelProdMode(cfg *configImpl) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func UploadOnlyConfig(ctx Context, _ ...string) Config {
|
func UploadOnlyConfig(ctx Context, args ...string) Config {
|
||||||
ret := &configImpl{
|
ret := &configImpl{
|
||||||
environ: OsEnvironment(),
|
environ: OsEnvironment(),
|
||||||
sandboxConfig: &SandboxConfig{},
|
sandboxConfig: &SandboxConfig{},
|
||||||
}
|
}
|
||||||
|
ret.parseArgs(ctx, args)
|
||||||
srcDir := absPath(ctx, ".")
|
srcDir := absPath(ctx, ".")
|
||||||
bc := os.Getenv("ANDROID_BUILD_ENVIRONMENT_CONFIG")
|
bc := os.Getenv("ANDROID_BUILD_ENVIRONMENT_CONFIG")
|
||||||
if err := loadEnvConfig(ctx, ret, bc); err != nil {
|
if err := loadEnvConfig(ctx, ret, bc); err != nil {
|
||||||
@@ -883,6 +885,14 @@ func (c *configImpl) parseArgs(ctx Context, args []string) {
|
|||||||
}
|
}
|
||||||
} else if arg == "--ensure-allowlist-integrity" {
|
} else if arg == "--ensure-allowlist-integrity" {
|
||||||
c.ensureAllowlistIntegrity = true
|
c.ensureAllowlistIntegrity = true
|
||||||
|
} else if strings.HasPrefix(arg, "--bazel-exit-code=") {
|
||||||
|
bazelExitCodeStr := strings.TrimPrefix(arg, "--bazel-exit-code=")
|
||||||
|
val, err := strconv.Atoi(bazelExitCodeStr)
|
||||||
|
if err == nil {
|
||||||
|
c.bazelExitCode = int32(val)
|
||||||
|
} else {
|
||||||
|
ctx.Fatalf("Error parsing bazel-exit-code", err)
|
||||||
|
}
|
||||||
} else if len(arg) > 0 && arg[0] == '-' {
|
} else if len(arg) > 0 && arg[0] == '-' {
|
||||||
parseArgNum := func(def int) int {
|
parseArgNum := func(def int) int {
|
||||||
if len(arg) > 2 {
|
if len(arg) > 2 {
|
||||||
@@ -1723,6 +1733,10 @@ func (c *configImpl) BuildStartedTimeOrDefault(defaultTime time.Time) time.Time
|
|||||||
return time.UnixMilli(c.buildStartedTime)
|
return time.UnixMilli(c.buildStartedTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *configImpl) BazelExitCode() int32 {
|
||||||
|
return c.bazelExitCode
|
||||||
|
}
|
||||||
|
|
||||||
func GetMetricsUploader(topDir string, env *Environment) string {
|
func GetMetricsUploader(topDir string, env *Environment) string {
|
||||||
if p, ok := env.Get("METRICS_UPLOADER"); ok {
|
if p, ok := env.Get("METRICS_UPLOADER"); ok {
|
||||||
metricsUploader := filepath.Join(topDir, p)
|
metricsUploader := filepath.Join(topDir, p)
|
||||||
|
@@ -141,7 +141,7 @@ func parsePhaseTiming(line string) bazel_metrics_proto.PhaseTiming {
|
|||||||
// This method takes a file created by bazel's --analyze-profile mode and
|
// This method takes a file created by bazel's --analyze-profile mode and
|
||||||
// writes bazel metrics data to the provided filepath.
|
// writes bazel metrics data to the provided filepath.
|
||||||
// TODO(b/279987768) - move this outside of upload.go
|
// TODO(b/279987768) - move this outside of upload.go
|
||||||
func processBazelMetrics(bazelProfileFile string, bazelMetricsFile string, ctx Context) {
|
func processBazelMetrics(bazelProfileFile string, bazelMetricsFile string, ctx Context, config Config) {
|
||||||
if bazelProfileFile == "" {
|
if bazelProfileFile == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -179,6 +179,7 @@ func processBazelMetrics(bazelProfileFile string, bazelMetricsFile string, ctx C
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
bazelProto := readBazelProto(bazelProfileFile)
|
bazelProto := readBazelProto(bazelProfileFile)
|
||||||
|
bazelProto.ExitCode = proto.Int32(config.bazelExitCode)
|
||||||
shared.Save(&bazelProto, bazelMetricsFile)
|
shared.Save(&bazelProto, bazelMetricsFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +193,7 @@ func UploadMetrics(ctx Context, config Config, simpleOutput bool, buildStarted t
|
|||||||
defer ctx.EndTrace()
|
defer ctx.EndTrace()
|
||||||
|
|
||||||
uploader := config.MetricsUploaderApp()
|
uploader := config.MetricsUploaderApp()
|
||||||
processBazelMetrics(bazelProfileFile, bazelMetricsFile, ctx)
|
processBazelMetrics(bazelProfileFile, bazelMetricsFile, ctx, config)
|
||||||
|
|
||||||
if uploader == "" {
|
if uploader == "" {
|
||||||
// If the uploader path was not specified, no metrics shall be uploaded.
|
// If the uploader path was not specified, no metrics shall be uploaded.
|
||||||
|
@@ -228,7 +228,7 @@ func (m *Metrics) SetBuildDateTime(buildTimestamp time.Time) {
|
|||||||
m.metrics.BuildDateTimestamp = proto.Int64(buildTimestamp.UnixNano() / int64(time.Second))
|
m.metrics.BuildDateTimestamp = proto.Int64(buildTimestamp.UnixNano() / int64(time.Second))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Metrics) UpdateTotalRealTime(data []byte) error {
|
func (m *Metrics) UpdateTotalRealTimeAndNonZeroExit(data []byte, bazelExitCode int32) error {
|
||||||
if err := proto.Unmarshal(data, &m.metrics); err != nil {
|
if err := proto.Unmarshal(data, &m.metrics); err != nil {
|
||||||
return fmt.Errorf("Failed to unmarshal proto", err)
|
return fmt.Errorf("Failed to unmarshal proto", err)
|
||||||
}
|
}
|
||||||
@@ -236,6 +236,9 @@ func (m *Metrics) UpdateTotalRealTime(data []byte) error {
|
|||||||
endTime := uint64(time.Now().UnixNano())
|
endTime := uint64(time.Now().UnixNano())
|
||||||
|
|
||||||
*m.metrics.Total.RealTime = *proto.Uint64(endTime - startTime)
|
*m.metrics.Total.RealTime = *proto.Uint64(endTime - startTime)
|
||||||
|
|
||||||
|
bazelError := bazelExitCode != 0
|
||||||
|
m.metrics.NonZeroExit = proto.Bool(bazelError)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user