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