From dc7bc5d8bf68a9212c756c4295ca6bafd3575598 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Thu, 20 Feb 2020 16:18:13 -0800 Subject: [PATCH 1/2] Use sdk variant of Soong modules when LOCAL_SDK_VERSION is set Soong now makes a variant of native modules that set sdk_version. Use the new variant for native modules or apps with JNI that are defined in Make and set LOCAL_SDK_VERSION. Test: m checkbuild Bug: 149591340 Change-Id: Ief378a007e43b0aea31fd5845410bbffec0ffae6 Merged-In: Ief378a007e43b0aea31fd5845410bbffec0ffae6 (cherry picked from commit b93411699498d893b7e8d71be73edb1f857c5079) --- core/binary.mk | 12 ++++++++++++ core/definitions.mk | 6 ++++++ core/install_jni_libs_internal.mk | 26 +++++++++++++++++++++++--- core/notice_files.mk | 4 ++++ 4 files changed, 45 insertions(+), 3 deletions(-) diff --git a/core/binary.mk b/core/binary.mk index 38ff9d650a..75f4874968 100644 --- a/core/binary.mk +++ b/core/binary.mk @@ -1160,6 +1160,18 @@ ifeq ($(LOCAL_USE_VNDK),) $(if $(filter $(l),$(VENDOR_PUBLIC_LIBRARIES)),$(l).vendorpublic,$(l))) endif +########################################################### +## When compiling against the NDK, use SDK variants of Soong libraries +########################################################### + +ifneq ($(LOCAL_SDK_VERSION),) + my_whole_static_libraries := $(call use_soong_sdk_libraries,$(my_whole_static_libraries)) + my_static_libraries := $(call use_soong_sdk_libraries,$(my_static_libraries)) + my_shared_libraries := $(call use_soong_sdk_libraries,$(my_shared_libraries)) + my_system_shared_libraries := $(call use_soong_sdk_libraries,$(my_system_shared_libraries)) + my_header_libraries := $(call use_soong_sdk_libraries,$(my_header_libraries)) +endif + ########################################################## ## Set up installed module dependency ## We cannot compute the full path of the LOCAL_SHARED_LIBRARIES for diff --git a/core/definitions.mk b/core/definitions.mk index 3772a918a5..91a873b2d7 100644 --- a/core/definitions.mk +++ b/core/definitions.mk @@ -3322,3 +3322,9 @@ $(hide) CLANG_BIN="$(LLVM_PREBUILTS_PATH)" \ XZ="$(XZ)" \ $(LIBRARY_IDENTITY_CHECK_SCRIPT) $(SOONG_STRIP_PATH) $(1) $(2) endef + +# Convert Soong libraries that have SDK variant +define use_soong_sdk_libraries + $(foreach l,$(1),$(if $(filter $(l),$(SOONG_SDK_VARIANT_MODULES)),\ + $(l).sdk,$(l))) +endef diff --git a/core/install_jni_libs_internal.mk b/core/install_jni_libs_internal.mk index d87513bd0e..b482eb59ba 100644 --- a/core/install_jni_libs_internal.mk +++ b/core/install_jni_libs_internal.mk @@ -12,9 +12,18 @@ # my_embedded_prebuilt_jni_libs, prebuilt jni libs embedded in prebuilt apk. # +my_sdk_variant = $(1) +ifneq (,$(and $(my_embed_jni),$(LOCAL_SDK_VERSION))) + # Soong produces $(lib).so in $(lib).sdk_intermediates so that the library + # has the correct name for embedding in an APK. Append .sdk to the name + # of the intermediates directory, but not the .so name. + my_sdk_variant = $(call use_soong_sdk_libraries,$(1)) +endif + my_jni_shared_libraries := $(strip \ - $(foreach lib,$(LOCAL_JNI_SHARED_LIBRARIES), \ - $(call intermediates-dir-for,SHARED_LIBRARIES,$(lib),,,$(my_2nd_arch_prefix))/$(lib).so)) + $(foreach lib,$(LOCAL_JNI_SHARED_LIBRARIES), \ + $(call intermediates-dir-for,SHARED_LIBRARIES,$(call my_sdk_variant,$(lib)),,,$(my_2nd_arch_prefix))/$(lib).so)) + # App-specific lib path. my_app_lib_path := $(dir $(LOCAL_INSTALLED_MODULE))lib/$(TARGET_$(my_2nd_arch_prefix)ARCH) @@ -115,7 +124,18 @@ ifneq ($(strip $(LOCAL_JNI_SHARED_LIBRARIES)),) my_allowed_types := $(my_allowed_ndk_types) native:platform native:product native:vendor native:vndk native:vndk_private native:platform_vndk endif - my_link_deps := $(addprefix SHARED_LIBRARIES:,$(LOCAL_JNI_SHARED_LIBRARIES)) + ifneq (,$(LOCAL_SDK_VERSION)) + ifeq ($(SOONG_ANDROID_MK),$(LOCAL_MODULE_MAKEFILE)) + # SOONG_SDK_VARIANT_MODULES isn't complete yet while parsing Soong modules, and Soong has + # already ensured that apps link against the correct SDK variants, rewrite all JNI libraries + # to the SDK variant. + my_link_deps := $(addprefix SHARED_LIBRARIES:,$(addsuffix .sdk,$(LOCAL_JNI_SHARED_LIBRARIES))) + else + my_link_deps := $(addprefix SHARED_LIBRARIES:,$(call use_soong_sdk_libraries,$(LOCAL_JNI_SHARED_LIBRARIES))) + endif + else + my_link_deps := $(addprefix SHARED_LIBRARIES:,$(LOCAL_JNI_SHARED_LIBRARIES)) + endif my_common := include $(BUILD_SYSTEM)/link_type.mk diff --git a/core/notice_files.mk b/core/notice_files.mk index 9df1c1125a..22f8e41844 100644 --- a/core/notice_files.mk +++ b/core/notice_files.mk @@ -82,6 +82,10 @@ else else ifeq ($(LOCAL_MODULE_CLASS),ETC) # ETC modules may be uninstallable, yet still have a NOTICE file. e.g. apex components module_installed_filename := + else ifneq (,$(and $(filter %.sdk,$(LOCAL_MODULE)),$(filter $(patsubst %.sdk,%,$(LOCAL_MODULE)),$(SOONG_SDK_VARIANT_MODULES)))) + # Soong produces uninstallable *.sdk shared libraries for embedding in APKs. + module_installed_filename := \ + $(patsubst $(PRODUCT_OUT)/%,%,$($(LOCAL_2ND_ARCH_VAR_PREFIX)$(my_prefix)OUT_SHARED_LIBRARIES))/$(notdir $(LOCAL_BUILT_MODULE)) else $(error Cannot determine where to install NOTICE file for $(LOCAL_MODULE)) endif # JAVA_LIBRARIES From 17c7264f44e1412507fb489afac3af9de30de0c9 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 13 Apr 2020 12:16:19 -0700 Subject: [PATCH 2/2] Don't install test suite files from uninstallable modules Don't copy tests or test data to the test suite directories if the module is marked LOCAL_UNINSTALLABLE_MODULE := true. Fixes: 153758132 Test: m checkbuild Change-Id: Ibdf18807a2ffe9bb352d74880a802ad55b57f154 Merged-In: Ibdf18807a2ffe9bb352d74880a802ad55b57f154 (cherry picked from commit fca369e4e3694b0f549613362f056ffff8c88f67) --- core/base_rules.mk | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/base_rules.mk b/core/base_rules.mk index b7e3da7a76..1db73ae6db 100644 --- a/core/base_rules.mk +++ b/core/base_rules.mk @@ -597,6 +597,7 @@ endif ## Compatibility suite files. ########################################################### ifdef LOCAL_COMPATIBILITY_SUITE +ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE)) # If we are building a native test or benchmark and its stem variants are not defined, # separate the multiple architectures into subdirectories of the testcase folder. @@ -750,6 +751,7 @@ $(call create-suite-dependencies) $(foreach suite, $(LOCAL_COMPATIBILITY_SUITE), \ $(eval my_compat_dist_config_$(suite) := )) +endif # LOCAL_UNINSTALLABLE_MODULE endif # LOCAL_COMPATIBILITY_SUITE ###########################################################