pkgbuild

package
v2.0.5 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package pkgbuild provides PKGBUILD structure and manipulation functionality.

Package pkgbuild provides PKGBUILD structure and manipulation functionality.

Index

Constants

View Source
const (
	ArchAny     = "any"
	ArchAarch64 = "aarch64"
	ArchArmv7   = "armv7"
)

Architecture constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type FuncBody

type FuncBody string

FuncBody is a tagged string type used exclusively for PKGBUILD function bodies. AddItem uses this type to distinguish function declarations from plain string variable values so that mapFunctions does not misidentify variables like "maintainer" as helper function definitions.

type PKGBUILD

type PKGBUILD struct {
	Arch            []string
	ArchComputed    string
	Backup          []string
	Build           string
	BuildArch       string // Build architecture for cross-compilation (where compilation happens)
	BuildDate       int64
	Changelog       string `json:"changelog,omitempty"`
	Checksum        string
	Codename        string
	Commit          string
	Conflicts       []string
	Copyright       []string
	CustomArrays    map[string][]string
	CustomVariables map[string]string
	DataHash        string
	DebConfig       string
	DebTemplate     string
	Depends         []string
	Distro          string
	Enhances        []string
	Supplements     []string
	Epoch           string
	Files           []string
	FullDistroName  string
	Group           string
	HashSums        []string
	HelperFunctions map[string]string
	Home            string
	HostArch        string // Host architecture for cross-compilation (where package will run)
	// RepoDir is the git repository root. Walks up from the yap.json directory
	// to find a .git dir; falls back to the parent of the yap.json directory.
	RepoDir           string
	Install           string
	InstalledSize     int64
	License           []string
	Maintainer        string
	MakeDepends       []string
	OptDepends        []string
	Options           []string
	NoExtract         []string
	Origin            string
	Package           string
	PackageDir        string
	PkgBase           string // pkgbase — shared base name for split packages; equals PkgName when not a split package
	PkgDesc           string
	PkgDest           string
	PkgName           string
	PkgNames          []string          // pkgname array — populated for split packages; empty for single packages
	SplitPackageFuncs map[string]string // package_<name>() bodies, keyed by sub-package name
	PkgRel            string
	PkgType           string
	PkgVer            string
	PostInst          string
	PostRm            string
	PostTrans         string
	PostUpgrade       string
	PreInst           string
	Prepare           string
	PreRm             string
	PreTrans          string
	PreUpgrade        string

	Priority         string
	Provides         []string
	Replaces         []string
	Section          string
	SourceDir        string
	SourceURI        []string
	StartDir         string
	TargetArch       string // Target architecture for cross-compilation (what we're building for)
	URL              string
	DebugEnabled     bool
	DocsEnabled      bool
	EmptyDirsEnabled bool
	LibtoolEnabled   bool
	PurgeEnabled     bool
	StaticEnabled    bool
	StripEnabled     bool
	ZipManEnabled    bool
	YAPVersion       string
	// contains filtered or unexported fields
}

PKGBUILD defines all the fields accepted by the yap specfile (variables, arrays, functions). templating and other rpm/deb descriptors.

func (*PKGBUILD) AddItem

func (pkgBuild *PKGBUILD) AddItem(key string, data any) error

AddItem adds an item to the PKGBUILD.

It takes a key string and data of any type as parameters. It returns an error.

func (*PKGBUILD) BuildEnvironmentSlice

func (pkgBuild *PKGBUILD) BuildEnvironmentSlice() []string

BuildEnvironmentSlice returns the package-specific environment variables as a "KEY=VALUE" slice that can be merged with os.Environ() for safe concurrent use. Unlike SetEnvironmentVariables, it does NOT mutate the process environment, making it safe to call from multiple goroutines simultaneously (parallel builds).

The returned slice includes:

  • pkgdir, srcdir, startdir, repodir — per-package directory paths (repodir = git repository root; empty string if not in a git repo)
  • pkgname, pkgver, pkgrel — per-package identity fields
  • SOURCE_DATE_EPOCH — for reproducible builds (if set)

func (*PKGBUILD) BuildScriptPreamble

func (pkgBuild *PKGBUILD) BuildScriptPreamble() string

BuildScriptPreamble generates a bash preamble that declares custom scalar variables, custom array variables, and helper function definitions so that they are available inside build(), prepare(), and package() scripts.

The preamble is prepended to every script body before execution. Declarations are emitted in sorted order so that the output is deterministic.

func (*PKGBUILD) ComputeArchitecture

func (pkgBuild *PKGBUILD) ComputeArchitecture()

ComputeArchitecture checks if the specified architecture is supported. If "any", sets to "any". Otherwise, checks if current architecture is supported. Logs error if not supported, then sets to current architecture if supported.

func (*PKGBUILD) CreateSpec

func (pkgBuild *PKGBUILD) CreateSpec(filePath string, tmpl *template.Template) error

CreateSpec reads the filepath where the specfile will be written and the content of the specfile. Specfile generation is done using go templates for every different distro family. It returns any error if encountered.

func (*PKGBUILD) EffectivePkgBase

func (pkgBuild *PKGBUILD) EffectivePkgBase() string

EffectivePkgBase returns the base name for this package. For split packages this is PkgBase (set from the pkgbase= directive). For single packages it falls back to PkgName.

func (*PKGBUILD) Finalize

func (pkgBuild *PKGBUILD) Finalize()

Finalize merges arch-specific source and checksum accumulators into the base SourceURI and HashSums slices. Must be called after all AddItem calls are complete (i.e. after parsing). Order-independent: arch entries are always appended after the base entries regardless of declaration order.

func (*PKGBUILD) GetDepends

func (pkgBuild *PKGBUILD) GetDepends(packageManager string, args, makeDepends []string) error

GetDepends reads the package manager name, its arguments and all the dependencies required to build the package. It returns any error if encountered.

func (*PKGBUILD) GetTargetArchitecture

func (pkgBuild *PKGBUILD) GetTargetArchitecture() string

GetTargetArchitecture returns the target architecture for cross-compilation. If a target architecture is explicitly set in the PKGBUILD, it returns that. Otherwise, it returns the computed architecture from the standard architecture processing.

func (*PKGBUILD) GetUpdates

func (pkgBuild *PKGBUILD) GetUpdates(packageManager string, args ...string) error

GetUpdates reads the package manager name and its arguments to perform a sync with remotes and consequently retrieve updates. It returns any error if encountered.

func (*PKGBUILD) HelperFunctionsPreamble

func (pkgBuild *PKGBUILD) HelperFunctionsPreamble(scriptletBody string) string

HelperFunctionsPreamble returns a bash snippet containing only the helper function definitions that are referenced by the given scriptlet body. Unlike BuildScriptPreamble it does NOT emit custom scalar or array variable declarations, which are build-time values and have no meaning inside package-manager scriptlets (preinst, postinst, prerm, postrm).

Only helpers whose names appear as call-sites in scriptletBody are included, so build-time helpers like _package or _package_systemd are not injected into install-time scripts.

func (*PKGBUILD) Init

func (pkgBuild *PKGBUILD) Init()

Init initializes the PKGBUILD struct.

It sets up the priorities map and assigns the full distribution name based on the Distro and Codename fields.

func (*PKGBUILD) IsCrossCompilation

func (pkgBuild *PKGBUILD) IsCrossCompilation() bool

IsCrossCompilation checks if cross-compilation is enabled for this PKGBUILD. Returns true if any of the cross-compilation architecture variables are set.

func (*PKGBUILD) IsSplitPackage

func (pkgBuild *PKGBUILD) IsSplitPackage() bool

IsSplitPackage reports whether this PKGBUILD defines multiple packages (i.e. pkgname is an array with more than one entry).

func (*PKGBUILD) ParseSplitOverrides

func (pkgBuild *PKGBUILD) ParseSplitOverrides(funcBody string) error

ParseSplitOverrides parses the body of a package_<name>() function and applies any recognized override variables (pkgdesc, depends, conflicts, etc.) to the PKGBUILD struct via AddItem — giving full __distro and _arch suffix support for free.

funcBody is the raw function body string as stored in SplitPackageFuncs (no braces).

func (*PKGBUILD) ReadChangelog

func (pkgBuild *PKGBUILD) ReadChangelog() ([]byte, error)

ReadChangelog returns the changelog file contents, resolved relative to the PKGBUILD directory. Returns empty bytes and nil error if Changelog is empty. Returns wrapped error if the path is set but the file is unreadable.

func (*PKGBUILD) RenderSpec

func (pkgBuild *PKGBUILD) RenderSpec(script string) *template.Template

RenderSpec initializes a new template with custom functions and parses the provided script. It adds two custom functions to the template:

"join": Takes a slice of strings and joins them into a single string, separated by commas,
while also trimming any leading or trailing spaces.
"multiline": Takes a string and replaces newline characters with a newline followed by a space,
effectively formatting the string for better readability in multi-line contexts.

The method returns the parsed template, which can be used for rendering with data.

func (*PKGBUILD) RestoreSplitOverrides added in v2.0.3

func (pkgBuild *PKGBUILD) RestoreSplitOverrides(snap *PKGBUILD)

RestoreSplitOverrides resets all overrideable fields to the snapshot values.

func (*PKGBUILD) RestoreTopLevelOverrides added in v2.0.3

func (pkgBuild *PKGBUILD) RestoreTopLevelOverrides()

RestoreTopLevelOverrides resets all overrideable fields to the top-level values captured by Finalize, preventing one sub-package's overrides from bleeding into the next. No-op for non-split packages.

func (*PKGBUILD) SetEnvironmentVariables

func (pkgBuild *PKGBUILD) SetEnvironmentVariables() error

SetEnvironmentVariables sets the environment variables for the PKGBUILD execution context. This should be called just before executing build/package functions to ensure each package uses its own directories, even when building multiple packages.

NOTE: For parallel builds, prefer BuildEnvironmentSlice() which does not mutate the global process environment and is safe to call from multiple goroutines.

It returns an error if setting any environment variable fails.

func (*PKGBUILD) SetMainFolders

func (pkgBuild *PKGBUILD) SetMainFolders()

SetMainFolders sets the main folders for the PKGBUILD.

It takes no parameters. It does not return anything.

func (*PKGBUILD) SetPackageDirForSplit

func (pkgBuild *PKGBUILD) SetPackageDirForSplit(subPkgName string)

SetPackageDirForSplit overrides PackageDir for a specific sub-package name. Called by Builder.Compile when iterating split sub-packages.

func (*PKGBUILD) SnapshotSplitOverrides added in v2.0.3

func (pkgBuild *PKGBUILD) SnapshotSplitOverrides() PKGBUILD

SnapshotSplitOverrides returns a copy of the PKGBUILD capturing the top-level values of all fields that package_<name>() functions may override. Call once before the split-package loop; pass to RestoreSplitOverrides before each sub-package to prevent overrides from bleeding between sub-packages.

func (*PKGBUILD) ValidateGeneral

func (pkgBuild *PKGBUILD) ValidateGeneral() error

ValidateGeneral checks that mandatory items are correctly provided by the PKGBUILD file.

func (*PKGBUILD) ValidateMandatoryItems

func (pkgBuild *PKGBUILD) ValidateMandatoryItems() error

ValidateMandatoryItems checks that mandatory items are correctly provided by the PKGBUILD file.

Jump to

Keyboard shortcuts

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