Skip to content

Commit

Permalink
Allow to build operators with run script
Browse files Browse the repository at this point in the history
Also:
- verify input validity using the improve listing from the last commit
- allow passing a path to the app/operator dir, for improve UX by leveraging
terminal autocompletion

Signed-off-by: Alexis Girault <[email protected]>
  • Loading branch information
agirault committed Dec 13, 2024
1 parent 7d08270 commit 6dc6e81
Showing 1 changed file with 41 additions and 22 deletions.
63 changes: 41 additions & 22 deletions run
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ HOLOHUB_PY_LIB="${HOLOHUB_PY_EXE/bin/lib}"

YELLOW="\e[1;33m"
RED="\e[1;31m"
CYAN="\e[0;36m"
NOCOLOR="\e[0m"

# Compare versions
Expand Down Expand Up @@ -72,9 +73,9 @@ run_command() {
local cmd="$*"

if [ "${DO_DRY_RUN}" != "true" ]; then
echo -e "${YELLOW}[command]${NOCOLOR} ${cmd}"
echo -e "${CYAN}[command]${NOCOLOR} ${cmd}"
else
echo -e "${YELLOW}[dryrun]${NOCOLOR} ${cmd}"
echo -e "${CYAN}[dryrun]${NOCOLOR} ${cmd}"
fi

[ "$(echo -n "$@")" = "" ] && return 1 # return 1 if there is no command available
Expand Down Expand Up @@ -210,6 +211,10 @@ print_error() {
echo -e "${RED}ERROR${NOCOLOR}:" $*
}

print_warning() {
echo -e "${YELLOW}WARNING${NOCOLOR}:" $*
}


check_exit_code() {
local exit_code=$1
Expand Down Expand Up @@ -666,57 +671,71 @@ build() {
fi
done

echo "Building Holohub"

# Application to build
# Application or operator to build
if [ "$1" == "" ]; then
print_error "Please specify which application to build."
echo "You can run ./run list for a full list of applications."
print_error "Please specify which operator or application to build."
echo "You can run ./run list for a full list of options."
exit 1
fi
project=$(basename "$1")
opt_prefix=""
is_app=false
if list_apps | grep -Fxq "$project"; then
opt_prefix="-D APP_"
is_app=true
elif list_operators | grep -Fxq "$project"; then
opt_prefix="-D OP_"
else
print_error "Unknown application or operator: $1"
echo "You can run ./run list for a full list of options."
exit 1
fi
echo "Building $project"
opt_flag="$opt_prefix$project:BOOL=1"

# Assign default build path
if [ "$build_path" == "" ]; then
build_path="build/$1"
build_path="build/$project"
fi

local app_source_root_path
if [ $benchmark == true ]; then
app_source_root_path=$(get_app_source_root_dir $1)
run_command benchmarks/holoscan_flow_benchmarking/patch_application.sh ${app_source_root_path}
if [ $is_app == true ]; then
app_source_root_path=$(get_app_source_root_dir $project)
run_command benchmarks/holoscan_flow_benchmarking/patch_application.sh ${app_source_root_path}
else
print_warning "Requesting benchmarking with --benchmark is only available for applications, ignoring"
fi
fi

echo "Building $1 application"
application="-DAPP_$1=1"

# We define the python path to make sure we grab the right one
cmake_extra_args="--no-warn-unused-cli -DPython3_EXECUTABLE=${HOLOHUB_PY_EXE} -DPython3_ROOT_DIR=${HOLOHUB_PY_LIB}"
cmake_extra_args="--no-warn-unused-cli -D Python3_EXECUTABLE=${HOLOHUB_PY_EXE} -D Python3_ROOT_DIR=${HOLOHUB_PY_LIB}"

# We set the data directory to be outside the build directory
cmake_extra_args="$cmake_extra_args $configure_args -DHOLOHUB_DATA_DIR:PATH=${SCRIPT_DIR}/data"
cmake_extra_args="$cmake_extra_args $configure_args -D HOLOHUB_DATA_DIR:PATH=${SCRIPT_DIR}/data"

# Sets the default path for cuda
export PATH=$PATH:/usr/local/cuda/bin
run_command cmake -S . -B ${build_path} ${cmake_extra_args} -DCMAKE_BUILD_TYPE=${build_type} ${holoscan_sdk} ${application}
run_command cmake -S . -B ${build_path} ${cmake_extra_args} -D CMAKE_BUILD_TYPE=${build_type} ${holoscan_sdk} ${opt_flag}
ret=$?
check_exit_code $ret "Error building application."
check_exit_code $ret "Error building $project."
# Job concurrency determined by the underlying build tool unless a number is specified
run_command cmake --build ${build_path} -j ${parallel_jobs}
ret=$?
check_exit_code $ret "Error building application."
check_exit_code $ret "Error building $project."

if [ $install == true ]; then
run_command cmake --install ${build_path}
ret=$?
check_exit_code $ret "Error installing application."
check_exit_code $ret "Error installing $project."
fi

if [ $benchmark == true ]; then
if [ $benchmark == true ] && [ $is_app == true ]; then
app_source_root_path=$(get_app_source_root_dir $1)
run_command benchmarks/holoscan_flow_benchmarking/restore_application.sh ${app_source_root_path}
fi

echo "Holohub build done."
echo "Build done."
}


Expand Down Expand Up @@ -937,7 +956,7 @@ autocompletion_list() {
for d in ${apps}; do
local appname=$(dirname $d | grep -Po '^'${SCRIPT_DIR}/applications/'\K[^ ]*')
filename="${appname%/*}"
# Deal with projectectories of applications
# Deal with subdirectories of applications
echo "${filename##*/}"
done
echo "build launch clear_cache cpp python install_lint_deps lint setup"
Expand Down

0 comments on commit 6dc6e81

Please sign in to comment.