blob: 0301a3e67999040316263b571d86e5fa74320848 [file] [log] [blame]
Igor Murashkin2bb70d32017-02-06 10:34:14 -08001#!/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
Igor Murashkin969ca5a2017-02-15 13:05:59 -080025 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
Igor Murashkin2bb70d32017-02-06 10:34:14 -080030 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.