forked from MentorEmbedded/meta-sokol-flex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-environment
151 lines (133 loc) · 5.61 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
# ---------------------------------------------------------------------------------------------------------------------
# SPDX-License-Identifier: MIT
# ---------------------------------------------------------------------------------------------------------------------
flex_sourced=0
if [ -n "$ZSH_EVAL_CONTEXT" ]; then
case $ZSH_EVAL_CONTEXT in *:file) flex_sourced=1;; esac
elif [ -n "$BASH_VERSION" ]; then
(return 0 2>/dev/null) && flex_sourced=1
else
echo >&2 "Error: This shell is unsupported. Please use bash or zsh"
flex_sourced=2
fi
if [ "$flex_sourced" -eq 0 ]; then
echo >&2 "Error: This script needs to be sourced. Please run as '. \"$0\"'"
false
elif [ "$flex_sourced" -eq 2 ]; then
false
else
# shellcheck disable=SC2128
if [ -n "$BASH_SOURCE" ]; then
layerdir="$(cd "$(dirname "$BASH_SOURCE")" && pwd -P)"
elif [ -n "$ZSH_NAME" ]; then
layerdir="$(cd "$(dirname "$0")" && pwd -P)"
else
layerdir="$(pwd -P)"
fi
export PYENV_ROOT="${PYENV_ROOT:-~/.pyenv}"
PATH="$PYENV_ROOT/shims:$PATH"
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
setup_flex_arg="$(eval printf "%s" "\${$i}")"
case "$setup_flex_arg" in
-b)
BUILDDIR="$(eval printf "%s" "\${$((i + 1))}")"
if [ -z "$BUILDDIR" ]; then
echo >&2 "-b requires an argument"
fi
BUILDDIR="$(readlink -f "$BUILDDIR")"
;;
esac
done
(
for layercheck in $layerdir . $layerdir/..; do
if [ -e "$layercheck/setup-environment.conf" ]; then
. "$layercheck/setup-environment.conf"
fi
if [ -e "$layercheck/.setup-environment.conf" ]; then
. "$layercheck/.setup-environment.conf"
fi
done
OPTIONALLAYERS="${OPTIONALLAYERS-flex-private}"
# Customer directory layers handling (e.g. <customername>-custom)
for layercheck in . $layerdir/..; do
if [ -e "$layercheck/customer.conf" ]; then
while read -r _customer; do
for layercheck2 in . $layerdir/..; do
if [ -d "$layercheck2/$_customer-custom" ]; then
if [ -e "$layercheck2/$_customer-custom/custom.conf" ]; then
CUSTOMERLAYERS=$(cat $layercheck2/$_customer-custom/custom.conf | sed -e '/^[ ]*#/d')
CUSTOMERLAYERS=$(echo $CUSTOMERLAYERS | sed -e 's/\n//g')
OPTIONALLAYERS="$OPTIONALLAYERS $CUSTOMERLAYERS"
fi
break
fi
done
done <"$layercheck/customer.conf"
break
fi
done
# 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"
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"
fi
export OPTIONALLAYERS EXTRAFLEXLAYERS EXCLUDEDLAYERS
$layerdir/scripts/setup-flex-builddir "$@"
)
flex_setup_ret=$?
if [ $flex_setup_ret -eq 0 ] && [ -n "$BUILDDIR" ] && [ -e "$BUILDDIR" ]; then
. $BUILDDIR/setup-environment
configured_layers() {
tac $BUILDDIR/conf/bblayers.conf \
| sed -n -e '/^"/,/^BBLAYERS = /{ /^BBLAYERS =/d; /^"/d; p;}' \
| awk {'print $1'} | sed -e "s#\${TOPDIR}/#$BUILDDIR/#"
}
load_lconf_snippet() {
if [ ! -e "$1/$2" ]; then
return
fi
(
lheadername="${1#${layerdir%/*}/}/$2"
printf '\n## Begin %s\n\n' "$lheadername"
cat "$1/$2"
printf '\n## End %s\n' "$lheadername"
) >>conf/local.conf
}
if [ -e "$BUILDDIR/conf/local.conf" ] && [ -e "$BUILDDIR/conf/bblayers.conf" ]; then
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")"
if [ -e "$layerdir/post-setup-environment" ]; then
layer="$layerdir"
. "$layerdir/post-setup-environment"
fi
load_lconf_snippet "$layerdir" "conf/local.conf.append"
load_lconf_snippet "$layerdir" "conf/local.conf.append.$SETUP_ENV_MACHINE"
configured_layers | grep -Fvx "$layerdir" | 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 >/dev/null 2>&1
fi
unset SETUP_ENV_MACHINE
unset load_lconf_snippet
unset configured_layers
fi
unset layerdir setup_flex_arg
test $flex_setup_ret -eq 0
fi