Invoke queryview from the bootstrap Ninja file.

It used to be invoked from out/soong/build.ninja, which required two
soong_build invocations one after the other (ne to generate
out/soong/build.ninja, one to generate the queryview workspace). This
was slower and required some shell-quoted-in-ninja-quoted-in-Go .

Test: Presubmits.
Change-Id: Idda79c067606663b66e9f94626fa24f3b5af4114
diff --git a/ui/build/soong.go b/ui/build/soong.go
index fef30da..04d106b 100644
--- a/ui/build/soong.go
+++ b/ui/build/soong.go
@@ -142,6 +142,7 @@
 
 	bootstrapGlobFile := shared.JoinPath(config.SoongOutDir(), ".bootstrap/build-globs.ninja")
 	bp2buildGlobFile := shared.JoinPath(config.SoongOutDir(), ".bootstrap/build-globs.bp2build.ninja")
+	queryviewGlobFile := shared.JoinPath(config.SoongOutDir(), ".bootstrap/build-globs.queryview.ninja")
 	moduleGraphGlobFile := shared.JoinPath(config.SoongOutDir(), ".bootstrap/build-globs.modulegraph.ninja")
 
 	// The glob .ninja files are subninja'd. However, they are generated during
@@ -149,6 +150,9 @@
 	// fail on clean builds
 	writeEmptyGlobFile(ctx, bootstrapGlobFile)
 	writeEmptyGlobFile(ctx, bp2buildGlobFile)
+	writeEmptyGlobFile(ctx, queryviewGlobFile)
+	writeEmptyGlobFile(ctx, moduleGraphGlobFile)
+
 	bootstrapDepFile := shared.JoinPath(config.SoongOutDir(), ".bootstrap/build.ninja.d")
 
 	args.RunGoTests = !config.skipSoongTests
@@ -160,7 +164,7 @@
 	// The primary builder (aka soong_build) will use bootstrapGlobFile as the globFile to generate build.ninja(.d)
 	// Building soong_build does not require a glob file
 	// Using "" instead of "<soong_build_glob>.ninja" will ensure that an unused glob file is not written to out/soong/.bootstrap during StagePrimary
-	args.Subninjas = []string{bootstrapGlobFile, bp2buildGlobFile}
+	args.Subninjas = []string{bootstrapGlobFile, bp2buildGlobFile, moduleGraphGlobFile, queryviewGlobFile}
 	args.EmptyNinjaFile = config.EmptyNinjaFile()
 
 	args.DelveListen = os.Getenv("SOONG_DELVE")
@@ -206,6 +210,22 @@
 		Args:    bp2buildArgs,
 	}
 
+	queryviewArgs := []string{
+		"--bazel_queryview_dir", filepath.Join(config.SoongOutDir(), "queryview"),
+		"--globListDir", "queryview",
+		"--globFile", queryviewGlobFile,
+	}
+
+	queryviewArgs = append(queryviewArgs, commonArgs...)
+	queryviewArgs = append(queryviewArgs, environmentArgs(config, ".queryview")...)
+	queryviewArgs = append(queryviewArgs, "Android.bp")
+
+	queryviewInvocation := bootstrap.PrimaryBuilderInvocation{
+		Inputs:  []string{"Android.bp"},
+		Outputs: []string{config.QueryviewMarkerFile()},
+		Args:    queryviewArgs,
+	}
+
 	moduleGraphArgs := []string{
 		"--module_graph_file", config.ModuleGraphFile(),
 		"--globListDir", "modulegraph",
@@ -226,6 +246,7 @@
 		bp2buildInvocation,
 		mainSoongBuildInvocation,
 		moduleGraphInvocation,
+		queryviewInvocation,
 	}
 
 	blueprintCtx := blueprint.NewContext()
@@ -361,6 +382,10 @@
 		targets = append(targets, config.Bp2BuildMarkerFile())
 	}
 
+	if config.Queryview() {
+		targets = append(targets, config.QueryviewMarkerFile())
+	}
+
 	if config.SoongBuildInvocationNeeded() {
 		// This build generates <builddir>/build.ninja, which is used later by build/soong/ui/build/build.go#Build().
 		targets = append(targets, config.MainNinjaFile())