Skip to content

Commit 8021373

Browse files
committed
Fix bin/format to work on mac os
For reasons I didn't explore further, /mnt/host/Users is shown in the directory listing of /mnt/host, but can't be traversed
1 parent fbcc2d9 commit 8021373

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

bin/format

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
set -e
44

5+
# Determine the script directory and repository root
6+
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
7+
REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd)
8+
59
# Go to the repository root directory.
6-
cd "$(dirname "$0")"/..
10+
cd "$REPO_ROOT"
711

812
# clang-format's behavior changes between versions, even given the same
913
# configuration.
@@ -41,16 +45,16 @@ if [ "$(docker image ls --quiet $image | wc -l)" -eq 0 ]; then
4145
esac
4246
fi
4347

44-
mount_path=/mnt/host
48+
mount_path=/mnt/repo
4549

46-
# File paths passed to the dockerized clang-format need to be resolved and
47-
# prefixed with the bind mount path.
50+
# File paths passed to the dockerized clang-format need to be relative to
51+
# the repository root and prefixed with the bind mount path.
4852
#
4953
# Non-path arguments (flags) are left alone.
5054
process_arg() {
5155
case "$1" in
5256
-*) printf '%s\0' "$1" ;;
53-
*) printf '%s/%s\0' "$mount_path" "$(realpath "$1")" ;;
57+
*) printf '%s/%s\0' "$mount_path" "$1" ;;
5458
esac
5559
}
5660

@@ -65,7 +69,7 @@ docker_clang_format() {
6569
--volume /etc/passwd:/etc/passwd:ro \
6670
--volume /etc/group:/etc/group:ro \
6771
--user "$(id -u):$(id -g)" \
68-
--mount "type=bind,source=/,destination=$mount_path" \
72+
--mount "type=bind,source=$REPO_ROOT,destination=$mount_path" \
6973
"$image" \
7074
clang-format $formatter_options
7175
}

0 commit comments

Comments
 (0)