platform_build/core/cleanbuild.mk

348 lines
13 KiB
Makefile
Raw Normal View History

# Copyright (C) 2007 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Don't bother with the cleanspecs if you are running mm/mmm
ifeq ($(ONE_SHOT_MAKEFILE)$(dont_bother),)
INTERNAL_CLEAN_STEPS :=
# Builds up a list of clean steps. Creates a unique
# id for each step by taking makefile path, INTERNAL_CLEAN_BUILD_VERSION
# and appending an increasing number of '@' characters.
#
# $(1): shell command to run
# $(2): indicate to not use makefile path as part of step id if not empty.
# $(2) should only be used in build/core/cleanspec.mk: just for compatibility.
define _add-clean-step
$(if $(strip $(INTERNAL_CLEAN_BUILD_VERSION)),, \
$(error INTERNAL_CLEAN_BUILD_VERSION not set))
$(eval _acs_makefile_prefix := $(lastword $(MAKEFILE_LIST)))
$(eval _acs_makefile_prefix := $(subst /,_,$(_acs_makefile_prefix)))
$(eval _acs_makefile_prefix := $(subst .,-,$(_acs_makefile_prefix)))
$(eval _acs_makefile_prefix := $(_acs_makefile_prefix)_acs)
$(if $($(_acs_makefile_prefix)),,\
$(eval $(_acs_makefile_prefix) := $(INTERNAL_CLEAN_BUILD_VERSION)))
$(eval $(_acs_makefile_prefix) := $($(_acs_makefile_prefix))@)
$(if $(strip $(2)),$(eval _acs_id := $($(_acs_makefile_prefix))),\
$(eval _acs_id := $(_acs_makefile_prefix)$($(_acs_makefile_prefix))))
$(eval INTERNAL_CLEAN_STEPS += $(_acs_id))
$(eval INTERNAL_CLEAN_STEP.$(_acs_id) := $(1))
$(eval _acs_id :=)
$(eval _acs_makefile_prefix :=)
endef
define add-clean-step
$(eval # for build/core/cleanspec.mk, dont use makefile path as part of step id) \
$(if $(filter %/cleanspec.mk,$(lastword $(MAKEFILE_LIST))),\
$(eval $(call _add-clean-step,$(1),true)),\
$(eval $(call _add-clean-step,$(1))))
endef
# Defines INTERNAL_CLEAN_BUILD_VERSION and the individual clean steps.
# cleanspec.mk is outside of the core directory so that more people
# can have permission to touch it.
include $(BUILD_SYSTEM)/cleanspec.mk
INTERNAL_CLEAN_BUILD_VERSION := $(strip $(INTERNAL_CLEAN_BUILD_VERSION))
# If the clean_steps.mk file is missing (usually after a clean build)
# then we won't do anything.
CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)
CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)
# Read the current state from the file, if present.
# Will set CURRENT_CLEAN_BUILD_VERSION and CURRENT_CLEAN_STEPS.
#
clean_steps_file := $(PRODUCT_OUT)/clean_steps.mk
-include $(clean_steps_file)
ifneq ($(CURRENT_CLEAN_BUILD_VERSION),$(INTERNAL_CLEAN_BUILD_VERSION))
# The major clean version is out-of-date. Do a full clean, and
# don't even bother with the clean steps.
$(info *** A clean build is required because of a recent change.)
$(shell rm -rf $(OUT_DIR))
$(info *** Done with the cleaning, now starting the real build.)
else
# The major clean version is correct. Find the list of clean steps
# that we need to execute to get up-to-date.
steps := \
$(filter-out $(CURRENT_CLEAN_STEPS),$(INTERNAL_CLEAN_STEPS))
$(foreach step,$(steps), \
$(info Clean step: $(INTERNAL_CLEAN_STEP.$(step))) \
$(shell $(INTERNAL_CLEAN_STEP.$(step))) \
)
# Rewrite the clean step for the second arch.
ifdef TARGET_2ND_ARCH
# $(1): the clean step cmd
# $(2): the prefix to search for
# $(3): the prefix to replace with
define -cs-rewrite-cleanstep
$(if $(filter $(2)/%,$(1)),\
$(eval _crs_new_cmd := $(patsubst $(2)/%,$(3)/%,$(1)))\
$(info Clean step: $(_crs_new_cmd))\
$(shell $(_crs_new_cmd)))
endef
$(foreach step,$(steps), \
$(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_INTERMEDIATES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES))\
$(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_SHARED_LIBRARIES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES))\
$(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$(TARGET_OUT_VENDOR_SHARED_LIBRARIES),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES))\
$(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES),$(TARGET_OUT_INTERMEDIATES))\
$(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_SHARED_LIBRARIES),$(TARGET_OUT_SHARED_LIBRARIES))\
$(call -cs-rewrite-cleanstep,$(INTERNAL_CLEAN_STEP.$(step)),$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_VENDOR_SHARED_LIBRARIES),$(TARGET_OUT_VENDOR_SHARED_LIBRARIES))\
)
endif
_crs_new_cmd :=
steps :=
endif
CURRENT_CLEAN_BUILD_VERSION :=
CURRENT_CLEAN_STEPS :=
# Write the new state to the file.
#
$(shell \
mkdir -p $(dir $(clean_steps_file)) && \
echo "CURRENT_CLEAN_BUILD_VERSION := $(INTERNAL_CLEAN_BUILD_VERSION)" > \
$(clean_steps_file) ;\
echo "CURRENT_CLEAN_STEPS := $(INTERNAL_CLEAN_STEPS)" >> \
$(clean_steps_file) \
)
clean_steps_file :=
INTERNAL_CLEAN_STEPS :=
INTERNAL_CLEAN_BUILD_VERSION :=
endif # if not ONE_SHOT_MAKEFILE dont_bother
# Since products and build variants (unfortunately) share the same
# PRODUCT_OUT staging directory, things can get out of sync if different
# build configurations are built in the same tree. The following logic
# will notice when the configuration has changed and remove the files
# necessary to keep things consistent.
previous_build_config_file := $(PRODUCT_OUT)/previous_build_config.mk
# A change in the list of aapt configs warrants an installclean, too.
aapt_config_list := $(strip $(PRODUCT_AAPT_CONFIG) $(PRODUCT_AAPT_PREF_CONFIG))
current_build_config := \
$(TARGET_PRODUCT)-$(TARGET_BUILD_VARIANT)-{$(aapt_config_list)}
current_sanitize_target := $(strip $(SANITIZE_TARGET))
ifeq (,$(current_sanitize_target))
current_sanitize_target := false
endif
aapt_config_list :=
force_installclean := false
force_objclean := false
# Read the current state from the file, if present.
# Will set PREVIOUS_BUILD_CONFIG.
#
PREVIOUS_BUILD_CONFIG :=
PREVIOUS_SANITIZE_TARGET :=
-include $(previous_build_config_file)
PREVIOUS_BUILD_CONFIG := $(strip $(PREVIOUS_BUILD_CONFIG))
PREVIOUS_SANITIZE_TARGET := $(strip $(PREVIOUS_SANITIZE_TARGET))
ifdef PREVIOUS_BUILD_CONFIG
ifneq "$(current_build_config)" "$(PREVIOUS_BUILD_CONFIG)"
$(info *** Build configuration changed: "$(PREVIOUS_BUILD_CONFIG)" -> "$(current_build_config)")
ifneq ($(DISABLE_AUTO_INSTALLCLEAN),true)
force_installclean := true
else
$(info DISABLE_AUTO_INSTALLCLEAN is set; skipping auto-clean. Your tree may be in an inconsistent state.)
endif
endif
endif # else, this is the first build, so no need to clean.
PREVIOUS_BUILD_CONFIG :=
ifdef PREVIOUS_SANITIZE_TARGET
ifneq "$(current_sanitize_target)" "$(PREVIOUS_SANITIZE_TARGET)"
$(info *** SANITIZE_TARGET changed: "$(PREVIOUS_SANITIZE_TARGET)" -> "$(current_sanitize_target)")
force_objclean := true
endif
endif # else, this is the first build, so no need to clean.
PREVIOUS_SANITIZE_TARGET :=
# Write the new state to the file.
#
$(shell \
mkdir -p $(dir $(previous_build_config_file)) && \
echo "PREVIOUS_BUILD_CONFIG := $(current_build_config)" > \
$(previous_build_config_file) && \
echo "PREVIOUS_SANITIZE_TARGET := $(current_sanitize_target)" >> \
$(previous_build_config_file) \
)
previous_build_config_file :=
current_build_config :=
#
# installclean logic
#
# The files/dirs to delete during an installclean. This includes the
# non-common APPS directory, which may contain the wrong resources.
#
# Deletes all of the files that change between different build types,
# like "make user" vs. "make sdk". This lets you work with different
# build types without having to do a full clean each time. E.g.:
#
# $ make -j8 all
# $ make installclean
# $ make -j8 user
# $ make installclean
# $ make -j8 sdk
#
installclean_files := \
$(HOST_OUT)/obj/NOTICE_FILES \
$(HOST_OUT)/sdk \
$(PRODUCT_OUT)/*.img \
$(PRODUCT_OUT)/*.ini \
$(PRODUCT_OUT)/*.txt \
$(PRODUCT_OUT)/*.xlb \
$(PRODUCT_OUT)/*.zip \
$(PRODUCT_OUT)/kernel \
$(PRODUCT_OUT)/data \
$(PRODUCT_OUT)/skin \
$(PRODUCT_OUT)/obj/APPS \
$(PRODUCT_OUT)/obj/NOTICE_FILES \
$(PRODUCT_OUT)/obj/PACKAGING \
$(PRODUCT_OUT)/recovery \
$(PRODUCT_OUT)/root \
$(PRODUCT_OUT)/system \
$(PRODUCT_OUT)/vendor \
$(PRODUCT_OUT)/oem \
$(PRODUCT_OUT)/dex_bootjars \
$(PRODUCT_OUT)/obj/JAVA_LIBRARIES \
$(PRODUCT_OUT)/obj/FAKE \
$(PRODUCT_OUT)/obj/EXECUTABLES/adbd_intermediates \
$(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libfs_mgr_intermediates \
$(PRODUCT_OUT)/obj/EXECUTABLES/init_intermediates \
$(PRODUCT_OUT)/obj/ETC/mac_permissions.xml_intermediates \
$(PRODUCT_OUT)/obj/ETC/sepolicy_intermediates \
$(PRODUCT_OUT)/obj/ETC/init.environ.rc_intermediates
# The files/dirs to delete during a dataclean, which removes any files
# in the staging and emulator data partitions.
dataclean_files := \
$(PRODUCT_OUT)/data/* \
$(PRODUCT_OUT)/data-qemu/* \
$(PRODUCT_OUT)/userdata-qemu.img
# The files/dirs to delete during an objclean, which removes any files
# in the staging and emulator data partitions.
objclean_files := \
$(TARGET_OUT_INTERMEDIATES) \
$($(TARGET_2ND_ARCH_VAR_PREFIX)TARGET_OUT_INTERMEDIATES)
# make sure *_OUT is set so that we won't result in deleting random parts
# of the filesystem.
ifneq (2,$(words $(HOST_OUT) $(PRODUCT_OUT)))
$(error both HOST_OUT and PRODUCT_OUT should be set at this point.)
endif
# Define the rules for commandline invocation.
.PHONY: dataclean
dataclean: FILES := $(dataclean_files)
dataclean:
$(hide) rm -rf $(FILES)
@echo "Deleted emulator userdata images."
.PHONY: installclean
installclean: FILES := $(installclean_files)
installclean: dataclean
$(hide) rm -rf $(FILES)
@echo "Deleted images and staging directories."
.PHONY: objclean
objclean: FILES := $(objclean_files)
objclean:
$(hide) rm -rf $(FILES)
@echo "Deleted images and staging directories."
ifeq "$(force_installclean)" "true"
$(info *** Forcing "make installclean"...)
$(info *** rm -rf $(dataclean_files) $(installclean_files))
$(shell rm -rf $(dataclean_files) $(installclean_files))
$(info *** Done with the cleaning, now starting the real build.)
endif
force_installclean :=
[DO NOT MERGE] Compile using Jack. This allows to compile dex targeted java sources using Jack and Jill. Default is still to compile with the legacy toolchain. Default can be switched to the new toolchain by setting environement variable: export ANDROID_COMPILE_WITH_JACK=true Toolchain can also be forced for one module by defining LOCAL_JACK_ENABLED:=full # disabled, full, incremental in the mk portion defining the module. Jack execution environement can be controlled with: Global variable ANDROID_JACK_VM allow to change the jvm executing Jack. Global variable ANDROID_JACK_VM_ARGS allows to change default args given to the jvm. Global variable ANDROID_JACK_EXTRA_ARGS allows to define some default args to give to Jack LOCAL_JACK_VM_ARGS allows to override default args given to the jvm for the module. LOCAL_JACK_EXTRA_ARGS allows to override default args passed to Jack. This includes cherry-picks of the following changes: b4c49cba57dafdcdfb693a549c5a1dc1beb71c25 22c3fa6d73adcf14b38c7cf03446d4e2a892f682 138768c1bbb49d549c4b14281fa5f0bffac7d933 5dd3e1d31293aaaae7c0c213743a7ca77d2dd688 83d5d040479e09a3dea6b7f88ca9a57c4ae984ac 8bc90fd2d6ccf70b65d2d3aad22b0453b86a262d 140274707e31c9585aa28b0de2f1418c64ecd272 0fbc9ff2a2eed243aabaa75e911e55c4cf4b8d4c 833b427d72c91c1d1b7f8ac99fb87a6742eb6f43 f9a27f45b49f670c0258c1b6c19056ae85ac1e45 2809666941aceea4af65ec6f9cea8cce1c1392ed 37822c443d3d2ba88dd009c994f088906a0f5568 c6b44d43c38b80a52ed9ade7f9b503685dd129a7 d2a76c14bf60f45a4bf19721a09a10f758c42a66 06744f60fc48d0a33bd538497e77b624adee7d75 95573d5036e3de1ff26d1a9fc9e832c1b0a476a1 b821391614896e6156ffa3e4c2b0f4aef7e80793 2794e7b5824ba1ea5687c7dcaaf7c7062edfa2bb 801f2c44d0a919284c72eca2be708aedb3a79d88 c76d99dca10bd41a30cbfce4699866716a1d4eaf f528e132d60fc8c982e41c242017beb6d4f7df76 76a5e0bd1abc19d9d5664a59b9602bb24e15c259 e25b3984ff5c74aa2a49d14b7df7aa9527096c32 Partially, only Jack related parts werekept ec46a3b71f2746ec209d60ca03f6129d5b129f75 abee3a9f4171a7aaf39c743e7032721b02f43f07 77cbe10fd9c27747f98825f4923a0cfc65b28faf daf07db4cd5d10b706164904a28323e6223b8aa3 b6bfb5893a64dc23dd4dbcbcbe62fe885bd68632 Ie all Jack related changes untill b6bfb5893a64dc23dd4dbcbcbe62fe885bd68632 except a96cc59ab508c1c803c15f4e5f22ab2415b6ac26 "Use Jack by default" Change-Id: If9d47ef1c4fd1e6765ad2a47d816c1ad3cfab0e3
2014-09-08 14:45:14 +02:00
ifeq "$(force_objclean)" "true"
$(info *** Forcing cleanup of intermediate files...)
$(info *** rm -rf $(objclean_files))
$(shell rm -rf $(objclean_files))
$(info *** Done with the cleaning, now starting the real build.)
endif
force_objclean :=
###########################################################
# Clean build tools when swithcing between prebuilt host tools (such as in
# apps_only build) and tools built from source (platform build).
previous_prebuilt_tools_config_file := $(HOST_OUT)/previous_prebuilt_tools_config.mk
ifneq (,$(TARGET_BUILD_APPS)$(filter true,$(TARGET_BUILD_PDK)))
current_prebuilt_tools := true
else
current_prebuilt_tools := false
endif
PREVIOUS_PREBUILT_TOOLS :=
-include $(previous_prebuilt_tools_config_file)
force_tools_clean :=
ifdef PREVIOUS_PREBUILT_TOOLS
ifneq ($(PREVIOUS_PREBUILT_TOOLS),$(current_prebuilt_tools))
force_tools_clean := true
endif
endif # else, this is the first build, so no need to clean.
# Write the new state to the file.
$(shell \
mkdir -p $(dir $(previous_prebuilt_tools_config_file)) && \
echo "PREVIOUS_PREBUILT_TOOLS:=$(current_prebuilt_tools)" > \
$(previous_prebuilt_tools_config_file))
ifeq ($(force_tools_clean),true)
# For this list of prebuilt tools, see prebuilts/sdk/tools/Android.mk.
tools_clean_files := \
$(HOST_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/signapk_intermediates \
$(HOST_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/dx_intermediates \
$(HOST_OUT_COMMON_INTERMEDIATES)/JAVA_LIBRARIES/shrinkedAndroid_intermediates \
$(HOST_OUT)/obj*/EXECUTABLES/aapt_intermediates \
$(HOST_OUT)/obj*/EXECUTABLES/aidl_intermediates \
$(HOST_OUT)/obj*/EXECUTABLES/zipalign_intermediates \
$(HOST_OUT)/obj*/lib/libc++$(HOST_SHLIB_SUFFIX) \
$(info *** build type changed, clean host tools...)
$(info *** rm -rf $(tools_clean_files))
$(shell rm -rf $(tools_clean_files))
endif
###########################################################
[DO NOT MERGE] Compile using Jack. This allows to compile dex targeted java sources using Jack and Jill. Default is still to compile with the legacy toolchain. Default can be switched to the new toolchain by setting environement variable: export ANDROID_COMPILE_WITH_JACK=true Toolchain can also be forced for one module by defining LOCAL_JACK_ENABLED:=full # disabled, full, incremental in the mk portion defining the module. Jack execution environement can be controlled with: Global variable ANDROID_JACK_VM allow to change the jvm executing Jack. Global variable ANDROID_JACK_VM_ARGS allows to change default args given to the jvm. Global variable ANDROID_JACK_EXTRA_ARGS allows to define some default args to give to Jack LOCAL_JACK_VM_ARGS allows to override default args given to the jvm for the module. LOCAL_JACK_EXTRA_ARGS allows to override default args passed to Jack. This includes cherry-picks of the following changes: b4c49cba57dafdcdfb693a549c5a1dc1beb71c25 22c3fa6d73adcf14b38c7cf03446d4e2a892f682 138768c1bbb49d549c4b14281fa5f0bffac7d933 5dd3e1d31293aaaae7c0c213743a7ca77d2dd688 83d5d040479e09a3dea6b7f88ca9a57c4ae984ac 8bc90fd2d6ccf70b65d2d3aad22b0453b86a262d 140274707e31c9585aa28b0de2f1418c64ecd272 0fbc9ff2a2eed243aabaa75e911e55c4cf4b8d4c 833b427d72c91c1d1b7f8ac99fb87a6742eb6f43 f9a27f45b49f670c0258c1b6c19056ae85ac1e45 2809666941aceea4af65ec6f9cea8cce1c1392ed 37822c443d3d2ba88dd009c994f088906a0f5568 c6b44d43c38b80a52ed9ade7f9b503685dd129a7 d2a76c14bf60f45a4bf19721a09a10f758c42a66 06744f60fc48d0a33bd538497e77b624adee7d75 95573d5036e3de1ff26d1a9fc9e832c1b0a476a1 b821391614896e6156ffa3e4c2b0f4aef7e80793 2794e7b5824ba1ea5687c7dcaaf7c7062edfa2bb 801f2c44d0a919284c72eca2be708aedb3a79d88 c76d99dca10bd41a30cbfce4699866716a1d4eaf f528e132d60fc8c982e41c242017beb6d4f7df76 76a5e0bd1abc19d9d5664a59b9602bb24e15c259 e25b3984ff5c74aa2a49d14b7df7aa9527096c32 Partially, only Jack related parts werekept ec46a3b71f2746ec209d60ca03f6129d5b129f75 abee3a9f4171a7aaf39c743e7032721b02f43f07 77cbe10fd9c27747f98825f4923a0cfc65b28faf daf07db4cd5d10b706164904a28323e6223b8aa3 b6bfb5893a64dc23dd4dbcbcbe62fe885bd68632 Ie all Jack related changes untill b6bfb5893a64dc23dd4dbcbcbe62fe885bd68632 except a96cc59ab508c1c803c15f4e5f22ab2415b6ac26 "Use Jack by default" Change-Id: If9d47ef1c4fd1e6765ad2a47d816c1ad3cfab0e3
2014-09-08 14:45:14 +02:00
.PHONY: clean-jack-files
clean-jack-files: clean-dex-files
$(hide) find $(OUT_DIR) -name "*.jack" | xargs rm -f
$(hide) find $(OUT_DIR) -type d -name "jack" | xargs rm -rf
@echo "All jack files have been removed."
.PHONY: clean-dex-files
clean-dex-files:
$(hide) find $(OUT_DIR) -name "*.dex" ! -path "*/jack-incremental/*" | xargs rm -f
$(hide) for i in `find $(OUT_DIR) -name "*.jar" -o -name "*.apk"` ; do ((unzip -l $$i 2> /dev/null | \
grep -q "\.dex$$" && rm -f $$i) || continue ) ; done
@echo "All dex files and archives containing dex files have been removed."
.PHONY: clean-jack-incremental
clean-jack-incremental:
$(hide) find $(OUT_DIR) -name "jack-incremental" -type d | xargs rm -rf
@echo "All jack incremental dirs have been removed."