aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2018-08-29 16:17:55 -0700
committerColin Cross <ccross@android.com>2018-08-30 11:18:50 -0700
commit632987ac21c22e4efc079008986f0ae9c3feb3b9 (patch)
treedbabc2bfc6ce6f680adbd9bf3cfd1a2a4a3e990d /cmd
parent42d48b7b8b94e301d703656db0b25bc5ee7eb3bc (diff)
downloadbuild_soong-632987ac21c22e4efc079008986f0ae9c3feb3b9.tar.gz
build_soong-632987ac21c22e4efc079008986f0ae9c3feb3b9.tar.bz2
build_soong-632987ac21c22e4efc079008986f0ae9c3feb3b9.zip
pom2bp: clean up templates
Move some of the more complicated conditional logic out to helper functions. Use the {{- }} syntax to strip previous whitespace to allow spacing out the remaning conditionals in the templates. Test: (cd prebuilts/sdk/current/androidx && pom2bp -regen Android.bp) Change-Id: I766bd0e1837aa04375f322fbe796d923cd99ecde
Diffstat (limited to 'cmd')
-rw-r--r--cmd/pom2bp/pom2bp.go74
1 files changed, 59 insertions, 15 deletions
diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go
index a66a4244..a79c84f4 100644
--- a/cmd/pom2bp/pom2bp.go
+++ b/cmd/pom2bp/pom2bp.go
@@ -186,6 +186,34 @@ func (p Pom) IsDeviceModule() bool {
return !p.IsHostModule()
}
+func (p Pom) ModuleType() string {
+ if p.IsAar() {
+ return "android_library"
+ } else if p.IsHostModule() {
+ return "java_library_host"
+ } else {
+ return "java_library_static"
+ }
+}
+
+func (p Pom) ImportModuleType() string {
+ if p.IsAar() {
+ return "android_library_import"
+ } else if p.IsHostModule() {
+ return "java_import_host"
+ } else {
+ return "java_import"
+ }
+}
+
+func (p Pom) ImportProperty() string {
+ if p.IsAar() {
+ return "aars"
+ } else {
+ return "jars"
+ }
+}
+
func (p Pom) BpName() string {
if p.BpTarget == "" {
p.BpTarget = rewriteNames.MavenToBp(p.GroupId, p.ArtifactId)
@@ -293,27 +321,43 @@ func (p *Pom) ExtractMinSdkVersion() error {
}
var bpTemplate = template.Must(template.New("bp").Parse(`
-{{if .IsAar}}android_library_import{{else if .IsDeviceModule}}java_import{{else}}java_import_host{{end}} {
+{{.ImportModuleType}} {
name: "{{.BpName}}-nodeps",
- {{if .IsAar}}aars{{else}}jars{{end}}: ["{{.ArtifactFile}}"],
- sdk_version: "{{.SdkVersion}}",{{if .IsAar}}
+ {{.ImportProperty}}: ["{{.ArtifactFile}}"],
+ sdk_version: "{{.SdkVersion}}",
+ {{- if .IsAar}}
min_sdk_version: "{{.MinSdkVersion}}",
- static_libs: [{{range .BpAarDeps}}
- "{{.}}",{{end}}{{range .BpExtraDeps}}
- "{{.}}",{{end}}
- ],{{end}}
+ static_libs: [
+ {{- range .BpAarDeps}}
+ "{{.}}",
+ {{- end}}
+ {{- range .BpExtraDeps}}
+ "{{.}}",
+ {{- end}}
+ ],
+ {{- end}}
}
-{{if .IsAar}}android_library{{else if .IsDeviceModule}}java_library_static{{else}}java_library_host{{end}} {
- name: "{{.BpName}}",{{if .IsDeviceModule}}
- sdk_version: "{{.SdkVersion}}",{{if .IsAar}}
+{{.ModuleType}} {
+ name: "{{.BpName}}",
+ {{- if .IsDeviceModule}}
+ sdk_version: "{{.SdkVersion}}",
+ {{- if .IsAar}}
min_sdk_version: "{{.MinSdkVersion}}",
- manifest: "manifests/{{.BpName}}/AndroidManifest.xml",{{end}}{{end}}
+ manifest: "manifests/{{.BpName}}/AndroidManifest.xml",
+ {{- end}}
+ {{- end}}
static_libs: [
- "{{.BpName}}-nodeps",{{range .BpJarDeps}}
- "{{.}}",{{end}}{{range .BpAarDeps}}
- "{{.}}",{{end}}{{range .BpExtraDeps}}
- "{{.}}",{{end}}
+ "{{.BpName}}-nodeps",
+ {{- range .BpJarDeps}}
+ "{{.}}",
+ {{- end}}
+ {{- range .BpAarDeps}}
+ "{{.}}",
+ {{- end}}
+ {{- range .BpExtraDeps}}
+ "{{.}}",
+ {{- end}}
],
java_version: "1.7",
}