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

Commit fc07a574 authored by Jason Wu's avatar Jason Wu Committed by Automerger Merge Worker
Browse files

Merge "Add re_analysis environment varibles fields to soong_metrics" am: e2df3b5f

parents ed1ce0c4 e2df3b5f
Loading
Loading
Loading
Loading
+11 −7
Original line number Original line Diff line number Diff line
@@ -55,20 +55,23 @@ func EnvFileContents(envDeps map[string]string) ([]byte, error) {
	return data, nil
	return data, nil
}
}


// Reads and deserializes a Soong environment file located at the given file path to determine its
// Reads and deserializes a Soong environment file located at the given file
// staleness. If any environment variable values have changed, it prints them out and returns true.
// 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.
// 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)
	data, err := ioutil.ReadFile(filepath)
	if err != nil {
	if err != nil {
		return true, err
		return true, nil, err
	}
	}


	var contents envFileData
	var contents envFileData


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


	var changed []string
	var changed []string
@@ -78,6 +81,7 @@ func StaleEnvFile(filepath string, getenv func(string) string) (bool, error) {
		cur := getenv(key)
		cur := getenv(key)
		if old != cur {
		if old != cur {
			changed = append(changed, fmt.Sprintf("%s (%q -> %q)", key, 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 {
		for _, s := range changed {
			fmt.Printf("   %s\n", s)
			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
// Deserializes and environment serialized by EnvFileContents() and returns it
+12 −8
Original line number Original line Diff line number Diff line
@@ -451,13 +451,17 @@ func bootstrapBlueprint(ctx Context, config Config) {
	_ = bootstrap.RunBlueprint(blueprintArgs, bootstrap.DoEverything, blueprintCtx, blueprintConfig)
	_ = 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 {
	getenv := func(k string) string {
		v, _ := currentEnv.Get(k)
		v, _ := currentEnv.Get(k)
		return v
		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)
		os.Remove(envFile)
	}
	}
}
}
@@ -502,26 +506,26 @@ func runSoong(ctx Context, config Config) {
		ctx.BeginTrace(metrics.RunSoong, "environment check")
		ctx.BeginTrace(metrics.RunSoong, "environment check")
		defer ctx.EndTrace()
		defer ctx.EndTrace()


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


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


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


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


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


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


+7 −0
Original line number Original line Diff line number Diff line
@@ -248,6 +248,13 @@ func (m *Metrics) SetBuildCommand(cmd []string) {
	m.metrics.BuildCommand = proto.String(strings.Join(cmd, " "))
	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
// Dump exports the collected metrics from the executed build to the file at
// out path.
// out path.
func (m *Metrics) Dump(out string) error {
func (m *Metrics) Dump(out string) error {