protoc

package
v0.0.0-...-f5ffb6e Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompileResult

type CompileResult struct {
	// The failures from all calls.
	Failures []*text.Failure
	// Will not be set if there are any failures.
	//
	// Will only be set if the CompilerWithFileDescriptorSet
	// option is used.
	FileDescriptorSets FileDescriptorSets
}

CompileResult is the result of a compile

type Compiler

type Compiler interface {
	// Compile the protobuf files with protoc.
	//
	// If there are compile failures, they will be returned in the slice
	// and there will be no error. The caller can determine if this is
	// an error case. If there is any other type of error, or some output
	// from protoc cannot be interpreted, an error will be returned.
	Compile(*file.ProtoSet) (*CompileResult, error)

	// Return the protoc commands that would be run on Compile.
	//
	// This will ignore the CompilerWithFileDescriptorSet option.
	ProtocCommands(*file.ProtoSet) ([]string, error)
}

Compiler compiles protobuf files.

func NewCompiler

func NewCompiler(options ...CompilerOption) Compiler

NewCompiler returns a new Compiler.

type CompilerOption

type CompilerOption func(*compiler)

CompilerOption is an option for a new Compiler.

func CompilerWithCachePath

func CompilerWithCachePath(cachePath string) CompilerOption

CompilerWithCachePath returns a CompilerOption that uses the given cachePath.

The default is ${XDG_CACHE_HOME}/prototool/$(uname -s)/$(uname -m).

func CompilerWithFileDescriptorSet

func CompilerWithFileDescriptorSet() CompilerOption

CompilerWithFileDescriptorSet says to also return the FileDescriptorSet.

func CompilerWithFileDescriptorSetFullControl

func CompilerWithFileDescriptorSetFullControl(includeImports bool, includeSourceInfo bool) CompilerOption

CompilerWithFileDescriptorSetFullControl says to also return the FileDescriptorSet but with extra controls.

This is added for backwards compatibility within the codebase.

func CompilerWithGen

func CompilerWithGen() CompilerOption

CompilerWithGen says to also generate the code.

func CompilerWithLogger

func CompilerWithLogger(logger *zap.Logger) CompilerOption

CompilerWithLogger returns a CompilerOption that uses the given logger.

The default is to use zap.NewNop().

func CompilerWithProtocBinPath

func CompilerWithProtocBinPath(protocBinPath string) CompilerOption

CompilerWithProtocBinPath returns a CompilerOption that uses the given protoc binary path.

func CompilerWithProtocURL

func CompilerWithProtocURL(protocURL string) CompilerOption

CompilerWithProtocURL returns a CompilerOption that uses the given protoc zip file URL.

The default is https://github.com/protocolbuffers/protobuf/releases/download/vVERSION/protoc-VERSION-OS-ARCH.zip.

func CompilerWithProtocWKTPath

func CompilerWithProtocWKTPath(protocWKTPath string) CompilerOption

CompilerWithProtocWKTPath returns a CompilerOption that uses the given path to include the well-known types.

type Downloader

type Downloader interface {
	// Download protobuf.
	//
	// If already downloaded, this has no effect. This is thread-safe.
	// This will download to ${XDG_CACHE_HOME}/prototool/$(uname -s)/$(uname -m)
	// unless overridden by a DownloaderOption.
	// If ${XDG_CACHE_HOME} is not set, it defaults to ${HOME}/Library/Caches on
	// Darwin, and ${HOME}/.cache on Linux.
	// If ${HOME} is not set, an error will be returned.
	//
	// Returns the path to the downloaded protobuf artifacts.
	//
	// ProtocPath and WellKnownTypesIncludePath implicitly call this.
	Download() (string, error)

	// Get the path to protoc.
	//
	// If not downloaded, this downloads and caches protobuf. This is thread-safe.
	ProtocPath() (string, error)

	// Get the path to include for the well-known types.
	//
	// Inside this directory will be the subdirectories google/protobuf.
	//
	// If not downloaded, this downloads and caches protobuf. This is thread-safe.
	WellKnownTypesIncludePath() (string, error)

	// Delete any downloaded artifacts.
	//
	// This is not thread-safe and no calls to other functions can be reliably
	// made simultaneously.
	Delete() error
}

Downloader downloads and caches protobuf.

func NewDownloader

func NewDownloader(config settings.Config, options ...DownloaderOption) (Downloader, error)

NewDownloader returns a new Downloader for the given config and DownloaderOptions.

type DownloaderOption

type DownloaderOption func(*downloader)

DownloaderOption is an option for a new Downloader.

func DownloaderWithCachePath

func DownloaderWithCachePath(cachePath string) DownloaderOption

DownloaderWithCachePath returns a DownloaderOption that uses the given cachePath.

The default is ${XDG_CACHE_HOME}/prototool/$(uname -s)/$(uname -m).

func DownloaderWithLogger

func DownloaderWithLogger(logger *zap.Logger) DownloaderOption

DownloaderWithLogger returns a DownloaderOption that uses the given logger.

The default is to use zap.NewNop().

func DownloaderWithProtocBinPath

func DownloaderWithProtocBinPath(protocBinPath string) DownloaderOption

DownloaderWithProtocBinPath returns a DownloaderOption that uses the given protoc binary path.

func DownloaderWithProtocURL

func DownloaderWithProtocURL(protocURL string) DownloaderOption

DownloaderWithProtocURL returns a DownloaderOption that uses the given protoc zip file URL.

The default is https://github.com/protocolbuffers/protobuf/releases/download/vVERSION/protoc-VERSION-OS-ARCH.zip.

func DownloaderWithProtocWKTPath

func DownloaderWithProtocWKTPath(protocWKTPath string) DownloaderOption

DownloaderWithProtocWKTPath returns a DownloaderOption that uses the given path to include the well-known types.

type FileDescriptorSet

type FileDescriptorSet struct {
	*descriptor.FileDescriptorSet
	// The containing ProtoSet.
	ProtoSet *file.ProtoSet
	// The absolute directory path for the built files in this FileDescriptorSet.
	// This directory path will always reside within the ProtoSetDirPath,
	// that is filepath.Rel(ProtoSetDirPath, DirPath) will never return
	// error and always return a non-empty string. Note the string could be ".".
	DirPath string
	// The ProtoFiles for the built files in this FileDescriptorSet.
	// The directory of Path will always be equal to DirPath.
	ProtoFiles []*file.ProtoFile
}

FileDescriptorSet is a wrapper for descriptor.FileDescriptorSet.

This will contain both the files specified by ProtoFiles and all imports.

type FileDescriptorSets

type FileDescriptorSets []*FileDescriptorSet

FileDescriptorSets are a slice of FileDescriptorSet objects.

func (FileDescriptorSets) Unwrap

Unwrap converts f to []*descriptor.FileDescriptorSet.

Used for backwards compatibility with existing code that is based on descriptor.FileDescriptorSets.

Jump to

Keyboard shortcuts

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