aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2018-03-21 16:25:19 -0700
committerColin Cross <ccross@android.com>2018-05-03 14:38:37 -0700
commitdc8dbe188b099c7f1a2ff6a90ec604643426471d (patch)
tree5ac401eaab89ff6bf4a9bc9f73e10f4796aa90f8
parent5dadd0e08aeda0d8a4d55b66e08f31a3828d967d (diff)
downloadbuild_soong-dc8dbe188b099c7f1a2ff6a90ec604643426471d.tar.gz
build_soong-dc8dbe188b099c7f1a2ff6a90ec604643426471d.tar.bz2
build_soong-dc8dbe188b099c7f1a2ff6a90ec604643426471d.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. Bug: 73724997 Test: androidmk_test.go Change-Id: I3ad2a3561f69ebd097eca97cb170754d64e06123 Merged-In: I3ad2a3561f69ebd097eca97cb170754d64e06123 (cherry picked from commit 2dee86d69cf51b38e8b0afac2e8b47ab77380fac)
-rw-r--r--androidmk/cmd/androidmk/android.go11
-rw-r--r--androidmk/cmd/androidmk/androidmk_test.go55
-rw-r--r--bpfix/bpfix/bpfix.go52
3 files changed, 115 insertions, 3 deletions
diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go
index b2a8914e..5cb4869c 100644
--- a/androidmk/cmd/androidmk/android.go
+++ b/androidmk/cmd/androidmk/android.go
@@ -64,6 +64,9 @@ var rewriteProperties = map[string](func(variableAssignmentContext) error){
"LOCAL_MODULE_SUFFIX": skip, // TODO
"LOCAL_PATH": skip, // Nothing to do, except maybe avoid the "./" in paths?
"LOCAL_PRELINK_MODULE": skip, // Already phased out
+ "LOCAL_BUILT_MODULE_STEM": skip,
+ "LOCAL_USE_AAPT2": skip, // Always enabled in Soong
+ "LOCAL_JAR_EXCLUDE_FILES": skip, // Soong never excludes files from jars
}
// adds a group of properties all having the same type
@@ -94,6 +97,7 @@ func init() {
"LOCAL_NOTICE_FILE": "notice",
"LOCAL_JAVA_LANGUAGE_VERSION": "java_version",
"LOCAL_INSTRUMENTATION_FOR": "instrumentation_for",
+ "LOCAL_MANIFEST_FILE": "manifest",
"LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING": "dex_preopt.profile",
})
@@ -128,6 +132,7 @@ func init() {
"LOCAL_RENDERSCRIPT_FLAGS": "renderscript.flags",
"LOCAL_JAVA_RESOURCE_DIRS": "java_resource_dirs",
+ "LOCAL_RESOURCE_DIR": "resource_dirs",
"LOCAL_JAVACFLAGS": "javacflags",
"LOCAL_ERROR_PRONE_FLAGS": "errorprone.javacflags",
"LOCAL_DX_FLAGS": "dxflags",
@@ -142,7 +147,13 @@ func init() {
"LOCAL_PROGUARD_FLAGS": "optimize.proguard_flags",
"LOCAL_PROGUARD_FLAG_FILES": "optimize.proguard_flag_files",
+
+ // These will be rewritten to libs/static_libs by bpfix, after their presence is used to convert
+ // java_library_static to android_library.
+ "LOCAL_SHARED_ANDROID_LIBRARIES": "android_libs",
+ "LOCAL_STATIC_ANDROID_LIBRARIES": "android_static_libs",
})
+
addStandardProperties(bpparser.BoolType,
map[string]string{
// Bool properties
diff --git a/androidmk/cmd/androidmk/androidmk_test.go b/androidmk/cmd/androidmk/androidmk_test.go
index dd646efe..1840e026 100644
--- a/androidmk/cmd/androidmk/androidmk_test.go
+++ b/androidmk/cmd/androidmk/androidmk_test.go
@@ -496,6 +496,7 @@ include $(call all-makefiles-under,$(LOCAL_PATH))
include $(CLEAR_VARS)
LOCAL_SRC_FILES := test.jar
LOCAL_MODULE_CLASS := JAVA_LIBRARIES
+ LOCAL_STATIC_ANDROID_LIBRARIES :=
include $(BUILD_PREBUILT)
`,
expected: `
@@ -520,6 +521,60 @@ include $(call all-makefiles-under,$(LOCAL_PATH))
}
`,
},
+
+ {
+ desc: "aar",
+ in: `
+ include $(CLEAR_VARS)
+ LOCAL_SRC_FILES := test.java
+ LOCAL_RESOURCE_DIR := res
+ include $(BUILD_STATIC_JAVA_LIBRARY)
+
+ include $(CLEAR_VARS)
+ LOCAL_SRC_FILES := test.java
+ LOCAL_STATIC_LIBRARIES := foo
+ LOCAL_STATIC_ANDROID_LIBRARIES := bar
+ include $(BUILD_STATIC_JAVA_LIBRARY)
+
+ include $(CLEAR_VARS)
+ LOCAL_SRC_FILES := test.java
+ LOCAL_SHARED_LIBRARIES := foo
+ LOCAL_SHARED_ANDROID_LIBRARIES := bar
+ include $(BUILD_STATIC_JAVA_LIBRARY)
+
+ include $(CLEAR_VARS)
+ LOCAL_SRC_FILES := test.java
+ LOCAL_STATIC_ANDROID_LIBRARIES :=
+ include $(BUILD_STATIC_JAVA_LIBRARY)
+ `,
+ expected: `
+ android_library {
+ srcs: ["test.java"],
+ resource_dirs: ["res"],
+ }
+
+ android_library {
+ srcs: ["test.java"],
+ static_libs: [
+ "foo",
+ "bar",
+ ],
+ }
+
+ android_library {
+ srcs: ["test.java"],
+ libs: [
+ "foo",
+ "bar",
+ ],
+ }
+
+ java_library_static {
+ srcs: ["test.java"],
+ static_libs: [],
+ }
+ `,
+ },
}
func TestEndToEnd(t *testing.T) {
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) {
// 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
- rewriteIncorrectAndroidmkPrebuilts bool
- mergeMatchingModuleProperties bool
+ simplifyKnownRedundantVariables bool
+ rewriteIncorrectAndroidmkPrebuilts bool
+ rewriteIncorrectAndroidmkAndroidLibraries bool
+ mergeMatchingModuleProperties bool
}
func NewFixRequest() FixRequest {
@@ -57,6 +58,7 @@ func (r FixRequest) AddAll() (result FixRequest) {
result = r
result.simplifyKnownRedundantVariables = true
result.rewriteIncorrectAndroidmkPrebuilts = true
+ result.rewriteIncorrectAndroidmkAndroidLibraries = true
result.mergeMatchingModuleProperties = true
return result
}
@@ -154,6 +156,13 @@ func (f *Fixer) fixTreeOnce(config FixRequest) error {
}
}
+ if config.rewriteIncorrectAndroidmkAndroidLibraries {
+ err := f.rewriteIncorrectAndroidmkAndroidLibraries()
+ if err != nil {
+ return err
+ }
+ }
+
if config.mergeMatchingModuleProperties {
err := f.mergeMatchingModuleProperties()
if err != nil {
@@ -191,6 +200,7 @@ func (f *Fixer) rewriteIncorrectAndroidmkPrebuilts() error {
switch filepath.Ext(src.Value) {
case ".jar":
renameProperty(mod, "srcs", "jars")
+
case ".aar":
renameProperty(mod, "srcs", "aars")
mod.Type = "android_library_import"
@@ -203,6 +213,37 @@ func (f *Fixer) rewriteIncorrectAndroidmkPrebuilts() error {
return nil
}
+func (f *Fixer) rewriteIncorrectAndroidmkAndroidLibraries() error {
+ for _, def := range f.tree.Defs {
+ mod, ok := def.(*parser.Module)
+ if !ok {
+ continue
+ }
+
+ hasAndroidLibraries := hasNonEmptyLiteralListProperty(mod, "android_libs")
+ hasStaticAndroidLibraries := hasNonEmptyLiteralListProperty(mod, "android_static_libs")
+ hasResourceDirs := hasNonEmptyLiteralListProperty(mod, "resource_dirs")
+
+ if hasAndroidLibraries || hasStaticAndroidLibraries || hasResourceDirs {
+ if mod.Type == "java_library_static" {
+ mod.Type = "android_library"
+ }
+ }
+
+ if mod.Type == "java_import" && !hasStaticAndroidLibraries {
+ removeProperty(mod, "android_static_libs")
+ }
+
+ // These may conflict with existing libs and static_libs properties, but the
+ // mergeMatchingModuleProperties pass will fix it.
+ renameProperty(mod, "shared_libs", "libs")
+ renameProperty(mod, "android_libs", "libs")
+ renameProperty(mod, "android_static_libs", "static_libs")
+ }
+
+ return nil
+}
+
func (f *Fixer) mergeMatchingModuleProperties() error {
// Make sure all the offsets are accurate
buf, err := f.reparse()
@@ -355,6 +396,11 @@ func (f *Fixer) removeMatchingModuleListProperties(canonicalName string, legacyN
return nil
}
+func hasNonEmptyLiteralListProperty(mod *parser.Module, name string) bool {
+ list, found := getLiteralListProperty(mod, name)
+ return found && len(list.Values) > 0
+}
+
func getLiteralListProperty(mod *parser.Module, name string) (list *parser.List, found bool) {
prop, ok := mod.GetProperty(name)
if !ok {