1# Copyright (C) 2012 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15# Clean steps that need global knowledge of individual modules. 16# This file must be included after all Android.mks have been loaded. 17 18####################################################### 19# Checks the current build configurations against the previous build, 20# clean artifacts in TARGET_COMMON_OUT_ROOT if necessary. 21# If a package's resource overlay has been changed, its R class needs to be 22# regenerated. 23previous_package_overlay_config := $(TARGET_OUT_COMMON_INTERMEDIATES)/APPS/previous_overlays.txt 24current_package_overlay_config := $(TARGET_OUT_COMMON_INTERMEDIATES)/APPS/current_overlays.txt 25current_all_packages_config := $(dir $(current_package_overlay_config))current_packages.txt 26 27$(shell rm -rf $(current_package_overlay_config) \ 28 && mkdir -p $(dir $(current_package_overlay_config)) \ 29 && touch $(current_package_overlay_config)) 30$(shell echo '$(PACKAGES)' > $(current_all_packages_config)) 31$(foreach p, $(PACKAGES), $(if $(PACKAGES.$(p).RESOURCE_OVERLAYS), \ 32 $(shell echo '$(p)' '$(PACKAGES.$(p).RESOURCE_OVERLAYS)' >> $(current_package_overlay_config)))) 33 34ifneq (,$(wildcard $(previous_package_overlay_config))) 35packages_overlay_changed := $(shell build/tools/diff_package_overlays.py \ 36 $(current_all_packages_config) $(current_package_overlay_config) \ 37 $(previous_package_overlay_config)) 38ifneq (,$(packages_overlay_changed)) 39overlay_cleanup_cmd := $(strip rm -rf $(foreach p, $(packages_overlay_changed),\ 40 $(TARGET_OUT_COMMON_INTERMEDIATES)/APPS/$(p)_intermediates)) 41$(info *** Overlay change detected, clean shared intermediate files...) 42$(info *** $(overlay_cleanup_cmd)) 43$(shell $(overlay_cleanup_cmd)) 44overlay_cleanup_cmd := 45endif 46packages_overlay_changed := 47endif 48 49# Now current becomes previous. 50$(shell mv -f $(current_package_overlay_config) $(previous_package_overlay_config)) 51 52previous_package_overlay_config := 53current_package_overlay_config := 54current_all_packages_config := 55 56####################################################### 57# Check if we need to delete obsolete aidl-generated java files. 58# When an aidl file gets deleted (or renamed), the generated java file is obsolete. 59previous_aidl_config := $(TARGET_OUT_COMMON_INTERMEDIATES)/previous_aidl_config.mk 60current_aidl_config := $(TARGET_OUT_COMMON_INTERMEDIATES)/current_aidl_config.mk 61 62$(shell rm -rf $(current_aidl_config) \ 63 && mkdir -p $(dir $(current_aidl_config))\ 64 && touch $(current_aidl_config)) 65-include $(previous_aidl_config) 66 67intermediates_to_clean := 68modules_with_aidl_files := 69$(foreach p, $(ALL_MODULES), \ 70 $(if $(ALL_MODULES.$(p).AIDL_FILES),\ 71 $(eval modules_with_aidl_files += $(p))\ 72 $(shell echo 'AIDL_FILES.$(p) := $(ALL_MODULES.$(p).AIDL_FILES)' >> $(current_aidl_config)))\ 73 $(if $(filter-out $(ALL_MODULES.$(p).AIDL_FILES),$(AIDL_FILES.$(p))),\ 74 $(eval intermediates_to_clean += $(ALL_MODULES.$(p).INTERMEDIATE_SOURCE_DIR)))) 75intermediates_to_clean := $(strip $(intermediates_to_clean)) 76ifdef intermediates_to_clean 77$(info *** Obsolete aidl-generated files detected, clean intermediate files...) 78$(info *** rm -rf $(intermediates_to_clean)) 79$(shell rm -rf $(intermediates_to_clean)) 80intermediates_to_clean := 81endif 82 83# For modules not loaded by the current build (e.g. you are running mm/mmm), 84# we copy the info from the previous bulid. 85$(foreach p, $(filter-out $(ALL_MODULES),$(MODULES_WITH_AIDL_FILES)),\ 86 $(shell echo 'AIDL_FILES.$(p) := $(AIDL_FILES.$(p))' >> $(current_aidl_config))) 87MODULES_WITH_AIDL_FILES := $(sort $(MODULES_WITH_AIDL_FILES) $(modules_with_aidl_files)) 88$(shell echo 'MODULES_WITH_AIDL_FILES := $(MODULES_WITH_AIDL_FILES)' >> $(current_aidl_config)) 89 90# Now current becomes previous. 91$(shell mv -f $(current_aidl_config) $(previous_aidl_config)) 92 93MODULES_WITH_AIDL_FILES := 94modules_with_aidl_files := 95previous_aidl_config := 96current_aidl_config := 97