diff options
author | Colin Cross | 2018-03-21 18:25:19 -0500 |
---|---|---|
committer | Colin Cross | 2018-04-16 12:32:23 -0500 |
commit | 2dee86d69cf51b38e8b0afac2e8b47ab77380fac (patch) | |
tree | c77d83b9ea7f0c4eb022de4fdea7977c0a96c4c3 /bpfix | |
parent | 9c55d237f6b72896209344aee18a1702c2f9ac3e (diff) | |
download | platform-build-soong-2dee86d69cf51b38e8b0afac2e8b47ab77380fac.tar.gz platform-build-soong-2dee86d69cf51b38e8b0afac2e8b47ab77380fac.tar.xz platform-build-soong-2dee86d69cf51b38e8b0afac2e8b47ab77380fac.zip |
Add more androidmk translations for android libraries
Add support for translating LOCAL_MANIFEST_FILE, LOCAL_RESOURCE_DIR
LOCAL_SHARED_ANDROID_LIBRARIES, and LOCAL_STATIC_ANDROID_LIBRARIES.
Use the presence of non-empty LOCAL_RESOURCE_DIR,
LOCAL_SHARED_ANDROID_LIBRARIES or LOCAL_STATIC_ANDROID_LIBRARIES
to convert a java_library_static into an android_library module,
and then squash LOCAL_SHARED_ANDROID_LIBRARIES into
LOCAL_SHARED_LIBRARIES and LOCAL_STATIC_ANDROID_LIBRARIES into
LOCAL_STATIC_LIBRARIES.
Test: androidmk_test.go
Change-Id: I3ad2a3561f69ebd097eca97cb170754d64e06123
Diffstat (limited to 'bpfix')
-rw-r--r-- | bpfix/bpfix/bpfix.go | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/bpfix/bpfix/bpfix.go b/bpfix/bpfix/bpfix.go index 4ab42a4e..e4d4e34e 100644 --- a/bpfix/bpfix/bpfix.go +++ b/bpfix/bpfix/bpfix.go | |||
@@ -44,9 +44,10 @@ func Reformat(input string) (string, error) { | |||
44 | // A FixRequest specifies the details of which fixes to apply to an individual file | 44 | // A FixRequest specifies the details of which fixes to apply to an individual file |
45 | // A FixRequest doesn't specify whether to do a dry run or where to write the results; that's in cmd/bpfix.go | 45 | // A FixRequest doesn't specify whether to do a dry run or where to write the results; that's in cmd/bpfix.go |
46 | type FixRequest struct { | 46 | type FixRequest struct { |
47 | simplifyKnownRedundantVariables bool | 47 | simplifyKnownRedundantVariables bool |
48 | rewriteIncorrectAndroidmkPrebuilts bool | 48 | rewriteIncorrectAndroidmkPrebuilts bool |
49 | mergeMatchingModuleProperties bool | 49 | rewriteIncorrectAndroidmkAndroidLibraries bool |
50 | mergeMatchingModuleProperties bool | ||
50 | } | 51 | } |
51 | 52 | ||
52 | func NewFixRequest() FixRequest { | 53 | func NewFixRequest() FixRequest { |
@@ -57,6 +58,7 @@ func (r FixRequest) AddAll() (result FixRequest) { | |||
57 | result = r | 58 | result = r |
58 | result.simplifyKnownRedundantVariables = true | 59 | result.simplifyKnownRedundantVariables = true |
59 | result.rewriteIncorrectAndroidmkPrebuilts = true | 60 | result.rewriteIncorrectAndroidmkPrebuilts = true |
61 | result.rewriteIncorrectAndroidmkAndroidLibraries = true | ||
60 | result.mergeMatchingModuleProperties = true | 62 | result.mergeMatchingModuleProperties = true |
61 | return result | 63 | return result |
62 | } | 64 | } |
@@ -154,6 +156,13 @@ func (f *Fixer) fixTreeOnce(config FixRequest) error { | |||
154 | } | 156 | } |
155 | } | 157 | } |
156 | 158 | ||
159 | if config.rewriteIncorrectAndroidmkAndroidLibraries { | ||
160 | err := f.rewriteIncorrectAndroidmkAndroidLibraries() | ||
161 | if err != nil { | ||
162 | return err | ||
163 | } | ||
164 | } | ||
165 | |||
157 | if config.mergeMatchingModuleProperties { | 166 | if config.mergeMatchingModuleProperties { |
158 | err := f.mergeMatchingModuleProperties() | 167 | err := f.mergeMatchingModuleProperties() |
159 | if err != nil { | 168 | if err != nil { |
@@ -191,6 +200,7 @@ func (f *Fixer) rewriteIncorrectAndroidmkPrebuilts() error { | |||
191 | switch filepath.Ext(src.Value) { | 200 | switch filepath.Ext(src.Value) { |
192 | case ".jar": | 201 | case ".jar": |
193 | renameProperty(mod, "srcs", "jars") | 202 | renameProperty(mod, "srcs", "jars") |
203 | |||
194 | case ".aar": | 204 | case ".aar": |
195 | renameProperty(mod, "srcs", "aars") | 205 | renameProperty(mod, "srcs", "aars") |
196 | mod.Type = "android_library_import" | 206 | mod.Type = "android_library_import" |
@@ -203,6 +213,37 @@ func (f *Fixer) rewriteIncorrectAndroidmkPrebuilts() error { | |||
203 | return nil | 213 | return nil |
204 | } | 214 | } |
205 | 215 | ||
216 | func (f *Fixer) rewriteIncorrectAndroidmkAndroidLibraries() error { | ||
217 | for _, def := range f.tree.Defs { | ||
218 | mod, ok := def.(*parser.Module) | ||
219 | if !ok { | ||
220 | continue | ||
221 | } | ||
222 | |||
223 | hasAndroidLibraries := hasNonEmptyLiteralListProperty(mod, "android_libs") | ||
224 | hasStaticAndroidLibraries := hasNonEmptyLiteralListProperty(mod, "android_static_libs") | ||
225 | hasResourceDirs := hasNonEmptyLiteralListProperty(mod, "resource_dirs") | ||
226 | |||
227 | if hasAndroidLibraries || hasStaticAndroidLibraries || hasResourceDirs { | ||
228 | if mod.Type == "java_library_static" { | ||
229 | mod.Type = "android_library" | ||
230 | } | ||
231 | } | ||
232 | |||
233 | if mod.Type == "java_import" && !hasStaticAndroidLibraries { | ||
234 | removeProperty(mod, "android_static_libs") | ||
235 | } | ||
236 | |||
237 | // These may conflict with existing libs and static_libs properties, but the | ||
238 | // mergeMatchingModuleProperties pass will fix it. | ||
239 | renameProperty(mod, "shared_libs", "libs") | ||
240 | renameProperty(mod, "android_libs", "libs") | ||
241 | renameProperty(mod, "android_static_libs", "static_libs") | ||
242 | } | ||
243 | |||
244 | return nil | ||
245 | } | ||
246 | |||
206 | func (f *Fixer) mergeMatchingModuleProperties() error { | 247 | func (f *Fixer) mergeMatchingModuleProperties() error { |
207 | // Make sure all the offsets are accurate | 248 | // Make sure all the offsets are accurate |
208 | buf, err := f.reparse() | 249 | buf, err := f.reparse() |
@@ -355,6 +396,11 @@ func (f *Fixer) removeMatchingModuleListProperties(canonicalName string, legacyN | |||
355 | return nil | 396 | return nil |
356 | } | 397 | } |
357 | 398 | ||
399 | func hasNonEmptyLiteralListProperty(mod *parser.Module, name string) bool { | ||
400 | list, found := getLiteralListProperty(mod, name) | ||
401 | return found && len(list.Values) > 0 | ||
402 | } | ||
403 | |||
358 | func getLiteralListProperty(mod *parser.Module, name string) (list *parser.List, found bool) { | 404 | func getLiteralListProperty(mod *parser.Module, name string) (list *parser.List, found bool) { |
359 | prop, ok := mod.GetProperty(name) | 405 | prop, ok := mod.GetProperty(name) |
360 | if !ok { | 406 | if !ok { |