diff --git a/Makefile b/Makefile index 780d120fdf19..dd33d57404b6 100644 --- a/Makefile +++ b/Makefile @@ -1690,6 +1690,7 @@ bins = \ bin/github-pull-request-make \ bin/gossipsim \ bin/langgen \ + bin/dev \ bin/protoc-gen-gogoroach \ bin/publish-artifacts \ bin/publish-provisional-artifacts \ diff --git a/pkg/cmd/dev/BUILD.bazel b/pkg/cmd/dev/BUILD.bazel new file mode 100644 index 000000000000..dd6463deded9 --- /dev/null +++ b/pkg/cmd/dev/BUILD.bazel @@ -0,0 +1,25 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") + +go_library( + name = "dev_lib", + srcs = [ + "bench.go", + "build.go", + "generate.go", + "lint.go", + "main.go", + "test.go", + ], + importpath = "github.com/cockroachdb/cockroach/pkg/cmd/dev", + visibility = ["//visibility:private"], + deps = [ + "@com_github_cockroachdb_errors//:errors", + "@com_github_spf13_cobra//:cobra", + ], +) + +go_binary( + name = "dev", + embed = [":dev_lib"], + visibility = ["//visibility:public"], +) diff --git a/pkg/cmd/dev/bench.go b/pkg/cmd/dev/bench.go new file mode 100644 index 000000000000..a0107109e558 --- /dev/null +++ b/pkg/cmd/dev/bench.go @@ -0,0 +1,32 @@ +// Copyright 2020 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package main + +import ( + "github.com/cockroachdb/errors" + "github.com/spf13/cobra" +) + +// benchCmd runs the specified cockroachdb benchmarks. +var benchCmd = &cobra.Command{ + Use: "bench", + Short: `Run the specified benchmarks`, + Long: `Run the specified benchmarks.`, + Example: ` + dev bench --pkg=sql/parser --filter=BenchmarkParse`, + Args: cobra.NoArgs, + RunE: runBench, +} + +func runBench(cmd *cobra.Command, args []string) error { + // TODO(irfansharif): Flesh out the example usage patterns. + return errors.New("unimplemented") +} diff --git a/pkg/cmd/dev/build.go b/pkg/cmd/dev/build.go new file mode 100644 index 000000000000..871ffdbbb0b9 --- /dev/null +++ b/pkg/cmd/dev/build.go @@ -0,0 +1,34 @@ +// Copyright 2020 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package main + +import ( + "github.com/cockroachdb/errors" + "github.com/spf13/cobra" +) + +// buildCmd builds the specified binaries. +var buildCmd = &cobra.Command{ + Use: "build", + Short: "Build the specified binaries", + Long: "Build the specified binaries.", + Example: ` + dev build cockroach --tags=deadlock + dev build cockroach-{short,oss} + dev build {opt,exec}gen`, + Args: cobra.NoArgs, + RunE: runBuild, +} + +func runBuild(cmd *cobra.Command, args []string) error { + // TODO(irfansharif): Flesh out the example usage patterns. + return errors.New("unimplemented") +} diff --git a/pkg/cmd/dev/generate.go b/pkg/cmd/dev/generate.go new file mode 100644 index 000000000000..c25a81cbc851 --- /dev/null +++ b/pkg/cmd/dev/generate.go @@ -0,0 +1,36 @@ +// Copyright 2020 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package main + +import ( + "github.com/cockroachdb/errors" + "github.com/spf13/cobra" +) + +// generateCmd generates the specified files. +var generateCmd = &cobra.Command{ + Use: "generate", + Aliases: []string{"gen"}, + Short: `Generate the specified files`, + Long: `Generate the specified files.`, + Example: ` + dev gen bazel + dev generate protobuf + dev generate {exec,opt}gen +`, + Args: cobra.NoArgs, + RunE: runGenerate, +} + +func runGenerate(cmd *cobra.Command, args []string) error { + // TODO(irfansharif): Flesh out the example usage patterns. + return errors.New("unimplemented") +} diff --git a/pkg/cmd/dev/lint.go b/pkg/cmd/dev/lint.go new file mode 100644 index 000000000000..29176067d37d --- /dev/null +++ b/pkg/cmd/dev/lint.go @@ -0,0 +1,32 @@ +// Copyright 2020 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package main + +import ( + "github.com/cockroachdb/errors" + "github.com/spf13/cobra" +) + +// lintCmd runs the specified linters. +var lintCmd = &cobra.Command{ + Use: "lint [pkg] (flags)", + Short: `Run the specified linters`, + Long: `Run the specified linters.`, + Example: ` + dev lint --filter=TestLowercaseFunctionNames --short --timeout=1m`, + Args: cobra.NoArgs, + RunE: runLint, +} + +func runLint(cmd *cobra.Command, args []string) error { + // TODO(irfansharif): Flesh out the example usage patterns. + return errors.New("unimplemented") +} diff --git a/pkg/cmd/dev/main.go b/pkg/cmd/dev/main.go new file mode 100644 index 000000000000..712b9098d4fa --- /dev/null +++ b/pkg/cmd/dev/main.go @@ -0,0 +1,59 @@ +// Copyright 2020 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package main + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +var devCmd = &cobra.Command{ + Use: "dev [command] (flags)", + Short: "Dev is the general-purpose dev tool for folks working on cockroachdb/cockroach.", + Long: ` +Dev is the general-purpose dev tool for folks working cockroachdb/cockroach. It +lets engineers do a few things: + +- build various binaries (cockroach, optgen, ...) +- run arbitrary tests (unit tests, logic tests, ...) +- run tests under arbitrary configurations (under stress, using race builds, ...) +- generate code (bazel files, protobufs, ...) + +...and much more. + +(PS: Almost none of the above is implemented yet, haha.) +`, +} + +func init() { + devCmd.AddCommand( + benchCmd, + buildCmd, + generateCmd, + lintCmd, + testCmd, + ) + + // Hide the `help` sub-command. + devCmd.SetHelpCommand(&cobra.Command{ + Use: "noop-help", + Hidden: true, + }) +} + +func main() { + if err := devCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} diff --git a/pkg/cmd/dev/test.go b/pkg/cmd/dev/test.go new file mode 100644 index 000000000000..8645b79bb49a --- /dev/null +++ b/pkg/cmd/dev/test.go @@ -0,0 +1,35 @@ +// Copyright 2020 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package main + +import ( + "github.com/cockroachdb/errors" + "github.com/spf13/cobra" +) + +// testCmd runs the specified cockroachdb tests. +var testCmd = &cobra.Command{ + Use: "test [pkg] (flags)", + Short: `Run the specified tests`, + Long: `Run the specified tests.`, + Example: ` + dev test kv/kvserver --filter=TestReplicaGC* -v -show-logs --timeout=1m + dev test --stress --race ... + dev test --logic --files=prepare|fk --subtests=20042 --config=local + dev test --fuzz sql/sem/tree --filter=Decimal`, + Args: cobra.NoArgs, + RunE: runTest, +} + +func runTest(cmd *cobra.Command, args []string) error { + // TODO(irfansharif): Flesh out the example usage patterns. + return errors.New("unimplemented") +}