python-eventlet: downversion to 0.18.4 to align with stx
[pti/rtp.git] / scripts / build_oran.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2019 Wind River Systems, Inc.
4 #
5 #  Licensed under the Apache License, Version 2.0 (the "License");
6 #  you may not use this file except in compliance with the License.
7 #  You may obtain a copy of the License at
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #  Unless required by applicable law or agreed to in writing, software
12 #  distributed under the License is distributed on an "AS IS" BASIS,
13 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #  See the License for the specific language governing permissions and
15 #  limitations under the License.
16
17 # Ensure we fail the job if any steps fail.
18 set -e -o pipefail
19
20 SUPPORTED_BSP="intel-x86-64 nxp-lx2xxx"
21 WRTEMPLATE_COMMON="feature/oran-host-rt-tune feature/kubernetes feature/self-hosted"
22 WRTEMPLATE_X86="feature/hosts-ia feature/kvm feature/dpdk"
23
24 SRC_ORAN_BRANCH="master"
25 SRC_WRL_BRANCH="WRLINUX_10_18_BASE"
26 SRC_WRL_URL="git://github.com/WindRiver-Labs/wrlinux-x.git"
27
28 SCRIPTS_DIR=$(dirname $(readlink -f $0))
29
30 help_info () {
31 cat << ENDHELP
32 Usage:
33 $(basename $0) <-w WORKSPACE_DIR> [-b BSP] [-n] [-h] [-r]
34 where:
35     -w WORKSPACE_DIR is the path for the project
36     -b BPS is one of supported BSP: "${SUPPORTED_BSP}"
37        (default is intel-x86-64 if not specified.)
38     -n dry-run only for bitbake
39     -h this help info
40     -e EXTRA_CONF is the pat for extra config file
41     -r whether to inherit rm_work (default is Yes)
42 ENDHELP
43 }
44
45 echo_info () {
46     echo "INFO: $1"
47 }
48
49 echo_error () {
50     echo "ERROR: $1"
51 }
52
53 echo_cmd () {
54     echo
55     echo_info "$1"
56     echo "CMD: ${RUN_CMD}"
57 }
58
59 if [ $# -eq 0 ]; then
60     echo "Missing options!"
61     help_info
62     exit
63 fi
64
65 check_yn_rm_work () {
66     yn="$1"
67     case ${yn} in
68         [Yy]|[Yy]es)
69             RM_WORK="Yes"
70             ;;
71         [Nn]|[Nn]o)
72             RM_WORK="No"
73             ;;
74         *)
75             echo "Invalid arg for -r option."
76             help_info
77             exit 1
78             ;;
79     esac
80 }
81
82 check_valid_bsp () {
83     bsp="$1"
84     for b in ${SUPPORTED_BSP}; do
85         if [ "${bsp}" == "${b}" ]; then
86             BSP_VALID="${bsp}"
87             break
88         fi
89     done
90     if [ -z "${BSP_VALID}" ]; then
91         echo_error "${bsp} is not a supported BSP, the supported BSPs are: ${SUPPORTED_BSP}"
92         exit 1
93     fi
94 }
95
96 DRYRUN=""
97 EXTRA_CONF=""
98 RM_WORK="Yes"
99 BSP="intel-x86-64"
100
101 while getopts "w:b:e:r:nh" OPTION; do
102     case ${OPTION} in
103         w)
104             WORKSPACE=`readlink -f ${OPTARG}`
105             ;;
106         b)
107             check_valid_bsp ${OPTARG}
108             ;;
109         e)
110             EXTRA_CONF=`readlink -f ${OPTARG}`
111             ;;
112         n)
113             DRYRUN="-n"
114             ;;
115         r)
116             check_yn_rm_work ${OPTARG}
117             ;;
118         h)
119             help_info
120             exit
121             ;;
122     esac
123 done
124
125 if [ -z "${WORKSPACE}" ]; then
126     echo_info "No workspace specified, a directory 'workspace' will be created in current directory as the workspace"
127     WORKSPACE=`readlink -f workspace`
128 fi
129
130 if [ -n "${BSP_VALID}" ]; then
131     BSP="${BSP_VALID}"
132 fi
133
134 SRC_WRL_DIR=${WORKSPACE}/src_wrlinux
135 SRC_ORAN_DIR=${WORKSPACE}/src_oran
136 PRJ_BUILD_DIR=${WORKSPACE}/prj_oran-inf
137
138 mkdir -p ${SRC_WRL_DIR} ${PRJ_BUILD_DIR} ${SRC_ORAN_DIR}
139
140 echo_info "The following directories are created in your workspace(${WORKSPACE}):"
141 echo_info "For wrlinux source: ${SRC_WRL_DIR}"
142 echo_info "For oran layer source: ${SRC_ORAN_DIR}"
143 echo_info "For build project: ${PRJ_BUILD_DIR}"
144
145 # Clone the source of WRLinux from github and setup
146 RUN_CMD="git clone --branch ${SRC_WRL_BRANCH} ${SRC_WRL_URL}"
147 echo_cmd "Cloning wrlinux-x source from github:"
148 cd ${SRC_WRL_DIR}
149 ${RUN_CMD}
150
151 RUN_CMD="./wrlinux-x/setup.sh --machines ${BSP} --layers meta-cloud-services"
152 echo_cmd "Setup wrlinux build project:"
153 ${RUN_CMD}
154
155 # Clone the oran layer if it's not already cloned
156 # Check if the script is inside the repo
157 if cd ${SCRIPTS_DIR} && git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
158     CLONED_ORAN_REPO=`dirname ${SCRIPTS_DIR}`
159     echo_info "Use the cloned oran repo: ${CLONED_ORAN_REPO}"
160     mkdir ${SRC_ORAN_DIR}/rtp
161     cd ${SRC_ORAN_DIR}/rtp
162     ln -sf ${CLONED_ORAN_REPO}/meta-oran meta-oran
163     ln -sf ${CLONED_ORAN_REPO}/scripts scripts
164 else
165     echo_info "Cloning oran layer:"
166     cd ${SRC_ORAN_DIR}
167     RUN_CMD="git clone --branch ${SRC_ORAN_BRANCH} https://gerrit.o-ran-sc.org/r/pti/rtp"
168     echo_cmd "Cloing with:"
169     ${RUN_CMD}
170 fi
171
172 # Apply meta patches for nxp-lx2xxx
173 if [ "${BSP}" == "nxp-lx2xxx" ]; then
174     cd ${SRC_WRL_DIR}/layers/nxp-lx2xxx/
175     git am ${SRC_ORAN_DIR}/rtp/scripts/meta-patches/nxp-lx2xxx/0001-Revert-nxp-lx2xxx-remove-preempt-rt-related-file.patch
176 fi
177
178 # Source the build env
179 cd ${SRC_WRL_DIR}
180 . ./environment-setup-x86_64-wrlinuxsdk-linux
181 set ${PRJ_BUILD_DIR}
182 . ./oe-init-build-env ${PRJ_BUILD_DIR}
183
184 # Add the meta-oran layer
185 cd ${PRJ_BUILD_DIR}
186 RUN_CMD="bitbake-layers add-layer ${SRC_ORAN_DIR}/rtp/meta-oran"
187 echo_cmd "Add the meta-oran layer into the build project"
188 ${RUN_CMD}
189
190 # Add extra configs into local.conf
191 cat << EOF >> conf/local.conf
192 ########################
193 # Configs for oran-inf #
194 ########################
195 DISTRO = "oran-inf"
196 BB_NO_NETWORK = '0'
197
198 # Work around for CI build
199 IMAGE_INSTALL_remove = "ceph"
200
201 # For container image
202 WR_APP_CONTAINER_APP = "rt-tests"
203
204 # Disable multilib fo nxp-lx2xxx
205 MULTILIBS_nxp-lx2xxx = ""
206 DEFAULTTUNE_virtclass-multilib-lib32_nxp-lx2xxx = ""
207
208 # Add templates
209 WRTEMPLATE += "${WRTEMPLATE_COMMON}"
210 WRTEMPLATE_prepend_x86-64 += "${WRTEMPLATE_X86}"
211 EOF
212
213 if [ "${RM_WORK}" == "Yes" ]; then
214     echo "INHERIT += 'rm_work'" >> conf/local.conf
215 fi
216
217 if [ "${EXTRA_CONF}" != "" ] && [ -f "${EXTRA_CONF}" ]; then
218     cat ${EXTRA_CONF} >> conf/local.conf
219 fi
220
221 # Build the oran-inf-host image
222 mkdir -p logs
223 TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
224 RUN_CMD="bitbake ${DRYRUN} oran-image-inf-host"
225 echo_cmd "Build the oran-image-inf-host image"
226 bitbake ${DRYRUN} oran-image-inf-host 2>&1|tee logs/bitbake_oran-image-inf-host_${TIMESTAMP}.log
227
228 RUN_CMD="bitbake ${DRYRUN} wr-app-container"
229 echo_cmd "Build the wr-app-container image"
230 bitbake ${DRYRUN} wr-app-container 2>&1|tee logs/bitbake_wr-app-container_${TIMESTAMP}.log
231
232 echo_info "Build succeeded, you can get the image in ${PRJ_BUILD_DIR}/tmp-glibc/deploy/images/intel-x86-64/oran-image-inf-host-intel-x86-64.iso"