From a2404510af5ead1b8dae72e024f50d710536f663 Mon Sep 17 00:00:00 2001 From: Ulya Trafimovich Date: Wed, 3 Mar 2021 16:24:18 +0000 Subject: [PATCH] Reimplement verify_uses_libraries.sh in manifest_check.py. Previously there were two different scripts that did similar things: 1) build/soong/scripts/manifest_check.py 2) build/make/core/verify_uses_libraries.sh Both scripts extracted tags and `targetSdkVersion` from the manifests of Java modules, but 1) worked for XML manifests, and 2) worked for APKs. This CL reimplements the functionality from 2) in 1), so that one script can handle both XML manifests and APKs. Bug: 132357300 Test: lunch cf_x86_64_phone-userdebug && m && launch_cvd \ adb wait-for-device && adb root && adb logcat \ | grep -E 'ClassLoaderContext [a-z ]+ mismatch' # empty grep output, no errors Change-Id: I386aa1a37699182cdf6f3f94ef8aa7b96a4017d3 --- core/app_prebuilt_internal.mk | 27 +++++++++++------ core/verify_uses_libraries.sh | 56 ----------------------------------- 2 files changed, 18 insertions(+), 65 deletions(-) delete mode 100755 core/verify_uses_libraries.sh diff --git a/core/app_prebuilt_internal.mk b/core/app_prebuilt_internal.mk index d47930c84..36b20670a 100644 --- a/core/app_prebuilt_internal.mk +++ b/core/app_prebuilt_internal.mk @@ -113,19 +113,28 @@ endif my_enforced_uses_libraries := ifdef LOCAL_ENFORCE_USES_LIBRARIES + my_verify_script := build/soong/scripts/manifest_check.py + my_uses_libs := $(patsubst %,--uses-library %,$(LOCAL_USES_LIBRARIES)) + my_optional_uses_libs := $(patsubst %,--optional-uses-library %, \ + $(LOCAL_OPTIONAL_USES_LIBRARIES)) + my_relax_check := $(if $(filter true,$(RELAX_USES_LIBRARY_CHECK)), \ + --enforce-uses-libraries-relax,) 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): PRIVATE_USES_LIBRARIES := $(my_uses_libs) + $(my_enforced_uses_libraries): PRIVATE_OPTIONAL_USES_LIBRARIES := $(my_optional_uses_libs) + $(my_enforced_uses_libraries): PRIVATE_RELAX_CHECK := $(my_relax_check) + $(my_enforced_uses_libraries): $(my_verify_script) $(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))" \ - relax_check="$(strip $(PRIVATE_RELAX_CHECK))" \ - $(BUILD_SYSTEM)/verify_uses_libraries.sh $< $@ + $(my_verify_script) \ + --enforce-uses-libraries \ + --enforce-uses-libraries-status $@ \ + --aapt $(AAPT) \ + $(PRIVATE_USES_LIBRARIES) \ + $(PRIVATE_OPTIONAL_USES_LIBRARIES) \ + $(PRIVATE_RELAX_CHECK) \ + $< $(built_module) : $(my_enforced_uses_libraries) endif diff --git a/core/verify_uses_libraries.sh b/core/verify_uses_libraries.sh deleted file mode 100755 index 1bd0a2cc6..000000000 --- a/core/verify_uses_libraries.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2018 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. - - -# apt_binary is $(AAPT) in the build. - -# Parse sdk, targetSdk, and uses librares in the APK, then cross reference against build specified ones. - -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. -export target_sdk_version=$(echo "${badging}" | grep "targetSdkVersion" | sed -n "s/targetSdkVersion:'\(.*\)'/\1/p") -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 - 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 - 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