genmain

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2024 License: AGPL-3.0 Imports: 18 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Output  string
	Verbose bool
	ListPkg bool
	CgoLink bool
)

Functions

func AddPackages

func AddPackages(repos *gir.Repositories, pkgs []Package) error

AddPackages adds the given list of packages into the repository.

func AppendGoFiles

func AppendGoFiles(path string, contents map[string]string) error

AppendGoFiles appends the value of the given contents map into the files at its keys and run go fmt on it.

func CleanDirectory

func CleanDirectory(path string, except []string) error

CleanDirectory cleans up the directory at the given path. Files listed inside except will not be wiped.

func EnsureDirectory

func EnsureDirectory(path string, expects ...[]string) error

EnsureDirectory ensures that all files inside the given directory path are present in the given list of string slices.

func Generate

func Generate(repos gir.Repositories, data Data)

Generate generates the packages based on the given data.

func GenerateAll

func GenerateAll(gen *girgen.Generator, dst string, except []string) []error

GenerateAll generates all namespaces inside the given generator into the given dst path. It uses WriteNamespace to do so. The namespaces will be generated in parallel. If a versioned namespace is in the except slice, then it is skipped.

func GeneratePackages

func GeneratePackages(gen *girgen.Generator, dst string, pkgs []Package, except []string) []error

GeneratePackages generates the given pkgs list into the given dst directory. It uses WriteNamespace to do so. The namespaces will be generated in parallel. Most external GIR generators should call this.

func LoadExternOverrides

func LoadExternOverrides(mod string, repos gir.Repositories) map[string]string

LoadExternOverrides creates a map of GIR versioned namespace names to the Go import path from the given list of all repositories.

func LoadPackages

func LoadPackages(pkgs []Package) (gir.Repositories, error)

LoadPackages loads all GIR repositories from the given list of packages.

func MajorVersion

func MajorVersion(nsp *gir.Namespace) int

MajorVersion returns the major version of the GIR namespace in int.

func ModulePath

func ModulePath(module string, overrides map[string]string) func(*gir.Namespace) string

ModulePath crafts the full module path from the given base module path. If the overrides map is given, then the function will use that as the list of special cases.

func MustAddPackages

func MustAddPackages(repos *gir.Repositories, pkgs []Package)

MustAddPackages bails if packages fail to be added.

func MustLoadPackages

func MustLoadPackages(pkgs []Package) gir.Repositories

MustLoadPackages bails if packages fail to load.

func ParseFlag

func ParseFlag()

ParseFlag calls flag.Parse() and initializes external global options.

func PrintAddedPkgs

func PrintAddedPkgs(repos gir.Repositories)

PrintAddedPkgs prints to console the added packages.

func Run

func Run(data Data)

Run runs the application.

func StringSet

func StringSet(strs ...[]string) map[string]struct{}

StringSet joins the given slices of strings into a map with the keys as the values of each of the given slices.

func WriteNamespace

func WriteNamespace(ng *girgen.NamespaceGenerator, basePath string) error

WriteNamespace generates everything in the given namespace and writes it to the given basePath.

Types

type Data

type Data struct {
	// Module is the Go Module name that the generator is running for. An
	// example is "github.com/diamondburned/gotk4/pkg".
	Module string
	// Packages lists pkg-config packages and optionally the namespaces to be
	// generated. If the list of namespaces is nil, then everything is
	// generated.
	Packages []Package
	// KnownPackages is similar to Packages, but no packages in this list will
	// be used to generate code. This list automatically includes Packages.
	KnownPackages []Package
	// ImportOverrides is the list of imports to defer to another library,
	// usually because it's tedious or impossible to generate.
	//
	// Not included: coreglib (gotk3/gotk3/glib).
	ImportOverrides map[string]string
	// ExternOverrides adds into ImportOverrides packages that were generated
	// from the given GIR repositories, with the map key being the Go module
	// root for those packages. It internally invokes LoadExternOverrides.
	ExternOverrides map[string]gir.Repositories
	// PkgExceptions contains a list of file names that won't be deleted off of
	// pkg/.
	PkgExceptions []string
	// GenerateExceptions contains the keys of the underneath ImportOverrides
	// map.
	GenerateExceptions []string
	// PkgGenerated contains a list of file names that are packages generated
	// using the given Packages list. It is manually updated.
	PkgGenerated []string
	// Preprocessors defines a list of preprocessors that the main generator
	// will use. It's mostly used for renaming colliding types/identifiers.
	Preprocessors []types.Preprocessor
	// Postprocessors is a map of versioned namespace names to a list of
	// functions that are called to modify any file before it is written out.
	Postprocessors map[string][]girgen.Postprocessor
	// ExtraGoContents contains the contents of files that are appended into
	// generated outputs. It is used to add custom implementations of missing
	// functions. It is a simpler version of Postprocessors.
	ExtraGoContents map[string]string
	// Filters defines a list of GIR types to be filtered. The map key is the
	// namespace, and the values are list of names.
	Filters []types.FilterMatcher
	// ProcessConverters is a list of things that can override a type converter.
	ProcessConverters []typeconv.ConversionProcessor
	// DynamicLinkNamespaces lists namespaces that should be generated directly
	// using Cgo. It includes important core packages as well as packages that
	// are small but performance-sensitive.
	DynamicLinkNamespaces []string
	// SingleFile, if true, will make all NamespaceGenerators generate a single
	// output file per package instead of correlating it to the source file.
	SingleFile bool
}

Data contains generation data that genmain uses to generate.

func Overlay added in v0.0.5

func Overlay(data ...Data) Data

Overlay joins the given list of data into a single Data. The last Data in the list will be used for generation.

type Package

type Package struct {
	// Name is the pkg-config name.
	Name string
	// Namespaces is the possible namespaces within it. Refer to
	// ./cmd/gir_namespaces.
	Namespaces []string
}

func (*Package) HasNamespace

func (pkg *Package) HasNamespace(n *gir.Namespace) bool

HasNamespace returns true if the package allows all namespaces or has the given namespace in the list.

Jump to

Keyboard shortcuts

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