diff options
Diffstat (limited to 'androidmk')
-rw-r--r-- | androidmk/cmd/androidmk/android.go | 58 | ||||
-rw-r--r-- | androidmk/cmd/androidmk/androidmk_test.go | 36 |
2 files changed, 94 insertions, 0 deletions
diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go index 82b5eb95..3e134b6e 100644 --- a/androidmk/cmd/androidmk/android.go +++ b/androidmk/cmd/androidmk/android.go @@ -53,6 +53,7 @@ var rewriteProperties = map[string](func(variableAssignmentContext) error){ "LOCAL_SANITIZE_DIAG": sanitize("diag."), "LOCAL_CFLAGS": cflags, "LOCAL_UNINSTALLABLE_MODULE": invert("installable"), + "LOCAL_PROGUARD_ENABLED": proguardEnabled, // composite functions "LOCAL_MODULE_TAGS": includeVariableIf(bpVariable{"tags", bpparser.ListType}, not(valueDumpEquals("optional"))), @@ -136,6 +137,9 @@ func init() { "LOCAL_ANNOTATION_PROCESSORS": "annotation_processors", "LOCAL_ANNOTATION_PROCESSOR_CLASSES": "annotation_processor_classes", + + "LOCAL_PROGUARD_FLAGS": "optimize.proguard_flags", + "LOCAL_PROGUARD_FLAG_FILES": "optimize.proguard_flag_files", }) addStandardProperties(bpparser.BoolType, map[string]string{ @@ -517,6 +521,60 @@ func cflags(ctx variableAssignmentContext) error { return includeVariableNow(bpVariable{"cflags", bpparser.ListType}, ctx) } +func proguardEnabled(ctx variableAssignmentContext) error { + val, err := makeVariableToBlueprint(ctx.file, ctx.mkvalue, bpparser.ListType) + if err != nil { + return err + } + + list, ok := val.(*bpparser.List) + if !ok { + return fmt.Errorf("unsupported proguard expression") + } + + set := func(prop string, value bool) { + bpValue := &bpparser.Bool{ + Value: value, + } + setVariable(ctx.file, false, ctx.prefix, prop, bpValue, true) + } + + enable := false + + for _, v := range list.Values { + s, ok := v.(*bpparser.String) + if !ok { + return fmt.Errorf("unsupported proguard expression") + } + + switch s.Value { + case "disabled": + set("optimize.enabled", false) + case "obfuscation": + enable = true + set("optimize.obfuscate", true) + case "optimization": + enable = true + set("optimize.optimize", true) + case "full": + enable = true + case "custom": + set("optimize.no_aapt_flags", true) + enable = true + default: + return fmt.Errorf("unsupported proguard value %q", s) + } + } + + if enable { + // This is only necessary for libraries which default to false, but we can't + // tell the difference between a library and an app here. + set("optimize.enabled", true) + } + + return nil +} + func invert(name string) func(ctx variableAssignmentContext) error { return func(ctx variableAssignmentContext) error { val, err := makeVariableToBlueprint(ctx.file, ctx.mkvalue, bpparser.BoolType) diff --git a/androidmk/cmd/androidmk/androidmk_test.go b/androidmk/cmd/androidmk/androidmk_test.go index 22a52d46..c85aaaac 100644 --- a/androidmk/cmd/androidmk/androidmk_test.go +++ b/androidmk/cmd/androidmk/androidmk_test.go @@ -438,6 +438,42 @@ include $(call all-makefiles-under,$(LOCAL_PATH)) `, expected: ``, }, + { + desc: "proguard options for java library", + in: ` + include $(CLEAR_VARS) + # Empty + LOCAL_PROGUARD_ENABLED := + # Disabled + LOCAL_PROGUARD_ENABLED := disabled + # Full + LOCAL_PROGUARD_ENABLED := full + # Obfuscation and optimization + LOCAL_PROGUARD_ENABLED := obfuscation optimization + # Custom + LOCAL_PROGUARD_ENABLED := custom + include $(BUILD_JAVA_LIBRARY) + `, + expected: ` + java_library { + // Empty + + // Disabled + optimize: { + enabled: false, + // Full + enabled: true, + // Obfuscation and optimization + obfuscate: true, + optimize: true, + enabled: true, + // Custom + no_aapt_flags: true, + enabled: true, + }, + } + `, + }, } func reformatBlueprint(input string) string { |