Skip to content

Commit 1fda4cc

Browse files
committed
dev,bazelrc: new flag --test-build-only
When specified, only the dependencies of test targets (including the test sources) are compiled; the test executables themselves are not linked. This change depends on cockroachdb/rules_go#16. Release note: None
1 parent 6fa90e9 commit 1fda4cc

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

.bazelrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ build:nolintonbuild --nolintonbuild
3030
# Note: nonogo is classically the name of the nolintonbuild configuration.
3131
build:nonogo --nolintonbuild
3232
build:test --crdb_test
33+
build:testbuildonly --crdb_test --@io_bazel_rules_go//go/config:testbuildonly
3334

3435
# Basic settings.
3536
build --define gotags=bazel,gss

pkg/cmd/dev/build.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const (
3535
nogoDisableFlag = "--//build/toolchains:nogo_disable_flag"
3636
geosTarget = "//c-deps:libgeos"
3737
devTarget = "//pkg/cmd/dev:dev"
38+
testbuildonly = "test-build-only"
3839
)
3940

4041
type buildTarget struct {
@@ -68,6 +69,7 @@ func makeBuildCmd(runE func(cmd *cobra.Command, args []string) error) *cobra.Com
6869
buildCmd.Flags().String(crossFlag, "", "cross-compiles using the builder image (options: linux, linuxarm, macos, macosarm, windows)")
6970
buildCmd.Flags().Lookup(crossFlag).NoOptDefVal = "linux"
7071
buildCmd.Flags().StringArray(dockerArgsFlag, []string{}, "additional arguments to pass to Docker (only used for cross builds)")
72+
buildCmd.Flags().Bool(testbuildonly, false, "only check test binaries can be built; do not link them")
7173
addCommonBuildFlags(buildCmd)
7274
return buildCmd
7375
}
@@ -147,6 +149,7 @@ func (d *dev) build(cmd *cobra.Command, commandLine []string) error {
147149
targets, additionalBazelArgs := splitArgsAtDash(cmd, commandLine)
148150
ctx := cmd.Context()
149151
cross := mustGetFlagString(cmd, crossFlag)
152+
testbuildonly := mustGetFlagBool(cmd, testbuildonly)
150153
dockerArgs := mustGetFlagStringArray(cmd, dockerArgsFlag)
151154

152155
// Set up dev cache unless it's disabled via the environment variable or the
@@ -166,7 +169,7 @@ func (d *dev) build(cmd *cobra.Command, commandLine []string) error {
166169
}
167170
}
168171

169-
args, buildTargets, err := d.getBasicBuildArgs(ctx, targets)
172+
args, buildTargets, err := d.getBasicBuildArgsInternal(ctx, targets, testbuildonly)
170173
if err != nil {
171174
return err
172175
}
@@ -387,6 +390,12 @@ func targetToBinBasename(target string) string {
387390
// (e.g. after translation, so short -> "//pkg/cmd/cockroach-short").
388391
func (d *dev) getBasicBuildArgs(
389392
ctx context.Context, targets []string,
393+
) (args []string, buildTargets []buildTarget, _ error) {
394+
return d.getBasicBuildArgsInternal(ctx, targets, false)
395+
}
396+
397+
func (d *dev) getBasicBuildArgsInternal(
398+
ctx context.Context, targets []string, testbuildonly bool,
390399
) (args []string, buildTargets []buildTarget, _ error) {
391400
if len(targets) == 0 {
392401
// Default to building the cockroach binary.
@@ -457,7 +466,11 @@ func (d *dev) getBasicBuildArgs(
457466
}
458467

459468
if shouldBuildWithTestConfig {
460-
args = append(args, "--config=test")
469+
if testbuildonly {
470+
args = append(args, "--config=testbuildonly")
471+
} else {
472+
args = append(args, "--config=test")
473+
}
461474
}
462475
if canDisableNogo {
463476
args = append(args, nogoDisableFlag)

0 commit comments

Comments
 (0)