Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2a28803
init code
yhmtsai Nov 15, 2019
5bec208
update format_header.sh
yhmtsai Nov 15, 2019
46879d8
reference works
yhmtsai Nov 18, 2019
aeb9598
final
yhmtsai Nov 18, 2019
f9c760e
fix * problem
yhmtsai Nov 18, 2019
98b216b
add some specified rule
yhmtsai Nov 18, 2019
efc2742
try to use config rule
yhmtsai Jan 9, 2020
6a1c8a6
format_header use config_regex
yhmtsai Jan 10, 2020
19009b8
avoid some unexpected behaviour
yhmtsai Jan 10, 2020
a2eaa35
update config
yhmtsai Jan 10, 2020
e0dcca7
keep the same empty lines and fix header def
yhmtsai Jan 12, 2020
fe7ac54
hip/device_functions problem
yhmtsai Jan 13, 2020
731663f
move get_include_regex
yhmtsai Jan 13, 2020
31383a4
add the alarm and handle the newline in #if
yhmtsai Jan 13, 2020
19fc2a0
fix non-self contain
yhmtsai Jan 13, 2020
8bda872
add component _kernels config
yhmtsai Jan 13, 2020
7f195f2
add discription
yhmtsai Jan 13, 2020
8557620
fix the config and rename zero_array and sorting
yhmtsai Jan 15, 2020
95571c6
add force-top
yhmtsai Mar 10, 2020
b5dba65
change the cuda/hip components filename
yhmtsai Mar 10, 2020
aedb6c0
manual fix
yhmtsai Mar 11, 2020
ecbcc7a
ignore the empty line in the beginning
yhmtsai Mar 11, 2020
950bfe9
add format_header and format_header_all in cmake
yhmtsai Mar 12, 2020
f784992
use better condition
yhmtsai Mar 12, 2020
06f9574
reference changes
yhmtsai Mar 12, 2020
ccf3542
include changes
yhmtsai Mar 12, 2020
bdf53c0
omp changes
yhmtsai Mar 12, 2020
43c4e84
cuda changes
yhmtsai Mar 12, 2020
fade352
core changes
yhmtsai Mar 12, 2020
a8c5390
hip changes
yhmtsai Mar 12, 2020
0eaa8cb
others changes
yhmtsai Mar 12, 2020
0f27071
manual fix, format_header on branch modification
yhmtsai Mar 17, 2020
7f3d8ae
separate executor-wide and others, fix MacOS
yhmtsai Mar 26, 2020
7b45b6a
Apply suggestions from code review
yhmtsai Apr 2, 2020
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
Prev Previous commit
Next Next commit
add the alarm and handle the newline in #if
  • Loading branch information
yhmtsai committed Mar 28, 2020
commit 31383a4b93b8873ff2f7430eb3ff875ab8baf363
146 changes: 74 additions & 72 deletions dev_tools/scripts/format_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,59 +43,59 @@ remove_regroup () {
}

get_include_regex () {
local file="$1"
local core_suffix=""
local path_prefix=""
local path_ignore="0"
local fix_include=""
local remove_test="false"
local item_regex="^-\ +\"(.*)\""
local path_prefix_regex="PathPrefix:\ +\"(.*)\""
local core_suffix_regex="CoreSuffix:\ +\"(.*)\""
local path_ignore_regex="PathIgnore:\ +\"(.*)\""
local fix_include_regex="FixInclude:\ +\"(.*)\""
local remove_test_regex="RemoveTest:\ +\"(.*)\""
local match="false"
while IFS='' read -r line; do
if [[ "$line" =~ $item_regex ]]; then
file_regex="${BASH_REMATCH[1]}"
if [[ "$match" = "true" ]]; then
break
elif [[ $file =~ $file_regex ]]; then
match="true"
local file="$1"
local core_suffix=""
local path_prefix=""
local path_ignore="0"
local fix_include=""
local remove_test="false"
local item_regex="^-\ +\"(.*)\""
local path_prefix_regex="PathPrefix:\ +\"(.*)\""
Comment thread
upsj marked this conversation as resolved.
local core_suffix_regex="CoreSuffix:\ +\"(.*)\""
local path_ignore_regex="PathIgnore:\ +\"(.*)\""
local fix_include_regex="FixInclude:\ +\"(.*)\""
local remove_test_regex="RemoveTest:\ +\"(.*)\""
local match="false"
while IFS='' read -r line; do
if [[ "$line" =~ $item_regex ]]; then
file_regex="${BASH_REMATCH[1]}"
if [[ "$match" = "true" ]]; then
break
elif [[ $file =~ $file_regex ]]; then
match="true"
fi
elif [ "$match" = "true" ]; then
if [[ "$line" =~ $path_prefix_regex ]]; then
path_prefix="${BASH_REMATCH[1]}"
elif [[ "$line" =~ $core_suffix_regex ]]; then
core_suffix="${BASH_REMATCH[1]}"
elif [[ "$line" =~ $path_ignore_regex ]]; then
path_ignore="${BASH_REMATCH[1]}"
elif [[ "$line" =~ $fix_include_regex ]]; then
fix_include="${BASH_REMATCH[1]}"
elif [[ "$line" =~ $remove_test_regex ]]; then
remove_test="${BASH_REMATCH[1]}"
else
echo "wrong: ${line}"
fi
fi
elif [ "$match" = "true" ]; then
if [[ "$line" =~ $path_prefix_regex ]]; then
path_prefix="${BASH_REMATCH[1]}"
elif [[ "$line" =~ $core_suffix_regex ]]; then
core_suffix="${BASH_REMATCH[1]}"
elif [[ "$line" =~ $path_ignore_regex ]]; then
path_ignore="${BASH_REMATCH[1]}"
elif [[ "$line" =~ $fix_include_regex ]]; then
fix_include="${BASH_REMATCH[1]}"
elif [[ "$line" =~ $remove_test_regex ]]; then
remove_test="${BASH_REMATCH[1]}"
else
echo "wrong: ${line}"
done < "dev_tools/scripts/config"
output=""
if [ -z "${fix_include}" ]; then
local path_regex="([a-zA-Z_]*\/){${path_ignore}}(.*)\.(cpp|hpp|cu|cuh)"
if [ ! -z "${path_prefix}" ]; then
path_prefix="${path_prefix}/"
fi
output=$(echo "${file}" | sed -E "s~\.hip~~g;s~$path_regex~$path_prefix\2~g")
output=$(echo "${output}" | sed -E "s~$core_suffix$~~g")
output="#include (<|\")$output\.(hpp|hip\.hpp|cuh)(\"|>)"
if [ "${remove_test}" = "true" ]; then
output=$(echo "${output}" | sed -E "s~test/~~g")
fi
else
output="#include (<|\")$fix_include(\"|>)"
fi
done < "dev_tools/scripts/config"
output=""
if [ -z "${fix_include}" ]; then
local path_regex="([a-zA-Z_]*\/){${path_ignore}}(.*)\.(cpp|hpp|cu|cuh)"
if [ ! -z "${path_prefix}" ]; then
path_prefix="${path_prefix}/"
fi
output=$(echo "${file}" | sed -E "s~\.hip~~g;s~$path_regex~$path_prefix\2~g")
output=$(echo "${output}" | sed -E "s~$core_suffix$~~g")
output="#include (<|\")$output\.(hpp|hip\.hpp|cuh)(\"|>)"
if [ "${remove_test}" = "true" ]; then
output=$(echo "${output}" | sed -E "s~test/~~g")
fi
else
output="#include (<|\")$fix_include(\"|>)"
fi
echo "$output"
echo "$output"
}

GINKGO_LICENSE_BEACON="******************************<GINKGO LICENSE>******************************"
Expand All @@ -105,6 +105,7 @@ BEFORE="before" # Store the main header and the #ifdef/#define of header file
HAS_HIP_RUNTIME="false"
DURING_LICENSE="false"
INCLUDE_REGEX="^#include.*"
INCLUDE_INC="\.inc"
MAIN_PART_MATCH="$(get_include_regex $1)"
HEADER_DEF=$(get_header_def $1)
IFNDEF=""
Expand All @@ -118,7 +119,8 @@ ENDIF_REX="^#endif"
IN_IF="false"
KEEP_LINES=0
LAST_NONEMPTY=""

ALARM=""
COMMENT_REGEX="^ *(\/\/|\/\*)"

while IFS='' read -r line || [ -n "$line" ]; do
if [ "${line}" = '#include "hip/hip_runtime.h"' ] && [ "${SKIP}" = "true" ]; then
Expand Down Expand Up @@ -150,18 +152,29 @@ while IFS='' read -r line || [ -n "$line" ]; do
IN_IF="false"
fi
SKIP="false"
if [ -z "${ALARM}" ]; then
ALARM="set"
fi
elif [ ! -z "${MAIN_PART_MATCH}" ] && [[ "${line}" =~ ${MAIN_PART_MATCH} ]]; then
line="$(convert_header ${line})"
echo "${line}" >> ${BEFORE}
else
if [[ "${line}" =~ $INCLUDE_REGEX ]]; then
if [ -z "${ALARM}" ] && [[ "${line}" =~ $COMMENT_REGEX ]]; then
ALARM="set"
elif [[ "${line}" =~ $INCLUDE_REGEX ]]; then
line="$(convert_header ${line})"
if [[ ! "${line}" =~ $INCLUDE_INC ]] && [ "${ALARM}" = "set" ]; then
ALARM="true"
fi
fi
echo "${line}" >> "${CONTENT}"
SKIP="false"
fi
fi
done < $1
if [ "${ALARM}" = "true" ]; then
echo "ALARM $1 may not be sorted correctly"
fi
echo "/*${GINKGO_LICENSE_BEACON}" > $1
cat LICENSE >> $1
echo "${GINKGO_LICENSE_BEACON}*/" >> $1
Expand Down Expand Up @@ -221,31 +234,20 @@ if [ -f "${CONTENT}" ]; then
PREV_INC=0
IN_IF="false"
while IFS='' read -r line; do
if [[ "${line}" =~ $IF_REX ]] || [ "$IN_IF" = "true" ]; then
# make sure that the header in #if is not extracted
echo "${line}" >> $1
IN_IF="true"
if [[ "${line}" =~ $ENDIF_REX ]]; then
IN_IF="false"
# To keep the original lines
PREV_INC=-3
if [[ ${line} =~ ${INCLUDE_REGEX} ]] && [[ ! ${line} =~ ${INCLUDE_INC} ]]; then
if [[ ${PREV_INC} == 1 ]]; then
echo "" >> $1
fi
PREV_INC=0
else
if [[ ${line} =~ ${INCLUDE_REGEX} ]]; then
if [[ ${PREV_INC} == 1 ]]; then
echo "" >> $1
fi
PREV_INC=0
if [ -z "${line}" ]; then
PREV_INC=$((PREV_INC+1))
else
if [ -z "${line}" ]; then
PREV_INC=$((PREV_INC+1))
else
# To keep the original lines
PREV_INC=-3
fi
# To keep the original lines
PREV_INC=-3
fi
echo "${line}" >> $1
fi
echo "${line}" >> $1
done < ${CONTENT}
rm ${CONTENT}
fi