-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-environment
executable file
·213 lines (177 loc) · 5.78 KB
/
setup-environment
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only
#
# -*- mode: shell-script; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
#
# Copyright (C) 2012, 2013, 2016 O.S. Systems Software LTDA.
# Authored-by: Otavio Salvador <otavio@ossystems.com.br>
#
# Copyright (C) 2017-2024 TQ-Systems GmbH <oss@ew.tq-group.com>,
# D-82229 Seefeld, Germany.
# Author: Markus Niebel
#
# Add options for the script
# Copyright (C) 2013 Freescale Semiconductor, Inc.
CWD=$(pwd)
PROGNAME="setup-environment"
SCRIPTDIR="${CWD}/ci"
CONFIG_TEMPLATE=x86
TEMPLATEDIR=${CWD}/sources/template/conf/templates
usage()
{
echo "
Usage: MACHINE=<machine> DISTRO=<distro> source ${PROGNAME} <build-dir> <config>
Usage: source ${PROGNAME} <build-dir> <config>
<machine> machine name
<distro> distro name
<build-dir> build directory
<config> configuration to use (optional, default: ${CONFIG_TEMPLATE})
The first usage is for creating a new build directory. In this case, the
script creates the build directory <build-dir>, configures it for the
specified <machine> and <distro>, and prepares the calling shell for running
bitbake on the build directory.
The second usage is for using an existing build directory. In this case,
the script prepares the calling shell for running bitbake on the build
directory <build-dir>. The build directory configuration is unchanged.
To query supported configs use:
${SCRIPTDIR}/ls-configs --file
To query supported machines for a configuration:
${SCRIPTDIR}/ls-machines --file --config=<config>
To query supported TQ-Systems distros for a configuration:
${SCRIPTDIR}/ls-distros --file --config=<config>
If 'meta-poky' is in 'bblayer.conf', available poky distros can be queried:
${SCRIPTDIR}/ls-distros --dir=sources/poky/meta-poky
Supported configurations in this project are:
$(${SCRIPTDIR}/ls-configs --file | sort)
Usage examples:
- To create a new Yocto build directory:
\$ MACHINE=<machine> DISTRO=<distro> source ${PROGNAME} <build-dir> <config>
- To use an existing Yocto build directory:
\$ source ${PROGNAME} <build-dir>
See README.md for valid combinations of <machine>, <distro> and <config>
"
}
clean_up() {
unset ARGS
unset CONFIG_TEMPLATE
unset CWD
unset DISTRO_VAR
unset generated_config
unset build_dir_setup_enabled
unset LIST_MACHINES
unset LONGOPTS
unset OEROOT
unset PROGNAME
unset SCRIPTDIR
unset SHORTOPTS
unset TEMPLATECONF
unset TEMPLATEDIR
unset THE_DISTRO
unset THE_MACHINE
unset VALID_MACHINE
}
# get command line options
SHORTOPTS="h"
LONGOPTS="help"
ARGS=$(getopt --options ${SHORTOPTS} \
--longoptions ${LONGOPTS} --name ${PROGNAME} -- "$@" )
# Print the usage menu if invalid options are specified
if [ $? != 0 ] || [ $# -lt 1 ]; then
usage && clean_up
return 1
fi
eval set -- "${ARGS}"
while true;
do
case $1 in
-h|--help)
usage
clean_up
return 0
;;
--)
shift
break
;;
esac
done
if [ "$(whoami)" = "root" ]; then
echo "ERROR: do not use the BSP as root. Exiting..." >&2
fi
if [ -n "${2}" ]; then
CONFIG_TEMPLATE=${2}
fi
TEMPLATECONF=${TEMPLATEDIR}/${CONFIG_TEMPLATE}
if [ ! -e ${1}/conf/local.conf.sample ]; then
build_dir_setup_enabled="true"
else
build_dir_setup_enabled="false"
fi
if [ "${build_dir_setup_enabled}" = "true" ]; then
if [ -z "${MACHINE}" ]; then
THE_MACHINE="$(${SCRIPTDIR}/ls-machines --file --config=${CONFIG_TEMPLATE} | awk 'NR==1 {print; exit}')"
else
THE_MACHINE=${MACHINE}
fi
if [ -z "${THE_MACHINE}" ]; then
usage
echo "ERROR: You must set MACHINE when creating a new build directory." >&2
clean_up
return 1
fi
if [ -z "${DISTRO}" ]; then
THE_DISTRO="$(${SCRIPTDIR}/ls-distros --file --config=${CONFIG_TEMPLATE} | awk 'NR==1 {print; exit}')"
else
THE_DISTRO=${DISTRO}
fi
if [ -z "${THE_DISTRO}" ]; then
usage
echo "ERROR: You must set DISTRO when creating a new build directory." >&2
clean_up
return 1
fi
fi
OEROOT="${CWD}/sources/poky"
if [ -e "${CWD}/sources/oe-core" ]; then
OEROOT="${CWD}/sources/oe-core"
fi
BB_ENV_PASSTHROUGH_ADDITIONS="${BB_ENV_PASSTHROUGH_ADDITIONS} TQ_GIT_BASEURL TQ_GIT_PROTOCOL"
# Hide messages from oe-init-build-env.
# Since we do some more stuff after the basic builddir setup
# as setting own bblayers.conf and display some licenses
# the output will not be read from most of the users.
# We therefore show the content of conf-notes.txt rigth before finishing.
. "${OEROOT}/oe-init-build-env" "${1}" > /dev/null
# if conf/local.conf not generated, no need to go further
if [ ! -e "conf/local.conf" ]; then
clean_up && return 1
fi
# Clean up PATH, because if it includes tokens to current directories somehow,
# wrong binaries can be used instead of the expected ones during task execution
export PATH="`echo ${PATH} | sed 's/\(:.\|:\)*:/:/g;s/^.\?://;s/:.\?$//'`"
generated_config=
if [ "$build_dir_setup_enabled" = "true" ]; then
"${SCRIPTDIR}/setup_builddir" confdir_setup "${TEMPLATECONF}"
if [ "${?}" -ne "0" ]; then
clean_up && return 1
fi
"${SCRIPTDIR}/setup_builddir" localconf_defaults "${THE_MACHINE}" "${THE_DISTRO}"
generated_config=1
fi
"${SCRIPTDIR}/setup_builddir" handle_licenses "${CWD}"
# Print welcome banner, since we drop output from oe-init-build-env above
if [ -e "${TEMPLATECONF}/conf-notes.txt" ]; then
cat "${TEMPLATECONF}/conf-notes.txt"
fi
# finally give info whether we use an existing buildspace or
# just created a new one ...
if [ -n "${generated_config}" ]; then
cat <<EOF
Your build environment has been configured with:
MACHINE=${THE_MACHINE}
DISTRO=${THE_DISTRO}
EOF
else
echo "Your configuration files at $1 have not been touched."
fi
clean_up