From 6b60b2151eaae27afdd3ae3f86660f5469fe3754 Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Thu, 28 Jun 2018 11:19:42 +0100 Subject: [PATCH] Refactor hiddenapi rules to share common code Java modules built with make and Soong currently invoke `hiddenapi` with their own rules. Refactor the definitions so that Soong uses make's definition. This will be useful for a subsequent CL which needs to invoke `hiddenapi` on all boot dex files simultaneously. Bug: 79409988 Test: m Change-Id: I85105e650605d37c3ee8200d7f0d40c297756fcb --- core/definitions.mk | 49 ++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/core/definitions.mk b/core/definitions.mk index 9dd7699c2..b8ab84d52 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -2835,37 +2835,40 @@ done \ fi endef +# Copy dex files, invoking $(HIDDENAPI) on them in the process. define hiddenapi-copy-dex-files $(2): $(1) $(HIDDENAPI) $(INTERNAL_PLATFORM_HIDDENAPI_LIGHT_GREYLIST) \ $(INTERNAL_PLATFORM_HIDDENAPI_DARK_GREYLIST) $(INTERNAL_PLATFORM_HIDDENAPI_BLACKLIST) @rm -rf $(dir $(2)) @mkdir -p $(dir $(2)) - find $(dir $(1)) -maxdepth 1 -name "classes*.dex" | sort | \ - xargs -I{} cp -f {} $(dir $(2)) - find $(dir $(2)) -name "classes*.dex" | sort | sed 's/^/--dex=/' | \ - xargs $(HIDDENAPI) encode \ - --light-greylist=$(INTERNAL_PLATFORM_HIDDENAPI_LIGHT_GREYLIST) \ - --dark-greylist=$(INTERNAL_PLATFORM_HIDDENAPI_DARK_GREYLIST) \ - --blacklist=$(INTERNAL_PLATFORM_HIDDENAPI_BLACKLIST) + find $(dir $(1)) -maxdepth 1 -name "classes*.dex" | xargs -I{} cp -f {} $(dir $(2))/; \ + find $(dir $(2)) -maxdepth 1 -name "classes*.dex" | sort | sed 's/^/--dex=/' \ + | xargs $(HIDDENAPI) encode \ + --light-greylist=$(INTERNAL_PLATFORM_HIDDENAPI_LIGHT_GREYLIST) \ + --dark-greylist=$(INTERNAL_PLATFORM_HIDDENAPI_DARK_GREYLIST) \ + --blacklist=$(INTERNAL_PLATFORM_HIDDENAPI_BLACKLIST) endef +# File names for intermediate dex files of `hiddenapi-copy-soong-jar`. +hiddenapi-soong-input-dex = $(dir $(1))/hiddenapi/dex-input/classes.dex +hiddenapi-soong-output-dex = $(dir $(1))/hiddenapi/dex-output/classes.dex + +# Decompress a JAR with dex files, invoke $(HIDDENAPI) on them and compress again. define hiddenapi-copy-soong-jar -$(2): PRIVATE_FOLDER := $(dir $(2))dex-hiddenapi -$(2): $(1) $(HIDDENAPI) $(SOONG_ZIP) $(MERGE_ZIPS) $(INTERNAL_PLATFORM_HIDDENAPI_LIGHT_GREYLIST) \ - $(INTERNAL_PLATFORM_HIDDENAPI_DARK_GREYLIST) $(INTERNAL_PLATFORM_HIDDENAPI_BLACKLIST) - @echo "Hidden API: $$@" - $$(copy-file-to-target) - @rm -rf $${PRIVATE_FOLDER} - @mkdir -p $${PRIVATE_FOLDER} - unzip -q $(2) 'classes*.dex' -d $${PRIVATE_FOLDER} - find $${PRIVATE_FOLDER} -name "classes*.dex" | sort | sed 's/^/--dex=/' | \ - xargs $(HIDDENAPI) encode \ - --light-greylist=$(INTERNAL_PLATFORM_HIDDENAPI_LIGHT_GREYLIST) \ - --dark-greylist=$(INTERNAL_PLATFORM_HIDDENAPI_DARK_GREYLIST) \ - --blacklist=$(INTERNAL_PLATFORM_HIDDENAPI_BLACKLIST) - $(SOONG_ZIP) -o $${PRIVATE_FOLDER}/classes.dex.jar -C $${PRIVATE_FOLDER} -D $${PRIVATE_FOLDER} - $(MERGE_ZIPS) -D -zipToNotStrip $${PRIVATE_FOLDER}/classes.dex.jar -stripFile "classes*.dex" \ - $(2) $${PRIVATE_FOLDER}/classes.dex.jar $(1) +$(call hiddenapi-soong-input-dex,$(2)): $(1) + @rm -rf `dirname $$@` + @mkdir -p `dirname $$@` + unzip -o -DD -q $(1) 'classes*.dex' -d `dirname $$@` + +$(call hiddenapi-copy-dex-files,\ + $(call hiddenapi-soong-input-dex,$(2)),\ + $(call hiddenapi-soong-output-dex,$(2))) + +$(2): OUTPUT_DIR := $(dir $(call hiddenapi-soong-output-dex,$(2))) +$(2): OUTPUT_JAR := $(dir $(call hiddenapi-soong-output-dex,$(2)))classes.jar +$(2): $(1) $(call hiddenapi-soong-output-dex,$(2)) | $(SOONG_ZIP) $(MERGE_ZIPS) + $(SOONG_ZIP) -o $${OUTPUT_JAR} -C $${OUTPUT_DIR} -D $${OUTPUT_DIR} + $(MERGE_ZIPS) -D -zipToNotStrip $${OUTPUT_JAR} -stripFile "classes*.dex" $(2) $${OUTPUT_JAR} $(1) endef ###########################################################