aboutsummaryrefslogtreecommitdiffstats
path: root/androidmk
diff options
context:
space:
mode:
authorSasha Smundak <asmundak@google.com>2019-02-22 14:41:33 -0800
committerSasha Smundak <asmundak@google.com>2019-02-25 15:19:06 -0800
commit1d318cbaa9440c6c8941bd1ffd48800c11f9d42c (patch)
tree00da5109dc8175a60a74b94f0f689f74c35abe00 /androidmk
parent18d3fe02aca73b920c1e006c603d947f925486af (diff)
downloadbuild_soong-1d318cbaa9440c6c8941bd1ffd48800c11f9d42c.tar.gz
build_soong-1d318cbaa9440c6c8941bd1ffd48800c11f9d42c.tar.bz2
build_soong-1d318cbaa9440c6c8941bd1ffd48800c11f9d42c.zip
Handle $(LOCAL_PATH) in androidmk
The variables LOCAL_ADDITIONAL_CERTIFICATES. LOCAL_ASSET_DIR, LOCAL_CERTIFICATE, LOCAL_JARJAR_RULES, LOCAL_PROGUARD_FLAG_FILES, LOCAL_RESOURCE_DIR specify the paths relative to the top of the source tree using $(LOCAL_PATH)/. Remove it when converting to blueprint files and diagnose the cases when these paths do not start with $(LOCAL_PATH). Fixes: 122728056 Test: Internal tests Change-Id: Id3fcacdd5445a97365c03e00656291bfe829c035
Diffstat (limited to 'androidmk')
-rw-r--r--androidmk/cmd/androidmk/android.go97
-rw-r--r--androidmk/cmd/androidmk/androidmk_test.go28
2 files changed, 105 insertions, 20 deletions
diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go
index 4af5d971..c66acdc6 100644
--- a/androidmk/cmd/androidmk/android.go
+++ b/androidmk/cmd/androidmk/android.go
@@ -42,21 +42,26 @@ type variableAssignmentContext struct {
var rewriteProperties = map[string](func(variableAssignmentContext) error){
// custom functions
- "LOCAL_32_BIT_ONLY": local32BitOnly,
- "LOCAL_AIDL_INCLUDES": localAidlIncludes,
- "LOCAL_C_INCLUDES": localIncludeDirs,
- "LOCAL_EXPORT_C_INCLUDE_DIRS": exportIncludeDirs,
- "LOCAL_LDFLAGS": ldflags,
- "LOCAL_MODULE_CLASS": prebuiltClass,
- "LOCAL_MODULE_STEM": stem,
- "LOCAL_MODULE_HOST_OS": hostOs,
- "LOCAL_SANITIZE": sanitize(""),
- "LOCAL_SANITIZE_DIAG": sanitize("diag."),
- "LOCAL_STRIP_MODULE": strip(),
- "LOCAL_CFLAGS": cflags,
- "LOCAL_UNINSTALLABLE_MODULE": invert("installable"),
- "LOCAL_PROGUARD_ENABLED": proguardEnabled,
- "LOCAL_MODULE_PATH": prebuiltModulePath,
+ "LOCAL_32_BIT_ONLY": local32BitOnly,
+ "LOCAL_ADDITIONAL_CERTIFICATES": localizePathList("additional_certificates"),
+ "LOCAL_AIDL_INCLUDES": localAidlIncludes,
+ "LOCAL_ASSET_DIR": localizePathList("asset_dirs"),
+ "LOCAL_C_INCLUDES": localIncludeDirs,
+ "LOCAL_CERTIFICATE": localizePath("certificate"),
+ "LOCAL_EXPORT_C_INCLUDE_DIRS": exportIncludeDirs,
+ "LOCAL_JARJAR_RULES": localizePath("jarjar_rules"),
+ "LOCAL_LDFLAGS": ldflags,
+ "LOCAL_MODULE_CLASS": prebuiltClass,
+ "LOCAL_MODULE_STEM": stem,
+ "LOCAL_MODULE_HOST_OS": hostOs,
+ "LOCAL_RESOURCE_DIR": localizePathList("resource_dirs"),
+ "LOCAL_SANITIZE": sanitize(""),
+ "LOCAL_SANITIZE_DIAG": sanitize("diag."),
+ "LOCAL_STRIP_MODULE": strip(),
+ "LOCAL_CFLAGS": cflags,
+ "LOCAL_UNINSTALLABLE_MODULE": invert("installable"),
+ "LOCAL_PROGUARD_ENABLED": proguardEnabled,
+ "LOCAL_MODULE_PATH": prebuiltModulePath,
// composite functions
"LOCAL_MODULE_TAGS": includeVariableIf(bpVariable{"tags", bpparser.ListType}, not(valueDumpEquals("optional"))),
@@ -93,8 +98,6 @@ func init() {
"LOCAL_MIN_SDK_VERSION": "min_sdk_version",
"LOCAL_NDK_STL_VARIANT": "stl",
"LOCAL_JAR_MANIFEST": "manifest",
- "LOCAL_JARJAR_RULES": "jarjar_rules",
- "LOCAL_CERTIFICATE": "certificate",
"LOCAL_PACKAGE_NAME": "name",
"LOCAL_MODULE_RELATIVE_PATH": "relative_install_path",
"LOCAL_PROTOC_OPTIMIZE_TYPE": "proto.type",
@@ -140,7 +143,6 @@ 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",
@@ -161,7 +163,6 @@ func init() {
// java_library_static to android_library.
"LOCAL_SHARED_ANDROID_LIBRARIES": "android_libs",
"LOCAL_STATIC_ANDROID_LIBRARIES": "android_static_libs",
- "LOCAL_ADDITIONAL_CERTIFICATES": "additional_certificates",
// Jacoco filters:
"LOCAL_JACK_COVERAGE_INCLUDE_FILTER": "jacoco.include_filter",
@@ -389,6 +390,64 @@ func localAidlIncludes(ctx variableAssignmentContext) error {
return splitAndAssign(ctx, classifyLocalOrGlobalPath, map[string]string{"global": "aidl.include_dirs", "local": "aidl.local_include_dirs"})
}
+func localizePathList(attribute string) func(ctx variableAssignmentContext) error {
+ return func(ctx variableAssignmentContext) error {
+ paths, err := localizePaths(ctx)
+ if err == nil {
+ err = setVariable(ctx.file, ctx.append, ctx.prefix, attribute, paths, true)
+ }
+ return err
+ }
+}
+
+func localizePath(attribute string) func(ctx variableAssignmentContext) error {
+ return func(ctx variableAssignmentContext) error {
+ paths, err := localizePaths(ctx)
+ if err == nil {
+ pathList, ok := paths.(*bpparser.List)
+ if !ok {
+ panic("Expected list")
+ }
+ switch len(pathList.Values) {
+ case 0:
+ err = setVariable(ctx.file, ctx.append, ctx.prefix, attribute, &bpparser.List{}, true)
+ case 1:
+ err = setVariable(ctx.file, ctx.append, ctx.prefix, attribute, pathList.Values[0], true)
+ default:
+ err = fmt.Errorf("Expected single value for %s", attribute)
+ }
+ }
+ return err
+ }
+}
+
+// Convert the "full" paths (that is, from the top of the source tree) to the relative one
+// (from the directory containing the blueprint file) and set given attribute to it.
+// This is needed for some of makefile variables (e.g., LOCAL_RESOURCE_DIR).
+// At the moment only the paths of the `$(LOCAL_PATH)/foo/bar` format can be converted
+// (to `foo/bar` in this case) as we cannot convert a literal path without
+// knowing makefiles's location in the source tree. We just issue a warning in the latter case.
+func localizePaths(ctx variableAssignmentContext) (bpparser.Expression, error) {
+ bpvalue, err := makeVariableToBlueprint(ctx.file, ctx.mkvalue, bpparser.ListType)
+ var result bpparser.Expression
+ if err != nil {
+ return result, err
+ }
+ classifiedPaths, err := splitBpList(bpvalue, classifyLocalOrGlobalPath)
+ if err != nil {
+ return result, err
+ }
+ for pathClass, path := range classifiedPaths {
+ switch pathClass {
+ case "local":
+ result = path
+ default:
+ err = fmt.Errorf("Only $(LOCAL_PATH)/.. values are allowed")
+ }
+ }
+ return result, err
+}
+
func stem(ctx variableAssignmentContext) error {
val, err := makeVariableToBlueprint(ctx.file, ctx.mkvalue, bpparser.StringType)
if err != nil {
diff --git a/androidmk/cmd/androidmk/androidmk_test.go b/androidmk/cmd/androidmk/androidmk_test.go
index 9af2beac..bc249d03 100644
--- a/androidmk/cmd/androidmk/androidmk_test.go
+++ b/androidmk/cmd/androidmk/androidmk_test.go
@@ -112,6 +112,32 @@ cc_library_shared {
}`,
},
{
+ desc: "Convert to local path",
+ in: `
+include $(CLEAR_VARS)
+LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res $(LOCAL_PATH)/res2
+LOCAL_ASSET_DIR := $(LOCAL_PATH)/asset
+LOCAL_JARJAR_RULES := $(LOCAL_PATH)/jarjar-rules.txt
+LOCAL_CERTIFICATE := $(LOCAL_PATH)/cert
+LOCAL_ADDITIONAL_CERTIFICATES := $(LOCAL_PATH)/cert1 $(LOCAL_PATH)/cert2
+include $(BUILD_PACKAGE)
+ `,
+ expected: `
+android_app {
+ resource_dirs: [
+ "res",
+ "res2",
+ ],
+ asset_dirs: ["asset"],
+ jarjar_rules: "jarjar-rules.txt",
+ certificate: "cert",
+ additional_certificates: [
+ "cert1",
+ "cert2",
+ ],
+}`,
+ },
+ {
desc: "LOCAL_MODULE_STEM",
in: `
include $(CLEAR_VARS)
@@ -642,7 +668,7 @@ include $(call all-makefiles-under,$(LOCAL_PATH))
in: `
include $(CLEAR_VARS)
LOCAL_SRC_FILES := test.java
- LOCAL_RESOURCE_DIR := res
+ LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res
LOCAL_JACK_COVERAGE_INCLUDE_FILTER := foo.*
include $(BUILD_STATIC_JAVA_LIBRARY)