12dce7bc9dc521ec455d1ff3bd2f4933c69fc01c
[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 help_info () {
21 cat << ENDHELP
22 Usage:
23 $(basename $0) <-w WORKSPACE_DIR> [-n] [-h]
24 where:
25     -w WORKSPACE_DIR is the path for the project
26     -n dry-run only for bitbake
27     -h this help info
28     -e EXTRA_CONF is the pat for extra config file
29     -r whether to inherit rm_work (default is Yes)
30 ENDHELP
31 }
32
33 echo_info () {
34     echo "INFO: $1"
35 }
36
37 echo_error () {
38     echo "ERROR: $1"
39 }
40
41 echo_cmd () {
42     echo
43     echo_info "$1"
44     echo "CMD: ${RUN_CMD}"
45 }
46
47 if [ $# -eq 0 ]; then
48     echo "Missing options!"
49     help_info
50     exit
51 fi
52
53 check_yn_rm_work () {
54     yn="$1"
55     case ${yn} in
56         [Yy]|[Yy]es)
57             RM_WORK="Yes"
58             ;;
59         [Nn]|[Nn]o)
60             RM_WORK="No"
61             ;;
62         *)
63             echo "Invalid arg for -r option."
64             help_info
65             exit 1
66             ;;
67     esac
68 }
69
70 DRYRUN=""
71 EXTRA_CONF=""
72 RM_WORK="Yes"
73
74 SCRIPTS_DIR=`dirname $0`
75 SCRIPTS_DIR=`readlink -f $SCRIPTS_DIR`
76
77 while getopts "w:e:r:nh" OPTION; do
78     case ${OPTION} in
79         w)
80             WORKSPACE=`readlink -f ${OPTARG}`
81             ;;
82         e)
83             EXTRA_CONF=`readlink -f ${OPTARG}`
84             ;;
85         n)
86             DRYRUN="-n"
87             ;;
88         r)
89             check_yn_rm_work ${OPTARG}
90             ;;
91         h)
92             help_info
93             exit
94             ;;
95     esac
96 done
97
98 if [ -z ${WORKSPACE} ]; then
99     echo_info "No workspace specified, a directory 'workspace' will be created in current directory as the workspace"
100     WORKSPACE=`readlink -f workspace`
101 fi
102
103 SRC_WRL_DIR=${WORKSPACE}/src_wrl1018
104 SRC_ORAN_DIR=${WORKSPACE}/src_oran
105 PRJ_BUILD_DIR=${WORKSPACE}/prj_oran-inf
106
107 mkdir -p ${SRC_WRL_DIR} ${PRJ_BUILD_DIR} ${SRC_ORAN_DIR}
108
109 echo_info "The following directories are created in your workspace(${WORKSPACE}):"
110 echo_info "For wrlinux1018 source: ${SRC_WRL_DIR}"
111 echo_info "For oran layer source: ${SRC_ORAN_DIR}"
112 echo_info "For build project: ${PRJ_BUILD_DIR}"
113
114 # Clone the source of WRLinux BASE 10.18 from github and setup
115 RUN_CMD="git clone --branch WRLINUX_10_18_BASE git://github.com/WindRiver-Labs/wrlinux-x.git"
116 echo_cmd "Cloning wrlinux 1018 source from github:"
117 cd ${SRC_WRL_DIR}
118 ${RUN_CMD}
119
120 RUN_CMD="./wrlinux-x/setup.sh --machines intel-x86-64 --layers meta-cloud-services"
121 echo_cmd "Setup wrlinux build project:"
122 ${RUN_CMD}
123
124 # Clone the oran layer if it's not already cloned
125 # Check if the script is inside the repo
126 if cd ${SCRIPTS_DIR} && git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
127     CLONED_ORAN_REPO=`dirname ${SCRIPTS_DIR}`
128     echo_info "Use the cloned oran repo: ${CLONED_ORAN_REPO}"
129     mkdir ${SRC_ORAN_DIR}/rtp
130     cd ${SRC_ORAN_DIR}/rtp
131     ln -sf ${CLONED_ORAN_REPO}/meta-oran meta-oran
132     ln -sf ${CLONED_ORAN_REPO}/scripts scripts
133 else
134     echo_info "Cloning oran layer:"
135     cd ${SRC_ORAN_DIR}
136     RUN_CMD="git clone https://gerrit.o-ran-sc.org/r/pti/rtp"
137     echo_cmd "Cloing with:"
138     ${RUN_CMD}
139 fi
140
141 # Source the build env
142 cd ${SRC_WRL_DIR}
143 . ./environment-setup-x86_64-wrlinuxsdk-linux
144 set ${PRJ_BUILD_DIR}
145 . ./oe-init-build-env ${PRJ_BUILD_DIR}
146
147 # Add the meta-oran layer
148 cd ${PRJ_BUILD_DIR}
149 RUN_CMD="bitbake-layers add-layer ${SRC_ORAN_DIR}/rtp/meta-oran"
150 echo_cmd "Add the meta-oran layer into the build project"
151 ${RUN_CMD}
152
153 # Add extra configs into local.conf
154 cat << EOF >> conf/local.conf
155 ########################
156 # Configs for oran-inf #
157 ########################
158 DISTRO = "oran-inf"
159 BB_NO_NETWORK = '0'
160 WRTEMPLATE += "feature/oran-host-rt-tune"
161
162 # Work around for CI build
163 IMAGE_INSTALL_remove = "ceph"
164 EOF
165
166 if [ "${RM_WORK}" == "Yes" ]; then
167     echo "INHERIT += 'rm_work'" >> conf/local.conf
168 fi
169
170 if [ "${EXTRA_CONF}" != "" ] && [ -f "${EXTRA_CONF}" ]; then
171     cat ${EXTRA_CONF} >> conf/local.conf
172 fi
173
174 # Build the oran-inf-host image
175 mkdir -p logs
176 TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
177 RUN_CMD="bitbake ${DRYRUN} oran-image-inf-host"
178 echo_cmd "Build the oran-image-inf-host image"
179 bitbake ${DRYRUN} oran-image-inf-host 2>&1|tee logs/bitbake_oran-image-inf-host_${TIMESTAMP}.log
180
181 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"