lutgen

package
v0.0.0-...-45a9bcf Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package lutgen provides tools to generate lookup tables for Go binaries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Binary

type Binary struct {
	Architecture string
	GoVersion    goversion.GoVersion
	Path         string
}

Binary wraps the information about a single compiled test binary that is given to the inspection callback.

type LookupFunction

type LookupFunction struct {
	Name            string
	OutputType      string
	OutputZeroValue string
	ExtractValue    func(inspectionResult interface{}) interface{}
	RenderValue     func(value interface{}) string
	DocComment      string
}

LookupFunction configures a single lookup table as a Go function that maps an input Go version/architecture to the specified output type.

type LookupTableGenerator

type LookupTableGenerator struct {
	Package                string
	MinGoVersion           goversion.GoVersion
	Architectures          []string
	CompilationParallelism int
	LookupFunctions        []LookupFunction
	ExtraImports           []string
	InspectBinary          func(binary Binary) (interface{}, error)
	TestProgramPath        string
	InstallDirectory       string
	OutDirectory           string
	// contains filtered or unexported fields
}

LookupTableGenerator configures the process of generating a Go source file that implements lookup table(s) for any value based on an input Go version and Go architecture. This can be used to resolve values about a binary that change based on the Go version/architecture, by compiling and inspecting small test binaries ahead-of-type for each Go version/architecture and generating the lookup table(s) based on the results of this process.

Each lookup table is implemented as a function, which are configured in LookupFunction types.

func (*LookupTableGenerator) Run

func (g *LookupTableGenerator) Run(ctx context.Context, writer io.Writer) error

Run runs the generator to completion, writing the generated Go source code to the given writer. If an error occurs installing Go toolchain versions, compiling the test program, or running the inspection function (or if the context is cancelled), then the function will return early.

Jump to

Keyboard shortcuts

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