From 218a3cc08f0f5dfb1da2e6bd7282ae5babb08fe7 Mon Sep 17 00:00:00 2001 From: Alanmas Date: Wed, 24 Feb 2021 12:49:53 -0600 Subject: [PATCH] Stringer missing files. This is the last part of the stringer auto-generated .go files that we need to include within bazel sandbox some of these files need an specific treatment so we might need to create a custome genrule Release note: None Release justification: non-production code changes --- BUILD.bazel | 2 ++ pkg/sql/schemachanger/scop/BUILD.bazel | 9 ++++++++- pkg/workload/schemachange/BUILD.bazel | 22 +++++++++++++--------- pkg/workload/schemachange/schemachange.go | 22 ++++++++++++++++------ 4 files changed, 39 insertions(+), 16 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 9826b6b073a2..564ef172c0ed 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -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 @@ -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 diff --git a/pkg/sql/schemachanger/scop/BUILD.bazel b/pkg/sql/schemachanger/scop/BUILD.bazel index 13ed234d6aff..406f2b474c15 100644 --- a/pkg/sql/schemachanger/scop/BUILD.bazel +++ b/pkg/sql/schemachanger/scop/BUILD.bazel @@ -1,4 +1,5 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") +load("//build:STRINGER.bzl", "stringer") go_library( name = "scop", @@ -6,10 +7,10 @@ go_library( "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", @@ -66,3 +67,9 @@ genrule( ":gen-visitors", ], ) + +stringer( + name = "gen-type-stringer", + src = "ops.go", + typ = "Type", +) diff --git a/pkg/workload/schemachange/BUILD.bazel b/pkg/workload/schemachange/BUILD.bazel index f52e266a4fdd..feffbd03b38c 100644 --- a/pkg/workload/schemachange/BUILD.bazel +++ b/pkg/workload/schemachange/BUILD.bazel @@ -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"], @@ -38,12 +36,6 @@ go_library( ], ) -stringer( - name = "gen-optype-stringer", - src = "operation_generator.go", - typ = "opType", -) - go_test( name = "schemachange_test", srcs = [ @@ -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", +) diff --git a/pkg/workload/schemachange/schemachange.go b/pkg/workload/schemachange/schemachange.go index 7f1d775e8f6e..df32b6e8e201 100644 --- a/pkg/workload/schemachange/schemachange.go +++ b/pkg/workload/schemachange/schemachange.go @@ -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.