aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2021-02-23 20:45:42 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-02-23 20:45:42 +0000
commitc66465a4b04578442bdd8889953789b803cbe5f3 (patch)
treec363e74c34ab5c3f6c9822f60a0817f0188f7375
parent68892c49dfb82f0ba58958cb75b6debeaaf69cf6 (diff)
parent5a09c2084d1cf7e673cdf0e4339e6523860d5e5a (diff)
downloadbuild-c66465a4b04578442bdd8889953789b803cbe5f3.tar.gz
Merge "Add non-fatal mode for verify_uses_libraries check."
-rw-r--r--core/app_prebuilt_internal.mk8
-rw-r--r--core/config.mk11
-rw-r--r--core/dex_preopt_config.mk1
-rw-r--r--core/dex_preopt_odex_install.mk4
-rwxr-xr-xcore/verify_uses_libraries.sh21
5 files changed, 36 insertions, 9 deletions
diff --git a/core/app_prebuilt_internal.mk b/core/app_prebuilt_internal.mk
index cb1b4538a3..ad96b5b545 100644
--- a/core/app_prebuilt_internal.mk
+++ b/core/app_prebuilt_internal.mk
@@ -104,17 +104,19 @@ endif
my_enforced_uses_libraries :=
ifdef LOCAL_ENFORCE_USES_LIBRARIES
- my_enforced_uses_libraries := $(intermediates.COMMON)/enforce_uses_libraries.timestamp
+ my_enforced_uses_libraries := $(intermediates.COMMON)/enforce_uses_libraries.status
$(my_enforced_uses_libraries): PRIVATE_USES_LIBRARIES := $(LOCAL_USES_LIBRARIES)
$(my_enforced_uses_libraries): PRIVATE_OPTIONAL_USES_LIBRARIES := $(LOCAL_OPTIONAL_USES_LIBRARIES)
+ $(my_enforced_uses_libraries): PRIVATE_RELAX_CHECK := $(RELAX_USES_LIBRARY_CHECK)
$(my_enforced_uses_libraries): $(BUILD_SYSTEM)/verify_uses_libraries.sh $(AAPT)
$(my_enforced_uses_libraries): $(my_prebuilt_src_file)
@echo Verifying uses-libraries: $<
+ rm -f $@
aapt_binary=$(AAPT) \
uses_library_names="$(strip $(PRIVATE_USES_LIBRARIES))" \
optional_uses_library_names="$(strip $(PRIVATE_OPTIONAL_USES_LIBRARIES))" \
- $(BUILD_SYSTEM)/verify_uses_libraries.sh $<
- touch $@
+ relax_check="$(strip $(PRIVATE_RELAX_CHECK))" \
+ $(BUILD_SYSTEM)/verify_uses_libraries.sh $< $@
$(built_module) : $(my_enforced_uses_libraries)
endif
diff --git a/core/config.mk b/core/config.mk
index dce347a2f2..3bd3622751 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -479,6 +479,17 @@ USE_PREBUILT_SDK_TOOLS_IN_PLACE := true
USE_D8 := true
.KATI_READONLY := USE_D8
+# Whether to fail immediately if verify_uses_libraries check fails, or to keep
+# going and restrict dexpreopt to not compile any code for the failed module.
+#
+# The intended use case for this flag is to have a smoother migration path for
+# the Java modules that need to add <uses-library> information in their build
+# files. The flag allows to quickly silence build errors. This flag should be
+# used with caution and only as a temporary measure, as it masks real errors
+# and affects performance.
+RELAX_USES_LIBRARY_CHECK ?= false
+.KATI_READONLY := RELAX_USES_LIBRARY_CHECK
+
#
# Tools that are prebuilts for TARGET_BUILD_USE_PREBUILT_SDKS
#
diff --git a/core/dex_preopt_config.mk b/core/dex_preopt_config.mk
index 06e2fb7d9f..dda7de01fc 100644
--- a/core/dex_preopt_config.mk
+++ b/core/dex_preopt_config.mk
@@ -105,6 +105,7 @@ ifeq ($(WRITE_SOONG_VARIABLES),true)
$(call add_json_bool, IsEng, $(filter eng,$(TARGET_BUILD_VARIANT)))
$(call add_json_bool, SanitizeLite, $(SANITIZE_LITE))
$(call add_json_bool, DefaultAppImages, $(WITH_DEX_PREOPT_APP_IMAGE))
+ $(call add_json_bool, RelaxUsesLibraryCheck, $(filter true,$(RELAX_USES_LIBRARY_CHECK)))
$(call add_json_str, Dex2oatXmx, $(DEX2OAT_XMX))
$(call add_json_str, Dex2oatXms, $(DEX2OAT_XMS))
$(call add_json_str, EmptyDirectory, $(OUT_DIR)/empty)
diff --git a/core/dex_preopt_odex_install.mk b/core/dex_preopt_odex_install.mk
index f9a9ba7ca4..cbd3069d31 100644
--- a/core/dex_preopt_odex_install.mk
+++ b/core/dex_preopt_odex_install.mk
@@ -278,6 +278,7 @@ ifdef LOCAL_DEX_PREOPT
$(call add_json_list, PreoptFlags, $(LOCAL_DEX_PREOPT_FLAGS))
$(call add_json_str, ProfileClassListing, $(if $(my_process_profile),$(LOCAL_DEX_PREOPT_PROFILE)))
$(call add_json_bool, ProfileIsTextListing, $(my_profile_is_text_listing))
+ $(call add_json_str, EnforceUsesLibrariesStatusFile, $(intermediates.COMMON)/enforce_uses_libraries.status)
$(call add_json_bool, EnforceUsesLibraries, $(LOCAL_ENFORCE_USES_LIBRARIES))
$(call add_json_str, ProvidesUsesLibrary, $(firstword $(LOCAL_PROVIDES_USES_LIBRARY) $(LOCAL_MODULE)))
$(call add_json_map, ClassLoaderContexts)
@@ -345,6 +346,9 @@ ifdef LOCAL_DEX_PREOPT
$(call intermediates-dir-for,JAVA_LIBRARIES,$(lib),,COMMON)/javalib.jar)
my_dexpreopt_deps += $(my_dexpreopt_images_deps)
my_dexpreopt_deps += $(DEXPREOPT_BOOTCLASSPATH_DEX_FILES)
+ ifeq ($(LOCAL_ENFORCE_USES_LIBRARIES),true)
+ my_dexpreopt_deps += $(intermediates.COMMON)/enforce_uses_libraries.status
+ endif
$(my_dexpreopt_zip): PRIVATE_MODULE := $(LOCAL_MODULE)
$(my_dexpreopt_zip): $(my_dexpreopt_deps)
diff --git a/core/verify_uses_libraries.sh b/core/verify_uses_libraries.sh
index dde0447d36..1bd0a2cc62 100755
--- a/core/verify_uses_libraries.sh
+++ b/core/verify_uses_libraries.sh
@@ -21,6 +21,7 @@
set -e
local_apk=$1
+status_file=$2
badging=$(${aapt_binary} dump badging "${local_apk}")
export sdk_version=$(echo "${badging}" | grep "sdkVersion" | sed -n "s/sdkVersion:'\(.*\)'/\1/p")
# Export target_sdk_version to the caller.
@@ -28,20 +29,28 @@ export target_sdk_version=$(echo "${badging}" | grep "targetSdkVersion" | sed -n
uses_libraries=$(echo "${badging}" | grep "uses-library" | sed -n "s/uses-library:'\(.*\)'/\1/p")
optional_uses_libraries=$(echo "${badging}" | grep "uses-library-not-required" | sed -n "s/uses-library-not-required:'\(.*\)'/\1/p")
+errmsg=
+
# Verify that the uses libraries match exactly.
# Currently we validate the ordering of the libraries since it matters for resolution.
single_line_libs=$(echo "${uses_libraries}" | tr '\n' ' ' | awk '{$1=$1}1')
if [[ "${single_line_libs}" != "${uses_library_names}" ]]; then
- echo "LOCAL_USES_LIBRARIES (${uses_library_names})" \
- "do not match (${single_line_libs}) in manifest for ${local_apk}"
- exit 1
+ errmsg="LOCAL_USES_LIBRARIES (${uses_library_names}) do not match (${single_line_libs}) in manifest for ${local_apk}"
fi
# Verify that the optional uses libraries match exactly.
single_line_optional_libs=$(echo "${optional_uses_libraries}" | tr '\n' ' ' | awk '{$1=$1}1')
if [[ "${single_line_optional_libs}" != "${optional_uses_library_names}" ]]; then
- echo "LOCAL_OPTIONAL_USES_LIBRARIES (${optional_uses_library_names}) " \
- "do not match (${single_line_optional_libs}) in manifest for ${local_apk}"
- exit 1
+ errmsg="LOCAL_OPTIONAL_USES_LIBRARIES (${optional_uses_library_names}) do not match (${single_line_optional_libs}) in manifest for ${local_apk}"
fi
+if [[ ! -z "${errmsg}" ]]; then
+ echo "${errmsg}" > "${status_file}"
+ if [[ "${relax_check}" != true ]]; then
+ # fail immediately
+ echo "${errmsg}"
+ exit 1
+ fi
+else
+ touch "${status_file}"
+fi