From d492853a52b3f07bf61e2123474863f98905ac95 Mon Sep 17 00:00:00 2001 From: Jeff Gaston Date: Fri, 24 Aug 2018 14:30:13 -0400 Subject: [PATCH] pom2bp support to specify which modules are host modules Bug: 112804807 Test: cd prebuilts/sdk/current/support && pom2bp -regen Android.bp Change-Id: Ib816db8274cb05c9d0ed2cb557799ddcf6ee74fd --- cmd/pom2bp/pom2bp.go | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go index 9ce6b504b..a39642fd3 100644 --- a/cmd/pom2bp/pom2bp.go +++ b/cmd/pom2bp/pom2bp.go @@ -104,6 +104,24 @@ func (e Exclude) Set(v string) error { 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 @@ func (p Pom) IsJar() bool { 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 @@ var bpTemplate = template.Must(template.New("bp").Parse(` ],{{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 @@ Usage: %s [--rewrite =] [-exclude ] [--extra-deps