diff options
Diffstat (limited to 'wrappers/install-wrappers.sh')
-rwxr-xr-x | wrappers/install-wrappers.sh | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/wrappers/install-wrappers.sh b/wrappers/install-wrappers.sh new file mode 100755 index 00000000..461e69a4 --- /dev/null +++ b/wrappers/install-wrappers.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +set -eu -o pipefail + +wrapper_dir=$(cd "$(dirname "$0")"; pwd) + +orig_bin_dir=$(cd "$1"; pwd) +shadow_bin_dir=$(cd "$2"; pwd) +top=$(cd "$3"; pwd) +shadow_top=$(mkdir -p "$4"; cd "$4"; pwd) +shift 4 + +cd "$orig_bin_dir" + +if [ $# = 0 ]; then + # wrap all files + readarray -t to_be_wrapped < <(find ./ ! -type d | sed -e "s#^\./##") +else + # wrap only listed files + to_be_wrapped=("$@") +fi + +bin=$(basename "$(pwd)") + +for exe in "${to_be_wrapped[@]}"; do + if ! [ -x "$exe" ]; then + continue + fi + + mkdir -p "../$bin.orig/$(dirname "$exe")" + mkdir -p "../$bin.wrapper/$(dirname "$exe")" + + # Install or update the wrapper + case "$exe" in + "clang") wrapper="shadow-cc.sh" ;; + "clang++") wrapper="shadow-cc.sh" ;; + "llvm-ar") wrapper="shadow-ar.sh" ;; + "strip.sh") wrapper="shadow-strip.sh" ;; + *) wrapper="count-wrapper.sh" ;; + esac + + exe_hash=$(git rev-parse HEAD) + ccache="CCACHE_COMPILERCHECK=string:$exe_hash /usr/bin/ccache" + + # We copy wrappers to bin.wrapper directory so that we can re-run install + # procedure multiple times without side-effects. + cp "$wrapper_dir/$wrapper" "../$bin.wrapper/$exe" + sed -i \ + -e "s%#TOP#%$top%" \ + -e "s%#SHADOW_TOP#%$shadow_top%" \ + -e "s%#ORIG_TOOL#%$orig_bin_dir/../$bin.orig/$exe%" \ + -e "s%#SHADOW_TOOL#%$shadow_bin_dir/$exe%" \ + -e "s%#CCACHE#%$ccache%" \ + "../$bin.wrapper/$exe" + + # Calculate path relative to $exe's directory -- for ln. + ln_rel_path="$bin.wrapper/$exe" + exe_path="$exe" + while true; do + ln_rel_path="../$ln_rel_path" + exe_path=$(dirname "$exe_path") + if [ "$exe_path" = "." ]; then + break + fi + done + + # Check if executable was already moved to ../bin.orig + if [ -L "$exe" ] \ + && [ x"$(readlink "$exe")" = x"$ln_rel_path" ]; then + continue + fi + + # Move the executable and symlink to the wrapper. + mv "$exe" "../$bin.orig/$exe" + ln -s "$ln_rel_path" "$exe" +done + +mkdir -p "${shadow_top}-counts" +echo "benchmark,symbol,size" > $shadow_top.size |