Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/dev: add generate parser subcommand #83727

Merged
merged 1 commit into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions pkg/cmd/dev/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion pkg/gen/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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()

Expand All @@ -16,6 +16,8 @@ misc()

docs()

parser()

gen(
name = "gen",
srcs = [
Expand All @@ -33,6 +35,7 @@ gen(
":gomock",
":misc",
":optgen",
":parser",
":stringer",
],
)
7 changes: 7 additions & 0 deletions pkg/gen/gen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"])
5 changes: 5 additions & 0 deletions pkg/gen/genbzl/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: `
Expand Down Expand Up @@ -88,6 +92,7 @@ kind("generated file", {{ .All }}) - (
+ {{ template "optgen" $ }}
+ {{ template "docs" $ }}
+ {{ template "excluded" $ }}
+ {{ template "parser" $ }}
)`,
},
}
Expand Down
8 changes: 0 additions & 8 deletions pkg/gen/misc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions pkg/gen/parser.bzl
Original file line number Diff line number Diff line change
@@ -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",
]