Merge "Collect useful resource information of each executed process in soong_ui."
diff --git a/apex/allowed_deps.txt b/apex/allowed_deps.txt
index e5b91e5..8c70a56 100644
--- a/apex/allowed_deps.txt
+++ b/apex/allowed_deps.txt
@@ -235,6 +235,7 @@
 libc_headers(minSdkVersion:apex_inherit)
 libc_headers_arch(minSdkVersion:apex_inherit)
 libcap(minSdkVersion:29)
+libclang_rt.hwasan-aarch64-android.llndk(minSdkVersion:(no version))
 libcodec2(minSdkVersion:29)
 libcodec2_headers(minSdkVersion:29)
 libcodec2_hidl@1.0(minSdkVersion:29)
diff --git a/apex/apex_singleton.go b/apex/apex_singleton.go
index 803e0c5..ee9fc81 100644
--- a/apex/apex_singleton.go
+++ b/apex/apex_singleton.go
@@ -100,6 +100,8 @@
 			"new_allowed_deps": newAllowedDeps.String(),
 		},
 	})
+
+	ctx.Phony("apex-allowed-deps-check", s.allowedApexDepsInfoCheckResult)
 }
 
 func (s *apexDepsInfoSingleton) MakeVars(ctx android.MakeVarsContext) {
diff --git a/ui/build/bazel.go b/ui/build/bazel.go
index c5702c0..978553d 100644
--- a/ui/build/bazel.go
+++ b/ui/build/bazel.go
@@ -15,6 +15,8 @@
 package build
 
 import (
+	"io/ioutil"
+	"os"
 	"path/filepath"
 	"strings"
 )
@@ -32,12 +34,6 @@
 	bazelExecutable := filepath.Join("tools", "bazel")
 	args := []string{
 		"build",
-		"--verbose_failures",
-		"--show_progress_rate_limit=0.05",
-		"--color=yes",
-		"--curses=yes",
-		"--show_timestamps",
-		"--announce_rc",
 		"--output_groups=" + outputGroups,
 		"//:" + config.TargetProduct() + "-" + config.TargetBuildVariant(),
 	}
@@ -51,4 +47,57 @@
 	cmd.Dir = filepath.Join(config.OutDir(), "..")
 	ctx.Status.Status("Starting Bazel..")
 	cmd.RunAndStreamOrFatal()
+
+	// Obtain the Bazel output directory for ninja_build.
+	infoArgs := []string{
+		"info",
+		"output_path",
+	}
+
+	infoCmd := Command(ctx, config, "bazel", bazelExecutable, infoArgs...)
+
+	infoCmd.Environment.Set("DIST_DIR", config.DistDir())
+	infoCmd.Environment.Set("SHELL", "/bin/bash")
+	infoCmd.Dir = filepath.Join(config.OutDir(), "..")
+	ctx.Status.Status("Getting Bazel Info..")
+	outputBasePath := string(infoCmd.OutputOrFatal())
+	// TODO: Don't hardcode out/ as the bazel output directory. This is
+	// currently hardcoded as ninja_build.output_root.
+	bazelNinjaBuildOutputRoot := filepath.Join(outputBasePath, "..", "out")
+
+	symlinkOutdir(ctx, config, bazelNinjaBuildOutputRoot, ".")
+}
+
+// For all files F recursively under rootPath/relativePath, creates symlinks
+// such that OutDir/F resolves to rootPath/F via symlinks.
+func symlinkOutdir(ctx Context, config Config, rootPath string, relativePath string) {
+	destDir := filepath.Join(rootPath, relativePath)
+	os.MkdirAll(destDir, 0755)
+	files, err := ioutil.ReadDir(destDir)
+	if err != nil {
+		ctx.Fatal(err)
+	}
+	for _, f := range files {
+		destPath := filepath.Join(destDir, f.Name())
+		srcPath := filepath.Join(config.OutDir(), relativePath, f.Name())
+		if statResult, err := os.Stat(srcPath); err == nil {
+			if statResult.Mode().IsDir() && f.IsDir() {
+				// Directory under OutDir already exists, so recurse on its contents.
+				symlinkOutdir(ctx, config, rootPath, filepath.Join(relativePath, f.Name()))
+			} else if !statResult.Mode().IsDir() && !f.IsDir() {
+				// File exists both in source and destination, and it's not a directory
+				// in either location. Do nothing.
+				// This can arise for files which are generated under OutDir outside of
+				// soong_build, such as .bootstrap files.
+			} else {
+				// File is a directory in one location but not the other. Raise an error.
+				ctx.Fatalf("Could not link %s to %s due to conflict", srcPath, destPath)
+			}
+		} else if os.IsNotExist(err) {
+			// Create symlink srcPath -> fullDestPath.
+			os.Symlink(destPath, srcPath)
+		} else {
+			ctx.Fatalf("Unable to stat %s: %s", srcPath, err)
+		}
+	}
 }