Build the proguard dict zip without PACKAGING intermediates

Before, as each module was built, it would dump its proguard-related
files into the PACKAGING folder. Then the rule for the final distable
zip would zip up this whole folder. This means that if you built a
module that was not part of the system, and then rebuilt the final
zip, it would erronously include more proguard files than necessary.
This problem was worked around by relying on CI to run `m installclean`
every time.

Now, the zip proguard files always include the same information.

This also makes it so that when you build a module, its proguard files
are not copied to the PACKAGING folder, making builds that don't
build the final proguard zips slightly faster.

Bug: 205632228
Test: diff'd proguard-dict.zip, proguard-dict-mapping.textproto, and proguard-usage.zip before/after this cl on sdk_phone_x86_64. They have diffs, but only in the order of files / lines.

Change-Id: I98c02e1eb117c337ba9b98f04ad486597eb9bb86
This commit is contained in:
Cole Faust
2023-08-30 15:57:16 -07:00
parent 401be560de
commit b35231ece0
5 changed files with 83 additions and 108 deletions

View File

@@ -6951,29 +6951,34 @@ endif # EMMA_INSTRUMENT=true
# finding the appropriate dictionary to deobfuscate a stack trace frame. # finding the appropriate dictionary to deobfuscate a stack trace frame.
# #
# The path to the zip file containing proguard dictionaries.
PROGUARD_DICT_ZIP := $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-dict.zip
# The path to the zip file containing mappings from dictionary hashes to filenames.
PROGUARD_DICT_MAPPING := $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-dict-mapping.textproto
.KATI_READONLY := PROGUARD_DICT_ZIP PROGUARD_DICT_MAPPING
# For apps_only build we'll establish the dependency later in build/make/core/main.mk.
ifeq (,$(TARGET_BUILD_UNBUNDLED)) ifeq (,$(TARGET_BUILD_UNBUNDLED))
$(PROGUARD_DICT_ZIP): $(INTERNAL_ALLIMAGES_FILES) $(updater_dep) _proguard_dict_zip_modules := $(call product-installed-modules,$(INTERNAL_PRODUCT))
else
_proguard_dict_zip_modules := $(unbundled_build_modules)
endif endif
$(PROGUARD_DICT_ZIP): PRIVATE_PACKAGING_DIR := $(call intermediates-dir-for,PACKAGING,proguard_dictionary)
$(PROGUARD_DICT_ZIP): PRIVATE_MAPPING_PACKAGING_DIR := $(call intermediates-dir-for,PACKAGING,proguard_dictionary_mapping) # The path to the zip file containing proguard dictionaries.
$(PROGUARD_DICT_ZIP): PRIVATE_LIST_FILE := $(call intermediates-dir-for,PACKAGING,proguard_dictionary_filelist)/filelist PROGUARD_DICT_ZIP :=$= $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-dict.zip
$(PROGUARD_DICT_ZIP): $(SOONG_ZIP) $(SYMBOLS_MAP) $(PROGUARD_DICT_ZIP): PRIVATE_SOONG_ZIP_ARGUMENTS := $(foreach m,$(_proguard_dict_zip_modules),$(ALL_MODULES.$(m).PROGUARD_DICTIONARY_SOONG_ZIP_ARGUMENTS))
$(PROGUARD_DICT_ZIP): $(SOONG_ZIP) $(foreach m,$(_proguard_dict_zip_modules),$(ALL_MODULES.$(m).PROGUARD_DICTIONARY_FILES))
@echo "Packaging Proguard obfuscation dictionary files." @echo "Packaging Proguard obfuscation dictionary files."
rm -rf $@ $(PRIVATE_LIST_FILE) # Zip all of the files in PROGUARD_DICTIONARY_FILES.
mkdir -p $(PRIVATE_PACKAGING_DIR) $(PRIVATE_MAPPING_PACKAGING_DIR) $(dir $(PRIVATE_LIST_FILE)) echo -n > $@.tmparglist
# Zip all of the files in the proguard dictionary directory. $(foreach arg,$(PRIVATE_SOONG_ZIP_ARGUMENTS),printf "%s\n" "$(arg)" >> $@.tmparglist$(newline))
$(SOONG_ZIP) --ignore_missing_files -d -o $@ -C $(PRIVATE_PACKAGING_DIR) -D $(PRIVATE_PACKAGING_DIR) $(SOONG_ZIP) -d -o $@ @$@.tmparglist
# Find all of the files in the proguard dictionary mapping directory and merge them into the mapping textproto. rm -f $@.tmparglist
# Strip the PRIVATE_PACKAGING_DIR off the filenames to match soong_zip's -C argument.
$(hide) find -L $(PRIVATE_MAPPING_PACKAGING_DIR) -type f | sort >$(PRIVATE_LIST_FILE) # The path to the zip file containing mappings from dictionary hashes to filenames.
$(SYMBOLS_MAP) -merge $(PROGUARD_DICT_MAPPING) -strip_prefix $(PRIVATE_PACKAGING_DIR)/ -ignore_missing_files @$(PRIVATE_LIST_FILE) PROGUARD_DICT_MAPPING :=$= $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-dict-mapping.textproto
$(PROGUARD_DICT_ZIP): .KATI_IMPLICIT_OUTPUTS := $(PROGUARD_DICT_MAPPING) _proguard_dict_mapping_files := $(foreach m,$(_proguard_dict_zip_modules),$(ALL_MODULES.$(m).PROGUARD_DICTIONARY_MAPPING))
$(PROGUARD_DICT_MAPPING): PRIVATE_MAPPING_FILES := $(_proguard_dict_mapping_files)
$(PROGUARD_DICT_MAPPING): $(SYMBOLS_MAP) $(_proguard_dict_mapping_files)
@echo "Packaging Proguard obfuscation dictionary mapping files."
# Merge all the mapping files together
echo -n > $@.tmparglist
$(foreach mf,$(PRIVATE_MAPPING_FILES),echo "$(mf)" >> $@.tmparglist$(newline))
$(SYMBOLS_MAP) -merge $(PROGUARD_DICT_MAPPING) @$@.tmparglist
rm -f $@.tmparglist
$(call declare-1p-container,$(PROGUARD_DICT_ZIP),) $(call declare-1p-container,$(PROGUARD_DICT_ZIP),)
ifeq (,$(TARGET_BUILD_UNBUNDLED)) ifeq (,$(TARGET_BUILD_UNBUNDLED))
@@ -6983,31 +6988,19 @@ endif
#------------------------------------------------------------------ #------------------------------------------------------------------
# A zip of Proguard usage files. # A zip of Proguard usage files.
# #
PROGUARD_USAGE_ZIP := $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-usage.zip PROGUARD_USAGE_ZIP :=$= $(PRODUCT_OUT)/$(TARGET_PRODUCT)-proguard-usage.zip
# For apps_only build we'll establish the dependency later in build/make/core/main.mk. _proguard_usage_zips := $(foreach m,$(_proguard_dict_zip_modules),$(ALL_MODULES.$(m).PROGUARD_USAGE_ZIP))
ifeq (,$(TARGET_BUILD_UNBUNDLED)) $(PROGUARD_USAGE_ZIP): PRIVATE_ZIPS := $(_proguard_usage_zips)
$(PROGUARD_USAGE_ZIP): \ $(PROGUARD_USAGE_ZIP): $(MERGE_ZIPS) $(_proguard_usage_zips)
$(INSTALLED_SYSTEMIMAGE_TARGET) \
$(INSTALLED_RAMDISK_TARGET) \
$(INSTALLED_BOOTIMAGE_TARGET) \
$(INSTALLED_INIT_BOOT_IMAGE_TARGET) \
$(INSTALLED_USERDATAIMAGE_TARGET) \
$(INSTALLED_VENDORIMAGE_TARGET) \
$(INSTALLED_PRODUCTIMAGE_TARGET) \
$(INSTALLED_SYSTEM_EXTIMAGE_TARGET) \
$(INSTALLED_ODMIMAGE_TARGET) \
$(INSTALLED_VENDOR_DLKMIMAGE_TARGET) \
$(INSTALLED_ODM_DLKMIMAGE_TARGET) \
$(INSTALLED_SYSTEM_DLKMIMAGE_TARGET) \
$(updater_dep)
endif
$(PROGUARD_USAGE_ZIP): PRIVATE_LIST_FILE := $(call intermediates-dir-for,PACKAGING,proguard_usage.zip)/filelist
$(PROGUARD_USAGE_ZIP): PRIVATE_PACKAGING_DIR := $(call intermediates-dir-for,PACKAGING,proguard_usage)
$(PROGUARD_USAGE_ZIP): $(MERGE_ZIPS)
@echo "Packaging Proguard usage files." @echo "Packaging Proguard usage files."
mkdir -p $(dir $@) $(PRIVATE_PACKAGING_DIR) $(dir $(PRIVATE_LIST_FILE)) echo -n > $@.tmparglist
find $(PRIVATE_PACKAGING_DIR) -name proguard_usage.zip > $(PRIVATE_LIST_FILE) $(foreach z,$(PRIVATE_ZIPS),echo "$(z)" >> $@.tmparglist$(newline))
$(MERGE_ZIPS) $@ @$(PRIVATE_LIST_FILE) $(MERGE_ZIPS) $@ @$@.tmparglist
rm -rf $@.tmparglist
_proguard_dict_mapping_files :=
_proguard_usage_zips :=
_proguard_dict_zip_modules :=
$(call declare-1p-container,$(PROGUARD_USAGE_ZIP),) $(call declare-1p-container,$(PROGUARD_USAGE_ZIP),)
ifeq (,$(TARGET_BUILD_UNBUNDLED)) ifeq (,$(TARGET_BUILD_UNBUNDLED))

View File

@@ -3428,16 +3428,6 @@ $(2): $(1)
.KATI_RESTAT: $(2) .KATI_RESTAT: $(2)
endef endef
# Returns the directory to copy proguard dictionaries into
define local-proguard-dictionary-directory
$(call intermediates-dir-for,PACKAGING,proguard_dictionary)/out/target/common/obj/$(LOCAL_MODULE_CLASS)/$(LOCAL_MODULE)_intermediates
endef
# Returns the directory to copy proguard dictionary mappings into
define local-proguard-dictionary-mapping-directory
$(call intermediates-dir-for,PACKAGING,proguard_dictionary_mapping)/out/target/common/obj/$(LOCAL_MODULE_CLASS)/$(LOCAL_MODULE)_intermediates
endef
########################################################### ###########################################################
## Commands to call R8 ## Commands to call R8

View File

@@ -1232,9 +1232,7 @@ define auto-included-modules
endef endef
# Lists most of the files a particular product installs, including: # Lists the modules particular product installs.
# - PRODUCT_PACKAGES, and their LOCAL_REQUIRED_MODULES
# - PRODUCT_COPY_FILES
# The base list of modules to build for this product is specified # The base list of modules to build for this product is specified
# by the appropriate product definition file, which was included # by the appropriate product definition file, which was included
# by product_config.mk. # by product_config.mk.
@@ -1246,8 +1244,7 @@ endef
# Name resolution for LOCAL_REQUIRED_MODULES: # Name resolution for LOCAL_REQUIRED_MODULES:
# See the select-bitness-of-required-modules definition. # See the select-bitness-of-required-modules definition.
# $(1): product makefile # $(1): product makefile
define product-installed-modules
define product-installed-files
$(eval _pif_modules := \ $(eval _pif_modules := \
$(call get-product-var,$(1),PRODUCT_PACKAGES) \ $(call get-product-var,$(1),PRODUCT_PACKAGES) \
$(if $(filter eng,$(tags_to_install)),$(call get-product-var,$(1),PRODUCT_PACKAGES_ENG)) \ $(if $(filter eng,$(tags_to_install)),$(call get-product-var,$(1),PRODUCT_PACKAGES_ENG)) \
@@ -1264,7 +1261,14 @@ define product-installed-files
$(eval ### Resolve the :32 :64 module name) \ $(eval ### Resolve the :32 :64 module name) \
$(eval _pif_modules := $(sort $(call resolve-bitness-for-modules,TARGET,$(_pif_modules)))) \ $(eval _pif_modules := $(sort $(call resolve-bitness-for-modules,TARGET,$(_pif_modules)))) \
$(call expand-required-modules,_pif_modules,$(_pif_modules),$(_pif_overrides)) \ $(call expand-required-modules,_pif_modules,$(_pif_modules),$(_pif_overrides)) \
$(filter-out $(HOST_OUT_ROOT)/%,$(call module-installed-files, $(_pif_modules))) \ $(_pif_modules)
endef
# Lists most of the files a particular product installs.
# It gives all the installed files for all modules returned by product-installed-modules,
# and also includes PRODUCT_COPY_FILES.
define product-installed-files
$(filter-out $(HOST_OUT_ROOT)/%,$(call module-installed-files, $(call product-installed-modules,$(1)))) \
$(call resolve-product-relative-paths,\ $(call resolve-product-relative-paths,\
$(foreach cf,$(call get-product-var,$(1),PRODUCT_COPY_FILES),$(call word-colon,2,$(cf)))) $(foreach cf,$(call get-product-var,$(1),PRODUCT_COPY_FILES),$(call word-colon,2,$(cf))))
endef endef
@@ -1437,6 +1441,16 @@ ifdef is_sdk_build
$(warning $(ALL_MODULES.$(m).MAKEFILE): Module '$(m)' in PRODUCT_PACKAGES_TESTS has nothing to install!))) $(warning $(ALL_MODULES.$(m).MAKEFILE): Module '$(m)' in PRODUCT_PACKAGES_TESTS has nothing to install!)))
endif endif
ifneq ($(TARGET_BUILD_APPS),)
# If this build is just for apps, only build apps and not the full system by default.
ifneq ($(filter all,$(TARGET_BUILD_APPS)),)
# If they used the magic goal "all" then build all apps in the source tree.
unbundled_build_modules := $(foreach m,$(sort $(ALL_MODULES)),$(if $(filter APPS,$(ALL_MODULES.$(m).CLASS)),$(m)))
else
unbundled_build_modules := $(sort $(TARGET_BUILD_APPS))
endif
endif
# build/make/core/Makefile contains extra stuff that we don't want to pollute this # build/make/core/Makefile contains extra stuff that we don't want to pollute this
# top-level makefile with. It expects that ALL_DEFAULT_INSTALLED_MODULES # top-level makefile with. It expects that ALL_DEFAULT_INSTALLED_MODULES
# contains everything that's built during the current make, but it also further # contains everything that's built during the current make, but it also further
@@ -1712,14 +1726,6 @@ ifeq ($(HOST_OS),darwin)
else ifneq ($(TARGET_BUILD_APPS),) else ifneq ($(TARGET_BUILD_APPS),)
# If this build is just for apps, only build apps and not the full system by default. # If this build is just for apps, only build apps and not the full system by default.
unbundled_build_modules :=
ifneq ($(filter all,$(TARGET_BUILD_APPS)),)
# If they used the magic goal "all" then build all apps in the source tree.
unbundled_build_modules := $(foreach m,$(sort $(ALL_MODULES)),$(if $(filter APPS,$(ALL_MODULES.$(m).CLASS)),$(m)))
else
unbundled_build_modules := $(sort $(TARGET_BUILD_APPS))
endif
# Dist the installed files if they exist, except the installed symlinks. dist-for-goals emits # Dist the installed files if they exist, except the installed symlinks. dist-for-goals emits
# `cp src dest` commands, which will fail to copy dangling symlinks. # `cp src dest` commands, which will fail to copy dangling symlinks.
apps_only_installed_files := $(foreach m,$(unbundled_build_modules),\ apps_only_installed_files := $(foreach m,$(unbundled_build_modules),\

View File

@@ -102,31 +102,24 @@ ifdef LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR
endif endif
ifdef LOCAL_SOONG_PROGUARD_DICT ifdef LOCAL_SOONG_PROGUARD_DICT
my_proguard_dictionary_directory := $(local-proguard-dictionary-directory)
my_proguard_dictionary_mapping_directory := $(local-proguard-dictionary-mapping-directory)
$(eval $(call copy-one-file,$(LOCAL_SOONG_PROGUARD_DICT),\
$(intermediates.COMMON)/proguard_dictionary))
$(eval $(call copy-r8-dictionary-file-with-mapping,\ $(eval $(call copy-r8-dictionary-file-with-mapping,\
$(LOCAL_SOONG_PROGUARD_DICT),\ $(LOCAL_SOONG_PROGUARD_DICT),\
$(my_proguard_dictionary_directory)/proguard_dictionary,\ $(intermediates.COMMON)/proguard_dictionary,\
$(my_proguard_dictionary_mapping_directory)/proguard_dictionary.textproto)) $(intermediates.COMMON)/proguard_dictionary.textproto))
$(eval $(call copy-one-file,$(LOCAL_SOONG_CLASSES_JAR),\
$(my_proguard_dictionary_directory)/classes.jar)) ALL_MODULES.$(my_register_name).PROGUARD_DICTIONARY_FILES := \
$(call add-dependency,$(LOCAL_BUILT_MODULE),\ $(intermediates.COMMON)/proguard_dictionary \
$(intermediates.COMMON)/proguard_dictionary) $(LOCAL_SOONG_CLASSES_JAR)
$(call add-dependency,$(LOCAL_BUILT_MODULE),\ ALL_MODULES.$(my_register_name).PROGUARD_DICTIONARY_SOONG_ZIP_ARGUMENTS := \
$(my_proguard_dictionary_directory)/proguard_dictionary) -e out/target/common/obj/$(LOCAL_MODULE_CLASS)/$(LOCAL_MODULE)_intermediates/proguard_dictionary \
$(call add-dependency,$(LOCAL_BUILT_MODULE),\ -f $(intermediates.COMMON)/proguard_dictionary \
$(my_proguard_dictionary_mapping_directory)/proguard_dictionary.textproto) -e out/target/common/obj/$(LOCAL_MODULE_CLASS)/$(LOCAL_MODULE)_intermediates/classes.jar \
$(call add-dependency,$(LOCAL_BUILT_MODULE),\ -f $(LOCAL_SOONG_CLASSES_JAR)
$(my_proguard_dictionary_directory)/classes.jar) ALL_MODULES.$(my_register_name).PROGUARD_DICTIONARY_MAPPING := $(intermediates.COMMON)/proguard_dictionary.textproto
endif endif
ifdef LOCAL_SOONG_PROGUARD_USAGE_ZIP ifdef LOCAL_SOONG_PROGUARD_USAGE_ZIP
$(eval $(call copy-one-file,$(LOCAL_SOONG_PROGUARD_USAGE_ZIP),\ ALL_MODULES.$(my_register_name).PROGUARD_USAGE_ZIP := $(LOCAL_SOONG_PROGUARD_USAGE_ZIP)
$(call local-packaging-dir,proguard_usage)/proguard_usage.zip))
$(call add-dependency,$(LOCAL_BUILT_MODULE),\
$(call local-packaging-dir,proguard_usage)/proguard_usage.zip)
endif endif
ifdef LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE ifdef LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE

View File

@@ -62,31 +62,24 @@ ifdef LOCAL_SOONG_JACOCO_REPORT_CLASSES_JAR
endif endif
ifdef LOCAL_SOONG_PROGUARD_DICT ifdef LOCAL_SOONG_PROGUARD_DICT
my_proguard_dictionary_directory := $(local-proguard-dictionary-directory)
my_proguard_dictionary_mapping_directory := $(local-proguard-dictionary-mapping-directory)
$(eval $(call copy-one-file,$(LOCAL_SOONG_PROGUARD_DICT),\
$(intermediates.COMMON)/proguard_dictionary))
$(eval $(call copy-r8-dictionary-file-with-mapping,\ $(eval $(call copy-r8-dictionary-file-with-mapping,\
$(LOCAL_SOONG_PROGUARD_DICT),\ $(LOCAL_SOONG_PROGUARD_DICT),\
$(my_proguard_dictionary_directory)/proguard_dictionary,\ $(intermediates.COMMON)/proguard_dictionary,\
$(my_proguard_dictionary_mapping_directory)/proguard_dictionary.textproto)) $(intermediates.COMMON)/proguard_dictionary.textproto))
$(eval $(call copy-one-file,$(LOCAL_SOONG_CLASSES_JAR),\
$(my_proguard_dictionary_directory)/classes.jar)) ALL_MODULES.$(my_register_name).PROGUARD_DICTIONARY_FILES := \
$(call add-dependency,$(common_javalib.jar),\ $(intermediates.COMMON)/proguard_dictionary \
$(intermediates.COMMON)/proguard_dictionary) $(LOCAL_SOONG_CLASSES_JAR)
$(call add-dependency,$(common_javalib.jar),\ ALL_MODULES.$(my_register_name).PROGUARD_DICTIONARY_SOONG_ZIP_ARGUMENTS := \
$(my_proguard_dictionary_directory)/proguard_dictionary) -e out/target/common/obj/$(LOCAL_MODULE_CLASS)/$(LOCAL_MODULE)_intermediates/proguard_dictionary \
$(call add-dependency,$(common_javalib.jar),\ -f $(intermediates.COMMON)/proguard_dictionary \
$(my_proguard_dictionary_mapping_directory)/proguard_dictionary.textproto) -e out/target/common/obj/$(LOCAL_MODULE_CLASS)/$(LOCAL_MODULE)_intermediates/classes.jar \
$(call add-dependency,$(common_javalib.jar),\ -f $(LOCAL_SOONG_CLASSES_JAR)
$(my_proguard_dictionary_directory)/classes.jar) ALL_MODULES.$(my_register_name).PROGUARD_DICTIONARY_MAPPING := $(intermediates.COMMON)/proguard_dictionary.textproto
endif endif
ifdef LOCAL_SOONG_PROGUARD_USAGE_ZIP ifdef LOCAL_SOONG_PROGUARD_USAGE_ZIP
$(eval $(call copy-one-file,$(LOCAL_SOONG_PROGUARD_USAGE_ZIP),\ ALL_MODULES.$(my_register_name).PROGUARD_USAGE_ZIP := $(LOCAL_SOONG_PROGUARD_USAGE_ZIP)
$(call local-packaging-dir,proguard_usage)/proguard_usage.zip))
$(call add-dependency,$(common_javalib.jar),\
$(call local-packaging-dir,proguard_usage)/proguard_usage.zip)
endif endif