generated from qualcomm/qualcomm-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsetup-environment
More file actions
executable file
·180 lines (156 loc) · 4.29 KB
/
setup-environment
File metadata and controls
executable file
·180 lines (156 loc) · 4.29 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/sh
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
# SPDX-License-Identifier: BSD-3-Clause-Clear
usage() {
cat <<'EOF'
Usage:
source setup-environment --machine <machine.yml> --distro <distro.yml> [--kernel <kernel.yml>]
Options:
-m, --machine Path to MACHINE kas configuration file (required)
-d, --distro Path to DISTRO kas configuration file (required)
-k, --kernel Path to KERNEL kas configuration file (optional)
-h, --help Show this help
Examples:
bash:
source setup-environment --machine meta-qcom/ci/qcs9100-ride-sx.yml --distro meta-qcom/ci/qcom-distro.yml
dash:
set -- -m meta-qcom/ci/qcs9100-ride-sx.yml -d meta-qcom/ci/qcom-distro.yml -k meta-qcom/ci/linux-qcom-6.18.yml
. ./setup-environment
EOF
}
# Parse --flags and populate MACHINE/DISTRO/KERNEL variables
parse_args() {
MACHINE=""
DISTRO=""
KERNEL=""
while [ $# -gt 0 ]; do
case "$1" in
-m|--machine)
[ $# -ge 2 ] || { echo "ERROR: --machine requires a value"; usage; return 1; }
MACHINE="$2"
shift 2
;;
-d|--distro)
[ $# -ge 2 ] || { echo "ERROR: --distro requires a value"; usage; return 1; }
DISTRO="$2"
shift 2
;;
-k|--kernel)
[ $# -ge 2 ] || { echo "ERROR: --kernel requires a value"; usage; return 1; }
KERNEL="$2"
shift 2
;;
-h|--help)
usage
SKIP_SETUP="1"
return 0
;;
-*)
echo "ERROR: Unknown option: $1"
usage
return 1
;;
*)
echo "ERROR: Unexpected positional argument: $1"
usage
return 1
;;
esac
done
}
validation_checks() {
if [ -z "$MACHINE" ]; then
echo "ERROR: MACHINE needs to be set (use --machine <file>)"
return 1
fi
if [ -z "$DISTRO" ]; then
echo "ERROR: DISTRO needs to be set (use --distro <file>)"
return 1
fi
if [ -n "$KERNEL" ] && [ ! -f "$KERNEL" ]; then
echo "ERROR: KERNEL needs to point to a kas configuration file"
return 1
fi
if [ ! -f "$MACHINE" ]; then
echo "ERROR: MACHINE needs to point to a kas configuration file"
return 1
fi
if [ ! -f "$DISTRO" ]; then
echo "ERROR: DISTRO needs to point to a kas configuration file"
return 1
fi
}
parse_env_vars() {
python3 -c "
import yaml
try:
with open('$1') as f:
config = yaml.safe_load(f)
except Exception as e:
print('Failed to parse {}: {}'.format('$1', e))
exit(1)
env_vars = config.get('env', {})
for key, value in env_vars.items():
print('export {}=\"{}\"'.format(key, value))
"
}
cleanup() {
[ -f .config.yaml ] && rm .config.yaml
unset MACHINE DISTRO KERNEL CONFIG_FILES SKIP_SETUP
}
init_env() {
parse_args "$@" || return $?
# if --help is passed, we can skip environment setup
if [ "$SKIP_SETUP" = "1" ]; then
cleanup
return
fi
echo "INFO: Running validation checks."
validation_checks || return $?
CONFIG_FILES="$MACHINE:$DISTRO"
if [ -n "$KERNEL" ]; then
CONFIG_FILES="$CONFIG_FILES:$KERNEL"
fi
# invoking kas shell should auto-generate BitBake configuration
# based on the kas local_conf_header
echo "INFO: Setting up bitbake configuration."
kas -l error shell \
--skip repo_setup_loop \
--skip finish_setup_repos \
--skip repos_checkout \
--skip repos_apply_patches \
"$CONFIG_FILES" -c "exit 0" || \
{
cleanup
echo "ERROR: Failure during bitbake configuration setup."
return 1
}
# parse and generate kas configuration
echo "INFO: Generating temporary kas configuration."
kas -l error dump \
--skip repo_setup_loop \
--skip finish_setup_repos \
--skip repos_checkout \
--skip repos_apply_patches \
"$CONFIG_FILES" > .config.yaml || \
{
cleanup
echo "ERROR: Failure while parsing kas configuration."
return 1
}
echo "INFO: Exporting environment variables from kas configuration."
eval "$(parse_env_vars .config.yaml)" || \
{
cleanup
echo "ERROR: Failure during environment variable setup."
return 1
}
echo "INFO: Cleaning up temporary contents."
cleanup
echo "INFO: Initializing bitbake environment."
# switch to oe-core directory, so oe-init-build-env can figure out OEROOT correctly
set -- "$PWD/build"
cd "${PWD}/oe-core"
. "$PWD/oe-init-build-env"
}
init_env "$@"