Documentation ¶
Overview ¶
Package build generates packages that can be installed by a system package manager. Supported formats include dpkg (used by Debian and Ubuntu), pacman (used by Arch Linux), and RPM (used by Suse, Redhat, Fedora, Mageia). RPM support is experimental.
This package contains the common API that is shared by all generators. The generator implementations are in this package's subdirectories.
Index ¶
- Constants
- type Architecture
- type Generator
- type GeneratorFactory
- type Package
- func (p *Package) AppendActions(actions ...PackageAction)
- func (p *Package) InsertFSNode(absolutePath string, entry filesystem.Node) error
- func (p *Package) PrepareBuild()
- func (p *Package) PrependActions(actions ...PackageAction)
- func (p *Package) Script(actionType uint) string
- func (pkg *Package) ValidateWith(r RegexSet, archMap map[Architecture]string) []error
- func (p *Package) WalkFSWithAbsolutePaths(callback func(absolutePath string, node filesystem.Node) error) error
- func (p *Package) WalkFSWithRelativePaths(callback func(relativePath string, node filesystem.Node) error) error
- type PackageAction
- type PackageRelation
- type PrereleaseType
- type RegexSet
- type VersionConstraint
Constants ¶
const ( //SetupAction is an acceptable value for `PackageAction.Type`. Setup //actions run immediately after the package has been installed or upgraded //on a system. SetupAction = iota //CleanupAction is an acceptable value for `PackageAction.Type`. Cleanup //actions run immediately after the package has been removed from a system. CleanupAction )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Architecture ¶
type Architecture uint
Architecture is an enum that describes the target architecture for this package (or "any" for packages without compiled binaries).
const ( // ArchitectureAny = no compiled binaries (default value!) ArchitectureAny Architecture = iota // ArchitectureI386 = i386 ArchitectureI386 // ArchitectureX86_64 = x86_64 ArchitectureX86_64 // ArchitectureARMv5 = ARMv5 ArchitectureARMv5 // ArchitectureARMv6h = ARMv6h (hardfloat) ArchitectureARMv6h // ArchitectureARMv7h = ARMv7h (hardfloat) ArchitectureARMv7h // ArchitectureAArch64 = AArch64 (ARMv8 64-bit) ArchitectureAArch64 )
type Generator ¶
type Generator interface { //Validate performs additional validations on the package that are specific //to the concrete generator. For example, if the package format imposes //restrictions on the format of certain fields (names, versions, etc.), they //should be checked here. // //If the package is valid, an empty slice is to be returned. Validate() []error //Build produces the final package (usually a compressed tar file) in the //return argument. The package must be built reproducibly; such that every //run (even across systems) produces an identical result. For example, no //timestamps or generator version information may be included. // //Build should call pkg.PrepareBuild() to execute some common preparation steps. Build() ([]byte, error) //Generate the recommended file name for this package. Distributions usually //have guidelines for this sort of thing. The string returned must be a plain //file name without any slashes. RecommendedFileName() string }
Generator is a generic interface for the package generator implementations. One Generator exists for every target package format (e.g. pacman, dpkg, RPM) supported by libpackagebuild.
A generator should take the package to be built as a struct field like this:
type DebianGenerator struct { Package *Package //... other fields ... }
Each generator implementation should also provide a function of type GeneratorFactory, see below.
type GeneratorFactory ¶
GeneratorFactory is a type of function that creates generators.
type Package ¶
type Package struct { //Name is the package name. Name string //Version is the version for the package contents. This field shall contain //only numbered versions separated by dots (e.g. "1.0" or "0.9.184.5" or //"2020.10.05"). Other version strings cannot be guaranteed to generate valid //outputs for all package formats. To specify an alpha or beta version, set //the PrereleaseType and PrereleaseVersion fields. For instance, //"1.2.0-beta.1" shall be encoded as (.Version = "1.2.0", //.PrereleaseType = PrereleaseTypeBeta, .PrereleaseVersion = 1). Version string //PrereleaseType specifies whether this package is an alpha, beta or a final //release. PrereleaseType PrereleaseType //PrereleaseVersion is a counter of prereleases of a given type. //(.PrereleaseType = PrereleaseTypeAlpha, .PrereleaseVersion = 5) will append //"alpha.5" to the package's version (with a separator appropriate for a //given package format). The value in this field is ignored when //.PrereleaseType is PrereleaseTypeNone. PrereleaseVersion uint //Release is a counter that can be increased when the same version of one //package needs to be rebuilt. The default value shall be 1. Release uint //Epoch is a counter that can be increased when the version of a newer //package is smaller than the previous version, thus breaking normal //version comparison logic. This is usually only necessary when changing to //a different version numbering scheme. The default value is 0, which //usually results in the epoch not being shown in the combined version //string at all. Epoch uint //Description is the optional package description. Description string //Author contains the package's author's name and mail address in the form //"Firstname Lastname <email.address@server.tld>", if this information is //available. Author string //Architecture specifies the target architecture of this package. Architecture Architecture //ArchitectureInput contains the raw architecture string specified by the //user (used only for error messages). ArchitectureInput string //Requires contains a list of other packages that are required dependencies //for this package and thus must be installed together with this package. //This is called "Depends" by some package managers. Requires []PackageRelation //Provides contains a list of packages that this package provides features //of (or virtual packages whose capabilities it implements). Provides []PackageRelation //Conflicts contains a list of other packages that cannot be installed at //the same time as this package. Conflicts []PackageRelation //Replaces contains a list of obsolete packages that are replaced by this //package. Upon performing a system upgrade, the obsolete packages will be //automatically replaced by this package. Replaces []PackageRelation //Actions contains a list of actions that can be executed while the package //manager runs. Actions []PackageAction //FSRoot represents the root directory of the package's file system, and //contains all other files and directories recursively. FSRoot *filesystem.Directory }
Package contains all information about a single package. This representation will be passed into the generator backends.
func (*Package) AppendActions ¶
func (p *Package) AppendActions(actions ...PackageAction)
AppendActions appends elements to p.Actions.
func (*Package) InsertFSNode ¶
func (p *Package) InsertFSNode(absolutePath string, entry filesystem.Node) error
InsertFSNode inserts a filesystem.Node into the package's FSRoot at the given absolute path.
func (*Package) PrepareBuild ¶
func (p *Package) PrepareBuild()
PrepareBuild executes common preparation steps. This should be called by each generator's Build() implementation.
func (*Package) PrependActions ¶
func (p *Package) PrependActions(actions ...PackageAction)
PrependActions prepends elements to p.Actions.
func (*Package) Script ¶
Script returns the concatenation of the scripts for all actions of the given type.
func (*Package) ValidateWith ¶
func (pkg *Package) ValidateWith(r RegexSet, archMap map[Architecture]string) []error
ValidateWith is a helper function provided for generators.
It validates the package name, version and related packages with the given set of regexes, and returns a non-empty list of errors if validation fails.
func (*Package) WalkFSWithAbsolutePaths ¶
func (p *Package) WalkFSWithAbsolutePaths(callback func(absolutePath string, node filesystem.Node) error) error
WalkFSWithAbsolutePaths wraps the FSRoot.Wrap function, yielding absolute paths (with a leading slash) to the callback.
func (*Package) WalkFSWithRelativePaths ¶
func (p *Package) WalkFSWithRelativePaths(callback func(relativePath string, node filesystem.Node) error) error
WalkFSWithRelativePaths wraps the FSRoot.Wrap function, yielding paths relative to the FSRoot (without leading slash) to the callback. The FSRoot itself will be visited with `relativePath = ""`.
type PackageAction ¶
type PackageAction struct { //Type determines when this action will be run. Acceptable values include //`SetupAction` and `CleanupAction`. Type uint //Content is a shell script that will be executed when the action is run. Content string }
PackageAction describes an action that can be executed by the package manager at various points during its execution.
type PackageRelation ¶
type PackageRelation struct { RelatedPackage string Constraints []VersionConstraint }
PackageRelation declares a relation to another package. For the related package, any number of version constraints may be given. For example, the following snippet makes a Package require any version of package "foo", and at least version 2.1.2 (but less than version 3.0) of package "bar".
pkg.Requires := []PackageRelation{ PackageRelation { "foo", nil }, PackageRelation { "bar", []VersionConstraint{ VersionConstraint { ">=", "2.1.2" }, VersionConstraint { "<", "3.0" }, } }
type PrereleaseType ¶ added in v1.1.0
type PrereleaseType uint
PrereleaseType is an enum that describes whether the package is an alpha, beta or final release.
const ( //PrereleaseTypeNone indicates a final release that does not have "alpha" or "beta" added to its version number. PrereleaseTypeNone PrereleaseType = iota //PrereleaseTypeAlpha indicates an alpha release. PrereleaseTypeAlpha //PrereleaseTypeBeta indicates a beta release. PrereleaseTypeBeta )
func (PrereleaseType) String ¶ added in v1.1.0
func (pt PrereleaseType) String() string
type RegexSet ¶
type RegexSet struct { PackageName string PackageVersion string RelatedName string RelatedVersion string FormatName string //used for error messages only }
RegexSet is a collection of regular expressions for validating a package. A RegexSet is typically constructed by a common.Generator for calling common.Package.ValidateWith() inside its Validate() method.
type VersionConstraint ¶
type VersionConstraint struct { //Relation is one of "<", "<=", "=", ">=" or ">". Relation string //Version is the version on the right side of the Relation, e.g. "1.2.3-1" //or "2:20151024-1.1". This field is not structured further in this level //since the acceptable version format may depend on the package generator //used. Version string }
VersionConstraint is used by the PackageRelation struct to specify version constraints for a related package.
Directories ¶
Path | Synopsis |
---|---|
Package debian provides a build.Generator for Debian packages.
|
Package debian provides a build.Generator for Debian packages. |
Package filesystem contains a simple representation of hierarchical filesystems that is used by libpackagebuild.
|
Package filesystem contains a simple representation of hierarchical filesystems that is used by libpackagebuild. |
Package pacman provides a build.Generator for Pacman packages (as used by Arch Linux).
|
Package pacman provides a build.Generator for Pacman packages (as used by Arch Linux). |
Package rpm provides a build.Generator for RPM packages.
|
Package rpm provides a build.Generator for RPM packages. |