diff --git a/androidmk/cmd/androidmk/android.go b/androidmk/cmd/androidmk/android.go index 4d928b129..f693f5de2 100644 --- a/androidmk/cmd/androidmk/android.go +++ b/androidmk/cmd/androidmk/android.go @@ -1,75 +1,79 @@ package main import ( - "android/soong/androidmk/parser" + mkparser "android/soong/androidmk/parser" "fmt" "strings" + + bpparser "github.com/google/blueprint/parser" ) const ( clear_vars = "__android_mk_clear_vars" ) -var stringProperties = map[string]string{ - "LOCAL_MODULE": "name", - "LOCAL_MODULE_STEM": "stem", - "LOCAL_MODULE_CLASS": "class", - "LOCAL_CXX_STL": "stl", - "LOCAL_STRIP_MODULE": "strip", - "LOCAL_MULTILIB": "compile_multilib", - "LOCAL_ARM_MODE_HACK": "instruction_set", - "LOCAL_SDK_VERSION": "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", -} +var standardProperties = map[string]struct { + string + bpparser.ValueType +}{ + // String properties + "LOCAL_MODULE": {"name", bpparser.String}, + "LOCAL_MODULE_STEM": {"stem", bpparser.String}, + "LOCAL_MODULE_CLASS": {"class", bpparser.String}, + "LOCAL_CXX_STL": {"stl", bpparser.String}, + "LOCAL_STRIP_MODULE": {"strip", bpparser.String}, + "LOCAL_MULTILIB": {"compile_multilib", bpparser.String}, + "LOCAL_ARM_MODE_HACK": {"instruction_set", bpparser.String}, + "LOCAL_SDK_VERSION": {"sdk_version", bpparser.String}, + "LOCAL_NDK_STL_VARIANT": {"stl", bpparser.String}, + "LOCAL_JAR_MANIFEST": {"manifest", bpparser.String}, + "LOCAL_JARJAR_RULES": {"jarjar_rules", bpparser.String}, + "LOCAL_CERTIFICATE": {"certificate", bpparser.String}, + "LOCAL_PACKAGE_NAME": {"name", bpparser.String}, + "LOCAL_MODULE_RELATIVE_PATH": {"relative_install_path", bpparser.String}, -var listProperties = map[string]string{ - "LOCAL_SRC_FILES": "srcs", - "LOCAL_SHARED_LIBRARIES": "shared_libs", - "LOCAL_STATIC_LIBRARIES": "static_libs", - "LOCAL_WHOLE_STATIC_LIBRARIES": "whole_static_libs", - "LOCAL_SYSTEM_SHARED_LIBRARIES": "system_shared_libs", - "LOCAL_C_INCLUDES": "include_dirs", - "LOCAL_EXPORT_C_INCLUDE_DIRS": "export_include_dirs", - "LOCAL_ASFLAGS": "asflags", - "LOCAL_CLANG_ASFLAGS": "clang_asflags", - "LOCAL_CFLAGS": "cflags", - "LOCAL_CONLYFLAGS": "conlyflags", - "LOCAL_CPPFLAGS": "cppflags", - "LOCAL_LDFLAGS": "ldflags", - "LOCAL_REQUIRED_MODULES": "required", - "LOCAL_MODULE_TAGS": "tags", - "LOCAL_LDLIBS": "host_ldlibs", - "LOCAL_CLANG_CFLAGS": "clang_cflags", - "LOCAL_YACCFLAGS": "yaccflags", + // List properties + "LOCAL_SRC_FILES": {"srcs", bpparser.List}, + "LOCAL_SHARED_LIBRARIES": {"shared_libs", bpparser.List}, + "LOCAL_STATIC_LIBRARIES": {"static_libs", bpparser.List}, + "LOCAL_WHOLE_STATIC_LIBRARIES": {"whole_static_libs", bpparser.List}, + "LOCAL_SYSTEM_SHARED_LIBRARIES": {"system_shared_libs", bpparser.List}, + "LOCAL_C_INCLUDES": {"include_dirs", bpparser.List}, + "LOCAL_EXPORT_C_INCLUDE_DIRS": {"export_include_dirs", bpparser.List}, + "LOCAL_ASFLAGS": {"asflags", bpparser.List}, + "LOCAL_CLANG_ASFLAGS": {"clang_asflags", bpparser.List}, + "LOCAL_CFLAGS": {"cflags", bpparser.List}, + "LOCAL_CONLYFLAGS": {"conlyflags", bpparser.List}, + "LOCAL_CPPFLAGS": {"cppflags", bpparser.List}, + "LOCAL_LDFLAGS": {"ldflags", bpparser.List}, + "LOCAL_REQUIRED_MODULES": {"required", bpparser.List}, + "LOCAL_MODULE_TAGS": {"tags", bpparser.List}, + "LOCAL_LDLIBS": {"host_ldlibs", bpparser.List}, + "LOCAL_CLANG_CFLAGS": {"clang_cflags", bpparser.List}, + "LOCAL_YACCFLAGS": {"yaccflags", bpparser.List}, - "LOCAL_JAVA_RESOURCE_DIRS": "java_resource_dirs", - "LOCAL_JAVACFLAGS": "javacflags", - "LOCAL_DX_FLAGS": "dxflags", - "LOCAL_JAVA_LIBRARIES": "java_libs", - "LOCAL_STATIC_JAVA_LIBRARIES": "java_static_libs", - "LOCAL_AIDL_INCLUDES": "aidl_includes", - "LOCAL_AAPT_FLAGS": "aaptflags", - "LOCAL_PACKAGE_SPLITS": "package_splits", -} + "LOCAL_JAVA_RESOURCE_DIRS": {"java_resource_dirs", bpparser.List}, + "LOCAL_JAVACFLAGS": {"javacflags", bpparser.List}, + "LOCAL_DX_FLAGS": {"dxflags", bpparser.List}, + "LOCAL_JAVA_LIBRARIES": {"java_libs", bpparser.List}, + "LOCAL_STATIC_JAVA_LIBRARIES": {"java_static_libs", bpparser.List}, + "LOCAL_AIDL_INCLUDES": {"aidl_includes", bpparser.List}, + "LOCAL_AAPT_FLAGS": {"aaptflags", bpparser.List}, + "LOCAL_PACKAGE_SPLITS": {"package_splits", bpparser.List}, -var boolProperties = map[string]string{ - "LOCAL_IS_HOST_MODULE": "host", - "LOCAL_CLANG": "clang", - "LOCAL_FORCE_STATIC_EXECUTABLE": "static", - "LOCAL_ADDRESS_SANITIZER": "asan", - "LOCAL_NATIVE_COVERAGE": "native_coverage", - "LOCAL_NO_CRT": "nocrt", - "LOCAL_ALLOW_UNDEFINED_SYMBOLS": "allow_undefined_symbols", - "LOCAL_RTTI_FLAG": "rtti", + // Bool properties + "LOCAL_IS_HOST_MODULE": {"host", bpparser.Bool}, + "LOCAL_CLANG": {"clang", bpparser.Bool}, + "LOCAL_FORCE_STATIC_EXECUTABLE": {"static", bpparser.Bool}, + "LOCAL_ADDRESS_SANITIZER": {"asan", bpparser.Bool}, + "LOCAL_NATIVE_COVERAGE": {"native_coverage", bpparser.Bool}, + "LOCAL_NO_CRT": {"nocrt", bpparser.Bool}, + "LOCAL_ALLOW_UNDEFINED_SYMBOLS": {"allow_undefined_symbols", bpparser.Bool}, + "LOCAL_RTTI_FLAG": {"rtti", bpparser.Bool}, - "LOCAL_NO_STANDARD_LIBRARIES": "no_standard_libraries", + "LOCAL_NO_STANDARD_LIBRARIES": {"no_standard_libraries", bpparser.Bool}, - "LOCAL_EXPORT_PACKAGE_RESOURCES": "export_package_resources", + "LOCAL_EXPORT_PACKAGE_RESOURCES": {"export_package_resources", bpparser.Bool}, } var deleteProperties = map[string]struct{}{ @@ -130,16 +134,16 @@ func allSubdirJavaFiles(args []string) string { } var moduleTypes = map[string]string{ - "BUILD_SHARED_LIBRARY": "cc_library_shared", - "BUILD_STATIC_LIBRARY": "cc_library_static", - "BUILD_HOST_SHARED_LIBRARY": "cc_library_host_shared", - "BUILD_HOST_STATIC_LIBRARY": "cc_library_host_static", - "BUILD_EXECUTABLE": "cc_binary", - "BUILD_HOST_EXECUTABLE": "cc_binary_host", - "BUILD_NATIVE_TEST": "cc_test", - "BUILD_HOST_NATIVE_TEST": "cc_test_host", - "BUILD_NATIVE_BENCHMARK": "cc_benchmark", - "BUILD_HOST_NATIVE_BENCHMARK": "cc_benchmark_host", + "BUILD_SHARED_LIBRARY": "cc_library_shared", + "BUILD_STATIC_LIBRARY": "cc_library_static", + "BUILD_HOST_SHARED_LIBRARY": "cc_library_host_shared", + "BUILD_HOST_STATIC_LIBRARY": "cc_library_host_static", + "BUILD_EXECUTABLE": "cc_binary", + "BUILD_HOST_EXECUTABLE": "cc_binary_host", + "BUILD_NATIVE_TEST": "cc_test", + "BUILD_HOST_NATIVE_TEST": "cc_test_host", + "BUILD_NATIVE_BENCHMARK": "cc_benchmark", + "BUILD_HOST_NATIVE_BENCHMARK": "cc_benchmark_host", "BUILD_JAVA_LIBRARY": "java_library", "BUILD_STATIC_JAVA_LIBRARY": "java_library_static", @@ -152,8 +156,8 @@ var moduleTypes = map[string]string{ var soongModuleTypes = map[string]bool{} -func androidScope() parser.Scope { - globalScope := parser.NewScope(nil) +func androidScope() mkparser.Scope { + globalScope := mkparser.NewScope(nil) globalScope.Set("CLEAR_VARS", clear_vars) globalScope.SetFunc("my-dir", mydir) globalScope.SetFunc("all-java-files-under", allJavaFilesUnder) diff --git a/androidmk/cmd/androidmk/androidmk.go b/androidmk/cmd/androidmk/androidmk.go index 555e59300..799b75868 100644 --- a/androidmk/cmd/androidmk/androidmk.go +++ b/androidmk/cmd/androidmk/androidmk.go @@ -231,12 +231,8 @@ func handleAssignment(file *bpFile, assignment mkparser.Assignment, c *condition } var err error - if prop, ok := stringProperties[name]; ok { - err = setVariable(file, assignment.Value, assignment.Type == "+=", prop, bpparser.String, true, class, suffix) - } else if prop, ok := listProperties[name]; ok { - err = setVariable(file, assignment.Value, assignment.Type == "+=", prop, bpparser.List, true, class, suffix) - } else if prop, ok := boolProperties[name]; ok { - err = setVariable(file, assignment.Value, assignment.Type == "+=", prop, bpparser.Bool, true, class, suffix) + if prop, ok := standardProperties[name]; ok { + err = setVariable(file, assignment.Value, assignment.Type == "+=", prop.string, prop.ValueType, true, class, suffix) } else if _, ok := deleteProperties[name]; ok { return } else {