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.
7#   my_copy_pairs: a list of extra files to install (in src:dest format)
8# Output variables:
9#   my_package_zip: the path to the output zip file.
10#
11#
12
13my_makefile := $(lastword $(filter-out $(lastword $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
14my_staging_dir := $(call intermediates-dir-for,PACKAGING,$(my_package_name))
15my_built_modules := $(foreach p,$(my_copy_pairs),$(call word-colon,1,$(p)))
16my_copy_pairs := $(foreach p,$(my_copy_pairs),$(call word-colon,1,$(p)):$(my_staging_dir)/$(call word-colon,2,$(p)))
17my_pickup_files :=
18
19# Iterate over the modules and include their direct dependencies stated in the
20# LOCAL_REQUIRED_MODULES.
21my_modules_and_deps := $(my_modules)
22$(foreach m,$(my_modules),\
23  $(eval _explicitly_required := \
24    $(strip $(ALL_MODULES.$(m).EXPLICITLY_REQUIRED_FROM_TARGET)\
25    $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).EXPLICITLY_REQUIRED_FROM_TARGET)))\
26  $(eval my_modules_and_deps += $(_explicitly_required))\
27)
28
29# Ignore unknown installed files on partial builds
30my_missing_files :=
31ifneq ($(ALLOW_MISSING_DEPENDENCIES),true)
32my_missing_files = $(shell $(call echo-warning,$(my_makefile),$(my_package_name): Unknown installed file for module '$(1)'))
33endif
34
35# Iterate over modules' built files and installed files;
36# Calculate the dest files in the output zip file.
37
38$(foreach m,$(my_modules_and_deps),\
39  $(eval _pickup_files := $(strip $(ALL_MODULES.$(m).PICKUP_FILES)\
40    $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).PICKUP_FILES)))\
41  $(eval _built_files := $(strip $(ALL_MODULES.$(m).BUILT_INSTALLED)\
42    $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).BUILT_INSTALLED)))\
43  $(eval _module_class_folder := $($(strip MODULE_CLASS_$(word 1, $(strip $(ALL_MODULES.$(m).CLASS)\
44    $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).CLASS))))))\
45  $(if $(_pickup_files)$(_built_files),,\
46    $(call my_missing_files,$(m)))\
47  $(eval my_pickup_files += $(_pickup_files))\
48  $(foreach i, $(_built_files),\
49    $(eval bui_ins := $(subst :,$(space),$(i)))\
50    $(eval ins := $(word 2,$(bui_ins)))\
51    $(if $(filter $(TARGET_OUT_ROOT)/%,$(ins)),\
52      $(eval bui := $(word 1,$(bui_ins)))\
53      $(eval my_built_modules += $(bui))\
54      $(if $(filter $(_module_class_folder), nativetest benchmarktest),\
55        $(eval module_class_folder_stem := $(_module_class_folder)$(findstring 64, $(patsubst $(PRODUCT_OUT)/%,%,$(ins)))),\
56        $(eval module_class_folder_stem := $(_module_class_folder)))\
57      $(eval my_copy_dest := $(patsubst data/%,DATA/%,\
58                               $(patsubst testcases/%,DATA/$(module_class_folder_stem)/%,\
59                                 $(patsubst testcases/$(m)/$(TARGET_ARCH)/%,DATA/$(module_class_folder_stem)/$(m)/%,\
60                                   $(patsubst testcases/$(m)/$(TARGET_2ND_ARCH)/%,DATA/$(module_class_folder_stem)/$(m)/%,\
61                                     $(patsubst system/%,DATA/%,\
62                                       $(patsubst $(PRODUCT_OUT)/%,%,$(ins))))))))\
63      $(eval my_copy_pairs += $(bui):$(my_staging_dir)/$(my_copy_dest)))\
64  ))
65
66my_package_zip := $(my_staging_dir)/$(my_package_name).zip
67$(my_package_zip): PRIVATE_COPY_PAIRS := $(my_copy_pairs)
68$(my_package_zip): PRIVATE_PICKUP_FILES := $(my_pickup_files)
69$(my_package_zip) : $(my_built_modules)
70	@echo "Package $@"
71	@rm -rf $(dir $@) && mkdir -p $(dir $@)
72	$(foreach p, $(PRIVATE_COPY_PAIRS),\
73	  $(eval pair := $(subst :,$(space),$(p)))\
74	  mkdir -p $(dir $(word 2,$(pair))) && \
75	  cp -Rf $(word 1,$(pair)) $(word 2,$(pair)) && ) true
76	$(hide) $(foreach f, $(PRIVATE_PICKUP_FILES),\
77	  cp -RfL $(f) $(dir $@) && ) true
78	$(hide) cd $(dir $@) && zip -rqX $(notdir $@) *
79
80my_makefile :=
81my_staging_dir :=
82my_built_modules :=
83my_copy_dest :=
84my_copy_pairs :=
85my_pickup_files :=
86my_missing_files :=
87my_modules_and_deps :=
88