From 18ffd5891ed9674f12929627fe18c43bed31e69c Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Wed, 31 Jul 2019 10:31:20 -0700 Subject: [PATCH] Remove import_includes/export_includes Now that ONE_SHOT_MAKEFILE no longer exists, we don't have to rely on the filesystem to store this informtion. This removes ~16.7k files from our build graph (aosp-master/aosp_arm64-eng), though only about 600 of them were being used in a normal build. Test: treehugger Change-Id: I3ac12f5ea7f11d25064109a0599bc5be1976fba5 --- CleanSpec.mk | 3 ++ core/binary.mk | 87 ++++++++++++------------------------ core/cc_prebuilt_internal.mk | 15 ++----- core/definitions.mk | 2 +- core/main.mk | 21 +++++++++ core/soong_cc_prebuilt.mk | 13 ++---- 6 files changed, 59 insertions(+), 82 deletions(-) diff --git a/CleanSpec.mk b/CleanSpec.mk index 426e25d12e..032f6e5c85 100644 --- a/CleanSpec.mk +++ b/CleanSpec.mk @@ -646,6 +646,9 @@ $(call add-clean-step, rm -rf $(OUT_DIR)/target/product/generic*/*/system_ext) # link_type and jni_link_type files are no longer needed $(call add-clean-step, find $(OUT_DIR) -type f -name "*link_type" -print0 | xargs -0 rm -f) +# import_includes and export_includes files are no longer needed +$(call add-clean-step, find $(OUT_DIR) -type f -name "import_includes" -o -name "export_includes" -print0 | xargs -0 rm -f) + # ************************************************ # NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST # ************************************************ diff --git a/core/binary.mk b/core/binary.mk index 874a4d343c..4709e8e3fc 100644 --- a/core/binary.mk +++ b/core/binary.mk @@ -1173,31 +1173,6 @@ endif endif -#################################################### -## Import includes -#################################################### -import_includes := $(intermediates)/import_includes -import_includes_deps := $(strip \ - $(if $(LOCAL_USE_VNDK),\ - $(call intermediates-dir-for,HEADER_LIBRARIES,device_kernel_headers,$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes) \ - $(foreach l, $(installed_shared_library_module_names), \ - $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes) \ - $(foreach l, $(my_static_libraries) $(my_whole_static_libraries), \ - $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes) \ - $(foreach l, $(my_header_libraries), \ - $(call intermediates-dir-for,HEADER_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes)) -$(import_includes): PRIVATE_IMPORT_EXPORT_INCLUDES := $(import_includes_deps) -$(import_includes) : $(import_includes_deps) - @echo Import includes file: $@ - $(hide) mkdir -p $(dir $@) && rm -f $@ -ifdef import_includes_deps - $(hide) for f in $(PRIVATE_IMPORT_EXPORT_INCLUDES); do \ - cat $$f >> $@; \ - done -else - $(hide) touch $@ -endif - #################################################### ## Verify that NDK-built libraries only link against ## other NDK-built libraries @@ -1309,7 +1284,6 @@ endif # that custom build rules which generate .o files don't consume other generated # sources as input (or if they do they take care of that dependency themselves). $(normal_objects) : | $(my_generated_sources) -$(all_objects) : $(import_includes) ALL_C_CPP_ETC_OBJECTS += $(all_objects) @@ -1678,6 +1652,22 @@ ifeq ($(NATIVE_COVERAGE),true) $(LOCAL_INTERMEDIATE_TARGETS): $(my_coverage_lib) endif +#################################################### +## Import includes +#################################################### +imported_includes := $(strip \ + $(if $(LOCAL_USE_VNDK),\ + $(call intermediates-dir-for,HEADER_LIBRARIES,device_kernel_headers,$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))) \ + $(foreach l, $(installed_shared_library_module_names), \ + $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))) \ + $(foreach l, $(my_static_libraries) $(my_whole_static_libraries), \ + $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))) \ + $(foreach l, $(my_header_libraries), \ + $(call intermediates-dir-for,HEADER_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross)))) + +$(foreach dep,$(imported_includes),\ + $(eval EXPORTS.$$(dep).USERS := $$(EXPORTS.$$(dep).USERS) $$(all_objects))) + ########################################################### ## Define PRIVATE_ variables used by multiple module types ########################################################### @@ -1730,7 +1720,7 @@ $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CPPFLAGS_NO_OVERRIDE := $(my_cppflags_no_ $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_RTTI_FLAG := $(LOCAL_RTTI_FLAG) $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_DEBUG_CFLAGS := $(debug_cflags) $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_C_INCLUDES := $(my_c_includes) -$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_IMPORT_INCLUDES := $(import_includes) +$(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_IMPORTED_INCLUDES := $(imported_includes) $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDFLAGS := $(my_ldflags) $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LDLIBS := $(my_ldlibs) $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_TIDY_CHECKS := $(my_tidy_checks) @@ -1757,51 +1747,30 @@ all_libraries := \ ########################################################### # Export includes ########################################################### -export_includes := $(intermediates)/export_includes -export_cflags := $(foreach d,$(my_export_c_include_dirs),-I $(d)) -$(export_includes): PRIVATE_EXPORT_CFLAGS := $(export_cflags) + # Headers exported by whole static libraries are also exported by this library. export_include_deps := $(strip \ $(foreach l,$(my_whole_static_libraries), \ - $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes)) + $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross)))) # Re-export requested headers from shared libraries. export_include_deps += $(strip \ $(foreach l,$(LOCAL_EXPORT_SHARED_LIBRARY_HEADERS), \ - $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes)) + $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross)))) # Re-export requested headers from static libraries. export_include_deps += $(strip \ $(foreach l,$(LOCAL_EXPORT_STATIC_LIBRARY_HEADERS), \ - $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes)) + $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross)))) # Re-export requested headers from header libraries. export_include_deps += $(strip \ $(foreach l,$(LOCAL_EXPORT_HEADER_LIBRARY_HEADERS), \ - $(call intermediates-dir-for,HEADER_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/export_includes)) -$(export_includes): PRIVATE_REEXPORTED_INCLUDES := $(export_include_deps) -# By adding $(my_generated_sources) it makes sure the headers get generated -# before any dependent source files get compiled. -$(export_includes) : $(my_export_c_include_deps) $(my_generated_sources) $(export_include_deps) $(LOCAL_EXPORT_C_INCLUDE_DEPS) - @echo Export includes file: $< -- $@ - $(hide) mkdir -p $(dir $@) && rm -f $@.tmp && touch $@.tmp -ifdef export_cflags - $(hide) echo "$(PRIVATE_EXPORT_CFLAGS)" >>$@.tmp -endif -ifdef export_include_deps - $(hide) for f in $(PRIVATE_REEXPORTED_INCLUDES); do \ - cat $$f >> $@.tmp; \ - done -endif - $(hide) if cmp -s $@.tmp $@ ; then \ - rm $@.tmp ; \ - else \ - mv $@.tmp $@ ; \ - fi -export_cflags := + $(call intermediates-dir-for,HEADER_LIBRARIES,$(l),$(my_kind),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross)))) -# Kati adds restat=1 to ninja. GNU make does nothing for this. -.KATI_RESTAT: $(export_includes) - -# Make sure export_includes gets generated when you are running mm/mmm -$(LOCAL_BUILT_MODULE) : | $(export_includes) +ifneq ($(strip $(my_export_c_include_dirs)$(export_include_deps)),) + EXPORTS_LIST := $(EXPORTS_LIST) $(intermediates) + EXPORTS.$(intermediates).FLAGS := $(foreach d,$(my_export_c_include_dirs),-I $(d)) + EXPORTS.$(intermediates).REEXPORT := $(export_include_deps) + EXPORTS.$(intermediates).DEPS := $(my_export_c_include_deps) $(my_generated_sources) $(LOCAL_EXPORT_C_INCLUDE_DEPS) +endif ifneq (,$(filter-out $(LOCAL_PATH)/%,$(my_export_c_include_dirs))) my_soong_problems += non_local__export_c_include_dirs diff --git a/core/cc_prebuilt_internal.mk b/core/cc_prebuilt_internal.mk index 0c87151aac..a8930d5998 100644 --- a/core/cc_prebuilt_internal.mk +++ b/core/cc_prebuilt_internal.mk @@ -75,18 +75,9 @@ else # my_strip_module not true built_module := $(LOCAL_BUILT_MODULE) ifdef prebuilt_module_is_a_library -export_includes := $(intermediates)/export_includes -export_cflags := $(foreach d,$(LOCAL_EXPORT_C_INCLUDE_DIRS),-I $(d)) -$(export_includes): PRIVATE_EXPORT_CFLAGS := $(export_cflags) -$(export_includes): $(LOCAL_EXPORT_C_INCLUDE_DEPS) - @echo Export includes file: $< -- $@ - $(hide) mkdir -p $(dir $@) && rm -f $@ -ifdef export_cflags - $(hide) echo "$(PRIVATE_EXPORT_CFLAGS)" >$@ -else - $(hide) touch $@ -endif -export_cflags := +EXPORTS_LIST := $(EXPORTS_LIST) $(intermediates) +EXPORTS.$(intermediates).FLAGS := $(foreach d,$(LOCAL_EXPORT_C_INCLUDE_DIRS),-I $(d)) +EXPORTS.$(intermediates).DEPS := $(LOCAL_EXPORT_C_INCLUDE_DEPS) include $(BUILD_SYSTEM)/allowed_ndk_types.mk diff --git a/core/definitions.mk b/core/definitions.mk index 16bec84cc1..f32a995840 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -1107,7 +1107,7 @@ endef ########################################################### define c-includes $(addprefix -I , $(PRIVATE_C_INCLUDES)) \ -$$(cat $(PRIVATE_IMPORT_INCLUDES))\ +$(foreach i,$(PRIVATE_IMPORTED_INCLUDES),$(EXPORTS.$(i)))\ $(if $(PRIVATE_NO_DEFAULT_COMPILER_FLAGS),,\ $(addprefix -I ,\ $(filter-out $(PRIVATE_C_INCLUDES), \ diff --git a/core/main.mk b/core/main.mk index 9f4b86c5a0..a240b35cee 100644 --- a/core/main.mk +++ b/core/main.mk @@ -972,6 +972,27 @@ ifdef link_type_error $(error exiting from previous errors) endif +# ------------------------------------------------------------------- +# Handle exported/imported includes + +# Recursively calculate flags +$(foreach export,$(EXPORTS_LIST), \ + $(eval EXPORTS.$$(export) = $$(EXPORTS.$(export).FLAGS) \ + $(foreach dep,$(EXPORTS.$(export).REEXPORT),$$(EXPORTS.$(dep))))) + +# Recursively calculate dependencies +$(foreach export,$(EXPORTS_LIST), \ + $(eval EXPORT_DEPS.$$(export) = $$(EXPORTS.$(export).DEPS) \ + $(foreach dep,$(EXPORTS.$(export).REEXPORT),$$(EXPORT_DEPS.$(dep))))) + +# Converts the recursive variables to simple variables so that we don't have to +# evaluate them for every .o rule +$(foreach export,$(EXPORTS_LIST),$(eval EXPORTS.$$(export) := $$(strip $$(EXPORTS.$$(export))))) +$(foreach export,$(EXPORTS_LIST),$(eval EXPORT_DEPS.$$(export) := $$(sort $$(EXPORT_DEPS.$$(export))))) + +# Add dependencies +$(foreach export,$(EXPORTS_LIST),$(eval $(call add-dependency,$$(EXPORTS.$$(export).USERS),$$(EXPORT_DEPS.$$(export))))) + # ------------------------------------------------------------------- # Figure out our module sets. # diff --git a/core/soong_cc_prebuilt.mk b/core/soong_cc_prebuilt.mk index 301f985d20..34dd3e8d80 100644 --- a/core/soong_cc_prebuilt.mk +++ b/core/soong_cc_prebuilt.mk @@ -65,16 +65,9 @@ include $(BUILD_SYSTEM)/base_rules.mk ifneq ($(filter STATIC_LIBRARIES SHARED_LIBRARIES HEADER_LIBRARIES,$(LOCAL_MODULE_CLASS)),) # Soong module is a static or shared library - export_includes := $(intermediates)/export_includes - $(export_includes): PRIVATE_EXPORT_CFLAGS := $(LOCAL_EXPORT_CFLAGS) - $(export_includes): $(LOCAL_EXPORT_C_INCLUDE_DEPS) - @echo Export includes file: $< -- $@ - $(hide) mkdir -p $(dir $@) && rm -f $@ - ifdef LOCAL_EXPORT_CFLAGS - $(hide) echo "$(PRIVATE_EXPORT_CFLAGS)" >$@ - else - $(hide) touch $@ - endif + EXPORTS_LIST := $(EXPORTS_LIST) $(intermediates) + EXPORTS.$(intermediates).FLAGS := $(LOCAL_EXPORT_CFLAGS) + EXPORTS.$(intermediates).DEPS := $(LOCAL_EXPORT_C_INCLUDE_DEPS) ifdef LOCAL_SOONG_TOC $(eval $(call copy-one-file,$(LOCAL_SOONG_TOC),$(LOCAL_BUILT_MODULE).toc))