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