forked from MentorEmbedded/meta-mentor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-environment
105 lines (96 loc) · 3.76 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
if [ -z "$ZSH_NAME" ] && [ "x$0" = "x./setup-environment" ]; then
echo >&2 "Error: This script needs to be sourced. Please run as '. ./setup-environment'"
else
if [ -n "$BASH_SOURCE" ]; then
layerdir="`dirname $BASH_SOURCE`"
elif [ -n "$ZSH_NAME" ]; then
layerdir="`dirname $0`"
else
layerdir="`pwd`"
fi
layerdir=`readlink -f "$layerdir"`
if [ -f conf/local.conf -o -f conf/bblayers.conf ]; then
# Assuming we're already in the build dir
BUILDDIR=$PWD
else
BUILDDIR=$PWD/build
fi
for i in $(seq $#); do
arg="$(eval printf "%s" "\$$i")"
case "$arg" in
-b)
BUILDDIR="$(eval printf "%s" "\$$(expr $i + 1)")"
if [ -z "$BUILDDIR" ]; then
echo >&2 "-b requires an argument"
fi
;;
esac
done
OPTIONALLAYERS="${OPTIONALLAYERS:-mentor-private tracing-layer}"
EXCLUDEDLAYERS="$EXCLUDEDLAYERS"
# Customer directory layers handling (e.g. <customername>-custom)
if [ -e "$layerdir/../customer.conf" ] ; then
for CUSTOMER in $(cat $layerdir/../customer.conf) ; do
if [ -d "$CUSTOMER-custom" ] ; then
if [ -e "$CUSTOMER-custom/custom.conf" ] ; then
CUSTOMERLAYERS=`cat $CUSTOMER-custom/custom.conf | sed -e '/^[ ]*#/d'`
CUSTOMERLAYERS=`echo $CUSTOMERLAYERS | sed -e 's/\n//g'`
OPTIONALLAYERS="$OPTIONALLAYERS $CUSTOMERLAYERS"
unset CUSTOMERLAYERS
fi
fi
done
unset CUSTOMER
fi
# Hotfix layers handling
if [ -e "$layerdir/../hotfixes/hotfix.conf" ] ; then
HOTFIXES=`cat $layerdir/../hotfixes/hotfix.conf | sed -e '/^[ ]*#/d'`
HOTFIXES=`echo $HOTFIXES | sed -e 's/\n//g'`
OPTIONALLAYERS="$OPTIONALLAYERS $HOTFIXES"
unset HOTFIXES
fi
# Extra layers handling
if [ -e "$layerdir/../xlayers.conf" ] ; then
EXTRALAYERS=`cat $layerdir/../xlayers.conf | sed -e '/^[ ]*#/d'`
EXTRALAYERS=`echo $EXTRALAYERS | sed -e 's/\n//g'`
OPTIONALLAYERS="$OPTIONALLAYERS $EXTRALAYERS"
unset EXTRALAYERS
fi
OPTIONALLAYERS="$OPTIONALLAYERS" EXTRAMELLAYERS="$EXTRAMELLAYERS" EXCLUDEDLAYERS="$EXCLUDEDLAYERS" $layerdir/scripts/setup-mel-builddir "$@"
if [ $? -eq 0 ] && [ -n "$BUILDDIR" ] && [ -e "$BUILDDIR" ]; then
. $BUILDDIR/setup-environment >/dev/null 2>&1
configured_layers () {
tac $BUILDDIR/conf/bblayers.conf | \
sed -n -e '/^"/,/^BBLAYERS = /{ /^BBLAYERS =/d; /^"/d; p;}' | \
awk {'print $1'}
}
load_lconf_snippet () {
if [ ! -e "$1/$2" ]; then
return
fi
(
lheadername="${1##*/}/$2"
printf '\n## Begin %s\n\n' "$lheadername"
cat "$1/$2"
printf '\n## End %s\n' "$lheadername"
) >>conf/local.conf
}
sed -i -n -e ":out; /^## Begin /{ :loop; /^## End /{ d; b out; }; n; b loop; }; p;" conf/local.conf
SETUP_ENV_MACHINE="$(sed -n -e 's/^MACHINE *?*= *"\(.*\)"/\1/p' "$BUILDDIR/conf/local.conf")"
configured_layers | while read layer; do
if [ -e $layer/post-setup-environment ]; then
. $layer/post-setup-environment
fi
load_lconf_snippet "$layer" "conf/local.conf.append"
load_lconf_snippet "$layer" "conf/local.conf.append.$SETUP_ENV_MACHINE"
done
. $BUILDDIR/setup-environment
unset SETUP_ENV_MACHINE
unset load_lconf_snippet
unset configured_layers
fi
unset EXTRAMELLAYERS
unset OPTIONALLAYERS
unset EXCLUDEDLAYERS
unset layerdir
fi