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