From 5b17a1fea41422ab0966767c28d4fa03b04bde4c Mon Sep 17 00:00:00 2001 From: Ricky Stewart Date: Wed, 17 Feb 2021 16:44:10 -0600 Subject: [PATCH] Bring `bazel generate` up-to-date with `make bazel-generate` at HEAD --- generate.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/generate.go b/generate.go index 6d4531a..b755505 100644 --- a/generate.go +++ b/generate.go @@ -12,6 +12,11 @@ package main import ( "context" + "fmt" + "io/ioutil" + "os" + "os/exec" + "path" "github.com/cockroachdb/errors" "github.com/spf13/cobra" @@ -73,5 +78,19 @@ func runGenerate(cmd *cobra.Command, targets []string) error { } func generateBazel(ctx context.Context, cmd *cobra.Command) error { - return execute(ctx, "bazel", "run", "@cockroach//:gazelle", "--color=yes") + if err := execute(ctx, "bazel", "run", "//:gazelle", "--", "update-repos", "-from_file=go.mod", "-build_file_proto_mode=disable_global", "-to_macro=DEPS.bzl%go_deps", "-prune=true"); err != nil { + return err + } + cwd, err := os.Getwd() + if err != nil { + return err + } + buf, err := exec.Command("bazel", "run", "//pkg/cmd/generate-test-suites", "--run_under", fmt.Sprintf("cd %s &&", cwd)).Output() + if err != nil { + return err + } + if err := ioutil.WriteFile(path.Join(cwd, "pkg/BUILD.bazel"), buf, 0644); err != nil { + return err + } + return execute(ctx, "bazel", "run", "//:gazelle") }