From 71edc8b8483b59fcbbd2a8c84ad5c60c4be1cd3f Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Wed, 2 Jan 2019 12:21:18 -0800 Subject: [PATCH] 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 --- ui/build/kati.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ui/build/kati.go b/ui/build/kati.go index 205d5ae5f..439c928ed 100644 --- a/ui/build/kati.go +++ b/ui/build/kati.go @@ -18,6 +18,8 @@ import ( "crypto/md5" "fmt" "io/ioutil" + "os" + "os/user" "path/filepath" "strings" @@ -96,6 +98,22 @@ func runKati(ctx Context, config Config, extraSuffix string, args []string, envF 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()