From c41f0a8ea8024ae51d975b0c4adcf8028e85b143 Mon Sep 17 00:00:00 2001 From: Dirkjan Bussink Date: Tue, 25 Jun 2024 08:44:35 +0200 Subject: [PATCH] Fix codegen (#16257) Signed-off-by: Dirkjan Bussink Signed-off-by: Florent Poinsard Co-authored-by: Florent Poinsard --- .github/workflows/static_checks_etc.yml | 15 +++++++++++++++ go/vt/sqlparser/ast_format_fast.go | 6 ++++-- tools/check_astfmtgen.sh | 21 +++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100755 tools/check_astfmtgen.sh diff --git a/.github/workflows/static_checks_etc.yml b/.github/workflows/static_checks_etc.yml index 65e29b67ba6..7c09697fec2 100644 --- a/.github/workflows/static_checks_etc.yml +++ b/.github/workflows/static_checks_etc.yml @@ -91,6 +91,16 @@ jobs: - 'bootstrap.sh' - 'misc/git/hooks/asthelpers' - '.github/workflows/static_checks_etc.yml' + astfmt: + - 'go/tools/astfmtgen/**' + - 'go/vt/sqlparser/**' + - 'Makefile' + - 'build.env' + - 'go.sum' + - 'go.mod' + - 'tools/**' + - 'bootstrap.sh' + - '.github/workflows/static_checks_etc.yml' end_to_end: - 'docker/**' - 'test.go' @@ -168,6 +178,11 @@ jobs: if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.visitor == 'true' || steps.changes.outputs.go_files == 'true') run: | misc/git/hooks/asthelpers || exit 1 + + - name: check_ast_format_fast + if: steps.skip-workflow.outputs.skip-workflow == 'false' && (steps.changes.outputs.astfmt == 'true' || steps.changes.outputs.go_files == 'true') + run: | + ./tools/check_astfmtgen.sh || exit 1 - name: run ensure_bootstrap_version if: steps.skip-workflow.outputs.skip-workflow == 'false' && steps.changes.outputs.end_to_end == 'true' diff --git a/go/vt/sqlparser/ast_format_fast.go b/go/vt/sqlparser/ast_format_fast.go index 4be0bfd75f7..46458329938 100644 --- a/go/vt/sqlparser/ast_format_fast.go +++ b/go/vt/sqlparser/ast_format_fast.go @@ -1132,8 +1132,10 @@ func (idx *IndexDefinition) FormatFast(buf *TrackedBuffer) { buf.WriteByte(')') for _, opt := range idx.Options { - buf.WriteByte(' ') - buf.WriteString(opt.Name) + if opt.Name != "" { + buf.WriteByte(' ') + buf.WriteString(opt.Name) + } if opt.String != "" { buf.WriteByte(' ') buf.WriteString(opt.String) diff --git a/tools/check_astfmtgen.sh b/tools/check_astfmtgen.sh new file mode 100755 index 00000000000..caddeb61808 --- /dev/null +++ b/tools/check_astfmtgen.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# +# Validate that the current version of ast_format_fast matches what gets generated. +# + +source build.env + +first_output=$(git status --porcelain) + +go run ./go/tools/astfmtgen vitess.io/vitess/go/vt/sqlparser/... + +second_output=$(git status --porcelain) + +diff=$(diff <( echo "$first_output") <( echo "$second_output")) + +if [[ "$diff" != "" ]]; then + echo "ERROR: Regenerated ast_format_fast file do not match the current version." + echo -e "File containing differences:\n$diff" + exit 1 +fi