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
This commit is contained in:
Dan Willemsen
2019-01-02 12:21:18 -08:00
parent e2e13a5d99
commit 71edc8b848

View File

@@ -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()