Add BUILD_USERNAME and BUILD_HOSTNAME
As part of a future change to sandbox the build on Linux, the real
username will be switching to "nobody", and the hostname will be
switching to "android-build".
The USER environment variable will reflect the sandboxed value, so for
the build properties that want the external USER, they'll need to use
BUILD_USERNAME.
Similarly, BUILD_HOSTNAME will reflect the real value, while the
`hostname` tool will return "android-build"
Bug: 122270019
Test: check build.prop
Change-Id: I99604b9488732a63690b256dc4dd7894d369a32c
diff --git a/ui/build/kati.go b/ui/build/kati.go
index 205d5ae..439c928 100644
--- a/ui/build/kati.go
+++ b/ui/build/kati.go
@@ -18,6 +18,8 @@
"crypto/md5"
"fmt"
"io/ioutil"
+ "os"
+ "os/user"
"path/filepath"
"strings"
@@ -96,6 +98,22 @@
envFunc(cmd.Environment)
+ if _, ok := cmd.Environment.Get("BUILD_USERNAME"); !ok {
+ u, err := user.Current()
+ if err != nil {
+ ctx.Println("Failed to get current user")
+ }
+ cmd.Environment.Set("BUILD_USERNAME", u.Username)
+ }
+
+ if _, ok := cmd.Environment.Get("BUILD_HOSTNAME"); !ok {
+ hostname, err := os.Hostname()
+ if err != nil {
+ ctx.Println("Failed to read hostname")
+ }
+ cmd.Environment.Set("BUILD_HOSTNAME", hostname)
+ }
+
cmd.StartOrFatal()
status.KatiReader(ctx.Status.StartTool(), pipe)
cmd.WaitOrFatal()