Skip to content

Commit 2bfa473

Browse files
committed
api: update generator with tarantool 3.2.0
Fix parsing box/errcode.h constants. Closes #6
1 parent ca3626f commit 2bfa473

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

generate.sh

+18-15
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ if [[ -z "${TT_REPO}" ]]; then
1111
TT_REPO="https://github.com/tarantool/tarantool.git"
1212
fi
1313

14-
TT_DIR=tarantool
14+
TT_DIR=tarantool-$TT_TAG
1515

1616
# Cleanup.
1717
rm -rf ${TT_DIR}
1818

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

236-
grep "(ER_" ${SRC_ERRORS} | \
237-
# Remove comments symbols.
238-
sed "s/\/\*//" | \
239-
sed "s/\*\/_(//" | \
240-
# Remove and of values.
241-
sed "s/) *\\\//" | \
242-
# Remove comma at an end of a value.
243-
sed "s/,/ /" | \
244-
# Finally print parsed values in Golang format.
245-
awk '{
236+
# Extract body of define ERROR_CODES
237+
ERROR_CODES=`sed -n '/^#define ERROR_CODES(/,/This one should be last/{//!p;}' ${SRC_ERRORS}`
238+
239+
echo "${ERROR_CODES}" | \
240+
# Get line with ER_* description
241+
sed -nE 's/^[^E]*(ER_.+)\s*\\\s*$/\1/p' | \
242+
# Remove trailing parenthesis or comment's ending
243+
sed -E 's/(.*)\s*(:?\)|\*\/)\s*$/\1/' | \
244+
awk '
245+
BEGIN{ FS=",[[:space:]]*" }
246+
{
247+
length_limit = 100-(4+3) # line_limit - (tab_size + len("// "))
246248
com="";
247-
for(i=3;i<=NF;i++){com=com" "$i};
248-
printf("\t//%s\n\t%s Error = %s\n", com, $2, $1)
249+
for(i=3; i<=NF; i++){ com=com" "$i };
250+
if(length(com) > length_limit) { print "\t// nolint:lll" }
251+
printf("\t//%s\n\t%s Error = %s\n", com, $1, $2)
249252
}' >> ${DST_ERRORS}
250253

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

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

0 commit comments

Comments
 (0)