From b47e67365784bd6d9c473c8b1952f3c35a430aca Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Thu, 7 Jul 2022 11:22:47 -0400 Subject: [PATCH] dev,genbzl: add more dev generate subcommands This adds a dev generate subcommand for optgen, execgen, and schemachanger. Release note: None --- dev | 2 +- pkg/cmd/dev/generate.go | 44 +++++++++++++++++++++++++-------------- pkg/gen/BUILD.bazel | 17 ++++++++++++++- pkg/gen/gen.bzl | 7 +++++++ pkg/gen/genbzl/targets.go | 24 ++++++++++++++------- pkg/gen/misc.bzl | 5 ----- pkg/gen/schemachanger.bzl | 18 ++++++++++++++++ 7 files changed, 86 insertions(+), 31 deletions(-) create mode 100644 pkg/gen/schemachanger.bzl diff --git a/dev b/dev index 796d134d2972..a2cfb1e18b01 100755 --- a/dev +++ b/dev @@ -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 diff --git a/pkg/cmd/dev/generate.go b/pkg/cmd/dev/generate.go index baff06353719..0462dd8970de 100644 --- a/pkg/cmd/dev/generate.go +++ b/pkg/cmd/dev/generate.go @@ -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 @@ -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 { @@ -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, diff --git a/pkg/gen/BUILD.bazel b/pkg/gen/BUILD.bazel index 89bca6d13f7b..de9b72777c75 100644 --- a/pkg/gen/BUILD.bazel +++ b/pkg/gen/BUILD.bazel @@ -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() @@ -18,6 +31,8 @@ docs() parser() +schemachanger() + gen( name = "gen", srcs = [ diff --git a/pkg/gen/gen.bzl b/pkg/gen/gen.bzl index 0d8ba099f4d5..367991521389 100644 --- a/pkg/gen/gen.bzl +++ b/pkg/gen/gen.bzl @@ -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 @@ -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"]) diff --git a/pkg/gen/genbzl/targets.go b/pkg/gen/genbzl/targets.go index 633f87b8ec57..563dc522d8b5 100644 --- a/pkg/gen/genbzl/targets.go +++ b/pkg/gen/genbzl/targets.go @@ -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: ` @@ -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" $ }}) )`, }, } diff --git a/pkg/gen/misc.bzl b/pkg/gen/misc.bzl index ae2a5db7f7b6..f66f084957b2 100644 --- a/pkg/gen/misc.bzl +++ b/pkg/gen/misc.bzl @@ -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", diff --git a/pkg/gen/schemachanger.bzl b/pkg/gen/schemachanger.bzl new file mode 100644 index 000000000000..ea0f127885d3 --- /dev/null +++ b/pkg/gen/schemachanger.bzl @@ -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", +]