forked from ni/nilrt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathni-oe-init-build-env
183 lines (153 loc) · 4.66 KB
/
ni-oe-init-build-env
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
181
182
183
#!/usr/bin/env
SCRIPT_ROOT=$(realpath $(dirname ${BASH_SOURCE:-${0}}))
usage() {
cat >&2 <<EOF
$(basename ${BASH_SOURCE}) [-h] [-o] \
[-s SSTATE_MIRROR_PREFIX SSTATE_MIRROR_PATH] \
[[--] OE_INIT_ARGS...]
Arguments:
-h, --help Print this usage text and exit.
-o, --org
Enable configurations which are only valid when the build host is connected
to the NI corporate network. Community builders should not use this
setting.
-s, --sstate-mirror SSTATE_MIRROR_PREFIX SSTATE_MIRROR_PATH
Add the SSTATE_MIRROR_PREFIX/_PATH pair to the bitbake environment's
SSTATE_MIRRORS variable.
Positionals:
PYREX_ARGS Arguments passed to pyrex.py as positional arguments.
EOF
}
enable_ni_org_conf=false
sstate_mirrors=()
positionals=()
set -u
while [ $# -ge 1 ]; do case "$1" in
-d|--download-dir)
shift
export DL_DIR=$(realpath "$1")
shift
;;
-h|--help)
usage
return 0
;;
-o|--org)
enable_ni_org_conf=true
shift
;;
-s|--sstate-mirror)
if [ -z "${2:-}" -o -z "${3:-}" ]; then
echo "ERROR: --sstate-mirror argument expected two strings." >&2
return 2
fi
sstate_mirrors+=("$2 $3")
shift 3
;;
--)
shift
for positional in $@; do
positionals+=($positional)
done
break
;;
-*|--*)
echo "ERROR: Unknown script argument $1." >&2
return 2
;;
*)
positionals+=($1)
shift
;;
esac; done
set +u
# Determine the OE build workspace path. We honor the user's BUILDDIR env
# variable, unless it is undefined, or overwritten with positional arguments.
if [ -n "${positionals[0]}" ]; then
BUILDDIR=${positionals[0]}
positionals=${positionals[@]:1} # shift array
elif [ -z "$BUILDDIR" ]; then
# if the user has expressed no preference, default to :build/
BUILDDIR="${SCRIPT_ROOT}/build"
fi # implicit-else: use the users's BUILDDIR value
echo "INFO: Using ${BUILDDIR} as the OE build workspace."
NILRT_ROOT="${SCRIPT_ROOT}"
# GIT_REPODIR is used by the meta-nilrt bblayers.conf to locate the BB layer
# top-level directory.
export GIT_REPODIR="${NILRT_ROOT}/sources"
# Enable color terminal by default
export TERM=${TERM:-xterm-256color}
BITBAKEDIR=${BITBAKEDIR:-${NILRT_ROOT}/sources/bitbake}
## BITBAKE VARIABLES ##
# Users can assert the maximum number of concurrent bitbake threads via the
# BB_NUMBER_THREADS variable, or let this script calculate a reasonable value
# based on the number of cores.
if [ -z "${BB_NUMBER_THREADS:-}" ]; then
echo "INFO: BB_NUMBER_THREADS not set. Calculating..."
# num_cores * 2 is the recommended value from the yocto manual
BB_NUMBER_THREADS=$(($(nproc) * 2))
fi
export BB_NUMBER_THREADS
echo "BB_NUMBER_THREADS=${BB_NUMBER_THREADS}"
# define the location of bitbake configuration files, which will be copied
# into the build workspace, if one needs to be created.
export TEMPLATECONF=${TEMPLATECONF:-${NILRT_ROOT}/sources/meta-nilrt/conf}
export SSTATE_MIRRORS="${SSTATE_MIRRORS:-} ${sstate_mirrors[@]/%/ \\n}"
# Define here all NILRT-specific variables which need to be passed to bitbake
# (should include everything we've set above which is non-standard)
export BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS:-} \
BB_NUMBER_THREADS \
BUILDNAME \
DISTRO \
DL_DIR \
GIT_REPODIR \
IPK_FEED_URIS \
MACHINE \
NILRT_LOCAL_FEED_URI \
SDKMACHINE \
SSTATE_DIR \
SSTATE_MIRRORS \
"
## PYREX VARIABLES ###
# Setup pyrex config variables
export PYREXCONFFILE=${PYREXCONFFILE:-"${SCRIPT_ROOT}/pyrex.ini"}
export PYREX_CONFIG_BIND="${NILRT_ROOT}"
export PYREX_OEINIT="${NILRT_ROOT}/sources/openembedded-core/oe-init-build-env"
export PYREX_ROOT="${NILRT_ROOT}/sources/pyrex"
nilrt_codename=$(grep -e '^LAYERSERIES_COMPAT_meta-nilrt' "${TEMPLATECONF}/layer.conf" | cut -d'"' -f2)
export PYREX_BUILD_NILRT_IMAGE="${PYREX_BUILD_NILRT_IMAGE:-build-nilrt:${nilrt_codename}}"
echo "INFO: Using pyrex image: ${PYREX_BUILD_NILRT_IMAGE}"
unset SCRIPT_ROOT
if [ -z "${PYREX_TEMP_ENV_FILE:-}" ]; then
PYREX_TEMP_ENV_FILE=$(mktemp -t pyrex-env.XXXXXX)
fi
pyrex_cleanup() {
rm -f "$PYREX_TEMP_ENV_FILE"
unset PYREX_OEINIT PYREX_ROOT PYREX_TEMP_ENV_FILE pyrex_cleanup
}
# Do some initial setup on the build directory
if $enable_ni_org_conf; then
{
install -D --mode=0644 \
"${NILRT_ROOT}/scripts/azdo/conf/ni-org.conf" \
"${BUILDDIR}/conf/site.conf"
} || exit 1
fi
# Invoke pyrex to: standup our build container and BB build directory, and to
# "capture" the current shell within the pyrex toolchain context.
"$PYREX_ROOT/pyrex.py" capture \
-a PYREX_OEINIT "$PYREX_OEINIT" \
-e PYREXCONFFILE \
-e TEMPLATECONF \
-- 9 "${BUILDDIR}" "${positionals[@]}" \
9> "$PYREX_TEMP_ENV_FILE"
if [ $? -ne 0 ]; then
pyrex_cleanup
return 1
fi
. "$PYREX_TEMP_ENV_FILE"
if [ $? -ne 0 ]; then
pyrex_cleanup
return 1
fi
pyrex_cleanup