From dd5a5d328bfecd3e0074b0ba2a98a552828d0ad8 Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Wed, 15 Jun 2016 19:20:57 -0700 Subject: [PATCH 1/2] Add macros for printing pretty warnings/errors in rules Change-Id: Ia58e6bc1328c84e5f4ba1f6a2fd2d650e94e127e --- core/definitions.mk | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/definitions.mk b/core/definitions.mk index 1b647aa3c..de1948ff6 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -834,6 +834,20 @@ $(subst //,/,$(1)/$(2)) endef +########################################################### +## Color-coded warnings and errors in build rules +## +## $(1): message to print +########################################################### +define echo-warning +echo -e "\e[1;35mwarning:\e[0m \e[1m" $(1) "\e[0m\n" +endef + +define echo-error +echo -e "\e[1;31merror:\e[0m \e[1m" $(1) "\e[0m\n" +endef + + ########################################################### ## Package filtering ########################################################### From b097fbed0a035198c67c3a5ffa61cae75c08537f Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Tue, 7 Jun 2016 14:25:14 -0700 Subject: [PATCH 2/2] Check that NDK-built modules only link to NDK-built modules Modules built against the NDK should only link against modules also built against the NDK (or link to the NDK prebuilts). This patch attempts to catch these cases, and prints a large warning when this is violated. Once the tree is cleaned up, this will change to an error. Change-Id: Ib6ffcc38d9161abdbe45a58af26ba429fb6f1876 --- core/binary.mk | 39 ++++++++++++++++++++++++++++++- core/install_jni_libs_internal.mk | 32 +++++++++++++++++++++++++ core/prebuilt_internal.mk | 9 ++++++- 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/core/binary.mk b/core/binary.mk index 0c57030a0..bcf07c272 100644 --- a/core/binary.mk +++ b/core/binary.mk @@ -1208,6 +1208,43 @@ else $(hide) touch $@ endif + +#################################################### +## Verify that NDK-built libraries only link against +## other NDK-built libraries +#################################################### + +my_link_type := $(intermediates)/link_type +ifdef LOCAL_SDK_VERSION +$(my_link_type): PRIVATE_LINK_TYPE := ndk +$(my_link_type): PRIVATE_ALLOWED_TYPES := ndk +else +$(my_link_type): PRIVATE_LINK_TYPE := platform +$(my_link_type): PRIVATE_ALLOWED_TYPES := (ndk|platform) +endif +my_link_type_deps := $(strip \ + $(foreach l,$(my_whole_static_libraries) $(my_static_libraries), \ + $(call intermediates-dir-for,STATIC_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/link_type)) +ifneq ($(LOCAL_MODULE_CLASS),STATIC_LIBRARIES) +my_link_type_deps += $(strip \ + $(foreach l,$(my_shared_libraries), \ + $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),$(LOCAL_IS_HOST_MODULE),,$(LOCAL_2ND_ARCH_VAR_PREFIX),$(my_host_cross))/link_type)) +endif +$(my_link_type): PRIVATE_DEPS := $(my_link_type_deps) +$(my_link_type): PRIVATE_MODULE := $(LOCAL_MODULE) +$(my_link_type): PRIVATE_MAKEFILE := $(LOCAL_MODULE_MAKEFILE) +$(my_link_type): $(my_link_type_deps) + @echo Check module type: $@ + $(hide) mkdir -p $(dir $@) && rm -f $@ +ifdef my_link_type_deps + $(hide) for f in $(PRIVATE_DEPS); do \ + grep -qE '^$(PRIVATE_ALLOWED_TYPES)$$' $$f || \ + $(call echo-warning,"$(PRIVATE_MAKEFILE): $(PRIVATE_MODULE) ($(PRIVATE_LINK_TYPE)) should not link to $$(basename $${f%_intermediates/link_type}) ($$(cat $$f))"); \ + done +endif + $(hide) echo $(PRIVATE_LINK_TYPE) >$@ + + ########################################################### ## Common object handling. ########################################################### @@ -1560,4 +1597,4 @@ endif .KATI_RESTAT: $(export_includes) # Make sure export_includes gets generated when you are running mm/mmm -$(LOCAL_BUILT_MODULE) : | $(export_includes) +$(LOCAL_BUILT_MODULE) : | $(export_includes) $(my_link_type) diff --git a/core/install_jni_libs_internal.mk b/core/install_jni_libs_internal.mk index 27b9697e0..6136968c6 100644 --- a/core/install_jni_libs_internal.mk +++ b/core/install_jni_libs_internal.mk @@ -98,3 +98,35 @@ $(LOCAL_INSTALLED_MODULE) : $(addprefix $(my_app_lib_path)/, $(notdir $(my_prebu endif # my_embed_jni endif # inner my_prebuilt_jni_libs endif # outer my_prebuilt_jni_libs + +# Verify that all included libraries are built against the NDK +ifneq ($(strip $(LOCAL_JNI_SHARED_LIBRARIES)),) +my_link_type := $(call intermediates-dir-for,APPS,$(LOCAL_MODULE))/$(my_2nd_arch_prefix)jni_link_type +my_link_type_deps := $(strip \ + $(foreach l,$(LOCAL_JNI_SHARED_LIBRARIES),\ + $(call intermediates-dir-for,SHARED_LIBRARIES,$(l),,,$(my_2nd_arch_prefix))/link_type)) +ifneq ($(LOCAL_SDK_VERSION),) +$(my_link_type): PRIVATE_LINK_TYPE := sdk +$(my_link_type): PRIVATE_ALLOWED_TYPES := ndk +else +$(my_link_type): PRIVATE_LINK_TYPE := platform +$(my_link_type): PRIVATE_ALLOWED_TYPES := (ndk|platform) +endif +$(my_link_type): PRIVATE_DEPS := $(my_link_type_deps) +$(my_link_type): PRIVATE_MODULE := $(LOCAL_MODULE) +$(my_link_type): PRIVATE_MAKEFILE := $(LOCAL_MODULE_MAKEFILE) +$(my_link_type): $(my_link_type_deps) + @echo Check JNI module types: $@ + $(hide) mkdir -p $(dir $@) + $(hide) rm -f $@ + $(hide) for f in $(PRIVATE_DEPS); do \ + grep -qE '^$(PRIVATE_ALLOWED_TYPES)$$' $$f || \ + $(call echo-warning,"$(PRIVATE_MAKEFILE): $(PRIVATE_MODULE) ($(PRIVATE_LINK_TYPE)) should not link to $$(basename $${f%_intermediates/link_type}) ($$(cat $$f))"); \ + done + $(hide) touch $@ + +$(LOCAL_BUILT_MODULE): | $(my_link_type) + +my_link_type := +my_link_type_deps := +endif diff --git a/core/prebuilt_internal.mk b/core/prebuilt_internal.mk index 3f89d80a8..9c4a98d3a 100644 --- a/core/prebuilt_internal.mk +++ b/core/prebuilt_internal.mk @@ -122,7 +122,14 @@ else $(hide) touch $@ endif -$(LOCAL_BUILT_MODULE) : | $(intermediates)/export_includes +my_link_type := $(intermediates)/link_type +$(my_link_type): PRIVATE_LINK_TYPE := $(if $(LOCAL_SDK_VERSION),ndk,platform) +$(my_link_type): + @echo Check module type: $@ + $(hide) mkdir -p $(dir $@) && rm -f $@ + $(hide) echo $(PRIVATE_LINK_TYPE) >$@ + +$(LOCAL_BUILT_MODULE) : | $(export_includes) $(my_link_type) endif # prebuilt_module_is_a_library # The real dependency will be added after all Android.mks are loaded and the install paths