From 5d31dd36f2c61f7f57332ad3be901ed56d396b9b Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Fri, 1 Jul 2022 15:55:47 -0400 Subject: [PATCH] cmd/dev: add generate parser subcommand This commit separates out the generated files needed for the parser into a separate genbzl target and then add a reference to that target from dev. You can now run `./dev generate parser` to regenerate the parser files. Release note: None --- dev | 2 +- pkg/cmd/dev/generate.go | 6 ++++++ pkg/gen/BUILD.bazel | 5 ++++- pkg/gen/gen.bzl | 7 +++++++ pkg/gen/genbzl/targets.go | 5 +++++ pkg/gen/misc.bzl | 8 -------- pkg/gen/parser.bzl | 15 +++++++++++++++ 7 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 pkg/gen/parser.bzl diff --git a/dev b/dev index e1f378eb93b7..b6161ef7bf6f 100755 --- a/dev +++ b/dev @@ -3,7 +3,7 @@ set -euo pipefail # Bump this counter to force rebuilding `dev` on all machines. -DEV_VERSION=38 +DEV_VERSION=39 THIS_DIR=$(cd "$(dirname "$0")" && pwd) BINARY_DIR=$THIS_DIR/bin/dev-versions diff --git a/pkg/cmd/dev/generate.go b/pkg/cmd/dev/generate.go index de07ef590747..c06018148a92 100644 --- a/pkg/cmd/dev/generate.go +++ b/pkg/cmd/dev/generate.go @@ -40,6 +40,7 @@ func makeGenerateCmd(runE func(cmd *cobra.Command, args []string) error) *cobra. dev generate go # generates go code (execgen, stringer, protobufs, etc.), plus everything 'cgo' generates dev generate go_nocgo # generates go code (execgen, stringer, protobufs, etc.) dev generate protobuf # *.pb.go files (subset of 'dev generate go') + dev generate parser # sql.go and parser dependencies (subset of 'dev generate go') `, Args: cobra.MinimumNArgs(0), // TODO(irfansharif): Errors but default just eaten up. Let's wrap these @@ -65,6 +66,7 @@ func (d *dev) generate(cmd *cobra.Command, targets []string) error { "go": d.generateGo, "go_nocgo": d.generateGoNoCgo, "protobuf": d.generateProtobuf, + "parser": d.generateParser, } if len(targets) == 0 { @@ -175,6 +177,10 @@ func (d *dev) generateProtobuf(cmd *cobra.Command) error { return d.generateTarget(cmd.Context(), "//pkg/gen:go_proto") } +func (d *dev) generateParser(cmd *cobra.Command) error { + return d.generateTarget(cmd.Context(), "//pkg/gen:parser") +} + func (d *dev) generateTarget(ctx context.Context, target string) error { if err := d.exec.CommandContextInheritingStdStreams( ctx, "bazel", "run", target, diff --git a/pkg/gen/BUILD.bazel b/pkg/gen/BUILD.bazel index 5d0b1e6c78df..89bca6d13f7b 100644 --- a/pkg/gen/BUILD.bazel +++ b/pkg/gen/BUILD.bazel @@ -1,4 +1,4 @@ -load(":gen.bzl", "bindata", "docs", "execgen", "gen", "go_proto", "gomock", "misc", "optgen", "stringer") +load(":gen.bzl", "bindata", "docs", "execgen", "gen", "go_proto", "gomock", "misc", "optgen", "parser", "stringer") bindata() @@ -16,6 +16,8 @@ misc() docs() +parser() + gen( name = "gen", srcs = [ @@ -33,6 +35,7 @@ gen( ":gomock", ":misc", ":optgen", + ":parser", ":stringer", ], ) diff --git a/pkg/gen/gen.bzl b/pkg/gen/gen.bzl index 66e3f0708ca1..0d8ba099f4d5 100644 --- a/pkg/gen/gen.bzl +++ b/pkg/gen/gen.bzl @@ -27,6 +27,7 @@ load(":misc.bzl", "MISC_SRCS") load(":optgen.bzl", "OPTGEN_SRCS") load(":protobuf.bzl", "PROTOBUF_SRCS") load(":stringer.bzl", "STRINGER_SRCS") +load(":parser.bzl", "PARSER_SRCS") # GeneratedFileInfo provides two pieces of information to the _hoist_files # rule. It provides the set of files to be hoisted via the generated_files @@ -281,5 +282,11 @@ def bindata(): srcs = BINDATA_SRCS, ) +def parser(): + _hoist_no_prefix( + name = "parser", + srcs = PARSER_SRCS, + ) + def gen(name, srcs): _hoist_files(name = name, data = srcs, tags = ["no-remote-exec"]) diff --git a/pkg/gen/genbzl/targets.go b/pkg/gen/genbzl/targets.go index 333be17f5797..633f87b8ec57 100644 --- a/pkg/gen/genbzl/targets.go +++ b/pkg/gen/genbzl/targets.go @@ -59,6 +59,10 @@ in $og - filter(".*:.*(-gen|gen-).*", $og)`, kind("generated file", //docs/...:*) - labels("outs", //docs/generated/sql/bnf:svg)`, }, + { + target: "parser", + query: `labels("outs", kind("genrule rule", //pkg/sql/sem/... + //pkg/sql/parser/... + //pkg/sql/lexbase/...))`, + }, { target: "excluded", query: ` @@ -88,6 +92,7 @@ kind("generated file", {{ .All }}) - ( + {{ template "optgen" $ }} + {{ template "docs" $ }} + {{ template "excluded" $ }} + + {{ template "parser" $ }} )`, }, } diff --git a/pkg/gen/misc.bzl b/pkg/gen/misc.bzl index bf05b5130dd7..ae2a5db7f7b6 100644 --- a/pkg/gen/misc.bzl +++ b/pkg/gen/misc.bzl @@ -9,19 +9,11 @@ MISC_SRCS = [ "//pkg/roachprod/vm/aws:terraform/main.tf", "//pkg/spanconfig/spanconfigstore:entry_interval_btree.go", "//pkg/spanconfig/spanconfigstore:entry_interval_btree_test.go", - "//pkg/sql/lexbase:keywords.go", - "//pkg/sql/lexbase:reserved_keywords.go", - "//pkg/sql/lexbase:tokens.go", - "//pkg/sql/parser:help_messages.go", - "//pkg/sql/parser:helpmap_test.go", - "//pkg/sql/parser:sql.go", "//pkg/sql/schemachanger/scop:backfill_visitor_generated.go", "//pkg/sql/schemachanger/scop:mutation_visitor_generated.go", "//pkg/sql/schemachanger/scop:validation_visitor_generated.go", "//pkg/sql/schemachanger/scpb:elements_generated.go", "//pkg/sql/schemachanger/scpb:uml/table.puml", - "//pkg/sql/sem/tree:eval_expr_generated.go", - "//pkg/sql/sem/tree:eval_op_generated.go", "//pkg/sql:txnstatetransitions_diagram.gv", "//pkg/sql:txnstatetransitions_report.txt", "//pkg/util/interval/generic:example_interval_btree.go", diff --git a/pkg/gen/parser.bzl b/pkg/gen/parser.bzl new file mode 100644 index 000000000000..dbccd43ece8c --- /dev/null +++ b/pkg/gen/parser.bzl @@ -0,0 +1,15 @@ +# Generated by genbzl + +PARSER_SRCS = [ + "//pkg/sql/lexbase:keywords.go", + "//pkg/sql/lexbase:reserved_keywords.go", + "//pkg/sql/lexbase:tokens.go", + "//pkg/sql/parser:help_messages.go", + "//pkg/sql/parser:helpmap_test.go", + "//pkg/sql/parser:sql.go", + "//pkg/sql/sem/tree:createtypevariety_string.go", + "//pkg/sql/sem/tree:eval_expr_generated.go", + "//pkg/sql/sem/tree:eval_op_generated.go", + "//pkg/sql/sem/tree:statementreturntype_string.go", + "//pkg/sql/sem/tree:statementtype_string.go", +]