forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dev: introduce a general purpose dev-tool for crdb engineers
Our Makefile UX has grown organically over the last six years, and is now home to various scripts that are orthogonal to simply building the crdb binary. These include the ability to run linters, building various useful binaries (such as roachprod, roachtest), running different kinds of tests (unit tests, logic tests, acceptance tests), and much more. Now that we're exploring a move towards Bazel for our build system (cockroachdb#55687), we have a chance to tuck away Bazel specific under a general purpose dev-tool. The intent here is to house all day-to-day dev operations under this tool, written in Go. This will be the component that actually replaces our Makefile in its entirety. It'll be (predictably) powered by bazel underneath, but with much nicer UX. It should capturing all common usage patterns in high-level docs. This diff only introduces the scaffolding for this CLI. Release note: None
- Loading branch information
1 parent
ad3dea8
commit 0ddb0d1
Showing
8 changed files
with
254 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") | ||
} |