diff options
author | Jaewoong Jung <jungjw@google.com> | 2019-05-23 20:55:57 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-05-23 20:55:57 +0000 |
commit | a725681ed8f56ac396420f04085a7150d0900cc6 (patch) | |
tree | 14ef1b6647f6d2dbad70381c2309b47d66a6aa8c /bpfix | |
parent | ace17d35fdb0a73172d78e1c5b57c7f6a8284ea6 (diff) | |
parent | e07b0b60e54c7a1ecdc36587a45919a618329c73 (diff) | |
download | build_soong-a725681ed8f56ac396420f04085a7150d0900cc6.tar.gz build_soong-a725681ed8f56ac396420f04085a7150d0900cc6.tar.bz2 build_soong-a725681ed8f56ac396420f04085a7150d0900cc6.zip |
Merge "androidmk conversion logic for android_app_import"
Diffstat (limited to 'bpfix')
-rw-r--r-- | bpfix/bpfix/bpfix.go | 83 | ||||
-rw-r--r-- | bpfix/bpfix/bpfix_test.go | 49 |
2 files changed, 111 insertions, 21 deletions
diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go index c8981965..17cff180 100644 --- a/bpfix/bpfix/bpfix.go +++ b/bpfix/bpfix/bpfix.go @@ -102,6 +102,10 @@ var fixSteps = []fixStep{ name: "rewriteAndroidTest", fix: rewriteAndroidTest, }, + { + name: "rewriteAndroidAppImport", + fix: rewriteAndroidAppImport, + }, } func NewFixRequest() FixRequest { @@ -525,27 +529,8 @@ func rewriteAndroidmkPrebuiltEtc(f *Fixer) error { continue } - // The rewriter converts LOCAL_SRC_FILES to `srcs` attribute. Convert - // it to 'src' attribute (which is where the file is installed). If the - // value 'srcs' is a list, we can convert it only if it contains a single - // element. - if srcs, ok := mod.GetProperty("srcs"); ok { - if srcList, ok := srcs.Value.(*parser.List); ok { - removeProperty(mod, "srcs") - if len(srcList.Values) == 1 { - mod.Properties = append(mod.Properties, - &parser.Property{Name: "src", NamePos: srcs.NamePos, ColonPos: srcs.ColonPos, Value: resolveLocalModule(mod, srcList.Values[0])}) - } else if len(srcList.Values) > 1 { - indicateAttributeError(mod, "src", "LOCAL_SRC_FILES should contain at most one item") - } - } else if _, ok = srcs.Value.(*parser.Variable); ok { - removeProperty(mod, "srcs") - mod.Properties = append(mod.Properties, - &parser.Property{Name: "src", NamePos: srcs.NamePos, ColonPos: srcs.ColonPos, Value: resolveLocalModule(mod, srcs.Value)}) - } else { - renameProperty(mod, "srcs", "src") - } - } + // 'srcs' --> 'src' conversion + convertToSingleSource(mod, "src") // The rewriter converts LOCAL_MODULE_PATH attribute into a struct attribute // 'local_module_path'. Analyze its contents and create the correct sub_dir:, @@ -603,6 +588,62 @@ func rewriteAndroidTest(f *Fixer) error { return nil } +func rewriteAndroidAppImport(f *Fixer) error { + for _, def := range f.tree.Defs { + mod, ok := def.(*parser.Module) + if !(ok && mod.Type == "android_app_import") { + continue + } + // 'srcs' --> 'apk' conversion + convertToSingleSource(mod, "apk") + // Handle special certificate value, "PRESIGNED". + if cert, ok := mod.GetProperty("certificate"); ok { + if certStr, ok := cert.Value.(*parser.String); ok { + if certStr.Value == "PRESIGNED" { + removeProperty(mod, "certificate") + prop := &parser.Property{ + Name: "presigned", + Value: &parser.Bool{ + Value: true, + }, + } + mod.Properties = append(mod.Properties, prop) + } + } + } + } + return nil +} + +// Converts the default source list property, 'srcs', to a single source property with a given name. +// "LOCAL_MODULE" reference is also resolved during the conversion process. +func convertToSingleSource(mod *parser.Module, srcPropertyName string) { + if srcs, ok := mod.GetProperty("srcs"); ok { + if srcList, ok := srcs.Value.(*parser.List); ok { + removeProperty(mod, "srcs") + if len(srcList.Values) == 1 { + mod.Properties = append(mod.Properties, + &parser.Property{ + Name: srcPropertyName, + NamePos: srcs.NamePos, + ColonPos: srcs.ColonPos, + Value: resolveLocalModule(mod, srcList.Values[0])}) + } else if len(srcList.Values) > 1 { + indicateAttributeError(mod, srcPropertyName, "LOCAL_SRC_FILES should contain at most one item") + } + } else if _, ok = srcs.Value.(*parser.Variable); ok { + removeProperty(mod, "srcs") + mod.Properties = append(mod.Properties, + &parser.Property{Name: srcPropertyName, + NamePos: srcs.NamePos, + ColonPos: srcs.ColonPos, + Value: resolveLocalModule(mod, srcs.Value)}) + } else { + renameProperty(mod, "srcs", "apk") + } + } +} + func runPatchListMod(modFunc func(mod *parser.Module, buf []byte, patchlist *parser.PatchList) error) func(*Fixer) error { return func(f *Fixer) error { // Make sure all the offsets are accurate diff --git a/bpfix/bpfix/bpfix_test.go b/bpfix/bpfix/bpfix_test.go index 459cd36b..5e0b8175 100644 --- a/bpfix/bpfix/bpfix_test.go +++ b/bpfix/bpfix/bpfix_test.go @@ -784,3 +784,52 @@ func TestRewriteAndroidTest(t *testing.T) { }) } } + +func TestRewriteAndroidAppImport(t *testing.T) { + tests := []struct { + name string + in string + out string + }{ + { + name: "android_app_import apk", + in: ` + android_app_import { + name: "foo", + srcs: ["package.apk"], + } + `, + out: ` + android_app_import { + name: "foo", + apk: "package.apk", + } + `, + }, + { + name: "android_app_import presigned", + in: ` + android_app_import { + name: "foo", + apk: "package.apk", + certificate: "PRESIGNED", + } + `, + out: ` + android_app_import { + name: "foo", + apk: "package.apk", + presigned: true, + + } + `, + }, + } + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + runPass(t, test.in, test.out, func(fixer *Fixer) error { + return rewriteAndroidAppImport(fixer) + }) + }) + } +} |