Add commit hook to check the visitor is in sync with the ast

Signed-off-by: Andres Taylor <andres@planetscale.com>
This commit is contained in:
Andres Taylor 2020-01-15 11:16:46 -08:00
Родитель 070347dfeb
Коммит 16300d647b
2 изменённых файлов: 27 добавлений и 1 удалений

Просмотреть файл

@ -17,6 +17,7 @@ MAKEFLAGS = -s
export GOBIN=$(PWD)/bin
export GO111MODULE=on
export GODEBUG=tls13=0
export REWRITER=go/vt/sqlparser/rewriter.go
# Disabled parallel processing of target prerequisites to avoid that integration tests are racing each other (e.g. for ports) and may fail.
# Since we are not using this Makefile for compilation, limiting parallelism will not increase build time.
@ -89,7 +90,7 @@ parser:
visitor:
go build -o visitorgen go/visitorgen/main/main.go
./visitorgen -input=go/vt/sqlparser/ast.go -output=go/vt/sqlparser/rewriter.go
./visitorgen -input=go/vt/sqlparser/ast.go -output=$(REWRITER)
rm ./visitorgen
# To pass extra flags, run test.go manually.

25
misc/git/hooks/visitorgen Executable file
Просмотреть файл

@ -0,0 +1,25 @@
#!/bin/bash
# Copyright 2019 The Vitess Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# this script, which should run before committing code, makes sure that the visitor is re-generated when the ast changes
make visitor REWRITER=tmp_rewriter.go
if ! cmp -s "tmp_rewriter.go" "go/vt/sqlparser/rewriter.go"; then
echo "The ast.go has changed, but not rewriter.go"
echo "You should 'make visitor' to update the generated rewriter"
rm -f tmp_rewriter.go
exit 1
fi
rm -f tmp_rewriter.go