blob: b0d3fd6c82cab7b1b34f7382b9af5b91bc3b8c42 [file] [log] [blame]
#!/bin/bash
#
# Copyright (C) 2019 Wind River Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Ensure we fail the job if any steps fail.
set -e -o pipefail
#########################################################################
# Variables
#########################################################################
# Only one bsp is supported now, there will be more in the future
SUPPORTED_BSP="intel-corei7-64 "
SRC_ORAN_BRANCH="master"
SRC_STX_BRANCH="master"
SRC_YP_BRANCH="warrior"
SRC_ORAN_URL="https://gerrit.o-ran-sc.org/r/pti/rtp"
SRC_YP_URL="\
git://git.yoctoproject.org/poky \
git://git.openembedded.org/meta-openembedded \
git://git.yoctoproject.org/meta-virtualization \
git://git.yoctoproject.org/meta-cloud-services \
git://git.yoctoproject.org/meta-security \
git://git.yoctoproject.org/meta-intel \
git://git.yoctoproject.org/meta-security \
git://git.yoctoproject.org/meta-selinux \
https://github.com/intel-iot-devkit/meta-iot-cloud \
git://git.openembedded.org/meta-python2 \
https://git.yoctoproject.org/git/meta-dpdk \
git://git.yoctoproject.org/meta-anaconda \
"
SUB_LAYER_META_OE="\
meta-oe \
meta-perl \
meta-python \
meta-networking \
meta-filesystems \
meta-webserver \
meta-initramfs \
meta-initramfs \
meta-gnome \
"
SUB_LAYER_META_CLOUD_SERVICES="meta-openstack"
SUB_LAYER_META_SECURITY="meta-security-compliance"
# For anaconda build
SUB_LAYER_META_OE_ANACONDA="\
meta-oe \
meta-python \
meta-filesystems \
meta-initramfs \
meta-networking \
meta-gnome \
"
SCRIPTS_DIR=$(dirname $(readlink -f $0))
TIMESTAMP=`date +"%Y%m%d_%H%M%S"`
#########################################################################
# Common Functions
#########################################################################
help_info () {
cat << ENDHELP
Usage:
$(basename $0) [-w WORKSPACE_DIR] [-b BSP] [-n] [-h] [-r Yes|No] [-s] [-e EXTRA_CONF]
where:
-w WORKSPACE_DIR is the path for the project
-b BPS is one of supported BSP: "${SUPPORTED_BSP}"
(default is intel-corei7-64 if not specified.)
-n dry-run only for bitbake
-h this help info
-e EXTRA_CONF is the pat for extra config file
-r whether to inherit rm_work (default is Yes)
-s whether to skip update the repo if already exists
examples:
./build_stx.sh
./build_stx.sh -w workspace_1234 -r no -e /path/to/extra_local.conf
ENDHELP
}
echo_step_start() {
[ -n "$1" ] && msg_step=$1
echo "#########################################################################################"
echo "## STEP START: ${msg_step}"
echo "#########################################################################################"
}
echo_step_end() {
[ -n "$1" ] && msg_step=$1
echo "#########################################################################################"
echo "## STEP END: ${msg_step}"
echo "#########################################################################################"
echo
}
echo_info () {
echo "INFO: $1"
}
echo_error () {
echo "ERROR: $1"
}
echo_cmd () {
echo
echo_info "$1"
echo "CMD: ${RUN_CMD}"
}
check_yn_rm_work () {
yn="$1"
case ${yn} in
[Yy]|[Yy]es)
RM_WORK="Yes"
;;
[Nn]|[Nn]o)
RM_WORK="No"
;;
*)
echo "Invalid arg for -r option."
help_info
exit 1
;;
esac
}
check_valid_bsp () {
bsp="$1"
for b in ${SUPPORTED_BSP}; do
if [ "${bsp}" == "${b}" ]; then
BSP_VALID="${bsp}"
break
fi
done
if [ -z "${BSP_VALID}" ]; then
echo_error "${bsp} is not a supported BSP, the supported BSPs are: ${SUPPORTED_BSP}"
exit 1
fi
}
clone_update_repo () {
REPO_BRANCH=$1
REPO_URL=$2
REPO_NAME=$3
if [ -d ${REPO_NAME}/.git ]; then
if [ "${SKIP_UPDATE}" == "Yes" ]; then
echo_info "The repo ${REPO_NAME} exists, skip updating for the branch ${REPO_BRANCH}"
else
echo_info "The repo ${REPO_NAME} exists, updating for the branch ${REPO_BRANCH}"
cd ${REPO_NAME}
git checkout ${REPO_BRANCH}
git pull
cd -
fi
else
RUN_CMD="git clone --branch ${REPO_BRANCH} ${REPO_URL} ${REPO_NAME}"
echo_cmd "Cloning the source of repo '${REPO_NAME}':"
${RUN_CMD}
fi
}
source_env () {
build_dir=$1
cd ${SRC_LAYER_DIR}/poky
set ${build_dir}
source ./oe-init-build-env ${build_dir}
}
#########################################################################
# Parse cmd options
#########################################################################
DRYRUN=""
EXTRA_CONF=""
SKIP_UPDATE="No"
RM_WORK="Yes"
BSP="intel-corei7-64"
while getopts "w:b:e:r:nsh" OPTION; do
case ${OPTION} in
w)
WORKSPACE=`readlink -f ${OPTARG}`
;;
b)
check_valid_bsp ${OPTARG}
;;
e)
EXTRA_CONF=`readlink -f ${OPTARG}`
;;
n)
DRYRUN="-n"
;;
s)
SKIP_UPDATE="Yes"
;;
r)
check_yn_rm_work ${OPTARG}
;;
h)
help_info
exit
;;
esac
done
if [ -z ${WORKSPACE} ]; then
echo_info "No workspace specified, a directory 'workspace' will be created in current directory as the workspace"
WORKSPACE=`readlink -f workspace`
fi
if [ -n "${BSP_VALID}" ]; then
BSP="${BSP_VALID}"
fi
#########################################################################
# Functions for each step
#########################################################################
SRC_LAYER_DIR=${WORKSPACE}/src_layers
SRC_ORAN_DIR=${SRC_LAYER_DIR}/oran
PRJ_BUILD_DIR=${WORKSPACE}/prj_oran_stx
PRJ_BUILD_DIR_ANACONDA=${WORKSPACE}/prj_oran_stx_anaconda
PRJ_SHARED_DIR=${WORKSPACE}/prj_shared
PRJ_SHARED_DL_DIR=${WORKSPACE}/prj_shared/downloads
PRJ_SHARED_SS_DIR=${WORKSPACE}/prj_shared/sstate-cache
SRC_META_PATCHES=${SRC_ORAN_DIR}/rtp/scripts/meta-patches/src_stx
SRC_CONFIGS=${SRC_ORAN_DIR}/rtp/scripts/configs
IMG_STX=stx-image-aio
IMG_ANACONDA=stx-image-aio-installer
ISO_STX=${PRJ_BUILD_DIR}/tmp/deploy/images/${BSP}/${IMG_STX}-${BSP}.iso
ISO_ANACONDA=${PRJ_BUILD_DIR_ANACONDA}/tmp-glibc/deploy/images/${BSP}/${IMG_ANACONDA}-${BSP}.iso
prepare_workspace () {
msg_step="Create workspace for the build"
echo_step_start
mkdir -p ${PRJ_BUILD_DIR} ${SRC_ORAN_DIR} ${PRJ_BUILD_DIR_ANACONDA} ${PRJ_SHARED_DL_DIR} ${PRJ_SHARED_SS_DIR}
echo_info "The following directories are created in your workspace(${WORKSPACE}):"
echo_info "For all layers source: ${SRC_LAYER_DIR}"
echo_info "For StarlingX build project: ${PRJ_BUILD_DIR}"
echo_info "For anaconda (installer) build project: ${PRJ_BUILD_DIR_ANACONDA}"
echo_step_end
}
prepare_src () {
msg_step="Get the source code repos"
echo_step_start
# Clone the oran layer if it's not already cloned
# Check if the script is inside the repo
if cd ${SCRIPTS_DIR} && git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
CLONED_ORAN_REPO=`dirname ${SCRIPTS_DIR}`
echo_info "Use the cloned oran repo: ${CLONED_ORAN_REPO}"
mkdir -p ${SRC_ORAN_DIR}/rtp
cd ${SRC_ORAN_DIR}/rtp
rm -rf meta-oran meta-stx scripts
ln -sf ${CLONED_ORAN_REPO}/meta-oran meta-oran
ln -sf ${CLONED_ORAN_REPO}/meta-stx meta-stx
ln -sf ${CLONED_ORAN_REPO}/scripts scripts
else
echo_info "Cloning oran layer:"
cd ${SRC_ORAN_DIR}
clone_update_repo ${SRC_ORAN_BRANCH} ${SRC_ORAN_URL} rtp
fi
echo_info "Cloning or update Yocto layers:"
cd ${SRC_LAYER_DIR}
for layer_url in ${SRC_YP_URL}; do
layer_name=$(basename ${layer_url})
clone_update_repo ${SRC_YP_BRANCH} ${layer_url} ${layer_name}
done
echo_step_end
# Apply meta patches
for l in $(ls -1 ${SRC_META_PATCHES}); do
msg_step="Apply meta patches for ${l}"
echo_step_start
cd ${SRC_LAYER_DIR}/${l}
# backup current branch
local_branch=$(git rev-parse --abbrev-ref HEAD)
git branch -m "${local_branch}_${TIMESTAMP}"
git checkout ${local_branch}
for p in $(ls -1 ${SRC_META_PATCHES}/${l}); do
echo_info "Apllying patch: ${SRC_META_PATCHES}/${l}/${p}"
git am ${SRC_META_PATCHES}/${l}/${p}
done
echo_step_end
done
}
add_layer_stx_build () {
msg_step="Add required layers to the StarlingX build project"
echo_step_start
source_env ${PRJ_BUILD_DIR}
SRC_LAYERS=""
for layer_url in ${SRC_YP_URL}; do
layer_name=$(basename ${layer_url})
case ${layer_name} in
poky)
continue
;;
meta-openembedded)
for sub_layer in ${SUB_LAYER_META_OE}; do
SRC_LAYERS="${SRC_LAYERS} ${SRC_LAYER_DIR}/${layer_name}/${sub_layer}"
done
;;
meta-cloud-services)
SRC_LAYERS="${SRC_LAYERS} ${SRC_LAYER_DIR}/${layer_name}"
for sub_layer in ${SUB_LAYER_META_CLOUD_SERVICES}; do
SRC_LAYERS="${SRC_LAYERS} ${SRC_LAYER_DIR}/${layer_name}/${sub_layer}"
done
;;
meta-security)
SRC_LAYERS="${SRC_LAYERS} ${SRC_LAYER_DIR}/${layer_name}"
for sub_layer in ${SUB_LAYER_META_SECURITY}; do
SRC_LAYERS="${SRC_LAYERS} ${SRC_LAYER_DIR}/${layer_name}/${sub_layer}"
done
;;
*)
SRC_LAYERS="${SRC_LAYERS} ${SRC_LAYER_DIR}/${layer_name}"
;;
esac
done
SRC_LAYERS="${SRC_LAYERS} ${SRC_ORAN_DIR}/rtp/meta-stx"
for src_layer in ${SRC_LAYERS}; do
RUN_CMD="bitbake-layers add-layer ${src_layer}"
echo_cmd "Add the ${src_layer} layer into the build project"
${RUN_CMD}
done
echo_step_end
}
add_configs_stx_build () {
msg_step="Add extra configs into local.conf for StarlingX build"
echo_step_start
cd ${PRJ_BUILD_DIR}
echo_info "Adding the following extra configs into local.conf"
cat ${SRC_CONFIGS}/local-stx.conf | \
sed -e "s/@BSP@/${BSP}/" | tee -a conf/local.conf
echo "DL_DIR = '${PRJ_SHARED_DL_DIR}'" | tee -a conf/local.conf
echo "SSTATE_DIR = '${PRJ_SHARED_SS_DIR}'" | tee -a conf/local.conf
if [ "${RM_WORK}" == "Yes" ]; then
echo "INHERIT += 'rm_work'" | tee -a conf/local.conf
fi
if [ "${EXTRA_CONF}" != "" ] && [ -f "${EXTRA_CONF}" ]; then
cat ${EXTRA_CONF} | tee -a conf/local.conf
fi
echo_step_end
}
setup_stx_build () {
echo_step_start "Setup StarlingX build project"
add_layer_stx_build
cd ${PRJ_BUILD_DIR}
if ! grep -q 'Configs for StarlingX' conf/local.conf; then
add_configs_stx_build
else
echo_info "Nothing is added into local.conf"
fi
echo_step_end "Setup StarlingX build project"
}
build_stx_image () {
msg_step="Build StarlingX images"
echo_step_start
source_env ${PRJ_BUILD_DIR}
mkdir -p logs
RUN_CMD="bitbake ${DRYRUN} ${IMG_STX}"
echo_cmd "Build the ${IMG_STX} image"
bitbake ${DRYRUN} ${IMG_STX} 2>&1|tee logs/bitbake_${IMG_STX}_${TIMESTAMP}.log
echo_step_end
echo_info "Build succeeded, you can get the image in ${ISO_STX}"
}
add_layer_anaconda_build () {
msg_step="Add required layers to the anaconda (installer) build project"
echo_step_start
source_env ${PRJ_BUILD_DIR_ANACONDA}
SRC_LAYERS=""
for sub_layer in ${SUB_LAYER_META_OE_ANACONDA}; do
SRC_LAYERS="${SRC_LAYERS} ${SRC_LAYER_DIR}/meta-openembedded/${sub_layer}"
done
SRC_LAYERS="${SRC_LAYERS} ${SRC_LAYER_DIR}/meta-intel"
SRC_LAYERS="${SRC_LAYERS} ${SRC_LAYER_DIR}/meta-anaconda"
SRC_LAYERS="${SRC_LAYERS} ${SRC_ORAN_DIR}/rtp/meta-stx"
for src_layer in ${SRC_LAYERS}; do
RUN_CMD="bitbake-layers add-layer ${src_layer}"
echo_cmd "Add the ${src_layer} layer into the build project"
${RUN_CMD}
done
echo_step_end
}
add_configs_anaconda_build () {
msg_step="Add extra configs into local.conf for anaconda (installer) build"
echo_step_start
cd ${PRJ_BUILD_DIR_ANACONDA}
echo_info "Adding the following extra configs into local.conf"
cat ${SRC_CONFIGS}/local-anaconda.conf | \
sed -e "s/@BSP@/${BSP}/" \
-e "s|@TARGET_BUILD@|${PRJ_BUILD_DIR}|" \
| tee -a conf/local.conf
echo "DL_DIR = '${PRJ_SHARED_DL_DIR}'" | tee -a conf/local.conf
echo "SSTATE_DIR = '${PRJ_SHARED_SS_DIR}'" | tee -a conf/local.conf
if [ "${RM_WORK}" == "Yes" ]; then
echo "INHERIT += 'rm_work'" | tee -a conf/local.conf
fi
if [ "${EXTRA_CONF}" != "" ] && [ -f "${EXTRA_CONF}" ]; then
cat ${EXTRA_CONF} | tee -a conf/local.conf
fi
echo_step_end
}
setup_anaconda_build () {
echo_step_start "Setup anaconda (installer) build project"
add_layer_anaconda_build
cd ${PRJ_BUILD_DIR_ANACONDA}
if ! grep -q 'Configs for anaconda' conf/local.conf; then
add_configs_anaconda_build
else
echo_info "Nothing is added into local.conf"
fi
echo_step_end "Setup anaconda build project"
}
build_anaconda_image () {
echo_step_start "Build anaconda (installer) images"
source_env ${PRJ_BUILD_DIR_ANACONDA}
mkdir -p logs
if [ -f ${ISO_ANACONDA} ]; then
bitbake ${DRYRUN} -c clean ${IMG_ANACONDA}
fi
RUN_CMD="bitbake ${DRYRUN} ${IMG_ANACONDA}"
echo_cmd "Build the ${IMG_ANACONDA} image"
bitbake ${DRYRUN} ${IMG_ANACONDA} 2>&1|tee logs/bitbake_${IMG_ANACONDA}_${TIMESTAMP}.log
echo_step_end
echo_info "Build succeeded, you can get the image in ${ISO_ANACONDA}"
}
#########################################################################
# Main process
#########################################################################
prepare_workspace
prepare_src
setup_stx_build
setup_anaconda_build
build_stx_image
build_anaconda_image