1#!/bin/sh 2# 3# Copyright (C) 2012 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18# Run a few sanity checks on a given NDK release install/package 19 20PROGNAME=$(basename "$0") 21PROGDIR=$(dirname "$0") 22 23. "$PROGDIR"/../build/core/ndk-common.sh 24 25panic () { 26 echo "ERROR: $@" >&2 27 exit 1 28} 29 30fail_panic () { 31 if [ $? != 0 ]; then panic "$@"; fi 32} 33 34# Command-line processing. Please keep this alphabetically sorted. 35HELP= 36NDK_DIR= 37NDK_PACKAGE= 38SYSTEM= 39 40for opt; do 41 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` 42 case $opt in 43 --help|-h|-?) 44 HELP=true 45 ;; 46 --package=*) 47 NDK_PACKAGE=$optarg 48 ;; 49 --system=*) 50 SYSTEM=$optarg 51 ;; 52 -*) 53 panic "Unknown option '$opt'. See --help for list of valid ones." 54 ;; 55 *) 56 if [ -z "$NDK_DIR" ]; then 57 NDK_DIR=$opt 58 else 59 panic "Only one parameter (ndk directory) is supported. See --help." 60 fi 61 ;; 62 esac 63done 64 65if [ "$HELP" ]; then 66 echo "Usage: $PROGNAME [options] [<ndk-install-path>]" 67 echo "" 68 echo "This script is used to run a series of sanity checks on a given" 69 echo "NDK release installation, or alternatively an NDK release package." 70 echo "" 71 echo "Valid options:" 72 echo "" 73 echo " --help|-h|-? Print this message." 74 echo " --package=<file> Specify NDK release archive file." 75 echo " --system=<name> Specify host system type." 76 echo "" 77 exit 0 78fi 79 80if [ -n "$NDK_PACKAGE" ]; then 81 if [ -n "$NDK_DIR" ]; then 82 panic "You can't use --package=<file> and a directory path at the same time." 83 fi 84 TMP_DIR=/tmp/ndk-$USER/tests/release 85 mkdir -p $TMP_DIR && rm -rf $TMP_DIR/* 86 87 echo "Unpacking '$(basename $NDK_PACKAGE)' into: $TMP_DIR" 88 unpack_archive "$NDK_PACKAGE" "$TMP_DIR" 89 fail_panic "Could not uncompress NDK release package!" 90 91 # Get into the first sub-directory. It should be something like android-ndk-* 92 NDK_DIR=$(ls -d $TMP_DIR/android-ndk-* | head -1) 93 if [ -z "$NDK_DIR" ]; then 94 panic "Could not find uncompressed NDK directory. Please check your package file: $TMP_DIR" 95 fi 96elif [ -z "$NDK_DIR" ]; then 97 panic "Please specify an NDK installation directory, or use --package=<file> option. See --help." 98fi 99 100FAILURES=0 101COUNT=0 102 103# Run a single test, and update failure/count appropriately. 104# $1: test function name, without the test_ prefix. 105# $2+: test textual abstract description. 106do_test () { 107 local NAME TEXT RET 108 NAME=$1 109 shift 110 echo -n "test: $@... " 111 TEXT=$(eval test_$NAME 2>/dev/null) 112 if [ $? != 0 ]; then 113 FAILURES=$(( $FAILURES + 1 )) 114 echo "KO: $TEXT" 115 else 116 echo "ok" 117 fi 118 COUNT=$(( $COUNT + 1 )) 119} 120 121# There must be a RELEASE file at the top of the NDK 122# installation tree. 123# 124test_RELEASE () { 125 local RELEASE 126 127 # Check that the RELEASE.TXT file is here 128 if [ ! -f "$NDK_DIR/RELEASE.TXT" ]; then 129 echo "Missing RELEASE.TXT file." 130 return 1 131 fi 132 133 # Extract the release version 134 RELEASE=$(cat $NDK_DIR/RELEASE.TXT) 135 136 # Check that the ChangeLog file documents the release properly 137 CHANGELOG_RELEASE=$(cat $NDK_DIR/docs/CHANGES.html | grep -e "^android-ndk-" | head -1) 138 CHANGELOG_RELEASE=${CHANGELOG_RELEASE##android-ndk-} 139 140 if [ "$RELEASE" != "$CHANGELOG_RELEASE" ]; then 141 echo "CHANGES.html documents release '$CHANGELOG_RELEASE', but RELEASE.TXT contains '$RELEASE'!" 142 return 1 143 fi 144 145 return 0 146} 147 148 149do_test RELEASE "Checking top-level release file" 150 151echo -n "$FAILURES/$COUNT tests failed." 152if [ "$FAILURES" = 0 ]; then 153 echo "Congratulations!" 154 exit 0 155else 156 echo "Please fix the errors!" 157 exit 1 158fi 159