aboutsummaryrefslogtreecommitdiffstats
path: root/bpfix
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2018-02-21 16:40:06 -0800
committerColin Cross <ccross@android.com>2018-02-22 14:54:47 -0800
commit336ad7a6676515ec1f2a432ca176af62ff180155 (patch)
tree8e088ff39cb337c37bcd82ce6f6c8457622871ee /bpfix
parent3fad895e756e9483fd3eee210d14a43f936703dd (diff)
downloadbuild_soong-336ad7a6676515ec1f2a432ca176af62ff180155.tar.gz
build_soong-336ad7a6676515ec1f2a432ca176af62ff180155.tar.bz2
build_soong-336ad7a6676515ec1f2a432ca176af62ff180155.zip
Fix java_import and android_library_import conversions
java_import and android_library_import modules can't be handled directly in androidmk because the results may depend on properties that haven't been parsed yet. Add a bpfix pass (which is automatically included at the end of androidmk) to select android_library_import vs. java_import based on the extension of the prebuilt file, and convert the srcs property to jars or aars as appropriate. Bug: 73724997 Test: androidmk_test.go Change-Id: I1024742e9e96d5e1e88c3cc139eeb0d5a2f6849b
Diffstat (limited to 'bpfix')
-rw-r--r--bpfix/bpfix/bpfix.go51
1 files changed, 50 insertions, 1 deletions
diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go
index 67a59099..2358f0cf 100644
--- a/bpfix/bpfix/bpfix.go
+++ b/bpfix/bpfix/bpfix.go
@@ -19,6 +19,7 @@ package bpfix
import (
"bytes"
"fmt"
+ "path/filepath"
"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 doesn't specify whether to do a dry run or where to write the results; that's in cmd/bpfix.go
type FixRequest struct {
- simplifyKnownRedundantVariables bool
+ simplifyKnownRedundantVariables bool
+ rewriteIncorrectAndroidmkPrebuilts bool
}
func NewFixRequest() FixRequest {
@@ -36,6 +38,7 @@ func NewFixRequest() FixRequest {
func (r FixRequest) AddAll() (result FixRequest) {
result = r
result.simplifyKnownRedundantVariables = true
+ result.rewriteIncorrectAndroidmkPrebuilts = true
return result
}
@@ -87,6 +90,12 @@ func fixTreeOnce(tree *parser.File, config FixRequest) error {
return err
}
}
+ if config.rewriteIncorrectAndroidmkPrebuilts {
+ err := rewriteIncorrectAndroidmkPrebuilts(tree)
+ if err != nil {
+ return err
+ }
+ }
return nil
}
@@ -95,6 +104,38 @@ func simplifyKnownPropertiesDuplicatingEachOther(tree *parser.File) error {
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>
func filterExpressionList(items *parser.List, removals *parser.List) {
writeIndex := 0
@@ -146,3 +187,11 @@ func getLiteralListProperty(mod *parser.Module, name string) (list *parser.List,
list, ok = prop.Value.(*parser.List)
return list, ok
}
+
+func renameProperty(mod *parser.Module, from, to string) {
+ for _, prop := range mod.Properties {
+ if prop.Name == from {
+ prop.Name = to
+ }
+ }
+}