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 |
Bob Badour | 8ef100a | 2022-06-07 21:07:11 -0700 | [diff] [blame] | 24 | LOCAL_LICENSE_PACKAGE_NAME := Android |
| 25 | LOCAL_NOTICE_FILE := build/soong/licenses/LICENSE |
Daniel Norman | 1d18d53 | 2020-03-25 14:18:42 -0700 | [diff] [blame] | 26 | LOCAL_MODULE_CLASS := PACKAGING |
| 27 | LOCAL_MODULE_STEM := $(my_package_name).zip |
| 28 | LOCAL_UNINSTALLABLE_MODULE := true |
| 29 | include $(BUILD_SYSTEM)/base_rules.mk |
Bob Badour | eb9431e | 2022-06-06 16:59:33 -0700 | [diff] [blame] | 30 | my_staging_dir := $(intermediates)/staging |
Daniel Norman | 1d18d53 | 2020-03-25 14:18:42 -0700 | [diff] [blame] | 31 | my_package_zip := $(LOCAL_BUILT_MODULE) |
| 32 | |
Dan Willemsen | f354b17 | 2017-06-20 15:57:32 -0700 | [diff] [blame] | 33 | my_built_modules := $(foreach p,$(my_copy_pairs),$(call word-colon,1,$(p))) |
| 34 | 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] | 35 | my_pickup_files := |
Dan Willemsen | 09c1107 | 2020-01-15 20:47:54 -0800 | [diff] [blame] | 36 | my_missing_error := |
Ying Wang | 3b81aab | 2014-05-05 16:46:52 -0700 | [diff] [blame] | 37 | |
Alex Deymo | 00dc667 | 2017-01-05 08:54:46 -0800 | [diff] [blame] | 38 | # Iterate over the modules and include their direct dependencies stated in the |
| 39 | # LOCAL_REQUIRED_MODULES. |
| 40 | my_modules_and_deps := $(my_modules) |
| 41 | $(foreach m,$(my_modules),\ |
| 42 | $(eval _explicitly_required := \ |
Dan Willemsen | 8e96a79 | 2019-04-02 14:43:32 -0700 | [diff] [blame] | 43 | $(strip $(ALL_MODULES.$(m).EXPLICITLY_REQUIRED_FROM_TARGET)\ |
| 44 | $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).EXPLICITLY_REQUIRED_FROM_TARGET)))\ |
Alex Deymo | 00dc667 | 2017-01-05 08:54:46 -0800 | [diff] [blame] | 45 | $(eval my_modules_and_deps += $(_explicitly_required))\ |
| 46 | ) |
| 47 | |
Dan Willemsen | 09c1107 | 2020-01-15 20:47:54 -0800 | [diff] [blame] | 48 | ifneq ($(filter-out true false,$(my_modules_strict)),) |
| 49 | $(shell $(call echo-error,$(my_makefile),$(my_package_name): Invalid value for 'my_module_strict' = '$(my_modules_strict)'. Valid values: 'true', 'false', '')) |
| 50 | $(error done) |
| 51 | endif |
| 52 | |
Sam Delmerico | 4c3b83f | 2023-02-21 13:54:27 -0500 | [diff] [blame] | 53 | my_missing_files = $(shell $(call echo-warning,$(my_makefile),$(my_package_name): Unknown installed file for module '$(1)'))$(shell$(call echo-warning,$(my_makefile),$(my_package_name): Some necessary modules may have been skipped by Soong. Check if PRODUCT_SOURCE_ROOT_DIRS is pruning necessary Android.bp files.)) |
Dan Willemsen | 09c1107 | 2020-01-15 20:47:54 -0800 | [diff] [blame] | 54 | ifeq ($(ALLOW_MISSING_DEPENDENCIES),true) |
| 55 | # Ignore unknown installed files on partial builds |
| 56 | my_missing_files = |
Dan Willemsen | 277972a | 2020-01-30 11:03:12 -0800 | [diff] [blame] | 57 | else ifneq ($(my_modules_strict),false) |
Sam Delmerico | 4c3b83f | 2023-02-21 13:54:27 -0500 | [diff] [blame] | 58 | my_missing_files = $(shell $(call echo-error,$(my_makefile),$(my_package_name): Unknown installed file for module '$(1)'))$(shell$(call echo-warning,$(my_makefile),$(my_package_name): Some necessary modules may have been skipped by Soong. Check if PRODUCT_SOURCE_ROOT_DIRS is pruning necessary Android.bp files.))$(eval my_missing_error := true) |
Dan Willemsen | b47d4e9 | 2017-04-08 00:31:31 -0700 | [diff] [blame] | 59 | endif |
| 60 | |
Ying Wang | 3380d3a | 2014-05-19 13:03:36 -0700 | [diff] [blame] | 61 | # Iterate over modules' built files and installed files; |
Ying Wang | 3b81aab | 2014-05-05 16:46:52 -0700 | [diff] [blame] | 62 | # Calculate the dest files in the output zip file. |
Ying Wang | 3380d3a | 2014-05-19 13:03:36 -0700 | [diff] [blame] | 63 | |
Alex Deymo | 00dc667 | 2017-01-05 08:54:46 -0800 | [diff] [blame] | 64 | $(foreach m,$(my_modules_and_deps),\ |
Ying Wang | c947b4a | 2014-06-16 15:14:45 -0700 | [diff] [blame] | 65 | $(eval _pickup_files := $(strip $(ALL_MODULES.$(m).PICKUP_FILES)\ |
| 66 | $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).PICKUP_FILES)))\ |
| 67 | $(eval _built_files := $(strip $(ALL_MODULES.$(m).BUILT_INSTALLED)\ |
| 68 | $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).BUILT_INSTALLED)))\ |
Nelson Li | 1f8357f | 2019-03-14 01:04:05 +0000 | [diff] [blame] | 69 | $(eval _module_class_folder := $($(strip MODULE_CLASS_$(word 1, $(strip $(ALL_MODULES.$(m).CLASS)\ |
| 70 | $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).CLASS))))))\ |
Ying Wang | c947b4a | 2014-06-16 15:14:45 -0700 | [diff] [blame] | 71 | $(if $(_pickup_files)$(_built_files),,\ |
Dan Willemsen | b47d4e9 | 2017-04-08 00:31:31 -0700 | [diff] [blame] | 72 | $(call my_missing_files,$(m)))\ |
Ying Wang | c947b4a | 2014-06-16 15:14:45 -0700 | [diff] [blame] | 73 | $(eval my_pickup_files += $(_pickup_files))\ |
| 74 | $(foreach i, $(_built_files),\ |
Ying Wang | 3380d3a | 2014-05-19 13:03:36 -0700 | [diff] [blame] | 75 | $(eval bui_ins := $(subst :,$(space),$(i)))\ |
| 76 | $(eval ins := $(word 2,$(bui_ins)))\ |
| 77 | $(if $(filter $(TARGET_OUT_ROOT)/%,$(ins)),\ |
| 78 | $(eval bui := $(word 1,$(bui_ins)))\ |
| 79 | $(eval my_built_modules += $(bui))\ |
Nelson Li | 1f8357f | 2019-03-14 01:04:05 +0000 | [diff] [blame] | 80 | $(if $(filter $(_module_class_folder), nativetest benchmarktest),\ |
| 81 | $(eval module_class_folder_stem := $(_module_class_folder)$(findstring 64, $(patsubst $(PRODUCT_OUT)/%,%,$(ins)))),\ |
| 82 | $(eval module_class_folder_stem := $(_module_class_folder)))\ |
Ying Wang | 571fee8 | 2014-05-07 16:39:21 -0700 | [diff] [blame] | 83 | $(eval my_copy_dest := $(patsubst data/%,DATA/%,\ |
Nelson Li | 1f8357f | 2019-03-14 01:04:05 +0000 | [diff] [blame] | 84 | $(patsubst testcases/%,DATA/$(module_class_folder_stem)/%,\ |
| 85 | $(patsubst testcases/$(m)/$(TARGET_ARCH)/%,DATA/$(module_class_folder_stem)/$(m)/%,\ |
| 86 | $(patsubst testcases/$(m)/$(TARGET_2ND_ARCH)/%,DATA/$(module_class_folder_stem)/$(m)/%,\ |
| 87 | $(patsubst system/%,DATA/%,\ |
| 88 | $(patsubst $(PRODUCT_OUT)/%,%,$(ins))))))))\ |
Ying Wang | 3380d3a | 2014-05-19 13:03:36 -0700 | [diff] [blame] | 89 | $(eval my_copy_pairs += $(bui):$(my_staging_dir)/$(my_copy_dest)))\ |
Ying Wang | 3b81aab | 2014-05-05 16:46:52 -0700 | [diff] [blame] | 90 | )) |
| 91 | |
Dan Willemsen | 09c1107 | 2020-01-15 20:47:54 -0800 | [diff] [blame] | 92 | ifneq ($(my_missing_error),) |
| 93 | $(error done) |
| 94 | endif |
| 95 | |
Ying Wang | 3b81aab | 2014-05-05 16:46:52 -0700 | [diff] [blame] | 96 | $(my_package_zip): PRIVATE_COPY_PAIRS := $(my_copy_pairs) |
Bob Badour | eb9431e | 2022-06-06 16:59:33 -0700 | [diff] [blame] | 97 | $(my_package_zip): PRIVATE_STAGING_DIR := $(my_staging_dir) |
Ying Wang | 3b81aab | 2014-05-05 16:46:52 -0700 | [diff] [blame] | 98 | $(my_package_zip): PRIVATE_PICKUP_FILES := $(my_pickup_files) |
Bob Badour | fc26ac0 | 2022-06-08 17:03:02 -0700 | [diff] [blame] | 99 | $(my_package_zip) : $(my_built_modules) |
Ying Wang | 3b81aab | 2014-05-05 16:46:52 -0700 | [diff] [blame] | 100 | @echo "Package $@" |
Bob Badour | eb9431e | 2022-06-06 16:59:33 -0700 | [diff] [blame] | 101 | @rm -rf $(PRIVATE_STAGING_DIR) && mkdir -p $(PRIVATE_STAGING_DIR) |
Colin Cross | f075bcb | 2017-03-14 16:58:34 -0700 | [diff] [blame] | 102 | $(foreach p, $(PRIVATE_COPY_PAIRS),\ |
| 103 | $(eval pair := $(subst :,$(space),$(p)))\ |
| 104 | mkdir -p $(dir $(word 2,$(pair))) && \ |
| 105 | cp -Rf $(word 1,$(pair)) $(word 2,$(pair)) && ) true |
Ying Wang | a47420a | 2014-09-23 21:50:12 -0700 | [diff] [blame] | 106 | $(hide) $(foreach f, $(PRIVATE_PICKUP_FILES),\ |
Bob Badour | eb9431e | 2022-06-06 16:59:33 -0700 | [diff] [blame] | 107 | cp -RfL $(f) $(PRIVATE_STAGING_DIR) && ) true |
Bob Badour | fc26ac0 | 2022-06-08 17:03:02 -0700 | [diff] [blame] | 108 | $(hide) cd $(PRIVATE_STAGING_DIR) && zip -rqX ../$(notdir $@) * |
Colin Cross | 585967c | 2023-09-29 19:19:20 +0000 | [diff] [blame] | 109 | rm -rf $(PRIVATE_STAGING_DIR) |
Dan Willemsen | f354b17 | 2017-06-20 15:57:32 -0700 | [diff] [blame] | 110 | |
| 111 | my_makefile := |
| 112 | my_staging_dir := |
| 113 | my_built_modules := |
| 114 | my_copy_dest := |
| 115 | my_copy_pairs := |
| 116 | my_pickup_files := |
| 117 | my_missing_files := |
Dan Willemsen | 09c1107 | 2020-01-15 20:47:54 -0800 | [diff] [blame] | 118 | my_missing_error := |
Dan Willemsen | f354b17 | 2017-06-20 15:57:32 -0700 | [diff] [blame] | 119 | my_modules_and_deps := |
Dan Willemsen | 09c1107 | 2020-01-15 20:47:54 -0800 | [diff] [blame] | 120 | my_modules_strict := |