wrapper

package
v0.0.0-...-4d55380 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package wrapper implements the actual functionality of wrapping protoc.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnnotateFullPaths

func AnnotateFullPaths(infos map[string]*FileInfo, allProtos []string, importDirs []string)

AnnotateFullPaths annotates an existing set of FileInfos with their full paths.

func CollectPackages

func CollectPackages(infos map[string]*FileInfo, protos []string, importDirs []string) (map[string]*PackageInfo, error)

CollectPackages returns a map of PackageInfos.

func ComputeGoLocations

func ComputeGoLocations(infos map[string]*FileInfo)

ComputeGoLocations uses the package and go_package information to figure out the effective Go location and package. It sets ComputedPackage to the full form "path;decl" (whether decl is redundant or not) as described in github.com/golang/protobuf/issues/139

func CopyAndChangePackage

func CopyAndChangePackage(in, out, pkg string) error

CopyAndChangePackage copies file `in` to file `out`, rewriting the `package` declaration to `pkg`.

func Disjoint

func Disjoint(existing, additional []string) []string

Disjoint takes a slice of existing .proto files, and a slice of new .proto files. It returns a slice containing the subset of the new .proto files with distinct paths not in the first set.

func FileDescriptorName

func FileDescriptorName(protoFile string, importDirs []string) string

FileDescriptorName computes the import-dir-relative Name that the FileDescriptor for a full filename will have.

func Generate

func Generate(pkg *PackageInfo, importDirs []string, protocCommand string, protocFlags []string, printOnly bool) (err error)

Generate does the actual generation of protos.

func GetFileInfos

func GetFileInfos(importPaths []string, protos []string, protocCommand string) (info map[string]*FileInfo, err error)

GetFileInfos gets the FileInfo struct for every proto passed in.

func ImportDirsUsed

func ImportDirsUsed(importDirs []string, protos []string) []string

ImportDirsUsed returns the set of import directories that contain entries in the set of proto files.

func ProtosBelow

func ProtosBelow(dirs []string) ([]string, error)

ProtosBelow returns a slice containing the filenames of all .proto files found in or below the given directories.

Types

type FileInfo

type FileInfo struct {
	Name      string   // The Name field of the FileDescriptorProto (import-path-relative)
	FullPath  string   // The full path to the file, as specified on the command-line
	Package   string   // The declared package
	GoPackage string   // The declared go_package
	Deps      []string // The names of files imported by this file (import-path-relative)

	// Our final decision for which package this file should generate
	// to. In the full form "path;decl" (whether decl is redundant or
	// not) as described in github.com/golang/protobuf/issues/139
	ComputedPackage string // Our final decision for which package this file should generate to
}

FileInfo is the set of information we need to know about a file from protoc.

func (FileInfo) GoPluginOutputFilename

func (f FileInfo) GoPluginOutputFilename() string

GoPluginOutputFilename returns the filename the vanilla go protoc plugin will use when generating output for this file.

func (FileInfo) PackageDir

func (f FileInfo) PackageDir() string

PackageDir returns the desired directory location for the given file; ComputedPackage, with dots replaced by slashes.

type FlagValues

type FlagValues map[string]string

Flag values is a simple map of parsed flag values. A map of string to string, with convenience getters.

func ParseArgs

func ParseArgs(args []string, custom map[string]bool) (customFlags FlagValues, protocFlags, protos, importDirs []string, err error)

ParseArgs parses protoc-style commandline arguments, splitting them into custom flags, protoc flags and input files, and capturing a list of import directories. Custom flag names are passed without dashes, and are expected to be specified with two dashes. If customFlagNames[name] is true, the custom flag expects a value; otherwise it can have no value, and will get a value of "".

func (FlagValues) Bool

func (fv FlagValues) Bool(name string, defaultValue bool) (bool, error)

Bool returns the boolean version of a flag, if set.

func (FlagValues) Has

func (fv FlagValues) Has(name string) bool

Has returns true if the given flag was specified at all.

func (FlagValues) Int

func (fv FlagValues) Int(name string, defaultValue int) (int, error)

Int returns the integer version of a flag, if set.

func (FlagValues) String

func (fv FlagValues) String(name string, defaultValue string) string

String returns the string version of a flag, if set.

type PackageInfo

type PackageInfo struct {
	ComputedPackage string
	Files           []*FileInfo
	Deps            []*FileInfo
	// contains filtered or unexported fields
}

PackageInfo collects all the information for a single package.

func (PackageInfo) ImportedPackageComputedNames

func (p PackageInfo) ImportedPackageComputedNames() []string

ImportedPackageComputedNames returns the list of packages imported by this package.

func (PackageInfo) PackageDir

func (p PackageInfo) PackageDir() string

PackageDir returns the desired directory location for the given package; ComputedPackage, with dots replaced by slashes.

func (PackageInfo) PackageName

func (p PackageInfo) PackageName() string

PackageName returns the desired package name for the given package; whatever follows the last dot in ComputedPackage.

type Wrapper

type Wrapper struct {
	ProtocCommand string   // The command to call to run protoc.
	Parallelism   int      // Number of simultaneous calls to make to protoc when generating.
	ProtocFlags   []string // Flags to pass to protoc.
	ImportDirs    []string // Base directories in which .proto files reside.
	ProtoFiles    []string // The list of .proto files to generate code for.
	NoExpand      bool     // If true, don't search for other protos in import directories.
	PrintOnly     bool     // If true, don't generate: just print the protoc commandlines that would be called.
	// contains filtered or unexported fields
}

The wrapper object.

func (*Wrapper) CheckCycles

func (w *Wrapper) CheckCycles() error

CheckCycles checks for proto import structures that would result in Go package cycles.

func (*Wrapper) Generate

func (w *Wrapper) Generate() error

Generate actually generates the output files.

func (*Wrapper) Init

func (w *Wrapper) Init() error

Init must be called before any of the methods that do anything.

func (*Wrapper) PrintStructure

func (w *Wrapper) PrintStructure(writer io.Writer)

PrintStructure dumps out the computed structure to the given io.Writer.

Jump to

Keyboard shortcuts

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