plugin_compiler

package
v0.48.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 31 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildPackageName

func BuildPackageName(pkg *types.Package) string

BuildPackageName builds the unique name for the package.

func BuildPlugin

func BuildPlugin(ctx context.Context, le *logrus.Entry, packageSearchPath, outputPath, codegenDir string, packages []string) error

BuildPlugin builds a plugin using a temporary code-gen path.

Automates the end-to-end build process with reasonable defaults. If codegenDir is empty, uses a tmpdir in the user .cache directory.

func CleanupOldVersions

func CleanupOldVersions(le *logrus.Entry, pluginOutputPath string) error

CleanupOldVersions cleans up old versions from the target path.

func CodegenPluginWrapperFromAnalysis

func CodegenPluginWrapperFromAnalysis(
	le *logrus.Entry,
	a *Analysis,
	binaryID, binaryVersion string,
) (*gast.File, error)

CodegenPluginWrapperFromAnalysis codegens a plugin wrapper from analysis.

func CompilePluginFromFile

func CompilePluginFromFile(
	le *logrus.Entry,
	gfile *gast.File,
	intermediateGoFile string,
	outFile string,
	preWriteOutFileHook func(nextOutFilePath, nextOutFileContentsPath string) error,
) error

CompilePluginFromFile compiles the plugin from the gfile.

{buildHash} will be replaced with the build hash in the output filename.

func FormatFile

func FormatFile(gf *gast.File) ([]byte, error)

FormatFile formats the output file.

func GeneratePluginWrapper

func GeneratePluginWrapper(
	ctx context.Context,
	le *logrus.Entry,
	an *Analysis,
	binaryName, binaryVersion string,
) (*gast.File, error)

GeneratePluginWrapper generates a wrapper package for a list of packages containing controller factories.

func HashPluginForBuildID

func HashPluginForBuildID(hhBaseKey []byte, filePath string) (string, error)

HashPluginForBuildID hashes a plugin to use for build id. hhBaseKey should be unique for the plugin. hhBaseKey should be 32 bytes long

Types

type Analysis

type Analysis struct {
	// contains filtered or unexported fields
}

Analysis contains the result of code analysis.

func AnalyzePackages

func AnalyzePackages(
	ctx context.Context,
	le *logrus.Entry,
	workDir string,
	packagePaths []string,
) (*Analysis, error)

AnalyzePackages analyzes code packages using Go module package resolution.

func (*Analysis) GetImportedModules

func (a *Analysis) GetImportedModules() map[string]*packages.Module

GetImportedModules returns the list of modules imported in the packages.

func (*Analysis) GetLoadedPackages

func (a *Analysis) GetLoadedPackages() map[string]*packages.Package

GetLoadedPackages returns the loaded packages.

func (*Analysis) GetProgramCodeFiles

func (a *Analysis) GetProgramCodeFiles(
	exactMatchFilter []string,
	importPathPrefixFilter string,
) map[string][]string

GetProgramCodeFiles returns file paths for packages in the program. exactMatchFilter and importPathPrefixFilter are optional.

type ModuleCompiler

type ModuleCompiler struct {
	// contains filtered or unexported fields
}

ModuleCompiler assembles a series of Go module files on disk to orchestrate "go build" commands and produce a plugin with unique import paths for the changed packages.

func NewModuleCompiler

func NewModuleCompiler(
	ctx context.Context,
	le *logrus.Entry,
	buildPrefix string,
	pluginCodegenPath string,
	pluginBinaryID string,
) (*ModuleCompiler, error)

NewModuleCompiler constructs a new module compiler with paths.

packagesLookupPath is the working directory for "go build."

func (*ModuleCompiler) Cleanup

func (m *ModuleCompiler) Cleanup()

Cleanup removes the codegen files, optionally with a build hash.

func (*ModuleCompiler) CompilePlugin

func (m *ModuleCompiler) CompilePlugin(outFile string) error

CompilePlugin compiles the plugin once. The module structure should have been built already.

func (*ModuleCompiler) GenerateModules

func (m *ModuleCompiler) GenerateModules(analysis *Analysis, pluginBinaryVersion string) error

GenerateModules builds the modules files in the codegen path.

buildPrefix should be something like cbus-plugin-abcdef (no slash)

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher watches a set of packages and re-generates an output plugin codegen and binary when the code files change.

func NewWatcher

func NewWatcher(le *logrus.Entry, packageLookupPath string, packagePaths []string) *Watcher

NewWatcher constructs a new watcher.

Recognizes and replaces {buildHash} in the output filename. The output path should be output-plugin-dir/output-plugin-{buildHash}.cbus.so

func (*Watcher) WatchCompilePlugin

func (w *Watcher) WatchCompilePlugin(
	ctx context.Context,
	pluginCodegenPath string,
	pluginOutputPath string,
	pluginBinaryID string,
	pluginBinaryVersion string,
	compiledCb func(packages []string, outpPath string) error,
) error

WatchCompilePlugin watches and compiles package. Detects if the output with the same {buildHash} already exists. Replaces {buildHash} in output filename and in plugin binary version.

Jump to

Keyboard shortcuts

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