Ying Wang | 3b81aab | 2014-05-05 16:46:52 -0700 | [diff] [blame] | 1 | # Package up modules to a zip file. |
| 2 | # It preserves the install path of the modules' installed files. |
| 3 | # |
| 4 | # Input variables: |
| 5 | # my_modules: a list of module names |
| 6 | # my_package_name: the name of the output zip file. |
Dan Willemsen | f354b17 | 2017-06-20 15:57:32 -0700 | [diff] [blame] | 7 | # my_copy_pairs: a list of extra files to install (in src:dest format) |
Dan Willemsen | 09c1107 | 2020-01-15 20:47:54 -0800 | [diff] [blame] | 8 | # Optional input variables: |
| 9 | # my_modules_strict: what happens when a module from my_modules does not exist |
| 10 | # "true": error out when a module is missing |
| 11 | # "false": print a warning when a module is missing |
| 12 | # "": defaults to false currently |
Ying Wang | 3b81aab | 2014-05-05 16:46:52 -0700 | [diff] [blame] | 13 | # Output variables: |
| 14 | # my_package_zip: the path to the output zip file. |
| 15 | # |
| 16 | # |
| 17 | |
Dan Willemsen | e19ca03 | 2017-02-24 13:14:23 -0800 | [diff] [blame] | 18 | my_makefile := $(lastword $(filter-out $(lastword $(MAKEFILE_LIST)),$(MAKEFILE_LIST))) |
Daniel Norman | 1d18d53 | 2020-03-25 14:18:42 -0700 | [diff] [blame] | 19 | |
| 20 | include $(CLEAR_VARS) |
| 21 | LOCAL_MODULE := $(my_package_name) |
Bob Badour | a8cf0e0 | 2021-03-10 23:07:45 -0800 | [diff] [blame] | 22 | LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 |
| 23 | LOCAL_LICENSE_CONDITIONS := notice |
Daniel Norman | 1d18d53 | 2020-03-25 14:18:42 -0700 | [diff] [blame] | 24 | LOCAL_MODULE_CLASS := PACKAGING |
| 25 | LOCAL_MODULE_STEM := $(my_package_name).zip |
| 26 | LOCAL_UNINSTALLABLE_MODULE := true |
| 27 | include $(BUILD_SYSTEM)/base_rules.mk |
Bob Badour | eb9431e | 2022-06-06 16:59:33 -0700 | [diff] [blame] | 28 | my_staging_dir := $(intermediates)/staging |
Daniel Norman | 1d18d53 | 2020-03-25 14:18:42 -0700 | [diff] [blame] | 29 | my_package_zip := $(LOCAL_BUILT_MODULE) |
| 30 | |
Dan Willemsen | f354b17 | 2017-06-20 15:57:32 -0700 | [diff] [blame] | 31 | my_built_modules := $(foreach p,$(my_copy_pairs),$(call word-colon,1,$(p))) |
| 32 | my_copy_pairs := $(foreach p,$(my_copy_pairs),$(call word-colon,1,$(p)):$(my_staging_dir)/$(call word-colon,2,$(p))) |
Ying Wang | 3b81aab | 2014-05-05 16:46:52 -0700 | [diff] [blame] | 33 | my_pickup_files := |
Dan Willemsen | 09c1107 | 2020-01-15 20:47:54 -0800 | [diff] [blame] | 34 | my_missing_error := |
Ying Wang | 3b81aab | 2014-05-05 16:46:52 -0700 | [diff] [blame] | 35 | |
Alex Deymo | 00dc667 | 2017-01-05 08:54:46 -0800 | [diff] [blame] | 36 | # Iterate over the modules and include their direct dependencies stated in the |
| 37 | # LOCAL_REQUIRED_MODULES. |
| 38 | my_modules_and_deps := $(my_modules) |
| 39 | $(foreach m,$(my_modules),\ |
| 40 | $(eval _explicitly_required := \ |
Dan Willemsen | 8e96a79 | 2019-04-02 14:43:32 -0700 | [diff] [blame] | 41 | $(strip $(ALL_MODULES.$(m).EXPLICITLY_REQUIRED_FROM_TARGET)\ |
| 42 | $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).EXPLICITLY_REQUIRED_FROM_TARGET)))\ |
Alex Deymo | 00dc667 | 2017-01-05 08:54:46 -0800 | [diff] [blame] | 43 | $(eval my_modules_and_deps += $(_explicitly_required))\ |
| 44 | ) |
| 45 | |
Dan Willemsen | 09c1107 | 2020-01-15 20:47:54 -0800 | [diff] [blame] | 46 | ifneq ($(filter-out true false,$(my_modules_strict)),) |
| 47 | $(shell $(call echo-error,$(my_makefile),$(my_package_name): Invalid value for 'my_module_strict' = '$(my_modules_strict)'. Valid values: 'true', 'false', '')) |
| 48 | $(error done) |
| 49 | endif |
| 50 | |
Dan Willemsen | b47d4e9 | 2017-04-08 00:31:31 -0700 | [diff] [blame] | 51 | my_missing_files = $(shell $(call echo-warning,$(my_makefile),$(my_package_name): Unknown installed file for module '$(1)')) |
Dan Willemsen | 09c1107 | 2020-01-15 20:47:54 -0800 | [diff] [blame] | 52 | ifeq ($(ALLOW_MISSING_DEPENDENCIES),true) |
| 53 | # Ignore unknown installed files on partial builds |
| 54 | my_missing_files = |
Dan Willemsen | 277972a | 2020-01-30 11:03:12 -0800 | [diff] [blame] | 55 | else ifneq ($(my_modules_strict),false) |
Dan Willemsen | 09c1107 | 2020-01-15 20:47:54 -0800 | [diff] [blame] | 56 | my_missing_files = $(shell $(call echo-error,$(my_makefile),$(my_package_name): Unknown installed file for module '$(1)'))$(eval my_missing_error := true) |
Dan Willemsen | b47d4e9 | 2017-04-08 00:31:31 -0700 | [diff] [blame] | 57 | endif |
| 58 | |
Ying Wang | 3380d3a | 2014-05-19 13:03:36 -0700 | [diff] [blame] | 59 | # Iterate over modules' built files and installed files; |
Ying Wang | 3b81aab | 2014-05-05 16:46:52 -0700 | [diff] [blame] | 60 | # Calculate the dest files in the output zip file. |
Ying Wang | 3380d3a | 2014-05-19 13:03:36 -0700 | [diff] [blame] | 61 | |
Alex Deymo | 00dc667 | 2017-01-05 08:54:46 -0800 | [diff] [blame] | 62 | $(foreach m,$(my_modules_and_deps),\ |
Ying Wang | c947b4a | 2014-06-16 15:14:45 -0700 | [diff] [blame] | 63 | $(eval _pickup_files := $(strip $(ALL_MODULES.$(m).PICKUP_FILES)\ |
| 64 | $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).PICKUP_FILES)))\ |
| 65 | $(eval _built_files := $(strip $(ALL_MODULES.$(m).BUILT_INSTALLED)\ |
| 66 | $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).BUILT_INSTALLED)))\ |
Nelson Li | 1f8357f | 2019-03-14 01:04:05 +0000 | [diff] [blame] | 67 | $(eval _module_class_folder := $($(strip MODULE_CLASS_$(word 1, $(strip $(ALL_MODULES.$(m).CLASS)\ |
| 68 | $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).CLASS))))))\ |
Ying Wang | c947b4a | 2014-06-16 15:14:45 -0700 | [diff] [blame] | 69 | $(if $(_pickup_files)$(_built_files),,\ |
Dan Willemsen | b47d4e9 | 2017-04-08 00:31:31 -0700 | [diff] [blame] | 70 | $(call my_missing_files,$(m)))\ |
Ying Wang | c947b4a | 2014-06-16 15:14:45 -0700 | [diff] [blame] | 71 | $(eval my_pickup_files += $(_pickup_files))\ |
| 72 | $(foreach i, $(_built_files),\ |
Ying Wang | 3380d3a | 2014-05-19 13:03:36 -0700 | [diff] [blame] | 73 | $(eval bui_ins := $(subst :,$(space),$(i)))\ |
| 74 | $(eval ins := $(word 2,$(bui_ins)))\ |
| 75 | $(if $(filter $(TARGET_OUT_ROOT)/%,$(ins)),\ |
| 76 | $(eval bui := $(word 1,$(bui_ins)))\ |
| 77 | $(eval my_built_modules += $(bui))\ |
Nelson Li | 1f8357f | 2019-03-14 01:04:05 +0000 | [diff] [blame] | 78 | $(if $(filter $(_module_class_folder), nativetest benchmarktest),\ |
| 79 | $(eval module_class_folder_stem := $(_module_class_folder)$(findstring 64, $(patsubst $(PRODUCT_OUT)/%,%,$(ins)))),\ |
| 80 | $(eval module_class_folder_stem := $(_module_class_folder)))\ |
Ying Wang | 571fee8 | 2014-05-07 16:39:21 -0700 | [diff] [blame] | 81 | $(eval my_copy_dest := $(patsubst data/%,DATA/%,\ |
Nelson Li | 1f8357f | 2019-03-14 01:04:05 +0000 | [diff] [blame] | 82 | $(patsubst testcases/%,DATA/$(module_class_folder_stem)/%,\ |
| 83 | $(patsubst testcases/$(m)/$(TARGET_ARCH)/%,DATA/$(module_class_folder_stem)/$(m)/%,\ |
| 84 | $(patsubst testcases/$(m)/$(TARGET_2ND_ARCH)/%,DATA/$(module_class_folder_stem)/$(m)/%,\ |
| 85 | $(patsubst system/%,DATA/%,\ |
| 86 | $(patsubst $(PRODUCT_OUT)/%,%,$(ins))))))))\ |
Ying Wang | 3380d3a | 2014-05-19 13:03:36 -0700 | [diff] [blame] | 87 | $(eval my_copy_pairs += $(bui):$(my_staging_dir)/$(my_copy_dest)))\ |
Ying Wang | 3b81aab | 2014-05-05 16:46:52 -0700 | [diff] [blame] | 88 | )) |
| 89 | |
Dan Willemsen | 09c1107 | 2020-01-15 20:47:54 -0800 | [diff] [blame] | 90 | ifneq ($(my_missing_error),) |
| 91 | $(error done) |
| 92 | endif |
| 93 | |
Ying Wang | 3b81aab | 2014-05-05 16:46:52 -0700 | [diff] [blame] | 94 | $(my_package_zip): PRIVATE_COPY_PAIRS := $(my_copy_pairs) |
Bob Badour | eb9431e | 2022-06-06 16:59:33 -0700 | [diff] [blame] | 95 | $(my_package_zip): PRIVATE_STAGING_DIR := $(my_staging_dir) |
Ying Wang | 3b81aab | 2014-05-05 16:46:52 -0700 | [diff] [blame] | 96 | $(my_package_zip): PRIVATE_PICKUP_FILES := $(my_pickup_files) |
Bob Badour | eb9431e | 2022-06-06 16:59:33 -0700 | [diff] [blame] | 97 | $(my_package_zip) : $(my_built_modules) $(SOONG_ZIP) |
Ying Wang | 3b81aab | 2014-05-05 16:46:52 -0700 | [diff] [blame] | 98 | @echo "Package $@" |
Bob Badour | eb9431e | 2022-06-06 16:59:33 -0700 | [diff] [blame] | 99 | @rm -rf $(PRIVATE_STAGING_DIR) && mkdir -p $(PRIVATE_STAGING_DIR) |
Colin Cross | f075bcb | 2017-03-14 16:58:34 -0700 | [diff] [blame] | 100 | $(foreach p, $(PRIVATE_COPY_PAIRS),\ |
| 101 | $(eval pair := $(subst :,$(space),$(p)))\ |
| 102 | mkdir -p $(dir $(word 2,$(pair))) && \ |
| 103 | cp -Rf $(word 1,$(pair)) $(word 2,$(pair)) && ) true |
Ying Wang | a47420a | 2014-09-23 21:50:12 -0700 | [diff] [blame] | 104 | $(hide) $(foreach f, $(PRIVATE_PICKUP_FILES),\ |
Bob Badour | eb9431e | 2022-06-06 16:59:33 -0700 | [diff] [blame] | 105 | cp -RfL $(f) $(PRIVATE_STAGING_DIR) && ) true |
| 106 | $(hide) $(SOONG_ZIP) -o $@ -C $(PRIVATE_STAGING_DIR) -D $(PRIVATE_STAGING_DIR) |
Dan Willemsen | f354b17 | 2017-06-20 15:57:32 -0700 | [diff] [blame] | 107 | |
| 108 | my_makefile := |
| 109 | my_staging_dir := |
| 110 | my_built_modules := |
| 111 | my_copy_dest := |
| 112 | my_copy_pairs := |
| 113 | my_pickup_files := |
| 114 | my_missing_files := |
Dan Willemsen | 09c1107 | 2020-01-15 20:47:54 -0800 | [diff] [blame] | 115 | my_missing_error := |
Dan Willemsen | f354b17 | 2017-06-20 15:57:32 -0700 | [diff] [blame] | 116 | my_modules_and_deps := |
Dan Willemsen | 09c1107 | 2020-01-15 20:47:54 -0800 | [diff] [blame] | 117 | my_modules_strict := |