Home | History | Annotate | Download | only in tools
      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 
     13 my_makefile := $(lastword $(filter-out $(lastword $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
     14 my_staging_dir := $(call intermediates-dir-for,PACKAGING,$(my_package_name))
     15 my_built_modules := $(foreach p,$(my_copy_pairs),$(call word-colon,1,$(p)))
     16 my_copy_pairs := $(foreach p,$(my_copy_pairs),$(call word-colon,1,$(p)):$(my_staging_dir)/$(call word-colon,2,$(p)))
     17 my_pickup_files :=
     18 
     19 # Iterate over the modules and include their direct dependencies stated in the
     20 # LOCAL_REQUIRED_MODULES.
     21 my_modules_and_deps := $(my_modules)
     22 $(foreach m,$(my_modules),\
     23   $(eval _explicitly_required := \
     24     $(strip $(ALL_MODULES.$(m).EXPLICITLY_REQUIRED)\
     25     $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).EXPLICITLY_REQUIRED)))\
     26   $(eval my_modules_and_deps += $(_explicitly_required))\
     27 )
     28 
     29 # Ignore unknown installed files on partial builds
     30 my_missing_files :=
     31 # These warnings are too noisy, silence them for now.
     32 #ifneq ($(ALLOW_MISSING_DEPENDENCIES),true)
     33 #my_missing_files = $(shell $(call echo-warning,$(my_makefile),$(my_package_name): Unknown installed file for module '$(1)'))
     34 #endif
     35 
     36 # Iterate over modules' built files and installed files;
     37 # Calculate the dest files in the output zip file.
     38 
     39 $(foreach m,$(my_modules_and_deps),\
     40   $(eval _pickup_files := $(strip $(ALL_MODULES.$(m).PICKUP_FILES)\
     41     $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).PICKUP_FILES)))\
     42   $(eval _built_files := $(strip $(ALL_MODULES.$(m).BUILT_INSTALLED)\
     43     $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).BUILT_INSTALLED)))\
     44   $(if $(_pickup_files)$(_built_files),,\
     45     $(call my_missing_files,$(m)))\
     46   $(eval my_pickup_files += $(_pickup_files))\
     47   $(foreach i, $(_built_files),\
     48     $(eval bui_ins := $(subst :,$(space),$(i)))\
     49     $(eval ins := $(word 2,$(bui_ins)))\
     50     $(if $(filter $(TARGET_OUT_ROOT)/%,$(ins)),\
     51       $(eval bui := $(word 1,$(bui_ins)))\
     52       $(eval my_built_modules += $(bui))\
     53       $(eval my_copy_dest := $(patsubst data/%,DATA/%,\
     54                                $(patsubst system/%,DATA/%,\
     55                                  $(patsubst $(PRODUCT_OUT)/%,%,$(ins)))))\
     56       $(eval my_copy_pairs += $(bui):$(my_staging_dir)/$(my_copy_dest)))\
     57   ))
     58 
     59 my_package_zip := $(my_staging_dir)/$(my_package_name).zip
     60 $(my_package_zip): PRIVATE_COPY_PAIRS := $(my_copy_pairs)
     61 $(my_package_zip): PRIVATE_PICKUP_FILES := $(my_pickup_files)
     62 $(my_package_zip) : $(my_built_modules)
     63 	@echo "Package $@"
     64 	@rm -rf $(dir $@) && mkdir -p $(dir $@)
     65 	$(foreach p, $(PRIVATE_COPY_PAIRS),\
     66 	  $(eval pair := $(subst :,$(space),$(p)))\
     67 	  mkdir -p $(dir $(word 2,$(pair))) && \
     68 	  cp -Rf $(word 1,$(pair)) $(word 2,$(pair)) && ) true
     69 	$(hide) $(foreach f, $(PRIVATE_PICKUP_FILES),\
     70 	  cp -RfL $(f) $(dir $@) && ) true
     71 	$(hide) cd $(dir $@) && zip -rqX $(notdir $@) *
     72 
     73 my_makefile :=
     74 my_staging_dir :=
     75 my_built_modules :=
     76 my_copy_dest :=
     77 my_copy_pairs :=
     78 my_pickup_files :=
     79 my_missing_files :=
     80 my_modules_and_deps :=
     81