David Brazdil | 5e0484e | 2019-08-07 15:06:57 +0100 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # Copyright 2019 The Hafnium Authors. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
David Brazdil | 5e0484e | 2019-08-07 15:06:57 +0100 | [diff] [blame] | 15 | |
| 16 | set -euxo pipefail |
| 17 | |
David Brazdil | 4a51d65 | 2019-12-20 13:27:54 +0000 | [diff] [blame] | 18 | SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 19 | SCRIPT_PATH="${SCRIPT_DIR}/$(basename "${BASH_SOURCE[0]}")" |
David Brazdil | 5e0484e | 2019-08-07 15:06:57 +0100 | [diff] [blame] | 20 | ROOT_DIR="$(realpath ${SCRIPT_DIR}/..)" |
| 21 | |
| 22 | if [ "${HAFNIUM_HERMETIC_BUILD:-}" == "true" ] |
| 23 | then |
David Brazdil | 4a51d65 | 2019-12-20 13:27:54 +0000 | [diff] [blame] | 24 | exec "${ROOT_DIR}/build/run_in_container.sh" -p ${SCRIPT_PATH} $@ |
David Brazdil | 5e0484e | 2019-08-07 15:06:57 +0100 | [diff] [blame] | 25 | fi |
| 26 | |
| 27 | if [ $# != 1 ] |
| 28 | then |
| 29 | echo "Usage: $0 <output_file>" 1>&2 |
| 30 | exit 1 |
| 31 | fi |
| 32 | |
| 33 | MAKE="$(which make)" |
| 34 | STRACE="$(which strace)" |
| 35 | |
| 36 | # Set up a temp directory and register a cleanup function on exit. |
| 37 | TMP_DIR="$(mktemp -d)" |
| 38 | function cleanup() { |
| 39 | rm -rf "${TMP_DIR}" |
| 40 | } |
| 41 | trap cleanup EXIT |
| 42 | |
| 43 | STRACE_LOG="${TMP_DIR}/strace.log" |
| 44 | |
| 45 | echo "Building with strace" |
| 46 | pushd ${ROOT_DIR} |
| 47 | ${MAKE} clobber |
| 48 | ${STRACE} \ |
| 49 | -o "${STRACE_LOG}" \ |
| 50 | -f \ |
| 51 | -qq \ |
| 52 | -e trace=%file,chdir,%process \ |
| 53 | ${MAKE} |
| 54 | popd |
| 55 | |
| 56 | echo "Processing strace output" |
| 57 | "${SCRIPT_DIR}/parse_strace_open.py" ${ROOT_DIR} < "${STRACE_LOG}" > "$1" |