Skip to content
This repository has been archived by the owner on Jan 7, 2023. It is now read-only.

improve logger for rdk scripts #24

Merged
merged 1 commit into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions rdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,11 @@ check_system_version()
if [[ -f /etc/lsb-release ]]; then
system_ver=$( < /etc/lsb-release grep -i "DISTRIB_RELEASE" | cut -d "=" -f2)
if [[ $system_ver != "18.04" ]] ;then
echo -e "\n${FG_RED}Error${FG_NONE}:
${FG_BLUE}sorry, robot_devkit currently supports only Ubuntu 18.04${FG_NONE}
"
error "Sorry, robot_devkit currently supports olny ubuntu 18.04"
exit 1
fi
else
echo -e "\n${FG_RED}Error${FG_BLUE}:
${FG_BLUE}sorry, robot_devkit currently supports olny ubuntu 18.04${FG_NONE}
"
error "Sorry, robot_devkit currently supports olny ubuntu 18.04"
exit 1
fi
}
Expand Down
42 changes: 20 additions & 22 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ set -e
#######################################
build_pkg()
{
info "\nBuild [$1] $2\n"
info "Build [$1] $2\n"

local pkg=$1
local build_options=$2
Expand All @@ -53,22 +53,21 @@ build_pkg()
# source ros2 core environment when build other packages
local ros2_core
ros2_core=$(get_current_product_deps_dir)/ros2-linux/local_setup.bash
info "\nSource ${ros2_core}\n"
info "Source ${ros2_core}\n"
if [[ -f "${ros2_core}" ]] ; then
. ${ros2_core}
else
warning "${ros2_core} not exist"
warn "${ros2_core} not exist"
fi

# Install dependences libraries for prebuild
local prebuild_exec
prebuild_exec=$(get_packages_dir)/${pkg}/scripts/pre_build.sh
if [[ -f "${prebuild_exec}" ]] ; then
info "\nInstall libs\n. ${prebuild_exec}\n"
info "Execute ${prebuild_exec} ${pkg_ws}"
. "${prebuild_exec}" "${pkg_ws}"
fi


build_execute "${pkg}" "${ros2_build_dir}" "${ros2_install_dir}" "${src_dir}" "${build_options}"
}

Expand All @@ -86,28 +85,27 @@ build_pkg()
#######################################
build_execute()
{
info "\nBuild packages\n"

local pkg=$1
local ros2_build_dir=$2
local ros2_install_dir=$3
local src_dir=$4
local build_options=$5

echo "execute colcon build \
--symlink-install \
--build-base ${ros2_build_dir} \
--install-base ${ros2_install_dir} \
--base-paths ${src_dir} \
$build_options"
info "Execute colcon build \
--symlink-install \
--build-base ${ros2_build_dir} \
--install-base ${ros2_install_dir} \
--base-paths ${src_dir} \
$build_options"

execute colcon build \
--symlink-install \
--build-base "${ros2_build_dir}" \
--install-base "${ros2_install_dir}" \
--base-paths "${src_dir}" \
"$build_options"
--symlink-install \
--build-base "${ros2_build_dir}" \
--install-base "${ros2_install_dir}" \
--base-paths "${src_dir}" \
"$build_options"

info "\nCompleted [$pkg] build.\n"
ok "Completed [$pkg] build.\n"
}


Expand All @@ -118,14 +116,14 @@ build_execute()
#######################################
build()
{

info "Build packages ...\n"
if [[ "$ROS_DISTRO" = "melodic" ]];then
warning "\nDetected system has already been sourced ROS environment, this will make RDK build fail. Suggest not to source any ROS setup.bash and open a new terminal for RDK build.\n"R
error "Detected system has already been sourced ROS environment, this will make RDK build fail. Suggest not to source any ROS setup.bash and open a new terminal for RDK build.\n"R
exit 1
fi

local build_options="$*"

read -r -a array <<< "$(get_packages_list)"
for pkg in "${array[@]}"
do
Expand Down
20 changes: 7 additions & 13 deletions scripts/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,41 @@ set -e

. "$CURRENT_DIR"/product.sh


#######################################
# Clean build files
# Arguments:
# pkg: selected packages
#######################################
do_clean()
{
info "\nClean [$1] \n"

local pkg=$1
local pkg_ws
rdk_ws=$(get_rdk_ws_dir)/${pkg}_ws
info "Clean [$1]"

local pkg_ws=${1}_ws
rdk_ws=$(get_rdk_ws_dir)/${pkg_ws}

if [[ -d "${rdk_ws}" ]]; then
local ros2_build_dir
local ros2_install_dir
ros2_build_dir="$rdk_ws"/build
ros2_install_dir="$rdk_ws"/install

info "Delete $ros2_build_dir"
info "Delete $ros2_install_dir"
info "Execute rm -rf $ros2_build_dir"
info "Execute rm -rf $ros2_install_dir"
rm -rf "$ros2_build_dir"
rm -rf "$ros2_install_dir"
else
warning "${rdk_ws} not exist, nothing to remove, skip"
warn "${rdk_ws} not exist, nothing to remove, skip"
fi

}


#######################################
# Common build entry
# Arguments:
# group: core or device or modules
#######################################
clean()
{
info "\nClean build and install under rdk_ws workspace...\n"
echo $(get_rdk_ws_dir)
info "Clean build and install under $(get_rdk_ws_dir) ...\n"
if [[ ! -d "$(get_rdk_ws_dir)" ]]; then
error "$(get_rdk_ws_dir) does not exist."
exit 1
Expand Down
45 changes: 28 additions & 17 deletions scripts/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,54 +24,65 @@ ROBOT_DEVKIT_WS_DIR=${ROBOT_DEVKIT_ROOT_DIR}/rdk_ws
# Color definitions for foreground
FG_NONE='\033[0m'
FG_BOLD='\033[1m'
# FG_BLACK='\033[0;30m'
# FG_GRAY="\033[1;30m"
FG_BLACK='\033[0;30m'
FG_GRAY="\033[1;30m"
FG_RED='\033[0;31m'
# FG_GREEN='\033[0;32m'
FG_GREEN='\033[0;32m'
FG_YELLOW='\033[0;33m'
FG_BLUE='\033[0;34m'
# FG_MAGENTA='\033[0;35m'
# FG_CYAN='\033[0;36m'
# FG_LIGHT_GRAY="\033[0;37m"
# FG_DARK_GRAY="\033[0;90m"
# FG_LIGHT_RED="\033[0;91m"
# FG_LIGHT_GREEN="\033[0;92m"
# FG_LIGHT_YELLOW="\033[0;93m"
FG_MAGENTA='\033[0;35m'
FG_CYAN='\033[0;36m'
FG_LIGHT_GRAY="\033[0;37m"
FG_DARK_GRAY="\033[0;90m"
FG_LIGHT_RED="\033[0;91m"
FG_LIGHT_GREEN="\033[0;92m"
FG_LIGHT_YELLOW="\033[0;93m"
FG_LIGHT_BLUE="\033[0;94m"
# FG_LIGHT_MAGENTA='\033[0;95m'
FG_LIGHT_MAGENTA='\033[0;95m'
FG_LIGHT_CYAN='\033[1;96m'
# FG_WHITE='\033[1;97m'
FG_WHITE='\033[1;97m'

log() {
FG=${1}
timestamp=$(date +'%Y-%m-%d %H:%M:%S')
filename=$(basename ${BASH_SOURCE[2]})
lineno=${BASH_LINENO[1]}

shift 1
string=${*}
echo -e "$FG[${timestamp}][${filename}:${lineno}]$string"
}

#######################################
# Show info message
#######################################
info()
{
(>&2 echo -e "${FG_BOLD}$*${FG_NONE}")
log "${FG_BLUE}" "[INFO] $*${FG_NONE}"
}

######################################
# Show info message
######################################
warning()
warn()
{
(>&2 echo -e "${FG_YELLOW}Warning: $*${FG_NONE}")
log "${FG_YELLOW}" "[WARN] $*${FG_NONE}"
}

######################################
# Show error message
######################################
error()
{
(>&2 echo -e "${FG_RED}$*${FG_NONE}")
log "${FG_RED}" "[ERROR] $*${FG_NONE}"
}

######################################
# Show ok message
######################################
ok()
{
(>&2 echo -e "${FG_LIGHT_CYAN}$*${FG_NONE}")
log "${FG_LIGHT_CYAN}" "[OK] $*${FG_NONE}"
}

######################################
Expand Down
36 changes: 15 additions & 21 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,12 @@ set -e

. "${CURRENT_DIR}"/product.sh

#######################################
# Generate robot_devkit_setup.bash file
#######################################
generate_setup_bash()
{
echo "bash"
}

#######################################
# Install the generated RDK to /opt/robot_devkit folder.
#######################################
install_rdk()
{
info "\nInstall rdk ...\n"
info "Install rdk ...\n"
local rdk_ws_dir
local target_dir

Expand All @@ -54,7 +46,7 @@ install_rdk()
ros2_core=${rdk_ws_dir}/third_party/ros2-linux
target_ros2_dir=${target_dir}/ros2-linux

info "Install [ros2_core] to [${target_ros2_dir}/ros2-linux]"
info "Link ${ros2_core} to ${target_ros2_dir}"
if [[ -d ${ros2_core} ]]; then
sudo rm -rf "${target_ros2_dir}"
sudo ln -sf "${ros2_core}" "${target_ros2_dir}"
Expand All @@ -65,7 +57,7 @@ install_rdk()
. ${target_ros2_dir}/local_setup.bash
EOF"
else
info "Not found: ${ros2_core}"
warn "Not found: ${ros2_core}"
exit
fi

Expand All @@ -80,28 +72,29 @@ EOF"
build_pkg_dir=${rdk_ws_dir}/${pkg}_ws/install
target_pkg_dir=${target_dir}/${pkg}

info "Install [$build_pkg_dir] to [${target_pkg_dir}]"
info "Link ${build_pkg_dir} to ${target_pkg_dir}"

if [[ -d ${build_pkg_dir} ]]; then
sudo rm -rf "$target_pkg_dir"
sudo ln -sf "${build_pkg_dir}" "$target_pkg_dir"
# Append setup bash file
echo ". ${target_pkg_dir}/local_setup.bash" | sudo tee -a ${target_dir}/robot_devkit_setup.bash > /dev/null
else
info "Not found: ${build_pkg_dir}"
warn "Not found: ${build_pkg_dir}"
fi
done


info "\nGenerated setup bash to $target_dir/robot_devkit_setup.bash"
ok "\nSuccessful install ROS package on ${target_dir}"
info "Generated setup bash to $target_dir/robot_devkit_setup.bash"
ok "Successful install ROS package on ${target_dir}.\n"
}

#######################################
# Clean the output folder
#######################################
uninstall_rdk()
{
info "Uninstall all build files...\n"
local install_dir
local rdk_ws
local log_dir
Expand All @@ -110,15 +103,16 @@ uninstall_rdk()
rdk_ws=$(get_rdk_ws_dir)
log_dir=$(get_root_dir)/log

info "DELETE: ${install_dir}"
info "DELETE: ${rdk_ws}"
info "DELETE: ${log_dir}"
info "unlink: products/current"

info "Delete: ${install_dir}"
sudo rm -fr "${install_dir}"

info "Delete: ${rdk_ws}"
sudo rm -fr "${rdk_ws}"

info "Delete: ${log_dir}"
sudo rm -fr "${log_dir}"
ok "\nSuccessful uninstall all build and installed files"

ok "Successfully uninstalled all build and installed files.\n"
}

unset CURRENT_DIR
Loading