Skip to content

Commit

Permalink
api: update generator with tarantool 3.2.0
Browse files Browse the repository at this point in the history
Fix parsing box/errcode.h constants.

Closes #6
  • Loading branch information
dmyger committed Oct 9, 2024
1 parent ca3626f commit 2bfa473
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ if [[ -z "${TT_REPO}" ]]; then
TT_REPO="https://github.com/tarantool/tarantool.git"
fi

TT_DIR=tarantool
TT_DIR=tarantool-$TT_TAG

# Cleanup.
rm -rf ${TT_DIR}

git clone --depth 1 --branch ${TT_TAG} ${TT_REPO} -o ${TT_DIR}
git clone --depth 1 --branch ${TT_TAG} ${TT_REPO} ${TT_DIR}
cd ${TT_DIR}
TT_COMMIT=$(git log -n 1 | head -n 1 | sed "s/commit //")
cd ..
Expand Down Expand Up @@ -233,19 +233,22 @@ type Error int
const (
EOF

grep "(ER_" ${SRC_ERRORS} | \
# Remove comments symbols.
sed "s/\/\*//" | \
sed "s/\*\/_(//" | \
# Remove and of values.
sed "s/) *\\\//" | \
# Remove comma at an end of a value.
sed "s/,/ /" | \
# Finally print parsed values in Golang format.
awk '{
# Extract body of define ERROR_CODES
ERROR_CODES=`sed -n '/^#define ERROR_CODES(/,/This one should be last/{//!p;}' ${SRC_ERRORS}`

echo "${ERROR_CODES}" | \
# Get line with ER_* description
sed -nE 's/^[^E]*(ER_.+)\s*\\\s*$/\1/p' | \
# Remove trailing parenthesis or comment's ending
sed -E 's/(.*)\s*(:?\)|\*\/)\s*$/\1/' | \
awk '
BEGIN{ FS=",[[:space:]]*" }
{
length_limit = 100-(4+3) # line_limit - (tab_size + len("// "))
com="";
for(i=3;i<=NF;i++){com=com" "$i};
printf("\t//%s\n\t%s Error = %s\n", com, $2, $1)
for(i=3; i<=NF; i++){ com=com" "$i };
if(length(com) > length_limit) { print "\t// nolint:lll" }
printf("\t//%s\n\t%s Error = %s\n", com, $1, $2)
}' >> ${DST_ERRORS}

echo ")" >> ${DST_ERRORS}
Expand All @@ -259,7 +262,7 @@ func TestError(t *testing.T) {
} {
EOF

grep -o "ER_[A-Z0-9_]\+," ${SRC_ERRORS} | \
echo "${ERROR_CODES}" | grep -o "ER_[A-Z0-9_]\+," | \
sed "s/,$//" | \
awk '{printf("\t\t{iproto.%s, \"%s\"},\n", $1, $1)}' >> ${DST_ERRORS_TEST}

Expand Down

0 comments on commit 2bfa473

Please sign in to comment.