Fix java_import and android_library_import conversions am: 336ad7a667
am: b4b91fa725
Change-Id: Ideeda0de950d7f153558b8691abacff8aa76c329
This commit is contained in:
commit
230c992943
2 changed files with 80 additions and 1 deletions
|
@ -492,6 +492,36 @@ include $(call all-makefiles-under,$(LOCAL_PATH))
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
desc: "java prebuilt",
|
||||||
|
in: `
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_SRC_FILES := test.jar
|
||||||
|
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
|
||||||
|
include $(BUILD_PREBUILT)
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
java_import {
|
||||||
|
jars: ["test.jar"],
|
||||||
|
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "aar prebuilt",
|
||||||
|
in: `
|
||||||
|
include $(CLEAR_VARS)
|
||||||
|
LOCAL_SRC_FILES := test.aar
|
||||||
|
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
|
||||||
|
include $(BUILD_PREBUILT)
|
||||||
|
`,
|
||||||
|
expected: `
|
||||||
|
android_library_import {
|
||||||
|
aars: ["test.aar"],
|
||||||
|
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func reformatBlueprint(input string) string {
|
func reformatBlueprint(input string) string {
|
||||||
|
|
|
@ -19,6 +19,7 @@ package bpfix
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/google/blueprint/parser"
|
"github.com/google/blueprint/parser"
|
||||||
)
|
)
|
||||||
|
@ -26,7 +27,8 @@ import (
|
||||||
// A FixRequest specifies the details of which fixes to apply to an individual file
|
// A FixRequest specifies the details of which fixes to apply to an individual file
|
||||||
// A FixRequest doesn't specify whether to do a dry run or where to write the results; that's in cmd/bpfix.go
|
// A FixRequest doesn't specify whether to do a dry run or where to write the results; that's in cmd/bpfix.go
|
||||||
type FixRequest struct {
|
type FixRequest struct {
|
||||||
simplifyKnownRedundantVariables bool
|
simplifyKnownRedundantVariables bool
|
||||||
|
rewriteIncorrectAndroidmkPrebuilts bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFixRequest() FixRequest {
|
func NewFixRequest() FixRequest {
|
||||||
|
@ -36,6 +38,7 @@ func NewFixRequest() FixRequest {
|
||||||
func (r FixRequest) AddAll() (result FixRequest) {
|
func (r FixRequest) AddAll() (result FixRequest) {
|
||||||
result = r
|
result = r
|
||||||
result.simplifyKnownRedundantVariables = true
|
result.simplifyKnownRedundantVariables = true
|
||||||
|
result.rewriteIncorrectAndroidmkPrebuilts = true
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +90,12 @@ func fixTreeOnce(tree *parser.File, config FixRequest) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if config.rewriteIncorrectAndroidmkPrebuilts {
|
||||||
|
err := rewriteIncorrectAndroidmkPrebuilts(tree)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,6 +104,38 @@ func simplifyKnownPropertiesDuplicatingEachOther(tree *parser.File) error {
|
||||||
return removeMatchingModuleListProperties(tree, "export_include_dirs", "local_include_dirs")
|
return removeMatchingModuleListProperties(tree, "export_include_dirs", "local_include_dirs")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func rewriteIncorrectAndroidmkPrebuilts(tree *parser.File) error {
|
||||||
|
for _, def := range tree.Defs {
|
||||||
|
mod, ok := def.(*parser.Module)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if mod.Type != "java_import" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
srcs, ok := getLiteralListProperty(mod, "srcs")
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(srcs.Values) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
src, ok := srcs.Values[0].(*parser.String)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch filepath.Ext(src.Value) {
|
||||||
|
case ".jar":
|
||||||
|
renameProperty(mod, "srcs", "jars")
|
||||||
|
case ".aar":
|
||||||
|
renameProperty(mod, "srcs", "aars")
|
||||||
|
mod.Type = "android_library_import"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// removes from <items> every item present in <removals>
|
// removes from <items> every item present in <removals>
|
||||||
func filterExpressionList(items *parser.List, removals *parser.List) {
|
func filterExpressionList(items *parser.List, removals *parser.List) {
|
||||||
writeIndex := 0
|
writeIndex := 0
|
||||||
|
@ -146,3 +187,11 @@ func getLiteralListProperty(mod *parser.Module, name string) (list *parser.List,
|
||||||
list, ok = prop.Value.(*parser.List)
|
list, ok = prop.Value.(*parser.List)
|
||||||
return list, ok
|
return list, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func renameProperty(mod *parser.Module, from, to string) {
|
||||||
|
for _, prop := range mod.Properties {
|
||||||
|
if prop.Name == from {
|
||||||
|
prop.Name = to
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue