builder

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2026 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildOptions

type BuildOptions struct {
	// Workers is the number of parallel workers (0 = auto)
	Workers int

	// Incremental enables incremental builds
	Incremental bool

	// Cache enables caching
	Cache bool

	// CacheDir is the cache directory
	CacheDir string

	// DryRun only shows what would be built
	DryRun bool

	// Verbose enables verbose logging
	Verbose bool
}

BuildOptions contains build configuration

type BuildPlan

type BuildPlan struct {
	// ProtoFiles is the list of proto files to compile
	ProtoFiles []string

	// ImportPaths are additional import paths
	ImportPaths []string

	// OutputDir is the base output directory
	OutputDir string

	// Languages are the target languages
	Languages []string

	// Options are additional build options
	Options BuildOptions
}

BuildPlan describes what to build

type BuildResult

type BuildResult struct {
	// Success indicates if build was successful
	Success bool

	// Duration is the total build time
	Duration time.Duration

	// FilesProcessed is the number of files processed
	FilesProcessed int

	// FilesGenerated is the number of generated files
	FilesGenerated int

	// Errors contains any build errors
	Errors []error

	// Warnings contains build warnings
	Warnings []string

	// CacheHits is the number of cache hits
	CacheHits int

	// CacheMisses is the number of cache misses
	CacheMisses int
}

BuildResult contains build results

type Builder

type Builder interface {
	// Build executes the build process
	Build(ctx context.Context, plan *BuildPlan) (*BuildResult, error)

	// GetMetrics returns build metrics
	GetMetrics() *metrics.Collector
}

Builder is the main interface for building protobuf files

func New

func New(cfg *config.Config, opts ...Option) (Builder, error)

New creates a new Builder

type CacheEntry

type CacheEntry struct {
	// File is the proto file path
	File string

	// Hash is the file content hash
	Hash string

	// DepsHash is the dependencies hash
	DepsHash string

	// Languages are the generated languages
	Languages []string

	// GeneratedFiles are the generated file paths
	GeneratedFiles []string
}

CacheEntry represents a cached build result

type CacheManager

type CacheManager interface {
	// Check checks cache for files
	Check(ctx context.Context, files []*ProtoFile) (hits int, misses int)

	// Get retrieves cache entry for a file
	Get(ctx context.Context, file *ProtoFile) (*CacheEntry, error)

	// Put stores cache entry
	Put(ctx context.Context, entry *CacheEntry) error

	// Invalidate removes cache entry
	Invalidate(ctx context.Context, file string) error

	// Clear clears all cache
	Clear(ctx context.Context) error
}

CacheManager manages build cache

func NewCacheManager

func NewCacheManager(log Logger) CacheManager

NewCacheManager creates a new CacheManager

type DependencyGraph

type DependencyGraph struct {
	// Nodes are the proto files
	Nodes map[string]*ProtoFile

	// Edges represent dependencies (file -> dependencies)
	Edges map[string][]string

	// CompilationOrder is the topologically sorted order
	CompilationOrder []string
}

DependencyGraph represents the dependency graph of proto files

func (*DependencyGraph) GetDependencies

func (g *DependencyGraph) GetDependencies(path string) []string

GetDependencies returns direct dependencies of a file

func (*DependencyGraph) GetTransitiveDependencies

func (g *DependencyGraph) GetTransitiveDependencies(path string) []string

GetTransitiveDependencies returns all transitive dependencies

func (*DependencyGraph) Validate

func (g *DependencyGraph) Validate() error

Validate checks if the graph is valid

type DependencyResolver

type DependencyResolver interface {
	// Resolve builds the dependency graph and determines compilation order
	Resolve(ctx context.Context, files []*ProtoFile) (*DependencyGraph, error)
}

DependencyResolver resolves proto file dependencies

func NewDependencyResolver

func NewDependencyResolver(log Logger) DependencyResolver

NewDependencyResolver creates a new DependencyResolver

type Enum

type Enum struct {
	Name   string
	Values []EnumValue
}

Enum represents a proto enum

type EnumValue

type EnumValue struct {
	Name   string
	Number int
}

EnumValue represents an enum value

type ExecutionPlan

type ExecutionPlan struct {
	// Graph is the dependency graph
	Graph *DependencyGraph

	// OutputDir is the output directory
	OutputDir string

	// ImportPaths are the import paths for protoc
	ImportPaths []string

	// Languages are the target languages
	Languages []string

	// Options are build options
	Options BuildOptions
}

ExecutionPlan describes how to execute the build

type ExecutionResult

type ExecutionResult struct {
	// FilesGenerated is the number of generated files
	FilesGenerated int

	// Warnings contains execution warnings
	Warnings []string

	// Metrics contains execution metrics
	Metrics map[string]interface{}
}

ExecutionResult contains execution results

type Executor

type Executor interface {
	// Execute runs the build execution
	Execute(ctx context.Context, plan *ExecutionPlan) (*ExecutionResult, error)
}

Executor executes the build plan

func NewExecutor

func NewExecutor(log Logger, m *metrics.Collector, cfg *config.Config) Executor

NewExecutor creates a new Executor

type Field

type Field struct {
	Name     string
	Type     string
	Number   int
	Repeated bool
	Optional bool
}

Field represents a message field

type Logger

type Logger interface {
	Debug(msg string, args ...interface{})
	Info(msg string, args ...interface{})
	Warn(msg string, args ...interface{})
	Error(msg string, args ...interface{})
}

Logger is a minimal interface for logging

func NewLoggerAdapter

func NewLoggerAdapter(log *logger.Logger) Logger

NewLoggerAdapter creates a new logger adapter

type Message

type Message struct {
	Name   string
	Fields []Field
}

Message represents a proto message

type Method

type Method struct {
	Name       string
	InputType  string
	OutputType string
	Options    map[string]string
}

Method represents a service method

type Option

type Option func(*builder) error

Option is a functional option for Builder

func WithCache

func WithCache(c CacheManager) Option

WithCache sets the cache manager

func WithExecutor

func WithExecutor(e Executor) Option

WithExecutor sets the executor

func WithLogger

func WithLogger(log *logger.Logger) Option

WithLogger sets the logger

func WithMetrics

func WithMetrics(m *metrics.Collector) Option

WithMetrics sets the metrics collector

func WithParser

func WithParser(p ProtoParser) Option

WithParser sets the proto parser

func WithPluginRegistry added in v1.0.0

func WithPluginRegistry(registry *plugin.Registry) Option

WithPluginRegistry sets the plugin registry

func WithResolver

func WithResolver(r DependencyResolver) Option

WithResolver sets the dependency resolver

type ProtoFile

type ProtoFile struct {
	// Path is the file path
	Path string

	// Package is the proto package name
	Package string

	// Syntax is the proto syntax version (proto2 or proto3)
	Syntax string

	// Imports are the imported proto files
	Imports []string

	// Services are the defined services
	Services []Service

	// Messages are the defined messages
	Messages []Message

	// Enums are the defined enums
	Enums []Enum

	// Options are file-level options
	Options map[string]string
}

ProtoFile represents a parsed proto file

type ProtoParser

type ProtoParser interface {
	// ParseFiles parses multiple proto files
	ParseFiles(ctx context.Context, files []string, importPaths []string) ([]*ProtoFile, error)

	// ParseFile parses a single proto file
	ParseFile(ctx context.Context, path string, importPaths []string) (*ProtoFile, error)
}

ProtoParser parses proto files

func NewProtoParser

func NewProtoParser(log Logger) ProtoParser

NewProtoParser creates a new ProtoParser

type Service

type Service struct {
	Name    string
	Methods []Method
}

Service represents a gRPC service

Jump to

Keyboard shortcuts

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