Skip to content

Commit

Permalink
Merge pull request #103027 from e-mbrown/backport23.1-101930
Browse files Browse the repository at this point in the history
release-23.1: build: add missing plpgsql build rules
  • Loading branch information
chengxiong-ruan authored May 12, 2023
2 parents 30db29c + 3162b3a commit 1a908d9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
50 changes: 49 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,9 @@ SQLPARSER_TARGETS = \
pkg/sql/lexbase/tokens.go \
pkg/sql/lexbase/keywords.go \
pkg/sql/lexbase/reserved_keywords.go \
pkg/sql/plpgsql/parser/plpgsql.go \
pkg/sql/plpgsql/parser/lexbase/tokens.go \
pkg/sql/plpgsql/parser/lexbase/keywords.go \
pkg/sql/scanner/token_names_test.go

PROTOBUF_TARGETS := bin/.go_protobuf_sources bin/.gw_protobuf_sources
Expand Down Expand Up @@ -1507,6 +1510,32 @@ pkg/sql/parser/sql.go: pkg/sql/parser/gen/sql.go.tmp | bin/.bootstrap
mv -f $@.tmp $@
goimports -w $@

.SECONDARY: pkg/sql/plpgsql/parser/gen/plpgsql.go.tmp
pkg/sql/plpgsql/parser/gen/plpgsql.go.tmp: pkg/sql/plpgsql/parser/gen/plpgsql-gen.y bin/.bootstrap
set -euo pipefail; \
ret=$$(cd pkg/sql/plpgsql/parser/gen && goyacc -p plpgsql -o plpgsql.go.tmp plpgsql-gen.y); \
if expr "$$ret" : ".*conflicts" >/dev/null; then \
echo "$$ret"; exit 1; \
fi

pkg/sql/plpgsql/parser/lexbase/tokens.go: pkg/sql/plpgsql/parser/gen/plpgsql.go.tmp
(echo "// Code generated by make. DO NOT EDIT."; \
echo "// GENERATED FILE DO NOT EDIT"; \
echo; \
echo "package lexbase"; \
echo; \
grep '^const [A-Z][_A-Z0-9]* ' $^) > $@.tmp || rm $@.tmp
mv -f $@.tmp $@


pkg/sql/plpgsql/parser/plpgsql.go: pkg/sql/plpgsql/parser/gen/plpgsql.go.tmp | bin/.bootstrap
(echo "// Code generated by goyacc. DO NOT EDIT."; \
echo "// GENERATED FILE DO NOT EDIT"; \
cat $^ | \
sed -E 's/^const ([A-Z][_A-Z0-9]*) =.*$$/const \1 = lexbase.\1/g') > $@.tmp || rm $@.tmp
mv -f $@.tmp $@
goimports -w $@

# This modifies the grammar to:
# - improve the types used by the generated parser for non-terminals
# - expand the help rules.
Expand Down Expand Up @@ -1546,6 +1575,25 @@ pkg/sql/lexbase/keywords.go: pkg/sql/parser/sql.y pkg/sql/lexbase/allkeywords/ma
mv -f $@.tmp $@
gofmt -s -w $@

.SECONDARY: pkg/sql/plpgsql/parser/gen/plpgsql-gen.y
pkg/sql/plpgsql/parser/gen/plpgsql-gen.y: pkg/sql/plpgsql/parser/plpgsql.y
mkdir -p pkg/sql/plpgsql/parser/gen
set -euo pipefail; \
awk '/func.*plpgsqlSymUnion/ {print $$(NF - 1)}' pkg/sql/plpgsql/parser/plpgsql.y | \
sed -e 's/[]\/$$*.^|[]/\\&/g' | \
sed -e "s/^/s_(type|token) <(/" | \
awk '{print $$0")>_\\1 <union> /* <\\2> */_"}' > pkg/sql/plpgsql/parser/gen/types_regex.tmp; \
sed -E -f pkg/sql/plpgsql/parser/gen/types_regex.tmp < pkg/sql/plpgsql/parser/plpgsql.y | \
sed -Ee 's,//.*$$,,g;s,/[*]([^*]|[*][^/])*[*]/, ,g;s/ +$$//g' > $@.tmp || rm $@.tmp
mv -f $@.tmp $@
rm pkg/sql/plpgsql/parser/gen/types_regex.tmp

pkg/sql/plpgsql/parser/lexbase/keywords.go: pkg/sql/plpgsql/parser/plpgsql.y pkg/sql/lexbase/allkeywords/main.go | bin/.bootstrap
$(GO) run -tags all-keywords pkg/sql/lexbase/allkeywords/main.go < $< > $@.tmp || rm $@.tmp
mv -f $@.tmp $@
gofmt -s -w $@


# This target will print unreserved_keywords which are not actually
# used in the grammar.
.PHONY: sqlparser-unused-unreserved-keywords
Expand Down Expand Up @@ -1720,7 +1768,7 @@ cleanshort:
-$(GO) clean $(GOFLAGS) -tags '$(TAGS)' -ldflags '$(LINKFLAGS)' -i github.com/cockroachdb/cockroach...
$(FIND_RELEVANT) -type f -name '*.test' -exec rm {} +
for f in cockroach*; do if [ -f "$$f" ]; then rm "$$f"; fi; done
rm -rf pkg/sql/parser/gen
rm -rf pkg/sql/parser/gen pkg/sql/plpgsql/parser/gen

.PHONY: clean
clean: ## Like cleanshort, but also includes C++ artifacts, Bazel artifacts, and the go build cache.
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/plpgsql/parser/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
# for reasoning and alternatives).

plpgsql.go
y.output
gen
2 changes: 2 additions & 0 deletions pkg/sql/plpgsql/parser/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ go_library(
"//pkg/sql/parser/statements",
"//pkg/sql/pgwire/pgcode",
"//pkg/sql/pgwire/pgerror",
"//pkg/sql/plpgsql/parser/lexbase", # keep
"//pkg/sql/scanner",
"//pkg/sql/sem/plpgsqltree",
"//pkg/sql/sem/tree",
"//pkg/sql/types",
"@com_github_cockroachdb_errors//:errors",
"@com_github_cockroachdb_redact//:redact", # keep
],
)

Expand Down
5 changes: 4 additions & 1 deletion pkg/sql/plpgsql/parser/plpgsql.y
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ package parser
import (
"fmt"

"github.com/cockroachdb/cockroach/pkg/sql/plpgsql/parser/lexbase"
"github.com/cockroachdb/cockroach/pkg/sql/scanner"
"github.com/cockroachdb/cockroach/pkg/sql/sem/plpgsqltree"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/redact"
)
%}

Expand Down Expand Up @@ -688,7 +690,8 @@ getdiag_item: unreserved_keyword {
case "returned_sqlstate":
$$.val = plpgsqltree.PlpgsqlGetdiagReturnedSqlstate;
default:
setErr(plpgsqllex, errors.New("unrecognized GET DIAGNOSTICS item " + $1 ))
// TODO(jane): Should this use an unimplemented error instead?
setErr(plpgsqllex, errors.Newf("unrecognized GET DIAGNOSTICS item: %s", redact.Safe($1)))
}
}
;
Expand Down

0 comments on commit 1a908d9

Please sign in to comment.