Fix generic comparisons on protobuf messages Generated protobuf messages contain internal data structures that general purpose comparison functions (e.g., reflect.DeepEqual, pretty.Compare, etc) do not properly compare. It is already the case today that these functions may report a difference when two messages are actually semantically equivalent. Fix all usages by either calling proto.Equal directly if the top-level types are themselves proto.Message, or by calling cmp.Equal with the cmp.Comparer(proto.Equal) option specified. This option teaches cmp to use proto.Equal anytime it encounters proto.Message types. PiperOrigin-RevId: 282412693
diff --git a/internal/ts_repositories.bzl b/internal/ts_repositories.bzl index 90a1c1a..30cb405 100644 --- a/internal/ts_repositories.bzl +++ b/internal/ts_repositories.bzl
@@ -47,6 +47,12 @@ ts_setup_workspace() go_repository( + name = "com_github_google_go_cmp", + commit = "2d0692c2e9617365a95b295612ac0d4415ba4627", + importpath = "github.com/google/go-cmp", + ) + + go_repository( name = "com_github_kylelemons_godebug", commit = "d65d576e9348f5982d7f6d83682b694e731a45c6", importpath = "github.com/kylelemons/godebug",
diff --git a/ts_auto_deps/analyze/analyze_test.go b/ts_auto_deps/analyze/analyze_test.go index ff529b8..7a7d90a 100644 --- a/ts_auto_deps/analyze/analyze_test.go +++ b/ts_auto_deps/analyze/analyze_test.go
@@ -12,6 +12,8 @@ "github.com/bazelbuild/rules_typescript/ts_auto_deps/platform" "github.com/golang/protobuf/proto" + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "github.com/kylelemons/godebug/pretty" appb "github.com/bazelbuild/buildtools/build_proto" @@ -616,7 +618,7 @@ t.Errorf("got err %q, expected %q", err, test.err) } - if diff := pretty.Compare(rt.sources, test.expected); err == nil && diff != "" { + if diff := cmp.Diff(rt.sources, test.expected, cmpopts.EquateEmpty(), cmp.Comparer(proto.Equal)); err == nil && diff != "" { t.Errorf("failed to set correct sources: (-got, +want)\n%s", diff) } })