From 85480629220c9afb0d138ff1ce5ea1ccbe66c7f7 Mon Sep 17 00:00:00 2001 From: Ying Wang Date: Thu, 9 Aug 2012 15:20:50 -0700 Subject: [PATCH] Automatically add Java resources carried by static Java libraries. Bug: 6892294 Change-Id: I3ff71ee3d7b9ccdfde6a5284cc350864fbffa71f --- core/definitions.mk | 16 +++++++++++++++- core/host_java_library.mk | 1 + core/java_library.mk | 1 + core/package.mk | 1 + 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/core/definitions.mk b/core/definitions.mk index bf8ce5828..bb645b4e0 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -1484,7 +1484,6 @@ endef define transform-java-to-classes.jar @echo "target Java: $(PRIVATE_MODULE) ($(PRIVATE_CLASS_INTERMEDIATES_DIR))" $(call compile-java,$(TARGET_JAVAC),$(PRIVATE_BOOTCLASSPATH)) -$(hide) rm -rf $(PRIVATE_CLASS_INTERMEDIATES_DIR) endef # Override the above definitions if we want to do incremetal javac @@ -1617,12 +1616,27 @@ cp $(PRIVATE_DEX_FILE) $$_adtp_classes_dex && \ $(AAPT) add -k $@ $$_adtp_classes_dex && rm -f $$_adtp_classes_dex) endef +# Add java resources added by the current module. +# define add-java-resources-to-package $(call dump-words-to-file, $(PRIVATE_EXTRA_JAR_ARGS), $(dir $@)jar-arg-list) $(hide) jar uf $@ @$(dir $@)jar-arg-list @rm -f $(dir $@)jar-arg-list endef +# Add java resources carried by static Java libraries. +# +define add-carried-java-resources +$(hide) if [ -d $(PRIVATE_CLASS_INTERMEDIATES_DIR) ] ; then \ + java_res_jar_flags=$$(find $(PRIVATE_CLASS_INTERMEDIATES_DIR) -type f -a -not -name "*.class" \ + | sed -e "s?^$(PRIVATE_CLASS_INTERMEDIATES_DIR)/? -C $(PRIVATE_CLASS_INTERMEDIATES_DIR) ?"); \ + if [ -n "$$java_res_jar_flags" ] ; then \ + echo $$java_res_jar_flags >$(dir $@)java_res_jar_flags; \ + jar uf $@ $$java_res_jar_flags; \ + fi; \ +fi +endef + # Sign a package using the specified key/cert. # define sign-package diff --git a/core/host_java_library.mk b/core/host_java_library.mk index 6cc0b1f4e..5930da62b 100644 --- a/core/host_java_library.mk +++ b/core/host_java_library.mk @@ -82,6 +82,7 @@ $(LOCAL_BUILT_MODULE): $(built_dex) $(java_resource_sources) | $(AAPT) @echo "Host Jar: $(PRIVATE_MODULE) ($@)" $(create-empty-package) $(add-dex-to-package) + $(add-carried-java-resources) ifneq ($(extra_jar_args),) $(add-java-resources-to-package) endif diff --git a/core/java_library.mk b/core/java_library.mk index 06cdfc45e..58d9ba656 100644 --- a/core/java_library.mk +++ b/core/java_library.mk @@ -67,6 +67,7 @@ $(common_javalib.jar) : $(built_dex) $(java_resource_sources) | $(AAPT) @echo "target Jar: $(PRIVATE_MODULE) ($@)" $(create-empty-package) $(add-dex-to-package) + $(add-carried-java-resources) ifneq ($(extra_jar_args),) $(add-java-resources-to-package) endif diff --git a/core/package.mk b/core/package.mk index e1b7da3dd..dfa66cc4a 100644 --- a/core/package.mk +++ b/core/package.mk @@ -376,6 +376,7 @@ endif ifneq ($(full_classes_jar),) $(add-dex-to-package) endif + $(add-carried-java-resources) ifneq ($(extra_jar_args),) $(add-java-resources-to-package) endif