1#!/bin/bash 2# 3# Copyright (C) 2017 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 19# Generates asm_support_gen.h into a temporary location. 20# Then verifies it is the same as our local stored copy. 21 22GEN_TOOL=cpp-define-generator-data 23 24if ! which "$GEN_TOOL"; then 25 if [[ -z $ANDROID_BUILD_TOP ]]; then 26 echo "ERROR: Can't find '$GEN_TOOL' in \$PATH. Perhaps try 'source build/envsetup.sh' ?" >&2 27 else 28 echo "ERROR: Can't find '$GEN_TOOL' in \$PATH. Perhaps try 'make $GEN_TOOL' ?" >&2 29 fi 30 exit 1 31fi 32 33####################### 34####################### 35 36PREUPLOAD_COMMIT_COPY="$(mktemp ${TMPDIR:-/tmp}/tmp.XXXXXX)" 37BUILD_COPY="$(mktemp ${TMPDIR:-/tmp}/tmp.XXXXXX)" 38 39function finish() { 40 # Delete temp files. 41 [[ -f "$PREUPLOAD_COMMIT_COPY" ]] && rm "$PREUPLOAD_COMMIT_COPY" 42 [[ -f "$BUILD_COPY" ]] && rm "$BUILD_COPY" 43} 44trap finish EXIT 45 46DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 47ART_DIR="$( cd "$DIR/../.." && pwd )" 48ASM_SUPPORT_GEN_CHECKED_IN_COPY="runtime/generated/asm_support_gen.h" 49 50# Repo upload hook runs inside of the top-level git directory. 51# If we run this script manually, be in the right place for git. 52cd "$ART_DIR" 53 54if [[ -z $PREUPLOAD_COMMIT ]]; then 55 echo "WARNING: Not running as a pre-upload hook. Assuming commit to check = 'HEAD'" 56 PREUPLOAD_COMMIT=HEAD 57fi 58 59# Get version we are about to push into git. 60git show "$PREUPLOAD_COMMIT:$ASM_SUPPORT_GEN_CHECKED_IN_COPY" > "$PREUPLOAD_COMMIT_COPY" || exit 1 61# Get version that our build would have made. 62"$GEN_TOOL" > "$BUILD_COPY" || exit 1 63 64if ! diff "$PREUPLOAD_COMMIT_COPY" "$BUILD_COPY"; then 65 echo "asm-support: ERROR: Checked-in copy of '$ASM_SUPPORT_GEN_CHECKED_IN_COPY' " >&2 66 echo " has diverged from the build copy." >&2 67 echo " Please re-run the 'generate-asm-support' command to resync the header." >&2 68 exit 1 69fi 70 71# Success. Print nothing to avoid spamming users. 72