2019-11-16 14:19:00 -06:00
|
|
|
#!/bin/bash
|
|
|
|
#title : openfpga.sh
|
|
|
|
#description : This script provides shortcut commands <bash functions>
|
|
|
|
# for several simple operations in OpenFPGA project
|
|
|
|
#author : Ganesh Gore <ganesh.gore@utah.edu>
|
|
|
|
#==============================================================================
|
|
|
|
|
|
|
|
export OPENFPGA_PATH="$(pwd)"
|
2019-11-16 16:52:32 -06:00
|
|
|
export OPENFPGA_SCRIPT_PATH="$(pwd)/openfpga_flow/scripts"
|
2019-11-16 14:19:00 -06:00
|
|
|
export OPENFPGA_TASK_PATH="$(pwd)/openfpga_flow/tasks"
|
2019-11-16 16:52:32 -06:00
|
|
|
if [ -z $PYTHON_EXEC ]; then export PYTHON_EXEC="python3"; fi
|
2019-11-16 14:19:00 -06:00
|
|
|
|
|
|
|
# This function checks the path and
|
|
|
|
# raises warning if the command is not executing
|
|
|
|
# inside current OpendFPGA folder
|
|
|
|
check_execution_path (){
|
|
|
|
if [[ $1 != *"${OPENFPGA_PATH}"* ]]; then
|
|
|
|
echo -e "\e[33mCommand is not executed from configured OPNEFPGA directory\e[0m"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-11-16 16:52:32 -06:00
|
|
|
run-task () {
|
|
|
|
$PYTHON_EXEC $OPENFPGA_SCRIPT_PATH/run_fpga_task.py "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
run-flow () {
|
|
|
|
$PYTHON_EXEC $OPENFPGA_SCRIPT_PATH/run_fpga_flow.py "$@"
|
|
|
|
}
|
|
|
|
|
2019-11-16 14:19:00 -06:00
|
|
|
# lists all the configure task in task directory
|
|
|
|
list-tasks () {
|
|
|
|
check_execution_path "$(pwd)"
|
|
|
|
ls -tdalh ${OPENFPGA_TASK_PATH}/* | awk '{printf("%-4s | %s %-3s | ", $5, $6, $7) ;system("basename " $9)}'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Switch directory to root of OpenFPGA
|
|
|
|
goto-root () {
|
|
|
|
cd $OPENFPGA_PATH
|
|
|
|
}
|
|
|
|
|
|
|
|
# Changes directory to task directory [goto_task <task_name> <run_num[default 0]>]
|
|
|
|
goto-task () {
|
|
|
|
if [ -z $1 ]; then
|
|
|
|
echo "requires task name goto_task <task_name> <run_num[default 0]>"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
goto_path=$OPENFPGA_TASK_PATH/$1
|
2019-11-16 16:52:32 -06:00
|
|
|
run_num=""
|
2019-11-16 14:19:00 -06:00
|
|
|
if [ ! -d $goto_path ]; then echo "Task directory not found"; return; fi
|
2019-11-16 16:52:32 -06:00
|
|
|
if [[ "$2" =~ '^[0-9]+$' ]] ; then
|
|
|
|
if ! [[ $2 == '0' ]] ; then run_num="$(printf run%03d $2)"; else run_num="latest"; fi
|
|
|
|
if [ ! -d "$goto_path/$run_num" ]; then run_num="latest"; fi
|
2019-11-16 14:19:00 -06:00
|
|
|
fi
|
|
|
|
if [ ! -d $goto_path/$run_num ]; then
|
2019-11-16 16:52:32 -06:00
|
|
|
echo "\e[33mTask run directory not found -" $goto_path/$run_num "\e[0m"
|
2019-11-16 14:19:00 -06:00
|
|
|
else
|
2019-11-16 16:52:32 -06:00
|
|
|
echo "Switching current dirctory to" $goto_path/$run_num
|
2019-11-16 14:19:00 -06:00
|
|
|
cd $goto_path/$run_num
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Clears enviroment variables and fucntions
|
2019-11-16 16:52:32 -06:00
|
|
|
unset-openfpga (){
|
2019-11-16 14:19:00 -06:00
|
|
|
unset -v OPENFPGA_PATH
|
2019-11-16 16:52:32 -06:00
|
|
|
unset -f list-tasks run-task run-flow goto-task goto-root >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
# Allow autocompletion of task
|
|
|
|
if [[ $(ps -p $$ -oargs=) == *"zsh"* ]]; then
|
|
|
|
autoload -U +X bashcompinit; bashcompinit;
|
|
|
|
fi
|
|
|
|
TaskList=$(ls -tdalh ${OPENFPGA_TASK_PATH}/* | awk '{system("basename " $9)}' | awk '{printf("%s ",$1)}')
|
|
|
|
complete -W "${TaskList}" goto-task
|
|
|
|
complete -W "${TaskList}" run-task
|