#!/bin/bash
current_dir=$(pwd)
variables_cmake="cmake/variables.cmake"
op_category_list=$(perl -0777 -ne 'if (/set\(OPS_CATEGORY_LIST\s*(.*?)\)/s) { print $1 }' "$current_dir/$variables_cmake" | grep -oP '"[^"]+"' | sed 's/"//g' | xargs)
IFS=' ' read -r -a op_categories <<< "$op_category_list"
valid_dirs=()
pr_file=$(realpath "${1:-pr_filelist.txt}")
for category in "${op_categories[@]}"
do
category_path="$current_dir/$category"
if [ -d "$category_path" ]; then
for dir in "$category_path"/*/
do
dir_name=$(basename "$dir")
if [[ "$dir_name" != *"common"* ]]; then
valid_dirs+=("$dir_name")
fi
done
fi
done
valid_example_dirs=("add_example")
for first_level in "$current_dir"/*/
do
for second_level in "$first_level"*/
do
examples_dir="$second_level""examples"
if [ -d "$examples_dir" ]; then
if ls "$examples_dir"/test_aclnn_* 1> /dev/null 2> /dev/null; then
dir_name=$(basename "$second_level")
valid_example_dirs+=("$dir_name")
fi
fi
done
done
ops_name=("add_example")
mapfile -t lines < ${pr_file}
for file_path in "${lines[@]}"
do
file_path=$(echo "$file_path" | xargs)
if [ -z "$file_path" ]; then
continue
fi
if [[ "$file_path" == *.md ]]; then
continue
fi
if [[ "$file_path" == "experimental/"* ]]; then
continue
fi
for dir in "${valid_dirs[@]}"
do
if [[ "$file_path" == *"/$dir/"* ]]; then
if [[ ! " ${ops_name[@]} " =~ " $dir " ]]; then
ops_name+=("$dir")
fi
break
fi
done
done
for name in "${ops_name[@]}"
do
rm -rf build
rm -rf build_out
if [[ "${REPOSITORY_NAME}" == "ops-math-dev" ]]; then
echo "bash build.sh --pkg --vendor_name=$name --ops=$name --cann_3rd_lib_path=${ASCEND_3RD_LIB_PATH} -j16"
bash build.sh --pkg --vendor_name=$name --ops=$name --cann_3rd_lib_path=${ASCEND_3RD_LIB_PATH} -j16
status=$?
elif [[ "${REPOSITORY_NAME}" == "ops-math" ]]; then
echo "bash build.sh --pkg --vendor_name=$name --ops=$name --cann_3rd_lib_path=${ASCEND_3RD_LIB_PATH} -j16"
bash build.sh --pkg --vendor_name=$name --ops=$name --cann_3rd_lib_path=${ASCEND_3RD_LIB_PATH} -j16
status=$?
fi
if [[ $status -ne 0 ]]; then
echo "check pkg fail"
exit 1
fi
for dir in "${valid_example_dirs[@]}"
do
if [[ "$dir" == "$name" ]]; then
mkdir -p ${WORKSPACE}/single
cp build_out/cann-ops-math-${name}_linux*.run ${WORKSPACE}/single/
fi
done
done
cd ${WORKSPACE}
tar -zcf single.tar.gz single/
ls