-
Notifications
You must be signed in to change notification settings - Fork 22
/
kp_common
83 lines (71 loc) · 2.42 KB
/
kp_common
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
export DOCKER_ARGS IMG_NAME KP_PATH
# Check if Docker image exists
# Use Directly from github container registry if not provided:
# dockerhub location is nishanthmenon/arm-kernel-dev
IMG_NAME="${IMG_NAME:-ghcr.io/nmenon/arm-kernel-dev}"
# TBD: If we are using from github -> I need to figure out how to get that working..
# If we are building locally
# IMG_NAME=arm-kernel-dev
# Check if docker exists
docker=$(which docker)
if [ -z "$docker" ]; then
echo "Please install Docker to be able to function"
exit 1
fi
# If we are working off docker image from github container reg, make sure
# we have the latest.
if [ "$IMG_NAME" = "ghcr.io/nmenon/arm-kernel-dev" ]; then
docker pull "$IMG_NAME"
fi
ccache=$(which ccache 2> /dev/null)
if [ -z "$ccache" ]; then
if [ ! -d "/tmp/ccache" ]; then
mkdir /tmp/ccache
fi
CCACHEDIR=/tmp/ccache
else
CCACHEDIR=$(ccache -s|grep "cache directory"|sed -e "s/\s\s*/ /g"|cut -d ' ' -f3|xargs echo)
if [ -z "$CCACHEDIR" ]; then
CCACHEDIR=$(ccache -v -s|grep -i "cache directory"|sed -e "s/\s\s*/ /g"|cut -d ':' -f2|xargs echo)
fi
fi
DOCKER_ARGS=()
DOCKER_ARGS+=(-v /tmp:/tmp)
DOCKER_ARGS+=(-v /opt:/opt)
DOCKER_ARGS+=(-v "$CCACHEDIR":/ccache)
# Check if current directory is a git directory
if ! git rev-parse --is-inside-work-tree > /dev/null; then
exit 1
fi
ROOT_GIT=$(git rev-parse --show-toplevel)
# if a submodule or worktree then we need to fetch and preserve the gitdir path
if [ -f "${ROOT_GIT}/.git" ]; then
gitdir_str=$(grep -P -o '(?<=gitdir:\s).*' "${ROOT_GIT}/.git")
relative_str=$(echo "$gitdir_str" | grep -P -o '^(../)*')
if [ -n "$relative_str" ]; then
# relative paths need to be preserved
common_path=$(realpath "$ROOT_GIT/$relative_str")
relative_pwd=$(realpath --relative-to="$common_path" "$PWD")
DOCKER_ARGS+=(-v "$common_path":"/workdir")
DOCKER_ARGS+=(-w "/workdir/${relative_pwd}")
else
# absolute paths can be passed through
gitdir_path=$(git rev-parse --git-common-dir)
DOCKER_ARGS+=(-v "$ROOT_GIT":"/workdir")
DOCKER_ARGS+=(-v "$gitdir_path":"$gitdir_path")
fi
else
# normal git directory, just toss everything in
DOCKER_ARGS+=(-v "$ROOT_GIT":"/workdir")
fi
# list of paths to append to the PATH variable in the container
extra_paths=(
/workdir/scripts/dtc
/opt/cross-gcc-linux-13/bin
/opt/cross-gcc-linux-12/bin
/opt/cross-gcc-linux-11/bin
/opt/cross-gcc-linux-10/bin
/opt/cross-gcc-linux-9/bin
)
KP_PATH=$(IFS=:; printf '%s' "${extra_paths[*]}")