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 the $OUT directory in the build. 20# Then verifies that it is the same as in runtime/generated/asm_support_gen.h 21 22# Validates that art/runtime/generated/asm_support_gen.h 23# - This must be run after a build since it uses cpp-define-generator-data 24 25# Path to asm_support_gen.h that we check into our git repository. 26ASM_SUPPORT_GEN_CHECKED_IN_COPY="runtime/generated/asm_support_gen.h" 27# Instead of producing an error if checked-in copy differs from the generated version, 28# overwrite the local checked-in copy instead. 29OVERWRITE_CHECKED_IN_COPY_IF_CHANGED="n" 30 31####################### 32####################### 33 34DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 35ART_DIR="$( cd "$DIR/../.." && pwd )" 36ABS_ASM_SUPPORT_GEN_CHECKED_IN_COPY="$ART_DIR/runtime/generated/asm_support_gen.h" 37 38# Sanity check that we haven't moved the file around. 39# If we did, perhaps the above constant should be updated. 40if ! [[ -f "$ABS_ASM_SUPPORT_GEN_CHECKED_IN_COPY" ]]; then 41 echo "ERROR: Missing asm_support_gen.h, expected to be in '$ABS_ASM_SUPPORT_GEN_CHECKED_IN_COPY'" >&2 42 exit 1 43fi 44 45# The absolute path to cpp-define-generator is in $1 46# Generate the file as part of the build into the out location specified by $2. 47 48# Compare that the generated file matches our golden copy that's checked into git. 49# If not, it is a fatal error and the user needs to run 'generate-asm-support' to rebuild. 50 51if [[ $# -lt 2 ]]; then 52 echo "Usage: $0 [--quiet] [--presubmit] <path-to-cpp-define-generator-data-binary> <output-file>'" >&2 53 exit 1 54fi 55 56# Supress 'chatty' messages during the build. 57# If anything is printed in a success case then 58# the main Android build can't reuse the same line for 59# showing multiple commands being executed. 60QUIET=false 61if [[ "$1" == "--quiet" ]]; then 62 QUIET=true 63 shift 64fi 65 66CPP_DEFINE_GENERATOR_TOOL="$1" 67OUTPUT_FILE="$2" 68 69function pecho() { 70 if ! $QUIET; then 71 echo "$@" 72 fi 73} 74 75# Generate the header. Print the command we're running to console for readability. 76pecho "cpp-define-generator-data > \"$OUTPUT_FILE\"" 77"$CPP_DEFINE_GENERATOR_TOOL" > "$OUTPUT_FILE" 78retval="$?" 79 80if [[ $retval -ne 0 ]]; then 81 echo "verify-asm-support: FATAL: Error while running cpp-define-generator-data" >&2 82 exit $retval 83fi 84 85if ! diff "$ABS_ASM_SUPPORT_GEN_CHECKED_IN_COPY" "$OUTPUT_FILE"; then 86 87 if [[ $OVERWRITE_CHECKED_IN_COPY_IF_CHANGED == "y" ]]; then 88 cp "$OUTPUT_FILE" "$ABS_ASM_SUPPORT_GEN_CHECKED_IN_COPY" 89 echo "verify-asm-support: OK: Overwrote '$ASM_SUPPORT_GEN_CHECKED_IN_COPY' with build copy." 90 echo " Please 'git add $ASM_SUPPORT_GEN_CHECKED_IN_COPY'." 91 else 92 echo "---------------------------------------------------------------------------------------------" >&2 93 echo "verify-asm-support: ERROR: Checked-in copy of '$ASM_SUPPORT_GEN_CHECKED_IN_COPY' " >&2 94 echo " has diverged from the build copy." >&2 95 echo " Please re-run the 'generate-asm-support' command to resync the header." >&2 96 [[ -f "$OUTPUT_FILE" ]] && rm "$OUTPUT_FILE" 97 exit 1 98 fi 99fi 100 101pecho "verify-asm-support: SUCCESS. Built '$OUTPUT_FILE' which matches our checked in copy." 102