bottle

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateCompletions added in v0.2.0

func GenerateCompletions(ctx context.Context, binaryPath, name string, command []string, dir string) (map[string]string, error)

GenerateCompletions runs `<binaryPath> <command...> <shell>` for bash, zsh and fish, writes each captured script under dir, and returns keg-relative archive path -> local path entries suitable for BuildOptions.ExtraFiles. name is the binary's configured (installed) name, used for the archive paths, the local file names and argv[0] of the exec'd process; it can differ from binaryPath's basename, since binaryPath may already be resolved through a symlink (e.g. ResolveBinary dereferencing an alias or an unpredictable versioned release filename). Any shell failing to generate is an error: shipping partial completions silently is worse than failing the build.

func ResolveBinary added in v0.9.0

func ResolveBinary(dir, name string) (string, error)

ResolveBinary resolves name within dir (an extracted artifact directory, or a directory artifact used as-is) to a regular file, dereferencing any symlink so callers always see the same content a poured bottle would contain. A configured binary may itself be a symlink inside the artifact (a release archive can ship a dereferenced copy under an unpredictable versioned name, e.g. mytool -> mytool_1.2.3, or an alias such as kubectl-mytool -> mytool). It is an error for name to be missing, dangling, to resolve outside dir, or to resolve to anything but a regular file.

Types

type BinaryInstall added in v0.2.0

type BinaryInstall struct {
	Name        string
	InstallPath string
	Links       []string // symlinked alias names, installed alongside Name
}

BinaryInstall names a binary and the keg-relative directory it installs into (empty means "bin").

type Bottle

type Bottle struct {
	Formula            string            // e.g., "myapp"
	Version            string            // e.g., "1.2.3"
	Platform           platform.Platform // The Homebrew platform
	SHA256             string            // SHA256 of the bottle tarball (formula sha256 == OCI layer digest)
	UncompressedSHA256 string            // SHA256 of the raw tar stream (OCI diff_id)
	UncompressedSize   int64             // raw tar size in bytes (installed_size basis)
	Path               string            // Local path to bottle file
	Binaries           []string          // Binaries included
	Cellar             string            // e.g., ":any_skip_relocation"
	Rebuild            int               // Rebuild number (usually 0)
	Tab                *Tab              // INSTALL_RECEIPT content (also pushed as sh.brew.tab)
	IgnoredSymlinks    []IgnoredSymlink  // artifact symlinks not declared as a binary or link (not bottled)
}

Bottle represents a built Homebrew bottle

func (*Bottle) BottleName

func (b *Bottle) BottleName() string

BottleName returns the local bottle filename, matching brew's convention: formula--version.platform.bottle[.rebuild].tar.gz

func (*Bottle) FileSize

func (b *Bottle) FileSize() (int64, error)

FileSize returns the size of the bottle tarball in bytes.

func (*Bottle) RefName

func (b *Bottle) RefName() string

RefName returns the org.opencontainers.image.ref.name annotation value: "version.platform_tag" or "version.platform_tag.rebuild".

func (*Bottle) VersionRebuild

func (b *Bottle) VersionRebuild() string

VersionRebuild returns the OCI tag for this bottle's version: "version" or "version-rebuild" (GitHubPackages.version_rebuild).

type BuildOptions

type BuildOptions struct {
	Formula      string
	Version      string
	Platform     platform.Platform
	ArtifactPath string          // Path to archive containing the binaries
	Binaries     []BinaryInstall // Binaries to include
	Cellar       string
	Rebuild      int
	Tap          string            // Tap name for INSTALL_RECEIPT.json (e.g., "user/homebrew-tap")
	FormulaRb    string            // Rendered formula source (sans bottle block) for .brew/<formula>.rb
	ExtraFiles   map[string]string // Keg-relative archive path -> local path (e.g. completions)
	SourceDate   time.Time
	OutputDir    string // Where to write the bottle (default: builder temp dir, removed on Close)
}

BuildOptions contains the parameters for building a bottle

type Builder

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

Builder transforms build artifacts into Homebrew bottles

func NewBuilder

func NewBuilder() (*Builder, error)

NewBuilder creates a new bottle builder with a temp work directory

func (*Builder) Build

func (b *Builder) Build(ctx context.Context, opts BuildOptions) (*Bottle, error)

Build creates a bottle from an artifact archive containing the binaries at its root. The output tarball is fully deterministic for identical inputs.

func (*Builder) Close

func (b *Builder) Close() error

Close cleans up the work directory

type IgnoredSymlink struct {
	Name   string
	Target string
}

IgnoredSymlink is a symlink found at the top level of the extracted artifact whose name is neither a configured binary nor one of its links. gobottle never bottles it: the config is the single source of truth for the bottle's layout, so it is reported for the caller to warn about instead.

type RuntimeDependency

type RuntimeDependency struct {
	FullName         string `json:"full_name"`
	Version          string `json:"version"`
	Revision         int    `json:"revision,omitempty"`
	PkgVersion       string `json:"pkg_version"`
	DeclaredDirectly bool   `json:"declared_directly"`
}

RuntimeDependency represents a runtime dependency in the tab

type Tab

type Tab struct {
	HomebrewVersion       string              `json:"homebrew_version"`
	UsedOptions           []string            `json:"used_options"`
	UnusedOptions         []string            `json:"unused_options"`
	BuiltAsBottle         bool                `json:"built_as_bottle"`
	PouredFromBottle      bool                `json:"poured_from_bottle"`
	InstalledAsDependency bool                `json:"installed_as_dependency"`
	InstalledOnRequest    bool                `json:"installed_on_request"`
	ChangedFiles          []string            `json:"changed_files"`
	Time                  int64               `json:"time"`
	SourceModifiedTime    int64               `json:"source_modified_time"`
	Compiler              string              `json:"compiler"`
	Stdlib                *string             `json:"stdlib"`
	Aliases               []string            `json:"aliases"`
	RuntimeDependencies   []RuntimeDependency `json:"runtime_dependencies"`
	Source                TabSource           `json:"source"`
	Arch                  string              `json:"arch"`
	BuiltOn               TabBuiltOn          `json:"built_on"`
}

Tab represents the INSTALL_RECEIPT.json structure used by Homebrew to track bottle metadata and installation information.

func NewTab

func NewTab(opts TabOptions) *Tab

NewTab creates a new Tab with the given options

func (*Tab) Marshal

func (t *Tab) Marshal() ([]byte, error)

Marshal returns the compact JSON representation of the Tab, used both for the INSTALL_RECEIPT.json inside the bottle and the sh.brew.tab manifest annotation.

type TabBuiltOn

type TabBuiltOn struct {
	OS            string `json:"os"`
	OSVersion     string `json:"os_version"`
	CPUFamily     string `json:"cpu_family"`
	Xcode         string `json:"xcode,omitempty"`
	CLT           string `json:"clt,omitempty"`
	PreferredPerl string `json:"preferred_perl,omitempty"`
}

TabBuiltOn contains build environment information

type TabOptions

type TabOptions struct {
	// Formula name
	Formula string

	// Version string
	Version string

	// Architecture (arm64 or x86_64)
	Arch string

	// OS (darwin or linux)
	OS string

	// OS version (e.g., "15.0" for macOS Sequoia)
	OSVersion string

	// Tap name (e.g., "user/homebrew-tap")
	Tap string

	// Compiler used (default: "go" for Go-built bottles)
	Compiler string

	// Time overrides the build timestamp (for reproducible bottles).
	// Falls back to SOURCE_DATE_EPOCH, then the Unix epoch — never
	// time.Now(), so identical inputs marshal identically.
	Time time.Time
}

TabOptions contains options for creating a new Tab

type TabSource

type TabSource struct {
	Spec       string      `json:"spec"`
	Versions   TabVersions `json:"versions"`
	Path       string      `json:"path,omitempty"`
	Tap        string      `json:"tap,omitempty"`
	TapGitHead string      `json:"tap_git_head,omitempty"`
}

TabSource contains source information for the formula

type TabVersions

type TabVersions struct {
	Stable        string  `json:"stable"`
	Head          *string `json:"head"`
	VersionScheme int     `json:"version_scheme"`
}

TabVersions contains version information

Jump to

Keyboard shortcuts

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