Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9135ac96 authored by Ulyana Trafimovich's avatar Ulyana Trafimovich Committed by Automerger Merge Worker
Browse files

Merge "Reimplement verify_uses_libraries.sh in manifest_check.py." am: d3109e25

Original change: https://android-review.googlesource.com/c/platform/build/+/1614845

Change-Id: I8a093a94f89f3b2e8ffbadabda29d12db1da0920
parents bb62a4f3 d3109e25
Loading
Loading
Loading
Loading
+18 −9
Original line number Diff line number Diff line
@@ -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

core/verify_uses_libraries.sh

deleted100755 → 0
+0 −56
Original line number Diff line number Diff line
#!/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