-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
324 lines (308 loc) · 12 KB
/
setup.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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#!/bin/bash -x
export -n BBPATH
if [ -n "$BASH_SOURCE" ]; then
THIS_SCRIPT=$BASH_SOURCE
elif [ -n "$ZSH_NAME" ]; then
THIS_SCRIPT=$0
else
THIS_SCRIPT="$(pwd)/setup.sh"
fi
if [ -z "$ZSH_NAME" ] && [ "$0" = "$THIS_SCRIPT" ]; then
EXIT="exit"
else
EXIT="return"
fi
export PATH=$PATH
THIS_SCRIPT=$(readlink -f $THIS_SCRIPT)
TOPDIR=$(dirname $THIS_SCRIPT)
if [ "x$1" = "x" ] ;
then
buildDir=$TOPDIR/project
echo "$buildDir used as project." 2>&1
echo "To change source $THIS_SCRIPT <builddir>" 2>&1
else
buildDir=$1
fi
mkdir -p $buildDir
buildDir=$(readlink -f $buildDir)
REPO_CONFIG="\
LAYER@https://github.com/MontaVista-OpenSourceTechnology/poky.git;branch=scarthgap-cgx;layer=meta \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/poky.git;branch=scarthgap-cgx;layer=meta-poky \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/poky.git;branch=scarthgap-cgx;layer=meta-yocto-bsp \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-openembedded.git;branch=scarthgap-cgx;layer=meta-oe \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-openembedded.git;branch=scarthgap-cgx;layer=meta-python \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-openembedded.git;branch=scarthgap-cgx;layer=meta-networking \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-openembedded.git;branch=scarthgap-cgx;layer=meta-filesystems \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-openembedded.git;branch=scarthgap-cgx;layer=meta-webserver \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-clang.git;branch=scarthgap-cgx \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-virtualization.git;branch=scarthgap-cgx \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-qa.git;branch=scarthgap-cgx;layer=meta-qa-framework \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-qa.git;branch=scarthgap-cgx;layer=meta-qa-testsuites \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-montavista-cgx.git;branch=scarthgap-cgx \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-openembedded.git;branch=scarthgap-cgx;layer=meta-perl \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-openembedded.git;branch=scarthgap-cgx;layer=meta-gnome \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-openembedded.git;branch=scarthgap-cgx;layer=meta-multimedia \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-openembedded.git;branch=scarthgap-cgx;layer=meta-xfce \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-selinux.git;branch=scarthgap-cgx \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-security.git;branch=scarthgap-cgx \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-cgl.git;branch=scarthgap-cgx;layer=meta-cgl-common \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-cloud-services.git;branch=scarthgap-cgx \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-montavista-cgl.git;branch=scarthgap-cgx \
LAYER@https://github.com/MontaVista-OpenSourceTechnology/meta-montavista-armsr.git;branch=scarthgap-cgx \
MACHINE@generic-arm64 \
CONFIG@PREFERRED_PROVIDER_virtual/kernel=linux-mvista \
CONFIG@USE_SYSTEMD=1 \
DISTRO@mvista-cgx \
"
TOPDIR=$(dirname $THIS_SCRIPT)
buildtar=""
URL=""
for config in $REPO_CONFIG; do
VAR=$(echo $config | cut -d @ -f 1)
VAL=$(echo $config | cut -d @ -f 2)
if [ "$VAR" = "URL" ] ; then
URL=$VAL
URLBASE=$(echo $URL | cut -d / -f 1-3)
HOST=$(echo $URL | cut -d / -f 3)
fi
done
export BUILD_TOOLS_LOCATION
export buildtar
$TOPDIR/bin/fetch-buildtools || $EXIT 1
if which python 2>/dev/null >/dev/null; then
PYTHON=python
elif which python2 2>/dev/null >/dev/null; then
PYTHON=python2
elif which python3 2>/dev/null >/dev/null; then
PYTHON=python3
else
echo "Could not find system python, please install"
$EXIT 1
fi
source $TOPDIR/buildtools/environment-setup-*
if [ "$?" != "0" ] ; then
$EXIT 1
fi
chmod 755 $TOPDIR/bin/*
if [[ ("x$URLBASE" != "x") && ( "$HOST" = "staging.support.mvista.com" || "$HOST" = "support.mvista.com") ]] ; then
git config --global credential.$URLBASE.helper $TOPDIR/bin/git-credential-mvl
git config --global http.$URLBASE.cookiefile $($TOPDIR/bin/mvl-fetch -c $URLBASE)
fi
if [ -z "$ALLOW_UPDATE" ] ; then
ALLOW_UPDATE=1
fi
if [ ! -e $TOPDIR/.drop -o "$ALLOW_UPDATE" = "1" ] ; then
if [ ! -e $TOPDIR/.repo ] ; then
pushd $TOPDIR 2>/dev/null 1>/dev/null
git config pull.rebase True
git submodule init || $EXIT 1
if [ -z "$GIT_RETRIES" -o "$GIT_RETRIES" = "0" ] ; then
GIT_RETRIES=5
fi
if [ -z "$GIT_DELAY" ] ; then
GIT_DELAY=10
fi
GIT_COUNT=1
while [ $GIT_COUNT -lt $GIT_RETRIES ] ; do
git submodule update --remote
if [ $? -eq 0 ] ; then
GIT_RETRIES=0
break
fi
GIT_COUNT=$(($GIT_COUNT + 1))
echo "git submodule update failed, sleeping for $GIT_DELAY seconds and retrying"
sleep $GIT_DELAY
done
if [ $GIT_RETRIES != 0 ] ; then
$EXIT 1
fi
popd 2>/dev/null 1>/dev/null
else
pushd $TOPDIR 2>/dev/null >/dev/null
repo sync
popd 2>/dev/null >/dev/null
fi
fi
if [ -z "$TEMPLATECONF" -o ! -d "$TEMPLATECONF" ] ; then
export TEMPLATECONF=$TOPDIR/layers/meta-montavista-cgx/conf/templates/default
fi
source $TOPDIR/layers/poky/oe-init-build-env $buildDir
if [ "$?" != "0" ] ; then
$EXIT 1
fi
export BB_NO_NETWORK="1"
export LAYERS_RELATIVE="1"
if [ -z "$LOCAL_SOURCES" ] ; then
LOCAL_SOURCES=1
fi
if [ -e $TOPDIR/.drop -o "$MAKEDROP" = "1" ] ; then
LOCAL_SOURCES=1
fi
echo "# Do not modify, automatically generated" > conf/local-content.conf
echo >> conf/local-content.conf
for config in $REPO_CONFIG; do
VAR=$(echo $config | cut -d @ -f 1)
VAL=$(echo $config | cut -d @ -f 2)
if [ "$VAR" = "LAYER" ] ; then
layer=$(echo $VAL | cut -d \; -f 1)
layerDir=$(basename $layer | sed s,.git,,)
options=$(echo $VAL | cut -d \; -f 2-)
sublayer=""
for option in $(echo $options | sed s,\;,\ ,g); do
if [ "$(echo $option | cut -d = -f 1)" = "layer" ] ; then
sublayer=$(echo $option | cut -d = -f 2)
fi
done
if [ "$MAKEDROP" != "1" ] ; then
mkdir -p $buildDir/.layers
if [ ! -e $buildDir/.layers/$layerDir-$sublayer ] ; then
echo "adding $layerDir/$sublayer"
bitbake-layers -F add-layer $TOPDIR/layers/$layerDir/$sublayer >/dev/null || $EXIT 1
touch $buildDir/.layers/$layerDir-$sublayer
fi
fi
fi
if [ "$VAR" = "MACHINE" ] ; then
echo "MACHINE ?= '$VAL'" >> conf/local-content.conf
echo >> conf/local-content.conf
fi
if [ "$VAR" = "DISTRO" ] ; then
echo "DISTRO ?= '$VAL'" >> conf/local-content.conf
echo >> conf/local-content.conf
fi
if [ "$VAR" = "SOURCE" ] ; then
META=""
BRANCH="master"
TREE=$(echo $VAL | cut -d \; -f 1)
for option in $(echo $VAL | sed s,\;,\ ,g); do
OVAR=$(echo $option | cut -d = -f 1)
OVAL=$(echo $option | cut -d = -f 2)
if [ "$OVAR" = "meta" ] ; then
META=$OVAL
fi
if [ "$OVAR" = "branch" ] ; then
BRANCH=$OVAL
fi
done
mkdir -p $TOPDIR/sources-export
LSOURCE=$TOPDIR/sources/$(basename $TREE | sed s,.git,,)
LSOURCE_EXPORT=$TOPDIR/sources-export/$(basename $TREE | sed s,.git,,)
if [ ! -e $TOPDIR/.drop -o "$ALLOW_UPDATE" = "1" ] ; then
pushd $LSOURCE 2>/dev/null >/dev/null
git checkout $BRANCH || $EXIT 1
git pull 2>/dev/null >/dev/null
popd 2>/dev/null >/dev/null
if [ ! -e $LSOURCE_EXPORT ] ; then
if [ "$BRANCH" = "master" ] ; then
git clone --bare $LSOURCE $LSOURCE_EXPORT
else
git clone -b $BRANCH --bare $LSOURCE $LSOURCE_EXPORT
fi
else
pushd $LSOURCE_EXPORT 2>/dev/null >/dev/null
git fetch origin $BRANCH:$BRANCH || $EXIT 1
popd 2>/dev/null >/dev/null
fi
fi
DL_TREE="git://$TOPDIR/sources-export/$(basename $TREE | sed s,.git,,)"
echo "$(echo $META)_TREE = '$DL_TREE'" >> conf/local-content.conf
echo "$(echo $META)_BRANCH = '$BRANCH'" >> conf/local-content.conf
echo "BB_HASHBASE_WHITELIST:append += \"$(echo $META)_TREE\"" >> conf/local-content.conf
echo >> conf/local-content.conf
fi
if [ "$VAR" = "CONFIG" ] ; then
option=$(echo $VAL | cut -d = -f 1)
setting=$(echo $VAL | cut -d = -f 2)
if [ -z "$(echo $option | grep append$)" ] ; then
echo "$option ?= '$setting'" >> conf/local-content.conf
else
echo "$option ?= ' $setting '" >> conf/local-content.conf
fi
fi
done
if [ -n "$SOURCE_MIRROR_URL" ] ; then
if [ -z "$(echo $SOURCE_MIRROR_URL | grep "://")" ] ; then
# Assume file
SOURCE_MIRROR_URL="file://$SOURCE_MIRROR_URL"
fi
echo "SOURCE_MIRROR_URL = '$SOURCE_MIRROR_URL'" >> conf/local-content.conf
echo >> conf/local-content.conf
SOURCE_MIRROR_URL=""
fi
if [ -n "$PROTECTED_SOURCE_URL" ] ; then
if [ -z "$(echo $PROTECTED_SOURCE_URL | grep "://")" ] ; then
# Assume file
PROTECTED_SOURCE_URL="file://$PROTECTED_SOURCE_URL"
fi
echo "PROTECTED_SOURCE_URL = '$PROTECTED_SOURCE_URL'" >> conf/local-content.conf
echo >> conf/local-content.conf
PROTECTED_SOURCE_URL=""
fi
if [ -n "$SSTATE_MIRRORS" ] ; then
if [ -z "$(echo $SSTATE_MIRRORS | grep "://")" ] ; then
# Assume file
SSTATE_MIRRORS="file://$SSTATE_MIRRORS"
fi
echo "SSTATE_MIRRORS = 'file://.* $SSTATE_MIRRORS/PATH \n '" >> conf/local-content.conf
echo >> conf/local-content.conf
SSTATE_MIRRORS=""
fi
export -n BB_NO_NETWORK
if [ "$MAKEDROP" != "1" ] ; then
# Temporary waiting for proper bitbake integration: https://patchwork.openembedded.org/patch/144806/
RELPATH=$($PYTHON -c "from os.path import relpath; print (relpath(\"$TOPDIR/layers\",\"$(pwd)\"))")
sed -i conf/bblayers.conf -e "s,$TOPDIR/layers/,\${TOPDIR}/$RELPATH/,"
if [ "$(readlink -f setup.sh)" = "$(readlink -f $TOPDIR/setup.sh)" ] ; then
echo "Something went wrong. Exiting to prevent overwritting setup.sh"
$EXIT 1
fi
SCRIPT_RELPATH=$($PYTHON -c "from os.path import relpath; print (relpath(\"$TOPDIR\",\"`pwd`\"))")
cat > setup.sh << EOF
if [ -n "\$BASH_SOURCE" ]; then
THIS_SCRIPT=\$BASH_SOURCE
elif [ -n "\$ZSH_NAME" ]; then
THIS_SCRIPT=\$0
else
THIS_SCRIPT="\$(pwd)/setup.sh"
fi
PROJECT_DIR=\$(dirname \$(readlink -f \$THIS_SCRIPT))
cd \$PROJECT_DIR
source $SCRIPT_RELPATH/buildtools/environment-setup-*
source $SCRIPT_RELPATH/layers/poky/oe-init-build-env \$PROJECT_DIR
EOF
rm -rf tmp-glibc
else
rm -rf tmp
cd $TOPDIR
rm -rf $TOPDIR/buildtools
touch $TOPDIR/.drop
rm -rf $TOPDIR/$buildDir
fi
if [ "$MAKEDROP" != "1" ] ; then
if [ "$EXIT" = "exit" ] ; then
echo
echo "=Setup Complete="
echo
echo "* Run the following to start building with your project:"
echo "source $buildDir/setup.sh"
echo "bitbake core-image-minimal"
echo
else
echo
echo "=Setup Complete="
echo
echo "* To start building run the following:"
echo "bitbake core-image-minimal"
echo
echo "* To re-setup your build environment for your build later, run:"
echo "source $buildDir/setup.sh"
echo
fi
fi
echo "* To update your content sources run:"
if [ "$(readlink -f $buildDir)" = "$(readlink -f $TOPDIR/project)" ] ; then
echo "source $TOPDIR/setup.sh"
else
echo "source $TOPDIR/setup.sh $buildDir"
fi
echo