release: set correct branch for release bronze
[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="bronze"
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 IMAGE_TYPE="iso"
101
102 while getopts "w:b:e:r:nh" OPTION; do
103     case ${OPTION} in
104         w)
105             WORKSPACE=`readlink -f ${OPTARG}`
106             ;;
107         b)
108             check_valid_bsp ${OPTARG}
109             ;;
110         e)
111             EXTRA_CONF=`readlink -f ${OPTARG}`
112             ;;
113         n)
114             DRYRUN="-n"
115             ;;
116         r)
117             check_yn_rm_work ${OPTARG}
118             ;;
119         h)
120             help_info
121             exit
122             ;;
123     esac
124 done
125
126 if [ -z "${WORKSPACE}" ]; then
127     echo_info "No workspace specified, a directory 'workspace' will be created in current directory as the workspace"
128     WORKSPACE=`readlink -f workspace`
129 fi
130
131 if [ -n "${BSP_VALID}" ]; then
132     BSP="${BSP_VALID}"
133 fi
134
135 # iso image is not supported by nxp-lx2xxx yet
136 if [ "${BSP}" == "nxp-lx2xxx" ]; then
137     IMAGE_TYPE="tar.bz2"
138 fi
139
140 SRC_WRL_DIR=${WORKSPACE}/src_wrlinux
141 SRC_ORAN_DIR=${WORKSPACE}/src_oran
142 PRJ_BUILD_DIR=${WORKSPACE}/prj_oran-inf
143
144 mkdir -p ${SRC_WRL_DIR} ${PRJ_BUILD_DIR} ${SRC_ORAN_DIR}
145
146 echo_info "The following directories are created in your workspace(${WORKSPACE}):"
147 echo_info "For wrlinux source: ${SRC_WRL_DIR}"
148 echo_info "For oran layer source: ${SRC_ORAN_DIR}"
149 echo_info "For build project: ${PRJ_BUILD_DIR}"
150
151 # Clone the source of WRLinux from github and setup
152 RUN_CMD="git clone --branch ${SRC_WRL_BRANCH} ${SRC_WRL_URL}"
153 echo_cmd "Cloning wrlinux-x source from github:"
154 cd ${SRC_WRL_DIR}
155 ${RUN_CMD}
156
157 RUN_CMD="./wrlinux-x/setup.sh --machines ${BSP} --layers meta-cloud-services"
158 echo_cmd "Setup wrlinux build project:"
159 ${RUN_CMD}
160
161 # Clone the oran layer if it's not already cloned
162 # Check if the script is inside the repo
163 if cd ${SCRIPTS_DIR} && git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
164     CLONED_ORAN_REPO=`dirname ${SCRIPTS_DIR}`
165     echo_info "Use the cloned oran repo: ${CLONED_ORAN_REPO}"
166     mkdir ${SRC_ORAN_DIR}/rtp
167     cd ${SRC_ORAN_DIR}/rtp
168     ln -sf ${CLONED_ORAN_REPO}/meta-oran meta-oran
169     ln -sf ${CLONED_ORAN_REPO}/scripts scripts
170 else
171     echo_info "Cloning oran layer:"
172     cd ${SRC_ORAN_DIR}
173     RUN_CMD="git clone --branch ${SRC_ORAN_BRANCH} https://gerrit.o-ran-sc.org/r/pti/rtp"
174     echo_cmd "Cloing with:"
175     ${RUN_CMD}
176 fi
177
178 # Apply meta patches for nxp-lx2xxx
179 if [ "${BSP}" == "nxp-lx2xxx" ]; then
180     cd ${SRC_WRL_DIR}/layers/nxp-lx2xxx/
181     git am ${SRC_ORAN_DIR}/rtp/scripts/meta-patches/nxp-lx2xxx/0001-Revert-nxp-lx2xxx-remove-preempt-rt-related-file.patch
182 fi
183
184 # Source the build env
185 cd ${SRC_WRL_DIR}
186 . ./environment-setup-x86_64-wrlinuxsdk-linux
187 set ${PRJ_BUILD_DIR}
188 . ./oe-init-build-env ${PRJ_BUILD_DIR}
189
190 # Add the meta-oran layer
191 cd ${PRJ_BUILD_DIR}
192 RUN_CMD="bitbake-layers add-layer ${SRC_ORAN_DIR}/rtp/meta-oran"
193 echo_cmd "Add the meta-oran layer into the build project"
194 ${RUN_CMD}
195
196 # Add extra configs into local.conf
197 cat << EOF >> conf/local.conf
198 ########################
199 # Configs for oran-inf #
200 ########################
201 DISTRO = "oran-inf"
202 BB_NO_NETWORK = '0'
203
204 # Work around for CI build
205 IMAGE_INSTALL_remove = "ceph"
206
207 # For container image
208 WR_APP_CONTAINER_APP = "rt-tests"
209
210 # Disable multilib fo nxp-lx2xxx
211 MULTILIBS_nxp-lx2xxx = ""
212 DEFAULTTUNE_virtclass-multilib-lib32_nxp-lx2xxx = ""
213
214 # Add templates
215 WRTEMPLATE += "${WRTEMPLATE_COMMON}"
216 WRTEMPLATE_prepend_x86-64 += "${WRTEMPLATE_X86}"
217 EOF
218
219 if [ "${RM_WORK}" == "Yes" ]; then
220     echo "INHERIT += 'rm_work'" >> conf/local.conf
221 fi
222
223 if [ "${EXTRA_CONF}" != "" ] && [ -f "${EXTRA_CONF}" ]; then
224     cat ${EXTRA_CONF} >> conf/local.conf
225 fi
226
227 # Build the oran-inf-host image
228 mkdir -p logs
229 TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
230 RUN_CMD="bitbake ${DRYRUN} oran-image-inf-host"
231 echo_cmd "Build the oran-image-inf-host image"
232 bitbake ${DRYRUN} oran-image-inf-host 2>&1|tee logs/bitbake_oran-image-inf-host_${TIMESTAMP}.log
233
234 RUN_CMD="bitbake ${DRYRUN} wr-app-container"
235 echo_cmd "Build the wr-app-container image"
236 bitbake ${DRYRUN} wr-app-container 2>&1|tee logs/bitbake_wr-app-container_${TIMESTAMP}.log
237
238 echo_info "Build succeeded, you can get the image in ${PRJ_BUILD_DIR}/tmp-glibc/deploy/images/${BSP}/oran-image-inf-host-${BSP}.${IMAGE_TYPE}"