post_clean.mk revision 3abc2a392664fd08288d39513fc41182af7fefaf
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))))
75ifdef intermediates_to_clean
76$(info *** Obsolete aidl-generated files detected, clean intermediate files...)
77$(info *** rm -rf $(intermediates_to_clean))
78$(shell rm -rf $(intermediates_to_clean))
79intermediates_to_clean :=
80endif
81
82# For modules not loaded by the current build (e.g. you are running mm/mmm),
83# we copy the info from the previous bulid.
84$(foreach p, $(filter-out $(modules_with_aidl_files),$(MODULES_WITH_AIDL_FILES)),\
85  $(shell echo 'AIDL_FILES.$(p) := $(AIDL_FILES.$(p))' >> $(current_aidl_config)))
86MODULES_WITH_AIDL_FILES := $(sort $(MODULES_WITH_AIDL_FILES) $(modules_with_aidl_files))
87$(shell echo 'MODULES_WITH_AIDL_FILES := $(MODULES_WITH_AIDL_FILES)' >> $(current_aidl_config))
88
89# Now current becomes previous.
90$(shell mv -f $(current_aidl_config) $(previous_aidl_config))
91
92MODULES_WITH_AIDL_FILES :=
93modules_with_aidl_files :=
94previous_aidl_config :=
95current_aidl_config :=
96