blob: e69a72d8457113c46198917409e52de7b851dfc1 [file] [log] [blame]
David Brazdil5e0484e2019-08-07 15:06:57 +01001#!/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 Brazdil5e0484e2019-08-07 15:06:57 +010015
16set -euxo pipefail
17
David Brazdil4a51d652019-12-20 13:27:54 +000018SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19SCRIPT_PATH="${SCRIPT_DIR}/$(basename "${BASH_SOURCE[0]}")"
David Brazdil5e0484e2019-08-07 15:06:57 +010020ROOT_DIR="$(realpath ${SCRIPT_DIR}/..)"
21
22if [ "${HAFNIUM_HERMETIC_BUILD:-}" == "true" ]
23then
David Brazdil4a51d652019-12-20 13:27:54 +000024 exec "${ROOT_DIR}/build/run_in_container.sh" -p ${SCRIPT_PATH} $@
David Brazdil5e0484e2019-08-07 15:06:57 +010025fi
26
27if [ $# != 1 ]
28then
29 echo "Usage: $0 <output_file>" 1>&2
30 exit 1
31fi
32
33MAKE="$(which make)"
34STRACE="$(which strace)"
35
36# Set up a temp directory and register a cleanup function on exit.
37TMP_DIR="$(mktemp -d)"
38function cleanup() {
39 rm -rf "${TMP_DIR}"
40}
41trap cleanup EXIT
42
43STRACE_LOG="${TMP_DIR}/strace.log"
44
45echo "Building with strace"
46pushd ${ROOT_DIR}
47${MAKE} clobber
48${STRACE} \
49 -o "${STRACE_LOG}" \
50 -f \
51 -qq \
52 -e trace=%file,chdir,%process \
53 ${MAKE}
54popd
55
56echo "Processing strace output"
57"${SCRIPT_DIR}/parse_strace_open.py" ${ROOT_DIR} < "${STRACE_LOG}" > "$1"