Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
61266: bazel: Stringer missing files. r=otan a=alan-mas

This is the last part of the stringer auto-generated .go files that we need to include within bazel sandbox cockroachdb#57787
some of these files need an specific treatment so we might need to create a custom genrule.


Release note: None

Release justification: non-production code changes

Co-authored-by: Alanmas <[email protected]>
  • Loading branch information
craig[bot] and alan-mas committed Mar 19, 2021
2 parents 7f7d4fd + 218a3cc commit ee9f47b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 16 deletions.
2 changes: 2 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ load("@bazel_gazelle//:def.bzl", "gazelle")
# gazelle:exclude pkg/sql/privilege/kind_string.go
# gazelle:exclude pkg/sql/roleoption/option_string.go
# gazelle:exclude pkg/sql/schemachange/columnconversionkind_string.go
# gazelle:exclude pkg/sql/schemachanger/scop/type_string.go
# gazelle:exclude pkg/sql/sem/tree/createtypevariety_string.go
# gazelle:exclude pkg/sql/sem/tree/statementtype_string.go
# gazelle:exclude pkg/sql/txnevent_string.go
Expand All @@ -120,6 +121,7 @@ load("@bazel_gazelle//:def.bzl", "gazelle")
# gazelle:exclude pkg/util/timeutil/pgdate/field_string.go
# gazelle:exclude pkg/util/timeutil/pgdate/parsemode_string.go
# gazelle:exclude pkg/workload/schemachange/optype_string.go
# gazelle:exclude pkg/workload/schemachange/txstatus_string.go
# gazelle:exclude pkg/geo/wkt/wkt_generated.go
# gazelle:exclude pkg/sql/schemachanger/scop/backfill_visitor_generated.go
# gazelle:exclude pkg/sql/schemachanger/scop/mutation_visitor_generated.go
Expand Down
9 changes: 8 additions & 1 deletion pkg/sql/schemachanger/scop/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("//build:STRINGER.bzl", "stringer")

go_library(
name = "scop",
srcs = [
"backfill.go",
"mutation.go",
"ops.go",
"type_string.go",
"validation.go",
":gen-backfill", # keep
":gen-mutation", # keep
":gen-type-stringer", # keep
":gen-validation", # keep
],
importpath = "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scop",
Expand Down Expand Up @@ -66,3 +67,9 @@ genrule(
":gen-visitors",
],
)

stringer(
name = "gen-type-stringer",
src = "ops.go",
typ = "Type",
)
22 changes: 13 additions & 9 deletions pkg/workload/schemachange/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ go_library(
"error_screening.go",
"operation_generator.go",
"schemachange.go",
# TODO(alanmas,irfansharif): Generate this stringer file within the
# sandbox as well.
"txstatus_string.go",
"type_resolver.go",
":gen-optype-stringer", # keep
":gen-txstatus-stringer", # keep
],
importpath = "github.com/cockroachdb/cockroach/pkg/workload/schemachange",
visibility = ["//visibility:public"],
Expand All @@ -38,12 +36,6 @@ go_library(
],
)

stringer(
name = "gen-optype-stringer",
src = "operation_generator.go",
typ = "opType",
)

go_test(
name = "schemachange_test",
srcs = [
Expand All @@ -69,3 +61,15 @@ go_test(
"@org_golang_x_sync//errgroup",
],
)

stringer(
name = "gen-optype-stringer",
src = "operation_generator.go",
typ = "opType",
)

stringer(
name = "gen-txstatus-stringer",
src = "schemachange.go",
typ = "TxStatus",
)
22 changes: 16 additions & 6 deletions pkg/workload/schemachange/schemachange.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,22 @@ type TxStatus int

//go:generate stringer -type TxStatus
const (
TxStatusInFailure TxStatus = pgx.TxStatusInFailure
TxStatusRollbackFailure TxStatus = pgx.TxStatusRollbackFailure
TxStatusCommitFailure TxStatus = pgx.TxStatusCommitFailure
TxStatusInProgress TxStatus = pgx.TxStatusInProgress
TxStatusCommitSuccess TxStatus = pgx.TxStatusCommitSuccess
TxStatusRollbackSuccess TxStatus = pgx.TxStatusRollbackSuccess
TxStatusInFailure TxStatus = -3
TxStatusRollbackFailure TxStatus = -2
TxStatusCommitFailure TxStatus = -1
TxStatusInProgress TxStatus = 0
TxStatusCommitSuccess TxStatus = 1
TxStatusRollbackSuccess TxStatus = 2
)

// Workaround to do compile-time asserts that values are equal.
const (
_ = uint((TxStatusInFailure - pgx.TxStatusInFailure) * (pgx.TxStatusInFailure - TxStatusInFailure))
_ = uint((TxStatusRollbackFailure - pgx.TxStatusRollbackFailure) * (pgx.TxStatusRollbackFailure - TxStatusRollbackFailure))
_ = uint((TxStatusCommitFailure - pgx.TxStatusCommitFailure) * (pgx.TxStatusCommitFailure - TxStatusCommitFailure))
_ = uint((TxStatusInProgress - pgx.TxStatusInProgress) * (pgx.TxStatusInProgress - TxStatusInProgress))
_ = uint((TxStatusCommitSuccess - pgx.TxStatusCommitSuccess) * (pgx.TxStatusCommitSuccess - TxStatusCommitSuccess))
_ = uint((TxStatusRollbackSuccess - pgx.TxStatusRollbackSuccess) * (pgx.TxStatusRollbackSuccess - TxStatusRollbackSuccess))
)

// MarshalJSON encodes a TxStatus to a string.
Expand Down

0 comments on commit ee9f47b

Please sign in to comment.