#!/bin/bash
ROOT_PATH=$(
cd "$(dirname $0)"/../..
pwd
)
cd ${ROOT_PATH}
if [ $# -lt 1 ]; then
echo "Usage: $0 <pr_filelist.txt> [soc_version]"
exit 1
fi
pr_filelist=$1
soc_version=$2
if [ ! -f "$pr_filelist" ]; then
echo "Error: File $pr_filelist not found"
exit 1
fi
ops=()
run_all=false
ignore_dirs="common include utils frame"
while IFS= read -r filepath; do
if [[ "$filepath" == *.md ]]; then
continue
fi
if [[ "$filepath" == include* ]]; then
run_all=true
break
fi
if [[ !"$filepath" =~ blas* ]] && [[ !"$filepath" =~ test* ]];then
continue
fi
paths=($(echo "$filepath" | sed 's/\// /g'))
second_dir=${paths[2]}
first_dir=${paths[1]}
root_dir=${paths[0]}
if [[ "$root_dir" == "test" ]] && ([[ ! -d "$root_dir/$first_dir" ]] || [[ " $ignore_dirs " =~ " $first_dir " ]]); then
run_all=true
break
fi
if [[ -n "$second_dir" ]] && [[ -d "./test/$first_dir/$second_dir" ]]; then
ops+=($second_dir)
elif [[ -n "$first_dir" ]] && [[ -d "./test/$first_dir" ]]; then
ops+=($first_dir)
fi
done < "$pr_filelist"
ops+=("blasLtMatmul")
declare -A _seen
_unique=()
for _op in "${ops[@]}"; do
if [[ -z "${_seen[$_op]}" ]]; then
_seen[$_op]=1
_unique+=("$_op")
fi
done
ops=("${_unique[@]}")
echo "Trigger Ops: ${ops[@]}."
echo "Need run all: ${run_all}."
if [ "$run_all" = true ]; then
if [ -n "$soc_version" ]; then
cmd="bash build.sh --run --soc=$soc_version"
else
cmd="bash build.sh --run"
fi
else
ops_str=""
for op in "${ops[@]}"; do
if [ -z "$ops_str" ]; then
ops_str="$op"
else
ops_str="$ops_str,$op"
fi
done
if [ -n "$soc_version" ]; then
cmd="bash build.sh --run --ops=$ops_str --soc=$soc_version"
else
cmd="bash build.sh --run --ops=$ops_str"
fi
fi
echo "Command: $cmd."
${cmd}