Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ac05233

Browse files
committedOct 10, 2024
api: update generator with tarantool 3.2.0
Fix parsing box/errcode.h constants. Closes #6
1 parent 402077f commit ac05233

File tree

2 files changed

+32
-26
lines changed

2 files changed

+32
-26
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release.
1111
### Added
1212

1313
### Changed
14+
- Update parsing enum macro of `errcode.h` from Tarantool 3.2.0 (#6)
1415

1516
### Fixed
1617

‎generate.sh

+31-26
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 ..
@@ -227,25 +227,30 @@ EOF
227227
echo "${FOOTER}" > ${DST_ERRORS}
228228
cat << EOF >> ${DST_ERRORS}
229229
// IPROTO error code constants, generated from
230-
// ${SRC_ERRORS}
230+
// ${SRC_ERRORS//-${TT_TAG}/}
231231
type Error int
232232
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 '{
246-
com="";
247-
for(i=3;i<=NF;i++){com=com" "$i};
248-
printf("\t//%s\n\t%s Error = %s\n", com, $2, $1)
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+
# Extract three fields: name, id and first comment string.
245+
# Match string based on https://regex101.com/library/zI0yV6
246+
sed -E 's/^([^"]+)("([^"]|\\")*[^\\]"|"").*$/\1\2/' | \
247+
# Format three fields comma separated for Go lang const declaration.
248+
awk '
249+
BEGIN{ FS=",[[:space:]]*" }
250+
{
251+
com=$3;
252+
for(i=4;i<=NF;i++){com=com", "$i};
253+
printf("\t// %s\n\t%s Error = %s\n", com, $1, $2)
249254
}' >> ${DST_ERRORS}
250255

251256
echo ")" >> ${DST_ERRORS}
@@ -259,7 +264,7 @@ func TestError(t *testing.T) {
259264
} {
260265
EOF
261266

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

@@ -286,7 +291,7 @@ EOF
286291
echo "${FOOTER}" > ${DST_FEATURES}
287292
cat << EOF >> ${DST_FEATURES}
288293
// IPROTO feature constants, generated from
289-
// ${SRC_FEATURES}
294+
// ${SRC_FEATURES//-${TT_TAG}/}
290295
EOF
291296

292297
read_define_with_prefix IPROTO_FEATURES iproto_feature_id ${SRC_FEATURES} | \
@@ -304,7 +309,7 @@ read_define_with_prefix IPROTO_FEATURES iproto_feature_id ${SRC_FEATURES} | \
304309
echo "${FOOTER}" > ${DST_FLAGS}
305310
cat << EOF >> ${DST_FLAGS}
306311
// IPROTO flag constants, generated from
307-
// ${SRC_CONST}
312+
// ${SRC_CONST//-${TT_TAG}/}
308313
EOF
309314

310315
read_define_with_prefix IPROTO_FLAGS iproto_flag ${SRC_CONST} | \
@@ -322,7 +327,7 @@ read_define_with_prefix IPROTO_FLAGS iproto_flag ${SRC_CONST} | \
322327
echo "${FOOTER}" > ${DST_ITERATORS}
323328
cat << EOF >> ${DST_ITERATORS}
324329
// IPROTO iterators constants, generated from
325-
// ${SRC_ITERATORS}
330+
// ${SRC_ITERATORS//-${TT_TAG}/}
326331
EOF
327332

328333
read_enum iterator_type ${SRC_ITERATORS} | \
@@ -340,7 +345,7 @@ read_enum iterator_type ${SRC_ITERATORS} | \
340345
echo "${FOOTER}" > ${DST_TYPES}
341346
cat << EOF >> ${DST_TYPES}
342347
// IPROTO type constants, generated from
343-
// ${SRC_CONST}
348+
// ${SRC_CONST//-${TT_TAG}/}
344349
EOF
345350

346351
read_define_with_prefix IPROTO_TYPES iproto_type ${SRC_CONST} | \
@@ -358,7 +363,7 @@ read_define_with_prefix IPROTO_TYPES iproto_type ${SRC_CONST} | \
358363
echo "${FOOTER}" > ${DST_KEYS}
359364
cat << EOF >> ${DST_KEYS}
360365
// IPROTO key constants, generated from
361-
// ${SRC_CONST}
366+
// ${SRC_CONST//-${TT_TAG}/}
362367
EOF
363368

364369
read_define_with_prefix IPROTO_KEYS iproto_key ${SRC_CONST} | \
@@ -367,7 +372,7 @@ read_define_with_prefix IPROTO_KEYS iproto_key ${SRC_CONST} | \
367372
cat << EOF >> ${DST_KEYS}
368373
369374
// IPROTO metadata key constants, generated from
370-
// ${SRC_CONST}
375+
// ${SRC_CONST//-${TT_TAG}/}
371376
EOF
372377

373378
read_define_with_prefix IPROTO_METADATA_KEYS iproto_metadata_key ${SRC_CONST} | \
@@ -376,7 +381,7 @@ read_define_with_prefix IPROTO_METADATA_KEYS iproto_metadata_key ${SRC_CONST} |
376381
cat << EOF >> ${DST_KEYS}
377382
378383
// IPROTO ballot key constants, generated from
379-
// ${SRC_CONST}
384+
// ${SRC_CONST//-${TT_TAG}/}
380385
EOF
381386

382387
read_define_with_prefix IPROTO_BALLOT_KEYS iproto_ballot_key ${SRC_CONST} | \
@@ -385,7 +390,7 @@ read_define_with_prefix IPROTO_BALLOT_KEYS iproto_ballot_key ${SRC_CONST} | \
385390
cat << EOF >> ${DST_KEYS}
386391
387392
// IPROTO raft key constants, generated from
388-
// ${SRC_CONST}
393+
// ${SRC_CONST//-${TT_TAG}/}
389394
EOF
390395

391396
read_define_with_prefix IPROTO_RAFT_KEYS iproto_raft_key ${SRC_CONST} | \
@@ -394,7 +399,7 @@ read_define_with_prefix IPROTO_RAFT_KEYS iproto_raft_key ${SRC_CONST} | \
394399
cat << EOF >> ${DST_KEYS}
395400
396401
// IPROTO SQL info key constants, generated from
397-
// ${SRC_EXECUTE}
402+
// ${SRC_EXECUTE//-${TT_TAG}/}
398403
EOF
399404

400405
read_enum sql_info_key ${SRC_EXECUTE} | \

0 commit comments

Comments
 (0)
Please sign in to comment.