pom2bp support to specify which modules are host modules

Bug: 112804807
Test: cd prebuilts/sdk/current/support && pom2bp -regen Android.bp
Change-Id: Ib816db8274cb05c9d0ed2cb557799ddcf6ee74fd
diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go
index 9ce6b50..a39642f 100644
--- a/cmd/pom2bp/pom2bp.go
+++ b/cmd/pom2bp/pom2bp.go
@@ -104,6 +104,24 @@
 
 var excludes = make(Exclude)
 
+type HostModuleNames map[string]bool
+
+func (n HostModuleNames) IsHostModule(groupId string, artifactId string) bool {
+	_, found := n[groupId + ":" + artifactId]
+	return found
+}
+
+func (n HostModuleNames) String() string {
+	return ""
+}
+
+func (n HostModuleNames) Set(v string) error {
+	n[v] = true
+	return nil
+}
+
+var hostModuleNames = HostModuleNames{}
+
 var sdkVersion string
 var useVersion string
 
@@ -160,6 +178,14 @@
 	return p.Packaging == "jar"
 }
 
+func (p Pom) IsHostModule() bool {
+	return hostModuleNames.IsHostModule(p.GroupId, p.ArtifactId)
+}
+
+func (p Pom) IsDeviceModule() bool {
+	return !p.IsHostModule()
+}
+
 func (p Pom) BpName() string {
 	if p.BpTarget == "" {
 		p.BpTarget = rewriteNames.MavenToBp(p.GroupId, p.ArtifactId)
@@ -278,11 +304,11 @@
     ],{{end}}
 }
 
-{{if .IsAar}}android_library{{else}}java_library_static{{end}} {
-    name: "{{.BpName}}",
+{{if .IsAar}}android_library{{else}}{{if .IsDeviceModule}}java_library_static{{else}}java_library_host{{end}}{{end}} {
+    name: "{{.BpName}}",{{if .IsDeviceModule}}
     sdk_version: "{{.SdkVersion}}",{{if .IsAar}}
     min_sdk_version: "{{.MinSdkVersion}}",
-    manifest: "manifests/{{.BpName}}/AndroidManifest.xml",{{end}}
+    manifest: "manifests/{{.BpName}}/AndroidManifest.xml",{{end}}{{end}}
     static_libs: [
         "{{.BpName}}-nodeps",{{range .BpJarDeps}}
         "{{.}}",{{end}}{{range .BpAarDeps}}
@@ -422,6 +448,7 @@
 	flag.Var(&excludes, "exclude", "Exclude module")
 	flag.Var(&extraDeps, "extra-deps", "Extra dependencies needed when depending on a module")
 	flag.Var(&rewriteNames, "rewrite", "Regex(es) to rewrite artifact names")
+	flag.Var(&hostModuleNames, "host", "Specifies that the corresponding module (specified in the form 'module.group:module.artifact') is a host module")
 	flag.StringVar(&sdkVersion, "sdk-version", "", "What to write to LOCAL_SDK_VERSION")
 	flag.StringVar(&useVersion, "use-version", "", "Only read artifacts of a specific version")
 	flag.Bool("static-deps", false, "Ignored")