blob: b3471556a1551cf0cd23b79351a8004148df88ea [file] [log] [blame]
Dan Willemsen2902fa72017-04-27 21:16:35 -07001// Copyright 2017 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package main
16
17import (
Colin Cross9f5633d2018-04-19 16:52:21 -070018 "bufio"
19 "bytes"
Dan Willemsen2902fa72017-04-27 21:16:35 -070020 "encoding/xml"
21 "flag"
22 "fmt"
Dan Willemsen2902fa72017-04-27 21:16:35 -070023 "io/ioutil"
24 "os"
Colin Cross9f5633d2018-04-19 16:52:21 -070025 "os/exec"
Dan Willemsen2902fa72017-04-27 21:16:35 -070026 "path/filepath"
27 "regexp"
28 "sort"
29 "strings"
30 "text/template"
31
32 "github.com/google/blueprint/proptools"
33)
34
35type RewriteNames []RewriteName
36type RewriteName struct {
37 regexp *regexp.Regexp
38 repl string
39}
40
41func (r *RewriteNames) String() string {
42 return ""
43}
44
45func (r *RewriteNames) Set(v string) error {
46 split := strings.SplitN(v, "=", 2)
47 if len(split) != 2 {
48 return fmt.Errorf("Must be in the form of <regex>=<replace>")
49 }
50 regex, err := regexp.Compile(split[0])
51 if err != nil {
52 return nil
53 }
54 *r = append(*r, RewriteName{
55 regexp: regex,
56 repl: split[1],
57 })
58 return nil
59}
60
Alan Viverette75b95f82017-12-04 16:24:07 -050061func (r *RewriteNames) MavenToMk(groupId string, artifactId string) string {
Dan Willemsen2902fa72017-04-27 21:16:35 -070062 for _, r := range *r {
Alan Viverette75b95f82017-12-04 16:24:07 -050063 if r.regexp.MatchString(groupId + ":" + artifactId) {
64 return r.regexp.ReplaceAllString(groupId+":"+artifactId, r.repl)
65 } else if r.regexp.MatchString(artifactId) {
66 return r.regexp.ReplaceAllString(artifactId, r.repl)
Dan Willemsen2902fa72017-04-27 21:16:35 -070067 }
68 }
Alan Viverette75b95f82017-12-04 16:24:07 -050069 return artifactId
Dan Willemsen2902fa72017-04-27 21:16:35 -070070}
71
72var rewriteNames = RewriteNames{}
73
74type ExtraDeps map[string][]string
75
76func (d ExtraDeps) String() string {
77 return ""
78}
79
80func (d ExtraDeps) Set(v string) error {
81 split := strings.SplitN(v, "=", 2)
82 if len(split) != 2 {
83 return fmt.Errorf("Must be in the form of <module>=<module>[,<module>]")
84 }
85 d[split[0]] = strings.Split(split[1], ",")
86 return nil
87}
88
89var extraDeps = make(ExtraDeps)
90
Colin Cross6b382bc2018-04-19 22:44:16 -070091type Exclude map[string]bool
92
93func (e Exclude) String() string {
94 return ""
95}
96
97func (e Exclude) Set(v string) error {
98 e[v] = true
99 return nil
100}
101
102var excludes = make(Exclude)
103
Dan Willemsen15a8e792017-11-10 14:02:44 -0800104var sdkVersion string
Dan Willemsen47e44a42017-10-05 13:28:16 -0700105var useVersion string
Alan Viverette1593d3d2017-12-11 17:14:26 -0500106var staticDeps bool
Dan Willemsen7fdab6e2019-04-20 21:47:14 -0700107var jetifier bool
Dan Willemsen47e44a42017-10-05 13:28:16 -0700108
Jeff Gaston8f084822018-03-29 14:58:50 -0400109func InList(s string, list []string) bool {
110 for _, l := range list {
111 if l == s {
112 return true
113 }
114 }
115
116 return false
117}
118
Dan Willemsen2902fa72017-04-27 21:16:35 -0700119type Dependency struct {
120 XMLName xml.Name `xml:"dependency"`
121
Alan Viverette1593d3d2017-12-11 17:14:26 -0500122 MakeTarget string `xml:"-"`
123
Dan Willemsen2902fa72017-04-27 21:16:35 -0700124 GroupId string `xml:"groupId"`
125 ArtifactId string `xml:"artifactId"`
126 Version string `xml:"version"`
127 Type string `xml:"type"`
Alan Viverette6bd35eb2018-02-13 13:25:24 -0500128 Scope string `xml:"scope"`
Dan Willemsen2902fa72017-04-27 21:16:35 -0700129}
130
Alan Viverette1593d3d2017-12-11 17:14:26 -0500131func (d Dependency) MkName() string {
132 if d.MakeTarget == "" {
133 d.MakeTarget = rewriteNames.MavenToMk(d.GroupId, d.ArtifactId)
134 }
135 return d.MakeTarget
136}
137
Dan Willemsen2902fa72017-04-27 21:16:35 -0700138type Pom struct {
139 XMLName xml.Name `xml:"http://maven.apache.org/POM/4.0.0 project"`
140
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700141 PomFile string `xml:"-"`
Dan Willemsen2902fa72017-04-27 21:16:35 -0700142 ArtifactFile string `xml:"-"`
Alan Viverette75b95f82017-12-04 16:24:07 -0500143 MakeTarget string `xml:"-"`
Dan Willemsen2902fa72017-04-27 21:16:35 -0700144
145 GroupId string `xml:"groupId"`
146 ArtifactId string `xml:"artifactId"`
147 Version string `xml:"version"`
148 Packaging string `xml:"packaging"`
149
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700150 Dependencies []*Dependency `xml:"dependencies>dependency"`
Dan Willemsen2902fa72017-04-27 21:16:35 -0700151}
152
Alan Viverette1593d3d2017-12-11 17:14:26 -0500153func (p Pom) IsAar() bool {
154 return p.Packaging == "aar"
155}
156
157func (p Pom) IsJar() bool {
158 return p.Packaging == "jar"
159}
160
Dan Willemsen2902fa72017-04-27 21:16:35 -0700161func (p Pom) MkName() string {
Alan Viverette75b95f82017-12-04 16:24:07 -0500162 if p.MakeTarget == "" {
163 p.MakeTarget = rewriteNames.MavenToMk(p.GroupId, p.ArtifactId)
164 }
165 return p.MakeTarget
Dan Willemsen2902fa72017-04-27 21:16:35 -0700166}
167
Alan Viverette1593d3d2017-12-11 17:14:26 -0500168func (p Pom) MkJarDeps() []string {
Jeff Gaston8f084822018-03-29 14:58:50 -0400169 return p.MkDeps("jar", []string{"compile", "runtime"})
Alan Viverette1593d3d2017-12-11 17:14:26 -0500170}
171
172func (p Pom) MkAarDeps() []string {
Jeff Gaston8f084822018-03-29 14:58:50 -0400173 return p.MkDeps("aar", []string{"compile", "runtime"})
Alan Viverette1593d3d2017-12-11 17:14:26 -0500174}
175
Alan Viverette6bd35eb2018-02-13 13:25:24 -0500176// MkDeps obtains dependencies filtered by type and scope. The results of this
177// method are formatted as Make targets, e.g. run through MavenToMk rules.
Jeff Gaston8f084822018-03-29 14:58:50 -0400178func (p Pom) MkDeps(typeExt string, scopes []string) []string {
Dan Willemsen2902fa72017-04-27 21:16:35 -0700179 var ret []string
Jeff Gaston358f25e2018-04-23 15:32:19 -0400180 if typeExt == "jar" {
181 // all top-level extra deps are assumed to be of type "jar" until we add syntax to specify other types
182 ret = append(ret, extraDeps[p.MkName()]...)
183 }
Dan Willemsen2902fa72017-04-27 21:16:35 -0700184 for _, d := range p.Dependencies {
Jeff Gaston8f084822018-03-29 14:58:50 -0400185 if d.Type != typeExt || !InList(d.Scope, scopes) {
Dan Willemsen2902fa72017-04-27 21:16:35 -0700186 continue
187 }
Alan Viverette75b95f82017-12-04 16:24:07 -0500188 name := rewriteNames.MavenToMk(d.GroupId, d.ArtifactId)
Dan Willemsen2902fa72017-04-27 21:16:35 -0700189 ret = append(ret, name)
190 ret = append(ret, extraDeps[name]...)
191 }
192 return ret
193}
194
Dan Willemsen15a8e792017-11-10 14:02:44 -0800195func (p Pom) SdkVersion() string {
196 return sdkVersion
197}
198
Dan Willemsen7fdab6e2019-04-20 21:47:14 -0700199func (p Pom) Jetifier() bool {
200 return jetifier
201}
202
Alan Viverette6bd35eb2018-02-13 13:25:24 -0500203func (p *Pom) FixDeps(modules map[string]*Pom) {
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700204 for _, d := range p.Dependencies {
Alan Viverette6bd35eb2018-02-13 13:25:24 -0500205 if d.Type == "" {
206 if depPom, ok := modules[d.MkName()]; ok {
207 // We've seen the POM for this dependency, use its packaging
208 // as the dependency type rather than Maven spec default.
209 d.Type = depPom.Packaging
210 } else {
211 // Dependency type was not specified and we don't have the POM
212 // for this artifact, use the default from Maven spec.
213 d.Type = "jar"
214 }
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700215 }
Alan Viverette6bd35eb2018-02-13 13:25:24 -0500216 if d.Scope == "" {
217 // Scope was not specified, use the default from Maven spec.
218 d.Scope = "compile"
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700219 }
220 }
221}
222
Dan Willemsen2902fa72017-04-27 21:16:35 -0700223var mkTemplate = template.Must(template.New("mk").Parse(`
224include $(CLEAR_VARS)
225LOCAL_MODULE := {{.MkName}}
226LOCAL_MODULE_CLASS := JAVA_LIBRARIES
227LOCAL_UNINSTALLABLE_MODULE := true
228LOCAL_SRC_FILES := {{.ArtifactFile}}
229LOCAL_BUILT_MODULE_STEM := javalib.jar
230LOCAL_MODULE_SUFFIX := .{{.Packaging}}
231LOCAL_USE_AAPT2 := true
Dan Willemsen15a8e792017-11-10 14:02:44 -0800232LOCAL_SDK_VERSION := {{.SdkVersion}}
Alan Viverette2b53a0c2018-03-28 10:32:10 -0400233LOCAL_STATIC_JAVA_LIBRARIES :={{range .MkJarDeps}} \
234 {{.}}{{end}}
235LOCAL_STATIC_ANDROID_LIBRARIES :={{range .MkAarDeps}} \
236 {{.}}{{end}}
Dan Willemsen7fdab6e2019-04-20 21:47:14 -0700237LOCAL_JETIFIER_ENABLED := {{if .Jetifier}}true{{end}}
Dan Willemsen2902fa72017-04-27 21:16:35 -0700238include $(BUILD_PREBUILT)
239`))
240
Alan Viverette1593d3d2017-12-11 17:14:26 -0500241var mkDepsTemplate = template.Must(template.New("mk").Parse(`
242include $(CLEAR_VARS)
243LOCAL_MODULE := {{.MkName}}-nodeps
244LOCAL_MODULE_CLASS := JAVA_LIBRARIES
245LOCAL_UNINSTALLABLE_MODULE := true
246LOCAL_SRC_FILES := {{.ArtifactFile}}
247LOCAL_BUILT_MODULE_STEM := javalib.jar
248LOCAL_MODULE_SUFFIX := .{{.Packaging}}
249LOCAL_USE_AAPT2 := true
250LOCAL_SDK_VERSION := {{.SdkVersion}}
251LOCAL_STATIC_ANDROID_LIBRARIES :={{range .MkAarDeps}} \
252 {{.}}{{end}}
253include $(BUILD_PREBUILT)
254include $(CLEAR_VARS)
255LOCAL_MODULE := {{.MkName}}
256LOCAL_SDK_VERSION := {{.SdkVersion}}{{if .IsAar}}
257LOCAL_MANIFEST_FILE := manifests/{{.MkName}}/AndroidManifest.xml{{end}}
258LOCAL_STATIC_JAVA_LIBRARIES :={{if .IsJar}} \
259 {{.MkName}}-nodeps{{end}}{{range .MkJarDeps}} \
260 {{.}}{{end}}
261LOCAL_STATIC_ANDROID_LIBRARIES :={{if .IsAar}} \
262 {{.MkName}}-nodeps{{end}}{{range .MkAarDeps}} \
263 {{.}}{{end}}
264LOCAL_JAR_EXCLUDE_FILES := none
265LOCAL_JAVA_LANGUAGE_VERSION := 1.7
266LOCAL_USE_AAPT2 := true
267include $(BUILD_STATIC_JAVA_LIBRARY)
268`))
269
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700270func parse(filename string) (*Pom, error) {
Dan Willemsen2902fa72017-04-27 21:16:35 -0700271 data, err := ioutil.ReadFile(filename)
272 if err != nil {
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700273 return nil, err
Dan Willemsen2902fa72017-04-27 21:16:35 -0700274 }
275
276 var pom Pom
277 err = xml.Unmarshal(data, &pom)
278 if err != nil {
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700279 return nil, err
Dan Willemsen2902fa72017-04-27 21:16:35 -0700280 }
281
Dan Willemsen47e44a42017-10-05 13:28:16 -0700282 if useVersion != "" && pom.Version != useVersion {
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700283 return nil, nil
Dan Willemsen47e44a42017-10-05 13:28:16 -0700284 }
285
Dan Willemsen2902fa72017-04-27 21:16:35 -0700286 if pom.Packaging == "" {
287 pom.Packaging = "jar"
288 }
289
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700290 pom.PomFile = filename
Dan Willemsen2902fa72017-04-27 21:16:35 -0700291 pom.ArtifactFile = strings.TrimSuffix(filename, ".pom") + "." + pom.Packaging
292
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700293 return &pom, nil
Dan Willemsen2902fa72017-04-27 21:16:35 -0700294}
295
Colin Cross9f5633d2018-04-19 16:52:21 -0700296func rerunForRegen(filename string) error {
297 buf, err := ioutil.ReadFile(filename)
298 if err != nil {
299 return err
300 }
301
302 scanner := bufio.NewScanner(bytes.NewBuffer(buf))
303
304 // Skip the first line in the file
305 for i := 0; i < 2; i++ {
306 if !scanner.Scan() {
307 if scanner.Err() != nil {
308 return scanner.Err()
309 } else {
310 return fmt.Errorf("unexpected EOF")
311 }
312 }
313 }
314
315 // Extract the old args from the file
316 line := scanner.Text()
317 if strings.HasPrefix(line, "# pom2mk ") {
318 line = strings.TrimPrefix(line, "# pom2mk ")
319 } else {
320 return fmt.Errorf("unexpected second line: %q", line)
321 }
322 args := strings.Split(line, " ")
323 lastArg := args[len(args)-1]
324 args = args[:len(args)-1]
325
326 // Append all current command line args except -regen <file> to the ones from the file
327 for i := 1; i < len(os.Args); i++ {
328 if os.Args[i] == "-regen" {
329 i++
330 } else {
331 args = append(args, os.Args[i])
332 }
333 }
334 args = append(args, lastArg)
335
336 cmd := os.Args[0] + " " + strings.Join(args, " ")
337 // Re-exec pom2mk with the new arguments
338 output, err := exec.Command("/bin/sh", "-c", cmd).Output()
339 if exitErr, _ := err.(*exec.ExitError); exitErr != nil {
340 return fmt.Errorf("failed to run %s\n%s", cmd, string(exitErr.Stderr))
341 } else if err != nil {
342 return err
343 }
344
345 return ioutil.WriteFile(filename, output, 0666)
346}
347
Dan Willemsen2902fa72017-04-27 21:16:35 -0700348func main() {
349 flag.Usage = func() {
350 fmt.Fprintf(os.Stderr, `pom2mk, a tool to create Android.mk files from maven repos
351
352The tool will extract the necessary information from *.pom files to create an Android.mk whose
353aar libraries can be linked against when using AAPT2.
354
Colin Cross6b382bc2018-04-19 22:44:16 -0700355Usage: %s [--rewrite <regex>=<replace>] [-exclude <module>] [--extra-deps <module>=<module>[,<module>]] [<dir>] [-regen <file>]
Dan Willemsen2902fa72017-04-27 21:16:35 -0700356
357 -rewrite <regex>=<replace>
Alan Viverette75b95f82017-12-04 16:24:07 -0500358 rewrite can be used to specify mappings between Maven projects and Make modules. The -rewrite
359 option can be specified multiple times. When determining the Make module for a given Maven
360 project, mappings are searched in the order they were specified. The first <regex> matching
361 either the Maven project's <groupId>:<artifactId> or <artifactId> will be used to generate
362 the Make module name using <replace>. If no matches are found, <artifactId> is used.
Colin Cross6b382bc2018-04-19 22:44:16 -0700363 -exclude <module>
364 Don't put the specified module in the makefile.
Dan Willemsen2902fa72017-04-27 21:16:35 -0700365 -extra-deps <module>=<module>[,<module>]
366 Some Android.mk modules have transitive dependencies that must be specified when they are
367 depended upon (like android-support-v7-mediarouter requires android-support-v7-appcompat).
368 This may be specified multiple times to declare these dependencies.
Dan Willemsen15a8e792017-11-10 14:02:44 -0800369 -sdk-version <version>
370 Sets LOCAL_SDK_VERSION := <version> for all modules.
Dan Willemsen47e44a42017-10-05 13:28:16 -0700371 -use-version <version>
372 If the maven directory contains multiple versions of artifacts and their pom files,
373 -use-version can be used to only write makefiles for a specific version of those artifacts.
Alan Viverette1593d3d2017-12-11 17:14:26 -0500374 -static-deps
375 Whether to statically include direct dependencies.
Dan Willemsen7fdab6e2019-04-20 21:47:14 -0700376 -jetifier
377 Enable jetifier in order to use androidx
Dan Willemsen2902fa72017-04-27 21:16:35 -0700378 <dir>
379 The directory to search for *.pom files under.
Colin Cross9f5633d2018-04-19 16:52:21 -0700380 The makefile is written to stdout, to be put in the current directory (often as Android.mk)
381 -regen <file>
382 Read arguments from <file> and overwrite it.
Dan Willemsen2902fa72017-04-27 21:16:35 -0700383`, os.Args[0])
384 }
385
Colin Cross9f5633d2018-04-19 16:52:21 -0700386 var regen string
387
Colin Cross6b382bc2018-04-19 22:44:16 -0700388 flag.Var(&excludes, "exclude", "Exclude module")
Dan Willemsen2902fa72017-04-27 21:16:35 -0700389 flag.Var(&extraDeps, "extra-deps", "Extra dependencies needed when depending on a module")
390 flag.Var(&rewriteNames, "rewrite", "Regex(es) to rewrite artifact names")
Dan Willemsen15a8e792017-11-10 14:02:44 -0800391 flag.StringVar(&sdkVersion, "sdk-version", "", "What to write to LOCAL_SDK_VERSION")
Dan Willemsen47e44a42017-10-05 13:28:16 -0700392 flag.StringVar(&useVersion, "use-version", "", "Only read artifacts of a specific version")
Alan Viverette1593d3d2017-12-11 17:14:26 -0500393 flag.BoolVar(&staticDeps, "static-deps", false, "Statically include direct dependencies")
Dan Willemsen7fdab6e2019-04-20 21:47:14 -0700394 flag.BoolVar(&jetifier, "jetifier", false, "Enable jetifier in order to use androidx")
Colin Cross9f5633d2018-04-19 16:52:21 -0700395 flag.StringVar(&regen, "regen", "", "Rewrite specified file")
Dan Willemsen2902fa72017-04-27 21:16:35 -0700396 flag.Parse()
397
Colin Cross9f5633d2018-04-19 16:52:21 -0700398 if regen != "" {
399 err := rerunForRegen(regen)
400 if err != nil {
401 fmt.Fprintln(os.Stderr, err)
402 os.Exit(1)
403 }
404 os.Exit(0)
405 }
406
407 if flag.NArg() == 0 {
408 fmt.Fprintln(os.Stderr, "Directory argument is required")
409 os.Exit(1)
410 } else if flag.NArg() > 1 {
411 fmt.Fprintln(os.Stderr, "Multiple directories provided:", strings.Join(flag.Args(), " "))
Dan Willemsen2902fa72017-04-27 21:16:35 -0700412 os.Exit(1)
413 }
414
415 dir := flag.Arg(0)
416 absDir, err := filepath.Abs(dir)
417 if err != nil {
Colin Crossf46e37f2018-03-21 16:25:58 -0700418 fmt.Fprintln(os.Stderr, "Failed to get absolute directory:", err)
Dan Willemsen2902fa72017-04-27 21:16:35 -0700419 os.Exit(1)
420 }
421
422 var filenames []string
423 err = filepath.Walk(absDir, func(path string, info os.FileInfo, err error) error {
424 if err != nil {
425 return err
426 }
427
428 name := info.Name()
429 if info.IsDir() {
430 if strings.HasPrefix(name, ".") {
431 return filepath.SkipDir
432 }
433 return nil
434 }
435
436 if strings.HasPrefix(name, ".") {
437 return nil
438 }
439
440 if strings.HasSuffix(name, ".pom") {
441 path, err = filepath.Rel(absDir, path)
442 if err != nil {
443 return err
444 }
445 filenames = append(filenames, filepath.Join(dir, path))
446 }
447 return nil
448 })
449 if err != nil {
450 fmt.Fprintln(os.Stderr, "Error walking files:", err)
451 os.Exit(1)
452 }
453
454 if len(filenames) == 0 {
455 fmt.Fprintln(os.Stderr, "Error: no *.pom files found under", dir)
456 os.Exit(1)
457 }
458
459 sort.Strings(filenames)
460
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700461 poms := []*Pom{}
462 modules := make(map[string]*Pom)
Jeff Gastonaf2191e2018-03-29 14:59:01 -0400463 duplicate := false
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700464 for _, filename := range filenames {
465 pom, err := parse(filename)
466 if err != nil {
467 fmt.Fprintln(os.Stderr, "Error converting", filename, err)
468 os.Exit(1)
469 }
470
471 if pom != nil {
Alan Viverette75b95f82017-12-04 16:24:07 -0500472 key := pom.MkName()
Colin Cross6b382bc2018-04-19 22:44:16 -0700473 if excludes[key] {
474 continue
475 }
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700476
Alan Viverette75b95f82017-12-04 16:24:07 -0500477 if old, ok := modules[key]; ok {
478 fmt.Fprintln(os.Stderr, "Module", key, "defined twice:", old.PomFile, pom.PomFile)
Jeff Gastonaf2191e2018-03-29 14:59:01 -0400479 duplicate = true
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700480 }
481
Colin Cross6b382bc2018-04-19 22:44:16 -0700482 poms = append(poms, pom)
Alan Viverette75b95f82017-12-04 16:24:07 -0500483 modules[key] = pom
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700484 }
485 }
Jeff Gastonaf2191e2018-03-29 14:59:01 -0400486 if duplicate {
487 os.Exit(1)
488 }
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700489
490 for _, pom := range poms {
Alan Viverette6bd35eb2018-02-13 13:25:24 -0500491 pom.FixDeps(modules)
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700492 }
493
Dan Willemsen2902fa72017-04-27 21:16:35 -0700494 fmt.Println("# Automatically generated with:")
Colin Cross0b9f31f2019-02-28 11:00:01 -0800495 fmt.Println("# pom2mk", strings.Join(proptools.ShellEscapeList(os.Args[1:]), " "))
Dan Willemsen2902fa72017-04-27 21:16:35 -0700496 fmt.Println("LOCAL_PATH := $(call my-dir)")
497
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700498 for _, pom := range poms {
Alan Viverette1593d3d2017-12-11 17:14:26 -0500499 var err error
500 if staticDeps {
501 err = mkDepsTemplate.Execute(os.Stdout, pom)
502 } else {
503 err = mkTemplate.Execute(os.Stdout, pom)
504 }
Dan Willemsen2902fa72017-04-27 21:16:35 -0700505 if err != nil {
Dan Willemsen5f9d8a62017-10-05 14:01:31 -0700506 fmt.Fprintln(os.Stderr, "Error writing", pom.PomFile, pom.MkName(), err)
Dan Willemsen2902fa72017-04-27 21:16:35 -0700507 os.Exit(1)
508 }
509 }
510}