formula

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(f *Formula, tmplText string) (string, error)

Generate renders a Ruby formula from the Formula model using the default template, or tmplText if non-empty (a user-supplied override receiving the same model).

func RubyLdflags added in v0.8.0

func RubyLdflags(tmplText, commitExpr string) ([]string, error)

RubyLdflags renders a gobottle ldflags template — the very text source.build.ldflags feeds to the cross-compiler, with the same template fields — substituting Ruby interpolations for the build-time values, then splits the result into %W[] tokens:

{{.Version}} -> #{version}      {{.Tag}}         -> v#{version}
{{.Date}}    -> #{time.iso8601} {{.Commit}}      -> #{<commitExpr>}
                                {{.ShortCommit}} -> #{<commitExpr>[0,7]}

commitExpr is the Ruby expression yielding the commit (typically the "commit" local computed by SourceBuild.CommitLocal).

Bare -s and -w tokens are dropped: std_go_args already supplies them unless the user asked for --debug-symbols, and forwarding them would defeat that. -trimpath is likewise std_go_args' business, not the ldflags'.

Every %W[] element is one whitespace-separated token, so ldflags values containing spaces are not supported — the same constraint the host build already imposes.

func ToPascalCase

func ToPascalCase(s string) string

ToPascalCase converts a string to PascalCase for Ruby class names Examples:

  • "myapp" -> "Myapp"
  • "my-app" -> "MyApp"
  • "my_app" -> "MyApp"
  • "myApp" -> "MyApp"

Types

type BinaryInstall added in v0.2.0

type BinaryInstall struct {
	Name        string
	InstallPath string
}

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

type BottleSpec

type BottleSpec struct {
	Platform string // e.g. "arm64_sonoma", "x86_64_linux"
	SHA256   string // bottle tarball SHA256
	Cellar   string // e.g. ":any_skip_relocation" or an absolute path
}

BottleSpec represents one sha256 line in the bottle block.

type EnvVar added in v0.8.0

type EnvVar struct {
	Key   string
	Value string
}

EnvVar is one ENV["Key"] = "Value" assignment in the install block.

type Formula

type Formula struct {
	Name        string // Formula name (e.g., "myapp")
	ClassName   string // PascalCase name for Ruby class (derived if empty)
	Description string // Short description (omitted if empty; brew audit wants it)
	Homepage    string // Project homepage URL
	URL         string // Source tarball URL
	SHA256      string // Source tarball SHA256 (omitted if empty)
	License     string // SPDX identifier (omitted if empty)
	Head        *Head  // Optional head stanza

	// Bottle block
	RootURL string       // e.g. "https://ghcr.io/v2/myorg/tap" (formula name appended by brew)
	Rebuild int          // rebuild counter; emitted as `rebuild N` when > 0
	Bottles []BottleSpec // one line per platform

	// Body
	Build        *SourceBuild    // source-build install block (nil: legacy bin.install)
	Dependencies []string        // depends_on lines
	Conflicts    []string        // conflicts_with lines
	Binaries     []BinaryInstall // install lines (first bin-installed binary drives the default test)
	Completions  []string        // completion-generating command rendered per bin-installed binary (empty: no line)
	ExtraInstall []string        // verbatim extra install lines
	Caveats      string          // literal caveats text
	Service      string          // verbatim service block body
	Test         Test            // test block (defaults to `system bin/"<bin>", "--version"`)
}

Formula is the complete model from which a Homebrew formula is generated. gobottle owns the formula outright: every publish renders it from this model; there is no in-place editing of hand-written formulae.

func (*Formula) BinBinaries added in v0.2.0

func (f *Formula) BinBinaries() []string

BinBinaries returns the names of the binaries installed into bin; only these are runnable from PATH, so they drive the default test and completion generation.

func (*Formula) BottleLines added in v0.8.2

func (f *Formula) BottleLines() []string

BottleLines renders the sha256 lines of the bottle block with the tag and digest columns aligned, as `brew audit --strict` (BottleTagIndentation, BottleDigestIndentation) requires:

sha256 cellar: :any,                 arm64_sonoma: "…"
sha256 cellar: :any_skip_relocation, x86_64_linux: "…"

func (*Formula) DependsOnArgs added in v0.8.0

func (f *Formula) DependsOnArgs() []string

DependsOnArgs returns the rendered arguments of every depends_on line: the source build's Go toolchain first, then the configured runtime dependencies. They form a single group in the formula, unlike the historic one-blank-line- per-dependency layout.

func (*Formula) SortBottles added in v0.8.2

func (f *Formula) SortBottles()

SortBottles orders the bottle block canonically (see bottleGroup), keeping the relative order within each group (newest macOS first, as discovered).

func (*Formula) StdGoArgs added in v0.8.0

func (f *Formula) StdGoArgs(t GoTarget) string

StdGoArgs renders the keyword arguments passed to std_go_args for one target. It never passes -s/-w/-trimpath: std_go_args supplies those itself (and honours --debug-symbols while doing so).

type GoTarget added in v0.8.0

type GoTarget struct {
	Package     string // "./cmd/foo"
	Binary      string // "foo"
	InstallPath string // "bin" | "libexec" | arbitrary keg-relative path
}

GoTarget pairs a Go package with the binary it produces and where that binary is installed, mirroring the package↔binary pairing the cross-compiler uses (see artifact.PackageBinaries).

type Head struct {
	URL    string // git URL, e.g. https://github.com/owner/repo.git
	Branch string // e.g. "main"
}

Head describes an optional `head` stanza.

type SourceBuild added in v0.8.0

type SourceBuild struct {
	GoDependency string   // "go" -> depends_on "go" => :build (empty: none)
	Env          []EnvVar // ENV["K"] = "V" assignments
	ModDir       string   // wrapped in `cd "<dir>" do … end` when set and != "."
	Ldflags      []string // %W[] tokens, already Ruby-interpolated
	Commit       string   // literal SHA of the release tag ("" -> tap.user)
	HeadCommit   bool     // emit the build.head? ternary for --HEAD builds
	Tags         []string // std_go_args(tags: [...])
	Flags        []string // extra go build flags, placed before the package
	Targets      []GoTarget
}

SourceBuild describes the install block that compiles the formula from source, honouring `brew install --build-from-source` and `--HEAD`. Homebrew never runs def install when pouring a bottle, so this is the recipe for everyone who cannot (or chooses not to) use one.

func (*SourceBuild) CommitLocal added in v0.8.0

func (b *SourceBuild) CommitLocal() string

CommitLocal renders the right-hand side of the `commit = …` local, or "" when the ldflags never reference it. --HEAD builds read the commit from the checkout; the stable spec bakes in the release tag's commit, falling back to the homebrew-core `tap.user` idiom when no commit is knowable.

func (*SourceBuild) Indent added in v0.8.0

func (b *SourceBuild) Indent() string

Indent is the extra indentation applied to lines inside the cd block.

func (*SourceBuild) LdflagLines added in v0.8.0

func (b *SourceBuild) LdflagLines() []string

LdflagLines groups the %W[] tokens onto rendered lines: a bare "-X" stays with the symbol assignment it introduces. %W[] splits on whitespace either way, so this is purely cosmetic — it just keeps the array readable.

func (*SourceBuild) WrapsModDir added in v0.8.0

func (b *SourceBuild) WrapsModDir() bool

WrapsModDir reports whether the build must run inside `cd "<dir>" do`.

type Test

type Test struct {
	Command []string
	Raw     string
}

Test describes the `test do` block. If Raw is set it is used verbatim (indented); otherwise `system bin/"<first binary>", <Command...>` is rendered, with Command defaulting to ["--version"].

Jump to

Keyboard shortcuts

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