Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2520f5e3 authored by Jason Wu's avatar Jason Wu
Browse files

Add re_analysis environment varibles fields to soong_metrics

Test: Tested by following steps
1.m nothing: field is empty
2.USE_RBE=false m nothing: field log cc_wrapper and rbe_wrapper
3.USE_RBE=false m nothing: field is empty
Bug: 281922291

Change-Id: I1bbb324752b9a2dea1ff2c9df5817559d4cec3a6
parent 5324cc84
Loading
Loading
Loading
Loading
+11 −7
Original line number Diff line number Diff line
@@ -55,20 +55,23 @@ func EnvFileContents(envDeps map[string]string) ([]byte, error) {
	return data, nil
}

// Reads and deserializes a Soong environment file located at the given file path to determine its
// staleness. If any environment variable values have changed, it prints them out and returns true.
// Reads and deserializes a Soong environment file located at the given file
// path to determine its staleness. If any environment variable values have
// changed, it prints and returns changed environment variable values and
// returns true.
// Failing to read or parse the file also causes it to return true.
func StaleEnvFile(filepath string, getenv func(string) string) (bool, error) {
func StaleEnvFile(filepath string, getenv func(string) string) (isStale bool,
	changedEnvironmentVariable []string, err error) {
	data, err := ioutil.ReadFile(filepath)
	if err != nil {
		return true, err
		return true, nil, err
	}

	var contents envFileData

	err = json.Unmarshal(data, &contents)
	if err != nil {
		return true, err
		return true, nil, err
	}

	var changed []string
@@ -78,6 +81,7 @@ func StaleEnvFile(filepath string, getenv func(string) string) (bool, error) {
		cur := getenv(key)
		if old != cur {
			changed = append(changed, fmt.Sprintf("%s (%q -> %q)", key, old, cur))
			changedEnvironmentVariable = append(changedEnvironmentVariable, key)
		}
	}

@@ -86,10 +90,10 @@ func StaleEnvFile(filepath string, getenv func(string) string) (bool, error) {
		for _, s := range changed {
			fmt.Printf("   %s\n", s)
		}
		return true, nil
		return true, changedEnvironmentVariable, nil
	}

	return false, nil
	return false, nil, nil
}

// Deserializes and environment serialized by EnvFileContents() and returns it
+12 −8
Original line number Diff line number Diff line
@@ -451,13 +451,17 @@ func bootstrapBlueprint(ctx Context, config Config) {
	_ = bootstrap.RunBlueprint(blueprintArgs, bootstrap.DoEverything, blueprintCtx, blueprintConfig)
}

func checkEnvironmentFile(currentEnv *Environment, envFile string) {
func checkEnvironmentFile(ctx Context, currentEnv *Environment, envFile string) {
	getenv := func(k string) string {
		v, _ := currentEnv.Get(k)
		return v
	}

	if stale, _ := shared.StaleEnvFile(envFile, getenv); stale {
	// Log the changed environment variables to ChangedEnvironmentVariable field
	if stale, changedEnvironmentVariableList, _ := shared.StaleEnvFile(envFile, getenv); stale {
		for _, changedEnvironmentVariable := range changedEnvironmentVariableList {
			ctx.Metrics.AddChangedEnvironmentVariable(changedEnvironmentVariable)
		}
		os.Remove(envFile)
	}
}
@@ -502,26 +506,26 @@ func runSoong(ctx Context, config Config) {
		ctx.BeginTrace(metrics.RunSoong, "environment check")
		defer ctx.EndTrace()

		checkEnvironmentFile(soongBuildEnv, config.UsedEnvFile(soongBuildTag))
		checkEnvironmentFile(ctx, soongBuildEnv, config.UsedEnvFile(soongBuildTag))

		if config.BazelBuildEnabled() || config.Bp2Build() {
			checkEnvironmentFile(soongBuildEnv, config.UsedEnvFile(bp2buildFilesTag))
			checkEnvironmentFile(ctx, soongBuildEnv, config.UsedEnvFile(bp2buildFilesTag))
		}

		if config.JsonModuleGraph() {
			checkEnvironmentFile(soongBuildEnv, config.UsedEnvFile(jsonModuleGraphTag))
			checkEnvironmentFile(ctx, soongBuildEnv, config.UsedEnvFile(jsonModuleGraphTag))
		}

		if config.Queryview() {
			checkEnvironmentFile(soongBuildEnv, config.UsedEnvFile(queryviewTag))
			checkEnvironmentFile(ctx, soongBuildEnv, config.UsedEnvFile(queryviewTag))
		}

		if config.ApiBp2build() {
			checkEnvironmentFile(soongBuildEnv, config.UsedEnvFile(apiBp2buildTag))
			checkEnvironmentFile(ctx, soongBuildEnv, config.UsedEnvFile(apiBp2buildTag))
		}

		if config.SoongDocs() {
			checkEnvironmentFile(soongBuildEnv, config.UsedEnvFile(soongDocsTag))
			checkEnvironmentFile(ctx, soongBuildEnv, config.UsedEnvFile(soongDocsTag))
		}
	}()

+7 −0
Original line number Diff line number Diff line
@@ -248,6 +248,13 @@ func (m *Metrics) SetBuildCommand(cmd []string) {
	m.metrics.BuildCommand = proto.String(strings.Join(cmd, " "))
}

// AddChangedEnvironmentVariable adds the changed environment variable to
// ChangedEnvironmentVariable field.
func (m *Metrics) AddChangedEnvironmentVariable(ChangedEnvironmentVariable string) {
	m.metrics.ChangedEnvironmentVariable = append(m.metrics.ChangedEnvironmentVariable,
		ChangedEnvironmentVariable)
}

// Dump exports the collected metrics from the executed build to the file at
// out path.
func (m *Metrics) Dump(out string) error {
+209 −193

File changed.

Preview size limit exceeded, changes collapsed.

+6 −0
Original line number Diff line number Diff line
@@ -131,6 +131,12 @@ message MetricsBase {

  // The metric of critical path in build
  optional CriticalPathInfo critical_path_info = 33;

  // Environment variables that have changed value since the previous build,
  // which were responsible for retriggering build analysis.
  // Note that not all changed environment variables result in analysis retriggering.
  // If there was no previous build, this list will be empty.
  repeated string changed_environment_variable = 34;
}

message BuildConfig {