bufpluginexec

package
v0.0.0-...-ad79e7e Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Overview

Package bufpluginexec provides protoc plugin handling and execution.

Note this is currently implicitly tested through buf's protoc command. If this were split out into a separate package, testing would need to be moved to this package.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ProtocProxyPluginNames are the names of the plugins that should be proxied through protoc
	// in the absence of a binary.
	ProtocProxyPluginNames = map[string]struct{}{
		"cpp":    {},
		"csharp": {},
		"java":   {},
		"js":     {},
		"objc":   {},
		"php":    {},
		"python": {},
		"pyi":    {},
		"ruby":   {},
		"kotlin": {},
	}

	// DefaultVersion represents the default version to use as compiler version for codegen requests.
	DefaultVersion = newVersion(
		defaultMajorVersion,
		defaultMinorVersion,
		defaultPatchVersion,
		defaultSuffixVersion,
	)
)

Functions

func NewBinaryHandler

func NewBinaryHandler(runner command.Runner, pluginPath string, pluginArgs []string) (appproto.Handler, error)

NewBinaryHandler returns a new Handler that invokes the specific plugin specified by pluginPath.

Used by other repositories.

func NewHandler

func NewHandler(
	storageosProvider storageos.Provider,
	runner command.Runner,
	wasmPluginExecutor bufwasm.PluginExecutor,
	pluginName string,
	options ...HandlerOption,
) (appproto.Handler, error)

NewHandler returns a new Handler based on the plugin name and optional path.

protocPath and pluginPath are optional.

  • If a WASM plugin path is specified as the plugin name, this returns a WASM handler.
  • If the plugin path is set, this returns a new binary handler for that path.
  • If the plugin path is unset, this does exec.LookPath for a binary named protoc-gen-pluginName, and if one is found, a new binary handler is returned for this.
  • Else, if the name is in ProtocProxyPluginNames, this returns a new protoc proxy handler.
  • Else, this returns error.

Types

type GenerateOption

type GenerateOption func(*generateOptions)

GenerateOption is an option for Generate.

func GenerateWithPluginPath

func GenerateWithPluginPath(pluginPath ...string) GenerateOption

GenerateWithPluginPath returns a new GenerateOption that uses the given path to the plugin. If the path has more than one element, the first is the plugin binary and the others are optional additional arguments to pass to the binary.

func GenerateWithProtocPath

func GenerateWithProtocPath(protocPath string) GenerateOption

GenerateWithProtocPath returns a new GenerateOption that uses the given protoc path to the plugin.

func GenerateWithWASMEnabled

func GenerateWithWASMEnabled() GenerateOption

GenerateWithWASMEnabled returns a new GenerateOption that sets wasmEnabled according to the env variable.

type Generator

type Generator interface {
	// Generate generates a CodeGeneratorResponse for the given pluginName. The
	// pluginName must be available on the system's PATH or one of the plugins
	// built-in to protoc. The plugin path can be overridden via the
	// GenerateWithPluginPath option.
	Generate(
		ctx context.Context,
		container app.EnvStderrContainer,
		pluginName string,
		requests []*pluginpb.CodeGeneratorRequest,
		options ...GenerateOption,
	) (*pluginpb.CodeGeneratorResponse, error)
}

Generator is used to generate code with plugins found on the local filesystem.

func NewGenerator

func NewGenerator(
	logger *zap.Logger,
	storageosProvider storageos.Provider,
	runner command.Runner,
	wasmPluginExecutor bufwasm.PluginExecutor,
) Generator

NewGenerator returns a new Generator.

type HandlerOption

type HandlerOption func(*handlerOptions)

HandlerOption is an option for a new Handler.

func HandlerWithPluginPath

func HandlerWithPluginPath(pluginPath ...string) HandlerOption

HandlerWithPluginPath returns a new HandlerOption that sets the path to the plugin binary.

The default is to do exec.LookPath on "protoc-gen-" + pluginName. pluginPath is expected to be unnormalized. If the path has more than one element, the first is the plugin binary and the others are optional additional arguments to pass to the binary

func HandlerWithProtocPath

func HandlerWithProtocPath(protocPath string) HandlerOption

HandlerWithProtocPath returns a new HandlerOption that sets the path to the protoc binary.

The default is to do exec.LookPath on "protoc". protocPath is expected to be unnormalized.

func HandlerWithWASMEnabled

func HandlerWithWASMEnabled() HandlerOption

HandlerWithWASMEnabled returns a new HandlerOption that sets wasmEnabled according to the env variable.

Jump to

Keyboard shortcuts

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