summaryrefslogtreecommitdiff
path: root/shared
diff options
context:
space:
mode:
author Jason Wu <juu@google.com> 2023-05-30 19:45:36 -0400
committer Jason Wu <juu@google.com> 2023-06-06 16:11:39 -0400
commit2520f5e36b460de08ae2961a80116be74855d4b8 (patch)
treebb27d8e12f522c6f07c942266634b9cf11b72f0e /shared
parent5324cc84ad415c366a38933046e8b210b21355ea (diff)
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
Diffstat (limited to 'shared')
-rw-r--r--shared/env.go18
1 files changed, 11 insertions, 7 deletions
diff --git a/shared/env.go b/shared/env.go
index b7d3bafb4..75190cc03 100644
--- a/shared/env.go
+++ b/shared/env.go
@@ -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