summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYing Wang <wangying@google.com>2012-06-19 14:25:14 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-06-19 14:25:14 -0700
commit0872a010659d20633f07f4ef54cf61f8e4b6e030 (patch)
tree2a31fdf0911d20c2836fd86edb98bc24c50d646f
parent03bb0851d6a86ac51becaa132f96ed1d8f4b604c (diff)
parentae25ec1bcdeb028a2db3103abdf1f22768928f0a (diff)
downloadbuild-0872a010659d20633f07f4ef54cf61f8e4b6e030.zip
build-0872a010659d20633f07f4ef54cf61f8e4b6e030.tar.gz
build-0872a010659d20633f07f4ef54cf61f8e4b6e030.tar.bz2
Merge "More flexibility to keep/remove R.class in static Java library" into jb-dev
-rw-r--r--core/clear_vars.mk4
-rw-r--r--core/definitions.mk8
-rw-r--r--core/static_java_library.mk17
3 files changed, 19 insertions, 10 deletions
diff --git a/core/clear_vars.mk b/core/clear_vars.mk
index f3929ad..5209a04 100644
--- a/core/clear_vars.mk
+++ b/core/clear_vars.mk
@@ -122,9 +122,7 @@ LOCAL_CTS_TEST_PACKAGE:=
LOCAL_CTS_TEST_RUNNER:=
LOCAL_CLANG:=
LOCAL_ADDRESS_SANITIZER:=
-# Whether to keep the generated R/Manifest classes when building static Java library
-# with Android resource. false(default), or true
-LOCAL_KEEP_R_CLASS_IN_STATIC_JAVA_LIBRARY:=
+LOCAL_JAR_EXCLUDE_FILES:=
# Trim MAKEFILE_LIST so that $(call my-dir) doesn't need to
# iterate over thousands of entries every time.
diff --git a/core/definitions.mk b/core/definitions.mk
index f3e4966..9fe0a11 100644
--- a/core/definitions.mk
+++ b/core/definitions.mk
@@ -81,6 +81,10 @@ ALL_FINDBUGS_FILES:=
# GPL module license files
ALL_GPL_MODULE_LICENSE_FILES:=
+# Generated class file names for Android resource.
+# They are escaped and quoted so can be passed safely to a bash command.
+ANDROID_RESOURCE_GENERATED_CLASSES := 'R.class' 'R$$*.class' 'Manifest.class' 'Manifest$$*.class'
+
###########################################################
## Debugging; prints a variable list to stdout
###########################################################
@@ -1515,6 +1519,10 @@ fi
$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list
$(hide) rm -f $(PRIVATE_CLASS_INTERMEDIATES_DIR)/java-source-list-uniq
$(hide) rm -f $@
+$(if $(PRIVATE_JAR_EXCLUDE_FILES), $(hide) find $(PRIVATE_CLASS_INTERMEDIATES_DIR) \
+ -name $(word 1, $(PRIVATE_JAR_EXCLUDE_FILES)) \
+ $(addprefix -o -name , $(wordlist 2, 999, $(PRIVATE_JAR_EXCLUDE_FILES))) \
+ | xargs rm -rf)
$(hide) jar $(if $(strip $(PRIVATE_JAR_MANIFEST)),-cfm,-cf) \
$@ $(PRIVATE_JAR_MANIFEST) -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) .
$(hide) mv $(PRIVATE_CLASS_INTERMEDIATES_DIR)/newstamp $(PRIVATE_CLASS_INTERMEDIATES_DIR)/stamp
diff --git a/core/static_java_library.mk b/core/static_java_library.mk
index 367ea5f..eaa74aa 100644
--- a/core/static_java_library.mk
+++ b/core/static_java_library.mk
@@ -36,14 +36,18 @@ all_resources := $(strip \
))
ifneq (,$(all_resources))
-# Those files will be excluded from the built jar.
-# The R/Manifest classes should be re-generated in the app Module instead.
-# Use '' and $ escape because they will be passed to bash.
-ifneq (true,$(LOCAL_KEEP_R_CLASS_IN_STATIC_JAVA_LIBRARY))
-LOCAL_JAR_EXCLUDE_FILES := 'R.class' 'R$$*.class' 'Manifest.class' 'Manifest$$*.class'
-endif
+# By default we should remove the R/Manifest classes from a static Java library,
+# because they will be regenerated in the app that uses it.
+# But if the static Java library will be used by a library, then we may need to
+# keep the generated classes with "LOCAL_JAR_EXCLUDE_FILES := none".
+ifndef LOCAL_JAR_EXCLUDE_FILES
+LOCAL_JAR_EXCLUDE_FILES := $(ANDROID_RESOURCE_GENERATED_CLASSES)
endif
+ifeq (none,$(LOCAL_JAR_EXCLUDE_FILES))
+LOCAL_JAR_EXCLUDE_FILES :=
endif
+endif # all_resources
+endif # LOCAL_RESOURCE_DIR
include $(BUILD_SYSTEM)/java_library.mk
@@ -107,4 +111,3 @@ endif
endif # $(all_resources) not empty
LOCAL_IS_STATIC_JAVA_LIBRARY :=
-LOCAL_JAR_EXCLUDE_FILES :=