aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorVladimir Marko <vmarko@google.com>2019-04-02 10:29:55 +0100
committerVladimir Marko <vmarko@google.com>2019-04-09 10:04:53 +0100
commite26f4a5e39d5e0ca64fe60d697f973fa538c8d91 (patch)
tree0ea56bd2360677e8da5401790fb718db991b8a1b /scripts
parentbed7cd31018813d0042cc86ae3bcb85da97e9997 (diff)
downloadbuild_soong-e26f4a5e39d5e0ca64fe60d697f973fa538c8d91.tar.gz
build_soong-e26f4a5e39d5e0ca64fe60d697f973fa538c8d91.tar.bz2
build_soong-e26f4a5e39d5e0ca64fe60d697f973fa538c8d91.zip
Check package restrictions for Java libs.
Test: m checkbuild; inspect verbose log. Test: Manual - compile with unmet restrictions. Bug: 122937705 (cherry picked from commit 0975ee0de3d2befefa613754b4dd684a1a9b8c0e) Change-Id: Ibecfb53072f060e046d3c8fdca0911d66cc6922d Merged-In: I9360ae8b6d9ce016b7827be5e8ffc6eb521809b7
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/package-check.sh72
1 files changed, 72 insertions, 0 deletions
diff --git a/scripts/package-check.sh b/scripts/package-check.sh
new file mode 100755
index 00000000..f982e824
--- /dev/null
+++ b/scripts/package-check.sh
@@ -0,0 +1,72 @@
+#!/bin/bash
+#
+# Copyright (C) 2019 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.
+
+set -e
+
+if [[ $# -le 1 ]]; then
+ cat <<EOF
+Usage:
+ package-check.sh <jar-file> <package-list>
+Checks that the class files in the <jar file> are in the <package-list> or
+sub-packages.
+EOF
+ exit 1
+fi
+
+jar_file=$1
+shift
+if [[ ! -f ${jar_file} ]]; then
+ echo "jar file \"${jar_file}\" does not exist."
+ exit 1
+fi
+
+prefixes=()
+while [[ $# -ge 1 ]]; do
+ package="$1"
+ if [[ "${package}" = */* ]]; then
+ echo "Invalid package \"${package}\". Use dot notation for packages."
+ exit 1
+ fi
+ # Transform to a slash-separated path and add a trailing slash to enforce
+ # package name boundary.
+ prefixes+=("${package//\./\/}/")
+ shift
+done
+
+# Get the file names from the jar file.
+zip_contents=`zipinfo -1 $jar_file`
+
+# Check all class file names against the expected prefixes.
+old_ifs=${IFS}
+IFS=$'\n'
+for zip_entry in ${zip_contents}; do
+ # Check the suffix.
+ if [[ "${zip_entry}" = *.class ]]; then
+ # Match against prefixes.
+ found=false
+ for prefix in ${prefixes[@]}; do
+ if [[ "${zip_entry}" = "${prefix}"* ]]; then
+ found=true
+ break
+ fi
+ done
+ if [[ "${found}" == "false" ]]; then
+ echo "Class file ${zip_entry} is outside specified packages."
+ exit 1
+ fi
+ fi
+done
+IFS=${old_ifs}