user.eclass: localize $ACCOUNTS_DIRS

If this variable gets set in the global scope, it can break prebuilts
sharing between boards. Use a local variable and cache the result in
$T instead (which will be created everytime the package is built).

TEST=emerge chromeos-base
BUG=chromium:363404

Change-Id: I548f151e4c0ce20784bb3f7088c6902a9d44eba8
Reviewed-on: https://chromium-review.googlesource.com/194569
Reviewed-by: Michael Spang <spang@chromium.org>
Tested-by: Michael Spang <spang@chromium.org>
Commit-Queue: Michael Spang <spang@chromium.org>
diff --git a/eclass/user.eclass b/eclass/user.eclass
index a848761..1df3966 100644
--- a/eclass/user.eclass
+++ b/eclass/user.eclass
@@ -52,6 +52,19 @@
 # global ACCOUNTS_DIRS array.
 _find_accounts_dirs() {
 	[[ ${#ACCOUNTS_DIRS[@]} -gt 0 ]] && return
+
+	# Load the cache from disk.  We don't want to use the env because that
+	# will be saved at build time and used when merging binpkgs.  Instead,
+	# we need it to be generated at binpkg time too.
+	local cache="${T}/_accounts_dir_cache.list"
+	if [[ -e ${cache} ]]; then
+		local dir
+		while read -d $'\0' -r dir; do
+			ACCOUNTS_DIRS+=("${dir}")
+		done <"${cache}"
+		return
+	fi
+
 	local overlay
 	for overlay in $(_call_portageq get_repos "${SYSROOT:-/}") ; do
 		local overlay_dir=$(_call_portageq get_repo_path "${SYSROOT:-/}" "${overlay}")
@@ -61,6 +74,8 @@
 			ACCOUNTS_DIRS+=("${accounts_dir}")
 		fi
 	done
+
+	printf '%s\0' "${ACCOUNTS_DIRS[@]}" >"${cache}"
 }
 
 # @FUNCTION: _call_portageq
@@ -226,6 +241,8 @@
 # /bin/false, default homedir is /dev/null, and there are no default groups.
 enewuser() {
 	_assert_pkg_ebuild_phase ${FUNCNAME}
+
+	local ACCOUNTS_DIRS
 	_find_accounts_dirs
 	if [[ ${#ACCOUNTS_DIRS[@]} -eq 0 ]] ; then
 		ewarn "No user/group data files present. Skipping."
@@ -368,6 +385,8 @@
 # allocate the next available one.
 enewgroup() {
 	_assert_pkg_ebuild_phase ${FUNCNAME}
+
+	local ACCOUNTS_DIRS
 	_find_accounts_dirs
 	if [[ ${#ACCOUNTS_DIRS[@]} -eq 0 ]] ; then
 		ewarn "No user/group data files present. Skipping."