Read $HOME first to determine the home directory (and when not present, fall back to getpwuid()) Also a minor compatibility fix in a sed invocation. -- MOS_MIGRATED_REVID=106291639
diff --git a/src/BUILD b/src/BUILD index adcaf26..21cb1f8 100644 --- a/src/BUILD +++ b/src/BUILD
@@ -52,7 +52,7 @@ outs = ["java.version"], cmd = """ VERSION_LINE=$$(cat $< | grep target_version); - JAVA_VERSION=$$(echo $${VERSION_LINE} | sed -E 's/.*value="([^"])".*/\\1/'); + JAVA_VERSION=$$(echo $${VERSION_LINE} | sed 's/.*value="\\([^"]\\)".*/\\1/'); if [ -z "$${JAVA_VERSION}" ]; then echo "1.8" >$@ # Java 8 is the default elif [[ "$${JAVA_VERSION}" =~ ^[0-9]+$$ ]]; then
diff --git a/src/main/cpp/blaze_util_linux.cc b/src/main/cpp/blaze_util_linux.cc index 08bd075..867fbb2 100644 --- a/src/main/cpp/blaze_util_linux.cc +++ b/src/main/cpp/blaze_util_linux.cc
@@ -36,15 +36,25 @@ string GetOutputRoot() { char buf[2048]; - struct passwd pwbuf; - struct passwd *pw = NULL; - int uid = getuid(); - int r = getpwuid_r(uid, &pwbuf, buf, 2048, &pw); - if (r != -1 && pw != NULL) { - return blaze_util::JoinPath(pw->pw_dir, ".cache/bazel"); + string base; + const char* home = getenv("HOME"); + if (home != NULL) { + base = home; } else { - return "/tmp"; + struct passwd pwbuf; + struct passwd *pw = NULL; + int uid = getuid(); + int r = getpwuid_r(uid, &pwbuf, buf, 2048, &pw); + if (r != -1 && pw != NULL) { + base = pw->pw_dir; + } } + + if (base != "") { + return blaze_util::JoinPath(base, ".cache/bazel"); + } + + return "/tmp"; } void WarnFilesystemType(const string& output_base) {