bb

package
v0.0.0-...-d8fbaca Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: BSD-3-Clause Imports: 13 Imported by: 3

Documentation

Overview

Package bb builds one busybox-like binary out of many Go command sources.

This allows you to take two Go commands, such as Go implementations of `sl` and `cowsay` and compile them into one binary, callable like `./bb sl` and `./bb cowsay`. Which command is invoked is determined by `argv[0]` or `argv[1]` if `argv[0]` is not recognized.

Under the hood, bb implements a Go source-to-source transformation on pure Go code. This AST transformation does the following:

  • Takes a Go command's source files and rewrites them into Go package files without global side effects.
  • Writes a `main.go` file with a `main()` that calls into the appropriate Go command package based on `argv[0]`.

Principally, the AST transformation moves all global side-effects into callable package functions. E.g. `main` becomes `registeredMain`, each `init` becomes `initN`, and global variable assignments are moved into their own `initN`.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildBusybox

func BuildBusybox(l ulog.Logger, opts *Opts) (nerr error)

BuildBusybox builds a busybox of many Go commands. opts contains both the commands to build and other options.

For documentation on how this works, please refer to the README at the top of the repository.

Types

type ErrBuild

type ErrBuild struct {
	CmdDir string
	GOPATH string
	Err    error
}

ErrBuild is returned for a go build failure when modules were disabled.

func (*ErrBuild) Error

func (e *ErrBuild) Error() string

Error implements error.Error.

func (*ErrBuild) Unwrap

func (e *ErrBuild) Unwrap() error

Unwrap implements error.Unwrap.

type Opts

type Opts struct {
	// Env are the environment variables used in Go compilation and package
	// discovery.
	Env *golang.Environ

	// LookupEnv is the environment for looking up and resolving command
	// paths.
	//
	// If left unset, DefaultEnv will be used.
	LookupEnv *findpkg.Env

	// GenSrcDir is an empty directory to generate the busybox source code
	// in.
	//
	// If GenSrcDir has children, BuildBusybox will return an error. If
	// GenSrcDir does not exist, it will be created. If no GenSrcDir is
	// given, a temporary directory will be generated. The generated
	// directory will be deleted if compilation succeeds.
	//
	// In GOPATH mode, GOPATH=GenSrcDir for compilation.
	GenSrcDir string

	// CommandPaths is a list of file system directories containing Go
	// commands, or Go import paths.
	CommandPaths []string

	// BinaryPath is the file to write the binary to.
	BinaryPath string

	// GoBuildOpts is configuration for the `go build` command that
	// compiles the busybox binary.
	GoBuildOpts *golang.BuildOpts

	// Generate the tree but don't build it. This is useful for systems
	// like Tamago which have their own way of building.
	GenerateOnly bool
}

Opts are the arguments to BuildBusybox.

Directories

Path Synopsis
Package bbinternal is the internal API for both bazel and standard Go busybox builds.
Package bbinternal is the internal API for both bazel and standard Go busybox builds.
Package bbmain is the package imported by all rewritten busybox command-packages to register themselves.
Package bbmain is the package imported by all rewritten busybox command-packages to register themselves.
cmd
Package main is the busybox main.go template.
Package main is the busybox main.go template.
Package findpkg finds packages from user-input strings that are either file paths or Go package paths.
Package findpkg finds packages from user-input strings that are either file paths or Go package paths.

Jump to

Keyboard shortcuts

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