diff options
Diffstat (limited to 'cmd/pom2bp/pom2bp.go')
-rw-r--r-- | cmd/pom2bp/pom2bp.go | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/cmd/pom2bp/pom2bp.go b/cmd/pom2bp/pom2bp.go index f8844fc94..ba0648d19 100644 --- a/cmd/pom2bp/pom2bp.go +++ b/cmd/pom2bp/pom2bp.go @@ -150,6 +150,7 @@ var sdkVersion string var defaultMinSdkVersion string var useVersion string var staticDeps bool +var writeCmd bool var jetifier bool func InList(s string, list []string) bool { @@ -206,6 +207,10 @@ func (p Pom) IsJar() bool { return p.Packaging == "jar" } +func (p Pom) IsApk() bool { + return p.Packaging == "apk" +} + func (p Pom) IsHostModule() bool { return hostModuleNames.IsHostModule(p.GroupId, p.ArtifactId) } @@ -243,6 +248,8 @@ func (p Pom) BazelTargetType() string { func (p Pom) ImportModuleType() string { if p.IsAar() { return "android_library_import" + } else if p.IsApk() { + return "android_app_import" } else if p.IsHostOnly() { return "java_import_host" } else { @@ -253,6 +260,8 @@ func (p Pom) ImportModuleType() string { func (p Pom) BazelImportTargetType() string { if p.IsAar() { return "aar_import" + } else if p.IsApk() { + return "apk_import" } else { return "java_import" } @@ -261,6 +270,8 @@ func (p Pom) BazelImportTargetType() string { func (p Pom) ImportProperty() string { if p.IsAar() { return "aars" + } else if p.IsApk() { + return "apk" } else { return "jars" } @@ -269,6 +280,8 @@ func (p Pom) ImportProperty() string { func (p Pom) BazelImportProperty() string { if p.IsAar() { return "aar" + } else if p.IsApk() { + return "apk" } else { return "jars" } @@ -492,8 +505,12 @@ func (p *Pom) ExtractMinSdkVersion() error { var bpTemplate = template.Must(template.New("bp").Parse(` {{.ImportModuleType}} { name: "{{.BpName}}", + {{- if .IsApk}} + {{.ImportProperty}}: "{{.ArtifactFile}}", + {{- else}} {{.ImportProperty}}: ["{{.ArtifactFile}}"], sdk_version: "{{.SdkVersion}}", + {{- end}} {{- if .Jetifier}} jetifier: true, {{- end}} @@ -534,8 +551,14 @@ var bpTemplate = template.Must(template.New("bp").Parse(` ], {{- end}} {{- else if not .IsHostOnly}} + {{- if not .IsApk}} min_sdk_version: "{{.DefaultMinSdkVersion}}", {{- end}} + {{- end}} + {{- if .IsApk}} + presigned: true + {{- end}} + } `)) @@ -810,6 +833,9 @@ Usage: %s [--rewrite <regex>=<replace>] [--exclude <module>] [--extra-static-lib -use-version <version> If the maven directory contains multiple versions of artifacts and their pom files, -use-version can be used to only write Android.bp files for a specific version of those artifacts. + -write-cmd + Whether to write the command line arguments used to generate the build file as a comment at + the top of the build file itself. -jetifier Sets jetifier: true for all modules. <dir> @@ -824,6 +850,7 @@ Usage: %s [--rewrite <regex>=<replace>] [--exclude <module>] [--extra-static-lib var regen string var pom2build bool + var prepend string flag.Var(&excludes, "exclude", "Exclude module") flag.Var(&extraStaticLibs, "extra-static-libs", "Extra static dependencies needed when depending on a module") @@ -836,9 +863,11 @@ Usage: %s [--rewrite <regex>=<replace>] [--exclude <module>] [--extra-static-lib flag.StringVar(&defaultMinSdkVersion, "default-min-sdk-version", "24", "Default min_sdk_version to use, if one is not available from AndroidManifest.xml. Default: 24") flag.StringVar(&useVersion, "use-version", "", "Only read artifacts of a specific version") flag.BoolVar(&staticDeps, "static-deps", false, "Statically include direct dependencies") + flag.BoolVar(&writeCmd, "write-cmd", true, "Write command line arguments as a comment") flag.BoolVar(&jetifier, "jetifier", false, "Sets jetifier: true on all modules") flag.StringVar(®en, "regen", "", "Rewrite specified file") flag.BoolVar(&pom2build, "pom2build", false, "If true, will generate a Bazel BUILD file *instead* of a .bp file") + flag.StringVar(&prepend, "prepend", "", "Path to a file containing text to insert at the beginning of the generated build file") flag.Parse() if regen != "" { @@ -962,8 +991,22 @@ Usage: %s [--rewrite <regex>=<replace>] [--exclude <module>] [--extra-static-lib if pom2build { commentString = "#" } - fmt.Fprintln(buf, commentString, "Automatically generated with:") - fmt.Fprintln(buf, commentString, "pom2bp", strings.Join(proptools.ShellEscapeList(os.Args[1:]), " ")) + + fmt.Fprintln(buf, commentString, "This is a generated file. Do not modify directly.") + + if writeCmd { + fmt.Fprintln(buf, commentString, "Automatically generated with:") + fmt.Fprintln(buf, commentString, "pom2bp", strings.Join(proptools.ShellEscapeList(os.Args[1:]), " ")) + } + + if prepend != "" { + contents, err := ioutil.ReadFile(prepend) + if err != nil { + fmt.Fprintln(os.Stderr, "Error reading", prepend, err) + os.Exit(1) + } + fmt.Fprintln(buf, string(contents)) + } depsTemplate := bpDepsTemplate template := bpTemplate @@ -974,7 +1017,7 @@ Usage: %s [--rewrite <regex>=<replace>] [--exclude <module>] [--extra-static-lib for _, pom := range poms { var err error - if staticDeps { + if staticDeps && !pom.IsApk() { err = depsTemplate.Execute(buf, pom) } else { err = template.Execute(buf, pom) |