Documentation
¶
Overview ¶
Package wrapper implements the actual functionality of wrapping protoc.
Index ¶
- Constants
- func AnnotateFullPaths(infos map[string]*FileInfo, allProtos []string, importDirs []string)
- func CollectPackages(infos map[string]*FileInfo, protos []string, importDirs []string) (map[string]*PackageInfo, error)
- func ComputeGoLocations(infos map[string]*FileInfo)
- func CopyAndChangePackage(in, out, pkg string) error
- func Disjoint(existing, additional []string) []string
- func FileDescriptorName(protoFile string, importDirs []string) string
- func Generate(pkg *PackageInfo, importDirs []string, protocCommand string, ...) (err error)
- func GetFileInfos(importPaths []string, protos []string, protocCommand string) (info map[string]*FileInfo, err error)
- func ImportDirsUsed(importDirs []string, protos []string) []string
- func ProtosBelow(dirs []string) ([]string, error)
- type Cache
- type FileInfo
- type FlagValues
- type PackageCache
- type PackageInfo
- type Wrapper
Constants ¶
const CacheVersion = 1
CacheVersion is the current cache format version. Increment this when the cache format changes incompatibly.
Variables ¶
This section is empty.
Functions ¶
func AnnotateFullPaths ¶
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 ¶
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 ¶
CopyAndChangePackage copies file `in` to file `out`, rewriting the `package` declaration to `pkg`.
func Disjoint ¶
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 ¶
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 ¶
ImportDirsUsed returns the set of import directories that contain entries in the set of proto files.
func ProtosBelow ¶
ProtosBelow returns a slice containing the filenames of all .proto files found in or below the given directories.
Types ¶
type Cache ¶ added in v0.4.0
type Cache struct {
Version int `json:"version"`
ProtocFlagsHash string `json:"protocFlagsHash"`
Packages map[string]*PackageCache `json:"packages"`
}
Cache represents the cached state of proto generation.
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 ¶
GoPluginOutputFilename returns the filename the vanilla go protoc plugin will use when generating output for this file.
func (FileInfo) PackageDir ¶
PackageDir returns the desired directory location for the given file; ComputedPackage, with dots replaced by slashes.
type FlagValues ¶
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.
type PackageCache ¶ added in v0.4.0
type PackageCache struct {
Hash string `json:"hash"`
GeneratedFiles []string `json:"generatedFiles"`
ProtoFiles []string `json:"protoFiles"`
LastGenerated time.Time `json:"lastGenerated"`
}
PackageCache represents the cached state of a single package.
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.
// Cache-related fields
CacheFile string // Path to cache manifest file.
ForceRegen bool // Force regeneration of all packages.
CacheVerbose bool // Print cache hit/miss information.
ToolVersions string // Tool versions string for cache invalidation.
// contains filtered or unexported fields
}
The wrapper object.
func (*Wrapper) CheckCycles ¶
CheckCycles checks for proto import structures that would result in Go package cycles.
func (*Wrapper) PrintStructure ¶
PrintStructure dumps out the computed structure to the given io.Writer.