-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathcraftenv.sh
83 lines (70 loc) · 2.08 KB
/
craftenv.sh
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
craftRoot="${BASH_SOURCE[0]}"
if [[ -z "$craftRoot" ]];then
craftRoot="$0"
fi
if [[ -z "$craftRoot" ]];then
craftRoot="$_"
fi
if [[ -z "$craftRoot" ]];then
echo "Failed to determine interpreter"
exit 1
fi
if [ -n "$CRAFT_PYTHON_BIN" ]; then
echo "Using user-provided CRAFT_PYTHON_BIN: $CRAFT_PYTHON_BIN";
else
# could not find python 3.9, try python3
if ! command -v python3 >/dev/null; then
echo "Failed to python Python 3.9+"
exit 1
fi
# check if python3 is at least version 3.9:
python_version=$(python3 --version)
# sort -V knows how to compare version numbers
# Note: this is just a sanity check. craft.py should check sys.version
comparison=$(printf '%s\nPython 3.9.0\n' "$python_version" | sort -V)
if [ "$(echo "${comparison}" | head -n1)" != "Python 3.9.0" ]; then
echo "Found Python3 version ${python_version} is too old. Need at least 3.9"
exit 1
fi
CRAFT_PYTHON_BIN=$(command -v python3)
fi
export CRAFT_PYTHON_BIN
if [[ ! -d "$craftRoot" ]]; then
craftRoot=$(${CRAFT_PYTHON_BIN} -c "import os; import sys; print(os.path.dirname(os.path.abspath(sys.argv[1])));" "$craftRoot")
fi
export craftRoot
while read -r -d '' env_var; do
# environment variable keys may not contain =, therefore parsing is relatively easy
key="$(cut -d= -f1 <<<"$env_var")"
value="$(cut -d= -f2- <<<"$env_var")"
export "$key"="$value"
done < <("${CRAFT_PYTHON_BIN}" "$craftRoot/bin/CraftSetupHelper.py" --setup --format null)
if [[ -n "$PS1" ]]; then
export PS1="CRAFT: $PS1"
fi
craft() {
local python="$KDEROOT/dev-utils/bin/python3"
if [[ ! -f "$python" ]]; then
local python=${CRAFT_PYTHON_BIN}
fi
${python} "$craftRoot/bin/craft.py" "$@"
}
cs() {
if ! dir="$(craft -q --ci-mode --get "sourceDir()" "$1")"; then
echo "$dir"
else
cd "$dir" || exit 2
fi
}
cb() {
if ! dir="$(craft -q --ci-mode --get "buildDir()" "$1")"; then
echo "$dir"
else
cd "$dir" || exit 2
fi
}
cr() {
cd "$KDEROOT" || exit 2
}
cr
declare -x -F cs cb cr