Update pom2mk to allow duplicate module names if rewritten

Fixes: 70162730
Test: ./update_current.py -s -t 4482279
Change-Id: I874d7bfb50fd2d2bc488f5458cfe57b2e0d4d4e5
This commit is contained in:
Alan Viverette 2017-12-04 16:24:07 -05:00
parent 73c2099534
commit 75b95f8a61

View file

@ -55,13 +55,15 @@ func (r *RewriteNames) Set(v string) error {
return nil return nil
} }
func (r *RewriteNames) Rewrite(name string) string { func (r *RewriteNames) MavenToMk(groupId string, artifactId string) string {
for _, r := range *r { for _, r := range *r {
if r.regexp.MatchString(name) { if r.regexp.MatchString(groupId + ":" + artifactId) {
return r.regexp.ReplaceAllString(name, r.repl) return r.regexp.ReplaceAllString(groupId+":"+artifactId, r.repl)
} else if r.regexp.MatchString(artifactId) {
return r.regexp.ReplaceAllString(artifactId, r.repl)
} }
} }
return name return artifactId
} }
var rewriteNames = RewriteNames{} var rewriteNames = RewriteNames{}
@ -102,6 +104,7 @@ type Pom struct {
PomFile string `xml:"-"` PomFile string `xml:"-"`
ArtifactFile string `xml:"-"` ArtifactFile string `xml:"-"`
MakeTarget string `xml:"-"`
GroupId string `xml:"groupId"` GroupId string `xml:"groupId"`
ArtifactId string `xml:"artifactId"` ArtifactId string `xml:"artifactId"`
@ -112,7 +115,10 @@ type Pom struct {
} }
func (p Pom) MkName() string { func (p Pom) MkName() string {
return rewriteNames.Rewrite(p.ArtifactId) if p.MakeTarget == "" {
p.MakeTarget = rewriteNames.MavenToMk(p.GroupId, p.ArtifactId)
}
return p.MakeTarget
} }
func (p Pom) MkDeps() []string { func (p Pom) MkDeps() []string {
@ -121,7 +127,7 @@ func (p Pom) MkDeps() []string {
if d.Type != "aar" { if d.Type != "aar" {
continue continue
} }
name := rewriteNames.Rewrite(d.ArtifactId) name := rewriteNames.MavenToMk(d.GroupId, d.ArtifactId)
ret = append(ret, name) ret = append(ret, name)
ret = append(ret, extraDeps[name]...) ret = append(ret, extraDeps[name]...)
} }
@ -137,7 +143,7 @@ func (p *Pom) FixDepTypes(modules map[string]*Pom) {
if d.Type != "" { if d.Type != "" {
continue continue
} }
if depPom, ok := modules[d.ArtifactId]; ok { if depPom, ok := modules[p.MkName()]; ok {
d.Type = depPom.Packaging d.Type = depPom.Packaging
} }
} }
@ -195,9 +201,11 @@ aar libraries can be linked against when using AAPT2.
Usage: %s [--rewrite <regex>=<replace>] [--extra-deps <module>=<module>[,<module>]] <dir> Usage: %s [--rewrite <regex>=<replace>] [--extra-deps <module>=<module>[,<module>]] <dir>
-rewrite <regex>=<replace> -rewrite <regex>=<replace>
rewrite can be used to specify mappings between the artifactId in the pom files and module rewrite can be used to specify mappings between Maven projects and Make modules. The -rewrite
names in the Android.mk files. This can be specified multiple times, the first matching option can be specified multiple times. When determining the Make module for a given Maven
regex will be used. project, mappings are searched in the order they were specified. The first <regex> matching
either the Maven project's <groupId>:<artifactId> or <artifactId> will be used to generate
the Make module name using <replace>. If no matches are found, <artifactId> is used.
-extra-deps <module>=<module>[,<module>] -extra-deps <module>=<module>[,<module>]
Some Android.mk modules have transitive dependencies that must be specified when they are Some Android.mk modules have transitive dependencies that must be specified when they are
depended upon (like android-support-v7-mediarouter requires android-support-v7-appcompat). depended upon (like android-support-v7-mediarouter requires android-support-v7-appcompat).
@ -282,13 +290,14 @@ The makefile is written to stdout, to be put in the current directory (often as
if pom != nil { if pom != nil {
poms = append(poms, pom) poms = append(poms, pom)
key := pom.MkName()
if old, ok := modules[pom.ArtifactId]; ok { if old, ok := modules[key]; ok {
fmt.Fprintln(os.Stderr, "Module", pom.ArtifactId, "defined twice:", old.PomFile, pom.PomFile) fmt.Fprintln(os.Stderr, "Module", key, "defined twice:", old.PomFile, pom.PomFile)
os.Exit(1) os.Exit(1)
} }
modules[pom.ArtifactId] = pom modules[key] = pom
} }
} }