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