Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
84005: dev,genbzl: add more dev generate subcommands r=ajwerner a=ajwerner

This adds a dev generate subcommand for optgen, execgen, and schemachanger.

Release note: None

Co-authored-by: Andrew Werner <[email protected]>
  • Loading branch information
craig[bot] and ajwerner committed Jul 8, 2022
2 parents 88789fe + b47e673 commit cd1abbb
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 31 deletions.
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=40
DEV_VERSION=41

THIS_DIR=$(cd "$(dirname "$0")" && pwd)
BINARY_DIR=$THIS_DIR/bin/dev-versions
Expand Down
44 changes: 28 additions & 16 deletions pkg/cmd/dev/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ func makeGenerateCmd(runE func(cmd *cobra.Command, args []string) error) *cobra.
Long: `Generate the specified files.`,
Example: `
dev generate
dev generate bazel # DEPS.bzl and BUILD.bazel files
dev generate cgo # files that help non-Bazel systems (IDEs, go) link to our C dependencies
dev generate docs # generates documentation
dev generate execgen # generates execgen go code (subset of 'dev generate go')
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')
dev generate bazel # DEPS.bzl and BUILD.bazel files
dev generate cgo # files that help non-Bazel systems (IDEs, go) link to our C dependencies
dev generate docs # generates documentation
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')
dev generate optgen # optgen targets (subset of 'dev generate go')
dev generate execgen # execgen targets (subset of 'dev generate go')
dev generate schemachanger # schemachanger targets (subset of 'dev generate go')
`,
Args: cobra.MinimumNArgs(0),
// TODO(irfansharif): Errors but default just eaten up. Let's wrap these
Expand All @@ -61,14 +63,16 @@ type configuration struct {

func (d *dev) generate(cmd *cobra.Command, targets []string) error {
var generatorTargetMapping = map[string]func(cmd *cobra.Command) error{
"bazel": d.generateBazel,
"cgo": d.generateCgo,
"docs": d.generateDocs,
"execgen": d.generateExecgen,
"go": d.generateGo,
"go_nocgo": d.generateGoNoCgo,
"protobuf": d.generateProtobuf,
"parser": d.generateParser,
"bazel": d.generateBazel,
"cgo": d.generateCgo,
"docs": d.generateDocs,
"execgen": d.generateExecgen,
"go": d.generateGo,
"go_nocgo": d.generateGoNoCgo,
"protobuf": d.generateProtobuf,
"parser": d.generateParser,
"optgen": d.generateOptGen,
"schemachanger": d.generateSchemaChanger,
}

if len(targets) == 0 {
Expand Down Expand Up @@ -187,6 +191,14 @@ func (d *dev) generateParser(cmd *cobra.Command) error {
return d.generateTarget(cmd.Context(), "//pkg/gen:parser")
}

func (d *dev) generateOptGen(cmd *cobra.Command) error {
return d.generateTarget(cmd.Context(), "//pkg/gen:optgen")
}

func (d *dev) generateSchemaChanger(cmd *cobra.Command) error {
return d.generateTarget(cmd.Context(), "//pkg/gen:schemachanger")
}

func (d *dev) generateTarget(ctx context.Context, target string) error {
if err := d.exec.CommandContextInheritingStdStreams(
ctx, "bazel", "run", target,
Expand Down
17 changes: 16 additions & 1 deletion pkg/gen/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
load(":gen.bzl", "bindata", "docs", "execgen", "gen", "go_proto", "gomock", "misc", "optgen", "parser", "stringer")
load(
":gen.bzl",
"bindata",
"docs",
"execgen",
"gen",
"go_proto",
"gomock",
"misc",
"optgen",
"parser",
"schemachanger",
"stringer",
)

bindata()

Expand All @@ -18,6 +31,8 @@ docs()

parser()

schemachanger()

gen(
name = "gen",
srcs = [
Expand Down
7 changes: 7 additions & 0 deletions pkg/gen/gen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ load(":optgen.bzl", "OPTGEN_SRCS")
load(":protobuf.bzl", "PROTOBUF_SRCS")
load(":stringer.bzl", "STRINGER_SRCS")
load(":parser.bzl", "PARSER_SRCS")
load(":schemachanger.bzl", "SCHEMACHANGER_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 @@ -288,5 +289,11 @@ def parser():
srcs = PARSER_SRCS,
)

def schemachanger():
_hoist_no_prefix(
name = "schemachanger",
srcs = SCHEMACHANGER_SRCS,
)

def gen(name, srcs):
_hoist_files(name = name, data = srcs, tags = ["no-remote-exec"])
24 changes: 16 additions & 8 deletions pkg/gen/genbzl/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ kind("generated file", //docs/...:*)
target: "parser",
query: `labels("outs", kind("genrule rule", //pkg/sql/sem/... + //pkg/sql/parser/... + //pkg/sql/lexbase/...))`,
},
{
target: "schemachanger",
query: `
kind("generated file", //pkg/sql/schemachanger/...:*)
- labels("out", kind("_gomock_prog_gen rule", //pkg/sql/schemachanger/...:*))
`,
},
{
target: "excluded",
query: `
Expand All @@ -85,14 +92,15 @@ kind("bindata", {{ .All }})`,
target: "misc",
query: `
kind("generated file", {{ .All }}) - (
{{ template "protobuf" $ }}
+ {{ template "gomock" $ }}
+ {{ template "stringer" $ }}
+ {{ template "execgen" $ }}
+ {{ template "optgen" $ }}
+ {{ template "docs" $ }}
+ {{ template "excluded" $ }}
+ {{ template "parser" $ }}
({{ template "protobuf" $ }})
+ ({{ template "gomock" $ }})
+ ({{ template "stringer" $ }})
+ ({{ template "execgen" $ }})
+ ({{ template "optgen" $ }})
+ ({{ template "docs" $ }})
+ ({{ template "excluded" $ }})
+ ({{ template "parser" $ }})
+ ({{ template "schemachanger" $ }})
)`,
},
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/gen/misc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ 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/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:txnstatetransitions_diagram.gv",
"//pkg/sql:txnstatetransitions_report.txt",
"//pkg/util/interval/generic:example_interval_btree.go",
Expand Down
18 changes: 18 additions & 0 deletions pkg/gen/schemachanger.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by genbzl

SCHEMACHANGER_SRCS = [
"//pkg/sql/schemachanger/rel/internal/comparetest:testattr_string.go",
"//pkg/sql/schemachanger/rel/internal/cyclegraphtest:testattr_string.go",
"//pkg/sql/schemachanger/rel/internal/entitynodetest:testattr_string.go",
"//pkg/sql/schemachanger/rel:systemattribute_string.go",
"//pkg/sql/schemachanger/scexec:mocks_generated_test.go",
"//pkg/sql/schemachanger/scop:backfill_visitor_generated.go",
"//pkg/sql/schemachanger/scop:mutation_visitor_generated.go",
"//pkg/sql/schemachanger/scop:phase_string.go",
"//pkg/sql/schemachanger/scop:type_string.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/schemachanger/scplan/internal/scgraph:depedgekind_string.go",
"//pkg/sql/schemachanger/screl:attr_string.go",
]

0 comments on commit cd1abbb

Please sign in to comment.