From f9e67a898079a17867623de3ca44ffad7c566308 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Wed, 8 Apr 2020 10:55:47 +0900 Subject: [PATCH] mark platform un-availability A module is marked unavailable for platform when 1) it does not have "//apex_available:platform" in its apex_available property, or 2) it depends on another module that is unavailable for platform. In that case, LOCAL_NOT_AVAILABLE_FOR_PLATFORM is set to true for the module in the Make world. Later, that flag is used to ensure that there is no module with the flag is installed to the device. The reason why this isn't entirely done in Soong is because Soong doesn't know if a module will be installed to the device or not. To explain this, let's have an example. cc_test { name: "mytest", static_libs: ["libfoo"]} cc_library_static { name: "libfoo", static_libs: ["libbar"]} cc_library { name: "libbar", apex_available: ["com.android.xxx"]} Here, libbar is not available for platform, but is used by libfoo which is available for platform (apex_available defaults to "//apex_available:platform"). libfoo is again depended on by mytest which again is available for platform. The use of libbar should be allowed in the context of test; we don't want to make libbar available to platform just for the dependency from test because it will allow non-test uses of the library as well. Soong by itself can't tell whether libfoo and libbar are used only in the context of a test. There could be another module depending them, e.g., cc_library_shared { name: "mylib", static_libs: ["libfoo"] } can exist and it might be installed to the device, in which case we really should trigger an error. Since Make has the knowledge of what's installed and what's not, the check should be done there. Bug: 153073816 Test: m Change-Id: I14ddf0e5700d0a7bf60e4e41536efbd26ab5ed3d --- core/base_rules.mk | 10 +++++++ core/clear_vars.mk | 1 + core/tasks/platform_availability_check.mk | 36 +++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 core/tasks/platform_availability_check.mk diff --git a/core/base_rules.mk b/core/base_rules.mk index b1613841fc..f5bfc7de68 100644 --- a/core/base_rules.mk +++ b/core/base_rules.mk @@ -805,6 +805,16 @@ ifdef LOCAL_PICKUP_FILES ALL_MODULES.$(my_register_name).PICKUP_FILES := \ $(ALL_MODULES.$(my_register_name).PICKUP_FILES) $(LOCAL_PICKUP_FILES) endif +# Record the platform availability of this module. Note that the availability is not +# meaningful for non-installable modules (e.g., static libs) or host modules. +# We only care about modules that are installable to the device. +ifeq (true,$(LOCAL_NOT_AVAILABLE_FOR_PLATFORM)) + ifneq (true,$(LOCAL_UNINSTALLABLE_MODULE)) + ifndef LOCAL_IS_HOST_MODULE + ALL_MODULES.$(my_register_name).NOT_AVAILABLE_FOR_PLATFORM := true + endif + endif +endif my_required_modules := $(LOCAL_REQUIRED_MODULES) \ $(LOCAL_REQUIRED_MODULES_$(TARGET_$(LOCAL_2ND_ARCH_VAR_PREFIX)ARCH)) diff --git a/core/clear_vars.mk b/core/clear_vars.mk index e2bdb37dc6..5af057036d 100644 --- a/core/clear_vars.mk +++ b/core/clear_vars.mk @@ -192,6 +192,7 @@ LOCAL_NO_PIC:= LOCAL_NOSANITIZE:= LOCAL_NO_STANDARD_LIBRARIES:= LOCAL_NO_STATIC_ANALYZER:= +LOCAL_NOT_AVAILABLE_FOR_PLATFORM:= LOCAL_NOTICE_FILE:= LOCAL_ODM_MODULE:= LOCAL_OEM_MODULE:= diff --git a/core/tasks/platform_availability_check.mk b/core/tasks/platform_availability_check.mk new file mode 100644 index 0000000000..043d130440 --- /dev/null +++ b/core/tasks/platform_availability_check.mk @@ -0,0 +1,36 @@ +# +# Copyright (C) 2020 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. +# + +# Check whether there is any module that isn't available for platform +# is installed to the platform. + +# Filter FAKE and NON_INSTALLABLE modules out and then collect those are not +# available for platform +_modules_not_available_for_platform := \ +$(strip $(foreach m,$(product_MODULES),\ + $(if $(filter-out FAKE,$(ALL_MODULES.$(m).CLASS)),\ + $(if $(ALL_MODULES.$(m).INSTALLED),\ + $(if $(filter true,$(ALL_MODULES.$(m).NOT_AVAILABLE_FOR_PLATFORM)),\ + $(m)))))) + +_violators_with_path := $(foreach m,$(sort $(_modules_not_available_for_platform)),\ + $(m):$(word 1,$(ALL_MODULES.$(m).PATH))\ +) + +$(call maybe-print-list-and-error,$(_violators_with_path),\ +Following modules are requested to be installed. But are not available \ +for platform because they do not have "//apex_available:platform" or \ +they depend on other modules that are not available for platform)