collector

package
v0.34.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 20, 2024 License: Apache-2.0 Imports: 21 Imported by: 3

README

Collector

This package contains code to support compiling protos

ProtoCompiler

A ProtoCompiler is given a root and produces the file descriptor for each file in the tree. It does this by traversing the file system, starting at the root and for each file:

  1. Collects the imports, using an injected Collector
  2. Runs protoc, using an injected ProtocExecutor, and writes the output to a tmp file
  3. Aggregates the file descriptors produced by protoc

Collector

A collector is responsible for traversing a tree of files, opening and parsing each. A collector uses an ImportsExtractor to parse these files and aggregate a full list of imports in the tree.

ProtocExecutor

DefaultProtocExecutor

This is the default implementation used during codegen. It is builds the protoc command and executes it

OpenApiProtocExecutor

This is the protoc implementation used by our protoc tool during schemagen.

ImportsExtractor

An ImportsExtractor is responsible for reading the imports from a proto file.

SynchronizedImportsExtractor

When extracting imports for a single file, we must walk the entire dependency tree. Since we do this for each file, it's possible that we are walking the same paths repeatedly. Therefore, we support this implementation, which only allows a single in flight request per file, and then memoizes the results.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FetchImportsTimeout = func(filename string) error {
		return eris.Errorf("Timed out while fetching imports for proto file: [%s]", filename)
	}
)

Functions

func NewCollector

func NewCollector(customImports, commonImports []string) *collector

func NewProtoCompiler added in v0.18.5

func NewProtoCompiler(collector Collector, executor ProtocExecutor) *protoCompiler

Types

type Collector

type Collector interface {
	CollectImportsForFile(root, protoFile string) ([]string, error)
}

type DefaultProtocExecutor added in v0.19.0

type DefaultProtocExecutor struct {
	// The output directory
	OutputDir string
	// whether or not to do a regular go-proto generate while collecting descriptors
	ShouldCompileFile func(string) bool
	// arguments for go_out=
	CustomGoArgs []string
	// custom plugins
	// each will append a <plugin>_out= directive to protoc command
	CustomPlugins []string
}

func (*DefaultProtocExecutor) Execute added in v0.19.0

func (d *DefaultProtocExecutor) Execute(protoFile string, toFile string, imports []string) error

type ImportsExtractor added in v0.18.5

type ImportsExtractor interface {
	FetchImportsForFile(protoFile string, importsFetcher ImportsFetcher) ([]string, error)
}

func NewSynchronizedImportsExtractor added in v0.18.5

func NewSynchronizedImportsExtractor() ImportsExtractor

type ImportsFetcher added in v0.18.5

type ImportsFetcher func(file string) ([]string, error)

type OpenApiProtocExecutor added in v0.19.0

type OpenApiProtocExecutor struct {
	OutputDir string

	// Whether to include descriptions in validation schemas
	IncludeDescriptionsInSchema bool

	// Whether to assign Enum fields the `x-kubernetes-int-or-string` property
	// which allows the value to either be an integer or a string
	EnumAsIntOrString bool

	// A list of messages (core.solo.io.Status) whose validation schema should
	// not be generated
	MessagesWithEmptySchema []string
}

func (*OpenApiProtocExecutor) Execute added in v0.19.0

func (o *OpenApiProtocExecutor) Execute(protoFile string, toFile string, imports []string) error

type ProtoCompiler added in v0.18.5

type ProtoCompiler interface {
	CompileDescriptorsFromRoot(root string, skipDirs []string) ([]*model.DescriptorWithPath, error)
}

type ProtocExecutor added in v0.19.0

type ProtocExecutor interface {
	Execute(protoFile string, toFile string, imports []string) error
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL