-
Notifications
You must be signed in to change notification settings - Fork 9
/
setup-env
222 lines (179 loc) · 5.78 KB
/
setup-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
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
214
215
216
217
218
219
220
221
222
#!/bin/sh
if [ -z "$ZSH_NAME"] && [ "x$0" = "x./setup-env" ]; then
echo "Error: This script needs to be sourced."
exit 1
fi
PROGNAME="setup-env"
DISTRO_DEFAULT="testdistro"
BUILDDIR_DEFAULT="build"
if [ -n "$BASH_SOURCE" ]; then
CWD="`dirname $BASH_SOURCE`"
elif [ -n "$ZSH_SOURCE"]; then
CWD="`dirname $0`"
else
CWD="`pwd`"
fi
if [ -n "$BBSERVER" ]; then
unset BBSERVER
fi
usage()
{
cat <<EOF
Usage: source $PROGNAME --machine <MACHINE> [<options>] [<BUILDDIR>]
Usage: source $PROGNAME [<BUILDDIR>]
Options:
-h, --help Print this usage message
-m, --machine Build MACHINE name
-d, --distro Build DISTRO name (default '${DISTRO_DEFAULT}')
-c, --color Colorize the output; can be 'never', 'always',
or 'auto' (default 'auto')
Arguments:
BUILDDIR Location of BUILDDIR (default '${BUILDDIR_DEFAULT}')
The first usage is for creating a new build directory. In this case, the
script creates the build directory <BUILDDIR>, 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 <BUILDDIR>. The build directory configuration is unchanged.
EOF
ls layers/*/conf/machine/*.conf > /dev/null 2>&1
ls layers/meta-testdistro/conf/distro/*.conf > /dev/null 2>&1
if [ $? -eq 0 ]; then
cat <<EOF
Supported machines: `echo; ls layers/*/conf/machine/*.conf \
| sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"`
Supported Tegra test distros: `echo; ls layers/meta-testdistro/conf/distro/*.conf \
| sed s/\.conf//g | sed -r 's/^.+\///' | xargs -I% echo -e "\t%"`
Examples:
- To create a new Yocto build directory:
$ source $PROGNAME --machine jetson-tx2 --distro testdistro build-testdistro
- To use an existing Yocto build directory:
$ source $PROGNAME build-testdistro
EOF
fi
}
clean_up()
{
unset LIST_MACHINES VALID_MACHINE
unset CWD TEMPLATES SHORTOPTS LONGOPTS ARGS PROGNAME
unset generated_config updated
unset MACHINE DISTRO OEROOT TEMPLATECONF BBPATH TDROOT
unset COLOR
}
# get command line options
SHORTOPTS="hm:d:b:c:"
LONGOPTS="help,machine,distro,color"
ARGS=$(getopt --options $SHORTOPTS \
--longoptions $LONGOPTS --name $PROGNAME -- "$@" )
# Print the usage menu if invalid options are specified
if [ $? != 0 ]; then
usage && clean_up
return 1
fi
eval set -- "$ARGS"
while true;
do
case $1 in
-h | --help) usage; clean_up; return 0 ;;
-m | --machine) MACHINE="$2"; shift; shift;;
-d | --distro) DISTRO="$2"; shift; shift;;
-c | --color) COLOR="$2"; shift; shift;;
-- ) shift; break ;;
* ) break ;;
esac
done
if [ $(id -u) -eq 0 ]; then
echo "ERROR: do not use the BSP as root. Exiting..."
clean_up
return 1
fi
BUILDDIR="${1:-$BUILDDIR_DEFAULT}"
if [ ! -e $BUILDDIR/conf/local.conf ]; then
build_dir_setup_enabled="true"
else
build_dir_setup_enabled="false"
fi
if [ "$build_dir_setup_enabled" = "true" ] && [ -z "$MACHINE" ]; then
usage
echo -e "ERROR: You must set MACHINE when creating a new build directory."
clean_up
return 1
fi
if [ "$build_dir_setup_enabled" = "true" ] && [ -z "$DISTRO" ]; then
DISTRO=$DISTRO_DEFAULT
fi
if [ -z "$COLOR" ]; then
COLOR=auto
fi
if [ $COLOR = "always" ]; then
COLOR=1
elif [ $COLOR = "auto" ]; then
if [ -t 1 ]; then
COLOR=1
else
COLOR=0
fi
else
COLOR=0
fi
(cd $CWD; git submodule sync > /dev/null 2>&1)
(cd $CWD; git submodule status | grep '^-' | awk '{print $2}' | xargs git submodule update --init --)
# Allow for multiple layer sets,
# default just "layers"
if [ "x$BMETA" = "x" ]; then
BMETA="layers"
fi
OEROOT=`readlink -f "$CWD/$BMETA"`
export OEROOT
# we need the OEROOT path later, but it gets unset by oe-init-build-env
TDROOT=$OEROOT
# templateconf uses this value, but only on initial setup
export DISTRO
. $OEROOT/openembedded-core/oe-init-build-env $CWD/$BUILDDIR > /dev/null
# if conf/local.conf not generated, no need to go further
if ! [ -d "$BUILDDIR" -a -e $BUILDDIR/conf/local.conf ]; then
echo -e "ERROR: could not create build directory or local.conf"
clean_up && return 1
fi
generated_config=
if [ "$build_dir_setup_enabled" = "true" ]; then
# Change settings according environment
sed -e "s,MACHINE ??=.*,MACHINE ??= '$MACHINE',g" \
-e "s,DISTRO ?=.*,DISTRO ?= '$DISTRO',g" \
-i conf/local.conf
for s in $HOME/.oe $HOME/.yocto; do
if [ -e $s/site.conf ]; then
echo "Linking $s/site.conf to conf/site.conf"
ln -s $s/site.conf conf
fi
done
generated_config=1
fi
TEMPLATECONF=$(cat "$BUILDDIR/conf/templateconf.cfg")
cat $TDROOT/$TEMPLATECONF/conf-notes.txt
if [ -d "$TDROOT/meta-testdistro/scripts" ]; then
PATH="$TDROOT/meta-testdistro/scripts:$PATH"
else
echo "Testdistro setup scripts could not be found!"
fi
if [ -n "$generated_config" ]; then
cat <<EOF
Your build environment has been configured with:
MACHINE=$MACHINE
DISTRO=$DISTRO
EOF
else
echo "Your configuration files at $BUILDDIR have not been touched."
. td-diff-layers
fi
if [ ! -f "$BUILDDIR/conf/site.conf" -a \
-f "$TDROOT/$TEMPLATECONF/site.conf.sample" ]; then
cp $TDROOT/$TEMPLATECONF/site.conf.sample $BUILDDIR/conf/site.conf
fi
. buildenv-host-gcc-check
BB_ENV_EXTRAWHITE="GNUPGHOME DBUS_SESSION_BUS_ADDRESS AWS_CONFIG_FILE AWS_PROFILE AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SHARED_CREDENTIALS_FILE AWS_SESSION_TOKEN AWS_DEFAULT_REGION $BB_ENV_EXTRAWHITE"
if [ "`umask | tail -c 2`" = "7" ]; then
umask 0022
fi
clean_up