Przeglądaj źródła

cmd/protoc-gen-go: make internal dependencies more patch-friendly

Declare the internal protobuf dependencies as variables of interface
type so that they can be more easily replaced by custom implementations.

Change-Id: I7fff885fd79ee0117c1c62654b2fd4b1877708da
Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/186659
Reviewed-by: Damien Neil <dneil@google.com>
Joe Tsai 6 lat temu
rodzic
commit
bda0ea8002
1 zmienionych plików z 22 dodań i 8 usunięć
  1. 22 8
      cmd/protoc-gen-go/internal_gengo/main.go

+ 22 - 8
cmd/protoc-gen-go/internal_gengo/main.go

@@ -73,17 +73,31 @@ const (
 	generateExportedExtensionFields = false
 )
 
+// Standard library dependencies.
 const (
-	mathPackage          = protogen.GoImportPath("math")
-	reflectPackage       = protogen.GoImportPath("reflect")
-	syncPackage          = protogen.GoImportPath("sync")
-	protoifacePackage    = protogen.GoImportPath("google.golang.org/protobuf/runtime/protoiface")
-	protoimplPackage     = protogen.GoImportPath("google.golang.org/protobuf/runtime/protoimpl")
-	protoreflectPackage  = protogen.GoImportPath("google.golang.org/protobuf/reflect/protoreflect")
-	protoregistryPackage = protogen.GoImportPath("google.golang.org/protobuf/reflect/protoregistry")
-	prototypePackage     = protogen.GoImportPath("google.golang.org/protobuf/reflect/prototype")
+	mathPackage    = protogen.GoImportPath("math")
+	reflectPackage = protogen.GoImportPath("reflect")
+	syncPackage    = protogen.GoImportPath("sync")
 )
 
+// Protobuf library dependencies.
+//
+// These are declared as an interface type so that they can be more easily
+// patched to support unique build environments that impose restrictions
+// on the dependencies of generated source code.
+var (
+	protoifacePackage    goImportPath = protogen.GoImportPath("google.golang.org/protobuf/runtime/protoiface")
+	protoimplPackage     goImportPath = protogen.GoImportPath("google.golang.org/protobuf/runtime/protoimpl")
+	protoreflectPackage  goImportPath = protogen.GoImportPath("google.golang.org/protobuf/reflect/protoreflect")
+	protoregistryPackage goImportPath = protogen.GoImportPath("google.golang.org/protobuf/reflect/protoregistry")
+	prototypePackage     goImportPath = protogen.GoImportPath("google.golang.org/protobuf/reflect/prototype")
+)
+
+type goImportPath interface {
+	String() string
+	Ident(string) protogen.GoIdent
+}
+
 type fileInfo struct {
 	*protogen.File