Allow Soong to generate its own build documentation

Add a rule in soong that re-executes soong_build in order to
generate build documentation.  This allows Soong to customize
the documentation.

Bug: 70516282
Test: m soong_docs
Change-Id: If143cfacd6ac20274cd7bb8d8fab0c07025a5553
diff --git a/cmd/soong_build/main.go b/cmd/soong_build/main.go
index ddde1c5..40beab8 100644
--- a/cmd/soong_build/main.go
+++ b/cmd/soong_build/main.go
@@ -25,6 +25,14 @@
 	"android/soong/android"
 )
 
+var (
+	docFile string
+)
+
+func init() {
+	flag.StringVar(&docFile, "soong_docs", "", "build documentation file to output")
+}
+
 func newNameResolver(config android.Config) *android.NameResolver {
 	namespacePathsToExport := make(map[string]bool)
 
@@ -56,9 +64,17 @@
 		os.Exit(1)
 	}
 
+	if docFile != "" {
+		configuration.SetStopBefore(bootstrap.StopBeforePrepareBuildActions)
+	}
+
 	ctx.SetNameInterface(newNameResolver(configuration))
 
 	ctx.SetAllowMissingDependencies(configuration.AllowMissingDependencies())
 
 	bootstrap.Main(ctx.Context, configuration, configuration.ConfigFileName, configuration.ProductVariablesFileName)
+
+	if docFile != "" {
+		writeDocs(ctx, docFile)
+	}
 }